summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/grpc_server.go6
-rw-r--r--server/server.go91
2 files changed, 63 insertions, 34 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go
index 12a3a87a..25af6dc7 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -43,8 +43,10 @@ const (
REQ_NEIGHBOR_POLICY
REQ_NEIGHBOR_POLICY_ADD_IMPORT
REQ_NEIGHBOR_POLICY_ADD_EXPORT
+ REQ_NEIGHBOR_POLICY_ADD_DISTRIBUTE
REQ_NEIGHBOR_POLICY_DEL_IMPORT
REQ_NEIGHBOR_POLICY_DEL_EXPORT
+ REQ_NEIGHBOR_POLICY_DEL_DISTRIBUTE
REQ_GLOBAL_RIB
REQ_GLOBAL_ADD
REQ_GLOBAL_DELETE
@@ -382,6 +384,8 @@ func (s *Server) ModNeighborPolicy(stream api.Grpc_ModNeighborPolicyServer) erro
reqType = REQ_NEIGHBOR_POLICY_ADD_IMPORT
case "export":
reqType = REQ_NEIGHBOR_POLICY_ADD_EXPORT
+ case "distribute":
+ reqType = REQ_NEIGHBOR_POLICY_ADD_DISTRIBUTE
}
case api.Operation_DEL:
switch arg.Name {
@@ -389,6 +393,8 @@ func (s *Server) ModNeighborPolicy(stream api.Grpc_ModNeighborPolicyServer) erro
reqType = REQ_NEIGHBOR_POLICY_DEL_IMPORT
case "export":
reqType = REQ_NEIGHBOR_POLICY_DEL_EXPORT
+ case "distribute":
+ reqType = REQ_NEIGHBOR_POLICY_DEL_DISTRIBUTE
}
}
req := NewGrpcRequest(reqType, arg.RouterId, rf, arg.ApplyPolicy)
diff --git a/server/server.go b/server/server.go
index 8fd32193..9c60f0ce 100644
--- a/server/server.go
+++ b/server/server.go
@@ -1031,61 +1031,68 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
}
resInPolicies := []*api.PolicyDefinition{}
resOutPolicies := []*api.PolicyDefinition{}
+ resDistPolicies := []*api.PolicyDefinition{}
pdList := server.routingPolicy.PolicyDefinitionList
df := server.routingPolicy.DefinedSets
- // Add importpolies that has been set in the configuration file to the list.
- // However, peer haven't target importpolicy when add PolicyDefinition of name only to the list.
- conInPolicyNames := peer.config.ApplyPolicy.ImportPolicies
- for _, conInPolicyName := range conInPolicyNames {
- match := false
- for _, pd := range pdList {
- if conInPolicyName == pd.Name {
- match = true
- resInPolicies = append(resInPolicies, policy.PolicyDefinitionToApiStruct(pd, df))
- break
+
+ extract := func(policies []string) []*api.PolicyDefinition {
+ extracted := []*api.PolicyDefinition{}
+ for _, conInPolicyName := range policies {
+ match := false
+ for _, pd := range pdList {
+ if conInPolicyName == pd.Name {
+ match = true
+ extracted = append(extracted, policy.PolicyDefinitionToApiStruct(pd, df))
+ break
+ }
+ }
+ if !match {
+ extracted = append(extracted, &api.PolicyDefinition{PolicyDefinitionName: conInPolicyName})
}
}
- if !match {
- resInPolicies = append(resInPolicies, &api.PolicyDefinition{PolicyDefinitionName: conInPolicyName})
- }
+ return extracted
}
+
+ // Add importpolies that has been set in the configuration file to the list.
+ // However, peer haven't target importpolicy when add PolicyDefinition of name only to the list.
+ conInPolicyNames := peer.config.ApplyPolicy.ImportPolicies
+ resInPolicies = extract(conInPolicyNames)
+
// Add importpolies that has been set in the configuration file to the list.
// However, peer haven't target importpolicy when add PolicyDefinition of name only to the list.
conOutPolicyNames := peer.config.ApplyPolicy.ExportPolicies
- for _, conOutPolicyName := range conOutPolicyNames {
- match := false
- for _, pd := range pdList {
- if conOutPolicyName == pd.Name {
- match = true
- resOutPolicies = append(resOutPolicies, policy.PolicyDefinitionToApiStruct(pd, df))
- break
- }
- }
- if !match {
- resOutPolicies = append(resOutPolicies, &api.PolicyDefinition{PolicyDefinitionName: conOutPolicyName})
- }
- }
+ resOutPolicies = extract(conOutPolicyNames)
+
+ distPolicyNames := peer.config.ApplyPolicy.DistributePolicies
+ resDistPolicies = extract(distPolicyNames)
defaultInPolicy := policy.ROUTE_REJECT
defaultOutPolicy := policy.ROUTE_REJECT
+ defaultDistPolicy := policy.ROUTE_REJECT
if loc.defaultImportPolicy == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE {
defaultInPolicy = policy.ROUTE_ACCEPT
}
if loc.defaultExportPolicy == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE {
defaultOutPolicy = policy.ROUTE_ACCEPT
}
+ if peer.defaultDistributePolicy == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE {
+ defaultDistPolicy = policy.ROUTE_ACCEPT
+ }
result := &GrpcResponse{
Data: &api.ApplyPolicy{
- DefaultImportPolicy: defaultInPolicy,
- ImportPolicies: resInPolicies,
- DefaultExportPolicy: defaultOutPolicy,
- ExportPolicies: resOutPolicies,
+ DefaultImportPolicy: defaultInPolicy,
+ ImportPolicies: resInPolicies,
+ DefaultExportPolicy: defaultOutPolicy,
+ ExportPolicies: resOutPolicies,
+ DefaultDistributePolicy: defaultDistPolicy,
+ DistributePolicies: resDistPolicies,
},
}
grpcReq.ResponseCh <- result
close(grpcReq.ResponseCh)
- case REQ_NEIGHBOR_POLICY_ADD_IMPORT, REQ_NEIGHBOR_POLICY_ADD_EXPORT, REQ_NEIGHBOR_POLICY_DEL_IMPORT, REQ_NEIGHBOR_POLICY_DEL_EXPORT:
+ case REQ_NEIGHBOR_POLICY_ADD_IMPORT, REQ_NEIGHBOR_POLICY_ADD_EXPORT, REQ_NEIGHBOR_POLICY_ADD_DISTRIBUTE,
+ REQ_NEIGHBOR_POLICY_DEL_IMPORT, REQ_NEIGHBOR_POLICY_DEL_EXPORT, REQ_NEIGHBOR_POLICY_DEL_DISTRIBUTE:
peer, err := server.checkNeighborRequest(grpcReq)
if err != nil {
break
@@ -1093,7 +1100,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
reqApplyPolicy := grpcReq.Data.(*api.ApplyPolicy)
reqPolicyMap := server.policyMap
applyPolicy := &peer.config.ApplyPolicy
- var defInPolicy, defOutPolicy config.DefaultPolicyType
+ var defInPolicy, defOutPolicy, defDistPolicy config.DefaultPolicyType
if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_ADD_IMPORT {
if reqApplyPolicy.DefaultImportPolicy != policy.ROUTE_ACCEPT {
defInPolicy = config.DEFAULT_POLICY_TYPE_REJECT_ROUTE
@@ -1106,15 +1113,31 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
}
peer.config.ApplyPolicy.DefaultExportPolicy = defOutPolicy
applyPolicy.ExportPolicies = policy.PoliciesToString(reqApplyPolicy.ExportPolicies)
+ } else if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_ADD_DISTRIBUTE {
+ if reqApplyPolicy.DefaultDistributePolicy != policy.ROUTE_ACCEPT {
+ defDistPolicy = config.DEFAULT_POLICY_TYPE_REJECT_ROUTE
+ }
+ peer.config.ApplyPolicy.DefaultDistributePolicy = defDistPolicy
+ applyPolicy.DistributePolicies = policy.PoliciesToString(reqApplyPolicy.DistributePolicies)
} else if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_DEL_IMPORT {
peer.config.ApplyPolicy.DefaultImportPolicy = config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE
peer.config.ApplyPolicy.ImportPolicies = make([]string, 0)
} else if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_DEL_EXPORT {
peer.config.ApplyPolicy.DefaultExportPolicy = config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE
peer.config.ApplyPolicy.ExportPolicies = make([]string, 0)
+ } else if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_DEL_DISTRIBUTE {
+ peer.config.ApplyPolicy.DefaultDistributePolicy = config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE
+ peer.config.ApplyPolicy.DistributePolicies = make([]string, 0)
}
- loc := server.localRibMap[peer.config.NeighborAddress.String()]
- loc.setPolicy(peer, reqPolicyMap)
+
+ if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_ADD_DISTRIBUTE ||
+ grpcReq.RequestType == REQ_NEIGHBOR_POLICY_DEL_DISTRIBUTE {
+ peer.setPolicy(reqPolicyMap)
+ } else {
+ loc := server.localRibMap[peer.config.NeighborAddress.String()]
+ loc.setPolicy(peer, reqPolicyMap)
+ }
+
grpcReq.ResponseCh <- &GrpcResponse{}
close(grpcReq.ResponseCh)