Search in sources :

Example 21 with AsPathBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder in project bgpcep by opendaylight.

the class BGPParserTest method testGetUpdateMessage3.

/*
     * Tests more AS Numbers in AS_PATH, AGGREGATOR, ORIGIN.INCOMPLETE
     *
     * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
     * 00 4b <- length (75) - including header
     * 02 <- message type
     * 00 00 <- withdrawn routes length
     * 00 30 <- total path attribute length (48)
     * 40 <- attribute flags
     * 01 <- attribute type code (origin)
     * 01 <- attribute length
     * 02 <- Origin value (Incomplete)
     * 40 <- attribute flags
     * 02 <- attribute type code (as path)
     * 10 <- attribute length
     * 02 <- AS_SEQUENCE
     * 01 <- path segment count
     * 00 00 00 1e <- path segment value (30)
     * 01 <- AS_SET
     * 02 <- path segment count
     * 00 00 00 0a <- path segment value (10)
     * 00 00 00 14 <- path segment value (20)
     * 40 <- attribute flags
     * 03 <- attribute type (Next hop)
     * 04 <- attribute length
     * 0a 00 00 09 <- value (10.0.0.9)
     * 80 <- attribute flags
     * 04 <- attribute type code (multi exit disc)
     * 04 <- attribute length
     * 00 00 00 00 <- value
     * c0 <- attribute flags
     * 07 <- attribute type (Aggregator)
     * 08 <- attribute length
     * 00 00 00 1e <- value (AS number = 30)
     * 0a 00 00 09 <- value (IP address = 10.0.0.9)
     *
     * //NLRI
     * 15 ac 10 00 <- IPv4 Prefix (172.16.0.0 / 21)
     */
@Test
public void testGetUpdateMessage3() throws Exception {
    final byte[] body = ByteArray.cutBytes(inputBytes.get(2), MessageUtil.COMMON_HEADER_LENGTH);
    final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(2), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
    final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
    final UpdateBuilder builder = new UpdateBuilder();
    // check nlri
    final List<Nlri> nlris = Lists.newArrayList(new NlriBuilder().setPrefix(new Ipv4Prefix("172.16.0.0/21")).build());
    builder.setNlri(nlris);
    assertEquals(builder.getNlri(), message.getNlri());
    // check fields
    assertNull(message.getWithdrawnRoutes());
    // attributes
    final List<AsNumber> asNumbers = new ArrayList<>();
    asNumbers.add(new AsNumber(30L));
    final List<Segments> asPath = Lists.newArrayList();
    asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build());
    final List<AsNumber> asSet = Lists.newArrayList(new AsNumber(10L), new AsNumber(20L));
    asPath.add(new SegmentsBuilder().setAsSet(asSet).build());
    final Aggregator aggregator = new AggregatorBuilder().setAsNumber(new AsNumber((long) 30)).setNetworkAddress(new Ipv4Address("10.0.0.9")).build();
    final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.9")).build()).build();
    // check path attributes
    final Attributes attrs = message.getAttributes();
    final AttributesBuilder paBuilder = new AttributesBuilder();
    paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Incomplete).build());
    assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
    paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
    assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
    paBuilder.setCNextHop(nextHop);
    assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
    paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
    assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
    paBuilder.setAggregator(aggregator);
    assertEquals(paBuilder.getAggregator(), attrs.getAggregator());
    paBuilder.setUnrecognizedAttributes(Collections.emptyList());
    builder.setAttributes(paBuilder.build());
    assertEquals(builder.build(), message);
    final ByteBuf buffer = Unpooled.buffer();
    BGPParserTest.updateParser.serializeMessage(message, buffer);
    assertArrayEquals(inputBytes.get(2), ByteArray.readAllBytes(buffer));
}
Also used : OriginBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.OriginBuilder) MultiExitDiscBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.MultiExitDiscBuilder) ArrayList(java.util.ArrayList) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) Segments(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.Segments) UpdateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.UpdateBuilder) Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update) ByteBuf(io.netty.buffer.ByteBuf) AsPathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder) Ipv4NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder) SegmentsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.SegmentsBuilder) AggregatorBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AggregatorBuilder) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Aggregator(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Aggregator) Ipv4NextHopCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) 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) 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) NlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.update.message.NlriBuilder) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder) Test(org.junit.Test)

Example 22 with AsPathBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder in project bgpcep by opendaylight.

the class BGPParserTest method testUpdateMessageNlriAddPath.

/*
     * Tests IPv4 NEXT_HOP, ATOMIC_AGGREGATE, COMMUNITY, NLRI with multiple paths.
     *
     * ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
     * 00 60 <- length (96) - including header
     * 02 <- message type
     * 00 00 <- withdrawn routes length
     * 00 31 <- total path attribute length (49)
     * 40 <- attribute flags
     * 01 <- attribute type code (origin)
     * 01 <- attribute length
     * 00 <- Origin value (IGP)
     * 40 <- attribute flags
     * 02 <- attribute type code (as path)
     * 06 <- attribute length
     * 02 <- AS_SEQUENCE
     * 01 <- path segment count
     * 00 00 fd ea <- path segment value (65002)
     * 40 <- attribute flags
     * 03 <- attribute type code (Next Hop)
     * 04 <- attribute length
     * 0a 00 00 02 <- value (10.0.0.2)
     * 80 <- attribute flags
     * 04 <- attribute type code (multi exit disc)
     * 04 <- attribute length
     * 00 00 00 00 <- value
     * 40 <- attribute flags
     * 06 <- attribute type code (atomic aggregate)
     * 00 <- attribute length
     * C0 <- attribute flags
     * 08 <- attribute type code (community)
     * 10 <- attribute length
     * FF FF FF 01 <- value (NO_EXPORT)
     * FF FF FF 02 <- value (NO_ADVERTISE)
     * FF FF FF 03 <- value (NO_EXPORT_SUBCONFED)
     * FF FF FF 10 <- unknown Community
     *
     * //NLRI
     * 00 00 00 01 <- path-id (1)
     * 18 ac 11 02 <- IPv4 Prefix (172.17.1.0 / 24)
     * 00 00 00 01 <- path-id (2)
     * 18 ac 11 01 <- IPv4 Prefix (172.17.1.0 / 24)
     * 00 00 00 01 <- path-id (1)
     * 18 ac 11 00 <- IPv4 Prefix (172.17.0.0 / 24)
     */
@Test
public void testUpdateMessageNlriAddPath() throws Exception {
    final byte[] body = ByteArray.cutBytes(updatesWithMultiplePath.get(0), MessageUtil.COMMON_HEADER_LENGTH);
    final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(updatesWithMultiplePath.get(0), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
    final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, constraint);
    // check fields
    assertNull(message.getWithdrawnRoutes());
    // attributes
    final List<AsNumber> asNumbers = new ArrayList<>();
    asNumbers.add(new AsNumber(65002L));
    final List<Segments> asPath = Lists.newArrayList();
    asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build());
    final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
    final List<Communities> comms = Lists.newArrayList();
    comms.add((Communities) CommunityUtil.NO_EXPORT);
    comms.add((Communities) CommunityUtil.NO_ADVERTISE);
    comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
    comms.add((Communities) CommunityUtil.create(NoopReferenceCache.getInstance(), 0xFFFF, 0xFF10));
    final UpdateBuilder builder = new UpdateBuilder();
    // check nlri
    final List<Nlri> nlris = Lists.newArrayList();
    nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("172.17.1.0/24")).setPathId(new PathId(1L)).build());
    nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("172.17.1.0/24")).setPathId(new PathId(2L)).build());
    nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("172.17.0.0/24")).setPathId(new PathId(1L)).build());
    assertEquals(nlris, message.getNlri());
    builder.setNlri(nlris);
    // check path attributes
    final Attributes attrs = message.getAttributes();
    final AttributesBuilder paBuilder = new AttributesBuilder();
    paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
    assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
    paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
    assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
    paBuilder.setCNextHop(nextHop);
    assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
    paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
    assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
    paBuilder.setAtomicAggregate(new AtomicAggregateBuilder().build());
    assertEquals(paBuilder.getAtomicAggregate(), attrs.getAtomicAggregate());
    paBuilder.setCommunities(comms);
    assertEquals(paBuilder.getCommunities(), attrs.getCommunities());
    paBuilder.setUnrecognizedAttributes(Collections.emptyList());
    builder.setAttributes(paBuilder.build());
    assertEquals(builder.build(), message);
    final ByteBuf buffer = Unpooled.buffer();
    BGPParserTest.updateParser.serializeMessage(message, buffer);
    assertArrayEquals(updatesWithMultiplePath.get(0), ByteArray.readAllBytes(buffer));
}
Also used : Communities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.Communities) ExtendedCommunities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.ExtendedCommunities) OriginBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.OriginBuilder) MultiExitDiscBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.MultiExitDiscBuilder) ArrayList(java.util.ArrayList) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) Segments(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.Segments) UpdateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.UpdateBuilder) Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update) ByteBuf(io.netty.buffer.ByteBuf) PathId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.PathId) AsPathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder) Ipv4NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder) SegmentsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.SegmentsBuilder) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Ipv4NextHopCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase) AtomicAggregateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AtomicAggregateBuilder) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) 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) 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) NlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.update.message.NlriBuilder) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder) Test(org.junit.Test)

Example 23 with AsPathBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder in project bgpcep by opendaylight.

the class AsPathAttributeParser method parseAsPath.

/**
 * Parses AS_PATH from bytes.
 *
 * @param refCache ReferenceCache shared reference of object
 * @param buffer bytes to be parsed
 * @return new ASPath object
 * @throws BGPDocumentedException if there is no AS_SEQUENCE present (mandatory)
 * @throws BGPParsingException
 */
private static AsPath parseAsPath(final ReferenceCache refCache, final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
    if (!buffer.isReadable()) {
        return EMPTY;
    }
    final ArrayList<Segments> ases = new ArrayList<>();
    boolean isSequence = false;
    while (buffer.isReadable()) {
        final int type = buffer.readUnsignedByte();
        final SegmentType segmentType = AsPathSegmentParser.parseType(type);
        if (segmentType == null) {
            throw new BGPParsingException("AS Path segment type unknown : " + type);
        }
        final int count = buffer.readUnsignedByte();
        final List<AsNumber> asList = AsPathSegmentParser.parseAsSegment(refCache, count, buffer.readSlice(count * AsPathSegmentParser.AS_NUMBER_LENGTH));
        if (segmentType == SegmentType.AS_SEQUENCE) {
            ases.add(new SegmentsBuilder().setAsSequence(asList).build());
            isSequence = true;
        } else {
            ases.add(new SegmentsBuilder().setAsSet(asList).build());
        }
    }
    if (!isSequence) {
        throw new BGPDocumentedException("AS_SEQUENCE must be present in AS_PATH attribute.", BGPError.AS_PATH_MALFORMED);
    }
    ases.trimToSize();
    return new AsPathBuilder().setSegments(ases).build();
}
Also used : SegmentType(org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathSegmentParser.SegmentType) AsPathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder) SegmentsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.SegmentsBuilder) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) ArrayList(java.util.ArrayList) Segments(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.Segments) BGPParsingException(org.opendaylight.protocol.bgp.parser.BGPParsingException) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)

Example 24 with AsPathBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder in project bgpcep by opendaylight.

the class ParserTest method testBGPLink.

/*
     * Tests BGP Link Ipv4
     *
     * 00 00 <- withdrawn routes length
     * 01 48 <- total path attribute length (328)
     * 90 <- attribute flags
        0e <- attribute type code (MP reach)
        01 2c <- attribute extended length (300)
        40 04 <- AFI (16388 - Linkstate)
        47 <- SAFI (71 - Linkstate)
        04 <- next hop length
        19 19 19 01 <- nexthop (25.25.25.1)
        00 <- reserved

        00 02 <- NLRI type (2 - linkNLRI)
        00 5d <- NLRI length (93)
        03 <- ProtocolID - OSPF
        00 00 00 00 00 00 00 01 <- identifier

        01 00 <- local node descriptor type (256)
        00 24 <- length (36)
        02 00 <- node descriptor type (member AS - 512)
        00 04 <- length
        00 00 00 64 <- value (100)
        02 01 <- node descriptor type (bgpId - 513)
        00 04 <- length
        19 19 19 01 <- bgpId (25.25.25.1)
        02 02 <- node descriptor type (areaId - 514)
        00 04 <- length
        00 00 00 00 <- value
        02 03 <- node descriptor type (routeId - 515)
        00 08 <- length
        03 03 03 04 0b 0b 0b 03 <- OSPF Router Id

        01 01 <- remote node descriptor type (257)
        00 20 <- length (32)
        02 00 <- node descriptor type (member AS - 512)
        00 04 <- length
        00 00 00 64 <- value (100)
        02 01 <- node descriptor type (bgpId - 513)
        00 04 <- length
        19 19 19 01 <- bgpId (25.25.25.1)
        02 02 <- node descriptor type (areaId - 514)
        00 04 <- length
        00 00 00 00 <- value
        02 03 <- node descriptor type (routeId - 515)
        00 04 <- length
        03 03 03 04 <- OSPF Router Id

        01 03 <- link descriptor type (IPv4 interface address - 259)
        00 04 <- length (4)
        0b 0b 0b 03 <- value (11.11.11.3)

        00 02 <- NLRI type (2 - linkNLRI)
        00 5d <- NLRI length (93)
        03 <- ProtocolID - OSPF
        00 00 00 00 00 00 00 01 <- identifier

        01 00 <- local node descriptor type (256)
        00 24 <- length (36)
        02 00 <- node descriptor type (member AS - 512)
        00 04 <- length
        00 00 00 64 <- value (100)
        02 01 <- node descriptor type (bgpId - 513)
        00 04 <- length
        19 19 19 01 <- bgpId (25.25.25.1)
        02 02 <- node descriptor type (areaId - 514)
        00 04 <- length
        00 00 00 00 <- value
        02 03 <- node descriptor type (routeId - 515)
        00 08 <- length
        03 03 03 04 0b 0b 0b 03 <- OSPF Router Id

        01 01 <- remote node descriptor type (257)
        00 20 <- length (32)
        02 00 <- node descriptor type (member AS - 512)
        00 04 <- length
        00 00 00 64 <- value (100)
        02 01 <- node descriptor type (bgpId - 513)
        00 04 <- length
        19 19 19 01 <- bgpId (25.25.25.1)
        02 02 <- node descriptor type (areaId - 514)
        00 04 <- length
        00 00 00 00 <- value
        02 03 <- node descriptor type (routeId - 515)
        00 04 <- length
        01 01 01 02 <- OSPF Router Id

        01 03 <- link descriptor type (IPv4 interface address - 259)
        00 04 <- length
        0b 0b 0b 01 <- value (11.11.11.1)

        00 02 <- NLRI type (2 - linkNLRI)
        00 5d <- NLRI length (93)
        03 <- ProtocolID - OSPF
        00 00 00 00 00 00 00 01 <- identifier

        01 00 <- local node descriptor type (256)
        00 20 <- length (32)
        02 00 <- node descriptor type (member AS - 512)
        00 04 <- length
        00 00 00 64 <- value (100)
        02 01 <- node descriptor type (bgpId - 513)
        00 04 <- length
        19 19 19 01 <- bgpId (25.25.25.1)
        02 02 <- node descriptor type (areaId - 514)
        00 04 <- length
        00 00 00 00 <- value
        02 03 <- node descriptor type (routeId - 515)
        00 04 <- length
        01 01 01 02 <- OSPF Router Id

        01 01 <- remote node descriptor type (257)
        00 24 <- length (36)
        02 00 <- node descriptor type (member AS - 512)
        00 04 <- length
        00 00 00 64 <- value (100)
        02 01 <- node descriptor type (bgpId - 513)
        00 04 <- length
        19 19 19 01 <- bgpId (25.25.25.1)
        02 02 <- node descriptor type (areaId - 514)
        00 04 <- length
        00 00 00 00 <- value
        02 03 <- node descriptor type (routeId - 515)
        00 08 <- length
        03 03 03 04 0b 0b 0b 03 <- OSPF Router Id

        01 03 <- link descriptor type (IPv4 interface address - 259)
        00 04 <- length
        0b 0b 0b 01 <- value (11.11.11.1)

        40 <- attribute flags
        01 <- attribute type (Origin)
        01 <- attribute length
        00 <- value (IGP)
        40 <- attribute flags
        02 <- attribute type (AS Path)
        00 <- length
        40 <- attribute flags
        05 <- attribute type (local pref)
        04 <- length
        00 00 00 64 <- value
        c0 <- attribute flags
        1D <- attribute type (Link STATE - 29)
        07 <- length
        04 47 <- link attribute (1095 - Metric)
        00 03 <- length
        00 00 01 <- value
     */
@Test
public void testBGPLink() throws Exception {
    final byte[] body = ByteArray.cutBytes(inputBytes.get(1), MessageUtil.COMMON_HEADER_LENGTH);
    final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(1), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
    final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
    final UpdateBuilder builder = new UpdateBuilder();
    // check fields
    assertNull(message.getWithdrawnRoutes());
    final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
    final LocalNodeDescriptorsBuilder ndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
    final RemoteNodeDescriptorsBuilder rdBuilder = new RemoteNodeDescriptorsBuilder().setAsNumber(new AsNumber((long) 100)).setDomainId(new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
    final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
    clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
    clBuilder.setProtocolId(ProtocolId.Ospf);
    final Attributes1Builder lsBuilder = new Attributes1Builder();
    final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
    mpBuilder.setAfi(LinkstateAddressFamily.class);
    mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
    mpBuilder.setCNextHop(nextHop);
    final List<CLinkstateDestination> linkstates = Lists.newArrayList();
    final LinkCaseBuilder lCase = new LinkCaseBuilder().setLocalNodeDescriptors(ndBuilder.setCRouterIdentifier(new OspfPseudonodeCaseBuilder().setOspfPseudonode(new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
    lCase.setRemoteNodeDescriptors(rdBuilder.setCRouterIdentifier(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
    lCase.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.3"))).build());
    linkstates.add(clBuilder.setObjectType(lCase.build()).build());
    lCase.setRemoteNodeDescriptors(rdBuilder.setCRouterIdentifier(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
    lCase.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(new Ipv4InterfaceIdentifier(new Ipv4Address("11.11.11.1"))).build());
    linkstates.add(clBuilder.setObjectType(lCase.build()).build());
    lCase.setLocalNodeDescriptors(ndBuilder.setCRouterIdentifier(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
    lCase.setRemoteNodeDescriptors(rdBuilder.setCRouterIdentifier(new OspfPseudonodeCaseBuilder().setOspfPseudonode(new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
    linkstates.add(clBuilder.setObjectType(lCase.build()).build());
    lsBuilder.setMpReachNlri(mpBuilder.build());
    // check path attributes
    final Attributes attrs = message.getAttributes();
    final AttributesBuilder paBuilder = new AttributesBuilder();
    paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
    assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
    paBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build());
    assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
    paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
    assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
    final MpReachNlri mp = attrs.getAugmentation(Attributes1.class).getMpReachNlri();
    assertEquals(mpBuilder.getAfi(), mp.getAfi());
    assertEquals(mpBuilder.getSafi(), mp.getSafi());
    assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
    final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
    dBuilder.setCLinkstateDestination(linkstates);
    mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
    lsBuilder.setMpReachNlri(mpBuilder.build());
    paBuilder.addAugmentation(Attributes1.class, lsBuilder.build());
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.Attributes1Builder lsAttrBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.Attributes1Builder();
    lsAttrBuilder.setLinkStateAttribute(new LinkAttributesCaseBuilder().setLinkAttributes(new LinkAttributesBuilder().setMetric(new Metric(1L)).build()).build());
    paBuilder.addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.Attributes1.class, lsAttrBuilder.build());
    paBuilder.setUnrecognizedAttributes(Collections.emptyList());
    assertEquals(lsAttrBuilder.build(), attrs.getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.Attributes1.class));
    final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
    assertEquals(linkstates.size(), dests.size());
    assertEquals(linkstates, dests);
    // check API message
    builder.setAttributes(paBuilder.build());
    assertEquals(builder.build(), message);
    final ByteBuf buffer = Unpooled.buffer();
    ParserTest.updateParser.serializeMessage(message, buffer);
    assertArrayEquals(inputBytes.get(1), ByteArray.readAllBytes(buffer));
}
Also used : LocalPrefBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.LocalPrefBuilder) MpReachNlriBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlriBuilder) CLinkstateDestinationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.destination.CLinkstateDestinationBuilder) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) DestinationLinkstateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder) Update(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update) DestinationLinkstateCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCaseBuilder) LocalNodeDescriptorsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.object.type.link._case.LocalNodeDescriptorsBuilder) OspfInterfaceIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.OspfInterfaceIdentifier) AreaIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.AreaIdentifier) Ipv4InterfaceIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.Ipv4InterfaceIdentifier) Identifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.Identifier) DomainIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.DomainIdentifier) RemoteNodeDescriptorsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.object.type.link._case.RemoteNodeDescriptorsBuilder) OspfPseudonodeCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.node.identifier.c.router.identifier.OspfPseudonodeCaseBuilder) OspfNodeCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.node.identifier.c.router.identifier.OspfNodeCaseBuilder) OspfPseudonodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonodeBuilder) Ipv4NextHopCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase) Ipv4InterfaceIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.Ipv4InterfaceIdentifier) Attributes1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1Builder) AdvertizedRoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder) LinkCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.object.type.LinkCaseBuilder) LinkAttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributesBuilder) AttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder) MpReachNlri(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri) Collections(java.util.Collections) OriginBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.OriginBuilder) UpdateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.UpdateBuilder) ByteBuf(io.netty.buffer.ByteBuf) AsPathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder) Ipv4NextHopCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder) OspfNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.node.identifier.c.router.identifier.ospf.node._case.OspfNodeBuilder) LinkAttributesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributesBuilder) CLinkstateDestination(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.destination.CLinkstateDestination) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) DomainIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.DomainIdentifier) Attributes1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) 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) LinkAttributesCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder) AreaIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.AreaIdentifier) LinkDescriptorsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.object.type.link._case.LinkDescriptorsBuilder) Metric(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric) OspfInterfaceIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.OspfInterfaceIdentifier) Test(org.junit.Test)

Aggregations

AsPathBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPathBuilder)24 AttributesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder)23 Test (org.junit.Test)16 OriginBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.OriginBuilder)16 SegmentsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.SegmentsBuilder)15 UpdateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.UpdateBuilder)14 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)12 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)10 LocalPrefBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.LocalPrefBuilder)10 Ipv4NextHopCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder)10 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)10 Segments (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.Segments)8 ByteBuf (io.netty.buffer.ByteBuf)7 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)7 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update)7 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes)7 MultiExitDiscBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.MultiExitDiscBuilder)7 Nlri (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.update.message.Nlri)7 NlriBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.update.message.NlriBuilder)7 ArrayList (java.util.ArrayList)6