diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-10-04 21:48:45 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-10-09 23:04:26 +0900 |
commit | e832aeaf9b2b942ff39c36c85b736b13531af36f (patch) | |
tree | 29fdb92a9a031907088969034351d8a2d5e40d15 /server | |
parent | 840755be18f226b202759aea8318de20ccc32057 (diff) |
cli: add command to show global policy
$ gobgp global policy
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r-- | server/grpc_server.go | 11 | ||||
-rw-r--r-- | server/server.go | 61 |
2 files changed, 47 insertions, 25 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go index 6d3ddf29..b3da4b3d 100644 --- a/server/grpc_server.go +++ b/server/grpc_server.go @@ -88,6 +88,7 @@ const ( REQ_VRFS REQ_VRF_MOD REQ_MOD_PATH + REQ_GLOBAL_POLICY ) const GRPC_PORT = 8080 @@ -269,7 +270,15 @@ func (s *Server) ModPath(stream api.GobgpApi_ModPathServer) error { } func (s *Server) GetNeighborPolicy(ctx context.Context, arg *api.Arguments) (*api.ApplyPolicy, error) { - req := NewGrpcRequest(REQ_NEIGHBOR_POLICY, arg.Name, bgp.RouteFamily(arg.Rf), nil) + if arg.Resource != api.Resource_LOCAL && arg.Resource != api.Resource_GLOBAL { + return nil, fmt.Errorf("unsupported resource: %s", arg.Resource) + } + var req *GrpcRequest + if arg.Resource == api.Resource_LOCAL { + req = NewGrpcRequest(REQ_NEIGHBOR_POLICY, arg.Name, bgp.RouteFamily(arg.Rf), nil) + } else { + req = NewGrpcRequest(REQ_GLOBAL_POLICY, "", bgp.RouteFamily(arg.Rf), nil) + } s.bgpServerCh <- req res := <-req.ResponseCh diff --git a/server/server.go b/server/server.go index 7557cf70..cc5349a8 100644 --- a/server/server.go +++ b/server/server.go @@ -1539,11 +1539,9 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { grpcReq.ResponseCh <- result close(grpcReq.ResponseCh) - case REQ_NEIGHBOR_POLICY: - peer, err := server.checkNeighborRequest(grpcReq) - if err != nil { - break - } + case REQ_NEIGHBOR_POLICY, REQ_GLOBAL_POLICY: + var in, imp, exp []*api.PolicyDefinition + var inD, impD, expD api.RouteAction extract := func(policyNames []string) []*api.PolicyDefinition { pdList := server.routingPolicy.PolicyDefinitions.PolicyDefinitionList @@ -1565,31 +1563,46 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { 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. - conImportPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.ImportPolicy - resImportPolicies := extract(conImportPolicyNames) + if grpcReq.RequestType == REQ_NEIGHBOR_POLICY { + peer, err := server.checkNeighborRequest(grpcReq) + if err != nil { + break + } + // 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. + conImportPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.ImportPolicy + imp = extract(conImportPolicyNames) + + // 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. + conExportPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.ExportPolicy + exp = extract(conExportPolicyNames) - // 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. - conExportPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.ExportPolicy - resExportPolicies := extract(conExportPolicyNames) + inPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.InPolicy + in = extract(inPolicyNames) - inPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.InPolicy - resInPolicies := extract(inPolicyNames) + impD = peer.GetDefaultPolicy(table.POLICY_DIRECTION_IMPORT).ToApiStruct() + expD = peer.GetDefaultPolicy(table.POLICY_DIRECTION_EXPORT).ToApiStruct() + inD = peer.GetDefaultPolicy(table.POLICY_DIRECTION_IN).ToApiStruct() + } else { + names := server.bgpConfig.Global.ApplyPolicy.ApplyPolicyConfig.ImportPolicy + imp = extract(names) - defaultImportPolicy := peer.GetDefaultPolicy(table.POLICY_DIRECTION_IMPORT).ToApiStruct() - defaultExportPolicy := peer.GetDefaultPolicy(table.POLICY_DIRECTION_EXPORT).ToApiStruct() - defaultInPolicy := peer.GetDefaultPolicy(table.POLICY_DIRECTION_IN).ToApiStruct() + names = server.bgpConfig.Global.ApplyPolicy.ApplyPolicyConfig.ExportPolicy + exp = extract(names) + + impD = server.globalRib.GetDefaultPolicy(table.POLICY_DIRECTION_IMPORT).ToApiStruct() + expD = server.globalRib.GetDefaultPolicy(table.POLICY_DIRECTION_EXPORT).ToApiStruct() + } result := &GrpcResponse{ Data: &api.ApplyPolicy{ - DefaultImportPolicy: defaultImportPolicy, - ImportPolicies: resImportPolicies, - DefaultExportPolicy: defaultExportPolicy, - ExportPolicies: resExportPolicies, - DefaultInPolicy: defaultInPolicy, - InPolicies: resInPolicies, + DefaultImportPolicy: impD, + ImportPolicies: imp, + DefaultExportPolicy: expD, + ExportPolicies: exp, + DefaultInPolicy: inD, + InPolicies: in, }, } grpcReq.ResponseCh <- result |