checkPeerConfigured(ip);
final BGPSessionId currentConnection = new BGPSessionId(sourceId, remoteId);
+ final BGPSessionListener p = this.peers.get(ip);
if (this.sessionIds.containsKey(ip)) {
- LOG.warn("Duplicate BGP session established with {}", ip);
-
- final BGPSessionId previousConnection = this.sessionIds.get(ip);
-
- // Session reestablished with different ids
- if (!previousConnection.equals(currentConnection)) {
- LOG.warn("BGP session with {} {} has to be dropped. Same session already present {}", ip, currentConnection, previousConnection);
- throw new BGPDocumentedException(
- String.format("BGP session with %s %s has to be dropped. Same session already present %s",
- ip, currentConnection, previousConnection),
- BGPError.CONNECTION_COLLISION_RESOLUTION);
-
- // Session reestablished with lower source bgp id, dropping current
- } else if (previousConnection.isHigherDirection(currentConnection)) {
- LOG.warn("BGP session with {} {} has to be dropped. Opposite session already present", ip, currentConnection);
- throw new BGPDocumentedException(
- String.format("BGP session with %s initiated %s has to be dropped. Opposite session already present",
- ip, currentConnection),
- BGPError.CONNECTION_COLLISION_RESOLUTION);
-
- // Session reestablished with higher source bgp id, dropping previous
- } else if (currentConnection.isHigherDirection(previousConnection)) {
- LOG.warn("BGP session with {} {} released. Replaced by opposite session", ip, previousConnection);
- this.peers.get(ip).releaseConnection();
- return this.peers.get(ip);
-
- // Session reestablished with same source bgp id, dropping current as duplicate
+ if (p.isSessionActive()) {
+
+ LOG.warn("Duplicate BGP session established with {}", ip);
+
+ final BGPSessionId previousConnection = this.sessionIds.get(ip);
+
+ // Session reestablished with different ids
+ if (!previousConnection.equals(currentConnection)) {
+ LOG.warn("BGP session with {} {} has to be dropped. Same session already present {}", ip, currentConnection, previousConnection);
+ throw new BGPDocumentedException(
+ String.format("BGP session with %s %s has to be dropped. Same session already present %s",
+ ip, currentConnection, previousConnection),
+ BGPError.CEASE);
+
+ // Session reestablished with lower source bgp id, dropping current
+ } else if (previousConnection.isHigherDirection(currentConnection)) {
+ LOG.warn("BGP session with {} {} has to be dropped. Opposite session already present", ip, currentConnection);
+ throw new BGPDocumentedException(
+ String.format("BGP session with %s initiated %s has to be dropped. Opposite session already present",
+ ip, currentConnection),
+ BGPError.CEASE);
+
+ // Session reestablished with higher source bgp id, dropping previous
+ } else if (currentConnection.isHigherDirection(previousConnection)) {
+ LOG.warn("BGP session with {} {} released. Replaced by opposite session", ip, previousConnection);
+ this.peers.get(ip).releaseConnection();
+ return this.peers.get(ip);
+
+ // Session reestablished with same source bgp id, dropping current as duplicate
+ } else {
+ LOG.warn("BGP session with %s initiated from %s to %s has to be dropped. Same session already present", ip, sourceId, remoteId);
+ throw new BGPDocumentedException(
+ String.format("BGP session with %s initiated %s has to be dropped. Same session already present",
+ ip, currentConnection),
+ BGPError.CEASE);
+ }
} else {
- LOG.warn("BGP session with %s initiated from %s to %s has to be dropped. Same session already present", ip, sourceId, remoteId);
- throw new BGPDocumentedException(
- String.format("BGP session with %s initiated %s has to be dropped. Same session already present",
- ip, currentConnection),
- BGPError.CONNECTION_COLLISION_RESOLUTION);
+ removePeerSession(ip);
}
}
// Map session id to peer IP address
this.sessionIds.put(ip, currentConnection);
- return this.peers.get(ip);
+ return p;
}
@Override