Search in sources :

Example 6 with BGPDocumentedException

use of org.opendaylight.protocol.bgp.parser.BGPDocumentedException in project bgpcep by opendaylight.

the class RouteMonitoringMessageHandler method parseMessageBody.

@Override
public Notification parseMessageBody(final ByteBuf bytes) throws BmpDeserializationException {
    final RouteMonitoringMessageBuilder routeMonitor = new RouteMonitoringMessageBuilder().setPeerHeader(parsePerPeerHeader(bytes));
    try {
        final Notification message = this.msgRegistry.parseMessage(bytes, null);
        requireNonNull(message, "UpdateMessage may not be null");
        Preconditions.checkArgument(message instanceof UpdateMessage, "An instance of UpdateMessage is required");
        final UpdateMessage updateMessage = (UpdateMessage) message;
        final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.route.monitoring.message.Update update = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.route.monitoring.message.UpdateBuilder(updateMessage).build();
        routeMonitor.setUpdate(update);
    } catch (final BGPDocumentedException | BGPParsingException e) {
        throw new BmpDeserializationException("Error while parsing Update Message.", e);
    }
    return routeMonitor.build();
}
Also used : UpdateMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.UpdateMessage) BGPParsingException(org.opendaylight.protocol.bgp.parser.BGPParsingException) RouteMonitoringMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.RouteMonitoringMessageBuilder) Notification(org.opendaylight.yangtools.yang.binding.Notification) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) BmpDeserializationException(org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException)

Example 7 with BGPDocumentedException

use of org.opendaylight.protocol.bgp.parser.BGPDocumentedException in project bgpcep by opendaylight.

the class StrictBGPPeerRegistryTest method testDuplicatePeersLowerAs.

@Test
public void testDuplicatePeersLowerAs() throws Exception {
    final AsNumber as2 = new AsNumber(3L);
    this.peerRegistry.addPeer(REMOTE_IP, this.peer1, this.mockPreferences);
    this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, this.classicOpen);
    try {
        this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, createOpen(TO, as2));
    } catch (final BGPDocumentedException e) {
        assertEquals(BGPError.CEASE, e.getError());
        return;
    }
    fail("Same peer cannot be connected twice");
}
Also used : BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) Test(org.junit.Test)

Example 8 with BGPDocumentedException

use of org.opendaylight.protocol.bgp.parser.BGPDocumentedException in project bgpcep by opendaylight.

the class StrictBGPPeerRegistryTest method testAsMismatch.

@Test
public void testAsMismatch() throws Exception {
    final AsNumber as2 = new AsNumber(3L);
    this.peerRegistry.addPeer(REMOTE_IP, this.peer1, this.mockPreferences);
    try {
        this.peerRegistry.getPeer(REMOTE_IP, FROM, TO, createOpen(TO, as2));
    } catch (final BGPDocumentedException e) {
        assertEquals(BGPError.BAD_PEER_AS, e.getError());
        return;
    }
    fail("Peer AS number mismatch");
}
Also used : BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) Test(org.junit.Test)

Example 9 with BGPDocumentedException

use of org.opendaylight.protocol.bgp.parser.BGPDocumentedException in project bgpcep by opendaylight.

the class BGPSessionImpl method handleMessage.

/**
 * Handles incoming message based on their type.
 *
 * @param msg incoming message
 */
synchronized void handleMessage(final Notification msg) {
    if (this.state == State.IDLE) {
        return;
    }
    try {
        // Update last reception time
        this.lastMessageReceivedAt = System.nanoTime();
        if (msg instanceof Open) {
            // Open messages should not be present here
            this.terminate(new BGPDocumentedException(null, BGPError.FSM_ERROR));
        } else if (msg instanceof Notify) {
            final Notify notify = (Notify) msg;
            // Notifications are handled internally
            LOG.info("Session closed because Notification message received: {} / {}, data={}", notify.getErrorCode(), notify.getErrorSubcode(), notify.getData() != null ? ByteBufUtil.hexDump(notify.getData()) : null);
            notifyTerminationReasonAndCloseWithoutMessage(notify.getErrorCode(), notify.getErrorSubcode());
        } else if (msg instanceof Keepalive) {
            // Keepalives are handled internally
            LOG.trace("Received KeepAlive message.");
            this.kaCounter++;
            if (this.kaCounter >= 2) {
                this.sync.kaReceived();
            }
        } else if (msg instanceof RouteRefresh) {
            this.listener.onMessage(this, msg);
        } else if (msg instanceof Update) {
            this.listener.onMessage(this, msg);
            this.sync.updReceived((Update) msg);
        } else {
            LOG.warn("Ignoring unhandled message: {}.", msg.getClass());
        }
        this.sessionState.messageReceived(msg);
    } catch (final BGPDocumentedException e) {
        this.terminate(e);
    }
}
Also used : Notify(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) RouteRefresh(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.RouteRefresh) Keepalive(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Keepalive) Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Open)

Example 10 with BGPDocumentedException

use of org.opendaylight.protocol.bgp.parser.BGPDocumentedException 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)

Aggregations

BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)27 BGPParsingException (org.opendaylight.protocol.bgp.parser.BGPParsingException)9 Test (org.junit.Test)5 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)5 Notification (org.opendaylight.yangtools.yang.binding.Notification)5 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)4 ByteBuf (io.netty.buffer.ByteBuf)3 ArrayList (java.util.ArrayList)3 BGPSessionPreferences (org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences)3 BmpDeserializationException (org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException)3 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)3 Keepalive (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Keepalive)3 Open (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Open)3 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update)3 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters)3 BgpTableTypeImpl (org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl)2 BGPSessionListener (org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener)2 KeepaliveBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.KeepaliveBuilder)2 Notify (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify)2 OpenBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.OpenBuilder)2