diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-09-30 14:56:42 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-09-30 15:29:08 +0900 |
commit | eaa7810893c10d2768e61306e38859e80da01111 (patch) | |
tree | 0bddb983624da1f10711c6529b0fd01773e02a53 /server | |
parent | c81fad9103e7bda297590040befbbce25f351d53 (diff) |
server: kill LocalRib
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r-- | server/peer.go | 169 | ||||
-rw-r--r-- | server/server.go | 184 |
2 files changed, 117 insertions, 236 deletions
diff --git a/server/peer.go b/server/peer.go index 2d3b4083..3b0bd44b 100644 --- a/server/peer.go +++ b/server/peer.go @@ -43,6 +43,10 @@ type Peer struct { outgoing chan *bgp.BGPMessage inPolicies []*policy.Policy defaultInPolicy config.DefaultPolicyType + importPolicies []*policy.Policy + defaultImportPolicy config.DefaultPolicyType + exportPolicies []*policy.Policy + defaultExportPolicy config.DefaultPolicyType isConfederationMember bool recvOpen *bgp.BGPMessage } @@ -213,10 +217,10 @@ func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) ([]*table.Path, bool, []*b return pathList, update, bgpMsgList } -func (peer *Peer) getBests(loc *LocalRib) []*table.Path { +func (peer *Peer) getBests(rib *table.TableManager) []*table.Path { pathList := []*table.Path{} for _, rf := range peer.configuredRFlist() { - for _, paths := range loc.rib.GetBestPathList(rf) { + for _, paths := range rib.GetBestPathList(rf) { pathList = append(pathList, paths) } } @@ -293,13 +297,7 @@ func (peer *Peer) ToApiStruct() *api.Peer { advertized += uint32(peer.adjRib.GetOutCount(rf)) received += uint32(peer.adjRib.GetInCount(rf)) // FIXME: we should store 'accepted' in memory - for _, p := range peer.adjRib.GetInPathList(rf) { - applied, path := peer.applyPolicies(POLICY_DIRECTION_IN, p) - if applied && path == nil || !applied && peer.defaultInPolicy != config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE { - continue - } - accepted += 1 - } + accepted += uint32(len(peer.ApplyPolicy(POLICY_DIRECTION_IN, peer.adjRib.GetInPathList(rf)))) } } @@ -364,43 +362,8 @@ func (peer *Peer) setPolicy(policyMap map[string]*policy.Policy) { } peer.inPolicies = inPolicies peer.defaultInPolicy = policyConf.ApplyPolicyConfig.DefaultInPolicy -} -func (peer *Peer) applyPolicies(d Direction, original *table.Path) (bool, *table.Path) { - var policies []*policy.Policy - switch d { - case POLICY_DIRECTION_IN: - policies = peer.inPolicies - } - return applyPolicy("Peer", peer.conf.NeighborConfig.NeighborAddress.String(), d, policies, original) -} - -type LocalRib struct { - rib *table.TableManager - importPolicies []*policy.Policy - defaultImportPolicy config.DefaultPolicyType - exportPolicies []*policy.Policy - defaultExportPolicy config.DefaultPolicyType -} - -func NewLocalRib(owner string, rfList []bgp.RouteFamily, minLabel, maxLabel uint32) *LocalRib { - return &LocalRib{ - rib: table.NewTableManager(owner, rfList, minLabel, maxLabel), - } -} - -func (loc *LocalRib) OwnerName() string { - return loc.rib.OwnerName() -} - -func (loc *LocalRib) isGlobal() bool { - return loc.OwnerName() == "global" -} - -func (loc *LocalRib) setPolicy(peer *Peer, policyMap map[string]*policy.Policy) { - // configure import policy - policyConf := peer.conf.ApplyPolicy - inPolicies := make([]*policy.Policy, 0) + importPolicies := make([]*policy.Policy, 0) for _, policyName := range policyConf.ApplyPolicyConfig.ImportPolicy { log.WithFields(log.Fields{ "Topic": "Peer", @@ -409,14 +372,14 @@ func (loc *LocalRib) setPolicy(peer *Peer, policyMap map[string]*policy.Policy) }).Info("import policy installed") if pol, ok := policyMap[policyName]; ok { log.Debug("import policy : ", pol) - inPolicies = append(inPolicies, pol) + importPolicies = append(importPolicies, pol) } } - loc.importPolicies = inPolicies - loc.defaultImportPolicy = policyConf.ApplyPolicyConfig.DefaultImportPolicy + peer.importPolicies = importPolicies + peer.defaultImportPolicy = policyConf.ApplyPolicyConfig.DefaultImportPolicy // configure export policy - outPolicies := make([]*policy.Policy, 0) + exportPolicies := make([]*policy.Policy, 0) for _, policyName := range policyConf.ApplyPolicyConfig.ExportPolicy { log.WithFields(log.Fields{ "Topic": "Peer", @@ -425,73 +388,69 @@ func (loc *LocalRib) setPolicy(peer *Peer, policyMap map[string]*policy.Policy) }).Info("export policy installed") if pol, ok := policyMap[policyName]; ok { log.Debug("export policy : ", pol) - outPolicies = append(outPolicies, pol) + exportPolicies = append(exportPolicies, pol) } } - loc.exportPolicies = outPolicies - loc.defaultExportPolicy = policyConf.ApplyPolicyConfig.DefaultExportPolicy + peer.exportPolicies = exportPolicies + peer.defaultExportPolicy = policyConf.ApplyPolicyConfig.DefaultExportPolicy } -// apply policies to the path -// if multiple policies are defined, -// this function applies each policy to the path in the order that -// policies are stored in the array passed to this function. -// -// the way of applying statements inside a single policy -// - apply statement until the condition in the statement matches. -// if the condition matches the path, apply the action on the statement and -// return value that indicates 'applied' to caller of this function -// - if no statement applied, then process the next policy -// -// if no policy applied, return value that indicates 'not applied' to the caller of this function -// -// return values: -// bool -- indicates that any of policy applied to the path that is passed to this function -// table.Path -- indicates new path object that is the result of modification according to -// policy's action. -// If the applied policy doesn't have a modification action, -// then return the path itself that is passed to this function, otherwise return -// modified path. -// If action of the policy is 'reject', return nil -// -func (loc *LocalRib) applyPolicies(d Direction, original *table.Path) (bool, *table.Path) { - var policies []*policy.Policy +func (peer *Peer) GetPolicy(d PolicyDirection) []*policy.Policy { switch d { + case POLICY_DIRECTION_IN: + return peer.inPolicies + case POLICY_DIRECTION_IMPORT: + return peer.importPolicies case POLICY_DIRECTION_EXPORT: - policies = loc.exportPolicies + return peer.exportPolicies + } + return nil +} + +func (peer *Peer) GetDefaultPolicy(d PolicyDirection) policy.RouteType { + var def config.DefaultPolicyType + switch d { + case POLICY_DIRECTION_IN: + def = peer.defaultInPolicy case POLICY_DIRECTION_IMPORT: - policies = loc.importPolicies + def = peer.defaultImportPolicy + case POLICY_DIRECTION_EXPORT: + def = peer.defaultExportPolicy } - return applyPolicy("Loc", loc.OwnerName(), d, policies, original) + + if def == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE { + return policy.ROUTE_TYPE_ACCEPT + } + return policy.ROUTE_TYPE_REJECT } -func applyPolicy(component, owner string, d Direction, policies []*policy.Policy, original *table.Path) (bool, *table.Path) { - var applied bool = true - for _, pol := range policies { - if result, action, newpath := pol.Apply(original); result { - log.Debug("newpath: ", newpath) - if action == policy.ROUTE_TYPE_REJECT { - log.WithFields(log.Fields{ - "Topic": component, - "Key": owner, - "NLRI": original.GetNlri(), - "Dir": d, - }).Debug("path was rejected") - // return applied, nil, this means path was rejected - return applied, nil - } else { - // return applied, new path - return applied, newpath +func (peer *Peer) ApplyPolicy(d PolicyDirection, paths []*table.Path) []*table.Path { + newpaths := make([]*table.Path, 0, len(paths)) + for _, path := range paths { + result := policy.ROUTE_TYPE_NONE + newpath := path + for _, p := range peer.GetPolicy(d) { + result, newpath = p.Apply(path) + if result != policy.ROUTE_TYPE_NONE { + break } } - } - log.WithFields(log.Fields{ - "Topic": component, - "Key": owner, - "Len": len(policies), - "NLRI": original, - "Dir": d, - }).Debug("no policy applied") - return !applied, original + if result == policy.ROUTE_TYPE_NONE { + result = peer.GetDefaultPolicy(d) + } + + switch result { + case policy.ROUTE_TYPE_ACCEPT: + newpaths = append(newpaths, newpath) + case policy.ROUTE_TYPE_REJECT: + log.WithFields(log.Fields{ + "Topic": "Peer", + "Key": peer.conf.NeighborConfig.NeighborAddress, + "Path": path, + "Direction": d, + }).Debug("reject") + } + } + return newpaths } diff --git a/server/server.go b/server/server.go index a989e48d..9d444a32 100644 --- a/server/server.go +++ b/server/server.go @@ -37,12 +37,12 @@ const ( GLOBAL_RIB_NAME = "global" ) -type Direction string +type PolicyDirection int const ( - POLICY_DIRECTION_IMPORT Direction = "import" - POLICY_DIRECTION_EXPORT = "export" - POLICY_DIRECTION_IN = "in" + POLICY_DIRECTION_IMPORT PolicyDirection = iota + POLICY_DIRECTION_EXPORT + POLICY_DIRECTION_IN ) type SenderMsg struct { @@ -101,7 +101,7 @@ type BgpServer struct { broadcastReqs []*GrpcRequest broadcastMsgs []broadcastMsg neighborMap map[string]*Peer - localRibMap map[string]*LocalRib + localRibMap map[string]*table.TableManager zclient *zebra.Client roaClient *roaClient bmpClient *bmpClient @@ -119,7 +119,7 @@ func NewBgpServer(port int) *BgpServer { b.bmpConnCh = make(chan *bmpConn) b.GrpcReqCh = make(chan *GrpcRequest, 1) b.policyUpdateCh = make(chan config.RoutingPolicy) - b.localRibMap = make(map[string]*LocalRib) + b.localRibMap = make(map[string]*table.TableManager) b.neighborMap = make(map[string]*Peer) b.listenPort = port b.roaClient, _ = newROAClient(config.RpkiServers{}) @@ -150,7 +150,7 @@ func listenAndAccept(proto string, port int, ch chan *net.TCPConn) (*net.TCPList return l, nil } -func (server *BgpServer) addLocalRib(rib *LocalRib) { +func (server *BgpServer) addLocalRib(rib *table.TableManager) { server.localRibMap[rib.OwnerName()] = rib } @@ -224,7 +224,7 @@ func (server *BgpServer) Serve() { return rfList }(g.AfiSafis.AfiSafiList) - server.addLocalRib(NewLocalRib(GLOBAL_RIB_NAME, rfList, g.MplsLabelRange.MinLabel, g.MplsLabelRange.MaxLabel)) + server.addLocalRib(table.NewTableManager(GLOBAL_RIB_NAME, rfList, g.MplsLabelRange.MinLabel, g.MplsLabelRange.MaxLabel)) listenerMap := make(map[string]*net.TCPListener) acceptCh := make(chan *net.TCPConn) @@ -354,10 +354,8 @@ func (server *BgpServer) Serve() { name := config.NeighborConfig.NeighborAddress.String() if config.RouteServer.RouteServerConfig.RouteServerClient { - loc := NewLocalRib(name, peer.configuredRFlist(), g.MplsLabelRange.MinLabel, g.MplsLabelRange.MaxLabel) - server.addLocalRib(loc) - loc.setPolicy(peer, server.policyMap) - // set in policy + rib := table.NewTableManager(name, peer.configuredRFlist(), g.MplsLabelRange.MinLabel, g.MplsLabelRange.MaxLabel) + server.addLocalRib(rib) peer.setPolicy(server.policyMap) pathList := make([]*table.Path, 0) @@ -369,9 +367,9 @@ func (server *BgpServer) Serve() { pathList = append(pathList, p.adjRib.GetInPathList(rf)...) } } - pathList = applyPolicies(peer, loc, POLICY_DIRECTION_IMPORT, pathList) + pathList = peer.ApplyPolicy(POLICY_DIRECTION_IMPORT, pathList) if len(pathList) > 0 { - loc.rib.ProcessPaths(pathList) + rib.ProcessPaths(pathList) } } server.neighborMap[name] = peer @@ -411,8 +409,6 @@ func (server *BgpServer) Serve() { peer := server.neighborMap[addr] if peer.isRouteServerClient() { peer.conf.ApplyPolicy = config.ApplyPolicy - loc := server.localRibMap[addr] - loc.setPolicy(peer, server.policyMap) peer.setPolicy(server.policyMap) } case e := <-incoming: @@ -555,12 +551,12 @@ func (server *BgpServer) dropPeerAllRoutes(peer *Peer) []*SenderMsg { for _, rf := range peer.configuredRFlist() { if peer.isRouteServerClient() { - for _, loc := range server.localRibMap { - targetPeer := server.neighborMap[loc.OwnerName()] - if loc.isGlobal() || loc.OwnerName() == peer.conf.NeighborConfig.NeighborAddress.String() { + for _, rib := range server.localRibMap { + targetPeer := server.neighborMap[rib.OwnerName()] + if rib.OwnerName() == GLOBAL_RIB_NAME || rib.OwnerName() == peer.conf.NeighborConfig.NeighborAddress.String() { continue } - pathList, _ := loc.rib.DeletePathsforPeer(peer.peerInfo, rf) + pathList, _ := rib.DeletePathsforPeer(peer.peerInfo, rf) pathList = dropSameAsPath(targetPeer.conf.NeighborConfig.PeerAs, pathList) if targetPeer.fsm.state != bgp.BGP_FSM_ESTABLISHED || len(pathList) == 0 { continue @@ -570,8 +566,8 @@ func (server *BgpServer) dropPeerAllRoutes(peer *Peer) []*SenderMsg { targetPeer.adjRib.UpdateOut(pathList) } } else { - loc := server.localRibMap[GLOBAL_RIB_NAME] - pathList, _ := loc.rib.DeletePathsforPeer(peer.peerInfo, rf) + rib := server.localRibMap[GLOBAL_RIB_NAME] + pathList, _ := rib.DeletePathsforPeer(peer.peerInfo, rf) if len(pathList) == 0 { continue } @@ -591,59 +587,6 @@ func (server *BgpServer) dropPeerAllRoutes(peer *Peer) []*SenderMsg { return msgs } -func applyPolicies(peer *Peer, loc *LocalRib, d Direction, pathList []*table.Path) []*table.Path { - var defaultPolicy config.DefaultPolicyType - ret := make([]*table.Path, 0, len(pathList)) - - switch d { - case POLICY_DIRECTION_EXPORT: - defaultPolicy = loc.defaultExportPolicy - case POLICY_DIRECTION_IMPORT: - defaultPolicy = loc.defaultImportPolicy - case POLICY_DIRECTION_IN: - defaultPolicy = peer.defaultInPolicy - default: - log.WithFields(log.Fields{ - "Topic": "Server", - "Key": peer.conf.NeighborConfig.NeighborAddress, - }).Error("direction is not specified.") - return ret - } - - for _, path := range pathList { - if !path.IsWithdraw { - var applied bool = false - switch d { - case POLICY_DIRECTION_IN: - applied, path = peer.applyPolicies(d, path) - case POLICY_DIRECTION_IMPORT, POLICY_DIRECTION_EXPORT: - applied, path = loc.applyPolicies(d, path) - } - - if applied { - if path == nil { - log.WithFields(log.Fields{ - "Topic": "Peer", - "Key": peer.conf.NeighborConfig.NeighborAddress, - "Data": path, - }).Debug("Policy applied and rejected.") - continue - } - } else if defaultPolicy != config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE { - log.WithFields(log.Fields{ - "Topic": "Peer", - "Key": peer.conf.NeighborConfig.NeighborAddress, - "Data": path, - }).Debug("Default policy applied and rejected.") - continue - } - } - // FIXME: probably we already clone. - ret = append(ret, path.Clone(path.IsWithdraw)) - } - return ret -} - func (server *BgpServer) broadcastBests(bests []*table.Path) { for _, path := range bests { if !path.IsFromZebra { @@ -717,19 +660,19 @@ func (server *BgpServer) propagateUpdate(peer *Peer, pathList []*table.Path) []* msgs := make([]*SenderMsg, 0) if peer != nil && peer.isRouteServerClient() { - newPathList := applyPolicies(peer, nil, POLICY_DIRECTION_IN, pathList) - for _, loc := range server.localRibMap { - targetPeer := server.neighborMap[loc.OwnerName()] + newPathList := peer.ApplyPolicy(POLICY_DIRECTION_IN, pathList) + for _, rib := range server.localRibMap { + targetPeer := server.neighborMap[rib.OwnerName()] neighborAddress := peer.conf.NeighborConfig.NeighborAddress.String() - if loc.isGlobal() || loc.OwnerName() == neighborAddress { + if rib.OwnerName() == GLOBAL_RIB_NAME || rib.OwnerName() == neighborAddress { continue } - sendPathList, _ := loc.rib.ProcessPaths(applyPolicies(targetPeer, loc, POLICY_DIRECTION_IMPORT, + sendPathList, _ := rib.ProcessPaths(targetPeer.ApplyPolicy(POLICY_DIRECTION_IMPORT, dropSameAsPath(targetPeer.conf.NeighborConfig.PeerAs, filterpath(targetPeer, newPathList)))) if targetPeer.fsm.state != bgp.BGP_FSM_ESTABLISHED || len(sendPathList) == 0 { continue } - sendPathList = applyPolicies(targetPeer, loc, POLICY_DIRECTION_EXPORT, sendPathList) + sendPathList = targetPeer.ApplyPolicy(POLICY_DIRECTION_EXPORT, sendPathList) if len(sendPathList) == 0 { continue } @@ -738,8 +681,8 @@ func (server *BgpServer) propagateUpdate(peer *Peer, pathList []*table.Path) []* msgs = append(msgs, newSenderMsg(targetPeer, msgList)) } } else { - globalLoc := server.localRibMap[GLOBAL_RIB_NAME] - sendPathList, _ := globalLoc.rib.ProcessPaths(pathList) + rib := server.localRibMap[GLOBAL_RIB_NAME] + sendPathList, _ := rib.ProcessPaths(pathList) if len(sendPathList) == 0 { return msgs } @@ -775,7 +718,6 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *fsmMsg, incoming chan * oldState := bgp.FSMState(peer.conf.NeighborState.SessionState) peer.conf.NeighborState.SessionState = uint32(nextState) peer.fsm.StateChange(nextState) - globalRib := server.localRibMap[GLOBAL_RIB_NAME] if oldState == bgp.BGP_FSM_ESTABLISHED { if ch := server.bmpClient.send(); ch != nil { @@ -811,12 +753,13 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *fsmMsg, incoming chan * } pathList := make([]*table.Path, 0) if peer.isRouteServerClient() { - loc := server.localRibMap[peer.conf.NeighborConfig.NeighborAddress.String()] - pathList = applyPolicies(peer, loc, POLICY_DIRECTION_EXPORT, peer.getBests(loc)) + rib := server.localRibMap[peer.conf.NeighborConfig.NeighborAddress.String()] + pathList = peer.ApplyPolicy(POLICY_DIRECTION_EXPORT, peer.getBests(rib)) } else { + rib := server.localRibMap[GLOBAL_RIB_NAME] l, _ := peer.fsm.LocalHostPort() peer.conf.Transport.TransportConfig.LocalAddress = net.ParseIP(l) - for _, path := range filterpath(peer, peer.getBests(globalRib)) { + for _, path := range filterpath(peer, peer.getBests(rib)) { p := path.Clone(path.IsWithdraw) p.UpdatePathAttrs(&server.bgpConfig.Global, &peer.conf) pathList = append(pathList, p) @@ -939,17 +882,15 @@ func (server *BgpServer) SetPolicy(pl config.RoutingPolicy) { func (server *BgpServer) handlePolicy(pl config.RoutingPolicy) { server.SetPolicy(pl) - for _, loc := range server.localRibMap { - if loc.isGlobal() { + for _, rib := range server.localRibMap { + if rib.OwnerName() == GLOBAL_RIB_NAME { continue } - targetPeer := server.neighborMap[loc.OwnerName()] + targetPeer := server.neighborMap[rib.OwnerName()] log.WithFields(log.Fields{ "Topic": "Peer", "Key": targetPeer.conf.NeighborConfig.NeighborAddress, }).Info("call set policy") - loc.setPolicy(targetPeer, server.policyMap) - // set distribute policy targetPeer.setPolicy(server.policyMap) } } @@ -1132,12 +1073,12 @@ func (server *BgpServer) handleModPathRequest(grpcReq *GrpcRequest) []*table.Pat rf = bgp.AfiSafiToRouteFamily(nlri.AFI(), nlri.SAFI()) if arg.Resource == api.Resource_VRF { - label, err := server.localRibMap[GLOBAL_RIB_NAME].rib.GetNextLabel(arg.Name, nexthop, path.IsWithdraw) + label, err := server.localRibMap[GLOBAL_RIB_NAME].GetNextLabel(arg.Name, nexthop, path.IsWithdraw) if err != nil { result.ResponseErr = err goto ERR } - vrf := server.localRibMap[GLOBAL_RIB_NAME].rib.Vrfs[arg.Name] + vrf := server.localRibMap[GLOBAL_RIB_NAME].Vrfs[arg.Name] switch rf { case bgp.RF_IPv4_UC: n := nlri.(*bgp.IPAddrPrefix) @@ -1172,7 +1113,7 @@ func (server *BgpServer) handleModPathRequest(grpcReq *GrpcRequest) []*table.Pat macIpAdv := evpnNlri.RouteTypeData.(*bgp.EVPNMacIPAdvertisementRoute) etag := macIpAdv.ETag mac := macIpAdv.MacAddress - paths := server.localRibMap[GLOBAL_RIB_NAME].rib.GetBestPathList(bgp.RF_EVPN) + paths := server.localRibMap[GLOBAL_RIB_NAME].GetBestPathList(bgp.RF_EVPN) if m := getMacMobilityExtendedCommunity(etag, mac, paths); m != nil { extcomms = append(extcomms, m) } @@ -1196,7 +1137,7 @@ ERR: } func (server *BgpServer) handleVrfMod(arg *api.ModVrfArguments) ([]*table.Path, error) { - manager := server.localRibMap[GLOBAL_RIB_NAME].rib + rib := server.localRibMap[GLOBAL_RIB_NAME] var msgs []*table.Path switch arg.Operation { case api.Operation_ADD: @@ -1224,13 +1165,13 @@ func (server *BgpServer) handleVrfMod(arg *api.ModVrfArguments) ([]*table.Path, AS: server.bgpConfig.Global.GlobalConfig.As, LocalID: server.bgpConfig.Global.GlobalConfig.RouterId, } - msgs, err = manager.AddVrf(arg.Vrf.Name, rd, importRt, exportRt, pi) + msgs, err = rib.AddVrf(arg.Vrf.Name, rd, importRt, exportRt, pi) if err != nil { return nil, err } case api.Operation_DEL: var err error - msgs, err = manager.DeleteVrf(arg.Vrf.Name) + msgs, err = rib.DeleteVrf(arg.Vrf.Name) if err != nil { return nil, err } @@ -1247,7 +1188,7 @@ func (server *BgpServer) handleVrfRequest(req *GrpcRequest) []*table.Path { switch req.RequestType { case REQ_VRF: name := req.Name - rib := server.localRibMap[GLOBAL_RIB_NAME].rib + rib := server.localRibMap[GLOBAL_RIB_NAME] vrfs := rib.Vrfs if _, ok := vrfs[name]; !ok { result.ResponseErr = fmt.Errorf("vrf %s not found", name) @@ -1279,7 +1220,7 @@ func (server *BgpServer) handleVrfRequest(req *GrpcRequest) []*table.Path { } goto END case REQ_VRFS: - vrfs := server.localRibMap[GLOBAL_RIB_NAME].rib.Vrfs + vrfs := server.localRibMap[GLOBAL_RIB_NAME].Vrfs for _, vrf := range vrfs { req.ResponseCh <- &GrpcResponse{ Data: vrf.ToApiStruct(), @@ -1336,11 +1277,11 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { switch grpcReq.RequestType { case REQ_GLOBAL_RIB: var results []*GrpcResponse - if t, ok := server.localRibMap[GLOBAL_RIB_NAME].rib.Tables[grpcReq.RouteFamily]; ok { + if t, ok := server.localRibMap[GLOBAL_RIB_NAME].Tables[grpcReq.RouteFamily]; ok { results = make([]*GrpcResponse, len(t.GetDestinations())) switch grpcReq.RouteFamily { case bgp.RF_IPv4_UC, bgp.RF_IPv6_UC: - results = sortedDsts(server.localRibMap[GLOBAL_RIB_NAME].rib.Tables[grpcReq.RouteFamily]) + results = sortedDsts(server.localRibMap[GLOBAL_RIB_NAME].Tables[grpcReq.RouteFamily]) default: i := 0 for _, dst := range t.GetDestinations() { @@ -1392,11 +1333,11 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { var results []*GrpcResponse if peer.isRouteServerClient() && peer.fsm.adminState != ADMIN_STATE_DOWN { remoteAddr := grpcReq.Name - if t, ok := server.localRibMap[remoteAddr].rib.Tables[grpcReq.RouteFamily]; ok { + if t, ok := server.localRibMap[remoteAddr].Tables[grpcReq.RouteFamily]; ok { results = make([]*GrpcResponse, len(t.GetDestinations())) switch grpcReq.RouteFamily { case bgp.RF_IPv4_UC, bgp.RF_IPv6_UC: - results = sortedDsts(server.localRibMap[remoteAddr].rib.Tables[grpcReq.RouteFamily]) + results = sortedDsts(server.localRibMap[remoteAddr].Tables[grpcReq.RouteFamily]) default: i := 0 for _, dst := range t.GetDestinations() { @@ -1547,15 +1488,6 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { if err != nil { break } - loc := server.localRibMap[peer.conf.NeighborConfig.NeighborAddress.String()] - if loc == nil { - result := &GrpcResponse{ - ResponseErr: fmt.Errorf("no local rib for %s", peer.conf.NeighborConfig.NeighborAddress.String()), - } - grpcReq.ResponseCh <- result - close(grpcReq.ResponseCh) - break - } extract := func(policyNames []string) []*api.PolicyDefinition { pdList := server.routingPolicy.PolicyDefinitions.PolicyDefinitionList @@ -1593,10 +1525,10 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { defaultImportPolicy := policy.ROUTE_REJECT defaultExportPolicy := policy.ROUTE_REJECT defaultInPolicy := policy.ROUTE_REJECT - if loc.defaultImportPolicy == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE { + if peer.defaultImportPolicy == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE { defaultImportPolicy = policy.ROUTE_ACCEPT } - if loc.defaultExportPolicy == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE { + if peer.defaultExportPolicy == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE { defaultExportPolicy = policy.ROUTE_ACCEPT } if peer.defaultInPolicy == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE { @@ -1655,17 +1587,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { applyPolicy.InPolicy = make([]string, 0) } - if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_ADD_IN || - grpcReq.RequestType == REQ_NEIGHBOR_POLICY_DEL_IN { - peer.setPolicy(reqPolicyMap) - } else { - loc, ok := server.localRibMap[peer.conf.NeighborConfig.NeighborAddress.String()] - if ok { - loc.setPolicy(peer, reqPolicyMap) - } else { - result.ResponseErr = fmt.Errorf("no local rib for %s", peer.conf.NeighborConfig.NeighborAddress.String()) - } - } + peer.setPolicy(reqPolicyMap) grpcReq.ResponseCh <- result close(grpcReq.ResponseCh) @@ -2318,24 +2240,24 @@ func (server *BgpServer) handleMrt(grpcReq *GrpcRequest) { now := uint32(time.Now().Unix()) view := "" result := &GrpcResponse{} - var manager *table.TableManager + var rib *table.TableManager switch grpcReq.RequestType { case REQ_MRT_GLOBAL_RIB: - manager = server.localRibMap[GLOBAL_RIB_NAME].rib + rib = server.localRibMap[GLOBAL_RIB_NAME] case REQ_MRT_LOCAL_RIB: _, err := server.checkNeighborRequest(grpcReq) if err != nil { return } - loc, ok := server.localRibMap[grpcReq.Name] + var ok bool + rib, ok = server.localRibMap[grpcReq.Name] if !ok { result.ResponseErr = fmt.Errorf("no local rib for %s", grpcReq.Name) grpcReq.ResponseCh <- result close(grpcReq.ResponseCh) return } - manager = loc.rib view = grpcReq.Name } @@ -2354,7 +2276,7 @@ func (server *BgpServer) handleMrt(grpcReq *GrpcRequest) { return } - tbl, ok := manager.Tables[grpcReq.RouteFamily] + tbl, ok := rib.Tables[grpcReq.RouteFamily] if !ok { result.ResponseErr = fmt.Errorf("unsupported route family: %s", grpcReq.RouteFamily) grpcReq.ResponseCh <- result |