import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
+import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupportUtil;
import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
+import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.protocol.util.Ipv6Util;
protected static void serializeNlri(final List<CLabeledUnicastDestination> dests, final ByteBuf buffer) {
final ByteBuf nlriByteBuf = Unpooled.buffer();
for (final CLabeledUnicastDestination dest: dests) {
+ PathIdUtil.writePathId(dest.getPathId(), buffer);
+
final List<LabelStack> labelStack = dest.getLabelStack();
final IpPrefix prefix = dest.getPrefix();
// Serialize the length field
}
@Override
- public void parseNlri(final ByteBuf nlri, final MpUnreachNlriBuilder builder)
- throws BGPParsingException {
- if (!nlri.isReadable()) {
- return;
- }
- final List<CLabeledUnicastDestination> dst = parseNlri(nlri, builder.getAfi());
-
- builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(
- dst).build()).build()).build());
+ public void parseNlri(final ByteBuf nlri, final MpUnreachNlriBuilder builder) throws BGPParsingException {
+ parseNlri(nlri, builder, null);
}
- private static List<CLabeledUnicastDestination> parseNlri(final ByteBuf nlri, final Class<? extends AddressFamily> afi) {
+ private static List<CLabeledUnicastDestination> parseNlri(final ByteBuf nlri, final Class<? extends AddressFamily> afi, final boolean mPathSupported) {
if (!nlri.isReadable()) {
return null;
}
while (nlri.isReadable()) {
final CLabeledUnicastDestinationBuilder builder = new CLabeledUnicastDestinationBuilder();
+ if (mPathSupported) {
+ builder.setPathId(PathIdUtil.readPathId(nlri));
+ }
final short length = nlri.readUnsignedByte();
builder.setLabelStack(parseLabel(nlri));
final int labelNum = builder.getLabelStack().size();
}
@Override
- public void parseNlri(final ByteBuf nlri, final MpReachNlriBuilder builder)
- throws BGPParsingException {
+ public void parseNlri(final ByteBuf nlri, final MpReachNlriBuilder builder) throws BGPParsingException {
+ parseNlri(nlri, builder, null);
+ }
+
+ @Override
+ public void parseNlri(@Nonnull final ByteBuf nlri, @Nonnull final MpReachNlriBuilder builder, @Nullable final PeerSpecificParserConstraint constraint) throws BGPParsingException {
if (!nlri.isReadable()) {
return;
}
- final List<CLabeledUnicastDestination> dst = parseNlri(nlri, builder.getAfi());
+ final boolean mPathSupported = MultiPathSupportUtil.isTableTypeSupported(constraint, new BgpTableTypeImpl(builder.getAfi(), builder.getSafi()));
+ final List<CLabeledUnicastDestination> dst = parseNlri(nlri, builder.getAfi(), mPathSupported);
builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
new DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
new DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(
dst).build()).build()).build());
}
+
+ @Override
+ public void parseNlri(@Nonnull final ByteBuf nlri, @Nonnull final MpUnreachNlriBuilder builder, @Nullable final PeerSpecificParserConstraint constraint) throws BGPParsingException {
+ if (!nlri.isReadable()) {
+ return;
+ }
+ final boolean mPathSupported = MultiPathSupportUtil.isTableTypeSupported(constraint, new BgpTableTypeImpl(builder.getAfi(), builder.getSafi()));
+ final List<CLabeledUnicastDestination> dst = parseNlri(nlri, builder.getAfi(), mPathSupported);
+
+ builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(
+ dst).build()).build()).build());
+ }
}
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import javax.annotation.Nonnull;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
+import org.opendaylight.protocol.bgp.parser.spi.PathIdUtil;
import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupport;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
public final class LabeledUnicastRIBSupport extends AbstractRIBSupport {
+ private static final QName PATHID_QNAME = QName.create(LabeledUnicastRoute.QNAME, "path-id").intern();
private static final Logger LOG = LoggerFactory.getLogger(LabeledUnicastRIBSupport.class);
-
private static final NodeIdentifier PREFIX_TYPE_NID = NodeIdentifier.create(QName.create(CLabeledUnicastDestination.QNAME, "prefix").intern());
+ private static final NodeIdentifier PATH_ID_LEAF = new NodeIdentifier(PATHID_QNAME);
private static final NodeIdentifier LABEL_STACK_NID = NodeIdentifier.create(QName.create(CLabeledUnicastDestination.QNAME, "label-stack").intern());
private static final NodeIdentifier LV_NID = NodeIdentifier.create(QName.create(CLabeledUnicastDestination.QNAME, "label-value").intern());
@Override
protected void deleteDestinationRoutes(final DOMDataWriteTransaction tx,
- final YangInstanceIdentifier tablePath, final ContainerNode destination,final NodeIdentifier routesNodeId) {
+ final YangInstanceIdentifier tablePath, final ContainerNode destination, final NodeIdentifier routesNodeId) {
processDestination(tx, tablePath.node(routesNodeId), destination, null, DELETE_ROUTE);
}
@Override
protected void putDestinationRoutes(final DOMDataWriteTransaction tx,
final YangInstanceIdentifier tablePath, final ContainerNode destination,
- final ContainerNode attributes,final NodeIdentifier routesNodeId) {
+ final ContainerNode attributes, final NodeIdentifier routesNodeId) {
processDestination(tx, tablePath.node(routesNodeId), destination, attributes, this.putRoute);
}
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, PATH_ID_LEAF));
return builder.build();
}
final List<LabelStack> labels = new ArrayList<>();
final Optional<DataContainerChild<? extends PathArgument, ?>> labelStacks = route.getChild(labelStackNid);
if (labelStacks.isPresent()) {
- for(final UnkeyedListEntryNode label : ((UnkeyedListNode)labelStacks.get()).getValue()) {
+ for (final UnkeyedListEntryNode label : ((UnkeyedListNode) labelStacks.get()).getValue()) {
final Optional<DataContainerChild<? extends PathArgument, ?>> labelStack = label.getChild(labelValueNid);
if (labelStack.isPresent()) {
final LabelStackBuilder labelStackbuilder = new LabelStackBuilder();
}
return labels;
}
+
+ @Nonnull
+ @Override
+ public PathArgument getRouteIdAddPath(final long pathId, final PathArgument routeId) {
+ return PathIdUtil.createNiiKey(pathId, routeId, LabeledUnicastRoute.QNAME, PATHID_QNAME, ROUTE_KEY);
+ }
+
+ @Override
+ public Long extractPathId(final NormalizedNode<?, ?> data) {
+ return PathIdUtil.extractPathId(data, PATH_ID_LEAF);
+ }
}
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.List;
+import java.util.Optional;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
+import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.destination.CLabeledUnicastDestinationBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLabeledUnicastCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1Builder;
(byte) 0x22, (byte) 0x01, (byte) 0x16,
};
+ /*label stacks with multiple labels.
+ *
+ * label stack:
+ * 1 <- Path Id
+ * 60 <- length 96
+ * 00 16 3 <- labelValue 355
+ * 0 <- etc&bottomBit 0
+ * 00 16 4 <- labelValue 356
+ * 0 <- etc&bottomBit 0
+ * 00 16 6 <- labelValue 357
+ * 1 <- bottomBit 1
+ * 22 01 16 <- prefixType IPV4=34.1.22.0/24
+ */
+ private static final byte[] LU_NLRI_IPv4_ADD_PATH = new byte[] {
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
+ (byte) 0x60,
+ (byte) 0x00, (byte) 0x16, (byte) 0x30,
+ (byte) 0x00, (byte) 0x16, (byte) 0x40,
+ (byte) 0x00, (byte) 0x16, (byte) 0x51,
+ (byte) 0x22, (byte) 0x01, (byte) 0x16,
+ };
+
/*label stacks with multiple labels.
*
* label stack:
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
};
+ /*label stacks with multiple labels.
+ *
+ * label stack:
+ * C8 <- length 200
+ * 00 16 3 <- labelValue 355
+ * 0 <- etc&bottomBit 0
+ * 00 16 4 <- labelValue 356
+ * 0 <- etc&bottomBit 0
+ * 00 16 6 <- labelValue 357
+ * 1 <- bottomBit 1
+ * 20 01 D B8 0 1 0 2 0 0 0 0 0 0 0 0 80 <- prefixType IPV6=2001:db8:1:2::/128
+ */
+ private static final byte[] LU_NLRI_IPv6_ADD_PATH = new byte[] {
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
+ (byte) 0xC8,
+ (byte) 0x00, (byte) 0x16, (byte) 0x30,
+ (byte) 0x00, (byte) 0x16, (byte) 0x40,
+ (byte) 0x00, (byte) 0x16, (byte) 0x51,
+ (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8,
+ (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ };
private static final List<LabelStack> LABEL_STACK = Lists.newArrayList(
new LabelStackBuilder().setLabelValue(new MplsLabel(355L)).build(),
new LabelStackBuilder().setLabelValue(new MplsLabel(356L)).build(),
private static final IpPrefix IPv4_PREFIX = new IpPrefix(new Ipv4Prefix("34.1.22.0/24"));
private static final IpPrefix IPv6_PREFIX = new IpPrefix(new Ipv6Prefix("2001:db8:1:2::/128"));
+ private static final PathId PATH_ID = new PathId(1L);
+
+ @Mock
+ private PeerSpecificParserConstraint constraint;
+ @Mock
+ private MultiPathSupport muliPathSupport;
+
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ Mockito.doReturn(Optional.of(this.muliPathSupport)).when(constraint).getPeerConstraint(Mockito.any());
+ Mockito.doReturn(true).when(this.muliPathSupport).isTableTypeSupported(Mockito.any());
+ }
@Test
public void testMpReachNlriIpv4() throws BGPParsingException {
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());
+ 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_NLRI_IPv4), testBuilder);
- Assert.assertEquals(mpBuilder.build(), mpReachExpected);
+ Assert.assertEquals(mpReachExpected, testBuilder.build());
//test serializer
final ByteBuf output = Unpooled.buffer();
Assert.assertArrayEquals(LU_NLRI_IPv4, ByteArray.readAllBytes(output));
}
+ @Test
+ public void testMpReachNlriIpv4Constraint() 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().setPathId(PATH_ID).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_NLRI_IPv4_ADD_PATH), testBuilder, this.constraint);
+ Assert.assertEquals(mpReachExpected, testBuilder.build());
+
+ //test serializer
+ final ByteBuf output = Unpooled.buffer();
+ parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class,
+ new Attributes1Builder().setMpReachNlri(mpReachExpected).build()).build(), output);
+ Assert.assertArrayEquals(LU_NLRI_IPv4_ADD_PATH, ByteArray.readAllBytes(output));
+ }
+
@Test
public void testMpUnreachNlriIpv4() throws BGPParsingException {
final LUNlriParser parser = new LUNlriParser();
mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build())
- .build())
- .build());
+ .build()).build());
final MpUnreachNlri mpUnreachExpected = mpBuilder.build();
//test parser
final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
testBuilder.setAfi(Ipv4AddressFamily.class);
+ testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv4), testBuilder);
- Assert.assertEquals(mpBuilder.build(), mpUnreachExpected);
+ Assert.assertEquals(mpUnreachExpected, testBuilder.build());
//test serializer
final ByteBuf output = Unpooled.buffer();
Assert.assertArrayEquals(LU_NLRI_IPv4, ByteArray.readAllBytes(output));
}
+ @Test
+ public void testMpUnreachNlriIpv4Constraint() throws BGPParsingException {
+ final LUNlriParser parser = new LUNlriParser();
+ final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
+ mpBuilder.setAfi(Ipv4AddressFamily.class);
+ mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
+ final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPv4_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.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build())
+ .build()).build());
+ final MpUnreachNlri mpUnreachExpected = mpBuilder.build();
+
+ //test parser
+ final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
+ testBuilder.setAfi(Ipv4AddressFamily.class);
+ testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
+ parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv4_ADD_PATH), testBuilder, this.constraint);
+ Assert.assertEquals(mpUnreachExpected, testBuilder.build());
+
+ //test serializer
+ final ByteBuf output = Unpooled.buffer();
+ parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
+ new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected).build()).build(), output);
+ Assert.assertArrayEquals(LU_NLRI_IPv4_ADD_PATH, ByteArray.readAllBytes(output));
+ }
+
@Test
public void testMpReachNlriIpv6() throws BGPParsingException {
final LUNlriParser parser = new LUNlriParser();
mpBuilder.setAfi(Ipv6AddressFamily.class);
mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPrefix(IPv6_PREFIX).setLabelStack(LABEL_STACK).build();
- mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
- new DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build())
- .build())
- .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(Ipv6AddressFamily.class);
+ testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv6), testBuilder);
- Assert.assertEquals(mpBuilder.build(), mpReachExpected);
+ Assert.assertEquals(mpReachExpected, testBuilder.build());
//test serializer
final ByteBuf output = Unpooled.buffer();
Assert.assertArrayEquals(LU_NLRI_IPv6, ByteArray.readAllBytes(output));
}
+ @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 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(Ipv6AddressFamily.class);
+ testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
+ parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv6_ADD_PATH), testBuilder, this.constraint);
+ Assert.assertEquals(mpReachExpected, testBuilder.build());
+
+ //test serializer
+ final ByteBuf output = Unpooled.buffer();
+ parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class,
+ new Attributes1Builder().setMpReachNlri(mpReachExpected).build()).build(), output);
+ Assert.assertArrayEquals(LU_NLRI_IPv6_ADD_PATH, ByteArray.readAllBytes(output));
+ }
+
@Test
public void testMpUnreachNlriIpv6() throws BGPParsingException {
final LUNlriParser parser = new LUNlriParser();
//test parser
final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
testBuilder.setAfi(Ipv6AddressFamily.class);
+ testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv6), testBuilder);
- Assert.assertEquals(mpBuilder.build(), mpUnreachExpected);
+ Assert.assertEquals(mpUnreachExpected, testBuilder.build());
//test serializer
final ByteBuf output = Unpooled.buffer();
new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected).build()).build(), output);
Assert.assertArrayEquals(LU_NLRI_IPv6, ByteArray.readAllBytes(output));
}
+
+ @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 lu = 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.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build())
+ .build())
+ .build());
+ final MpUnreachNlri mpUnreachExpected = mpBuilder.build();
+
+ //test parser
+ final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
+ testBuilder.setAfi(Ipv6AddressFamily.class);
+ testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
+ parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv6_ADD_PATH), testBuilder, this.constraint);
+ Assert.assertEquals(mpUnreachExpected, testBuilder.build());
+
+ //test serializer
+ final ByteBuf output = Unpooled.buffer();
+ parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
+ new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected).build()).build(), output);
+ Assert.assertArrayEquals(LU_NLRI_IPv6_ADD_PATH, ByteArray.readAllBytes(output));
+ }
}