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.rev180329.PathId;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1Builder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2Builder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlri;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlriBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlri;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlriBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv6AddressFamily;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel;
55 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,
77 /*label value for withdraw message.
81 * 80 00 00 <- labelValue for withdraw
82 * 22 01 16 <- prefixType IPV4=34.1.22.0/24
84 private static final byte[] LU_UNREACH_NLRI_IPv4 = new byte[] {
86 (byte) 0x80, (byte) 0x00, (byte) 0x00,
87 (byte) 0x22, (byte) 0x01, (byte) 0x16,
90 /*label stacks with multiple labels.
95 * 00 16 3 <- labelValue 355
96 * 0 <- etc&bottomBit 0
97 * 00 16 4 <- labelValue 356
98 * 0 <- etc&bottomBit 0
99 * 00 16 6 <- labelValue 357
101 * 22 01 16 <- prefixType IPV4=34.1.22.0/24
103 private static final byte[] LU_REACH_NLRI_IPv4_ADD_PATH = new byte[]{
104 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
106 (byte) 0x00, (byte) 0x16, (byte) 0x30,
107 (byte) 0x00, (byte) 0x16, (byte) 0x40,
108 (byte) 0x00, (byte) 0x16, (byte) 0x51,
109 (byte) 0x22, (byte) 0x01, (byte) 0x16,
112 /*label value for withdraw message.
117 * 80 00 00 <- labelValue for withdraw
118 * 22 01 16 <- prefixType IPV4=34.1.22.0/24
120 private static final byte[] LU_UNREACH_NLRI_IPv4_ADD_PATH = new byte[] {
121 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
123 (byte) 0x80, (byte) 0x00, (byte) 0x00,
124 (byte) 0x22, (byte) 0x01, (byte) 0x16,
127 /*label stacks with multiple labels.
131 * 00 16 3 <- labelValue 355
132 * 0 <- etc&bottomBit 0
133 * 00 16 4 <- labelValue 356
134 * 0 <- etc&bottomBit 0
135 * 00 16 6 <- labelValue 357
137 * 20 01 D B8 0 1 0 2 0 0 0 0 0 0 0 0 80 <- prefixType IPV6=2001:db8:1:2::/128
139 private static final byte[] LU_REACH_NLRI_IPv6 = new byte[]{
141 (byte) 0x00, (byte) 0x16, (byte) 0x30,
142 (byte) 0x00, (byte) 0x16, (byte) 0x40,
143 (byte) 0x00, (byte) 0x16, (byte) 0x51,
144 (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8,
145 (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02,
146 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
147 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
150 /*label value for withdraw message.
154 * 80 00 00 <- labelValue for withdraw
155 * 20 01 D B8 0 1 0 2 0 0 0 0 0 0 0 0 80 <- prefixType IPV6=2001:db8:1:2::/128
157 private static final byte[] LU_UNREACH_NLRI_IPv6 = new byte[] {
159 (byte) 0x80, (byte) 0x00, (byte) 0x00,
160 (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8,
161 (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02,
162 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
163 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
166 /*label stacks with multiple labels.
170 * 00 16 3 <- labelValue 355
171 * 0 <- etc&bottomBit 0
172 * 00 16 4 <- labelValue 356
173 * 0 <- etc&bottomBit 0
174 * 00 16 6 <- labelValue 357
176 * 20 01 D B8 0 1 0 2 0 0 0 0 0 0 0 0 80 <- prefixType IPV6=2001:db8:1:2::/128
178 private static final byte[] LU_REACH_NLRI_IPv6_ADD_PATH = new byte[]{
179 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
181 (byte) 0x00, (byte) 0x16, (byte) 0x30,
182 (byte) 0x00, (byte) 0x16, (byte) 0x40,
183 (byte) 0x00, (byte) 0x16, (byte) 0x51,
184 (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8,
185 (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02,
186 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
187 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
190 /*label value for withdraw message.
194 * 80 00 00 <- labelValue for withdraw
195 * 20 01 D B8 0 1 0 2 0 0 0 0 0 0 0 0 80 <- prefixType IPV6=2001:db8:1:2::/128
197 private static final byte[] LU_UNREACH_NLRI_IPv6_ADD_PATH = new byte[] {
198 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
200 (byte) 0x80, (byte) 0x00, (byte) 0x00,
201 (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8,
202 (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02,
203 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
204 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
207 private static final List<LabelStack> LABEL_STACK = Lists.newArrayList(
208 new LabelStackBuilder().setLabelValue(new MplsLabel(355L)).build(),
209 new LabelStackBuilder().setLabelValue(new MplsLabel(356L)).build(),
210 new LabelStackBuilder().setLabelValue(new MplsLabel(357L)).build());
212 private static final IpPrefix IPv4_PREFIX = new IpPrefix(new Ipv4Prefix("34.1.22.0/24"));
213 private static final IpPrefix IPv6_PREFIX = new IpPrefix(new Ipv6Prefix("2001:db8:1:2::/128"));
214 private static final PathId PATH_ID = new PathId(1L);
217 private PeerSpecificParserConstraint constraint;
219 private MultiPathSupport muliPathSupport;
223 public void setUp() {
224 MockitoAnnotations.initMocks(this);
225 Mockito.doReturn(Optional.of(this.muliPathSupport)).when(this.constraint).getPeerConstraint(Mockito.any());
226 Mockito.doReturn(true).when(this.muliPathSupport).isTableTypeSupported(Mockito.any());
230 public void testMpReachNlriIpv4() throws BGPParsingException {
231 final LUNlriParser parser = new LUNlriParser();
232 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
233 mpBuilder.setAfi(Ipv4AddressFamily.class);
234 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
235 final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPrefix(IPv4_PREFIX)
236 .setLabelStack(LABEL_STACK).build();
237 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
238 new DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
239 new DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build())
241 final MpReachNlri mpReachExpected = mpBuilder.build();
244 final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
245 testBuilder.setAfi(Ipv4AddressFamily.class);
246 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
247 parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPv4), testBuilder, null);
248 assertEquals(mpReachExpected, testBuilder.build());
251 final ByteBuf output = Unpooled.buffer();
252 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class,
253 new Attributes1Builder().setMpReachNlri(mpReachExpected).build()).build(), output);
254 assertArrayEquals(LU_REACH_NLRI_IPv4, ByteArray.readAllBytes(output));
258 public void testMpReachNlriIpv4Constraint() throws BGPParsingException {
259 final LUNlriParser parser = new LUNlriParser();
260 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
261 mpBuilder.setAfi(Ipv4AddressFamily.class);
262 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
263 final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID)
264 .setPrefix(IPv4_PREFIX).setLabelStack
265 (LABEL_STACK).build();
266 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
267 new DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
268 new DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu))
269 .build()).build()).build());
270 final MpReachNlri mpReachExpected = mpBuilder.build();
273 final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
274 testBuilder.setAfi(Ipv4AddressFamily.class);
275 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
276 parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPv4_ADD_PATH), testBuilder, this.constraint);
277 assertEquals(mpReachExpected, testBuilder.build());
280 final ByteBuf output = Unpooled.buffer();
281 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class,
282 new Attributes1Builder().setMpReachNlri(mpReachExpected).build()).build(), output);
283 assertArrayEquals(LU_REACH_NLRI_IPv4_ADD_PATH, ByteArray.readAllBytes(output));
287 public void testMpUnreachNlriIpv4() throws BGPParsingException {
288 final LUNlriParser parser = new LUNlriParser();
289 final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
290 mpBuilder.setAfi(Ipv4AddressFamily.class);
291 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
293 final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPrefix(IPv4_PREFIX).build();
294 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
295 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update
296 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder()
297 .setDestinationLabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
298 .labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
299 .destination.labeled.unicast._case.DestinationLabeledUnicastBuilder()
300 .setCLabeledUnicastDestination(Lists.newArrayList(lu1)).build())
302 final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
304 final CLabeledUnicastDestination lu2 = new CLabeledUnicastDestinationBuilder().setPrefix(IPv4_PREFIX)
305 .setLabelStack(LABEL_STACK).build();
306 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
307 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update
308 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder()
309 .setDestinationLabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
310 .labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.
311 destination.labeled.unicast._case.DestinationLabeledUnicastBuilder()
312 .setCLabeledUnicastDestination(Lists.newArrayList(lu2)).build())
314 final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
317 final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
318 testBuilder.setAfi(Ipv4AddressFamily.class);
319 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
320 parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPv4), testBuilder, null);
321 assertEquals(mpUnreachExpected1, testBuilder.build());
324 final ByteBuf output = Unpooled.buffer();
325 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
326 new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()).build(), output);
327 assertArrayEquals(LU_UNREACH_NLRI_IPv4, ByteArray.readAllBytes(output));
329 final ByteBuf output1 = Unpooled.buffer();
330 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
331 new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build()).build(), output1);
332 assertArrayEquals(LU_UNREACH_NLRI_IPv4, ByteArray.readAllBytes(output1));
336 public void testMpUnreachNlriIpv4Constraint() throws BGPParsingException {
337 final LUNlriParser parser = new LUNlriParser();
338 final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
339 mpBuilder.setAfi(Ipv4AddressFamily.class);
340 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
342 final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID)
343 .setPrefix(IPv4_PREFIX).build();
344 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
345 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update
346 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder()
347 .setDestinationLabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
348 .labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
349 .destination.labeled.unicast._case.DestinationLabeledUnicastBuilder()
350 .setCLabeledUnicastDestination(Lists.newArrayList(lu1)).build())
352 final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
354 final CLabeledUnicastDestination lu2 = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID)
355 .setPrefix(IPv4_PREFIX).setLabelStack(LABEL_STACK).build();
356 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
357 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update
358 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLabeledUnicastCaseBuilder()
359 .setDestinationLabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
360 .labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
361 .destination.labeled.unicast._case.DestinationLabeledUnicastBuilder()
362 .setCLabeledUnicastDestination(Lists.newArrayList(lu2)).build())
364 final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
367 final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
368 testBuilder.setAfi(Ipv4AddressFamily.class);
369 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
370 parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPv4_ADD_PATH), testBuilder, this.constraint);
371 assertEquals(mpUnreachExpected1, testBuilder.build());
374 final ByteBuf output = Unpooled.buffer();
375 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
376 new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()).build(), output);
377 assertArrayEquals(LU_UNREACH_NLRI_IPv4_ADD_PATH, ByteArray.readAllBytes(output));
379 final ByteBuf output1 = Unpooled.buffer();
380 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
381 new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build()).build(), output1);
382 assertArrayEquals(LU_UNREACH_NLRI_IPv4_ADD_PATH, ByteArray.readAllBytes(output1));
386 public void testMpReachNlriIpv6() throws BGPParsingException {
387 final LUNlriParser parser = new LUNlriParser();
388 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
389 mpBuilder.setAfi(Ipv6AddressFamily.class);
390 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
391 final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPrefix(IPv6_PREFIX)
392 .setLabelStack(LABEL_STACK).build();
393 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
394 new DestinationIpv6LabeledUnicastCaseBuilder()
395 .setDestinationIpv6LabeledUnicast(new DestinationIpv6LabeledUnicastBuilder()
396 .setCLabeledUnicastDestination(Lists.newArrayList(lu)).build())
398 final MpReachNlri mpReachExpected = mpBuilder.build();
401 final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
402 testBuilder.setAfi(Ipv6AddressFamily.class);
403 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
404 parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPv6), testBuilder, null);
405 assertEquals(mpReachExpected, testBuilder.build());
408 final ByteBuf output = Unpooled.buffer();
409 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class,
410 new Attributes1Builder().setMpReachNlri(mpReachExpected).build()).build(), output);
411 assertArrayEquals(LU_REACH_NLRI_IPv6, ByteArray.readAllBytes(output));
415 public void testMpReachNlriIpv6Constraint() throws BGPParsingException {
416 final LUNlriParser parser = new LUNlriParser();
417 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
418 mpBuilder.setAfi(Ipv6AddressFamily.class);
419 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
420 final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID)
421 .setPrefix(IPv6_PREFIX).setLabelStack(LABEL_STACK).build();
422 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
423 new DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
424 new DestinationIpv6LabeledUnicastBuilder()
425 .setCLabeledUnicastDestination(Lists.newArrayList(lu)).build()).build())
427 final MpReachNlri mpReachExpected = mpBuilder.build();
430 final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
431 testBuilder.setAfi(Ipv6AddressFamily.class);
432 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
433 parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPv6_ADD_PATH), testBuilder, this.constraint);
434 assertEquals(mpReachExpected, testBuilder.build());
437 final ByteBuf output = Unpooled.buffer();
438 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class,
439 new Attributes1Builder().setMpReachNlri(mpReachExpected).build()).build(), output);
440 assertArrayEquals(LU_REACH_NLRI_IPv6_ADD_PATH, ByteArray.readAllBytes(output));
444 public void testMpUnreachNlriIpv6() throws BGPParsingException {
445 final LUNlriParser parser = new LUNlriParser();
446 final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
447 mpBuilder.setAfi(Ipv6AddressFamily.class);
448 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
450 final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPrefix(IPv6_PREFIX).build();
451 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
452 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update
453 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder()
454 .setDestinationIpv6LabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
455 .bgp.labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
456 .destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder()
457 .setCLabeledUnicastDestination(Lists.newArrayList(lu1)).build()).build()).build());
458 final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
460 final CLabeledUnicastDestination lu2 = new CLabeledUnicastDestinationBuilder().setPrefix(IPv6_PREFIX)
461 .setLabelStack(LABEL_STACK).build();
462 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(new org.opendaylight.yang.gen.v1
463 .urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update.attributes.mp.unreach
464 .nlri.withdrawn.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder()
465 .setDestinationIpv6LabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp
466 .labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
467 .destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder()
468 .setCLabeledUnicastDestination(Lists.newArrayList(lu2)).build()).build()).build());
469 final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
472 final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
473 testBuilder.setAfi(Ipv6AddressFamily.class);
474 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
475 parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPv6), testBuilder, null);
476 assertEquals(mpUnreachExpected1, testBuilder.build());
479 final ByteBuf output = Unpooled.buffer();
480 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
481 new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()).build(), output);
482 assertArrayEquals(LU_UNREACH_NLRI_IPv6, ByteArray.readAllBytes(output));
484 final ByteBuf output1 = Unpooled.buffer();
485 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
486 new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build()).build(), output1);
487 assertArrayEquals(LU_UNREACH_NLRI_IPv6, ByteArray.readAllBytes(output1));
491 public void testMpUnreachNlriIpv6Constraint() throws BGPParsingException {
492 final LUNlriParser parser = new LUNlriParser();
493 final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
494 mpBuilder.setAfi(Ipv6AddressFamily.class);
495 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
497 final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID)
498 .setPrefix(IPv6_PREFIX).build();
499 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
500 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329.update
501 .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder()
502 .setDestinationIpv6LabeledUnicast(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
503 .bgp.labeled.unicast.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
504 .destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder()
505 .setCLabeledUnicastDestination(Lists.newArrayList(lu1)).build()).build()).build());
506 final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
508 final CLabeledUnicastDestination lu2 = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID)
509 .setPrefix(IPv6_PREFIX).setLabelStack(LABEL_STACK).build();
510 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
511 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329
512 .update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
513 .DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
514 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev180329
515 .update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.ipv6.labeled
516 .unicast._case.DestinationIpv6LabeledUnicastBuilder()
517 .setCLabeledUnicastDestination(Lists.newArrayList(lu2)).build()).build()).build());
518 final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
521 final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
522 testBuilder.setAfi(Ipv6AddressFamily.class);
523 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
524 parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPv6_ADD_PATH), testBuilder, this.constraint);
525 assertEquals(mpUnreachExpected1, testBuilder.build());
528 final ByteBuf output = Unpooled.buffer();
529 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
530 new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()).build(), output);
531 assertArrayEquals(LU_UNREACH_NLRI_IPv6_ADD_PATH, ByteArray.readAllBytes(output));
533 final ByteBuf output1 = Unpooled.buffer();
534 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
535 new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build()).build(), output1);
536 assertArrayEquals(LU_UNREACH_NLRI_IPv6_ADD_PATH, ByteArray.readAllBytes(output1));