Search in sources :

Example 1 with BGPSessionListener

use of org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener in project bgpcep by opendaylight.

the class BGPSessionImplTest method testSessionRecoveryOnException.

@Test
public void testSessionRecoveryOnException() throws Exception {
    final BGPSessionListener listener = mock(BGPSessionListener.class);
    Mockito.doThrow(new RuntimeException("Mocked runtime exception.")).when(listener).onSessionUp(Matchers.any());
    this.bgpSession = Mockito.spy(new BGPSessionImpl(listener, this.speakerListener, this.classicOpen, this.classicOpen.getHoldTimer(), null));
    this.bgpSession.setChannelExtMsgCoder(this.classicOpen);
    Mockito.verify(this.bgpSession, Mockito.never()).handleException(Matchers.any());
    Mockito.verify(this.bgpSession, Mockito.never()).writeAndFlush(Matchers.any(Notification.class));
    Mockito.verify(this.bgpSession, Mockito.never()).terminate(Matchers.any(BGPDocumentedException.class));
    try {
        this.bgpSession.sessionUp();
        // expect the exception to be populated
        Assert.fail();
    } catch (final RuntimeException ignored) {
    }
    Assert.assertNotEquals(State.UP, this.bgpSession.getState());
    Mockito.verify(this.bgpSession).handleException(Matchers.any());
    Mockito.verify(this.bgpSession).writeAndFlush(Matchers.any(Notification.class));
    Mockito.verify(this.bgpSession).terminate(Matchers.any(BGPDocumentedException.class));
    Mockito.verify(listener).onSessionTerminated(this.bgpSession, new BGPTerminationReason(BGPError.CEASE));
}
Also used : BGPSessionListener(org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener) BGPTerminationReason(org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) Notification(org.opendaylight.yangtools.yang.binding.Notification) Test(org.junit.Test)

Example 2 with BGPSessionListener

use of org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener in project bgpcep by opendaylight.

the class StrictBGPPeerRegistryTest method testPeerConnectionSuccessfull.

@Test
public void testPeerConnectionSuccessfull() throws Exception {
    final Ipv4Address to2 = new Ipv4Address("255.255.255.254");
    final IpAddress remoteIp2 = new IpAddress(to2);
    this.peerRegistry.addPeer(REMOTE_IP, this.peer1, this.mockPreferences);
    final BGPSessionListener session2 = getMockSession();
    this.peerRegistry.addPeer(remoteIp2, session2, this.mockPreferences);
    final BGPSessionListener returnedSession1 = this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, this.classicOpen);
    assertSame(this.peer1, returnedSession1);
    final BGPSessionListener returnedSession2 = this.peerRegistry.getPeer(remoteIp2, FROM, to2, this.classicOpen);
    assertSame(session2, returnedSession2);
    Mockito.verifyZeroInteractions(this.peer1);
    Mockito.verifyZeroInteractions(session2);
}
Also used : BGPSessionListener(org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Test(org.junit.Test)

Example 3 with BGPSessionListener

use of org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener in project bgpcep by opendaylight.

the class StrictBGPPeerRegistryTest method getMockSession.

private static BGPSessionListener getMockSession() {
    final BGPSessionListener mock = Mockito.mock(BGPSessionListener.class);
    Mockito.doReturn(Futures.immediateFuture(null)).when(mock).releaseConnection();
    return mock;
}
Also used : BGPSessionListener(org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener)

Example 4 with BGPSessionListener

use of org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener 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 5 with BGPSessionListener

use of org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener in project bgpcep by opendaylight.

the class AbstractBGPSessionNegotiator method handleOpen.

private synchronized void handleOpen(final Open openObj) {
    final IpAddress remoteIp = getRemoteIp();
    final BGPSessionPreferences preferences = this.registry.getPeerPreferences(remoteIp);
    try {
        final BGPSessionListener peer = this.registry.getPeer(remoteIp, getSourceId(openObj, preferences), getDestinationId(openObj, preferences), openObj);
        sendMessage(new KeepaliveBuilder().build());
        this.state = State.OPEN_CONFIRM;
        this.session = new BGPSessionImpl(peer, this.channel, openObj, preferences, this.registry);
        this.session.setChannelExtMsgCoder(openObj);
        LOG.debug("Channel {} moved to OPEN_CONFIRM state with remote proposal {}", this.channel, openObj);
    } catch (final BGPDocumentedException e) {
        LOG.warn("Channel {} negotiation failed", this.channel, e);
        negotiationFailed(e);
    }
}
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) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) KeepaliveBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.KeepaliveBuilder)

Aggregations

BGPSessionListener (org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener)6 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)3 Test (org.junit.Test)2 BGPSessionPreferences (org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 BGPDispatcher (org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher)1 PeerRegistrySessionListener (org.opendaylight.protocol.bgp.rib.impl.spi.PeerRegistrySessionListener)1 BGPTerminationReason (org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason)1 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)1 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)1 LinkstateAddressFamily (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.LinkstateAddressFamily)1 LinkstateSubsequentAddressFamily (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.LinkstateSubsequentAddressFamily)1 KeepaliveBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.KeepaliveBuilder)1 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters)1 OptionalCapabilities (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.OptionalCapabilities)1 Ipv4AddressFamily (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily)1 UnicastSubsequentAddressFamily (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily)1 Notification (org.opendaylight.yangtools.yang.binding.Notification)1