From a88e0b5592b5f344981983d91f4f55a6d3f002bf Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Sun, 18 Oct 2015 15:06:33 +0900 Subject: api: support statement modification via grpc Signed-off-by: ISHIDA Wataru --- server/server.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'server/server.go') diff --git a/server/server.go b/server/server.go index e25d314f..69c27f14 100644 --- a/server/server.go +++ b/server/server.go @@ -1650,6 +1650,12 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { } } close(grpcReq.ResponseCh) + case REQ_MOD_STATEMENT: + err := server.handleGrpcModStatement(grpcReq) + grpcReq.ResponseCh <- &GrpcResponse{ + ResponseErr: err, + } + close(grpcReq.ResponseCh) case REQ_POLICY_ROUTEPOLICY, REQ_POLICY_ROUTEPOLICIES: info := server.policy.PolicyMap typ := grpcReq.RequestType @@ -1783,6 +1789,36 @@ func (server *BgpServer) handleGrpcGetStatement(grpcReq *GrpcRequest) error { return nil } +func (server *BgpServer) handleGrpcModStatement(grpcReq *GrpcRequest) error { + arg := grpcReq.Data.(*api.ModStatementArguments) + s, err := table.NewStatementFromApiStruct(arg.Statement, server.policy.DefinedSetMap) + if err != nil { + return err + } + m := server.policy.StatementMap + name := s.Name + d, ok := m[name] + switch arg.Operation { + case api.Operation_ADD: + if ok { + err = d.Add(s) + } else { + m[name] = s + } + case api.Operation_DEL: + err = d.Remove(s) + case api.Operation_DEL_ALL: + if server.policy.StatementInUse(d) { + return fmt.Errorf("can't delete. statement %s is in use", name) + } + delete(m, name) + case api.Operation_REPLACE: + err = d.Replace(s) + } + return err + +} + func (server *BgpServer) handleMrt(grpcReq *GrpcRequest) { now := uint32(time.Now().Unix()) view := "" -- cgit v1.2.3