use of org.opendaylight.protocol.bgp.rib.impl.spi.PeerRegistrySessionListener in project bgpcep by opendaylight.
the class StrictBGPPeerRegistryTest method testClosePeerSessionOneListener.
@Test
public void testClosePeerSessionOneListener() throws Exception {
final PeerRegistrySessionListener sessionListener1 = getMockSessionListener();
final AutoCloseable registration1 = this.peerRegistry.registerPeerSessionListener(sessionListener1);
final PeerRegistrySessionListener sessionListener2 = getMockSessionListener();
this.peerRegistry.registerPeerSessionListener(sessionListener2);
this.peerRegistry.addPeer(REMOTE_IP, this.peer1, this.mockPreferences);
this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, this.classicOpen);
this.peerRegistry.removePeerSession(REMOTE_IP);
registration1.close();
this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, this.classicOpen);
this.peerRegistry.removePeerSession(REMOTE_IP);
Mockito.verify(sessionListener1, Mockito.times(1)).onSessionCreated(REMOTE_IP);
Mockito.verify(sessionListener2, Mockito.times(2)).onSessionCreated(REMOTE_IP);
Mockito.verify(sessionListener1, Mockito.times(1)).onSessionRemoved(REMOTE_IP);
Mockito.verify(sessionListener2, Mockito.times(2)).onSessionRemoved(REMOTE_IP);
}
use of org.opendaylight.protocol.bgp.rib.impl.spi.PeerRegistrySessionListener in project bgpcep by opendaylight.
the class StrictBGPPeerRegistry method removePeerSession.
@Override
public synchronized void removePeerSession(final IpAddress oldIp) {
IpAddress fullIp = getFullIp(oldIp);
this.sessionIds.remove(fullIp);
for (final PeerRegistrySessionListener peerRegistrySessionListener : this.sessionListeners) {
peerRegistrySessionListener.onSessionRemoved(fullIp);
}
}
use of org.opendaylight.protocol.bgp.rib.impl.spi.PeerRegistrySessionListener in project bgpcep by opendaylight.
the class StrictBGPPeerRegistry method getPeer.
@Override
public synchronized BGPSessionListener getPeer(final IpAddress ip, final Ipv4Address sourceId, final Ipv4Address remoteId, final Open openObj) throws BGPDocumentedException {
requireNonNull(ip);
requireNonNull(sourceId);
requireNonNull(remoteId);
final AsNumber remoteAsNumber = AsNumberUtil.advertizedAsNumber(openObj);
requireNonNull(remoteAsNumber);
final BGPSessionPreferences prefs = getPeerPreferences(ip);
checkPeerConfigured(ip);
final BGPSessionId currentConnection = new BGPSessionId(sourceId, remoteId, remoteAsNumber);
final BGPSessionListener p = this.peers.get(ip);
final BGPSessionId previousConnection = this.sessionIds.get(ip);
if (previousConnection != null) {
LOG.warn("Duplicate BGP session established with {}", 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) || previousConnection.hasHigherAsNumber(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) || currentConnection.hasHigherAsNumber(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);
}
}
validateAs(remoteAsNumber, openObj, prefs);
// Map session id to peer IP address
this.sessionIds.put(ip, currentConnection);
for (final PeerRegistrySessionListener peerRegistrySessionListener : this.sessionListeners) {
peerRegistrySessionListener.onSessionCreated(ip);
}
return p;
}
use of org.opendaylight.protocol.bgp.rib.impl.spi.PeerRegistrySessionListener in project bgpcep by opendaylight.
the class StrictBGPPeerRegistryTest method getMockSessionListener.
private static PeerRegistrySessionListener getMockSessionListener() {
final PeerRegistrySessionListener mock = Mockito.mock(PeerRegistrySessionListener.class);
Mockito.doNothing().when(mock).onSessionCreated(Mockito.any(IpAddress.class));
Mockito.doNothing().when(mock).onSessionRemoved(Mockito.any(IpAddress.class));
return mock;
}
use of org.opendaylight.protocol.bgp.rib.impl.spi.PeerRegistrySessionListener in project bgpcep by opendaylight.
the class StrictBGPPeerRegistryTest method testRegisterPeerSessionListener.
@Test
public void testRegisterPeerSessionListener() throws Exception {
final PeerRegistrySessionListener sessionListener1 = getMockSessionListener();
this.peerRegistry.registerPeerSessionListener(sessionListener1);
final PeerRegistrySessionListener sessionListener2 = getMockSessionListener();
this.peerRegistry.registerPeerSessionListener(sessionListener2);
this.peerRegistry.addPeer(REMOTE_IP, this.peer1, this.mockPreferences);
this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, this.classicOpen);
Mockito.verify(sessionListener1, Mockito.times(1)).onSessionCreated(REMOTE_IP);
Mockito.verify(sessionListener2, Mockito.times(1)).onSessionCreated(REMOTE_IP);
this.peerRegistry.removePeerSession(REMOTE_IP);
Mockito.verify(sessionListener1, Mockito.times(1)).onSessionRemoved(REMOTE_IP);
Mockito.verify(sessionListener2, Mockito.times(1)).onSessionRemoved(REMOTE_IP);
}
Aggregations