summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-12-02 16:01:47 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-12-02 16:02:21 +0900
commita36c84c510bd7cde344e6cbabd043153e4a0196c (patch)
treec9a529ea365def97af86cd5aba6d315aed6671ab /server
parentb83d3cc802cdaa69b8c77b6db54aa8fe4e472ba7 (diff)
make adj-rib implementation more clear and efficient
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r--server/peer.go61
-rw-r--r--server/server.go23
2 files changed, 33 insertions, 51 deletions
diff --git a/server/peer.go b/server/peer.go
index ac3c2409..8f43299e 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -37,28 +37,29 @@ type Peer struct {
fsm *FSM
rfMap map[bgp.RouteFamily]bool
capMap map[bgp.BGPCapabilityCode][]bgp.ParameterCapabilityInterface
- adjRib *table.AdjRib
+ adjRibIn *table.AdjRib
+ adjRibOut *table.AdjRib
outgoing chan *bgp.BGPMessage
inPolicies []*table.Policy
defaultInPolicy table.RouteType
- accepted uint32
- staleAccepted bool
recvOpen *bgp.BGPMessage
localRib *table.TableManager
}
func NewPeer(g config.Global, conf config.Neighbor, loc *table.TableManager) *Peer {
+ rfs, _ := conf.AfiSafis.ToRfList()
peer := &Peer{
- gConf: g,
- conf: conf,
- rfMap: make(map[bgp.RouteFamily]bool),
- capMap: make(map[bgp.BGPCapabilityCode][]bgp.ParameterCapabilityInterface),
- outgoing: make(chan *bgp.BGPMessage, 128),
- localRib: loc,
+ gConf: g,
+ conf: conf,
+ rfMap: make(map[bgp.RouteFamily]bool),
+ capMap: make(map[bgp.BGPCapabilityCode][]bgp.ParameterCapabilityInterface),
+ outgoing: make(chan *bgp.BGPMessage, 128),
+ adjRibIn: table.NewAdjRib(rfs),
+ adjRibOut: table.NewAdjRib(rfs),
+ localRib: loc,
}
conf.NeighborState.SessionState = uint32(bgp.BGP_FSM_IDLE)
conf.Timers.TimersState.Downtime = time.Now().Unix()
- peer.adjRib = table.NewAdjRib(peer.configuredRFlist())
peer.fsm = NewFSM(&g, &conf, peer)
return peer
}
@@ -84,22 +85,12 @@ func (peer *Peer) isRouteReflectorClient() bool {
}
func (peer *Peer) configuredRFlist() []bgp.RouteFamily {
- return peer.localRib.GetRFlist()
-}
-
-func (peer *Peer) updateAccepted(accepted uint32) {
- peer.accepted = accepted
- peer.staleAccepted = false
+ rfs, _ := peer.conf.AfiSafis.ToRfList()
+ return rfs
}
func (peer *Peer) getAccepted(rfList []bgp.RouteFamily) []*table.Path {
- var pathList []*table.Path
- for _, path := range peer.adjRib.GetInPathList(rfList) {
- if path.Filtered == false {
- pathList = append(pathList, path)
- }
- }
- return pathList
+ return peer.adjRibIn.PathList(rfList, true)
}
func (peer *Peer) getBestFromLocal(rfList []bgp.RouteFamily) ([]*table.Path, []*table.Path) {
@@ -184,9 +175,9 @@ func (peer *Peer) handleBGPmessage(e *FsmMsg) ([]*table.Path, bool, []*bgp.BGPMe
}
if _, ok := peer.capMap[bgp.BGP_CAP_ROUTE_REFRESH]; ok {
rfList := []bgp.RouteFamily{rf}
- peer.adjRib.DropOut(rfList)
+ peer.adjRibOut.Drop(rfList)
accepted, filtered := peer.getBestFromLocal(rfList)
- peer.adjRib.UpdateOut(accepted)
+ peer.adjRibOut.Update(accepted)
pathList = append(pathList, accepted...)
for _, path := range filtered {
path.IsWithdraw = true
@@ -203,9 +194,8 @@ func (peer *Peer) handleBGPmessage(e *FsmMsg) ([]*table.Path, bool, []*bgp.BGPMe
update = true
peer.conf.Timers.TimersState.UpdateRecvTime = time.Now().Unix()
if len(e.PathList) > 0 {
+ peer.adjRibIn.Update(e.PathList)
pathList = e.PathList
- peer.staleAccepted = true
- peer.adjRib.UpdateIn(pathList)
}
case bgp.BGP_MSG_NOTIFICATION:
body := m.Body.(*bgp.BGPNotification)
@@ -284,14 +274,9 @@ func (peer *Peer) ToApiStruct() *api.Peer {
accepted := uint32(0)
if f.state == bgp.BGP_FSM_ESTABLISHED {
rfList := peer.configuredRFlist()
- advertized = uint32(peer.adjRib.GetOutCount(rfList))
- received = uint32(peer.adjRib.GetInCount(rfList))
- if peer.staleAccepted {
- accepted = uint32(len(peer.getAccepted(rfList)))
- peer.updateAccepted(accepted)
- } else {
- accepted = peer.accepted
- }
+ advertized = uint32(peer.adjRibOut.Count(rfList))
+ received = uint32(peer.adjRibIn.Count(rfList))
+ accepted = uint32(peer.adjRibIn.Accepted(rfList))
}
uptime := int64(0)
@@ -448,8 +433,6 @@ func (peer *Peer) ApplyPolicy(d table.PolicyDirection, paths []*table.Path) ([]*
}
func (peer *Peer) DropAll(rfList []bgp.RouteFamily) {
- peer.adjRib.DropIn(rfList)
- peer.adjRib.DropOut(rfList)
- peer.staleAccepted = false
- peer.accepted = 0
+ peer.adjRibIn.Drop(rfList)
+ peer.adjRibOut.Drop(rfList)
}
diff --git a/server/server.go b/server/server.go
index 3bd4b448..a09b7d02 100644
--- a/server/server.go
+++ b/server/server.go
@@ -329,7 +329,7 @@ func (server *BgpServer) Serve() {
if targetPeer.fsm.state != bgp.BGP_FSM_ESTABLISHED {
continue
}
- for _, p := range targetPeer.adjRib.GetInPathList(targetPeer.configuredRFlist()) {
+ for _, p := range targetPeer.adjRibIn.PathList(targetPeer.configuredRFlist(), false) {
// avoid to merge for timestamp
u := table.CreateUpdateMsgFromPaths([]*table.Path{p})
buf, _ := u[0].Serialize()
@@ -560,7 +560,7 @@ func (server *BgpServer) dropPeerAllRoutes(peer *Peer) []*SenderMsg {
}
msgList := table.CreateUpdateMsgFromPaths(pathList)
msgs = append(msgs, newSenderMsg(targetPeer, msgList))
- targetPeer.adjRib.UpdateOut(pathList)
+ targetPeer.adjRibOut.Update(pathList)
}
} else {
rib := server.globalRib
@@ -579,7 +579,7 @@ func (server *BgpServer) dropPeerAllRoutes(peer *Peer) []*SenderMsg {
if _, ok := targetPeer.rfMap[rf]; !ok {
continue
}
- targetPeer.adjRib.UpdateOut(pathList)
+ targetPeer.adjRibOut.Update(pathList)
msgs = append(msgs, newSenderMsg(targetPeer, msgList))
}
}
@@ -678,7 +678,7 @@ func (server *BgpServer) propagateUpdate(peer *Peer, pathList []*table.Path) []*
continue
}
msgList := table.CreateUpdateMsgFromPaths(sendPathList)
- targetPeer.adjRib.UpdateOut(sendPathList)
+ targetPeer.adjRibOut.Update(sendPathList)
msgs = append(msgs, newSenderMsg(targetPeer, msgList))
}
} else {
@@ -702,9 +702,8 @@ func (server *BgpServer) propagateUpdate(peer *Peer, pathList []*table.Path) []*
for _, path := range f {
path.UpdatePathAttrs(&server.bgpConfig.Global, &targetPeer.conf)
}
- targetPeer.adjRib.UpdateOut(f)
+ targetPeer.adjRibOut.Update(f)
msgList := table.CreateUpdateMsgFromPaths(f)
-
msgs = append(msgs, newSenderMsg(targetPeer, msgList))
}
}
@@ -755,7 +754,7 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *FsmMsg, incoming chan *
}
pathList, _ := peer.getBestFromLocal(peer.configuredRFlist())
if len(pathList) > 0 {
- peer.adjRib.UpdateOut(pathList)
+ peer.adjRibOut.Update(pathList)
msgs = append(msgs, newSenderMsg(peer, table.CreateUpdateMsgFromPaths(pathList)))
}
} else {
@@ -1517,10 +1516,10 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
rf := bgp.RouteFamily(arg.Family)
var paths []*table.Path
if grpcReq.RequestType == REQ_ADJ_RIB_IN {
- paths = peer.adjRib.GetInPathList([]bgp.RouteFamily{rf})
+ paths = peer.adjRibIn.PathList([]bgp.RouteFamily{rf}, false)
log.Debugf("RouteFamily=%v adj-rib-in found : %d", rf.String(), len(paths))
} else {
- paths = peer.adjRib.GetOutPathList([]bgp.RouteFamily{rf})
+ paths = peer.adjRibOut.PathList([]bgp.RouteFamily{rf}, false)
log.Debugf("RouteFamily=%v adj-rib-out found : %d", rf.String(), len(paths))
}
@@ -1602,7 +1601,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
}
for _, peer := range peers {
- pathList := peer.adjRib.GetInPathList([]bgp.RouteFamily{grpcReq.RouteFamily})
+ pathList := peer.adjRibIn.PathList([]bgp.RouteFamily{grpcReq.RouteFamily}, false)
if peer.isRouteServerClient() {
pathList, _ = peer.ApplyPolicy(table.POLICY_DIRECTION_IN, pathList)
}
@@ -1625,10 +1624,10 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
}
for _, peer := range peers {
rfList := peer.configuredRFlist()
- peer.adjRib.DropOut(rfList)
+ peer.adjRibOut.Drop(rfList)
pathList, filtered := peer.getBestFromLocal(rfList)
if len(pathList) > 0 {
- peer.adjRib.UpdateOut(pathList)
+ peer.adjRibOut.Update(pathList)
msgs = append(msgs, newSenderMsg(peer, table.CreateUpdateMsgFromPaths(pathList)))
}
if len(filtered) > 0 {