summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/grpc_server.go20
-rw-r--r--server/server.go100
2 files changed, 115 insertions, 5 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go
index 618344fd..8f2ca497 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -58,6 +58,11 @@ const (
REQ_POLICY_NEIGHBOR_ADD
REQ_POLICY_NEIGHBOR_DELETE
REQ_POLICY_NEIGHBORS_DELETE
+ REQ_POLICY_ASPATH
+ REQ_POLICY_ASPATHS
+ REQ_POLICY_ASPATH_ADD
+ REQ_POLICY_ASPATH_DELETE
+ REQ_POLICY_ASPATHS_DELETE
REQ_POLICY_ROUTEPOLICIES
REQ_POLICY_ROUTEPOLICY
REQ_POLICY_ROUTEPOLICY_ADD
@@ -373,6 +378,17 @@ func (s *Server) modPolicy(arg *api.PolicyArguments, stream interface{}) error {
default:
return fmt.Errorf("unsupported operation: %s", arg.Operation)
}
+ case api.Resource_POLICY_ASPATH:
+ switch arg.Operation {
+ case api.Operation_ADD:
+ reqType = REQ_POLICY_ASPATH_ADD
+ case api.Operation_DEL:
+ reqType = REQ_POLICY_ASPATH_DELETE
+ case api.Operation_DEL_ALL:
+ reqType = REQ_POLICY_ASPATHS_DELETE
+ default:
+ return fmt.Errorf("unsupported operation: %s", arg.Operation)
+ }
case api.Resource_POLICY_ROUTEPOLICY:
switch arg.Operation {
case api.Operation_ADD:
@@ -410,6 +426,8 @@ func (s *Server) GetPolicyRoutePolicies(arg *api.PolicyArguments, stream api.Grp
reqType = REQ_POLICY_PREFIXES
case api.Resource_POLICY_NEIGHBOR:
reqType = REQ_POLICY_NEIGHBORS
+ case api.Resource_POLICY_ASPATH:
+ reqType = REQ_POLICY_ASPATHS
case api.Resource_POLICY_ROUTEPOLICY:
reqType = REQ_POLICY_ROUTEPOLICIES
default:
@@ -437,6 +455,8 @@ func (s *Server) GetPolicyRoutePolicy(ctx context.Context, arg *api.PolicyArgume
reqType = REQ_POLICY_PREFIX
case api.Resource_POLICY_NEIGHBOR:
reqType = REQ_POLICY_NEIGHBOR
+ case api.Resource_POLICY_ASPATH:
+ reqType = REQ_POLICY_ASPATH
case api.Resource_POLICY_ROUTEPOLICY:
reqType = REQ_POLICY_ROUTEPOLICY
default:
diff --git a/server/server.go b/server/server.go
index 3ff104d5..78cd5c8f 100644
--- a/server/server.go
+++ b/server/server.go
@@ -1048,15 +1048,15 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
grpcReq.ResponseCh <- &GrpcResponse{}
close(grpcReq.ResponseCh)
- case REQ_POLICY_PREFIXES, REQ_POLICY_NEIGHBORS, REQ_POLICY_ROUTEPOLICIES:
+ case REQ_POLICY_PREFIXES, REQ_POLICY_NEIGHBORS, REQ_POLICY_ASPATHS, REQ_POLICY_ROUTEPOLICIES:
server.handleGrpcShowPolicies(grpcReq)
- case REQ_POLICY_PREFIX, REQ_POLICY_NEIGHBOR, REQ_POLICY_ROUTEPOLICY:
+ case REQ_POLICY_PREFIX, REQ_POLICY_NEIGHBOR, REQ_POLICY_ASPATH, REQ_POLICY_ROUTEPOLICY:
server.handleGrpcShowPolicy(grpcReq)
- case REQ_POLICY_PREFIX_ADD, REQ_POLICY_NEIGHBOR_ADD, REQ_POLICY_ROUTEPOLICY_ADD:
+ case REQ_POLICY_PREFIX_ADD, REQ_POLICY_NEIGHBOR_ADD, REQ_POLICY_ASPATH_ADD, REQ_POLICY_ROUTEPOLICY_ADD:
server.handleGrpcAddPolicy(grpcReq)
- case REQ_POLICY_PREFIX_DELETE, REQ_POLICY_NEIGHBOR_DELETE, REQ_POLICY_ROUTEPOLICY_DELETE:
+ case REQ_POLICY_PREFIX_DELETE, REQ_POLICY_NEIGHBOR_DELETE, REQ_POLICY_ASPATH_DELETE, REQ_POLICY_ROUTEPOLICY_DELETE:
server.handleGrpcDelPolicy(grpcReq)
- case REQ_POLICY_PREFIXES_DELETE, REQ_POLICY_NEIGHBORS_DELETE, REQ_POLICY_ROUTEPOLICIES_DELETE:
+ case REQ_POLICY_PREFIXES_DELETE, REQ_POLICY_NEIGHBORS_DELETE, REQ_POLICY_ASPATHS_DELETE, REQ_POLICY_ROUTEPOLICIES_DELETE:
server.handleGrpcDelPolicies(grpcReq)
default:
errmsg := "Unknown request type"
@@ -1104,6 +1104,22 @@ func (server *BgpServer) handleGrpcShowPolicies(grpcReq *GrpcRequest) {
result.ResponseErr = fmt.Errorf("Policy neighbor doesn't exist.")
grpcReq.ResponseCh <- result
}
+ case REQ_POLICY_ASPATHS:
+ info := server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSetList
+ if len(info) > 0 {
+ for _, as := range info {
+ resAsPathSet := policy.AsPathSetToApiStruct(as)
+ pd := &api.PolicyDefinition{}
+ pd.StatementList = []*api.Statement{{Conditions: &api.Conditions{MatchAsPathSet: resAsPathSet}}}
+ result = &GrpcResponse{
+ Data: pd,
+ }
+ grpcReq.ResponseCh <- result
+ }
+ } else {
+ result.ResponseErr = fmt.Errorf("Policy aspath doesn't exist.")
+ grpcReq.ResponseCh <- result
+ }
case REQ_POLICY_ROUTEPOLICIES:
info := server.routingPolicy.PolicyDefinitionList
df := server.routingPolicy.DefinedSets
@@ -1163,6 +1179,24 @@ func (server *BgpServer) handleGrpcShowPolicy(grpcReq *GrpcRequest) {
} else {
result.ResponseErr = fmt.Errorf("policy neighbor that has %v doesn't exist.", name)
}
+ case REQ_POLICY_ASPATH:
+ info := server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSetList
+ resAsPathSet := &api.AsPathSet{}
+ for _, as := range info {
+ if as.AsPathSetName == name {
+ resAsPathSet = policy.AsPathSetToApiStruct(as)
+ break
+ }
+ }
+ if len(resAsPathSet.AsPathMembers) > 0 {
+ pd := &api.PolicyDefinition{}
+ pd.StatementList = []*api.Statement{{Conditions: &api.Conditions{MatchAsPathSet: resAsPathSet}}}
+ result = &GrpcResponse{
+ Data: pd,
+ }
+ } else {
+ result.ResponseErr = fmt.Errorf("policy aspath that has %v doesn't exist.", name)
+ }
case REQ_POLICY_ROUTEPOLICY:
log.Error("IN RoutePolicy")
info := server.routingPolicy.PolicyDefinitionList
@@ -1232,6 +1266,27 @@ func (server *BgpServer) handleGrpcAddPolicy(grpcReq *GrpcRequest) {
}
}
server.routingPolicy.DefinedSets.NeighborSetList = conNeighborSetList
+ case REQ_POLICY_ASPATH_ADD:
+ reqAsPathSet := grpcReq.Data.(*api.PolicyDefinition).StatementList[0].Conditions.MatchAsPathSet
+ conAsPathSetList := server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSetList
+ isReqAsPathSet, asPathSet := policy.AsPathSetToConfigStruct(reqAsPathSet)
+ if !isReqAsPathSet {
+ result.ResponseErr = fmt.Errorf("doesn't reqest of policy aspath.")
+ grpcReq.ResponseCh <- result
+ close(grpcReq.ResponseCh)
+ }
+ // If the same NeighborSet is not set, add NeighborSet of request to the end.
+ // If only name of the NeighborSet is same, overwrite with NeighborSet of request
+ idxAsPathSet, idxAsPath := policy.IndexOfAsPathSet(conAsPathSetList, asPathSet)
+ if idxAsPathSet == -1 {
+ conAsPathSetList = append(conAsPathSetList, asPathSet)
+ } else {
+ if idxAsPath == -1 {
+ conAsPathSetList[idxAsPathSet].AsPathSetMembers =
+ append(conAsPathSetList[idxAsPathSet].AsPathSetMembers, asPathSet.AsPathSetMembers[0])
+ }
+ }
+ server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSetList = conAsPathSetList
case REQ_POLICY_ROUTEPOLICY_ADD:
reqPolicy := grpcReq.Data.(*api.PolicyDefinition)
reqConditions := reqPolicy.StatementList[0].Conditions
@@ -1258,6 +1313,9 @@ func (server *BgpServer) handleGrpcAddPolicy(grpcReq *GrpcRequest) {
if reqConditions.MatchSetOptions != "" {
conStatement.Conditions.MatchSetOptions = statement.Conditions.MatchSetOptions
}
+ if reqConditions.MatchAsPathSet != nil {
+ conStatement.Conditions.BgpConditions.MatchAsPathSet = statement.Conditions.BgpConditions.MatchAsPathSet
+ }
if reqConditions.MatchAsPathLength != nil {
conStatement.Conditions.BgpConditions.AsPathLength = statement.Conditions.BgpConditions.AsPathLength
}
@@ -1353,6 +1411,36 @@ func (server *BgpServer) handleGrpcDelPolicy(grpcReq *GrpcRequest) {
}
}
server.routingPolicy.DefinedSets.NeighborSetList = conNeighborSetList
+ case REQ_POLICY_ASPATH_DELETE:
+ reqAsPathSet := grpcReq.Data.(*api.PolicyDefinition).StatementList[0].Conditions.MatchAsPathSet
+ conAsPathSetList := server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSetList
+ result := &GrpcResponse{}
+ isReqAsPathSet, asPathSet := policy.AsPathSetToConfigStruct(reqAsPathSet)
+ // If only name of the NeighborSet is same, delete all of the elements of the NeighborSet.
+ // If the same element NeighborSet, delete the it's element from NeighborSet.
+ idxAsPathSet, idxAsPath := policy.IndexOfAsPathSet(conAsPathSetList, asPathSet)
+ if isReqAsPathSet {
+ if idxAsPathSet == -1 {
+ result.ResponseErr = fmt.Errorf("Policy aspath that has %v %v doesn't exist.", asPathSet.AsPathSetName,
+ asPathSet.AsPathSetMembers[0])
+ } else {
+ if idxAsPath == -1 {
+ result.ResponseErr = fmt.Errorf("Policy aspath that has %v %v doesn't exist.", asPathSet.AsPathSetName,
+ asPathSet.AsPathSetMembers[0])
+ } else {
+ conAsPathSetList[idxAsPathSet].AsPathSetMembers =
+ append(conAsPathSetList[idxAsPathSet].AsPathSetMembers[:idxAsPath],
+ conAsPathSetList[idxAsPathSet].AsPathSetMembers[idxAsPath+1:]...)
+ }
+ }
+ } else {
+ if idxAsPathSet == -1 {
+ result.ResponseErr = fmt.Errorf("Policy aspath %v doesn't exist.", asPathSet.AsPathSetName)
+ } else {
+ conAsPathSetList = append(conAsPathSetList[:idxAsPathSet], conAsPathSetList[idxAsPathSet+1:]...)
+ }
+ }
+ server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSetList = conAsPathSetList
case REQ_POLICY_ROUTEPOLICY_DELETE:
reqPolicy := grpcReq.Data.(*api.PolicyDefinition)
conPolicyList := server.routingPolicy.PolicyDefinitionList
@@ -1398,6 +1486,8 @@ func (server *BgpServer) handleGrpcDelPolicies(grpcReq *GrpcRequest) {
server.routingPolicy.DefinedSets.PrefixSetList = make([]config.PrefixSet, 0)
case REQ_POLICY_NEIGHBORS_DELETE:
server.routingPolicy.DefinedSets.NeighborSetList = make([]config.NeighborSet, 0)
+ case REQ_POLICY_ASPATHS_DELETE:
+ server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSetList = make([]config.AsPathSet, 0)
case REQ_POLICY_ROUTEPOLICIES_DELETE:
server.routingPolicy.PolicyDefinitionList = make([]config.PolicyDefinition, 0)
}