From 7854b9a6c376aecb45f1c6837a1555808ec052a3 Mon Sep 17 00:00:00 2001 From: IWASE Yusuke Date: Wed, 24 May 2017 13:20:35 +0900 Subject: bmp: Support number of withdraw updates and prefixes This patch enables to send BMP statistics reports for the following types; - Stat Type = 11: (32-bit Counter) Number of updates subjected to treat-as-withdraw treatment. - Stat Type = 12: (32-bit Counter) Number of prefixes subjected to treat-as-withdraw treatment. Note: Currently, this implementation considers only updates or prefixes received from neighbors, but not enough to follow the handling process described in RFC7606. Signed-off-by: IWASE Yusuke --- server/bmp.go | 2 ++ server/fsm.go | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/server/bmp.go b/server/bmp.go index 16db2c55..4d76822b 100644 --- a/server/bmp.go +++ b/server/bmp.go @@ -295,6 +295,8 @@ func bmpPeerStats(peerType uint8, peerDist uint64, timestamp int64, neighConf *c []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), }, ) } diff --git a/server/fsm.go b/server/fsm.go index 6107f749..3817bd23 100644 --- a/server/fsm.go +++ b/server/fsm.go @@ -20,6 +20,7 @@ import ( "github.com/eapache/channels" "github.com/osrg/gobgp/config" "github.com/osrg/gobgp/packet/bgp" + "github.com/osrg/gobgp/packet/bmp" "github.com/osrg/gobgp/table" log "github.com/sirupsen/logrus" "gopkg.in/tomb.v2" @@ -182,6 +183,18 @@ func (fsm *FSM) bgpMessageStateUpdate(MessageType uint8, isIn bool) { } } +func (fsm *FSM) bmpStatsUpdate(statType uint16, increment int) { + stats := &fsm.pConf.State.Messages.Received + switch statType { + // TODO + // Support other stat types. + case bmp.BMP_STAT_TYPE_WITHDRAW_UPDATE: + stats.WithdrawUpdate += uint32(increment) + case bmp.BMP_STAT_TYPE_WITHDRAW_PREFIX: + stats.WithdrawPrefix += uint32(increment) + } +} + func NewFSM(gConf *config.Global, pConf *config.Neighbor, policy *table.RoutingPolicy) *FSM { adminState := ADMIN_STATE_UP if pConf.Config.AdminDown { @@ -712,6 +725,17 @@ func (h *FSMHandler) recvMessageWithError() (*FsmMsg, error) { return fmsg, err } + if routes := len(body.WithdrawnRoutes); routes > 0 { + h.fsm.bmpStatsUpdate(bmp.BMP_STAT_TYPE_WITHDRAW_UPDATE, 1) + h.fsm.bmpStatsUpdate(bmp.BMP_STAT_TYPE_WITHDRAW_PREFIX, routes) + } else if attr := getPathAttrFromBGPUpdate(body, bgp.BGP_ATTR_TYPE_MP_UNREACH_NLRI); attr != nil { + mpUnreach := attr.(*bgp.PathAttributeMpUnreachNLRI) + if routes = len(mpUnreach.Value); routes > 0 { + h.fsm.bmpStatsUpdate(bmp.BMP_STAT_TYPE_WITHDRAW_UPDATE, 1) + h.fsm.bmpStatsUpdate(bmp.BMP_STAT_TYPE_WITHDRAW_PREFIX, routes) + } + } + table.UpdatePathAttrs4ByteAs(body) if err = table.UpdatePathAggregator4ByteAs(body); err != nil { fmsg.MsgData = err -- cgit v1.2.3