Cleanup deprecation warnings in bgp/extensions/labeled-unicast
[bgpcep.git] / bgp / extensions / labeled-unicast / src / test / java / org / opendaylight / protocol / bgp / labeled / unicast / LUNlriParserTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.labeled.unicast;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12
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;
53
54 public class LUNlriParserTest {
55
56     /*
57      * label stacks with multiple labels.
58      *
59      * label stack:
60      * 60       <- length 96
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
66      * 1        <- bottomBit 1
67      * 22 01 16 <- prefixType IPV4=34.1.22.0/24
68      */
69     private static final byte[] LU_REACH_NLRI_IPV4 = new byte[]{
70         (byte) 0x60,
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,
75     };
76
77     /*
78      * label value for withdraw message.
79      *
80      * label stack:
81      * 30       <- length 48
82      * 80 00 00 <- labelValue for withdraw
83      * 22 01 16 <- prefixType IPV4=34.1.22.0/24
84      */
85     private static final byte[] LU_UNREACH_NLRI_IPV4 = new byte[] {
86         (byte) 0x30,
87         (byte) 0x80, (byte) 0x00, (byte) 0x00,
88         (byte) 0x22, (byte) 0x01, (byte) 0x16,
89     };
90
91     /*
92      * label stacks with multiple labels.
93      *
94      * label stack:
95      * 1        <- Path Id
96      * 60       <- length 96
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
102      * 1        <- bottomBit 1
103      * 22 01 16 <- prefixType IPV4=34.1.22.0/24
104      */
105     private static final byte[] LU_REACH_NLRI_IPV4_ADD_PATH = new byte[]{
106         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
107         (byte) 0x60,
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,
112     };
113
114     /*
115      * label value for withdraw message.
116      *
117      * label stack:
118      * 1        <- Path Id
119      * 30       <- length 48
120      * 80 00 00 <- labelValue for withdraw
121      * 22 01 16 <- prefixType IPV4=34.1.22.0/24
122      */
123     private static final byte[] LU_UNREACH_NLRI_IPV4_ADD_PATH = new byte[] {
124         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
125         (byte) 0x30,
126         (byte) 0x80, (byte) 0x00, (byte) 0x00,
127         (byte) 0x22, (byte) 0x01, (byte) 0x16,
128     };
129
130     /*
131      * label stacks with multiple labels.
132      *
133      * label stack:
134      * C8       <- length 200
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
140      * 1        <- bottomBit 1
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
142      */
143     private static final byte[] LU_REACH_NLRI_IPV6 = new byte[]{
144         (byte) 0xC8,
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,
152     };
153
154     /*
155      * label value for withdraw message.
156      *
157      * label stack:
158      * 98       <- length 152
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
161      */
162     private static final byte[] LU_UNREACH_NLRI_IPV6 = new byte[] {
163         (byte) 0x98,
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,
169     };
170
171     /*
172      * label stacks with multiple labels.
173      *
174      * label stack:
175      * C8       <- length 200
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
181      * 1        <- bottomBit 1
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
183      */
184     private static final byte[] LU_REACH_NLRI_IPV6_ADD_PATH = new byte[]{
185         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
186         (byte) 0xC8,
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,
194     };
195
196     /*
197      * label value for withdraw message.
198      *
199      * label stack:
200      * 98       <- length 152
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
203      */
204     private static final byte[] LU_UNREACH_NLRI_IPV6_ADD_PATH = new byte[] {
205         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
206         (byte) 0x98,
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,
212     };
213
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());
218
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);
222
223     @Mock
224     private PeerSpecificParserConstraint constraint;
225     @Mock
226     private MultiPathSupport muliPathSupport;
227
228     @Before
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());
233     }
234
235     @Test
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())
246                 .build()).build());
247         final MpReachNlri mpReachExpected = mpBuilder.build();
248
249         //test parser
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());
255
256         //test serializer
257         final ByteBuf output = Unpooled.buffer();
258         parser.serializeAttribute(new AttributesBuilder()
259             .addAugmentation(new Attributes1Builder().setMpReachNlri(mpReachExpected).build())
260             .build(), output);
261         assertArrayEquals(LU_REACH_NLRI_IPV4, ByteArray.readAllBytes(output));
262     }
263
264     @Test
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();
277
278         //test parser
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());
284
285         //test serializer
286         final ByteBuf output = Unpooled.buffer();
287         parser.serializeAttribute(new AttributesBuilder()
288             .addAugmentation(new Attributes1Builder().setMpReachNlri(mpReachExpected).build())
289             .build(), output);
290         assertArrayEquals(LU_REACH_NLRI_IPV4_ADD_PATH, ByteArray.readAllBytes(output));
291     }
292
293     @Test
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);
299
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())
308                 .build()).build());
309         final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
310
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())
320                 .build()).build());
321         final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
322
323         //test parser
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());
329
330         //test serializer
331         final ByteBuf output = Unpooled.buffer();
332         parser.serializeAttribute(new AttributesBuilder()
333             .addAugmentation(new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build())
334             .build(), output);
335         assertArrayEquals(LU_UNREACH_NLRI_IPV4, ByteArray.readAllBytes(output));
336
337         final ByteBuf output1 = Unpooled.buffer();
338         parser.serializeAttribute(new AttributesBuilder()
339             .addAugmentation(new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build())
340             .build(), output1);
341         assertArrayEquals(LU_UNREACH_NLRI_IPV4, ByteArray.readAllBytes(output1));
342     }
343
344     @Test
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);
350
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())
360                 .build()).build());
361         final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
362
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())
372                 .build()).build());
373         final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
374
375         //test parser
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());
381
382         //test serializer
383         final ByteBuf output = Unpooled.buffer();
384         parser.serializeAttribute(new AttributesBuilder()
385             .addAugmentation(new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build())
386             .build(), output);
387         assertArrayEquals(LU_UNREACH_NLRI_IPV4_ADD_PATH, ByteArray.readAllBytes(output));
388
389         final ByteBuf output1 = Unpooled.buffer();
390         parser.serializeAttribute(new AttributesBuilder()
391             .addAugmentation(new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build())
392             .build(), output1);
393         assertArrayEquals(LU_UNREACH_NLRI_IPV4_ADD_PATH, ByteArray.readAllBytes(output1));
394     }
395
396     @Test
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())
408             .build()).build());
409         final MpReachNlri mpReachExpected = mpBuilder.build();
410
411         //test parser
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());
417
418         //test serializer
419         final ByteBuf output = Unpooled.buffer();
420         parser.serializeAttribute(new AttributesBuilder()
421             .addAugmentation(new Attributes1Builder().setMpReachNlri(mpReachExpected).build())
422             .build(), output);
423         assertArrayEquals(LU_REACH_NLRI_IPV6, ByteArray.readAllBytes(output));
424     }
425
426     @Test
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())
438             .build());
439         final MpReachNlri mpReachExpected = mpBuilder.build();
440
441         //test parser
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());
447
448         //test serializer
449         final ByteBuf output = Unpooled.buffer();
450         parser.serializeAttribute(new AttributesBuilder()
451             .addAugmentation(new Attributes1Builder().setMpReachNlri(mpReachExpected).build())
452             .build(), output);
453         assertArrayEquals(LU_REACH_NLRI_IPV6_ADD_PATH, ByteArray.readAllBytes(output));
454     }
455
456     @Test
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);
462
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();
472
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();
483
484         //test parser
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());
490
491         //test serializer
492         final ByteBuf output = Unpooled.buffer();
493         parser.serializeAttribute(new AttributesBuilder()
494             .addAugmentation(new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build())
495             .build(), output);
496         assertArrayEquals(LU_UNREACH_NLRI_IPV6, ByteArray.readAllBytes(output));
497
498         final ByteBuf output1 = Unpooled.buffer();
499         parser.serializeAttribute(new AttributesBuilder()
500             .addAugmentation(new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build())
501             .build(), output1);
502         assertArrayEquals(LU_UNREACH_NLRI_IPV6, ByteArray.readAllBytes(output1));
503     }
504
505     @Test
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);
511
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();
522
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();
534
535         //test parser
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());
541
542         //test serializer
543         final ByteBuf output = Unpooled.buffer();
544         parser.serializeAttribute(new AttributesBuilder()
545             .addAugmentation(new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected2).build())
546             .build(), output);
547         assertArrayEquals(LU_UNREACH_NLRI_IPV6_ADD_PATH, ByteArray.readAllBytes(output));
548
549         final ByteBuf output1 = Unpooled.buffer();
550         parser.serializeAttribute(new AttributesBuilder()
551             .addAugmentation(new Attributes2Builder().setMpUnreachNlri(mpUnreachExpected1).build())
552             .build(), output1);
553         assertArrayEquals(LU_UNREACH_NLRI_IPV6_ADD_PATH, ByteArray.readAllBytes(output1));
554     }
555 }