Skip to content
Snippets Groups Projects
Unverified Commit 6a15247f authored by Daniel Czerwonk's avatar Daniel Czerwonk Committed by GitHub
Browse files

Merge pull request #99 from hikhvar/add-states-to-peer-state

Added a states slice to peer info.
parents a252acec 31a15576
Branches
Tags
No related merge requests found
...@@ -16,6 +16,7 @@ type PeerInfo struct { ...@@ -16,6 +16,7 @@ type PeerInfo struct {
PeerAddr bnet.IP PeerAddr bnet.IP
PeerASN uint32 PeerASN uint32
LocalASN uint32 LocalASN uint32
States []string
} }
type peer struct { type peer struct {
...@@ -50,10 +51,19 @@ type familyParameters struct { ...@@ -50,10 +51,19 @@ type familyParameters struct {
} }
func (p *peer) snapshot() PeerInfo { 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{ return PeerInfo{
PeerAddr: p.addr, PeerAddr: p.addr,
PeerASN: p.peerASN, PeerASN: p.peerASN,
LocalASN: p.localASN, LocalASN: p.localASN,
States: states,
} }
} }
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"github.com/bio-routing/bio-rd/routingtable/locRIB" "github.com/bio-routing/bio-rd/routingtable/locRIB"
bnet "github.com/bio-routing/bio-rd/net" bnet "github.com/bio-routing/bio-rd/net"
"github.com/stretchr/testify/assert"
) )
func TestBgpServerPeerSnapshot(t *testing.T) { func TestBgpServerPeerSnapshot(t *testing.T) {
...@@ -60,13 +61,12 @@ func TestBgpServerPeerSnapshot(t *testing.T) { ...@@ -60,13 +61,12 @@ func TestBgpServerPeerSnapshot(t *testing.T) {
break break
} }
if want, got := bnet.IPv4FromOctets(169, 254, 200, 1), peer.PeerAddr; !want.Equal(got) { want := PeerInfo{
t.Errorf("PeerAddr: got %v, want %v", got, want) PeerAddr: bnet.IPv4FromOctets(169, 254, 200, 1),
} PeerASN: uint32(65300),
if want, got := uint32(65300), peer.PeerASN; want != got { LocalASN: uint32(204880),
t.Errorf("PeerASN: got %v, want %v", got, want) States: []string{"idle"},
}
if want, got := uint32(204880), peer.LocalASN; want != got {
t.Errorf("PeerASN: got %v, want %v", got, want)
} }
assert.Equal(t, want, peer)
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment