summaryrefslogtreecommitdiffhomepage
path: root/server/server_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'server/server_test.go')
-rw-r--r--server/server_test.go106
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
+ }
+ }
+}