diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-10-18 18:03:04 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-10-20 10:33:10 +0900 |
commit | 95e68a8d8824874d0919435d7829fdfd2afdc6bc (patch) | |
tree | cc6d231744307f02ac73c97db52d7e8310870238 /server/server.go | |
parent | f834e421284080a8d4b9150d19148be3b886779e (diff) |
api/cli: refactor api to retrieve policy
make it similar to other policy api
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server/server.go')
-rw-r--r-- | server/server.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/server/server.go b/server/server.go index 69c27f14..91466753 100644 --- a/server/server.go +++ b/server/server.go @@ -1656,6 +1656,13 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { ResponseErr: err, } close(grpcReq.ResponseCh) + case REQ_POLICY: + if err := server.handleGrpcGetPolicy(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 @@ -1819,6 +1826,28 @@ func (server *BgpServer) handleGrpcModStatement(grpcReq *GrpcRequest) error { } +func (server *BgpServer) handleGrpcGetPolicy(grpcReq *GrpcRequest) error { + arg := grpcReq.Data.(*api.Policy) + name := arg.Name + found := false + for _, s := range server.policy.PolicyMap { + if name != "" && name != s.Name() { + continue + } + grpcReq.ResponseCh <- &GrpcResponse{ + Data: s.ToApiStruct(), + } + found = true + if name != "" { + break + } + } + if !found { + return fmt.Errorf("not found %s", name) + } + return nil +} + func (server *BgpServer) handleMrt(grpcReq *GrpcRequest) { now := uint32(time.Now().Unix()) view := "" |