}
}
+ @Override
+ public boolean isSessionActive() {
+ return this.session != null;
+ }
+
@Override
public synchronized byte[] getRawIdentifier() {
return Arrays.copyOf(this.rawIdentifier, this.rawIdentifier.length);
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
package org.opendaylight.protocol.bgp.rib.impl;
import com.google.common.collect.Lists;
-
import java.util.List;
-
import org.opendaylight.protocol.bgp.rib.impl.spi.ReusableBGPPeer;
import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
public void releaseConnection() {
LOG.debug("Releasing connection");
}
+
+ @Override
+ public boolean isSessionActive() {
+ return true;
+ }
}
package org.opendaylight.protocol.bgp.rib.impl;
import com.google.common.collect.Lists;
-
import java.util.List;
import java.util.Set;
-
import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
LOG.debug("Session terminated. Cause : {}", cause.toString());
this.up = false;
}
+
+ @Override
+ public boolean isSessionActive() {
+ return true;
+ }
}
import static org.junit.Assert.fail;
import java.net.InetSocketAddress;
-
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@Before
public void setUp() throws Exception {
- droppingBGPSessionRegistry = new StrictBGPPeerRegistry();
- mockPreferences = getMockPreferences();
+ this.droppingBGPSessionRegistry = new StrictBGPPeerRegistry();
+ this.mockPreferences = getMockPreferences();
}
@Test
final Ipv4Address to = new Ipv4Address("255.255.255.255");
final ReusableBGPPeer session1 = getMockSession();
- droppingBGPSessionRegistry.addPeer(remoteIp, session1, mockPreferences);
+ this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
- droppingBGPSessionRegistry.getPeer(remoteIp, from, to);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to);
try {
- droppingBGPSessionRegistry.getPeer(remoteIp, from, to);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to);
} catch (final IllegalStateException e) {
- Mockito.verifyZeroInteractions(session1);
+ Mockito.verify(session1).isSessionActive();
return;
}
final Ipv4Address to = new Ipv4Address("255.255.255.255");
try {
- droppingBGPSessionRegistry.getPeer(remoteIp, from, to);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to);
} catch (final IllegalStateException e) {
return;
}
final IpAddress remoteIp2 = new IpAddress(to2);
final ReusableBGPPeer session1 = getMockSession();
- droppingBGPSessionRegistry.addPeer(remoteIp, session1, mockPreferences);
+ this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
final ReusableBGPPeer session2 = getMockSession();
- droppingBGPSessionRegistry.addPeer(remoteIp2, session2, mockPreferences);
+ this.droppingBGPSessionRegistry.addPeer(remoteIp2, session2, this.mockPreferences);
- final BGPSessionListener returnedSession1 = droppingBGPSessionRegistry.getPeer(remoteIp, from, to);
+ final BGPSessionListener returnedSession1 = this.droppingBGPSessionRegistry.getPeer(remoteIp, from, to);
assertSame(session1, returnedSession1);
- final BGPSessionListener returnedSession2 = droppingBGPSessionRegistry.getPeer(remoteIp2, from, to2);
+ final BGPSessionListener returnedSession2 = this.droppingBGPSessionRegistry.getPeer(remoteIp2, from, to2);
assertSame(session2, returnedSession2);
Mockito.verifyZeroInteractions(session1);
final IpAddress remoteIp = new IpAddress(lower);
final ReusableBGPPeer session1 = getMockSession();
- droppingBGPSessionRegistry.addPeer(remoteIp, session1, mockPreferences);
+ this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
- droppingBGPSessionRegistry.getPeer(remoteIp, higher, lower);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, higher, lower);
try {
- droppingBGPSessionRegistry.getPeer(remoteIp, lower, higher);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, lower, higher);
} catch (final BGPDocumentedException e) {
- Mockito.verifyZeroInteractions(session1);
+ Mockito.verify(session1).isSessionActive();
return;
}
final IpAddress remoteIp = new IpAddress(lower);
final ReusableBGPPeer session1 = getMockSession();
- droppingBGPSessionRegistry.addPeer(remoteIp, session1, mockPreferences);
+ this.droppingBGPSessionRegistry.addPeer(remoteIp, session1, this.mockPreferences);
- droppingBGPSessionRegistry.getPeer(remoteIp, lower, higher);
- droppingBGPSessionRegistry.getPeer(remoteIp, higher, lower);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, lower, higher);
+ this.droppingBGPSessionRegistry.getPeer(remoteIp, higher, lower);
Mockito.verify(session1).releaseConnection();
}
private ReusableBGPPeer getMockSession() {
final ReusableBGPPeer mock = Mockito.mock(ReusableBGPPeer.class);
Mockito.doNothing().when(mock).releaseConnection();
+ Mockito.doReturn(Boolean.TRUE).when(mock).isSessionActive();
return mock;
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-
import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
public void onSessionTerminated(final BGPSession session, final BGPTerminationReason reason) {
this.connected = false;
}
+
+ @Override
+ public boolean isSessionActive() {
+ return true;
+ }
}
*/
public interface BGPSessionListener extends SessionListener<Notification, BGPSession, BGPTerminationReason> {
+ /**
+ * Returns state of BGP session associated with this listener.
+ *
+ * @return false if session associated with this listener is null, true if its non-null
+ */
+ boolean isSessionActive();
}
public void releaseConnection() {
LOG.info("Client Listener: Connection released.");
}
+
+ @Override
+ public boolean isSessionActive() {
+ return true;
+ }
}
LOG.info("Server: Message received: {}", message);
// this.d.stop();
}
+
+ @Override
+ public boolean isSessionActive() {
+ return true;
+ }
}