summaryrefslogtreecommitdiffhomepage
path: root/server/server.go
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-10-16 15:32:28 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-10-20 10:33:10 +0900
commit68635d8f0613fc9e13edc7065c63bed3e00851ca (patch)
treee2f82d205d8337ffe1a903951b7d3a69649c5eec /server/server.go
parent722975bfafdd723160dced623936c361475c9bff (diff)
api: support defined set modification via grpc
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server/server.go')
-rw-r--r--server/server.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/server/server.go b/server/server.go
index f60d4d6e..8867186c 100644
--- a/server/server.go
+++ b/server/server.go
@@ -1637,6 +1637,13 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
}
}
close(grpcReq.ResponseCh)
+ case REQ_MOD_DEFINED_SET:
+ if err := server.handleGrpcModDefinedSet(grpcReq); err != nil {
+ grpcReq.ResponseCh <- &GrpcResponse{
+ ResponseErr: err,
+ }
+ }
+ close(grpcReq.ResponseCh)
case REQ_POLICY_ROUTEPOLICY, REQ_POLICY_ROUTEPOLICIES:
info := server.policy.PolicyMap
typ := grpcReq.RequestType
@@ -1705,6 +1712,44 @@ func (server *BgpServer) handleGrpcGetDefinedSet(grpcReq *GrpcRequest) error {
return nil
}
+func (server *BgpServer) handleGrpcModDefinedSet(grpcReq *GrpcRequest) error {
+ arg := grpcReq.Data.(*api.ModDefinedSetArguments)
+ set := arg.Set
+ typ := table.DefinedType(set.Type)
+ name := set.Name
+ var err error
+ m, ok := server.policy.DefinedSetMap[typ]
+ if !ok {
+ return fmt.Errorf("invalid defined-set type: %d", typ)
+ }
+ d, ok := m[name]
+ if arg.Operation != api.Operation_ADD && !ok {
+ return fmt.Errorf("not found defined-set: %s", name)
+ }
+ s, err := table.NewDefinedSetFromApiStruct(set)
+ if err != nil {
+ return err
+ }
+ switch arg.Operation {
+ case api.Operation_ADD:
+ if ok {
+ err = d.Append(s)
+ } else {
+ m[name] = s
+ }
+ case api.Operation_DEL:
+ err = d.Remove(s)
+ case api.Operation_DEL_ALL:
+ if server.policy.InUse(d) {
+ return fmt.Errorf("can't delete. defined-set %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 := ""