diff options
author | Naoto Hanaue <hanaue.naoto@po.ntts.co.jp> | 2015-06-16 14:11:02 +0900 |
---|---|---|
committer | Naoto Hanaue <hanaue.naoto@po.ntts.co.jp> | 2015-06-16 14:11:02 +0900 |
commit | b109116fb80767040dddeabd45f64bd236b43be2 (patch) | |
tree | 5823d186dcb0440fd21a89dfd7536b20304be3a8 /server/server.go | |
parent | 29de1da7c796051549f92a4a5ce1fae472ca3c7f (diff) |
cli: aggregate grpc communication interface associated with the policy to api.policyDefinition
Diffstat (limited to 'server/server.go')
-rw-r--r-- | server/server.go | 441 |
1 files changed, 222 insertions, 219 deletions
diff --git a/server/server.go b/server/server.go index 43d0e51e..3ff104d5 100644 --- a/server/server.go +++ b/server/server.go @@ -950,12 +950,6 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { if err != nil { break } - - resInPolicies := []*api.PolicyDefinition{} - resOutPolicies := []*api.PolicyDefinition{} - // 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 loc := server.localRibMap[peer.config.NeighborAddress.String()] if loc == nil { result := &GrpcResponse{ @@ -965,12 +959,19 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { close(grpcReq.ResponseCh) break } + resInPolicies := []*api.PolicyDefinition{} + resOutPolicies := []*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 _, inPolicy := range loc.importPolicies { - if conInPolicyName == inPolicy.Name { + for _, pd := range pdList { + if conInPolicyName == pd.Name { match = true - resInPolicies = append(resInPolicies, inPolicy.ToApiStruct()) + resInPolicies = append(resInPolicies, policy.PolicyDefinitionToApiStruct(pd, df)) break } } @@ -983,10 +984,10 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { conOutPolicyNames := peer.config.ApplyPolicy.ExportPolicies for _, conOutPolicyName := range conOutPolicyNames { match := false - for _, outPolicy := range loc.exportPolicies { - if conOutPolicyName == outPolicy.Name { + for _, pd := range pdList { + if conOutPolicyName == pd.Name { match = true - resOutPolicies = append(resOutPolicies, outPolicy.ToApiStruct()) + resOutPolicies = append(resOutPolicies, policy.PolicyDefinitionToApiStruct(pd, df)) break } } @@ -994,6 +995,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { resOutPolicies = append(resOutPolicies, &api.PolicyDefinition{PolicyDefinitionName: conOutPolicyName}) } } + defaultInPolicy := policy.ROUTE_REJECT defaultOutPolicy := policy.ROUTE_REJECT if loc.defaultImportPolicy == config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE { @@ -1019,8 +1021,6 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { break } reqApplyPolicy := grpcReq.Data.(*api.ApplyPolicy) - grpcReq.Data = []interface{}{reqApplyPolicy, server.policyMap} - reqPolicyMap := server.policyMap applyPolicy := &peer.config.ApplyPolicy var defInPolicy, defOutPolicy config.DefaultPolicyType @@ -1048,14 +1048,39 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { grpcReq.ResponseCh <- &GrpcResponse{} close(grpcReq.ResponseCh) + case REQ_POLICY_PREFIXES, REQ_POLICY_NEIGHBORS, REQ_POLICY_ROUTEPOLICIES: + server.handleGrpcShowPolicies(grpcReq) + case REQ_POLICY_PREFIX, REQ_POLICY_NEIGHBOR, REQ_POLICY_ROUTEPOLICY: + server.handleGrpcShowPolicy(grpcReq) + case REQ_POLICY_PREFIX_ADD, REQ_POLICY_NEIGHBOR_ADD, REQ_POLICY_ROUTEPOLICY_ADD: + server.handleGrpcAddPolicy(grpcReq) + case REQ_POLICY_PREFIX_DELETE, REQ_POLICY_NEIGHBOR_DELETE, REQ_POLICY_ROUTEPOLICY_DELETE: + server.handleGrpcDelPolicy(grpcReq) + case REQ_POLICY_PREFIXES_DELETE, REQ_POLICY_NEIGHBORS_DELETE, REQ_POLICY_ROUTEPOLICIES_DELETE: + server.handleGrpcDelPolicies(grpcReq) + default: + errmsg := "Unknown request type" + result := &GrpcResponse{ + ResponseErr: fmt.Errorf(errmsg), + } + grpcReq.ResponseCh <- result + close(grpcReq.ResponseCh) + } + return msgs +} + +func (server *BgpServer) handleGrpcShowPolicies(grpcReq *GrpcRequest) { + result := &GrpcResponse{} + switch grpcReq.RequestType { case REQ_POLICY_PREFIXES: info := server.routingPolicy.DefinedSets.PrefixSetList - result := &GrpcResponse{} if len(info) > 0 { for _, ps := range info { resPrefixSet := policy.PrefixSetToApiStruct(ps) + pd := &api.PolicyDefinition{} + pd.StatementList = []*api.Statement{{Conditions: &api.Conditions{MatchPrefixSet: resPrefixSet}}} result = &GrpcResponse{ - Data: resPrefixSet, + Data: pd, } grpcReq.ResponseCh <- result } @@ -1063,12 +1088,47 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { result.ResponseErr = fmt.Errorf("Policy prefix doesn't exist.") grpcReq.ResponseCh <- result } - close(grpcReq.ResponseCh) - + case REQ_POLICY_NEIGHBORS: + info := server.routingPolicy.DefinedSets.NeighborSetList + if len(info) > 0 { + for _, ns := range info { + resNeighborSet := policy.NeighborSetToApiStruct(ns) + pd := &api.PolicyDefinition{} + pd.StatementList = []*api.Statement{{Conditions: &api.Conditions{MatchNeighborSet: resNeighborSet}}} + result = &GrpcResponse{ + Data: pd, + } + grpcReq.ResponseCh <- result + } + } else { + result.ResponseErr = fmt.Errorf("Policy neighbor doesn't exist.") + grpcReq.ResponseCh <- result + } + case REQ_POLICY_ROUTEPOLICIES: + info := server.routingPolicy.PolicyDefinitionList + df := server.routingPolicy.DefinedSets + result := &GrpcResponse{} + if len(info) > 0 { + for _, pd := range info { + resPolicyDefinition := policy.PolicyDefinitionToApiStruct(pd, df) + result = &GrpcResponse{ + Data: resPolicyDefinition, + } + grpcReq.ResponseCh <- result + } + } else { + result.ResponseErr = fmt.Errorf("Route Policy doesn't exist.") + grpcReq.ResponseCh <- result + } + } + close(grpcReq.ResponseCh) +} +func (server *BgpServer) handleGrpcShowPolicy(grpcReq *GrpcRequest) { + name := grpcReq.Data.(string) + result := &GrpcResponse{} + switch grpcReq.RequestType { case REQ_POLICY_PREFIX: - name := grpcReq.Data.(string) info := server.routingPolicy.DefinedSets.PrefixSetList - result := &GrpcResponse{} resPrefixSet := &api.PrefixSet{} for _, ps := range info { if ps.PrefixSetName == name { @@ -1077,20 +1137,62 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { } } if len(resPrefixSet.PrefixList) > 0 { + pd := &api.PolicyDefinition{} + pd.StatementList = []*api.Statement{{Conditions: &api.Conditions{MatchPrefixSet: resPrefixSet}}} result = &GrpcResponse{ - Data: resPrefixSet, + Data: pd, } - grpcReq.ResponseCh <- result } else { - result.ResponseErr = fmt.Errorf("Policy prefix that has %v doesn't exist.", name) - grpcReq.ResponseCh <- result + result.ResponseErr = fmt.Errorf("policy prefix that has %v doesn't exist.", name) } - close(grpcReq.ResponseCh) + case REQ_POLICY_NEIGHBOR: + info := server.routingPolicy.DefinedSets.NeighborSetList + resNeighborSet := &api.NeighborSet{} + for _, ns := range info { + if ns.NeighborSetName == name { + resNeighborSet = policy.NeighborSetToApiStruct(ns) + break + } + } + if len(resNeighborSet.NeighborList) > 0 { + pd := &api.PolicyDefinition{} + pd.StatementList = []*api.Statement{{Conditions: &api.Conditions{MatchNeighborSet: resNeighborSet}}} + result = &GrpcResponse{ + Data: pd, + } + } else { + result.ResponseErr = fmt.Errorf("policy neighbor that has %v doesn't exist.", name) + } + case REQ_POLICY_ROUTEPOLICY: + log.Error("IN RoutePolicy") + info := server.routingPolicy.PolicyDefinitionList + df := server.routingPolicy.DefinedSets + resPolicyDefinition := &api.PolicyDefinition{} + for _, pd := range info { + if pd.Name == name { + resPolicyDefinition = policy.PolicyDefinitionToApiStruct(pd, df) + break + } + } + log.Error("IN RoutePolicy: ",len(resPolicyDefinition.StatementList)) + if len(resPolicyDefinition.StatementList) > 0 { + result = &GrpcResponse{ + Data: resPolicyDefinition, + } + } else { + result.ResponseErr = fmt.Errorf("Route Policy that has %v doesn't exist.", name) + } + } + grpcReq.ResponseCh <- result + close(grpcReq.ResponseCh) +} +func (server *BgpServer) handleGrpcAddPolicy(grpcReq *GrpcRequest) { + result := &GrpcResponse{} + switch grpcReq.RequestType { case REQ_POLICY_PREFIX_ADD: - reqPrefixSet := grpcReq.Data.(*api.PrefixSet) + reqPrefixSet := grpcReq.Data.(*api.PolicyDefinition).StatementList[0].Conditions.MatchPrefixSet conPrefixSetList := server.routingPolicy.DefinedSets.PrefixSetList - result := &GrpcResponse{} isReqPrefixSet, prefixSet := policy.PrefixSetToConfigStruct(reqPrefixSet) if !isReqPrefixSet { result.ResponseErr = fmt.Errorf("doesn't reqest of policy prefix.") @@ -1104,22 +1206,88 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { conPrefixSetList = append(conPrefixSetList, prefixSet) } else { if idxPrefix == -1 { - conPrefixSetList[idxPrefixSet].PrefixList = append(conPrefixSetList[idxPrefixSet].PrefixList, prefixSet.PrefixList[0]) + conPrefixSetList[idxPrefixSet].PrefixList = + append(conPrefixSetList[idxPrefixSet].PrefixList, prefixSet.PrefixList[0]) } } server.routingPolicy.DefinedSets.PrefixSetList = conPrefixSetList - server.handlePolicy(server.routingPolicy) - grpcReq.ResponseCh <- result - close(grpcReq.ResponseCh) + case REQ_POLICY_NEIGHBOR_ADD: + reqNeighborSet := grpcReq.Data.(*api.PolicyDefinition).StatementList[0].Conditions.MatchNeighborSet + conNeighborSetList := server.routingPolicy.DefinedSets.NeighborSetList + isReqNeighborSet, neighborSet := policy.NeighborSetToConfigStruct(reqNeighborSet) + if !isReqNeighborSet { + result.ResponseErr = fmt.Errorf("doesn't reqest of policy neighbor.") + 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 + idxNeighborSet, idxNeighbor := policy.IndexOfNeighborSet(conNeighborSetList, neighborSet) + if idxNeighborSet == -1 { + conNeighborSetList = append(conNeighborSetList, neighborSet) + } else { + if idxNeighbor == -1 { + conNeighborSetList[idxNeighborSet].NeighborInfoList = + append(conNeighborSetList[idxNeighborSet].NeighborInfoList, neighborSet.NeighborInfoList[0]) + } + } + server.routingPolicy.DefinedSets.NeighborSetList = conNeighborSetList + case REQ_POLICY_ROUTEPOLICY_ADD: + reqPolicy := grpcReq.Data.(*api.PolicyDefinition) + reqConditions := reqPolicy.StatementList[0].Conditions + reqActions := reqPolicy.StatementList[0].Actions + conPolicyList := server.routingPolicy.PolicyDefinitionList + _, policyDef := policy.PolicyDefinitionToConfigStruct(reqPolicy) + idxPolicy, idxStatement := policy.IndexOfPolicyDefinition(conPolicyList, policyDef) + if idxPolicy == -1 { + conPolicyList = append(conPolicyList, policyDef) + } else { + statement := policyDef.StatementList[0] + if idxStatement == -1 { + conPolicyList[idxPolicy].StatementList = + append(conPolicyList[idxPolicy].StatementList, statement) + } else { + conStatement := &conPolicyList[idxPolicy].StatementList[idxStatement] + if reqConditions != nil { + if reqConditions.MatchPrefixSet != nil { + conStatement.Conditions.MatchPrefixSet = statement.Conditions.MatchPrefixSet + } + if reqConditions.MatchNeighborSet != nil { + conStatement.Conditions.MatchNeighborSet = statement.Conditions.MatchNeighborSet + } + if reqConditions.MatchSetOptions != "" { + conStatement.Conditions.MatchSetOptions = statement.Conditions.MatchSetOptions + } + if reqConditions.MatchAsPathLength != nil { + conStatement.Conditions.BgpConditions.AsPathLength = statement.Conditions.BgpConditions.AsPathLength + } + } + if reqActions != nil { + if reqActions.RouteAction != "" { + conStatement.Actions.AcceptRoute = statement.Actions.AcceptRoute + conStatement.Actions.RejectRoute = statement.Actions.RejectRoute + } + conStatement.Actions = statement.Actions + } + } + } + server.routingPolicy.PolicyDefinitionList = conPolicyList + } + server.handlePolicy(server.routingPolicy) + grpcReq.ResponseCh <- result + close(grpcReq.ResponseCh) +} +func (server *BgpServer) handleGrpcDelPolicy(grpcReq *GrpcRequest) { + result := &GrpcResponse{} + switch grpcReq.RequestType { case REQ_POLICY_PREFIX_DELETE: - reqPrefixSet := grpcReq.Data.(*api.PrefixSet) + reqPrefixSet := grpcReq.Data.(*api.PolicyDefinition).StatementList[0].Conditions.MatchPrefixSet conPrefixSetList := server.routingPolicy.DefinedSets.PrefixSetList - result := &GrpcResponse{} isReqPrefixSet, prefixSet := policy.PrefixSetToConfigStruct(reqPrefixSet) if isReqPrefixSet { // If only name of the PrefixSet is same, delete all of the elements of the PrefixSet. - //If the same element PrefixSet, delete the it's element from PrefixSet. + // If the same element PrefixSet, delete the it's element from PrefixSet. idxPrefixSet, idxPrefix := policy.IndexOfPrefixSet(conPrefixSetList, prefixSet) prefix := prefixSet.PrefixList[0] if idxPrefixSet == -1 { @@ -1131,7 +1299,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { prefix.Address, prefix.Masklength, prefix.MasklengthRange) } else { conPrefixSetList[idxPrefixSet].PrefixList = - append(conPrefixSetList[idxPrefixSet].PrefixList[:idxPrefix], conPrefixSetList[idxPrefixSet].PrefixList[idxPrefix+1:]...) + append(conPrefixSetList[idxPrefixSet].PrefixList[:idxPrefix], conPrefixSetList[idxPrefixSet].PrefixList[idxPrefix+1:]...) } } } else { @@ -1149,85 +1317,9 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { } } server.routingPolicy.DefinedSets.PrefixSetList = conPrefixSetList - server.handlePolicy(server.routingPolicy) - grpcReq.ResponseCh <- result - close(grpcReq.ResponseCh) - - case REQ_POLICY_PREFIXES_DELETE: - result := &GrpcResponse{} - server.routingPolicy.DefinedSets.PrefixSetList = make([]config.PrefixSet, 0) - server.handlePolicy(server.routingPolicy) - grpcReq.ResponseCh <- result - close(grpcReq.ResponseCh) - - case REQ_POLICY_NEIGHBORS: - info := server.routingPolicy.DefinedSets.NeighborSetList - result := &GrpcResponse{} - if len(info) > 0 { - for _, ns := range info { - resNeighborSet := policy.NeighborSetToApiStruct(ns) - result = &GrpcResponse{ - Data: resNeighborSet, - } - grpcReq.ResponseCh <- result - } - } else { - result.ResponseErr = fmt.Errorf("Policy neighbor doesn't exist.") - grpcReq.ResponseCh <- result - } - close(grpcReq.ResponseCh) - - case REQ_POLICY_NEIGHBOR: - name := grpcReq.Data.(string) - info := server.routingPolicy.DefinedSets.NeighborSetList - result := &GrpcResponse{} - resNeighborSet := &api.NeighborSet{} - for _, ns := range info { - if ns.NeighborSetName == name { - resNeighborSet = policy.NeighborSetToApiStruct(ns) - break - } - } - if len(resNeighborSet.NeighborList) > 0 { - result = &GrpcResponse{ - Data: resNeighborSet, - } - grpcReq.ResponseCh <- result - } else { - result.ResponseErr = fmt.Errorf("Policy neighbor that has %v doesn't exist.", name) - grpcReq.ResponseCh <- result - } - close(grpcReq.ResponseCh) - - case REQ_POLICY_NEIGHBOR_ADD: - reqNeighborSet := grpcReq.Data.(*api.NeighborSet) - conNeighborSetList := server.routingPolicy.DefinedSets.NeighborSetList - result := &GrpcResponse{} - isReqNeighborSet, neighborSet := policy.NeighborSetToConfigStruct(reqNeighborSet) - if !isReqNeighborSet { - result.ResponseErr = fmt.Errorf("doesn't reqest of policy neighbor.") - 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 - idxNeighborSet, idxNeighbor := policy.IndexOfNeighborSet(conNeighborSetList, neighborSet) - if idxNeighborSet == -1 { - conNeighborSetList = append(conNeighborSetList, neighborSet) - } else { - if idxNeighbor == -1 { - conNeighborSetList[idxNeighborSet].NeighborInfoList = - append(conNeighborSetList[idxNeighborSet].NeighborInfoList, neighborSet.NeighborInfoList[0]) - } - } - server.routingPolicy.DefinedSets.NeighborSetList = conNeighborSetList - server.handlePolicy(server.routingPolicy) - grpcReq.ResponseCh <- result - close(grpcReq.ResponseCh) case REQ_POLICY_NEIGHBOR_DELETE: - reqNeighborSet := grpcReq.Data.(*api.NeighborSet) + reqNeighborSet := grpcReq.Data.(*api.PolicyDefinition).StatementList[0].Conditions.MatchNeighborSet conNeighborSetList := server.routingPolicy.DefinedSets.NeighborSetList - result := &GrpcResponse{} isReqNeighborSet, neighborSet := policy.NeighborSetToConfigStruct(reqNeighborSet) if isReqNeighborSet { // If only name of the NeighborSet is same, delete all of the elements of the NeighborSet. @@ -1242,8 +1334,8 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { neighborSet.NeighborInfoList[0].Address) } else { conNeighborSetList[idxNeighborSet].NeighborInfoList = - append(conNeighborSetList[idxNeighborSet].NeighborInfoList[:idxNeighbor], - conNeighborSetList[idxNeighborSet].NeighborInfoList[idxNeighbor+1:]...) + append(conNeighborSetList[idxNeighborSet].NeighborInfoList[:idxNeighbor], + conNeighborSetList[idxNeighborSet].NeighborInfoList[idxNeighbor+1:]...) } } } else { @@ -1261,95 +1353,6 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { } } server.routingPolicy.DefinedSets.NeighborSetList = conNeighborSetList - server.handlePolicy(server.routingPolicy) - grpcReq.ResponseCh <- result - close(grpcReq.ResponseCh) - case REQ_POLICY_NEIGHBORS_DELETE: - result := &GrpcResponse{} - server.routingPolicy.DefinedSets.NeighborSetList = make([]config.NeighborSet, 0) - server.handlePolicy(server.routingPolicy) - grpcReq.ResponseCh <- result - close(grpcReq.ResponseCh) - case REQ_POLICY_ROUTEPOLICIES: - info := server.routingPolicy.PolicyDefinitionList - df := server.routingPolicy.DefinedSets - result := &GrpcResponse{} - if len(info) > 0 { - for _, pd := range info { - resPolicyDefinition := policy.PolicyDefinitionToApiStruct(pd, df) - result = &GrpcResponse{ - Data: resPolicyDefinition, - } - grpcReq.ResponseCh <- result - } - } else { - result.ResponseErr = fmt.Errorf("Route Policy doesn't exist.") - grpcReq.ResponseCh <- result - } - close(grpcReq.ResponseCh) - case REQ_POLICY_ROUTEPOLICY: - name := grpcReq.Data.(string) - info := server.routingPolicy.PolicyDefinitionList - df := server.routingPolicy.DefinedSets - result := &GrpcResponse{} - resPolicyDefinition := &api.PolicyDefinition{} - for _, pd := range info { - if pd.Name == name { - resPolicyDefinition = policy.PolicyDefinitionToApiStruct(pd, df) - break - } - } - if len(resPolicyDefinition.StatementList) > 0 { - result = &GrpcResponse{ - Data: resPolicyDefinition, - } - grpcReq.ResponseCh <- result - } else { - result.ResponseErr = fmt.Errorf("Route Policy that has %v doesn't exist.", name) - grpcReq.ResponseCh <- result - } - close(grpcReq.ResponseCh) - case REQ_POLICY_ROUTEPOLICY_ADD: - reqPolicy := grpcReq.Data.(*api.PolicyDefinition) - reqConditions := reqPolicy.StatementList[0].Conditions - reqActions := reqPolicy.StatementList[0].Actions - conPolicyList := server.routingPolicy.PolicyDefinitionList - result := &GrpcResponse{} - _, policyDef := policy.PolicyDefinitionToConfigStruct(reqPolicy) - idxPolicy, idxStatement := policy.IndexOfPolicyDefinition(conPolicyList, policyDef) - if idxPolicy == -1 { - conPolicyList = append(conPolicyList, policyDef) - } else { - statement := policyDef.StatementList[0] - if idxStatement == -1 { - conPolicyList[idxPolicy].StatementList = - append(conPolicyList[idxPolicy].StatementList, statement) - } else { - conStatement := &conPolicyList[idxPolicy].StatementList[idxStatement] - if reqConditions != nil { - if reqConditions.MatchPrefixSet != nil { - conStatement.Conditions.MatchPrefixSet = statement.Conditions.MatchPrefixSet - } - if reqConditions.MatchNeighborSet != nil { - conStatement.Conditions.MatchNeighborSet = statement.Conditions.MatchNeighborSet - } - if reqConditions.MatchSetOptions != "" { - conStatement.Conditions.MatchSetOptions = statement.Conditions.MatchSetOptions - } - if reqConditions.MatchAsPathLength != nil { - conStatement.Conditions.BgpConditions.AsPathLength = statement.Conditions.BgpConditions.AsPathLength - } - } - if reqActions != nil { - conStatement.Actions = statement.Actions - } - } - } - server.routingPolicy.PolicyDefinitionList = conPolicyList - server.handlePolicy(server.routingPolicy) - grpcReq.ResponseCh <- result - close(grpcReq.ResponseCh) - case REQ_POLICY_ROUTEPOLICY_DELETE: reqPolicy := grpcReq.Data.(*api.PolicyDefinition) conPolicyList := server.routingPolicy.PolicyDefinitionList @@ -1364,7 +1367,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { result.ResponseErr = fmt.Errorf("Policy Statment that has %v doesn't exist.", policyDef.StatementList[0].Name) } else { conPolicyList[idxPolicy].StatementList = - append(conPolicyList[idxPolicy].StatementList[:idxStatement], conPolicyList[idxPolicy].StatementList[idxStatement+1:]...) + append(conPolicyList[idxPolicy].StatementList[:idxStatement], conPolicyList[idxPolicy].StatementList[idxStatement+1:]...) } } } else { @@ -1382,23 +1385,23 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { } } server.routingPolicy.PolicyDefinitionList = conPolicyList - server.handlePolicy(server.routingPolicy) - grpcReq.ResponseCh <- result - close(grpcReq.ResponseCh) + } + server.handlePolicy(server.routingPolicy) + grpcReq.ResponseCh <- result + close(grpcReq.ResponseCh) +} +func (server *BgpServer) handleGrpcDelPolicies(grpcReq *GrpcRequest) { + result := &GrpcResponse{} + switch grpcReq.RequestType { + case REQ_POLICY_PREFIXES_DELETE: + server.routingPolicy.DefinedSets.PrefixSetList = make([]config.PrefixSet, 0) + case REQ_POLICY_NEIGHBORS_DELETE: + server.routingPolicy.DefinedSets.NeighborSetList = make([]config.NeighborSet, 0) case REQ_POLICY_ROUTEPOLICIES_DELETE: - result := &GrpcResponse{} server.routingPolicy.PolicyDefinitionList = make([]config.PolicyDefinition, 0) - server.handlePolicy(server.routingPolicy) - grpcReq.ResponseCh <- result - close(grpcReq.ResponseCh) - default: - errmsg := "Unknown request type" - result := &GrpcResponse{ - ResponseErr: fmt.Errorf(errmsg), - } - grpcReq.ResponseCh <- result - close(grpcReq.ResponseCh) } - return msgs + server.handlePolicy(server.routingPolicy) + grpcReq.ResponseCh <- result + close(grpcReq.ResponseCh) } |