summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-05-18 13:33:15 +0900
committerIWASE Yusuke <iwase.yusuke0@gmail.com>2017-05-22 13:14:07 +0900
commitb42dec119506e651d98047add481da3467405fec (patch)
tree6d4ea638a36e1625a6436aa7a651d49083ad1ae3 /server
parent76ba8fcbda9480f9356d1733799974771f0280b0 (diff)
bmp: Stats reports for Adj-RIBs-In and Loc-RIB routes
This patch enable to send BMP statistics reports for the following types; - Stat Type = 7: Number of routes in Adj-RIBs-In = Regarding number of "accepted" routes in AdjTable state - Stat Type = 8: Number of routes in Loc-RIB = Regarding number of "advertised" and "filtered" routes in AdjTable state which means the all routes selected by the local BGP speaker's Decision Process. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'server')
-rw-r--r--server/bmp.go43
1 files changed, 37 insertions, 6 deletions
diff --git a/server/bmp.go b/server/bmp.go
index df98ab66..1d97104f 100644
--- a/server/bmp.go
+++ b/server/bmp.go
@@ -113,23 +113,32 @@ func (b *bmpClient) loop() {
if func() bool {
ops := []WatchOption{WatchPeerState(true)}
- if b.typ == config.BMP_ROUTE_MONITORING_POLICY_TYPE_BOTH {
+ if b.c.RouteMonitoringPolicy == config.BMP_ROUTE_MONITORING_POLICY_TYPE_BOTH {
log.WithFields(
log.Fields{"Topic": "bmp"},
).Warn("both option for route-monitoring-policy is obsoleted")
}
- if b.typ == config.BMP_ROUTE_MONITORING_POLICY_TYPE_PRE_POLICY || b.typ == config.BMP_ROUTE_MONITORING_POLICY_TYPE_ALL {
+ if b.c.RouteMonitoringPolicy == config.BMP_ROUTE_MONITORING_POLICY_TYPE_PRE_POLICY || b.c.RouteMonitoringPolicy == config.BMP_ROUTE_MONITORING_POLICY_TYPE_ALL {
ops = append(ops, WatchUpdate(true))
}
- if b.typ == config.BMP_ROUTE_MONITORING_POLICY_TYPE_POST_POLICY || b.typ == config.BMP_ROUTE_MONITORING_POLICY_TYPE_ALL {
+ if b.c.RouteMonitoringPolicy == config.BMP_ROUTE_MONITORING_POLICY_TYPE_POST_POLICY || b.c.RouteMonitoringPolicy == config.BMP_ROUTE_MONITORING_POLICY_TYPE_ALL {
ops = append(ops, WatchPostUpdate(true))
}
- if b.typ == config.BMP_ROUTE_MONITORING_POLICY_TYPE_LOCAL_RIB || b.typ == config.BMP_ROUTE_MONITORING_POLICY_TYPE_ALL {
+ if b.c.RouteMonitoringPolicy == config.BMP_ROUTE_MONITORING_POLICY_TYPE_LOCAL_RIB || b.c.RouteMonitoringPolicy == config.BMP_ROUTE_MONITORING_POLICY_TYPE_ALL {
ops = append(ops, WatchBestPath(true))
}
w := b.s.Watch(ops...)
defer w.Stop()
+ var tickerCh <-chan time.Time
+ if b.c.StatisticsTimeout == 0 {
+ log.WithFields(log.Fields{"Topic": "bmp"}).Debug("statistics reports disabled")
+ } else {
+ t := time.NewTicker(time.Duration(b.c.StatisticsTimeout) * time.Second)
+ defer t.Stop()
+ tickerCh = t.C
+ }
+
write := func(msg *bmp.BMPMessage) error {
buf, _ := msg.Serialize()
_, err := conn.Write(buf)
@@ -201,6 +210,16 @@ 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, 0, n)); err != nil {
+ return false
+ }
+ }
case <-b.dead:
conn.Close()
return true
@@ -216,7 +235,7 @@ type bmpClient struct {
s *BgpServer
dead chan struct{}
host string
- typ config.BmpRouteMonitoringPolicyType
+ c *config.BmpServerConfig
ribout ribout
}
@@ -250,6 +269,18 @@ func bmpPeerRoute(t uint8, policy bool, pd uint64, peeri *table.PeerInfo, timest
return m
}
+func bmpPeerStats(peerType uint8, peerDist uint64, timestamp int64, neighConf *config.Neighbor) *bmp.BMPMessage {
+ var peerFlags uint8 = 0
+ ph := bmp.NewBMPPeerHeader(peerType, peerFlags, peerDist, neighConf.Config.NeighborAddress, neighConf.State.PeerAs, neighConf.State.RemoteRouterId, float64(timestamp))
+ 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)),
+ },
+ )
+}
+
func (b *bmpClientManager) addServer(c *config.BmpServerConfig) error {
host := net.JoinHostPort(c.Address, strconv.Itoa(int(c.Port)))
if _, y := b.clientMap[host]; y {
@@ -259,7 +290,7 @@ func (b *bmpClientManager) addServer(c *config.BmpServerConfig) error {
s: b.s,
dead: make(chan struct{}),
host: host,
- typ: c.RouteMonitoringPolicy,
+ c: c,
ribout: newribout(),
}
go b.clientMap[host].loop()