Search in sources :

Example 1 with PeerRegistrySessionListener

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);
}
Also used : PeerRegistrySessionListener(org.opendaylight.protocol.bgp.rib.impl.spi.PeerRegistrySessionListener) Test(org.junit.Test)

Example 2 with PeerRegistrySessionListener

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);
    }
}
Also used : IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) PeerRegistrySessionListener(org.opendaylight.protocol.bgp.rib.impl.spi.PeerRegistrySessionListener)

Example 3 with PeerRegistrySessionListener

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;
}
Also used : BGPSessionListener(org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener) BGPSessionPreferences(org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) PeerRegistrySessionListener(org.opendaylight.protocol.bgp.rib.impl.spi.PeerRegistrySessionListener) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)

Example 4 with PeerRegistrySessionListener

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;
}
Also used : IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) PeerRegistrySessionListener(org.opendaylight.protocol.bgp.rib.impl.spi.PeerRegistrySessionListener)

Example 5 with PeerRegistrySessionListener

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);
}
Also used : PeerRegistrySessionListener(org.opendaylight.protocol.bgp.rib.impl.spi.PeerRegistrySessionListener) Test(org.junit.Test)

Aggregations

PeerRegistrySessionListener (org.opendaylight.protocol.bgp.rib.impl.spi.PeerRegistrySessionListener)5 Test (org.junit.Test)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)1 BGPSessionPreferences (org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences)1 BGPSessionListener (org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener)1 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)1