summaryrefslogtreecommitdiffhomepage
path: root/server/server.go
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 /server/server.go
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>
Diffstat (limited to 'server/server.go')
-rw-r--r--server/server.go51
1 files changed, 38 insertions, 13 deletions
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 }()