summaryrefslogtreecommitdiffhomepage
path: root/server/fsm_test.go
diff options
context:
space:
mode:
authorHiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp>2015-01-26 16:34:24 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-26 20:41:08 +0900
commitc4c487118dc9a77c1c36dbcc173fe116c2edc769 (patch)
tree700acd02d2a90945d147ad6ba89395f89d452805 /server/fsm_test.go
parentdafa0a31d73f49b6cd68e658f000da904565f36c (diff)
fsm: add OpenSent and OpenConfirm testcases
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/fsm_test.go')
-rw-r--r--server/fsm_test.go61
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