summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-01-29 11:11:54 +0900
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-01-29 11:38:24 +0900
commit0ce9409f1768f5b4a0bc4b3e3e5593ca773056fa (patch)
treed1362f1c02b1e776c614b25ab20c685419ef6ede
parent8285553257512e2f732f9e71e7576b53cdb5186f (diff)
server: remove a redundant FSM negotiatedHoldtime field
use config.TimerState struct instead Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--server/fsm.go64
-rw-r--r--server/fsm_test.go16
-rw-r--r--server/peer.go10
3 files changed, 44 insertions, 46 deletions
diff --git a/server/fsm.go b/server/fsm.go
index 0511f0af..872f8b8c 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -116,26 +116,25 @@ func (s AdminState) String() string {
}
type FSM struct {
- t tomb.Tomb
- gConf *config.Global
- pConf *config.Neighbor
- state bgp.FSMState
- reason FsmStateReason
- conn net.Conn
- connCh chan net.Conn
- idleHoldTime float64
- opensentHoldTime float64
- negotiatedHoldTime float64
- adminState AdminState
- adminStateCh chan AdminState
- getActiveCh chan struct{}
- h *FSMHandler
- rfMap map[bgp.RouteFamily]bool
- capMap map[bgp.BGPCapabilityCode][]bgp.ParameterCapabilityInterface
- recvOpen *bgp.BGPMessage
- confedCheck bool
- peerInfo *table.PeerInfo
- policy *table.RoutingPolicy
+ t tomb.Tomb
+ gConf *config.Global
+ pConf *config.Neighbor
+ state bgp.FSMState
+ reason FsmStateReason
+ conn net.Conn
+ connCh chan net.Conn
+ idleHoldTime float64
+ opensentHoldTime float64
+ adminState AdminState
+ adminStateCh chan AdminState
+ getActiveCh chan struct{}
+ h *FSMHandler
+ rfMap map[bgp.RouteFamily]bool
+ capMap map[bgp.BGPCapabilityCode][]bgp.ParameterCapabilityInterface
+ recvOpen *bgp.BGPMessage
+ confedCheck bool
+ peerInfo *table.PeerInfo
+ policy *table.RoutingPolicy
}
func (fsm *FSM) bgpMessageStateUpdate(MessageType uint8, isIn bool) {
@@ -704,9 +703,9 @@ func (h *FSMHandler) opensent() (bgp.FSMState, FsmStateReason) {
holdTime := float64(body.HoldTime)
myHoldTime := fsm.pConf.Timers.Config.HoldTime
if holdTime > myHoldTime {
- fsm.negotiatedHoldTime = myHoldTime
+ fsm.pConf.Timers.State.NegotiatedHoldTime = myHoldTime
} else {
- fsm.negotiatedHoldTime = holdTime
+ fsm.pConf.Timers.State.NegotiatedHoldTime = holdTime
}
msg := bgp.NewBGPKeepAliveMessage()
@@ -758,12 +757,13 @@ func (h *FSMHandler) opensent() (bgp.FSMState, FsmStateReason) {
}
func keepaliveTicker(fsm *FSM) *time.Ticker {
- if fsm.negotiatedHoldTime == 0 {
+ negotiatedTime := fsm.pConf.Timers.State.NegotiatedHoldTime
+ if negotiatedTime == 0 {
return &time.Ticker{}
}
sec := time.Second * time.Duration(fsm.pConf.Timers.Config.KeepaliveInterval)
- if fsm.negotiatedHoldTime < fsm.pConf.Timers.Config.HoldTime {
- sec = time.Second * time.Duration(fsm.negotiatedHoldTime) / 3
+ if negotiatedTime < fsm.pConf.Timers.Config.HoldTime {
+ sec = time.Second * time.Duration(negotiatedTime) / 3
}
if sec == 0 {
sec = 1
@@ -780,12 +780,12 @@ func (h *FSMHandler) openconfirm() (bgp.FSMState, FsmStateReason) {
h.t.Go(h.recvMessage)
var holdTimer *time.Timer
- if fsm.negotiatedHoldTime == 0 {
+ if fsm.pConf.Timers.State.NegotiatedHoldTime == 0 {
holdTimer = &time.Timer{}
} else {
// RFC 4271 P.65
// sets the HoldTimer according to the negotiated value
- holdTimer = time.NewTimer(time.Second * time.Duration(fsm.negotiatedHoldTime))
+ holdTimer = time.NewTimer(time.Second * time.Duration(fsm.pConf.Timers.State.NegotiatedHoldTime))
}
for {
@@ -875,7 +875,7 @@ func (h *FSMHandler) sendMessageloop() error {
fsm.bgpMessageStateUpdate(0, false)
return nil
}
- if err := conn.SetWriteDeadline(time.Now().Add(time.Second * time.Duration(fsm.negotiatedHoldTime))); err != nil {
+ if err := conn.SetWriteDeadline(time.Now().Add(time.Second * time.Duration(fsm.pConf.Timers.State.NegotiatedHoldTime))); err != nil {
h.errorCh <- FSM_WRITE_FAILED
return fmt.Errorf("failed to set write deadline")
}
@@ -960,10 +960,10 @@ func (h *FSMHandler) established() (bgp.FSMState, FsmStateReason) {
h.t.Go(h.recvMessageloop)
var holdTimer *time.Timer
- if fsm.negotiatedHoldTime == 0 {
+ if fsm.pConf.Timers.State.NegotiatedHoldTime == 0 {
holdTimer = &time.Timer{}
} else {
- holdTimer = time.NewTimer(time.Second * time.Duration(fsm.negotiatedHoldTime))
+ holdTimer = time.NewTimer(time.Second * time.Duration(fsm.pConf.Timers.State.NegotiatedHoldTime))
}
for {
@@ -995,8 +995,8 @@ func (h *FSMHandler) established() (bgp.FSMState, FsmStateReason) {
h.outgoing <- m
return bgp.BGP_FSM_IDLE, FSM_HOLD_TIMER_EXPIRED
case <-h.holdTimerResetCh:
- if fsm.negotiatedHoldTime != 0 {
- holdTimer.Reset(time.Second * time.Duration(fsm.negotiatedHoldTime))
+ 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)
diff --git a/server/fsm_test.go b/server/fsm_test.go
index 5fa94641..a6720a3d 100644
--- a/server/fsm_test.go
+++ b/server/fsm_test.go
@@ -165,7 +165,7 @@ func TestFSMHandlerOpensent_HoldTimerExpired(t *testing.T) {
p.fsm.conn = m
// set keepalive ticker
- p.fsm.negotiatedHoldTime = 3
+ p.fsm.pConf.Timers.State.NegotiatedHoldTime = 3
// set holdtime
p.fsm.opensentHoldTime = 2
@@ -193,7 +193,7 @@ func TestFSMHandlerOpenconfirm_HoldTimerExpired(t *testing.T) {
p.fsm.pConf.Timers.Config.KeepaliveInterval = 1
// set holdtime
- p.fsm.negotiatedHoldTime = 2
+ p.fsm.pConf.Timers.State.NegotiatedHoldTime = 2
state, _ := h.openconfirm()
assert.Equal(bgp.BGP_FSM_IDLE, state)
@@ -214,7 +214,7 @@ func TestFSMHandlerEstablish_HoldTimerExpired(t *testing.T) {
p.fsm.conn = m
// set keepalive ticker
- p.fsm.negotiatedHoldTime = 3
+ p.fsm.pConf.Timers.State.NegotiatedHoldTime = 3
msg := keepalive()
header, _ := msg.Header.Serialize()
@@ -228,7 +228,7 @@ func TestFSMHandlerEstablish_HoldTimerExpired(t *testing.T) {
// set holdtime
p.fsm.pConf.Timers.Config.HoldTime = 2
- p.fsm.negotiatedHoldTime = 2
+ p.fsm.pConf.Timers.State.NegotiatedHoldTime = 2
go pushPackets()
state, _ := h.established()
@@ -253,7 +253,7 @@ func TestFSMHandlerOpenconfirm_HoldtimeZero(t *testing.T) {
// set up keepalive ticker
p.fsm.pConf.Timers.Config.KeepaliveInterval = 1
// set holdtime
- p.fsm.negotiatedHoldTime = 0
+ p.fsm.pConf.Timers.State.NegotiatedHoldTime = 0
go h.openconfirm()
time.Sleep(100 * time.Millisecond)
@@ -272,11 +272,9 @@ func TestFSMHandlerEstablished_HoldtimeZero(t *testing.T) {
// push mock connection
p.fsm.conn = m
- // set keepalive ticker
- p.fsm.negotiatedHoldTime = 3
-
// set holdtime
- p.fsm.negotiatedHoldTime = 0
+ p.fsm.pConf.Timers.State.NegotiatedHoldTime = 0
+
go h.established()
time.Sleep(100 * time.Millisecond)
diff --git a/server/peer.go b/server/peer.go
index 02db27c0..8c8f96d4 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -232,8 +232,8 @@ func (peer *Peer) ToApiStruct() *api.Peer {
LocalCap: localCap,
}
- timer := &c.Timers
- s := &c.State
+ timer := c.Timers
+ s := c.State
advertized := uint32(0)
received := uint32(0)
@@ -255,9 +255,9 @@ func (peer *Peer) ToApiStruct() *api.Peer {
}
keepalive := uint32(0)
- if f.negotiatedHoldTime != 0 {
- if f.negotiatedHoldTime < timer.Config.HoldTime {
- keepalive = uint32(f.negotiatedHoldTime / 3)
+ if t := timer.State.NegotiatedHoldTime; t != 0 {
+ if t < timer.Config.HoldTime {
+ keepalive = uint32(t / 3)
} else {
keepalive = uint32(timer.Config.KeepaliveInterval)
}