2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.labeled.unicast;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
13 import com.google.common.collect.Lists;
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
16 import java.util.List;
17 import java.util.Optional;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.Mock;
21 import org.mockito.Mockito;
22 import org.mockito.MockitoAnnotations;
23 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
24 import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
25 import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
26 import org.opendaylight.protocol.util.ByteArray;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.LabeledUnicastSubsequentAddressFamily;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.LabelStack;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.LabelStackBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.destination.CLabeledUnicastDestination;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.labeled.unicast.destination.CLabeledUnicastDestinationBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLabeledUnicastCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.PathId;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1Builder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2Builder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlri;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlriBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlri;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlriBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv6AddressFamily;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel;
52 import org.opendaylight.yangtools.yang.common.Uint32;
54 public class LUNlriParserTest {
57 * label stacks with multiple labels.
61 * 00 16 3 <- labelValue 355
62 * 0 <- etc&bottomBit 0
63 * 00 16 4 <- labelValue 356
64 * 0 <- etc&bottomBit 0
65 * 00 16 6 <- labelValue 357
67 * 22 01 16 <- prefixType IPV4=34.1.22.0/24
69 private static final byte[] LU_REACH_NLRI_IPV4 = new byte[]{
71 (byte) 0x00, (byte) 0x16, (byte) 0x30,
72 (byte) 0x00, (byte) 0x16, (byte) 0x40,
73 (byte) 0x00, (byte) 0x16, (byte) 0x51,
74 (byte) 0x22, (byte) 0x01, (byte) 0x16,
78 * label value for withdraw message.
82 * 80 00 00 <- labelValue for withdraw
83 * 22 01 16 <- prefixType IPV4=34.1.22.0/24
85 private static final byte[] LU_UNREACH_NLRI_IPV4 = new byte[] {
87 (byte) 0x80, (byte) 0x00, (byte) 0x00,
88 (byte) 0x22, (byte) 0x01, (byte) 0x16,
92 * label stacks with multiple labels.
97 * 00 16 3 <- labelValue 355
98 * 0 <- etc&bottomBit 0
99 * 00 16 4 <- labelValue 356
100 * 0 <- etc&bottomBit 0
101 * 00 16 6 <- labelValue 357
103 * 22 01 16 <- prefixType IPV4=34.1.22.0/24
105 private static final byte[] LU_REACH_NLRI_IPV4_ADD_PATH = new byte[]{
106 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
108 (byte) 0x00, (byte) 0x16, (byte) 0x30,
109 (byte) 0x00, (byte) 0x16, (byte) 0x40,
110 (byte) 0x00, (byte) 0x16, (byte) 0x51,
111 (byte) 0x22, (byte) 0x01, (byte) 0x16,
115 * label value for withdraw message.
120 * 80 00 00 <- labelValue for withdraw
121 * 22 01 16 <- prefixType IPV4=34.1.22.0/24
123 private static final byte[] LU_UNREACH_NLRI_IPV4_ADD_PATH = new byte[] {
124 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
126 (byte) 0x80, (byte) 0x00, (byte) 0x00,
127 (byte) 0x22, (byte) 0x01, (byte) 0x16,
131 * label stacks with multiple labels.
135 * 00 16 3 <- labelValue 355
136 * 0 <- etc&bottomBit 0
137 * 00 16 4 <- labelValue 356
138 * 0 <- etc&bottomBit 0
139 * 00 16 6 <- labelValue 357
141 * 20 01 D B8 0 1 0 2 0 0 0 0 0 0 0 0 80 <- prefixType IPV6=2001:db8:1:2::/128
143 private static final byte[] LU_REACH_NLRI_IPV6 = new byte[]{
145 (byte) 0x00, (byte) 0x16, (byte) 0x30,
146 (byte) 0x00, (byte) 0x16, (byte) 0x40,
147 (byte) 0x00, (byte) 0x16, (byte) 0x51,
148 (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8,
149 (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02,
150 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
151 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
155 * label value for withdraw message.
159 * 80 00 00 <- labelValue for withdraw
160 * 20 01 D B8 0 1 0 2 0 0 0 0 0 0 0 0 80 <- prefixType IPV6=2001:db8:1:2::/128
162 private static final byte[] LU_UNREACH_NLRI_IPV6 = new byte[] {
164 (byte) 0x80, (byte) 0x00, (byte) 0x00,
165 (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8,
166 (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02,
167 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
168 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
172 * label stacks with multiple labels.
176 * 00 16 3 <- labelValue 355
177 * 0 <- etc&bottomBit 0
178 * 00 16 4 <- labelValue 356
179 * 0 <- etc&bottomBit 0
180 * 00 16 6 <- labelValue 357
182 * 20 01 D B8 0 1 0 2 0 0 0 0 0 0 0 0 80 <- prefixType IPV6=2001:db8:1:2::/128
184 private static final byte[] LU_REACH_NLRI_IPV6_ADD_PATH = new byte[]{
185 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
187 (byte) 0x00, (byte) 0x16, (byte) 0x30,
188 (byte) 0x00, (byte) 0x16, (byte) 0x40,
189 (byte) 0x00, (byte) 0x16, (byte) 0x51,
190 (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8,
191 (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02,
192 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
193 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
197 * label value for withdraw message.
201 * 80 00 00 <- labelValue for withdraw
202 * 20 01 D B8 0 1 0 2 0 0 0 0 0 0 0 0 80 <- prefixType IPV6=2001:db8:1:2::/128
204 private static final byte[] LU_UNREACH_NLRI_IPV6_ADD_PATH = new byte[] {
205 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
207 (byte) 0x80, (byte) 0x00, (byte) 0x00,
208 (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8,
209 (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02,
210 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
211 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
214 private static final List<LabelStack> LABEL_STACK = Lists.newArrayList(
215 new LabelStackBuilder().setLabelValue(new MplsLabel(Uint32.valueOf(355))).build(),
216 new LabelStackBuilder().setLabelValue(new MplsLabel(Uint32.valueOf(356))).build(),
217 new LabelStackBuilder().setLabelValue(new MplsLabel(Uint32.valueOf(357))).build());
219 private static final IpPrefix IPV4_PREFIX = new IpPrefix(new Ipv4Prefix("34.1.22.0/24"));
220 private static final IpPrefix IPV6_PREFIX = new IpPrefix(new Ipv6Prefix("2001:db8:1:2::/128"));
221 private static final PathId PATH_ID = new PathId(Uint32.ONE);
224 private PeerSpecificParserConstraint constraint;
226 private MultiPathSupport muliPathSupport;
229 public void setUp() {
230 MockitoAnnotations.initMocks(this);
231 Mockito.doReturn(Optional.of(this.muliPathSupport)).when(this.constraint).getPeerConstraint(Mockito.any());
232 Mockito.doReturn(true).when(this.muliPathSupport).isTableTypeSupported(Mockito.any());
236 public void testMpReachNlriIpv4() throws BGPParsingException {
237 final LUNlriParser parser = new LUNlriParser();
238 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
239 mpBuilder.setAfi(Ipv4AddressFamily.class);
240 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
241 final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPrefix(IPV4_PREFIX)
242 .setLabelStack(LABEL_STACK).build();
243 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
244 new DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
245 new DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build())
247 final MpReachNlri mpReachExpected = mpBuilder.build();
250 final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
251 testBuilder.setAfi(Ipv4AddressFamily.class);
252 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
253 parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPV4), testBuilder, null);
254 assertEquals(mpReachExpected, testBuilder.build());
257 final ByteBuf output = Unpooled.buffer();
258 parser.serializeAttribute(new AttributesBuilder()
259 .addAugmentation(new Attributes1Builder().setMpReachNlri(mpReachExpected).build())
261 assertArrayEquals(LU_REACH_NLRI_IPV4, ByteArray.readAllBytes(output));
265 public void testMpReachNlriIpv4Constraint() throws BGPParsingException {
266 final LUNlriParser parser = new LUNlriParser();
267 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
268 mpBuilder.setAfi(Ipv4AddressFamily.class);
269 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
270 final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID)
271 .setPrefix(IPV4_PREFIX).setLabelStack(LABEL_STACK).build();
272 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
273 new DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
274 new DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu))
275 .build()).build()).build());
276 final MpReachNlri mpReachExpected = mpBuilder.build();
279 final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
280 testBuilder.setAfi(Ipv4AddressFamily.class);
281 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
282 parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPV4_ADD_PATH), testBuilder, this.constraint);
283 assertEquals(mpReachExpected, testBuilder.build());
286 final ByteBuf output = Unpooled.buffer();
287 parser.serializeAttribute(new AttributesBuilder()
288 .addAugmentation(new Attributes1Builder().setMpReachNlri(mpReachExpected).build())
290 assertArrayEquals(LU_REACH_NLRI_IPV4_ADD_PATH, ByteArray.readAllBytes(output));
294 public void testMpUnreachNlriIpv4() throws BGPParsingException {
295 final LUNlriParser parser = new LUNlriParser();
296 final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
297 mpBuilder.setAfi(Ipv4AddressFamily.class);
298 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
300 final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPrefix(IPV4_PREFIX).build();
301 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
302 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update
303 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder()
304 .setDestinationLabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
305 .labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
306 .destination.labeled.unicast._case.DestinationLabeledUnicastBuilder()
307 .setCLabeledUnicastDestination(Lists.newArrayList(lu1)).build())
309 final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
311 final CLabeledUnicastDestination lu2 = new CLabeledUnicastDestinationBuilder().setPrefix(IPV4_PREFIX)
312 .setLabelStack(LABEL_STACK).build();
313 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
314 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update
315 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder()
316 .setDestinationLabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
317 .labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
318 .destination.labeled.unicast._case.DestinationLabeledUnicastBuilder()
319 .setCLabeledUnicastDestination(Lists.newArrayList(lu2)).build())
321 final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
324 final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
325 testBuilder.setAfi(Ipv4AddressFamily.class);
326 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
327 parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPV4), testBuilder, null);
328 assertEquals(mpUnreachExpected1, testBuilder.build());
331 final ByteBuf output = Unpooled.buffer();
332 parser.serializeAttribute(new AttributesBuilder()
333 .addAugmentation(new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build())
335 assertArrayEquals(LU_UNREACH_NLRI_IPV4, ByteArray.readAllBytes(output));
337 final ByteBuf output1 = Unpooled.buffer();
338 parser.serializeAttribute(new AttributesBuilder()
339 .addAugmentation(new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build())
341 assertArrayEquals(LU_UNREACH_NLRI_IPV4, ByteArray.readAllBytes(output1));
345 public void testMpUnreachNlriIpv4Constraint() throws BGPParsingException {
346 final LUNlriParser parser = new LUNlriParser();
347 final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
348 mpBuilder.setAfi(Ipv4AddressFamily.class);
349 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
351 final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID)
352 .setPrefix(IPV4_PREFIX).build();
353 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
354 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update
355 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder()
356 .setDestinationLabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
357 .labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
358 .destination.labeled.unicast._case.DestinationLabeledUnicastBuilder()
359 .setCLabeledUnicastDestination(Lists.newArrayList(lu1)).build())
361 final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
363 final CLabeledUnicastDestination lu2 = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID)
364 .setPrefix(IPV4_PREFIX).setLabelStack(LABEL_STACK).build();
365 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
366 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update
367 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder()
368 .setDestinationLabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
369 .labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
370 .destination.labeled.unicast._case.DestinationLabeledUnicastBuilder()
371 .setCLabeledUnicastDestination(Lists.newArrayList(lu2)).build())
373 final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
376 final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
377 testBuilder.setAfi(Ipv4AddressFamily.class);
378 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
379 parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPV4_ADD_PATH), testBuilder, this.constraint);
380 assertEquals(mpUnreachExpected1, testBuilder.build());
383 final ByteBuf output = Unpooled.buffer();
384 parser.serializeAttribute(new AttributesBuilder()
385 .addAugmentation(new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build())
387 assertArrayEquals(LU_UNREACH_NLRI_IPV4_ADD_PATH, ByteArray.readAllBytes(output));
389 final ByteBuf output1 = Unpooled.buffer();
390 parser.serializeAttribute(new AttributesBuilder()
391 .addAugmentation(new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build())
393 assertArrayEquals(LU_UNREACH_NLRI_IPV4_ADD_PATH, ByteArray.readAllBytes(output1));
397 public void testMpReachNlriIpv6() throws BGPParsingException {
398 final LUNlriParser parser = new LUNlriParser();
399 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
400 mpBuilder.setAfi(Ipv6AddressFamily.class);
401 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
402 final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPrefix(IPV6_PREFIX)
403 .setLabelStack(LABEL_STACK).build();
404 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
405 new DestinationIpv6LabeledUnicastCaseBuilder()
406 .setDestinationIpv6LabeledUnicast(new DestinationIpv6LabeledUnicastBuilder()
407 .setCLabeledUnicastDestination(Lists.newArrayList(lu)).build())
409 final MpReachNlri mpReachExpected = mpBuilder.build();
412 final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
413 testBuilder.setAfi(Ipv6AddressFamily.class);
414 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
415 parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPV6), testBuilder, null);
416 assertEquals(mpReachExpected, testBuilder.build());
419 final ByteBuf output = Unpooled.buffer();
420 parser.serializeAttribute(new AttributesBuilder()
421 .addAugmentation(new Attributes1Builder().setMpReachNlri(mpReachExpected).build())
423 assertArrayEquals(LU_REACH_NLRI_IPV6, ByteArray.readAllBytes(output));
427 public void testMpReachNlriIpv6Constraint() throws BGPParsingException {
428 final LUNlriParser parser = new LUNlriParser();
429 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
430 mpBuilder.setAfi(Ipv6AddressFamily.class);
431 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
432 final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID)
433 .setPrefix(IPV6_PREFIX).setLabelStack(LABEL_STACK).build();
434 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
435 new DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
436 new DestinationIpv6LabeledUnicastBuilder()
437 .setCLabeledUnicastDestination(Lists.newArrayList(lu)).build()).build())
439 final MpReachNlri mpReachExpected = mpBuilder.build();
442 final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
443 testBuilder.setAfi(Ipv6AddressFamily.class);
444 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
445 parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPV6_ADD_PATH), testBuilder, this.constraint);
446 assertEquals(mpReachExpected, testBuilder.build());
449 final ByteBuf output = Unpooled.buffer();
450 parser.serializeAttribute(new AttributesBuilder()
451 .addAugmentation(new Attributes1Builder().setMpReachNlri(mpReachExpected).build())
453 assertArrayEquals(LU_REACH_NLRI_IPV6_ADD_PATH, ByteArray.readAllBytes(output));
457 public void testMpUnreachNlriIpv6() throws BGPParsingException {
458 final LUNlriParser parser = new LUNlriParser();
459 final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
460 mpBuilder.setAfi(Ipv6AddressFamily.class);
461 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
463 final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPrefix(IPV6_PREFIX).build();
464 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
465 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update
466 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder()
467 .setDestinationIpv6LabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
468 .bgp.labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
469 .destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder()
470 .setCLabeledUnicastDestination(Lists.newArrayList(lu1)).build()).build()).build());
471 final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
473 final CLabeledUnicastDestination lu2 = new CLabeledUnicastDestinationBuilder().setPrefix(IPV6_PREFIX)
474 .setLabelStack(LABEL_STACK).build();
475 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(new org.opendaylight.yang.gen.v1
476 .urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.unreach
477 .nlri.withdrawn.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder()
478 .setDestinationIpv6LabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
479 .labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
480 .destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder()
481 .setCLabeledUnicastDestination(Lists.newArrayList(lu2)).build()).build()).build());
482 final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
485 final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
486 testBuilder.setAfi(Ipv6AddressFamily.class);
487 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
488 parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPV6), testBuilder, null);
489 assertEquals(mpUnreachExpected1, testBuilder.build());
492 final ByteBuf output = Unpooled.buffer();
493 parser.serializeAttribute(new AttributesBuilder()
494 .addAugmentation(new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build())
496 assertArrayEquals(LU_UNREACH_NLRI_IPV6, ByteArray.readAllBytes(output));
498 final ByteBuf output1 = Unpooled.buffer();
499 parser.serializeAttribute(new AttributesBuilder()
500 .addAugmentation(new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build())
502 assertArrayEquals(LU_UNREACH_NLRI_IPV6, ByteArray.readAllBytes(output1));
506 public void testMpUnreachNlriIpv6Constraint() throws BGPParsingException {
507 final LUNlriParser parser = new LUNlriParser();
508 final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
509 mpBuilder.setAfi(Ipv6AddressFamily.class);
510 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
512 final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID)
513 .setPrefix(IPV6_PREFIX).build();
514 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
515 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update
516 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder()
517 .setDestinationIpv6LabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
518 .bgp.labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
519 .destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder()
520 .setCLabeledUnicastDestination(Lists.newArrayList(lu1)).build()).build()).build());
521 final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
523 final CLabeledUnicastDestination lu2 = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID)
524 .setPrefix(IPV6_PREFIX).setLabelStack(LABEL_STACK).build();
525 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
526 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329
527 .update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
528 .DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
529 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329
530 .update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.ipv6.labeled
531 .unicast._case.DestinationIpv6LabeledUnicastBuilder()
532 .setCLabeledUnicastDestination(Lists.newArrayList(lu2)).build()).build()).build());
533 final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
536 final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
537 testBuilder.setAfi(Ipv6AddressFamily.class);
538 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
539 parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPV6_ADD_PATH), testBuilder, this.constraint);
540 assertEquals(mpUnreachExpected1, testBuilder.build());
543 final ByteBuf output = Unpooled.buffer();
544 parser.serializeAttribute(new AttributesBuilder()
545 .addAugmentation(new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build())
547 assertArrayEquals(LU_UNREACH_NLRI_IPV6_ADD_PATH, ByteArray.readAllBytes(output));
549 final ByteBuf output1 = Unpooled.buffer();
550 parser.serializeAttribute(new AttributesBuilder()
551 .addAugmentation(new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build())
553 assertArrayEquals(LU_UNREACH_NLRI_IPV6_ADD_PATH, ByteArray.readAllBytes(output1));