Search in sources :

Example 6 with Metric

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric in project bgpcep by opendaylight.

the class MetricObjectParser method localSerializeObject.

@Override
public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) {
    Preconditions.checkArgument(teLspObject instanceof MetricObject, "BandwidthObject is mandatory.");
    final MetricObject metric = (MetricObject) teLspObject;
    serializeAttributeHeader(BODY_SIZE, CLASS_NUM, CTYPE, output);
    output.writeZero(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
    final BitArray reflect = new BitArray(FLAGS_SIZE);
    reflect.set(BOUND, metric.isBound());
    reflect.set(COMPUTED, metric.isComputed());
    reflect.toByteBuf(output);
    output.writeByte(metric.getMetricType());
    writeFloat32(metric.getValue(), output);
}
Also used : BitArray(org.opendaylight.protocol.util.BitArray) MetricObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.metric.object.MetricObject)

Example 7 with Metric

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric in project bgpcep by opendaylight.

the class Util method validateMonitoringMetrics.

public static MetricPce validateMonitoringMetrics(final List<Object> objects) throws PCEPDeserializerException {
    final MetricPceBuilder metricPceBuilder = new MetricPceBuilder();
    if (!(objects.get(0) instanceof PceId)) {
        throw new PCEPDeserializerException("metric-pce-list must start with PCE-ID object.");
    }
    metricPceBuilder.setPceId((PceId) (objects.get(0)));
    objects.remove(0);
    State state = State.START;
    while (!objects.isEmpty() && !state.equals(State.END)) {
        final Object obj = objects.get(0);
        state = insertObject(metricPceBuilder, state, obj);
        if (!state.equals(State.END)) {
            objects.remove(0);
        }
    }
    return metricPceBuilder.build();
}
Also used : PceId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId) Object(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object) MetricPceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.metrics.MetricPceBuilder) PCEPDeserializerException(org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)

Example 8 with Metric

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric in project bgpcep by opendaylight.

the class PCEPMetricObjectParser method serializeObject.

@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
    Preconditions.checkArgument(object instanceof Metric, "Wrong instance of PCEPObject. Passed %s. Needed MetricObject.", object.getClass());
    final Metric mObj = (Metric) object;
    final ByteBuf body = Unpooled.buffer(SIZE);
    body.writeZero(RESERVED);
    final BitArray flags = new BitArray(FLAGS_SIZE);
    flags.set(C_FLAG_OFFSET, mObj.isComputed());
    flags.set(B_FLAG_OFFSET, mObj.isBound());
    flags.toByteBuf(body);
    Preconditions.checkArgument(mObj.getMetricType() != null, "MetricType is mandatory.");
    writeUnsignedByte(mObj.getMetricType(), body);
    writeFloat32(mObj.getValue(), body);
    ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
Also used : Metric(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.Metric) BitArray(org.opendaylight.protocol.util.BitArray) ByteBuf(io.netty.buffer.ByteBuf)

Example 9 with Metric

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric 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)

Example 10 with Metric

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric in project bgpcep by opendaylight.

the class SrAttributeParserTest method testRangeTlv.

// tools.ietf.org/html/draft-gredler-idr-bgp-ls-segment-routing-ext-00#section-2.3.2
@Test
public void testRangeTlv() {
    final byte[] tested = { 0, 0, 0, 5, // sid
    4, // sid
    (byte) 0x89, // sid
    0, // sid
    4, // sid
    1, // sid
    2, // sid
    3, // sid
    4, // prefix + mpls label
    4, // prefix + mpls label
    (byte) 0x86, // prefix + mpls label
    0, // prefix + mpls label
    7, // prefix + mpls label
    (byte) 0xac, // prefix + mpls label
    1, // prefix + mpls label
    0, // prefix + mpls label
    0, // prefix + mpls label
    1, // prefix + mpls label
    2, // prefix + mpls label
    0, // binding sid
    4, // binding sid
    (byte) 0x88, // binding sid
    0, // binding sid
    0x58, // binding sid
    5, // binding sid
    0x48, // binding sid
    0, // binding sid
    0, // prefix
    4, // prefix
    (byte) 0x86, // prefix
    0, // prefix
    8, // prefix
    (byte) 0xa0, // prefix
    1, // prefix
    0, // prefix
    0, // prefix
    1, // prefix
    2, // prefix
    3, // prefix
    4, // sid
    4, // sid
    (byte) 0x89, // sid
    0, // sid
    4, // sid
    1, // sid
    2, // sid
    3, // sid
    4, // ero metric
    4, // ero metric
    (byte) 0x8a, // ero metric
    0, // ero metric
    4, // ero metric
    0, // ero metric
    0, // ero metric
    0, // ero metric
    6, // IPv4 ERO
    4, // IPv4 ERO
    (byte) 0x8b, // IPv4 ERO
    0, // IPv4 ERO
    8, // IPv4 ERO
    0, // IPv4 ERO
    0, // IPv4 ERO
    0, // IPv4 ERO
    0, // IPv4 ERO
    9, // IPv4 ERO
    8, // IPv4 ERO
    7, // IPv4 ERO
    6, // Unnumbered Interface ID ERO Sub-TLV
    4, // Unnumbered Interface ID ERO Sub-TLV
    (byte) 0x8d, // Unnumbered Interface ID ERO Sub-TLV
    0, // Unnumbered Interface ID ERO Sub-TLV
    0x0c, // Unnumbered Interface ID ERO Sub-TLV
    0, // Unnumbered Interface ID ERO Sub-TLV
    0, // Unnumbered Interface ID ERO Sub-TLV
    0, // Unnumbered Interface ID ERO Sub-TLV
    0, // Unnumbered Interface ID ERO Sub-TLV
    1, // Unnumbered Interface ID ERO Sub-TLV
    1, // Unnumbered Interface ID ERO Sub-TLV
    1, // Unnumbered Interface ID ERO Sub-TLV
    1, // Unnumbered Interface ID ERO Sub-TLV
    2, // Unnumbered Interface ID ERO Sub-TLV
    2, // Unnumbered Interface ID ERO Sub-TLV
    2, // Unnumbered Interface ID ERO Sub-TLV
    2, // IPv4 ERO backup
    4, // IPv4 ERO backup
    (byte) 0x8e, // IPv4 ERO backup
    0, // IPv4 ERO backup
    8, // IPv4 ERO backup
    0, // IPv4 ERO backup
    0, // IPv4 ERO backup
    0, // IPv4 ERO backup
    0, // IPv4 ERO backup
    3, // IPv4 ERO backup
    4, // IPv4 ERO backup
    5, // IPv4 ERO backup
    6, // Unnumbered Interface ID ERO Sub-TLV Backup
    4, // Unnumbered Interface ID ERO Sub-TLV Backup
    (byte) 0x90, // Unnumbered Interface ID ERO Sub-TLV Backup
    0, // Unnumbered Interface ID ERO Sub-TLV Backup
    0x0c, // Unnumbered Interface ID ERO Sub-TLV Backup
    0, // Unnumbered Interface ID ERO Sub-TLV Backup
    0, // Unnumbered Interface ID ERO Sub-TLV Backup
    0, // Unnumbered Interface ID ERO Sub-TLV Backup
    0, // Unnumbered Interface ID ERO Sub-TLV Backup
    3, // Unnumbered Interface ID ERO Sub-TLV Backup
    3, // Unnumbered Interface ID ERO Sub-TLV Backup
    3, // Unnumbered Interface ID ERO Sub-TLV Backup
    3, // Unnumbered Interface ID ERO Sub-TLV Backup
    4, // Unnumbered Interface ID ERO Sub-TLV Backup
    4, // Unnumbered Interface ID ERO Sub-TLV Backup
    4, // Unnumbered Interface ID ERO Sub-TLV Backup
    4 };
    final SrRange parsedRange = RangeTlvParser.parseSrRange(Unpooled.wrappedBuffer(tested), ProtocolId.IsisLevel1);
    final List<SubTlvs> rangeSubTlvs = new ArrayList<>();
    addSubTlvs(rangeSubTlvs);
    final SrRange expected = new SrRangeBuilder().setInterArea(Boolean.FALSE).setRangeSize(5).setSubTlvs(rangeSubTlvs).build();
    assertEquals(expected, parsedRange);
    final ByteBuf serializedRange = Unpooled.buffer();
    RangeTlvParser.serializeSrRange(parsedRange, serializedRange);
    assertArrayEquals(tested, ByteArray.getAllBytes(serializedRange));
}
Also used : SrRange(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrRange) SrRangeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrRangeBuilder) ArrayList(java.util.ArrayList) SubTlvs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.range.tlv.SubTlvs) BindingSubTlvs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.binding.sid.tlv.BindingSubTlvs) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)5 BitArray (org.opendaylight.protocol.util.BitArray)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Metric (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric)3 List (java.util.List)2 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)2 LinkAttributesCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder)2 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)2 SrRange (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.prefix.state.SrRange)2 Attributes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes)2 Preconditions (com.google.common.base.Preconditions)1 Collections (java.util.Collections)1 Counter (org.opendaylight.infrautils.metrics.Counter)1 BGPExtensionProviderContext (org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext)1 ServiceLoaderBGPExtensionProviderContext (org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext)1 ByteBufWriteUtil.writeFloat32 (org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32)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