use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.destination.CLabeledUnicastDestinationBuilder in project bgpcep by opendaylight.
the class AbstractLabeledUnicastRIBSupport method extractCLabeledUnicastDestination.
/**
* Conversion from DataContainer to LabeledUnicastDestination Object
*
* @param route DataContainer
* @return LabeledUnicastDestination Object
*/
private CLabeledUnicastDestination extractCLabeledUnicastDestination(final DataContainerNode<? extends PathArgument> route) {
final CLabeledUnicastDestinationBuilder builder = new CLabeledUnicastDestinationBuilder();
builder.setPrefix(extractPrefix(route, PREFIX_TYPE_NID));
builder.setLabelStack(extractLabel(route, LABEL_STACK_NID, LV_NID));
builder.setPathId(PathIdUtil.buildPathId(route, routePathIdNid()));
return builder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.destination.CLabeledUnicastDestinationBuilder in project bgpcep by opendaylight.
the class LUNlriParser method parseNlri.
private static List<CLabeledUnicastDestination> parseNlri(final ByteBuf nlri, final Class<? extends AddressFamily> afi, final boolean multiPathSupported) {
if (!nlri.isReadable()) {
return null;
}
final List<CLabeledUnicastDestination> dests = new ArrayList<>();
while (nlri.isReadable()) {
final CLabeledUnicastDestinationBuilder builder = new CLabeledUnicastDestinationBuilder();
if (multiPathSupported) {
builder.setPathId(PathIdUtil.readPathId(nlri));
}
final short length = nlri.readUnsignedByte();
final List<LabelStack> labels = parseLabel(nlri);
builder.setLabelStack(labels);
final int labelNum = labels != null ? labels.size() : 1;
final int prefixLen = length - LABEL_LENGTH * Byte.SIZE * labelNum;
builder.setPrefix(parseIpPrefix(nlri, prefixLen, afi));
dests.add(builder.build());
}
return dests;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.destination.CLabeledUnicastDestinationBuilder in project bgpcep by opendaylight.
the class LUNlriParserTest method testMpUnreachNlriIpv6Constraint.
@Test
public void testMpUnreachNlriIpv6Constraint() throws BGPParsingException {
final LUNlriParser parser = new LUNlriParser();
final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
mpBuilder.setAfi(Ipv6AddressFamily.class);
mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPV6_PREFIX).build();
mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu1)).build()).build()).build());
final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
final CLabeledUnicastDestination lu2 = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPV6_PREFIX).setLabelStack(LABEL_STACK).build();
mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu2)).build()).build()).build());
final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
// test parser
final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
testBuilder.setAfi(Ipv6AddressFamily.class);
testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPV6_ADD_PATH), testBuilder, this.constraint);
assertEquals(mpUnreachExpected1, testBuilder.build());
// test serializer
final ByteBuf output = Unpooled.buffer();
parser.serializeAttribute(new AttributesBuilder().addAugmentation(new AttributesUnreachBuilder().setMpUnreachNlri(mpUnreachExpected2).build()).build(), output);
assertArrayEquals(LU_UNREACH_NLRI_IPV6_ADD_PATH, ByteArray.readAllBytes(output));
final ByteBuf output1 = Unpooled.buffer();
parser.serializeAttribute(new AttributesBuilder().addAugmentation(new AttributesUnreachBuilder().setMpUnreachNlri(mpUnreachExpected1).build()).build(), output1);
assertArrayEquals(LU_UNREACH_NLRI_IPV6_ADD_PATH, ByteArray.readAllBytes(output1));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.destination.CLabeledUnicastDestinationBuilder in project bgpcep by opendaylight.
the class LUNlriParserTest method testMpReachNlriIpv4.
@Test
public void testMpReachNlriIpv4() throws BGPParsingException {
final LUNlriParser parser = new LUNlriParser();
final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
mpBuilder.setAfi(Ipv4AddressFamily.class);
mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPrefix(IPV4_PREFIX).setLabelStack(LABEL_STACK).build();
mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(new DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build()).build()).build());
final MpReachNlri mpReachExpected = mpBuilder.build();
// test parser
final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
testBuilder.setAfi(Ipv4AddressFamily.class);
testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPV4), testBuilder, null);
assertEquals(mpReachExpected, testBuilder.build());
// test serializer
final ByteBuf output = Unpooled.buffer();
parser.serializeAttribute(new AttributesBuilder().addAugmentation(new AttributesReachBuilder().setMpReachNlri(mpReachExpected).build()).build(), output);
assertArrayEquals(LU_REACH_NLRI_IPV4, ByteArray.readAllBytes(output));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.destination.CLabeledUnicastDestinationBuilder in project bgpcep by opendaylight.
the class LUNlriParserTest method testMpReachNlriIpv6Constraint.
@Test
public void testMpReachNlriIpv6Constraint() throws BGPParsingException {
final LUNlriParser parser = new LUNlriParser();
final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
mpBuilder.setAfi(Ipv6AddressFamily.class);
mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPV6_PREFIX).setLabelStack(LABEL_STACK).build();
mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(new DestinationIpv6LabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build()).build()).build());
final MpReachNlri mpReachExpected = mpBuilder.build();
// test parser
final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
testBuilder.setAfi(Ipv6AddressFamily.class);
testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPV6_ADD_PATH), testBuilder, this.constraint);
assertEquals(mpReachExpected, testBuilder.build());
// test serializer
final ByteBuf output = Unpooled.buffer();
parser.serializeAttribute(new AttributesBuilder().addAugmentation(new AttributesReachBuilder().setMpReachNlri(mpReachExpected).build()).build(), output);
assertArrayEquals(LU_REACH_NLRI_IPV6_ADD_PATH, ByteArray.readAllBytes(output));
}
Aggregations