diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-31 23:18:04 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-31 23:18:04 +0900 |
commit | 3f324d55bd3cc6dca6612ad582624d2933dc6b10 (patch) | |
tree | f52980474876f030ffb520b6194046aff9d21b85 /server/peer.go | |
parent | 04f90d2087d3a0741527d5ee111f7a3900e0687b (diff) |
server: merge bgp update messages if possible
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/peer.go')
-rw-r--r-- | server/peer.go | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/server/peer.go b/server/peer.go index 8379d079..35fc3d90 100644 --- a/server/peer.go +++ b/server/peer.go @@ -89,7 +89,7 @@ func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) { case bgp.BGP_MSG_ROUTE_REFRESH: pathList := peer.adjRib.GetOutPathList(peer.rf) - peer.sendMessages(peer.path2update(pathList)) + peer.sendMessages(table.CreateUpdateMsgFromPaths(pathList)) case bgp.BGP_MSG_UPDATE: peer.peerConfig.BgpNeighborCommonState.UpdateRecvTime = time.Now() body := m.Body.(*bgp.BGPUpdate) @@ -106,31 +106,24 @@ func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) { func (peer *Peer) sendMessages(msgs []*bgp.BGPMessage) { for _, m := range msgs { - if m.Header.Type == bgp.BGP_MSG_UPDATE { - _, y := peer.capMap[bgp.BGP_CAP_FOUR_OCTET_AS_NUMBER] - if !y { - log.Debug("update BGPUpdate for 2byte AS peer, ", peer.peerConfig.NeighborAddress.String()) - table.UpdatePathAttrs2ByteAs(m.Body.(*bgp.BGPUpdate)) - } + // FIXME: there is race where state change + // (established) event arrived before open message + if peer.peerConfig.BgpNeighborCommonState.State != uint32(bgp.BGP_FSM_ESTABLISHED) { + continue } - peer.outgoing <- m - } -} -func (peer *Peer) path2update(pathList []table.Path) []*bgp.BGPMessage { - msgs := make([]*bgp.BGPMessage, 0) - var pMsg *bgp.BGPMessage - for _, p := range pathList { - if peer.rf != p.GetRouteFamily() { - continue + if m.Header.Type != bgp.BGP_MSG_UPDATE { + log.Fatal("not update message ", m.Header.Type) } - msg, _ := table.CreateUpdateMsgFromPath(p, pMsg) - if msg != nil { - msgs = append(msgs, msg) - pMsg = msg + + _, y := peer.capMap[bgp.BGP_CAP_FOUR_OCTET_AS_NUMBER] + if !y { + log.Debug("update BGPUpdate for 2byte AS peer, ", peer.peerConfig.NeighborAddress.String()) + table.UpdatePathAttrs2ByteAs(m.Body.(*bgp.BGPUpdate)) } + + peer.outgoing <- m } - return msgs } func (peer *Peer) handleREST(restReq *api.RestRequest) { @@ -152,7 +145,7 @@ func (peer *Peer) handlePeermessage(m *message) { } } peer.adjRib.UpdateOut(pathList) - peer.sendMessages(peer.path2update(pathList)) + peer.sendMessages(table.CreateUpdateMsgFromPaths(pathList)) } switch m.event { @@ -183,7 +176,7 @@ func (peer *Peer) loop() error { sameState = false if nextState == bgp.BGP_FSM_ESTABLISHED { pathList := peer.adjRib.GetOutPathList(peer.rf) - peer.sendMessages(peer.path2update(pathList)) + peer.sendMessages(table.CreateUpdateMsgFromPaths(pathList)) peer.fsm.peerConfig.BgpNeighborCommonState.Uptime = time.Now() peer.fsm.peerConfig.BgpNeighborCommonState.EstablishedCount++ } |