Search in sources :

Example 26 with WithdrawnRoutes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.WithdrawnRoutes in project bgpcep by opendaylight.

the class BGPUpdateMessageParser method withdrawUpdate.

private Update withdrawUpdate(final Update parsed, final RevisedErrorHandling errorHandling, final BGPTreatAsWithdrawException withdrawCause) throws BGPDocumentedException {
    if (errorHandling == RevisedErrorHandling.NONE) {
        throw new BGPDocumentedException(withdrawCause);
    }
    // TODO: additional checks as per RFC7606 section 5.2
    LOG.debug("Converting BGP Update message {} to withdraw", parsed, withdrawCause);
    final UpdateBuilder builder = new UpdateBuilder();
    final List<Nlri> nlris = parsed.getNlri();
    final List<WithdrawnRoutes> withdrawn;
    if (nlris != null && !nlris.isEmpty()) {
        withdrawn = Streams.concat(parsed.nonnullWithdrawnRoutes().stream(), nlris.stream().map(nlri -> new WithdrawnRoutesBuilder(nlri).build())).collect(ImmutableList.toImmutableList());
    } else {
        withdrawn = parsed.getWithdrawnRoutes();
    }
    builder.setWithdrawnRoutes(withdrawn);
    final Attributes attributes = parsed.getAttributes();
    if (attributes != null) {
        builder.setAttributes(withdrawAttributes(attributes, withdrawCause));
    }
    return builder.build();
}
Also used : MpReachNlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.MpReachNlri) Nlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.Nlri) MpUnreachNlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlri) LoggerFactory(org.slf4j.LoggerFactory) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes) Unpooled(io.netty.buffer.Unpooled) Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update) UpdateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.UpdateBuilder) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) MpReachNlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.MpReachNlri) Ipv4AddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Notification(org.opendaylight.yangtools.yang.binding.Notification) BGPTreatAsWithdrawException(org.opendaylight.protocol.bgp.parser.BGPTreatAsWithdrawException) Nlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.Nlri) BgpTableTypeImpl(org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl) ParsedAttributes(org.opendaylight.protocol.bgp.parser.spi.ParsedAttributes) PathIdUtil(org.opendaylight.protocol.bgp.parser.spi.PathIdUtil) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) BGPParsingException(org.opendaylight.protocol.bgp.parser.BGPParsingException) Streams(com.google.common.collect.Streams) MultiPathSupportUtil(org.opendaylight.protocol.bgp.parser.spi.MultiPathSupportUtil) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder) TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.graceful.restart.capability.TablesKey) AttributeRegistry(org.opendaylight.protocol.bgp.parser.spi.AttributeRegistry) OriginAttributeParser(org.opendaylight.protocol.bgp.parser.impl.message.update.OriginAttributeParser) NlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.NlriBuilder) MpUnreachNlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlri) List(java.util.List) WithdrawnRoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.WithdrawnRoutesBuilder) MessageParser(org.opendaylight.protocol.bgp.parser.spi.MessageParser) RevisedErrorHandling(org.opendaylight.protocol.bgp.parser.spi.RevisedErrorHandling) Optional(java.util.Optional) WithdrawnRoutes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.WithdrawnRoutes) PeerSpecificParserConstraint(org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint) NextHopAttributeParser(org.opendaylight.protocol.bgp.parser.impl.message.update.NextHopAttributeParser) AsPathAttributeParser(org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathAttributeParser) PathId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId) BGPError(org.opendaylight.protocol.bgp.parser.BGPError) ArrayList(java.util.ArrayList) AttributesReach(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesReach) ImmutableList(com.google.common.collect.ImmutableList) ByteBuf(io.netty.buffer.ByteBuf) MessageUtil(org.opendaylight.protocol.bgp.parser.spi.MessageUtil) Objects.requireNonNull(java.util.Objects.requireNonNull) MessageSerializer(org.opendaylight.protocol.bgp.parser.spi.MessageSerializer) AttributesUnreach(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesUnreach) Logger(org.slf4j.Logger) NlriRegistry(org.opendaylight.protocol.bgp.parser.spi.NlriRegistry) Ipv4Util(org.opendaylight.protocol.util.Ipv4Util) AttributesUnreachBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesUnreachBuilder) UnicastSubsequentAddressFamily(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.UnicastSubsequentAddressFamily) WithdrawnRoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.WithdrawnRoutesBuilder) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes) ParsedAttributes(org.opendaylight.protocol.bgp.parser.spi.ParsedAttributes) UpdateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.UpdateBuilder) WithdrawnRoutes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.WithdrawnRoutes)

Example 27 with WithdrawnRoutes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.WithdrawnRoutes in project bgpcep by opendaylight.

the class BGPUpdateMessageParser method serializeMessage.

@Override
public void serializeMessage(final Notification message, final ByteBuf bytes) {
    checkArgument(message instanceof Update, "Message needs to be of type Update");
    final Update update = (Update) message;
    final ByteBuf messageBody = Unpooled.buffer();
    final List<WithdrawnRoutes> withdrawnRoutes = update.getWithdrawnRoutes();
    if (withdrawnRoutes != null) {
        final ByteBuf withdrawnRoutesBuf = Unpooled.buffer();
        withdrawnRoutes.forEach(withdrawnRoute -> writePathIdPrefix(withdrawnRoutesBuf, withdrawnRoute.getPathId(), withdrawnRoute.getPrefix()));
        messageBody.writeShort(withdrawnRoutesBuf.writerIndex());
        messageBody.writeBytes(withdrawnRoutesBuf);
    } else {
        messageBody.writeShort(0);
    }
    if (update.getAttributes() != null) {
        final ByteBuf pathAttributesBuf = Unpooled.buffer();
        this.attrReg.serializeAttribute(update.getAttributes(), pathAttributesBuf);
        messageBody.writeShort(pathAttributesBuf.writerIndex());
        messageBody.writeBytes(pathAttributesBuf);
    } else {
        messageBody.writeShort(0);
    }
    final List<Nlri> nlris = update.getNlri();
    if (nlris != null) {
        nlris.forEach(nlri -> writePathIdPrefix(messageBody, nlri.getPathId(), nlri.getPrefix()));
    }
    MessageUtil.formatMessage(TYPE, messageBody, bytes);
}
Also used : MpReachNlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.MpReachNlri) Nlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.Nlri) MpUnreachNlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlri) WithdrawnRoutes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.WithdrawnRoutes) Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update) ByteBuf(io.netty.buffer.ByteBuf)

Example 28 with WithdrawnRoutes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.WithdrawnRoutes in project bgpcep by opendaylight.

the class BGPParserTest method testUpdateMessageWithdrawAddPath.

/*
     * Tests withdrawn routes with multiple paths.
     *
     * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
     * 00 29 <- length (41) - including header
     * 02 <- message type
     * 00 12 <- withdrawn routes length (18)
     * 00 00 00 01 <- path-id (1)
     * 1e ac 10 00 04 <- route (172.16.0.4)
     * 00 00 00 02 <- path-id (2)
     * 1e ac 10 00 04 <- route (172.16.0.4)
     * 00 00 <- total path attribute length
     *
     */
@Test
public void testUpdateMessageWithdrawAddPath() throws Exception {
    final byte[] body = ByteArray.cutBytes(updatesWithMultiplePath.get(1), MessageUtil.COMMON_HEADER_LENGTH);
    final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(updatesWithMultiplePath.get(1), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
    final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, mpConstraint);
    // attributes
    final List<WithdrawnRoutes> withdrawnRoutes = new ArrayList<>();
    withdrawnRoutes.add(new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("172.16.0.4/30")).setPathId(new PathId(Uint32.ONE)).build());
    withdrawnRoutes.add(new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("172.16.0.4/30")).setPathId(new PathId(Uint32.TWO)).build());
    // check API message
    final Update expectedMessage = new UpdateBuilder().setWithdrawnRoutes(withdrawnRoutes).build();
    assertEquals(expectedMessage.getWithdrawnRoutes(), message.getWithdrawnRoutes());
    final ByteBuf buffer = Unpooled.buffer();
    BGPParserTest.updateParser.serializeMessage(message, buffer);
    assertArrayEquals(updatesWithMultiplePath.get(1), ByteArray.readAllBytes(buffer));
}
Also used : PathId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId) WithdrawnRoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.WithdrawnRoutesBuilder) ArrayList(java.util.ArrayList) UpdateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.UpdateBuilder) WithdrawnRoutes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.WithdrawnRoutes) Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update) ByteBuf(io.netty.buffer.ByteBuf) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) PeerSpecificParserConstraint(org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint) Test(org.junit.Test)

Example 29 with WithdrawnRoutes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.WithdrawnRoutes in project bgpcep by opendaylight.

the class MvpnIpv6NlriHandler method serializeAttribute.

@Override
public void serializeAttribute(final Attributes pathAttributes, final ByteBuf byteAggregator) {
    final AttributesReach pathAttributes1 = pathAttributes.augmentation(AttributesReach.class);
    final AttributesUnreach pathAttributes2 = pathAttributes.augmentation(AttributesUnreach.class);
    if (pathAttributes1 != null) {
        final AdvertizedRoutes routes = pathAttributes1.getMpReachNlri().getAdvertizedRoutes();
        if (routes != null && routes.getDestinationType() instanceof DestinationMvpnIpv6AdvertizedCase) {
            final DestinationMvpnIpv6AdvertizedCase reach = (DestinationMvpnIpv6AdvertizedCase) routes.getDestinationType();
            Ipv6NlriHandler.serializeNlri(reach.getDestinationMvpn().getMvpnDestination(), byteAggregator);
        }
    } else if (pathAttributes2 != null) {
        final WithdrawnRoutes withdrawnRoutes = pathAttributes2.getMpUnreachNlri().getWithdrawnRoutes();
        if (withdrawnRoutes != null && withdrawnRoutes.getDestinationType() instanceof DestinationMvpnIpv6WithdrawnCase) {
            final DestinationMvpnIpv6WithdrawnCase reach = (DestinationMvpnIpv6WithdrawnCase) withdrawnRoutes.getDestinationType();
            Ipv6NlriHandler.serializeNlri(reach.getDestinationMvpn().getMvpnDestination(), byteAggregator);
        }
    }
}
Also used : AttributesReach(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesReach) AdvertizedRoutes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.mp.reach.nlri.AdvertizedRoutes) DestinationMvpnIpv6WithdrawnCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.ipv6.rev180417.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationMvpnIpv6WithdrawnCase) DestinationMvpnIpv6AdvertizedCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.ipv6.rev180417.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationMvpnIpv6AdvertizedCase) AttributesUnreach(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesUnreach) WithdrawnRoutes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.mp.unreach.nlri.WithdrawnRoutes)

Aggregations

WithdrawnRoutes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.mp.unreach.nlri.WithdrawnRoutes)14 AttributesReach (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesReach)13 AttributesUnreach (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesUnreach)13 AdvertizedRoutes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.mp.reach.nlri.AdvertizedRoutes)12 WithdrawnRoutes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.WithdrawnRoutes)9 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update)7 ByteBuf (io.netty.buffer.ByteBuf)6 Test (org.junit.Test)6 WithdrawnRoutesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.WithdrawnRoutesBuilder)6 MpUnreachNlri (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlri)6 PeerSpecificParserConstraint (org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)5 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)5 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes)5 UpdateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.UpdateBuilder)5 Attributes1 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1)5 Attributes2 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes2)5 AdvertizedRoutes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutes)5 WithdrawnRoutes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.unreach.nlri.WithdrawnRoutes)5 Nlri (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.update.message.Nlri)4 MpUnreachNlriBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlriBuilder)4