private static final VpnIpv4NlriParser PARSER = new VpnIpv4NlriParser();
- private static final byte[] NLRI_TYPE1 = new byte[]{
+ /* Reach NLRI prefix value.
+ *
+ * prefix contents:
+ * 70 <- length 112
+ * 00 16 3 <- labelValue 355
+ * 1 <- bottomBit 1
+ * 00 01 <- routeDistinguisher Type=1
+ * 01 02 03 04 <- routeDistinguisher IPV4=1.2.3.4
+ * 01 02 <- routeDistinguisher AS=258
+ * 22 01 16 <- prefixType IPV4=34.1.22.0/24
+ */
+ private static final byte[] REACH_NLRI = new byte[] {
(byte) 0x70,
(byte) 0x00, (byte) 0x16, (byte) 0x31,
0, 1, 1, 2, 3, 4, 1, 2,
(byte) 0x22, (byte) 0x01, (byte) 0x16,
};
+
+ /* Unreach NLRI prefix value.
+ *
+ * prefix contents:
+ * 70 <- length 112
+ * 80 00 00 <- labelValue for withdraw
+ * 00 01 <- routeDistinguisher Type=1
+ * 01 02 03 04 <- routeDistinguisher IPV4=1.2.3.4
+ * 01 02 <- routeDistinguisher AS=258
+ * 22 01 16 <- prefixType IPV4=34.1.22.0/24
+ */
+ private static final byte[] UNREACH_NLRI = new byte[] {
+ (byte) 0x70,
+ (byte) 0x80, (byte) 0x00, (byte) 0x00,
+ 0, 1, 1, 2, 3, 4, 1, 2,
+ (byte) 0x22, (byte) 0x01, (byte) 0x16,
+ };
+
static final IpPrefix IPv4_PREFIX = new IpPrefix(new Ipv4Prefix("34.1.22.0/24"));
static final List<LabelStack> LABEL_STACK = Lists.newArrayList(
new LabelStackBuilder().setLabelValue(new MplsLabel(355L)).build());
static final RouteDistinguisher DISTINGUISHER = RouteDistinguisherBuilder.getDefaultInstance("1.2.3.4:258");
static final VpnDestination IPV4_VPN = new VpnDestinationBuilder().setRouteDistinguisher(DISTINGUISHER).setPrefix(IPv4_PREFIX).setLabelStack(LABEL_STACK).build();
+ private static final VpnDestination IPV4_VPN_WITHOUT_LABELS = new VpnDestinationBuilder().setRouteDistinguisher(DISTINGUISHER).setPrefix(IPv4_PREFIX).build();
@Test
public void testMpReachNlri() throws BGPParsingException {
final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
testBuilder.setAfi(Ipv4AddressFamily.class);
- PARSER.parseNlri(Unpooled.copiedBuffer(NLRI_TYPE1), testBuilder);
+ PARSER.parseNlri(Unpooled.copiedBuffer(REACH_NLRI), testBuilder);
Assert.assertEquals(mpReachExpected, testBuilder.build());
final ByteBuf output = Unpooled.buffer();
new Attributes1Builder().setMpReachNlri(mpReachExpected).build()
).build(), output
);
- Assert.assertArrayEquals(NLRI_TYPE1, ByteArray.readAllBytes(output));
+ Assert.assertArrayEquals(REACH_NLRI, ByteArray.readAllBytes(output));
}
@Test
public void testMpUnreachNlri() throws BGPParsingException {
final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
mpBuilder.setAfi(Ipv4AddressFamily.class);
+
mpBuilder.setWithdrawnRoutes(
new WithdrawnRoutesBuilder().setDestinationType(
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev160210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationVpnIpv4CaseBuilder().setVpnIpv4Destination(
- new VpnIpv4DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV4_VPN)).build()
+ new VpnIpv4DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV4_VPN_WITHOUT_LABELS)).build()
).build()
).build()
).build();
+ final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
- final MpUnreachNlri mpUnreachExpected = mpBuilder.build();
+ mpBuilder.setWithdrawnRoutes(
+ new WithdrawnRoutesBuilder().setDestinationType(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv4.rev160210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationVpnIpv4CaseBuilder().setVpnIpv4Destination(
+ new VpnIpv4DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV4_VPN)).build()
+ ).build()
+ ).build()
+ ).build();
+ final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
testBuilder.setAfi(Ipv4AddressFamily.class);
- PARSER.parseNlri(Unpooled.copiedBuffer(NLRI_TYPE1), testBuilder);
- Assert.assertEquals(mpUnreachExpected, testBuilder.build());
+ PARSER.parseNlri(Unpooled.copiedBuffer(UNREACH_NLRI), testBuilder);
+ Assert.assertEquals(mpUnreachExpected1, testBuilder.build());
final ByteBuf output = Unpooled.buffer();
PARSER.serializeAttribute(
new AttributesBuilder().addAugmentation(Attributes2.class,
- new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected).build()
+ new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()
).build(), output
);
- Assert.assertArrayEquals(NLRI_TYPE1, ByteArray.readAllBytes(output));
+ Assert.assertArrayEquals(UNREACH_NLRI, ByteArray.readAllBytes(output));
}
}
private static final VpnIpv6NlriParser PARSER = new VpnIpv6NlriParser();
- private static final byte[] NLRI_TYPE1 = new byte[]{
- (byte) 0x88, // length
- (byte) 0x00, (byte) 0x16, (byte) 0x31, // label
- 0, 1, 1, 2, 3, 4, 1, 2, // route distinguisher
- (byte) 0x20, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x56, (byte) 0x89 // specify the IPv6 prefix here
+ /* Reach NLRI prefix value.
+ *
+ * prefix contents:
+ * 88 <- length 136
+ * 00 16 3 <- labelValue 355
+ * 01 <- bottomBit 1
+ * 00 01 <- routeDistinguisher Type=1
+ * 01 02 03 04 <- routeDistinguisher IPV4=1.2.3.4
+ * 01 02 <- routeDistinguisher AS=258
+ * 20 01 23 45 56 89 <- prefixType IPV6=2001:2345:5689::/48
+ */
+ private static final byte[] REACH_NLRI = new byte[] {
+ (byte) 0x88,
+ (byte) 0x00, (byte) 0x16, (byte) 0x31,
+ 0, 1, 1, 2, 3, 4, 1, 2,
+ (byte) 0x20, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x56, (byte) 0x89
};
+
+ /* Unreach NLRI prefix value.
+ *
+ * prefix contents:
+ * 88 <- length 136
+ * 80 00 00 <- labelValue for withdraw
+ * 00 01 <- routeDistinguisher Type=1
+ * 01 02 03 04 <- routeDistinguisher IPV4=1.2.3.4
+ * 01 02 <- routeDistinguisher AS=258
+ * 20 01 23 45 56 89 <- prefixType IPV6=2001:2345:5689::/48
+ */
+ private static final byte[] UNREACH_NLRI = new byte[] {
+ (byte) 0x88,
+ (byte) 0x80, (byte) 0x00, (byte) 0x00,
+ 0, 1, 1, 2, 3, 4, 1, 2,
+ (byte) 0x20, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x56, (byte) 0x89
+ };
+
static final IpPrefix IPv6_PREFIX = new IpPrefix(new Ipv6Prefix("2001:2345:5689::/48"));
static final List<LabelStack> LABEL_STACK = Lists.newArrayList(
new LabelStackBuilder().setLabelValue(new MplsLabel(355L)).build());
static final RouteDistinguisher DISTINGUISHER = RouteDistinguisherBuilder.getDefaultInstance("1.2.3.4:258");
static final VpnDestination IPV6_VPN = new VpnDestinationBuilder().setRouteDistinguisher(DISTINGUISHER).setPrefix(IPv6_PREFIX).setLabelStack(LABEL_STACK).build();
+ private static final VpnDestination IPV6_VPN_WITHOUT_LABELS = new VpnDestinationBuilder().setRouteDistinguisher(DISTINGUISHER).setPrefix(IPv6_PREFIX).build();
@Test
public void testMpReachNlri() throws BGPParsingException {
final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
testBuilder.setAfi(Ipv6AddressFamily.class);
- PARSER.parseNlri(Unpooled.copiedBuffer(NLRI_TYPE1), testBuilder);
+ PARSER.parseNlri(Unpooled.copiedBuffer(REACH_NLRI), testBuilder);
Assert.assertEquals(mpReachExpected, testBuilder.build());
final ByteBuf output = Unpooled.buffer();
new Attributes1Builder().setMpReachNlri(mpReachExpected).build()
).build(), output
);
- Assert.assertArrayEquals(NLRI_TYPE1, ByteArray.readAllBytes(output));
+ Assert.assertArrayEquals(REACH_NLRI, ByteArray.readAllBytes(output));
}
@Test
public void testMpUnreachNlri() throws BGPParsingException {
final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
mpBuilder.setAfi(Ipv6AddressFamily.class);
+
mpBuilder.setWithdrawnRoutes(
new WithdrawnRoutesBuilder().setDestinationType(
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev160331.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationVpnIpv6CaseBuilder().setVpnIpv6Destination(
- new VpnIpv6DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV6_VPN)).build()
+ new VpnIpv6DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV6_VPN_WITHOUT_LABELS)).build()
).build()
).build()
).build();
+ final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
- final MpUnreachNlri mpUnreachExpected = mpBuilder.build();
+ mpBuilder.setWithdrawnRoutes(
+ new WithdrawnRoutesBuilder().setDestinationType(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.vpn.ipv6.rev160331.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationVpnIpv6CaseBuilder().setVpnIpv6Destination(
+ new VpnIpv6DestinationBuilder().setVpnDestination(Lists.newArrayList(IPV6_VPN)).build()
+ ).build()
+ ).build()
+ ).build();
+ final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
testBuilder.setAfi(Ipv6AddressFamily.class);
- PARSER.parseNlri(Unpooled.copiedBuffer(NLRI_TYPE1), testBuilder);
- Assert.assertEquals(mpUnreachExpected, testBuilder.build());
+ PARSER.parseNlri(Unpooled.copiedBuffer(UNREACH_NLRI), testBuilder);
+ Assert.assertEquals(mpUnreachExpected1, testBuilder.build());
final ByteBuf output = Unpooled.buffer();
PARSER.serializeAttribute(
new AttributesBuilder().addAugmentation(Attributes2.class,
- new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected).build()
+ new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()
).build(), output
);
- Assert.assertArrayEquals(NLRI_TYPE1, ByteArray.readAllBytes(output));
+ Assert.assertArrayEquals(UNREACH_NLRI, ByteArray.readAllBytes(output));
}
}
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
+import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel;
import org.opendaylight.yangtools.yang.binding.DataObject;
public class LUNlriParser implements NlriParser, NlriSerializer {
public static final int LABEL_LENGTH = 3;
+ private static final byte[] WITHDRAW_LABEL_BYTE_ARRAY = { (byte) 0x80, (byte) 0x00, (byte) 0x00 };
+ private static final int WITHDRAW_LABEL_INT_VALUE = 0x800000;
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
if ( destinationType instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLabeledUnicastCase){
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLabeledUnicastCase labeledUnicastCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLabeledUnicastCase) routes.getDestinationType();
- serializeNlri(labeledUnicastCase.getDestinationLabeledUnicast().getCLabeledUnicastDestination(), byteAggregator);
+ serializeNlri(labeledUnicastCase.getDestinationLabeledUnicast().getCLabeledUnicastDestination(), false, byteAggregator);
} else if (destinationType instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6LabeledUnicastCase) {
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6LabeledUnicastCase labeledUnicastCase = ( org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6LabeledUnicastCase) routes.getDestinationType();
- serializeNlri(labeledUnicastCase.getDestinationIpv6LabeledUnicast().getCLabeledUnicastDestination(), byteAggregator);
+ serializeNlri(labeledUnicastCase.getDestinationIpv6LabeledUnicast().getCLabeledUnicastDestination(), false, byteAggregator);
}
}
} else if (pathAttributes2 != null) {
final DestinationType destinationType = mpUnreachNlri.getWithdrawnRoutes().getDestinationType();
if (destinationType instanceof DestinationLabeledUnicastCase) {
final DestinationLabeledUnicastCase labeledUnicastCase = (DestinationLabeledUnicastCase) mpUnreachNlri.getWithdrawnRoutes().getDestinationType();
- serializeNlri(labeledUnicastCase.getDestinationLabeledUnicast().getCLabeledUnicastDestination(), byteAggregator);
+ serializeNlri(labeledUnicastCase.getDestinationLabeledUnicast().getCLabeledUnicastDestination(), true, byteAggregator);
} else if(destinationType instanceof DestinationIpv6LabeledUnicastCase) {
final DestinationIpv6LabeledUnicastCase labeledUnicastCase = (DestinationIpv6LabeledUnicastCase) mpUnreachNlri.getWithdrawnRoutes().getDestinationType();
- serializeNlri(labeledUnicastCase.getDestinationIpv6LabeledUnicast().getCLabeledUnicastDestination(), byteAggregator);
+ serializeNlri(labeledUnicastCase.getDestinationIpv6LabeledUnicast().getCLabeledUnicastDestination(), true, byteAggregator);
}
}
}
}
- protected static void serializeNlri(final List<CLabeledUnicastDestination> dests, final ByteBuf buffer) {
+ protected static void serializeNlri(final List<CLabeledUnicastDestination> dests, final boolean isUnreachNlri,
+ final ByteBuf buffer) {
final ByteBuf nlriByteBuf = Unpooled.buffer();
- for (final CLabeledUnicastDestination dest: dests) {
+ 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
// Length field contains one Byte which represents the length of label stack and prefix in bits
- nlriByteBuf.writeByte(((LABEL_LENGTH * labelStack.size()) + getPrefixLength(prefix)) * Byte.SIZE);
+ nlriByteBuf.writeByte(((LABEL_LENGTH * (!isUnreachNlri ? labelStack.size() : 1)) + getPrefixLength(prefix)) * Byte.SIZE);
- serializeLabelStackEntries(labelStack, nlriByteBuf);
+ serializeLabelStackEntries(labelStack, isUnreachNlri, nlriByteBuf);
serializePrefixField(prefix, nlriByteBuf);
}
buffer.writeBytes(nlriByteBuf);
}
- public static void serializeLabelStackEntries(final List<LabelStack> stack, final ByteBuf buffer) {
- int i = 1;
- for (final LabelStack labelStackEntry : stack) {
- if (i++ == stack.size()) {
- //mark last label stack entry with bottom-bit
- buffer.writeBytes(MplsLabelUtil.byteBufForMplsLabelWithBottomBit(labelStackEntry.getLabelValue()));
- } else {
- buffer.writeBytes(MplsLabelUtil.byteBufForMplsLabel(labelStackEntry.getLabelValue()));
+ public static void serializeLabelStackEntries(final List<LabelStack> stack, final boolean isUnreachNlri,
+ final ByteBuf buffer) {
+ if (!isUnreachNlri) {
+ int i = 1;
+ for (final LabelStack labelStackEntry : stack) {
+ if (i++ == stack.size()) {
+ // mark last label stack entry with bottom-bit
+ buffer.writeBytes(MplsLabelUtil.byteBufForMplsLabelWithBottomBit(labelStackEntry.getLabelValue()));
+ } else {
+ buffer.writeBytes(MplsLabelUtil.byteBufForMplsLabel(labelStackEntry.getLabelValue()));
+ }
}
+ } else {
+ buffer.writeBytes(WITHDRAW_LABEL_BYTE_ARRAY);
}
}
builder.setPathId(PathIdUtil.readPathId(nlri));
}
final short length = nlri.readUnsignedByte();
- builder.setLabelStack(parseLabel(nlri));
- final int labelNum = builder.getLabelStack().size();
+ 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());
do {
final ByteBuf slice = nlri.readSlice(LABEL_LENGTH);
bottomBit = MplsLabelUtil.getBottomBit(slice);
- labels.add(new LabelStackBuilder().setLabelValue(MplsLabelUtil.mplsLabelForByteBuf(slice)).build());
+ final MplsLabel mplsLabel = MplsLabelUtil.mplsLabelForByteBuf(slice);
+ if (MplsLabelUtil.intForMplsLabel(mplsLabel) == WITHDRAW_LABEL_INT_VALUE) {
+ return null;
+ }
+ labels.add(new LabelStackBuilder().setLabelValue(mplsLabel).build());
} while (!bottomBit);
return labels;
}
* 1 <- bottomBit 1
* 22 01 16 <- prefixType IPV4=34.1.22.0/24
*/
- private static final byte[] LU_NLRI_IPv4 = new byte[]{
+ private static final byte[] LU_REACH_NLRI_IPv4 = new byte[]{
(byte) 0x60,
(byte) 0x00, (byte) 0x16, (byte) 0x30,
(byte) 0x00, (byte) 0x16, (byte) 0x40,
(byte) 0x22, (byte) 0x01, (byte) 0x16,
};
+ /*label value for withdraw message.
+ *
+ * label stack:
+ * 30 <- length 48
+ * 80 00 00 <- labelValue for withdraw
+ * 22 01 16 <- prefixType IPV4=34.1.22.0/24
+ */
+ private static final byte[] LU_UNREACH_NLRI_IPv4 = new byte[] {
+ (byte) 0x30,
+ (byte) 0x80, (byte) 0x00, (byte) 0x00,
+ (byte) 0x22, (byte) 0x01, (byte) 0x16,
+ };
+
/*label stacks with multiple labels.
*
* label stack:
* 1 <- bottomBit 1
* 22 01 16 <- prefixType IPV4=34.1.22.0/24
*/
- private static final byte[] LU_NLRI_IPv4_ADD_PATH = new byte[]{
+ private static final byte[] LU_REACH_NLRI_IPv4_ADD_PATH = new byte[]{
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
(byte) 0x60,
(byte) 0x00, (byte) 0x16, (byte) 0x30,
(byte) 0x22, (byte) 0x01, (byte) 0x16,
};
+ /*label value for withdraw message.
+ *
+ * label stack:
+ * 1 <- Path Id
+ * 30 <- length 48
+ * 80 00 00 <- labelValue for withdraw
+ * 22 01 16 <- prefixType IPV4=34.1.22.0/24
+ */
+ private static final byte[] LU_UNREACH_NLRI_IPv4_ADD_PATH = new byte[] {
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
+ (byte) 0x30,
+ (byte) 0x80, (byte) 0x00, (byte) 0x00,
+ (byte) 0x22, (byte) 0x01, (byte) 0x16,
+ };
+
/*label stacks with multiple labels.
*
* label stack:
* 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 = new byte[]{
+ private static final byte[] LU_REACH_NLRI_IPv6 = new byte[]{
(byte) 0xC8,
(byte) 0x00, (byte) 0x16, (byte) 0x30,
(byte) 0x00, (byte) 0x16, (byte) 0x40,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
};
+ /*label value for withdraw message.
+ *
+ * label stack:
+ * 98 <- length 152
+ * 80 00 00 <- labelValue for withdraw
+ * 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_UNREACH_NLRI_IPv6 = new byte[] {
+ (byte) 0x98,
+ (byte) 0x80, (byte) 0x00, (byte) 0x00,
+ (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,
+ };
+
/*label stacks with multiple labels.
*
* label stack:
* 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[]{
+ private static final byte[] LU_REACH_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) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
};
+
+ /*label value for withdraw message.
+ *
+ * label stack:
+ * 98 <- length 152
+ * 80 00 00 <- labelValue for withdraw
+ * 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_UNREACH_NLRI_IPv6_ADD_PATH = new byte[] {
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
+ (byte) 0x98,
+ (byte) 0x80, (byte) 0x00, (byte) 0x00,
+ (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(),
final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
testBuilder.setAfi(Ipv4AddressFamily.class);
testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
- parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv4), testBuilder);
+ parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPv4), testBuilder);
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, ByteArray.readAllBytes(output));
+ Assert.assertArrayEquals(LU_REACH_NLRI_IPv4, ByteArray.readAllBytes(output));
}
@Test
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);
+ parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_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));
+ Assert.assertArrayEquals(LU_REACH_NLRI_IPv4_ADD_PATH, ByteArray.readAllBytes(output));
}
@Test
final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
mpBuilder.setAfi(Ipv4AddressFamily.class);
mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
- final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPrefix(IPv4_PREFIX).setLabelStack(LABEL_STACK).build();
+
+ final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPrefix(IPv4_PREFIX).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(lu1)).build())
+ .build()).build());
+ final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
+
+ final CLabeledUnicastDestination lu2 = new CLabeledUnicastDestinationBuilder().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())
+ 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(lu2)).build())
.build()).build());
- final MpUnreachNlri mpUnreachExpected = mpBuilder.build();
+ final MpUnreachNlri mpUnreachExpected2 = 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(mpUnreachExpected, testBuilder.build());
+ parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPv4), testBuilder);
+ Assert.assertEquals(mpUnreachExpected1, 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, ByteArray.readAllBytes(output));
+ new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()).build(), output);
+ Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv4, ByteArray.readAllBytes(output));
+
+ final ByteBuf output1 = Unpooled.buffer();
+ parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
+ new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build()).build(), output1);
+ Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv4, ByteArray.readAllBytes(output1));
}
@Test
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();
+
+ final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPv4_PREFIX).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())
+ 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(lu1)).build())
.build()).build());
- final MpUnreachNlri mpUnreachExpected = mpBuilder.build();
+ final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
+
+ final CLabeledUnicastDestination lu2 = 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(lu2)).build())
+ .build()).build());
+ final MpUnreachNlri mpUnreachExpected2 = 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());
+ parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPv4_ADD_PATH), testBuilder, this.constraint);
+ Assert.assertEquals(mpUnreachExpected1, 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));
+ new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()).build(), output);
+ Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv4_ADD_PATH, ByteArray.readAllBytes(output));
+
+ final ByteBuf output1 = Unpooled.buffer();
+ parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
+ new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build()).build(), output1);
+ Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv4_ADD_PATH, ByteArray.readAllBytes(output1));
}
@Test
final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
testBuilder.setAfi(Ipv6AddressFamily.class);
testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
- parser.parseNlri(Unpooled.copiedBuffer(LU_NLRI_IPv6), testBuilder);
+ parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPv6), testBuilder);
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, ByteArray.readAllBytes(output));
+ Assert.assertArrayEquals(LU_REACH_NLRI_IPv6, ByteArray.readAllBytes(output));
}
@Test
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);
+ parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_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));
+ Assert.assertArrayEquals(LU_REACH_NLRI_IPv6_ADD_PATH, ByteArray.readAllBytes(output));
}
@Test
final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
mpBuilder.setAfi(Ipv6AddressFamily.class);
mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
- final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPrefix(IPv6_PREFIX).setLabelStack(LABEL_STACK).build();
+
+ final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPrefix(IPv6_PREFIX).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.DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
+ 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.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder()
+ .setCLabeledUnicastDestination(Lists.newArrayList(lu1)).build()).build()).build());
+ final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
+
+ final CLabeledUnicastDestination lu2 = new CLabeledUnicastDestinationBuilder().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.DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
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.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder()
- .setCLabeledUnicastDestination(Lists.newArrayList(lu)).build()).build()).build());
- final MpUnreachNlri mpUnreachExpected = mpBuilder.build();
+ .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_NLRI_IPv6), testBuilder);
- Assert.assertEquals(mpUnreachExpected, testBuilder.build());
+ parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPv6), testBuilder);
+ Assert.assertEquals(mpUnreachExpected1, 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, ByteArray.readAllBytes(output));
+ new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()).build(), output);
+ Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv6, ByteArray.readAllBytes(output));
+
+ final ByteBuf output1 = Unpooled.buffer();
+ parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
+ new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build()).build(), output1);
+ Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv6, ByteArray.readAllBytes(output1));
}
@Test
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();
+
+ 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.rev150525.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.rev150525.update.attributes.mp
.unreach.nlri.withdrawn.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder()
- .setCLabeledUnicastDestination(Lists.newArrayList(lu)).build()).build()).build());
- final MpUnreachNlri mpUnreachExpected = mpBuilder.build();
+ .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.rev150525.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.rev150525.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_NLRI_IPv6_ADD_PATH), testBuilder, this.constraint);
- Assert.assertEquals(mpUnreachExpected, testBuilder.build());
+ parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPv6_ADD_PATH), testBuilder, this.constraint);
+ Assert.assertEquals(mpUnreachExpected1, 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));
+ new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()).build(), output);
+ Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv6_ADD_PATH, ByteArray.readAllBytes(output));
+
+ final ByteBuf output1 = Unpooled.buffer();
+ parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
+ new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build()).build(), output1);
+ Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv6_ADD_PATH, ByteArray.readAllBytes(output1));
}
}