diff options
-rw-r--r-- | server/grpc_server.go | 12 | ||||
-rw-r--r-- | server/server.go | 83 |
2 files changed, 51 insertions, 44 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go index 8c938fd3..cbe5bf55 100644 --- a/server/grpc_server.go +++ b/server/grpc_server.go @@ -471,19 +471,11 @@ func (s *Server) ShutdownNeighbor(ctx context.Context, arg *api.ShutdownNeighbor } func (s *Server) EnableNeighbor(ctx context.Context, arg *api.EnableNeighborRequest) (*api.EnableNeighborResponse, error) { - d, err := s.neighbor(REQ_NEIGHBOR_ENABLE, arg.Address, arg) - if err != nil { - return nil, err - } - return d.(*api.EnableNeighborResponse), err + return &api.EnableNeighborResponse{}, s.bgpServer.EnableNeighbor(arg.Address) } func (s *Server) DisableNeighbor(ctx context.Context, arg *api.DisableNeighborRequest) (*api.DisableNeighborResponse, error) { - d, err := s.neighbor(REQ_NEIGHBOR_DISABLE, arg.Address, arg) - if err != nil { - return nil, err - } - return d.(*api.DisableNeighborResponse), err + return &api.DisableNeighborResponse{}, s.bgpServer.DisableNeighbor(arg.Address) } func (s *Server) api2PathList(resource api.Resource, ApiPathList []*api.Path) ([]*table.Path, error) { diff --git a/server/server.go b/server/server.go index f2fcddd2..5d01ecfa 100644 --- a/server/server.go +++ b/server/server.go @@ -1623,40 +1623,6 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) { } grpcReq.ResponseCh <- &GrpcResponse{Data: &api.SoftResetNeighborResponse{}} close(grpcReq.ResponseCh) - - case REQ_NEIGHBOR_ENABLE, REQ_NEIGHBOR_DISABLE: - peer, err1 := server.checkNeighborRequest(grpcReq) - if err1 != nil { - break - } - result := &GrpcResponse{} - if grpcReq.RequestType == REQ_NEIGHBOR_ENABLE { - select { - case peer.fsm.adminStateCh <- ADMIN_STATE_UP: - log.WithFields(log.Fields{ - "Topic": "Peer", - "Key": peer.fsm.pConf.Config.NeighborAddress, - }).Debug("ADMIN_STATE_UP requested") - default: - log.Warning("previous request is still remaining. : ", peer.fsm.pConf.Config.NeighborAddress) - result.ResponseErr = fmt.Errorf("previous request is still remaining %v", peer.fsm.pConf.Config.NeighborAddress) - } - result.Data = &api.EnableNeighborResponse{} - } else { - select { - case peer.fsm.adminStateCh <- ADMIN_STATE_DOWN: - log.WithFields(log.Fields{ - "Topic": "Peer", - "Key": peer.fsm.pConf.Config.NeighborAddress, - }).Debug("ADMIN_STATE_DOWN requested") - default: - log.Warning("previous request is still remaining. : ", peer.fsm.pConf.Config.NeighborAddress) - result.ResponseErr = fmt.Errorf("previous request is still remaining %v", peer.fsm.pConf.Config.NeighborAddress) - } - result.Data = &api.DisableNeighborResponse{} - } - grpcReq.ResponseCh <- result - close(grpcReq.ResponseCh) case REQ_VALIDATE_RIB: server.handleValidateRib(grpcReq) case REQ_INITIALIZE_RPKI: @@ -1951,6 +1917,55 @@ func (s *BgpServer) ResetNeighbor(addr string) (err error) { return err } +func (s *BgpServer) setAdminState(addr string, enable bool) error { + peers, err := s.addrToPeers(addr) + if err == nil { + for _, peer := range peers { + f := func(state AdminState, message string) { + select { + case peer.fsm.adminStateCh <- state: + log.WithFields(log.Fields{ + "Topic": "Peer", + "Key": peer.fsm.pConf.Config.NeighborAddress, + }).Debug(message) + default: + log.Warning("previous request is still remaining. : ", peer.fsm.pConf.Config.NeighborAddress) + } + } + if enable { + f(ADMIN_STATE_UP, "ADMIN_STATE_UP requested") + } else { + f(ADMIN_STATE_DOWN, "ADMIN_STATE_DOWN requested") + } + } + } + return err +} + +func (s *BgpServer) EnableNeighbor(addr string) (err error) { + ch := make(chan struct{}) + defer func() { <-ch }() + + s.mgmtCh <- func() { + defer close(ch) + + err = s.setAdminState(addr, true) + } + return err +} + +func (s *BgpServer) DisableNeighbor(addr string) (err error) { + ch := make(chan struct{}) + defer func() { <-ch }() + + s.mgmtCh <- func() { + defer close(ch) + + err = s.setAdminState(addr, false) + } + return err +} + func (s *BgpServer) GetDefinedSet(typ table.DefinedType) (sets *config.DefinedSets, err error) { ch := make(chan struct{}) defer func() { <-ch }() |