Search in sources :

Example 6 with BGPParsingException

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

the class BgpTestActivator method startImpl.

@Override
protected List<AutoCloseable> startImpl(final BGPExtensionProviderContext context) {
    initMock();
    final List<AutoCloseable> regs = Lists.newArrayList();
    regs.add(context.registerAttributeParser(TYPE, this.attrParser));
    regs.add(context.registerAttributeSerializer(DataObject.class, this.attrSerializer));
    regs.add(context.registerParameterParser(TYPE, this.paramParser));
    regs.add(context.registerParameterSerializer(BgpParameters.class, this.paramSerializer));
    regs.add(context.registerCapabilityParser(TYPE, this.capaParser));
    regs.add(context.registerCapabilitySerializer(CParameters.class, this.capaSerializer));
    regs.add(context.registerBgpPrefixSidTlvParser(TYPE, this.sidTlvParser));
    regs.add(context.registerBgpPrefixSidTlvSerializer(BgpPrefixSidTlv.class, this.sidTlvSerializer));
    regs.add(context.registerMessageParser(TYPE, this.msgParser));
    regs.add(context.registerMessageSerializer(Notification.class, this.msgSerializer));
    regs.add(context.registerAddressFamily(Ipv4AddressFamily.class, 1));
    regs.add(context.registerAddressFamily(Ipv6AddressFamily.class, 2));
    regs.add(context.registerSubsequentAddressFamily(UnicastSubsequentAddressFamily.class, 1));
    this.nextHopParserSerializer = new NextHopParserSerializer() {

        @Override
        public CNextHop parseNextHop(final ByteBuf buffer) throws BGPParsingException {
            return new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("127.0.0.1")).build()).build();
        }

        @Override
        public void serializeNextHop(final CNextHop cNextHop, final ByteBuf byteAggregator) {
            final byte[] mpReachBytes = { 0x7f, 0x00, 0x00, 0x01 };
            byteAggregator.writeBytes(mpReachBytes);
        }
    };
    regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, this.nlriParser, this.nextHopParserSerializer, Ipv4NextHopCase.class));
    regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, this.nlriParser, this.nextHopParserSerializer, Ipv6NextHopCase.class));
    regs.add(context.registerNlriSerializer(DataObject.class, this.nlriSerializer));
    regs.add(context.registerExtendedCommunityParser(0, 0, this.exParser));
    regs.add(context.registerExtendedCommunitySerializer(RouteTargetIpv4Case.class, this.exSerializer));
    return regs;
}
Also used : Ipv6AddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily) RouteTargetIpv4Case(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteTargetIpv4Case) Ipv4AddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily) CParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParameters) BGPParsingException(org.opendaylight.protocol.bgp.parser.BGPParsingException) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters) ByteBuf(io.netty.buffer.ByteBuf) CNextHop(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.CNextHop) Ipv4NextHopCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase) Notification(org.opendaylight.yangtools.yang.binding.Notification) Ipv6NextHopCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCase) Ipv4NextHopBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) BgpPrefixSidTlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.BgpPrefixSidTlv) Ipv4NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder) UnicastSubsequentAddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily) NextHopParserSerializer(org.opendaylight.protocol.bgp.parser.spi.NextHopParserSerializer) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 7 with BGPParsingException

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

the class SimpleNlriRegistry method getAfi.

private Class<? extends AddressFamily> getAfi(final ByteBuf buffer) throws BGPParsingException {
    final int afiVal = buffer.readUnsignedShort();
    final Class<? extends AddressFamily> afi = this.afiReg.classForFamily(afiVal);
    if (afi == null) {
        throw new BGPParsingException("Address Family Identifier: '" + afiVal + "' not supported.");
    }
    return afi;
}
Also used : BGPParsingException(org.opendaylight.protocol.bgp.parser.BGPParsingException) PeerSpecificParserConstraint(org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)

Example 8 with BGPParsingException

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

the class SimpleNlriRegistry method getSafi.

private Class<? extends SubsequentAddressFamily> getSafi(final ByteBuf buffer) throws BGPParsingException {
    final int safiVal = buffer.readUnsignedByte();
    final Class<? extends SubsequentAddressFamily> safi = this.safiReg.classForFamily(safiVal);
    if (safi == null) {
        throw new BGPParsingException("Subsequent Address Family Identifier: '" + safiVal + "' not supported.");
    }
    return safi;
}
Also used : BGPParsingException(org.opendaylight.protocol.bgp.parser.BGPParsingException) PeerSpecificParserConstraint(org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)

Example 9 with BGPParsingException

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

the class PeerDownHandler method parseBgpNotificationMessage.

private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.Notification parseBgpNotificationMessage(final ByteBuf bytes) throws BmpDeserializationException {
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.NotificationBuilder notificationCBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.NotificationBuilder();
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.notification.NotificationBuilder notificationBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.down.data.notification.NotificationBuilder();
    try {
        final Notification not = this.msgRegistry.parseMessage(bytes, null);
        requireNonNull(not, "Notify message may not be null.");
        Preconditions.checkArgument(not instanceof NotifyMessage, "An instance of NotifyMessage is required");
        notificationBuilder.fieldsFrom((NotifyMessage) not);
        notificationCBuilder.setNotification(notificationBuilder.build());
    } catch (final BGPDocumentedException | BGPParsingException e) {
        throw new BmpDeserializationException("Error while parsing BGP Notification message.", e);
    }
    return notificationCBuilder.build();
}
Also used : Preconditions(com.google.common.base.Preconditions) BGPParsingException(org.opendaylight.protocol.bgp.parser.BGPParsingException) PeerDownNotification(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerDownNotification) Notification(org.opendaylight.yangtools.yang.binding.Notification) PeerDownNotificationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerDownNotificationBuilder) NotifyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.NotifyMessage) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) BmpDeserializationException(org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException)

Example 10 with BGPParsingException

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

the class BGPUpdateMessageParser method parseMessageBody.

/**
 * Parse Update message from buffer.
 * Calls {@link #checkMandatoryAttributesPresence(Update)} to check for presence of mandatory attributes.
 *
 * @param buffer Encoded BGP message in ByteBuf
 * @param messageLength Length of the BGP message
 * @param constraint Peer specific constraints
 * @return Parsed Update message body
 */
@Override
public Update parseMessageBody(final ByteBuf buffer, final int messageLength, final PeerSpecificParserConstraint constraint) throws BGPDocumentedException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Buffer cannot be null or empty.");
    final UpdateBuilder builder = new UpdateBuilder();
    final boolean isMultiPathSupported = MultiPathSupportUtil.isTableTypeSupported(constraint, new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
    final int withdrawnRoutesLength = buffer.readUnsignedShort();
    if (withdrawnRoutesLength > 0) {
        final List<WithdrawnRoutes> withdrawnRoutes = new ArrayList<>();
        final ByteBuf withdrawnRoutesBuffer = buffer.readBytes(withdrawnRoutesLength);
        while (withdrawnRoutesBuffer.isReadable()) {
            final WithdrawnRoutesBuilder withdrawnRoutesBuilder = new WithdrawnRoutesBuilder();
            if (isMultiPathSupported) {
                withdrawnRoutesBuilder.setPathId(PathIdUtil.readPathId(withdrawnRoutesBuffer));
            }
            withdrawnRoutesBuilder.setPrefix(Ipv4Util.prefixForByteBuf(withdrawnRoutesBuffer));
            withdrawnRoutes.add(withdrawnRoutesBuilder.build());
        }
        builder.setWithdrawnRoutes(withdrawnRoutes);
    }
    final int totalPathAttrLength = buffer.readUnsignedShort();
    if (withdrawnRoutesLength == 0 && totalPathAttrLength == 0) {
        return builder.build();
    }
    if (totalPathAttrLength > 0) {
        try {
            final Attributes attributes = this.reg.parseAttributes(buffer.readSlice(totalPathAttrLength), constraint);
            builder.setAttributes(attributes);
        } catch (final RuntimeException | BGPParsingException e) {
            // Catch everything else and turn it into a BGPDocumentedException
            throw new BGPDocumentedException("Could not parse BGP attributes.", BGPError.MALFORMED_ATTR_LIST, e);
        }
    }
    final List<Nlri> nlri = new ArrayList<>();
    while (buffer.isReadable()) {
        final NlriBuilder nlriBuilder = new NlriBuilder();
        if (isMultiPathSupported) {
            nlriBuilder.setPathId(PathIdUtil.readPathId(buffer));
        }
        nlriBuilder.setPrefix(Ipv4Util.prefixForByteBuf(buffer));
        nlri.add(nlriBuilder.build());
    }
    if (!nlri.isEmpty()) {
        builder.setNlri(nlri);
    }
    final Update msg = builder.build();
    checkMandatoryAttributesPresence(msg);
    LOG.debug("BGP Update message was parsed {}.", msg);
    return msg;
}
Also used : Ipv4AddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily) ArrayList(java.util.ArrayList) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) UpdateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.UpdateBuilder) BGPParsingException(org.opendaylight.protocol.bgp.parser.BGPParsingException) WithdrawnRoutes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.update.message.WithdrawnRoutes) ByteBuf(io.netty.buffer.ByteBuf) Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update) PeerSpecificParserConstraint(org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint) Nlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.update.message.Nlri) WithdrawnRoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.update.message.WithdrawnRoutesBuilder) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) BgpTableTypeImpl(org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl) NlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.update.message.NlriBuilder) UnicastSubsequentAddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily)

Aggregations

BGPParsingException (org.opendaylight.protocol.bgp.parser.BGPParsingException)14 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)9 ByteBuf (io.netty.buffer.ByteBuf)5 Notification (org.opendaylight.yangtools.yang.binding.Notification)5 ArrayList (java.util.ArrayList)3 PeerSpecificParserConstraint (org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)3 BmpDeserializationException (org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException)3 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters)2 Ipv4AddressFamily (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily)2 UnicastSubsequentAddressFamily (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily)2 Preconditions (com.google.common.base.Preconditions)1 BgpTableTypeImpl (org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl)1 SegmentType (org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathSegmentParser.SegmentType)1 NextHopParserSerializer (org.opendaylight.protocol.bgp.parser.spi.NextHopParserSerializer)1 RSVPParsingException (org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException)1 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)1 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)1 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)1 PortNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber)1 TeLspAttributesCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.path.attribute.link.state.attribute.TeLspAttributesCaseBuilder)1