From 724adb6752745d1c8e20de453cb2995561def506 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Sat, 12 Mar 2022 23:02:19 +0100 Subject: Improve BGP FSM --- src/main/java/com/lumaserv/bgp/BGPFsm.java | 70 ++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/lumaserv/bgp/BGPFsm.java b/src/main/java/com/lumaserv/bgp/BGPFsm.java index 9bfc30b..96378a5 100644 --- a/src/main/java/com/lumaserv/bgp/BGPFsm.java +++ b/src/main/java/com/lumaserv/bgp/BGPFsm.java @@ -171,8 +171,7 @@ public class BGPFsm { // TODO TcpConnection_Valid event (Event 14) // TODO Tcp_CR_Invalid event (Event 15) - @Override - void tcpCRAcked() { // Or incoming tcpConnectionConfirmed + protected void tcpCRAckedOrTcpConnectionConfirmed() { if (delayOpen) { setConnectRetryTimer(0); // - sets the DelayOpenTimer to the initial value, and @@ -190,6 +189,16 @@ public class BGPFsm { } } + @Override + void tcpCRAcked() { + tcpCRAckedOrTcpConnectionConfirmed(); + } + + @Override + void tcpConnectionConfirmed() { + tcpCRAckedOrTcpConnectionConfirmed(); + } + // FIXME @Override void tcpConnectionFails() { @@ -219,6 +228,50 @@ public class BGPFsm { } class Active extends State { + @Override + void manualStart() {} + @Override + void automaticStart() {} + @Override + void manualStartPassive() {} + @Override + void automaticStartPassive() {} + + protected void stop() { + // - If the DelayOpenTimer is running and the + try { + BGPNotification notification = new BGPNotification() + .setMajorErrorCode(BGPNotification.Error.CEASE.getCode()); + session.sendNotification(notification); + } catch (IOException ex) { + } + // - releases all BGP resources including stopping the + // DelayOpenTimer + session.dropConnection(); + connectRetryCounter = 0; + setConnectRetryTimer(0); + setState(IDLE); + } + + @Override + void manualStop() { + stop(); + } + + @Override + void automaticStop() { + stop(); + } + + @Override + void connectRetryTimerExpires() { + setConnectRetryTimer(connectRetryTime); + setState(CONNECT); + session.startOutgoing(); + // - continues to listen for a TCP connection that may be initiated + // by a remote BGP peer, and + } + @Override void tcpConnectionConfirmed() { if (delayOpen) { @@ -275,6 +328,15 @@ public class BGPFsm { stop(true); } + @Override + void tcpConnectionFails() { + session.dropConnection(); + setConnectRetryTimer(connectRetryTime); + // - continues to listen for a connection that may be initiated by + // the remote BGP peer, and + setState(ACTIVE); + } + @Override void openMsg(BGPOpen msg) { System.out.println("openMsg:" + msg); @@ -345,7 +407,7 @@ public class BGPFsm { setConnectRetryTimer(0); // - releases all BGP resources, session.dropConnection(); - // - increments the ConnectRetryCounter by 1, + connectRetryCounter++; // - (optionally) performs peer oscillation damping if the // DampPeerOscillations attribute is set to TRUE, and setState(IDLE); @@ -432,7 +494,7 @@ public class BGPFsm { // - deletes all routes associated with this connection, // - releases all BGP resources, session.dropConnection(); - // - increments the ConnectRetryCounter by 1, + connectRetryCounter++; setState(IDLE); } -- cgit v1.2.3