diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2017-01-31 09:13:27 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-02-03 22:47:34 -0800 |
commit | 64360afd459436a49a1f1254cca21fffbe6945b5 (patch) | |
tree | 9b61d1357d73f8be7e8501e78c606eb41cda94d6 /server/fsm.go | |
parent | ada5cb1db61b481378ad78ba2d78bf36eff67e2e (diff) |
cli: Administrative Shutdown Communication on disable neighbor
This patch adds "--reason" option support into the disable neighbor command
which can specify "Administrative Shutdown Communication" on the BGP Cease
NOTIFICATION message.
Usage:
$ gobgp neighbor <neighbor address> disable --reason "some messages"
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'server/fsm.go')
-rw-r--r-- | server/fsm.go | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/server/fsm.go b/server/fsm.go index a8ca047a..2f93ff03 100644 --- a/server/fsm.go +++ b/server/fsm.go @@ -102,6 +102,11 @@ func (s AdminState) String() string { } } +type AdminStateOperation struct { + State AdminState + Communication []byte +} + var fsmVersion uint type FSM struct { @@ -115,7 +120,7 @@ type FSM struct { idleHoldTime float64 opensentHoldTime float64 adminState AdminState - adminStateCh chan AdminState + adminStateCh chan AdminStateOperation getActiveCh chan struct{} h *FSMHandler rfMap map[bgp.RouteFamily]bool @@ -192,7 +197,7 @@ func NewFSM(gConf *config.Global, pConf *config.Neighbor, policy *table.RoutingP connCh: make(chan net.Conn, 1), opensentHoldTime: float64(HOLDTIME_OPENSENT), adminState: adminState, - adminStateCh: make(chan AdminState, 1), + adminStateCh: make(chan AdminStateOperation, 1), getActiveCh: make(chan struct{}), rfMap: make(map[bgp.RouteFamily]bool), capMap: make(map[bgp.BGPCapabilityCode][]bgp.ParameterCapabilityInterface), @@ -441,10 +446,10 @@ func (h *FSMHandler) idle() (bgp.FSMState, FsmStateReason) { log.WithFields(log.Fields{"Topic": "Peer"}).Debug("IdleHoldTimer expired, but stay at idle because the admin state is DOWN") } - case s := <-fsm.adminStateCh: - err := h.changeAdminState(s) + case stateOp := <-fsm.adminStateCh: + err := h.changeAdminState(stateOp.State) if err == nil { - switch s { + switch stateOp.State { case ADMIN_STATE_DOWN: // stop idle hold timer idleHoldTimer.Stop() @@ -492,10 +497,10 @@ func (h *FSMHandler) active() (bgp.FSMState, FsmStateReason) { } case err := <-h.errorCh: return bgp.BGP_FSM_IDLE, err - case s := <-fsm.adminStateCh: - err := h.changeAdminState(s) + case stateOp := <-fsm.adminStateCh: + err := h.changeAdminState(stateOp.State) if err == nil { - switch s { + switch stateOp.State { case ADMIN_STATE_DOWN: return bgp.BGP_FSM_IDLE, FSM_ADMIN_DOWN case ADMIN_STATE_UP: @@ -503,7 +508,7 @@ func (h *FSMHandler) active() (bgp.FSMState, FsmStateReason) { "Topic": "Peer", "Key": fsm.pConf.Config.NeighborAddress, "State": fsm.state.String(), - "AdminState": s.String(), + "AdminState": stateOp.State.String(), }).Panic("code logic bug") } } @@ -932,10 +937,10 @@ func (h *FSMHandler) opensent() (bgp.FSMState, FsmStateReason) { fsm.sendNotification(bgp.BGP_ERROR_HOLD_TIMER_EXPIRED, 0, nil, "hold timer expired") h.t.Kill(nil) return bgp.BGP_FSM_IDLE, FSM_HOLD_TIMER_EXPIRED - case s := <-fsm.adminStateCh: - err := h.changeAdminState(s) + case stateOp := <-fsm.adminStateCh: + err := h.changeAdminState(stateOp.State) if err == nil { - switch s { + switch stateOp.State { case ADMIN_STATE_DOWN: h.conn.Close() return bgp.BGP_FSM_IDLE, FSM_ADMIN_DOWN @@ -944,7 +949,7 @@ func (h *FSMHandler) opensent() (bgp.FSMState, FsmStateReason) { "Topic": "Peer", "Key": fsm.pConf.Config.NeighborAddress, "State": fsm.state.String(), - "AdminState": s.String(), + "AdminState": stateOp.State.String(), }).Panic("code logic bug") } } @@ -1043,10 +1048,10 @@ func (h *FSMHandler) openconfirm() (bgp.FSMState, FsmStateReason) { fsm.sendNotification(bgp.BGP_ERROR_HOLD_TIMER_EXPIRED, 0, nil, "hold timer expired") h.t.Kill(nil) return bgp.BGP_FSM_IDLE, FSM_HOLD_TIMER_EXPIRED - case s := <-fsm.adminStateCh: - err := h.changeAdminState(s) + case stateOp := <-fsm.adminStateCh: + err := h.changeAdminState(stateOp.State) if err == nil { - switch s { + switch stateOp.State { case ADMIN_STATE_DOWN: h.conn.Close() return bgp.BGP_FSM_IDLE, FSM_ADMIN_DOWN @@ -1055,7 +1060,7 @@ func (h *FSMHandler) openconfirm() (bgp.FSMState, FsmStateReason) { "Topic": "Peer", "Key": fsm.pConf.Config.NeighborAddress, "State": fsm.state.String(), - "AdminState": s.String(), + "AdminState": stateOp.State.String(), }).Panic("code logic bug") } } @@ -1253,12 +1258,12 @@ func (h *FSMHandler) established() (bgp.FSMState, FsmStateReason) { if fsm.pConf.Timers.State.NegotiatedHoldTime != 0 { holdTimer.Reset(time.Second * time.Duration(fsm.pConf.Timers.State.NegotiatedHoldTime)) } - case s := <-fsm.adminStateCh: - err := h.changeAdminState(s) + case stateOp := <-fsm.adminStateCh: + err := h.changeAdminState(stateOp.State) if err == nil { - switch s { + switch stateOp.State { case ADMIN_STATE_DOWN: - m := bgp.NewBGPNotificationMessage(bgp.BGP_ERROR_CEASE, bgp.BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN, nil) + m := bgp.NewBGPNotificationMessage(bgp.BGP_ERROR_CEASE, bgp.BGP_ERROR_SUB_ADMINISTRATIVE_SHUTDOWN, stateOp.Communication) h.outgoing.In() <- &FsmOutgoingMsg{Notification: m} } } |