From 452eb2a4f679b26a6aa71761160ba9ec43d97ffc Mon Sep 17 00:00:00 2001 From: IWASE Yusuke Date: Fri, 2 Jun 2017 14:11:01 +0900 Subject: 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 --- server/server_test.go | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) (limited to 'server/server_test.go') 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 + } + } +} -- cgit v1.2.3