summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-07-27 16:27:09 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-07-27 16:27:09 +0900
commit5565e89ffcd46c20af6891bec533ca12e0c08d9c (patch)
tree1ddfe0a539395adeef3e8537abbb18a223343a53
parent474f7c3a4d992b4597536e36a2f1597db418580f (diff)
move gRPC-related code for REQ_NEIGHBOR_SHUTDOWN to grpc_server.go
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--server/grpc_server.go6
-rw-r--r--server/server.go51
2 files changed, 39 insertions, 18 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go
index e69b2b0d..73068b55 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -471,11 +471,7 @@ func (s *Server) SoftResetNeighbor(ctx context.Context, arg *api.SoftResetNeighb
}
func (s *Server) ShutdownNeighbor(ctx context.Context, arg *api.ShutdownNeighborRequest) (*api.ShutdownNeighborResponse, error) {
- d, err := s.neighbor(REQ_NEIGHBOR_SHUTDOWN, arg.Address, arg)
- if err != nil {
- return nil, err
- }
- return d.(*api.ShutdownNeighborResponse), err
+ return &api.ShutdownNeighborResponse{}, s.bgpServer.ShutdownNeighbor(arg.Address)
}
func (s *Server) EnableNeighbor(ctx context.Context, arg *api.EnableNeighborRequest) (*api.EnableNeighborResponse, error) {
diff --git a/server/server.go b/server/server.go
index bddde1e2..aa781dbe 100644
--- a/server/server.go
+++ b/server/server.go
@@ -1511,19 +1511,6 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) {
Data: paths,
}
close(grpcReq.ResponseCh)
- case REQ_NEIGHBOR_SHUTDOWN:
- peers, err := reqToPeers(grpcReq)
- if err != nil {
- break
- }
- logOp(grpcReq.Name, "Neighbor shutdown")
- m := bgp.NewBGPNotificationMessage(bgp.BGP_ERROR_CEASE, bgp.BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN, nil)
- for _, peer := range peers {
- sendFsmOutgoingMsg(peer, nil, m, false)
- }
- grpcReq.ResponseCh <- &GrpcResponse{Data: &api.ShutdownNeighborResponse{}}
- close(grpcReq.ResponseCh)
-
case REQ_NEIGHBOR_RESET:
peers, err := reqToPeers(grpcReq)
if err != nil {
@@ -1917,6 +1904,44 @@ func (s *BgpServer) UpdateNeighbor(c *config.Neighbor) (policyUpdated bool, err
return policyUpdated, err
}
+func (s *BgpServer) addrToPeers(address string) (l []*Peer, err error) {
+ if address == "all" {
+ for _, p := range s.neighborMap {
+ l = append(l, p)
+ }
+ return l, nil
+ }
+ peer, found := s.neighborMap[address]
+ if !found {
+ return l, fmt.Errorf("Neighbor that has %v doesn't exist.", address)
+ }
+ return []*Peer{peer}, nil
+}
+
+func (s *BgpServer) ShutdownNeighbor(address string) (err error) {
+ ch := make(chan struct{})
+ defer func() { <-ch }()
+
+ s.mgmtCh <- func() {
+ defer close(ch)
+
+ log.WithFields(log.Fields{
+ "Topic": "Operation",
+ "Key": address,
+ }).Info("Neighbor shutdown")
+
+ l := []*Peer{}
+ l, err = s.addrToPeers(address)
+ if err == nil {
+ m := bgp.NewBGPNotificationMessage(bgp.BGP_ERROR_CEASE, bgp.BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN, nil)
+ for _, peer := range l {
+ sendFsmOutgoingMsg(peer, nil, m, false)
+ }
+ }
+ }
+ return err
+}
+
func (s *BgpServer) GetDefinedSet(typ table.DefinedType) (sets *config.DefinedSets, err error) {
ch := make(chan struct{})
defer func() { <-ch }()