Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package server
import (
"net"
"testing"
"time"
"github.com/bio-routing/bio-rd/config"
"github.com/bio-routing/bio-rd/routingtable"
"github.com/bio-routing/bio-rd/routingtable/filter"
"github.com/bio-routing/bio-rd/routingtable/locRIB"
)
func TestBgpServerPeerSnapshot(t *testing.T) {
s := NewBgpServer()
err := s.Start(&config.Global{
LocalASN: 204880,
RouterID: 2137,
})
if err != nil {
t.Fatalf("server should have started, got err: %v", err)
}
info := s.GetPeerInfoAll()
if len(info) != 0 {
t.Fatalf("empty server should have 0 peers, has %d", len(info))
}
rib := locRIB.New()
pc := config.Peer{
AdminEnabled: true,
PeerAS: 65300,
PeerAddress: net.IP([]byte{169, 254, 200, 1}),
LocalAddress: net.IP([]byte{169, 254, 200, 0}),
ReconnectInterval: time.Second * 15,
HoldTime: time.Second * 90,
KeepAlive: time.Second * 30,
Passive: true,
RouterID: s.RouterID(),
AddPathSend: routingtable.ClientOptions{
MaxPaths: 10,
},
ImportFilter: filter.NewDrainFilter(),
ExportFilter: filter.NewAcceptAllFilter(),
}
s.AddPeer(pc, rib)
info = s.GetPeerInfoAll()
if want, got := 1, len(info); want != got {
t.Fatalf("empty server should have %d peers, has %d", want, got)
}
var peer PeerInfo
for _, v := range info {
peer = v
break
}
if want, got := net.ParseIP("169.254.200.1"), peer.PeerAddr; !want.Equal(got) {
t.Errorf("PeerAddr: got %v, want %v", got, want)
}
if want, got := uint32(65300), peer.PeerASN; want != got {
t.Errorf("PeerASN: got %v, want %v", got, want)
}
if want, got := uint32(204880), peer.LocalASN; want != got {
t.Errorf("PeerASN: got %v, want %v", got, want)
}
}