diff options
author | Hiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp> | 2015-01-26 16:34:24 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-01-26 20:41:08 +0900 |
commit | c4c487118dc9a77c1c36dbcc173fe116c2edc769 (patch) | |
tree | 700acd02d2a90945d147ad6ba89395f89d452805 | |
parent | dafa0a31d73f49b6cd68e658f000da904565f36c (diff) |
fsm: add OpenSent and OpenConfirm testcases
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | server/fsm_test.go | 61 |
1 files changed, 56 insertions, 5 deletions
diff --git a/server/fsm_test.go b/server/fsm_test.go index 76b2a095..894fcb88 100644 --- a/server/fsm_test.go +++ b/server/fsm_test.go @@ -44,6 +44,11 @@ func NewMockConnection() *MockConnection { func (m *MockConnection) Read(buf []byte) (int, error) { data := <-m.recvCh + rest := len(buf) - m.readBytes + if len(data) > rest { + m.recvCh <- data[rest:] + data = data[:rest] + } for _, val := range data { buf[m.readBytes] = val @@ -86,7 +91,7 @@ func showMessageType(t uint8) string { } func (m *MockConnection) Close() error { - fmt.Printf("close called") + fmt.Printf("close called\n") return nil } @@ -121,6 +126,56 @@ func TestReadAll(t *testing.T) { assert.Equal(expected2, actual2) } +func TestFSMHandlerOpensent_HoldTimerExpired(t *testing.T) { + assert := assert.New(t) + m := NewMockConnection() + + p, h := makePeerAndHandler() + + // push mock connection + p.fsm.passiveConn = m + + // set up keepalive ticker + sec := time.Second * 2 + p.fsm.keepaliveTicker = time.NewTicker(sec) + + // set holdtime + p.fsm.opensentHoldTime = 5 + + state := h.opensent() + + assert.Equal(bgp.BGP_FSM_IDLE, state) + lastMsg := m.sendBuf[len(m.sendBuf)-1] + sent, _ := bgp.ParseBGPMessage(lastMsg) + assert.Equal(bgp.BGP_MSG_NOTIFICATION, sent.Header.Type) + assert.Equal(bgp.BGP_ERROR_HOLD_TIMER_EXPIRED, sent.Body.(*bgp.BGPNotification).ErrorCode) + +} + +func TestFSMHandlerOpenconfirm_HoldTimerExpired(t *testing.T) { + assert := assert.New(t) + m := NewMockConnection() + + p, h := makePeerAndHandler() + + // push mock connection + p.fsm.passiveConn = m + + // set up keepalive ticker + p.fsm.peerConfig.Timers.KeepaliveInterval = 2 + + // set holdtime + p.fsm.negotiatedHoldTime = 10 + state := h.openconfirm() + + assert.Equal(bgp.BGP_FSM_IDLE, state) + lastMsg := m.sendBuf[len(m.sendBuf)-1] + sent, _ := bgp.ParseBGPMessage(lastMsg) + assert.Equal(bgp.BGP_MSG_NOTIFICATION, sent.Header.Type) + assert.Equal(bgp.BGP_ERROR_HOLD_TIMER_EXPIRED, sent.Body.(*bgp.BGPNotification).ErrorCode) + +} + func TestFSMHandlerEstablish_HoldTimerExpired(t *testing.T) { assert := assert.New(t) m := NewMockConnection() @@ -142,10 +197,6 @@ func TestFSMHandlerEstablish_HoldTimerExpired(t *testing.T) { // first keepalive from peer m.recvCh <- header m.recvCh <- body - time.Sleep(time.Second * 4) - // second keepalive from peer - m.recvCh <- header - m.recvCh <- body } // set holdtime |