summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-12-30 17:39:13 +0900
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-01-09 22:43:01 +0900
commitf4c07da88154dd4b21012576a4ceb205715f4b3e (patch)
tree1c00c7ee3c5d439008291532c3b70e83ab230d74
parentda01fa48af05820d8b8731379cf647be049be503 (diff)
server: add REQ_BMP_NEIGHBORS api for internal bmp use
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--packet/bmp.go2
-rw-r--r--server/bmp.go14
-rw-r--r--server/grpc_server.go1
-rw-r--r--server/server.go20
4 files changed, 28 insertions, 9 deletions
diff --git a/packet/bmp.go b/packet/bmp.go
index 82f93da9..1cb49200 100644
--- a/packet/bmp.go
+++ b/packet/bmp.go
@@ -39,7 +39,7 @@ const (
)
const (
- BMP_PEER_TYPE_GLOBAL = iota
+ BMP_PEER_TYPE_GLOBAL uint8 = iota
BMP_PEER_TYPE_L3VPN
)
diff --git a/server/bmp.go b/server/bmp.go
index 86029983..3d8b50f6 100644
--- a/server/bmp.go
+++ b/server/bmp.go
@@ -35,7 +35,7 @@ func (m *broadcastBMPMsg) send() {
m.ch <- m
}
-type bmpConn struct {
+type bmpServer struct {
conn *net.TCPConn
host string
}
@@ -160,18 +160,18 @@ func (c *bmpClient) send() chan *broadcastBMPMsg {
return c.ch
}
-func bmpPeerUp(laddr string, lport, rport uint16, sent, recv *bgp.BGPMessage, t int, policy bool, pd uint64, peeri *table.PeerInfo, timestamp int64) *bgp.BMPMessage {
- ph := bgp.NewBMPPeerHeader(uint8(t), policy, pd, peeri.Address.String(), peeri.AS, peeri.LocalID.String(), float64(timestamp))
+func bmpPeerUp(laddr string, lport, rport uint16, sent, recv *bgp.BGPMessage, t uint8, policy bool, pd uint64, peeri *table.PeerInfo, timestamp int64) *bgp.BMPMessage {
+ ph := bgp.NewBMPPeerHeader(t, policy, pd, peeri.Address.String(), peeri.AS, peeri.ID.String(), float64(timestamp))
return bgp.NewBMPPeerUpNotification(*ph, laddr, lport, rport, sent, recv)
}
-func bmpPeerDown(reason uint8, t int, policy bool, pd uint64, peeri *table.PeerInfo, timestamp int64) *bgp.BMPMessage {
- ph := bgp.NewBMPPeerHeader(uint8(t), policy, pd, peeri.Address.String(), peeri.AS, peeri.LocalID.String(), float64(timestamp))
+func bmpPeerDown(reason uint8, t uint8, policy bool, pd uint64, peeri *table.PeerInfo, timestamp int64) *bgp.BMPMessage {
+ ph := bgp.NewBMPPeerHeader(t, policy, pd, peeri.Address.String(), peeri.AS, peeri.ID.String(), float64(timestamp))
return bgp.NewBMPPeerDownNotification(*ph, reason, nil, []byte{})
}
-func bmpPeerRoute(t int, policy bool, pd uint64, peeri *table.PeerInfo, timestamp int64, payload []byte) *bgp.BMPMessage {
- ph := bgp.NewBMPPeerHeader(uint8(t), policy, pd, peeri.Address.String(), peeri.AS, peeri.LocalID.String(), float64(timestamp))
+func bmpPeerRoute(t uint8, policy bool, pd uint64, peeri *table.PeerInfo, timestamp int64, payload []byte) *bgp.BMPMessage {
+ ph := bgp.NewBMPPeerHeader(t, policy, pd, peeri.Address.String(), peeri.AS, peeri.ID.String(), float64(timestamp))
m := bgp.NewBMPRouteMonitoring(*ph, nil)
body := m.Body.(*bgp.BMPRouteMonitoring)
body.BGPUpdatePayload = payload
diff --git a/server/grpc_server.go b/server/grpc_server.go
index 212e9842..63d6e1ad 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -66,6 +66,7 @@ const (
REQ_MOD_POLICY
REQ_POLICY_ASSIGNMENT
REQ_MOD_POLICY_ASSIGNMENT
+ REQ_BMP_NEIGHBORS
)
type Server struct {
diff --git a/server/server.go b/server/server.go
index 71eefced..8de474a2 100644
--- a/server/server.go
+++ b/server/server.go
@@ -1658,7 +1658,25 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
i++
}
go sendMultipleResponses(grpcReq, results)
-
+ case REQ_BMP_NEIGHBORS:
+ //TODO: merge REQ_NEIGHBORS and REQ_BMP_NEIGHBORS
+ msgs := make([]*bgp.BMPMessage, 0, len(server.neighborMap))
+ for _, peer := range server.neighborMap {
+ if peer.fsm.state != bgp.BGP_FSM_ESTABLISHED {
+ continue
+ }
+ laddr, lport := peer.fsm.LocalHostPort()
+ _, rport := peer.fsm.RemoteHostPort()
+ sentOpen := buildopen(peer.fsm.gConf, peer.fsm.pConf)
+ info := peer.fsm.peerInfo
+ timestamp := peer.conf.Timers.State.Uptime
+ msg := bmpPeerUp(laddr, lport, rport, sentOpen, peer.recvOpen, bgp.BMP_PEER_TYPE_GLOBAL, false, 0, info, timestamp)
+ msgs = append(msgs, msg)
+ }
+ grpcReq.ResponseCh <- &GrpcResponse{
+ Data: msgs,
+ }
+ close(grpcReq.ResponseCh)
case REQ_NEIGHBOR:
peer, err := server.checkNeighborRequest(grpcReq)
if err != nil {