From cdf36e2a7d01c4aa713a1c3883d15a7c59964879 Mon Sep 17 00:00:00 2001 From: Naoto Hanaue Date: Mon, 25 May 2015 12:03:50 +0900 Subject: cli: add the add/del commands to policy of neighbor % gobgp -u 10.0.255.1 neighbor 10.0.0.3 policy DefaultImportPolicy: ACCEPT DefaultExportPolicy: ACCEPT ImportPolicies: PolicyName policy1: StatementName st0: Conditions: PrefixSet: ps2 192.168.20.0/24 NeighborSet: ns0 10.0.0.2 10.0.0.3 AsPathLength: eq 5 MatchOption: ALL Actions: ACCEPT ExportPolicies: % gobgp -u 10.0.255.1 neighbor 10.0.0.3 policy add export policy0 reject % gobgp -u 10.0.255.1 neighbor 10.0.0.3 policy del import % gobgp -u 10.0.255.1 neighbor 10.0.0.3 policy DefaultImportPolicy: ACCEPT DefaultExportPolicy: REJECT ImportPolicies: ExportPolicies: PolicyName policy0: StatementName st0: Conditions: PrefixSet: ps0 192.168.0.0/16 16..24 NeighborSet: ns2 10.0.0.4 AsPathLength: MatchOption: ALL Actions: REJECT --- server/grpc_server.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'server/grpc_server.go') diff --git a/server/grpc_server.go b/server/grpc_server.go index f1d040a2..79a3dc4d 100644 --- a/server/grpc_server.go +++ b/server/grpc_server.go @@ -41,6 +41,10 @@ const ( REQ_NEIGHBOR_ENABLE REQ_NEIGHBOR_DISABLE REQ_NEIGHBOR_POLICY + REQ_NEIGHBOR_POLICY_ADD_IMPORT + REQ_NEIGHBOR_POLICY_ADD_EXPORT + REQ_NEIGHBOR_POLICY_DEL_IMPORT + REQ_NEIGHBOR_POLICY_DEL_EXPORT REQ_GLOBAL_RIB REQ_GLOBAL_ADD REQ_GLOBAL_DELETE @@ -293,6 +297,52 @@ func (s *Server) GetNeighborPolicy(ctx context.Context, arg *api.Arguments) (*ap return res.Data.(*api.ApplyPolicy), nil } +func (s *Server) ModNeighborPolicy(stream api.Grpc_ModNeighborPolicyServer) error { + for { + arg, err := stream.Recv() + if err == io.EOF { + return nil + } else if err != nil { + return err + } + + if arg.Resource != api.Resource_POLICY_ROUTEPOLICY { + return fmt.Errorf("unsupported resource: %s", arg.Resource) + } + var rf bgp.RouteFamily + var reqType int + switch arg.Operation { + case api.Operation_ADD: + switch arg.Name { + case "import": + reqType = REQ_NEIGHBOR_POLICY_ADD_IMPORT + case "export": + reqType = REQ_NEIGHBOR_POLICY_ADD_EXPORT + } + case api.Operation_DEL: + switch arg.Name { + case "import": + reqType = REQ_NEIGHBOR_POLICY_DEL_IMPORT + case "export": + reqType = REQ_NEIGHBOR_POLICY_DEL_EXPORT + } + } + req := NewGrpcRequest(reqType, arg.RouterId, rf, arg.ApplyPolicy) + s.bgpServerCh <- req + res := <-req.ResponseCh + if err := res.Err(); err != nil { + log.Debug(err.Error()) + return err + } + err = stream.Send(&api.Error{ + Code: api.Error_SUCCESS, + }) + if err != nil { + return err + } + } +} + func (s *Server) getPolicies(reqType int, arg *api.PolicyArguments, stream interface{}) error { var rf bgp.RouteFamily req := NewGrpcRequest(reqType, "", rf, nil) -- cgit v1.2.3