summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/lumaserv/bgp/BGPFsm.java31
-rw-r--r--src/main/java/com/lumaserv/bgp/BGPSession.java19
2 files changed, 22 insertions, 28 deletions
diff --git a/src/main/java/com/lumaserv/bgp/BGPFsm.java b/src/main/java/com/lumaserv/bgp/BGPFsm.java
index 2cf598f..a2143bd 100644
--- a/src/main/java/com/lumaserv/bgp/BGPFsm.java
+++ b/src/main/java/com/lumaserv/bgp/BGPFsm.java
@@ -1,8 +1,5 @@
package com.lumaserv.bgp;
-import com.lumaserv.bgp.protocol.AFI;
-import com.lumaserv.bgp.protocol.BGPPacket;
-import com.lumaserv.bgp.protocol.SAFI;
import com.lumaserv.bgp.protocol.message.BGPNotification;
import com.lumaserv.bgp.protocol.message.BGPOpen;
import com.lumaserv.bgp.protocol.message.BGPUpdate;
@@ -15,8 +12,8 @@ import java.util.Timer;
import java.util.TimerTask;
public class BGPFsm {
- final int CONFIG_HOLD_TIME = 80; // FIXME use from configuration
- final byte CONFIG_VERSION = 4;
+ public static final int CONFIG_HOLD_TIME = 80; // FIXME use from configuration
+ public static final byte CONFIG_VERSION = 4;
public final State IDLE;
public final State CONNECT;
@@ -182,18 +179,8 @@ public class BGPFsm {
setConnectRetryTimer(0);
// - completes BGP initialization
- BGPSessionConfiguration config = session.getConfiguration();
- BGPOpen.Capabilities caps = new BGPOpen.Capabilities();
- caps.getCapabilities().add(new BGPOpen.MultiprotocolExtensionCapability(AFI.IPV4.getValue(), SAFI.UNICAST.getValue()));
- caps.getCapabilities().add(new BGPOpen.MultiprotocolExtensionCapability(AFI.IPV6.getValue(), SAFI.UNICAST.getValue()));
- BGPOpen request = new BGPOpen()
- .setAsn(config.getLocalAs())
- .setHoldTime(CONFIG_HOLD_TIME)
- .setVersion(CONFIG_VERSION)
- .setIdentifier(config.getLocalIdentifier());
- request.getOptionalParameters().add(caps);
try {
- session.sendOpen(request);
+ session.sendOpen();
setHoldTimer(4 * 60);
setState(OPEN_SENT);
} catch (IOException ex) {
@@ -242,18 +229,8 @@ public class BGPFsm {
setConnectRetryTimer(0);
// - completes the BGP initialization,
- BGPSessionConfiguration config = session.getConfiguration();
- BGPOpen.Capabilities caps = new BGPOpen.Capabilities();
- caps.getCapabilities().add(new BGPOpen.MultiprotocolExtensionCapability(AFI.IPV4.getValue(), SAFI.UNICAST.getValue()));
- caps.getCapabilities().add(new BGPOpen.MultiprotocolExtensionCapability(AFI.IPV6.getValue(), SAFI.UNICAST.getValue()));
- BGPOpen request = new BGPOpen()
- .setAsn(config.getLocalAs())
- .setHoldTime(CONFIG_HOLD_TIME)
- .setVersion(CONFIG_VERSION)
- .setIdentifier(config.getLocalIdentifier());
- request.getOptionalParameters().add(caps);
try {
- session.sendOpen(request);
+ session.sendOpen();
setHoldTimer(4 * 60);
setState(OPEN_SENT);
} catch (IOException ex) {
diff --git a/src/main/java/com/lumaserv/bgp/BGPSession.java b/src/main/java/com/lumaserv/bgp/BGPSession.java
index 94a4f5a..21a5564 100644
--- a/src/main/java/com/lumaserv/bgp/BGPSession.java
+++ b/src/main/java/com/lumaserv/bgp/BGPSession.java
@@ -1,6 +1,8 @@
package com.lumaserv.bgp;
+import com.lumaserv.bgp.protocol.AFI;
import com.lumaserv.bgp.protocol.BGPPacket;
+import com.lumaserv.bgp.protocol.SAFI;
import com.lumaserv.bgp.protocol.message.BGPNotification;
import com.lumaserv.bgp.protocol.message.BGPOpen;
import com.lumaserv.bgp.protocol.message.BGPUpdate;
@@ -92,11 +94,26 @@ public class BGPSession implements Runnable {
thread.start();
}
- public void sendOpen(BGPOpen request) throws IOException {
+ void sendOpen(BGPOpen request) throws IOException {
outputStream.write(new BGPPacket().setType(BGPPacket.Type.OPEN).setMessage(request.build()).build());
System.out.println("Sent open");
}
+ public void sendOpen() throws IOException {
+ BGPOpen.Capabilities caps = new BGPOpen.Capabilities();
+ caps.getCapabilities().add(new BGPOpen.MultiprotocolExtensionCapability(AFI.IPV4.getValue(), SAFI.UNICAST.getValue()));
+ caps.getCapabilities().add(new BGPOpen.MultiprotocolExtensionCapability(AFI.IPV6.getValue(), SAFI.UNICAST.getValue()));
+
+ BGPOpen request = new BGPOpen()
+ .setAsn(configuration.getLocalAs())
+ .setHoldTime(BGPFsm.CONFIG_HOLD_TIME)
+ .setVersion(BGPFsm.CONFIG_VERSION)
+ .setIdentifier(configuration.getLocalIdentifier());
+ request.getOptionalParameters().add(caps);
+
+ sendOpen(request);
+ }
+
public void retryConnection() {
if (!socket.isConnected()) {
try {