summaryrefslogtreecommitdiff
path: root/src/main/java/com/lumaserv/bgp/BGPSession.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/lumaserv/bgp/BGPSession.java')
-rw-r--r--src/main/java/com/lumaserv/bgp/BGPSession.java40
1 files changed, 36 insertions, 4 deletions
diff --git a/src/main/java/com/lumaserv/bgp/BGPSession.java b/src/main/java/com/lumaserv/bgp/BGPSession.java
index bb38ebf..e785e3b 100644
--- a/src/main/java/com/lumaserv/bgp/BGPSession.java
+++ b/src/main/java/com/lumaserv/bgp/BGPSession.java
@@ -11,6 +11,7 @@ import lombok.Getter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketException;
@@ -18,6 +19,8 @@ import java.net.SocketException;
public class BGPSession implements Runnable {
@Getter
+ final BGPServer server;
+ @Getter
final BGPSessionConfiguration configuration;
final String host;
final int port;
@@ -27,13 +30,17 @@ public class BGPSession implements Runnable {
@Getter
boolean closed;
boolean outgoing;
+ @Getter
BGPFsm fsm;
Thread thread;
boolean isAdvAS4Capability;
@Getter
boolean isAS4Capability;
+ @Getter
+ byte[] remoteIdentifier;
- public BGPSession(Socket socket, BGPSessionConfiguration configuration, BGPFsm fsm) throws IOException {
+ public BGPSession(BGPServer server, Socket socket, BGPSessionConfiguration configuration, BGPFsm fsm) throws IOException {
+ this.server = server;
this.configuration = configuration;
this.socket = socket;
this.inputStream = socket.getInputStream();
@@ -43,13 +50,26 @@ public class BGPSession implements Runnable {
this.port = -1;
}
- public BGPSession(BGPSessionConfiguration configuration, BGPFsm fsm, String host, int port) throws IOException {
+ public BGPSession(BGPServer server, BGPSessionConfiguration configuration, BGPFsm fsm, String host, int port) throws IOException {
+ this.server = server;
this.configuration = configuration;
this.fsm = fsm;
this.host = host;
this.port = port;
}
+ public InetAddress getInetAddress() {
+ return socket.getInetAddress();
+ }
+
+ public InetAddress getLocalAddress() {
+ return socket.getLocalAddress();
+ }
+
+ protected void finalize() throws Throwable {
+ System.out.println("Finalize BGPSession");
+ }
+
public void automaticStop() {
fsm.getCurrentState().automaticStop();
}
@@ -78,8 +98,20 @@ public class BGPSession implements Runnable {
break;
case OPEN:
BGPOpen open = new BGPOpen(packet.getMessage());
- isAS4Capability = isAdvAS4Capability && open.getAS4Capability().isPresent();
- fsm.getCurrentState().openMsg(open);
+ if (server.hasCollided(this, open)) {
+ BGPNotification notification = new BGPNotification()
+ .setMajorErrorCode(BGPNotification.Error.CEASE.getCode());
+ try {
+ sendNotification(notification);
+ } catch(IOException ex) {
+ }
+ dropConnection();
+ // TODO Break links between fsm and session!
+ } else {
+ isAS4Capability = isAdvAS4Capability && open.getAS4Capability().isPresent();
+ remoteIdentifier = open.getIdentifier();
+ fsm.getCurrentState().openMsg(open);
+ }
break;
case UPDATE: {
BGPUpdate update = new BGPUpdate(this, packet.getMessage());