diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-07-26 11:57:55 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-07-26 11:57:55 +0900 |
commit | f623f8d538cd0ce9b31a97248ac862bb1c8b8b7c (patch) | |
tree | d8fd8c23792c0248583836f38b6d0dc1eefb5028 | |
parent | 9b1dac34bb22f159babf352bf43d7e3ffdf157e5 (diff) |
move gRPC-related code for REQ_STOP_SERVER to grpc_server.go
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | server/grpc_server.go | 6 | ||||
-rw-r--r-- | server/server.go | 41 |
2 files changed, 22 insertions, 25 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go index 61a80f77..8ad5c3c8 100644 --- a/server/grpc_server.go +++ b/server/grpc_server.go @@ -1740,11 +1740,7 @@ func (s *Server) StartServer(ctx context.Context, arg *api.StartServerRequest) ( } func (s *Server) StopServer(ctx context.Context, arg *api.StopServerRequest) (*api.StopServerResponse, error) { - d, err := s.get(REQ_STOP_SERVER, arg) - if err != nil { - return nil, err - } - return d.(*api.StopServerResponse), err + return &api.StopServerResponse{}, s.bgpServer.Stop() } type GrpcRequest struct { diff --git a/server/server.go b/server/server.go index dc8ab200..6b15527a 100644 --- a/server/server.go +++ b/server/server.go @@ -1317,19 +1317,6 @@ func (server *BgpServer) handleModConfig(grpcReq *GrpcRequest) error { c = &b.Global case *config.Global: c = arg - case *api.StopServerRequest: - for k, _ := range server.neighborMap { - err := server.deleteNeighbor(&config.Neighbor{Config: config.NeighborConfig{ - NeighborAddress: k}}, bgp.BGP_ERROR_CEASE, bgp.BGP_ERROR_SUB_PEER_DECONFIGURED) - if err != nil { - return err - } - } - for _, l := range server.listeners { - l.Close() - } - server.bgpConfig.Global = config.Global{} - return nil } if server.bgpConfig.Global.Config.As != 0 { @@ -1362,6 +1349,27 @@ func (server *BgpServer) handleModConfig(grpcReq *GrpcRequest) error { return nil } +func (s *BgpServer) Stop() (err error) { + ch := make(chan struct{}) + defer func() { <-ch }() + + s.mgmtCh <- func() { + defer close(ch) + + for k, _ := range s.neighborMap { + if err = s.deleteNeighbor(&config.Neighbor{Config: config.NeighborConfig{ + NeighborAddress: k}}, bgp.BGP_ERROR_CEASE, bgp.BGP_ERROR_SUB_PEER_DECONFIGURED); err != nil { + return + } + } + for _, l := range s.listeners { + l.Close() + } + s.bgpConfig.Global = config.Global{} + } + return nil +} + func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) { logOp := func(addr string, action string) { log.WithFields(log.Fields{ @@ -1406,13 +1414,6 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) { Data: &api.StartServerResponse{}, } close(grpcReq.ResponseCh) - case REQ_STOP_SERVER: - err := server.handleModConfig(grpcReq) - grpcReq.ResponseCh <- &GrpcResponse{ - ResponseErr: err, - Data: &api.StopServerResponse{}, - } - close(grpcReq.ResponseCh) case REQ_GLOBAL_RIB, REQ_LOCAL_RIB: arg := grpcReq.Data.(*api.GetRibRequest) rib := server.globalRib |