diff --git a/protocols/bgp/server/peer.go b/protocols/bgp/server/peer.go index 4f101d815a7789a26564b6d37527026746404e5e..bde263b504a590b411dc02291f64fe578d282263 100644 --- a/protocols/bgp/server/peer.go +++ b/protocols/bgp/server/peer.go @@ -16,6 +16,7 @@ type PeerInfo struct { PeerAddr bnet.IP PeerASN uint32 LocalASN uint32 + States []string } type peer struct { @@ -50,10 +51,19 @@ type familyParameters struct { } func (p *peer) snapshot() PeerInfo { + p.fsmsMu.Lock() + defer p.fsmsMu.Unlock() + states := make([]string, 0, len(p.fsms)) + for _, fsm := range p.fsms { + fsm.stateMu.RLock() + states = append(states, stateName(fsm.state)) + fsm.stateMu.RUnlock() + } return PeerInfo{ PeerAddr: p.addr, PeerASN: p.peerASN, LocalASN: p.localASN, + States: states, } } diff --git a/protocols/bgp/server/server_test.go b/protocols/bgp/server/server_test.go index 896c3201b01799c3317a5f1e4e1ad1eed194f2bd..2b4e8385204a411fed304e847c3c18c4c107cc7c 100644 --- a/protocols/bgp/server/server_test.go +++ b/protocols/bgp/server/server_test.go @@ -10,6 +10,7 @@ import ( "github.com/bio-routing/bio-rd/routingtable/locRIB" bnet "github.com/bio-routing/bio-rd/net" + "github.com/stretchr/testify/assert" ) func TestBgpServerPeerSnapshot(t *testing.T) { @@ -60,13 +61,12 @@ func TestBgpServerPeerSnapshot(t *testing.T) { break } - if want, got := bnet.IPv4FromOctets(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) + want := PeerInfo{ + PeerAddr: bnet.IPv4FromOctets(169, 254, 200, 1), + PeerASN: uint32(65300), + LocalASN: uint32(204880), + States: []string{"idle"}, } + + assert.Equal(t, want, peer) }