diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2017-06-02 14:11:01 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-06-06 13:11:21 +0900 |
commit | 452eb2a4f679b26a6aa71761160ba9ec43d97ffc (patch) | |
tree | 08768a413b8f4b1bbf9754912b7f26fc5c33ad81 | |
parent | cb1a3753dcea868b331fb20887922b04759e8107 (diff) |
server_test: Test for Graceful Restart timer expired
This test case checks whether BGP session is freed or not when Graceful
Restart timer expired.
If BGP session is not freed as expectedly, this test case will exit with
state 1 after waiting 120 seconds and will output the following.
FATA[0147] failed to free the fsm.h.t for 127.0.0.1 BGP_FSM_OPENSENT
BGP_FSM_IDLE Topic=Peer
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
-rw-r--r-- | server/server_test.go | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/server/server_test.go b/server/server_test.go index 8c1c8582..98564b9f 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -440,3 +440,109 @@ func TestPeerGroup(test *testing.T) { } } } + +func TestGracefulRestartTimerExpired(t *testing.T) { + assert := assert.New(t) + s1 := NewBgpServer() + go s1.Serve() + err := s1.Start(&config.Global{ + Config: config.GlobalConfig{ + As: 1, + RouterId: "1.1.1.1", + Port: 10179, + }, + }) + assert.Nil(err) + defer s1.Stop() + + n := &config.Neighbor{ + Config: config.NeighborConfig{ + NeighborAddress: "127.0.0.1", + PeerAs: 2, + }, + Transport: config.Transport{ + Config: config.TransportConfig{ + PassiveMode: true, + }, + }, + GracefulRestart: config.GracefulRestart{ + Config: config.GracefulRestartConfig{ + Enabled: true, + RestartTime: 10, + }, + }, + } + err = s1.AddNeighbor(n) + assert.Nil(err) + + s2 := NewBgpServer() + go s2.Serve() + err = s2.Start(&config.Global{ + Config: config.GlobalConfig{ + As: 2, + RouterId: "2.2.2.2", + Port: -1, + }, + }) + assert.Nil(err) + defer s2.Stop() + + m := &config.Neighbor{ + Config: config.NeighborConfig{ + NeighborAddress: "127.0.0.1", + PeerAs: 1, + }, + Transport: config.Transport{ + Config: config.TransportConfig{ + RemotePort: 10179, + }, + }, + GracefulRestart: config.GracefulRestart{ + Config: config.GracefulRestartConfig{ + Enabled: true, + RestartTime: 10, + }, + }, + } + err = s2.AddNeighbor(m) + assert.Nil(err) + + // Waiting for BGP session established. + for { + time.Sleep(time.Second) + if s2.GetNeighbor("", false)[0].State.SessionState == config.SESSION_STATE_ESTABLISHED { + break + } + } + + // Force TCP session disconnected in order to cause Graceful Restart at s1 + // side. + for _, n := range s2.neighborMap { + n.fsm.conn.Close() + } + s2.Stop() + + time.Sleep(5 * time.Second) + + // Create dummy session which does NOT send BGP OPEN message in order to + // cause Graceful Restart timer expired. + var conn net.Conn + for { + time.Sleep(time.Second) + var err error + conn, err = net.Dial("tcp", "127.0.0.1:10179") + if err != nil { + log.Warn("net.Dial:", err) + } + break + } + defer conn.Close() + + // Waiting for Graceful Restart timer expired and moving on to IDLE state. + for { + time.Sleep(time.Second) + if s1.GetNeighbor("", false)[0].State.SessionState == config.SESSION_STATE_IDLE { + break + } + } +} |