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 com.google.common.collect.Lists;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import java.util.List;
14 import java.util.Optional;
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.mockito.Mock;
19 import org.mockito.Mockito;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
22 import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
23 import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
24 import org.opendaylight.protocol.util.ByteArray;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.LabeledUnicastSubsequentAddressFamily;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.LabelStack;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.LabelStackBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.destination.CLabeledUnicastDestination;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.labeled.unicast.destination.CLabeledUnicastDestinationBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLabeledUnicastCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.labeled.unicast._case.DestinationLabeledUnicastBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathId;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1Builder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes2Builder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlri;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlriBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlri;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel;
53 public class LUNlriParserTest {
55 /*label stacks with multiple labels.
59 * 00 16 3 <- labelValue 355
60 * 0 <- etc&bottomBit 0
61 * 00 16 4 <- labelValue 356
62 * 0 <- etc&bottomBit 0
63 * 00 16 6 <- labelValue 357
65 * 22 01 16 <- prefixType IPV4=34.1.22.0/24
67 private static final byte[] LU_REACH_NLRI_IPv4 = new byte[]{
69 (byte) 0x00, (byte) 0x16, (byte) 0x30,
70 (byte) 0x00, (byte) 0x16, (byte) 0x40,
71 (byte) 0x00, (byte) 0x16, (byte) 0x51,
72 (byte) 0x22, (byte) 0x01, (byte) 0x16,
75 /*label value for withdraw message.
79 * 80 00 00 <- labelValue for withdraw
80 * 22 01 16 <- prefixType IPV4=34.1.22.0/24
82 private static final byte[] LU_UNREACH_NLRI_IPv4 = new byte[] {
84 (byte) 0x80, (byte) 0x00, (byte) 0x00,
85 (byte) 0x22, (byte) 0x01, (byte) 0x16,
88 /*label stacks with multiple labels.
93 * 00 16 3 <- labelValue 355
94 * 0 <- etc&bottomBit 0
95 * 00 16 4 <- labelValue 356
96 * 0 <- etc&bottomBit 0
97 * 00 16 6 <- labelValue 357
99 * 22 01 16 <- prefixType IPV4=34.1.22.0/24
101 private static final byte[] LU_REACH_NLRI_IPv4_ADD_PATH = new byte[]{
102 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
104 (byte) 0x00, (byte) 0x16, (byte) 0x30,
105 (byte) 0x00, (byte) 0x16, (byte) 0x40,
106 (byte) 0x00, (byte) 0x16, (byte) 0x51,
107 (byte) 0x22, (byte) 0x01, (byte) 0x16,
110 /*label value for withdraw message.
115 * 80 00 00 <- labelValue for withdraw
116 * 22 01 16 <- prefixType IPV4=34.1.22.0/24
118 private static final byte[] LU_UNREACH_NLRI_IPv4_ADD_PATH = new byte[] {
119 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
121 (byte) 0x80, (byte) 0x00, (byte) 0x00,
122 (byte) 0x22, (byte) 0x01, (byte) 0x16,
125 /*label stacks with multiple labels.
129 * 00 16 3 <- labelValue 355
130 * 0 <- etc&bottomBit 0
131 * 00 16 4 <- labelValue 356
132 * 0 <- etc&bottomBit 0
133 * 00 16 6 <- labelValue 357
135 * 20 01 D B8 0 1 0 2 0 0 0 0 0 0 0 0 80 <- prefixType IPV6=2001:db8:1:2::/128
137 private static final byte[] LU_REACH_NLRI_IPv6 = new byte[]{
139 (byte) 0x00, (byte) 0x16, (byte) 0x30,
140 (byte) 0x00, (byte) 0x16, (byte) 0x40,
141 (byte) 0x00, (byte) 0x16, (byte) 0x51,
142 (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8,
143 (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02,
144 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
145 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
148 /*label value for withdraw message.
152 * 80 00 00 <- labelValue for withdraw
153 * 20 01 D B8 0 1 0 2 0 0 0 0 0 0 0 0 80 <- prefixType IPV6=2001:db8:1:2::/128
155 private static final byte[] LU_UNREACH_NLRI_IPv6 = new byte[] {
157 (byte) 0x80, (byte) 0x00, (byte) 0x00,
158 (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8,
159 (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02,
160 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
161 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
164 /*label stacks with multiple labels.
168 * 00 16 3 <- labelValue 355
169 * 0 <- etc&bottomBit 0
170 * 00 16 4 <- labelValue 356
171 * 0 <- etc&bottomBit 0
172 * 00 16 6 <- labelValue 357
174 * 20 01 D B8 0 1 0 2 0 0 0 0 0 0 0 0 80 <- prefixType IPV6=2001:db8:1:2::/128
176 private static final byte[] LU_REACH_NLRI_IPv6_ADD_PATH = new byte[]{
177 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
179 (byte) 0x00, (byte) 0x16, (byte) 0x30,
180 (byte) 0x00, (byte) 0x16, (byte) 0x40,
181 (byte) 0x00, (byte) 0x16, (byte) 0x51,
182 (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8,
183 (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02,
184 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
185 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
188 /*label value for withdraw message.
192 * 80 00 00 <- labelValue for withdraw
193 * 20 01 D B8 0 1 0 2 0 0 0 0 0 0 0 0 80 <- prefixType IPV6=2001:db8:1:2::/128
195 private static final byte[] LU_UNREACH_NLRI_IPv6_ADD_PATH = new byte[] {
196 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
198 (byte) 0x80, (byte) 0x00, (byte) 0x00,
199 (byte) 0x20, (byte) 0x01, (byte) 0x0d, (byte) 0xb8,
200 (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02,
201 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
202 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
205 private static final List<LabelStack> LABEL_STACK = Lists.newArrayList(
206 new LabelStackBuilder().setLabelValue(new MplsLabel(355L)).build(),
207 new LabelStackBuilder().setLabelValue(new MplsLabel(356L)).build(),
208 new LabelStackBuilder().setLabelValue(new MplsLabel(357L)).build());
210 private static final IpPrefix IPv4_PREFIX = new IpPrefix(new Ipv4Prefix("34.1.22.0/24"));
211 private static final IpPrefix IPv6_PREFIX = new IpPrefix(new Ipv6Prefix("2001:db8:1:2::/128"));
212 private static final PathId PATH_ID = new PathId(1L);
215 private PeerSpecificParserConstraint constraint;
217 private MultiPathSupport muliPathSupport;
221 public void setUp() {
222 MockitoAnnotations.initMocks(this);
223 Mockito.doReturn(Optional.of(this.muliPathSupport)).when(this.constraint).getPeerConstraint(Mockito.any());
224 Mockito.doReturn(true).when(this.muliPathSupport).isTableTypeSupported(Mockito.any());
228 public void testMpReachNlriIpv4() throws BGPParsingException {
229 final LUNlriParser parser = new LUNlriParser();
230 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
231 mpBuilder.setAfi(Ipv4AddressFamily.class);
232 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
233 final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPrefix(IPv4_PREFIX).setLabelStack(LABEL_STACK).build();
234 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
235 new DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
236 new DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build()).build()).build());
237 final MpReachNlri mpReachExpected = mpBuilder.build();
240 final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
241 testBuilder.setAfi(Ipv4AddressFamily.class);
242 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
243 parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPv4), testBuilder);
244 Assert.assertEquals(mpReachExpected, testBuilder.build());
247 final ByteBuf output = Unpooled.buffer();
248 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class,
249 new Attributes1Builder().setMpReachNlri(mpReachExpected).build()).build(), output);
250 Assert.assertArrayEquals(LU_REACH_NLRI_IPv4, ByteArray.readAllBytes(output));
254 public void testMpReachNlriIpv4Constraint() throws BGPParsingException {
255 final LUNlriParser parser = new LUNlriParser();
256 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
257 mpBuilder.setAfi(Ipv4AddressFamily.class);
258 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
259 final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPv4_PREFIX).setLabelStack
260 (LABEL_STACK).build();
261 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
262 new DestinationLabeledUnicastCaseBuilder().setDestinationLabeledUnicast(
263 new DestinationLabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build()).build()).build());
264 final MpReachNlri mpReachExpected = mpBuilder.build();
267 final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
268 testBuilder.setAfi(Ipv4AddressFamily.class);
269 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
270 parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPv4_ADD_PATH), testBuilder, this.constraint);
271 Assert.assertEquals(mpReachExpected, testBuilder.build());
274 final ByteBuf output = Unpooled.buffer();
275 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class,
276 new Attributes1Builder().setMpReachNlri(mpReachExpected).build()).build(), output);
277 Assert.assertArrayEquals(LU_REACH_NLRI_IPv4_ADD_PATH, ByteArray.readAllBytes(output));
281 public void testMpUnreachNlriIpv4() throws BGPParsingException {
282 final LUNlriParser parser = new LUNlriParser();
283 final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
284 mpBuilder.setAfi(Ipv4AddressFamily.class);
285 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
287 final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPrefix(IPv4_PREFIX).build();
288 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
289 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(
290 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())
292 final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
294 final CLabeledUnicastDestination lu2 = new CLabeledUnicastDestinationBuilder().setPrefix(IPv4_PREFIX).setLabelStack(LABEL_STACK).build();
295 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
296 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(
297 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())
299 final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
302 final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
303 testBuilder.setAfi(Ipv4AddressFamily.class);
304 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
305 parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPv4), testBuilder);
306 Assert.assertEquals(mpUnreachExpected1, testBuilder.build());
309 final ByteBuf output = Unpooled.buffer();
310 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
311 new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()).build(), output);
312 Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv4, ByteArray.readAllBytes(output));
314 final ByteBuf output1 = Unpooled.buffer();
315 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
316 new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build()).build(), output1);
317 Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv4, ByteArray.readAllBytes(output1));
321 public void testMpUnreachNlriIpv4Constraint() throws BGPParsingException {
322 final LUNlriParser parser = new LUNlriParser();
323 final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
324 mpBuilder.setAfi(Ipv4AddressFamily.class);
325 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
327 final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPv4_PREFIX).build();
328 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
329 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(
330 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())
332 final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
334 final CLabeledUnicastDestination lu2 = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPv4_PREFIX).setLabelStack(LABEL_STACK).build();
335 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
336 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(
337 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())
339 final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
342 final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
343 testBuilder.setAfi(Ipv4AddressFamily.class);
344 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
345 parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPv4_ADD_PATH), testBuilder, this.constraint);
346 Assert.assertEquals(mpUnreachExpected1, testBuilder.build());
349 final ByteBuf output = Unpooled.buffer();
350 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
351 new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()).build(), output);
352 Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv4_ADD_PATH, ByteArray.readAllBytes(output));
354 final ByteBuf output1 = Unpooled.buffer();
355 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
356 new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build()).build(), output1);
357 Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv4_ADD_PATH, ByteArray.readAllBytes(output1));
361 public void testMpReachNlriIpv6() throws BGPParsingException {
362 final LUNlriParser parser = new LUNlriParser();
363 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
364 mpBuilder.setAfi(Ipv6AddressFamily.class);
365 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
366 final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPrefix(IPv6_PREFIX).setLabelStack(LABEL_STACK).build();
367 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationIpv6LabeledUnicastCaseBuilder()
368 .setDestinationIpv6LabeledUnicast(new DestinationIpv6LabeledUnicastBuilder().setCLabeledUnicastDestination(Lists.newArrayList(lu)).build())
370 final MpReachNlri mpReachExpected = mpBuilder.build();
373 final MpReachNlriBuilder testBuilder = new MpReachNlriBuilder();
374 testBuilder.setAfi(Ipv6AddressFamily.class);
375 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
376 parser.parseNlri(Unpooled.copiedBuffer(LU_REACH_NLRI_IPv6), testBuilder);
377 Assert.assertEquals(mpReachExpected, testBuilder.build());
380 final ByteBuf output = Unpooled.buffer();
381 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes1.class,
382 new Attributes1Builder().setMpReachNlri(mpReachExpected).build()).build(), output);
383 Assert.assertArrayEquals(LU_REACH_NLRI_IPv6, ByteArray.readAllBytes(output));
387 public void testMpReachNlriIpv6Constraint() throws BGPParsingException {
388 final LUNlriParser parser = new LUNlriParser();
389 final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
390 mpBuilder.setAfi(Ipv6AddressFamily.class);
391 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
392 final CLabeledUnicastDestination lu = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPv6_PREFIX).setLabelStack(LABEL_STACK).build();
393 mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
394 new DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
395 new DestinationIpv6LabeledUnicastBuilder().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_ADD_PATH), testBuilder, this.constraint);
405 Assert.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 Assert.assertArrayEquals(LU_REACH_NLRI_IPv6_ADD_PATH, ByteArray.readAllBytes(output));
415 public void testMpUnreachNlriIpv6() throws BGPParsingException {
416 final LUNlriParser parser = new LUNlriParser();
417 final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
418 mpBuilder.setAfi(Ipv6AddressFamily.class);
419 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
421 final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPrefix(IPv6_PREFIX).build();
422 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
423 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach
424 .nlri.withdrawn.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
425 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp
426 .unreach.nlri.withdrawn.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder()
427 .setCLabeledUnicastDestination(Lists.newArrayList(lu1)).build()).build()).build());
428 final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
430 final CLabeledUnicastDestination lu2 = new CLabeledUnicastDestinationBuilder().setPrefix(IPv6_PREFIX).setLabelStack(LABEL_STACK).build();
431 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
432 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach
433 .nlri.withdrawn.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
434 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp
435 .unreach.nlri.withdrawn.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder()
436 .setCLabeledUnicastDestination(Lists.newArrayList(lu2)).build()).build()).build());
437 final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
440 final MpUnreachNlriBuilder testBuilder = new MpUnreachNlriBuilder();
441 testBuilder.setAfi(Ipv6AddressFamily.class);
442 testBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
443 parser.parseNlri(Unpooled.copiedBuffer(LU_UNREACH_NLRI_IPv6), testBuilder);
444 Assert.assertEquals(mpUnreachExpected1, testBuilder.build());
447 final ByteBuf output = Unpooled.buffer();
448 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
449 new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()).build(), output);
450 Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv6, ByteArray.readAllBytes(output));
452 final ByteBuf output1 = Unpooled.buffer();
453 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
454 new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build()).build(), output1);
455 Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv6, ByteArray.readAllBytes(output1));
459 public void testMpUnreachNlriIpv6Constraint() throws BGPParsingException {
460 final LUNlriParser parser = new LUNlriParser();
461 final MpUnreachNlriBuilder mpBuilder = new MpUnreachNlriBuilder();
462 mpBuilder.setAfi(Ipv6AddressFamily.class);
463 mpBuilder.setSafi(LabeledUnicastSubsequentAddressFamily.class);
465 final CLabeledUnicastDestination lu1 = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPv6_PREFIX).build();
466 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
467 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach
468 .nlri.withdrawn.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
469 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp
470 .unreach.nlri.withdrawn.routes.destination.type.destination.ipv6.labeled.unicast._case.DestinationIpv6LabeledUnicastBuilder()
471 .setCLabeledUnicastDestination(Lists.newArrayList(lu1)).build()).build()).build());
472 final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
474 final CLabeledUnicastDestination lu2 = new CLabeledUnicastDestinationBuilder().setPathId(PATH_ID).setPrefix(IPv6_PREFIX).setLabelStack
475 (LABEL_STACK).build();
476 mpBuilder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
477 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp.unreach
478 .nlri.withdrawn.routes.destination.type.DestinationIpv6LabeledUnicastCaseBuilder().setDestinationIpv6LabeledUnicast(
479 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev150525.update.attributes.mp
480 .unreach.nlri.withdrawn.routes.destination.type.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_ADD_PATH), testBuilder, this.constraint);
489 Assert.assertEquals(mpUnreachExpected1, testBuilder.build());
492 final ByteBuf output = Unpooled.buffer();
493 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
494 new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build()).build(), output);
495 Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv6_ADD_PATH, ByteArray.readAllBytes(output));
497 final ByteBuf output1 = Unpooled.buffer();
498 parser.serializeAttribute(new AttributesBuilder().addAugmentation(Attributes2.class,
499 new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build()).build(), output1);
500 Assert.assertArrayEquals(LU_UNREACH_NLRI_IPv6_ADD_PATH, ByteArray.readAllBytes(output1));