summaryrefslogtreecommitdiffhomepage
path: root/server/grpc_server.go
diff options
context:
space:
mode:
authorNaoto Hanaue <hanaue.naoto@po.ntts.co.jp>2015-05-25 12:03:50 +0900
committerNaoto Hanaue <hanaue.naoto@po.ntts.co.jp>2015-05-26 17:31:58 +0900
commitcdf36e2a7d01c4aa713a1c3883d15a7c59964879 (patch)
tree2317c24811b1f9f0faae8fd44c6471b1a91b09b5 /server/grpc_server.go
parentfd4f6a91efb81646281ae8175433872627ec8611 (diff)
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
Diffstat (limited to 'server/grpc_server.go')
-rw-r--r--server/grpc_server.go50
1 files changed, 50 insertions, 0 deletions
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)