diff options
author | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2018-12-28 22:48:54 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2018-12-28 23:27:53 +0900 |
commit | d7e5bf22a6ef7ebbed02968d5610968e3f06cfc6 (patch) | |
tree | edfbe24fd80c7eafa035708a704b6e2ba9815b6e /pkg | |
parent | c83d234c308ce3b9f0d9e7b52ecfb84657e4e300 (diff) |
fix bmp statistics
fix the regression of the adj counter due to
301b48532d4a5510c9d4ffdc44eb2754fdd1a3d1
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/server/bmp.go | 34 | ||||
-rw-r--r-- | pkg/server/server.go | 8 |
2 files changed, 24 insertions, 18 deletions
diff --git a/pkg/server/bmp.go b/pkg/server/bmp.go index ea6a9fe6..67ed3a91 100644 --- a/pkg/server/bmp.go +++ b/pkg/server/bmp.go @@ -16,11 +16,13 @@ package server import ( + "context" "fmt" "net" "strconv" "time" + api "github.com/osrg/gobgp/api" "github.com/osrg/gobgp/internal/pkg/config" "github.com/osrg/gobgp/internal/pkg/table" "github.com/osrg/gobgp/pkg/packet/bgp" @@ -225,14 +227,15 @@ func (b *bmpClient) loop() { } } case <-tickerCh: - neighborList := b.s.getNeighbor("", true) - for _, n := range neighborList { - if n.State.SessionState != config.SESSION_STATE_ESTABLISHED { - continue - } - if err := write(bmpPeerStats(bmp.BMP_PEER_TYPE_GLOBAL, 0, time.Now().Unix(), n)); err != nil { - return false - } + var err error + b.s.ListPeer(context.Background(), &api.ListPeerRequest{EnableAdvertised: true}, + func(peer *api.Peer) { + if err == nil && peer.State.SessionState == api.PeerState_ESTABLISHED { + err = write(bmpPeerStats(bmp.BMP_PEER_TYPE_GLOBAL, 0, time.Now().Unix(), peer)) + } + }) + if err != nil { + return false } case <-b.dead: term := bmp.NewBMPTermination([]bmp.BMPTermTLVInterface{ @@ -292,16 +295,19 @@ func bmpPeerRoute(t uint8, policy bool, pd uint64, fourBytesAs bool, peeri *tabl return m } -func bmpPeerStats(peerType uint8, peerDist uint64, timestamp int64, neighConf *config.Neighbor) *bmp.BMPMessage { +func bmpPeerStats(peerType uint8, peerDist uint64, timestamp int64, peer *api.Peer) *bmp.BMPMessage { var peerFlags uint8 = 0 - ph := bmp.NewBMPPeerHeader(peerType, peerFlags, peerDist, neighConf.State.NeighborAddress, neighConf.State.PeerAs, neighConf.State.RemoteRouterId, float64(timestamp)) + ph := bmp.NewBMPPeerHeader(peerType, peerFlags, peerDist, peer.State.NeighborAddress, peer.State.PeerAs, peer.State.RouterId, float64(timestamp)) + accepted := uint64(0) + for _, a := range peer.AfiSafis { + accepted += a.State.Accepted + } return bmp.NewBMPStatisticsReport( *ph, []bmp.BMPStatsTLVInterface{ - bmp.NewBMPStatsTLV64(bmp.BMP_STAT_TYPE_ADJ_RIB_IN, uint64(neighConf.State.AdjTable.Accepted)), - bmp.NewBMPStatsTLV64(bmp.BMP_STAT_TYPE_LOC_RIB, uint64(neighConf.State.AdjTable.Advertised+neighConf.State.AdjTable.Filtered)), - bmp.NewBMPStatsTLV32(bmp.BMP_STAT_TYPE_WITHDRAW_UPDATE, neighConf.State.Messages.Received.WithdrawUpdate), - bmp.NewBMPStatsTLV32(bmp.BMP_STAT_TYPE_WITHDRAW_PREFIX, neighConf.State.Messages.Received.WithdrawPrefix), + bmp.NewBMPStatsTLV64(bmp.BMP_STAT_TYPE_ADJ_RIB_IN, accepted), + bmp.NewBMPStatsTLV32(bmp.BMP_STAT_TYPE_WITHDRAW_UPDATE, uint32(peer.State.Messages.Received.WithdrawUpdate)), + bmp.NewBMPStatsTLV32(bmp.BMP_STAT_TYPE_WITHDRAW_PREFIX, uint32(peer.State.Messages.Received.WithdrawPrefix)), }, ) } diff --git a/pkg/server/server.go b/pkg/server/server.go index 728214f5..1f103c12 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -2517,12 +2517,12 @@ func (s *BgpServer) ListPeer(ctx context.Context, r *api.ListPeerRequest, fn fun c := afisafi.Config if c.Family != nil && c.Family.Afi == api.Family_Afi(afi) && c.Family.Safi == api.Family_Safi(safi) { flist := []bgp.RouteFamily{family} - received := uint32(peer.adjRibIn.Count(flist)) - accepted := uint32(peer.adjRibIn.Accepted(flist)) - advertised := uint32(0) + received := uint64(peer.adjRibIn.Count(flist)) + accepted := uint64(peer.adjRibIn.Accepted(flist)) + advertised := uint64(0) if getAdvertised { pathList, _ := s.getBestFromLocal(peer, flist) - advertised = uint32(len(pathList)) + advertised = uint64(len(pathList)) } p.AfiSafis[i].State = &api.AfiSafiState{ Family: c.Family, |