diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-03-10 01:09:30 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-03-10 01:09:30 +0900 |
commit | 27a1609aca0a448edf43afc149c5d863abf3b04a (patch) | |
tree | 177599fedc3c3c58494d64ee780088687f63aa23 /server | |
parent | 564cbd963887f8cc8d91d9c28371e06e059caea0 (diff) |
server: add helper function to send paths to siblings
kill duplicated code.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r-- | server/peer.go | 45 |
1 files changed, 16 insertions, 29 deletions
diff --git a/server/peer.go b/server/peer.go index 447920c2..2efceeac 100644 --- a/server/peer.go +++ b/server/peer.go @@ -106,6 +106,19 @@ func (peer *Peer) configuredRFlist() []bgp.RouteFamily { return rfList } +func (peer *Peer) sendPathsToSiblings(pathList []table.Path) { + if len(pathList) == 0 { + return + } + pm := &peerMsg{ + msgType: PEER_MSG_PATH, + msgData: pathList, + } + for _, s := range peer.siblings { + s.peerMsgCh <- pm + } +} + func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) { log.WithFields(log.Fields{ "Topic": "Peer", @@ -194,17 +207,8 @@ func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) { table.UpdatePathAttrs4ByteAs(body) msg := table.NewProcessMessage(m, peer.peerInfo) pathList := msg.ToPathList() - if len(pathList) == 0 { - return - } peer.adjRib.UpdateIn(pathList) - pm := &peerMsg{ - msgType: PEER_MSG_PATH, - msgData: pathList, - } - for _, s := range peer.siblings { - s.peerMsgCh <- pm - } + peer.sendPathsToSiblings(pathList) } } @@ -251,14 +255,7 @@ func (peer *Peer) handleREST(restReq *api.RestRequest) { peer.outgoing <- bgp.NewBGPNotificationMessage(bgp.BGP_ERROR_CEASE, bgp.BGP_ERROR_SUB_ADMINISTRATIVE_RESET, nil) case api.REQ_NEIGHBOR_SOFT_RESET, api.REQ_NEIGHBOR_SOFT_RESET_IN: // soft-reconfiguration inbound - pathList := peer.adjRib.GetInPathList(restReq.RouteFamily) - pm := &peerMsg{ - msgType: PEER_MSG_PATH, - msgData: pathList, - } - for _, s := range peer.siblings { - s.peerMsgCh <- pm - } + peer.sendPathsToSiblings(peer.adjRib.GetInPathList(restReq.RouteFamily)) if restReq.RequestType == api.REQ_NEIGHBOR_SOFT_RESET_IN { break } @@ -352,17 +349,7 @@ func (peer *Peer) handleServerMsg(m *serverMsg) { d := m.msgData.(*serverMsgDataPeer) peer.siblings[d.address.String()] = d for _, rf := range peer.configuredRFlist() { - pathList := peer.adjRib.GetInPathList(rf) - if len(pathList) == 0 { - continue - } - pm := &peerMsg{ - msgType: PEER_MSG_PATH, - msgData: pathList, - } - for _, s := range peer.siblings { - s.peerMsgCh <- pm - } + peer.sendPathsToSiblings(peer.adjRib.GetInPathList(rf)) } case SRV_MSG_PEER_DELETED: d := m.msgData.(*table.PeerInfo) |