diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-12-16 07:58:35 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-12-16 15:35:31 -0800 |
commit | c8a3caacf30fd28f4732de91c05e51f61eb15b99 (patch) | |
tree | 0181e413b220f6ac7e453f90d6a61cdab20d2b14 /server/bmp.go | |
parent | 2648b9bae2d02d268bbda01cf1b13be0d50157c3 (diff) |
bmp: support post-policy routing monitoring
"RouteMonitoringPolicy" option added:
0: pre-policy (by default)
1: post-policy
2: both
=
[BmpServers]
[[BmpServers.BmpServerList]]
[BmpServers.BmpServerList.BmpServerConfig]
Address = "127.0.0.1"
Port = 11019
RouteMonitoringPolicy = 2
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/bmp.go')
-rw-r--r-- | server/bmp.go | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/server/bmp.go b/server/bmp.go index 5384c3f6..9496236d 100644 --- a/server/bmp.go +++ b/server/bmp.go @@ -29,7 +29,6 @@ type broadcastBMPMsg struct { ch chan *broadcastBMPMsg msgList []*bgp.BMPMessage conn *net.TCPConn - addr string } func (m *broadcastBMPMsg) send() { @@ -38,7 +37,7 @@ func (m *broadcastBMPMsg) send() { type bmpConn struct { conn *net.TCPConn - addr string + host string } type bmpClient struct { @@ -55,16 +54,16 @@ func newBMPClient(conf config.BmpServers, connCh chan *bmpConn) (*bmpClient, err b.ch = make(chan *broadcastBMPMsg) b.connCh = connCh - tryConnect := func(addr string) { + tryConnect := func(host string) { for { - conn, err := net.Dial("tcp", addr) + conn, err := net.Dial("tcp", host) if err != nil { time.Sleep(30 * time.Second) } else { - log.Info("bmp server is connected, ", addr) + log.Info("bmp server is connected, ", host) connCh <- &bmpConn{ conn: conn.(*net.TCPConn), - addr: addr, + host: host, } break } @@ -86,21 +85,47 @@ func newBMPClient(conf config.BmpServers, connCh chan *bmpConn) (*bmpClient, err buf, _ := i.Serialize() _, err := m.conn.Write(buf) if err == nil { - connMap[m.addr] = m.conn + connMap[m.conn.RemoteAddr().String()] = m.conn } } - for addr, conn := range connMap { + for host, conn := range connMap { if m.conn != nil && m.conn != conn { continue } for _, msg := range m.msgList { + if msg.Header.Type == bgp.BMP_MSG_ROUTE_MONITORING { + c := func() *config.BmpServerConfig { + for _, c := range conf.BmpServerList { + b := &c.BmpServerConfig + if host == net.JoinHostPort(b.Address.String(), strconv.Itoa(int(b.Port))) { + return b + } + } + return nil + }() + if c == nil { + log.Fatal(host) + } + ph := msg.PeerHeader + switch c.RouteMonitoringPolicy { + case config.BMP_ROUTE_MONITORING_POLICY_TYPE_PRE_POLICY: + if ph.IsPostPolicy != false { + continue + } + case config.BMP_ROUTE_MONITORING_POLICY_TYPE_POST_POLICY: + if ph.IsPostPolicy != true { + continue + } + } + + } b, _ := msg.Serialize() _, err := conn.Write(b) if err != nil { - delete(connMap, addr) - go tryConnect(addr) + delete(connMap, host) + go tryConnect(host) break } } |