diff options
author | Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp> | 2015-02-15 17:46:31 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-02-16 10:13:40 +0900 |
commit | 560fa6cbd5c6ddb8fcd5c262b720459c064a9b23 (patch) | |
tree | 94b407108e89687ef010504938edd14d104c29f3 /server/peer.go | |
parent | 161ea3b25709820991b1b1e17e621eb9a2082865 (diff) |
peer: support enable/disable
Diffstat (limited to 'server/peer.go')
-rw-r--r-- | server/peer.go | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/server/peer.go b/server/peer.go index d04947fa..61a229ee 100644 --- a/server/peer.go +++ b/server/peer.go @@ -199,7 +199,17 @@ func (peer *Peer) handleREST(restReq *api.RestRequest) { result := &api.RestResponse{} switch restReq.RequestType { case api.REQ_LOCAL_RIB: - j, _ := json.Marshal(peer.rib.Tables[peer.rf]) + var t table.Table + if peer.fsm.adminState == ADMIN_STATE_DOWN { + if peer.rf == bgp.RF_IPv4_UC { + t = table.NewIPv4Table(0) + } else { + t = table.NewIPv6Table(0) + } + } else { + t = peer.rib.Tables[peer.rf] + } + j, _ := json.Marshal(t) result.Data = j case api.REQ_NEIGHBOR_SHUTDOWN: peer.outgoing <- bgp.NewBGPNotificationMessage(bgp.BGP_ERROR_CEASE, bgp.BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN, nil) @@ -215,9 +225,7 @@ func (peer *Peer) handleREST(restReq *api.RestRequest) { case api.REQ_NEIGHBOR_SOFT_RESET_OUT: pathList := peer.adjRib.GetOutPathList(peer.rf) peer.sendMessages(table.CreateUpdateMsgFromPaths(pathList)) - case api.REQ_ADJ_RIB_IN: - fallthrough - case api.REQ_ADJ_RIB_OUT: + case api.REQ_ADJ_RIB_IN, api.REQ_ADJ_RIB_OUT: rfs := []bgp.RouteFamily{bgp.RF_IPv4_UC, bgp.RF_IPv6_UC} adjrib := make(map[string][]table.Path) @@ -236,6 +244,35 @@ func (peer *Peer) handleREST(restReq *api.RestRequest) { } j, _ := json.Marshal(adjrib) result.Data = j + case api.REQ_NEIGHBOR_ENABLE, api.REQ_NEIGHBOR_DISABLE: + r := make(map[string]string) + if restReq.RequestType == api.REQ_NEIGHBOR_ENABLE { + select { + case peer.fsm.adminStateCh <- ADMIN_STATE_UP: + log.WithFields(log.Fields{ + "Topic": "Peer", + "Key": peer.peerConfig.NeighborAddress, + }).Debug("ADMIN_STATE_UP requested") + r["result"] = "ADMIN_STATE_UP" + default: + log.Warning("previous request is still remaining. : ", peer.peerConfig.NeighborAddress) + r["result"] = "previous request is still remaining" + } + } else { + select { + case peer.fsm.adminStateCh <- ADMIN_STATE_DOWN: + log.WithFields(log.Fields{ + "Topic": "Peer", + "Key": peer.peerConfig.NeighborAddress, + }).Debug("ADMIN_STATE_DOWN requested") + r["result"] = "ADMIN_STATE_DOWN" + default: + log.Warning("previous request is still remaining. : ", peer.peerConfig.NeighborAddress) + r["result"] = "previous request is still remaining" + } + } + j, _ := json.Marshal(r) + result.Data = j } restReq.ResponseCh <- result close(restReq.ResponseCh) @@ -352,6 +389,12 @@ func (peer *Peer) loop() error { s.peerMsgCh <- pm } } + + // clear counter + if h.fsm.adminState == ADMIN_STATE_DOWN { + h.fsm.peerConfig.BgpNeighborCommonState = config.BgpNeighborCommonStateType{} + } + case FSM_MSG_BGP_MESSAGE: switch m := e.MsgData.(type) { case *bgp.MessageError: |