Search in sources :

Example 1 with RouteRefresh

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.RouteRefresh 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 2 with RouteRefresh

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.RouteRefresh in project bgpcep by opendaylight.

the class BGPActivator method registerCapabilityParsers.

private static void registerCapabilityParsers(final List<AutoCloseable> regs, final BGPExtensionProviderContext context) {
    final AddressFamilyRegistry afiReg = context.getAddressFamilyRegistry();
    final SubsequentAddressFamilyRegistry safiReg = context.getSubsequentAddressFamilyRegistry();
    final MultiProtocolCapabilityHandler multi = new MultiProtocolCapabilityHandler(afiReg, safiReg);
    regs.add(context.registerCapabilityParser(MultiProtocolCapabilityHandler.CODE, multi));
    regs.add(context.registerCapabilitySerializer(MultiprotocolCapability.class, multi));
    final AddPathCapabilityHandler addPath = new AddPathCapabilityHandler(afiReg, safiReg);
    regs.add(context.registerCapabilityParser(AddPathCapabilityHandler.CODE, addPath));
    regs.add(context.registerCapabilitySerializer(AddPathCapability.class, addPath));
    final RouteRefreshCapabilityHandler routeRefresh = new RouteRefreshCapabilityHandler();
    regs.add(context.registerCapabilityParser(RouteRefreshCapabilityHandler.CODE, routeRefresh));
    regs.add(context.registerCapabilitySerializer(RouteRefreshCapability.class, routeRefresh));
    final As4CapabilityHandler as4 = new As4CapabilityHandler();
    regs.add(context.registerCapabilityParser(As4CapabilityHandler.CODE, as4));
    regs.add(context.registerCapabilitySerializer(As4BytesCapability.class, as4));
    final GracefulCapabilityHandler grace = new GracefulCapabilityHandler(afiReg, safiReg);
    regs.add(context.registerCapabilitySerializer(GracefulRestartCapability.class, grace));
    regs.add(context.registerCapabilityParser(GracefulCapabilityHandler.CODE, grace));
    final CapabilityParameterParser cpp = new CapabilityParameterParser(context.getCapabilityRegistry());
    regs.add(context.registerParameterParser(CapabilityParameterParser.TYPE, cpp));
    regs.add(context.registerParameterSerializer(BgpParameters.class, cpp));
    final BgpExtendedMessageCapabilityHandler bgpextmessage = new BgpExtendedMessageCapabilityHandler();
    regs.add(context.registerCapabilityParser(BgpExtendedMessageCapabilityHandler.CODE, bgpextmessage));
    regs.add(context.registerCapabilitySerializer(BgpExtendedMessageCapability.class, bgpextmessage));
}
Also used : AddressFamilyRegistry(org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry) SubsequentAddressFamilyRegistry(org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry) RouteRefreshCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.RouteRefreshCapability) RouteRefreshCapabilityHandler(org.opendaylight.protocol.bgp.parser.impl.message.open.RouteRefreshCapabilityHandler) AddPathCapabilityHandler(org.opendaylight.protocol.bgp.parser.impl.message.open.AddPathCapabilityHandler) GracefulCapabilityHandler(org.opendaylight.protocol.bgp.parser.impl.message.open.GracefulCapabilityHandler) CapabilityParameterParser(org.opendaylight.protocol.bgp.parser.impl.message.open.CapabilityParameterParser) As4CapabilityHandler(org.opendaylight.protocol.bgp.parser.impl.message.open.As4CapabilityHandler) As4BytesCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapability) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters) MultiProtocolCapabilityHandler(org.opendaylight.protocol.bgp.parser.impl.message.open.MultiProtocolCapabilityHandler) BgpExtendedMessageCapabilityHandler(org.opendaylight.protocol.bgp.parser.impl.message.open.BgpExtendedMessageCapabilityHandler) SubsequentAddressFamilyRegistry(org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry) MultiprotocolCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.MultiprotocolCapability) AddPathCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.AddPathCapability) GracefulRestartCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.GracefulRestartCapability) BgpExtendedMessageCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.c.parameters.BgpExtendedMessageCapability)

Example 3 with RouteRefresh

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.RouteRefresh in project bgpcep by opendaylight.

the class BGPRouteRefreshMessageParser method serializeMessage.

/**
 * Serializes BGP Route Refresh message.
 *
 * @param message to be serialized
 * @param bytes ByteBuf where the message will be serialized
 */
@Override
public void serializeMessage(final Notification message, final ByteBuf bytes) {
    Preconditions.checkArgument(message instanceof RouteRefresh, "Message is not of type RouteRefresh.");
    final RouteRefresh msg = (RouteRefresh) message;
    final ByteBuf msgBuf = Unpooled.buffer(TRIPLET_BYTE_SIZE);
    MultiprotocolCapabilitiesUtil.serializeMPAfiSafi(this.afiReg, this.safiReg, msg.getAfi(), msg.getSafi(), msgBuf);
    LOG.trace("RouteRefresh message serialized to: {}", ByteBufUtil.hexDump(msgBuf));
    MessageUtil.formatMessage(TYPE, msgBuf, bytes);
}
Also used : RouteRefresh(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.RouteRefresh) ByteBuf(io.netty.buffer.ByteBuf)

Example 4 with RouteRefresh

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.RouteRefresh in project bgpcep by opendaylight.

the class BGPPeer method onRouteRefreshMessage.

private void onRouteRefreshMessage(final RouteRefresh message) {
    final Class<? extends AddressFamily> rrAfi = message.getAfi();
    final Class<? extends SubsequentAddressFamily> rrSafi = message.getSafi();
    final TablesKey key = new TablesKey(rrAfi, rrSafi);
    final AdjRibOutListener listener = this.adjRibOutListenerSet.get(key);
    if (listener != null) {
        listener.close();
        this.adjRibOutListenerSet.remove(key);
        createAdjRibOutListener(key, listener.isMpSupported());
    } else {
        LOG.info("Ignoring RouteRefresh message. Afi/Safi is not supported: {}, {}.", rrAfi, rrSafi);
    }
}
Also used : TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey)

Example 5 with RouteRefresh

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.RouteRefresh in project bgpcep by opendaylight.

the class BGPRouteRefreshMessageParser method parseMessageBody.

/**
 * Parses BGP Route Refresh message to bytes.
 *
 * @param body ByteBuf to be parsed
 * @param messageLength the length of the message
 * @return {@link RouteRefresh} which represents BGP notification message
 * @throws BGPDocumentedException if parsing goes wrong
 */
@Override
public RouteRefresh parseMessageBody(final ByteBuf body, final int messageLength) throws BGPDocumentedException {
    Preconditions.checkArgument(body != null, "Body buffer cannot be null.");
    if (body.readableBytes() < TRIPLET_BYTE_SIZE) {
        throw BGPDocumentedException.badMessageLength("RouteRefresh message is too small.", messageLength);
    }
    final Optional<BgpTableType> parsedAfiSafi = MultiprotocolCapabilitiesUtil.parseMPAfiSafi(body, this.afiReg, this.safiReg);
    if (!parsedAfiSafi.isPresent()) {
        throw new BGPDocumentedException("Unsupported afi/safi in Route Refresh message.", BGPError.WELL_KNOWN_ATTR_NOT_RECOGNIZED);
    }
    return new RouteRefreshBuilder(parsedAfiSafi.get()).build();
}
Also used : BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType) RouteRefreshBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.RouteRefreshBuilder) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException)

Aggregations

RouteRefresh (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.RouteRefresh)3 ByteBuf (io.netty.buffer.ByteBuf)2 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)2 RouteRefreshBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.RouteRefreshBuilder)2 Test (org.junit.Test)1 AddPathCapabilityHandler (org.opendaylight.protocol.bgp.parser.impl.message.open.AddPathCapabilityHandler)1 As4CapabilityHandler (org.opendaylight.protocol.bgp.parser.impl.message.open.As4CapabilityHandler)1 BgpExtendedMessageCapabilityHandler (org.opendaylight.protocol.bgp.parser.impl.message.open.BgpExtendedMessageCapabilityHandler)1 CapabilityParameterParser (org.opendaylight.protocol.bgp.parser.impl.message.open.CapabilityParameterParser)1 GracefulCapabilityHandler (org.opendaylight.protocol.bgp.parser.impl.message.open.GracefulCapabilityHandler)1 MultiProtocolCapabilityHandler (org.opendaylight.protocol.bgp.parser.impl.message.open.MultiProtocolCapabilityHandler)1 RouteRefreshCapabilityHandler (org.opendaylight.protocol.bgp.parser.impl.message.open.RouteRefreshCapabilityHandler)1 AddressFamilyRegistry (org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry)1 SubsequentAddressFamilyRegistry (org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry)1 Keepalive (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Keepalive)1 Notify (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify)1 Open (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Open)1 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update)1 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters)1 As4BytesCapability (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapability)1