summaryrefslogtreecommitdiffhomepage
path: root/server/grpc_server.go
diff options
context:
space:
mode:
authorNaoto Hanaue <hanaue.naoto@po.ntts.co.jp>2015-05-15 15:11:11 +0900
committerNaoto Hanaue <hanaue.naoto@po.ntts.co.jp>2015-05-26 17:28:40 +0900
commitfa5d2fe25ee3670a5ba2e66431dfd617f48737af (patch)
tree69241afd5e5c39fb3e9896cab546cec836e35cec /server/grpc_server.go
parentdffb57e43dcdbd419b49fcab089ad4c68342c76a (diff)
cli: add the add/del commands to neighbor condition
% gobgp -u 10.0.255.1 policy neighbor Name Address ns0 10.0.0.2 10.0.0.3 ns1 2001::192:168:0:2 % gobgp -u 10.0.255.1 policy neighbor add ns2 10.0.0.4 % gobgp -u 10.0.255.1 policy neighbor del ns1 % gobgp -u 10.0.255.1 policy neighbor Name Address ns0 10.0.0.2 10.0.0.3 ns2 10.0.0.4
Diffstat (limited to 'server/grpc_server.go')
-rw-r--r--server/grpc_server.go46
1 files changed, 43 insertions, 3 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go
index d8188c56..dbd1be1e 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -51,6 +51,9 @@ const (
REQ_POLICY_PREFIXES_DELETE
REQ_POLICY_NEIGHBOR
REQ_POLICY_NEIGHBORS
+ REQ_POLICY_NEIGHBOR_ADD
+ REQ_POLICY_NEIGHBOR_DELETE
+ REQ_POLICY_NEIGHBORS_DELETE
REQ_POLICY_ROUTEPOLICIES
REQ_POLICY_ROUTEPOLICY
)
@@ -341,6 +344,7 @@ func (s *Server) getPolicy(arg *api.PolicyArguments) (interface{}, error) {
func (s *Server) modPolicy(arg *api.PolicyArguments, stream interface{}) error {
var rf bgp.RouteFamily
var reqType int
+ var err error
switch arg.Resource {
case api.Resource_POLICY_PREFIX:
switch arg.Operation {
@@ -361,17 +365,38 @@ func (s *Server) modPolicy(arg *api.PolicyArguments, stream interface{}) error {
log.Debug(err.Error())
return err
}
-
- err := stream.(api.Grpc_ModPolicyPrefixServer).Send(&api.Error{
+ err = stream.(api.Grpc_ModPolicyPrefixServer).Send(&api.Error{
Code: api.Error_SUCCESS,
})
+ case api.Resource_POLICY_NEIGHBOR:
+ switch arg.Operation {
+ case api.Operation_ADD:
+ reqType = REQ_POLICY_NEIGHBOR_ADD
+ case api.Operation_DEL:
+ reqType = REQ_POLICY_NEIGHBOR_DELETE
+ case api.Operation_DEL_ALL:
+ reqType = REQ_POLICY_NEIGHBORS_DELETE
+ default:
+ return fmt.Errorf("unsupported operation: %s", arg.Operation)
+ }
+ req := NewGrpcRequest(reqType, "", rf, arg.NeighborSet)
+ s.bgpServerCh <- req
- if err != nil {
+ res := <-req.ResponseCh
+ if err := res.Err(); err != nil {
+ log.Debug(err.Error())
return err
}
+ err = stream.(api.Grpc_ModPolicyNeighborServer).Send(&api.Error{
+ Code: api.Error_SUCCESS,
+ })
default:
return fmt.Errorf("unsupported resource type: %v", arg.Resource)
}
+
+ if err != nil {
+ return err
+ }
return nil
}
@@ -421,6 +446,21 @@ func (s *Server) GetPolicyNeighbor(ctx context.Context, arg *api.PolicyArguments
return data.(*api.NeighborSet), nil
}
+func (s *Server) ModPolicyNeighbor(stream api.Grpc_ModPolicyNeighborServer) error {
+ for {
+ arg, err := stream.Recv()
+ if err == io.EOF {
+ return nil
+ } else if err != nil {
+ return err
+ }
+ if err := s.modPolicy(arg, stream); err != nil {
+ return err
+ }
+ return nil
+ }
+}
+
func (s *Server) GetPolicyRoutePolicies(arg *api.PolicyArguments, stream api.Grpc_GetPolicyRoutePoliciesServer) error {
if err := s.getPolicies(REQ_POLICY_ROUTEPOLICIES, arg, stream); err != nil {
return err