Provide Add Path support for all AFI/SAFI
[bgpcep.git] / bgp / 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.rev171207.PathId;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.AttributesBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes1Builder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes2;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.Attributes2Builder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlri;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpReachNlriBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpUnreachNlri;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.MpUnreachNlriBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel;
54
55 public class LUNlriParserTest {
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     /*label value for withdraw message.
78     *
79     * label stack:
80     * 30       <- length 48
81     * 80 00 00 <- labelValue for withdraw
82     * 22 01 16 <- prefixType IPV4=34.1.22.0/24
83     */
84    private static final byte[] LU_UNREACH_NLRI_IPv4 = new byte[] {
85        (byte) 0x30,
86        (byte) 0x80, (byte) 0x00, (byte) 0x00,
87        (byte) 0x22, (byte) 0x01, (byte) 0x16,
88    };
89
90     /*label stacks with multiple labels.
91     *
92     * label stack:
93     * 1        <- Path Id
94     * 60       <- length 96
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
100     * 1        <- bottomBit 1
101     * 22 01 16 <- prefixType IPV4=34.1.22.0/24
102     */
103     private static final byte[] LU_REACH_NLRI_IPv4_ADD_PATH = new byte[]{
104         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
105         (byte) 0x60,
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,
110     };
111
112     /*label value for withdraw message.
113     *
114     * label stack:
115     * 1        <- Path Id
116     * 30       <- length 48
117     * 80 00 00 <- labelValue for withdraw
118     * 22 01 16 <- prefixType IPV4=34.1.22.0/24
119     */
120     private static final byte[] LU_UNREACH_NLRI_IPv4_ADD_PATH = new byte[] {
121         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
122         (byte) 0x30,
123         (byte) 0x80, (byte) 0x00, (byte) 0x00,
124         (byte) 0x22, (byte) 0x01, (byte) 0x16,
125     };
126
127     /*label stacks with multiple labels.
128      *
129      * label stack:
130      * C8       <- length 200
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
136      * 1        <- bottomBit 1
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
138      */
139     private static final byte[] LU_REACH_NLRI_IPv6 = new byte[]{
140         (byte) 0xC8,
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,
148     };
149
150     /*label value for withdraw message.
151     *
152     * label stack:
153     * 98       <- length 152
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
156     */
157    private static final byte[] LU_UNREACH_NLRI_IPv6 = new byte[] {
158        (byte) 0x98,
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,
164    };
165
166     /*label stacks with multiple labels.
167      *
168      * label stack:
169      * C8       <- length 200
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
175      * 1        <- bottomBit 1
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
177      */
178     private static final byte[] LU_REACH_NLRI_IPv6_ADD_PATH = new byte[]{
179         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
180         (byte) 0xC8,
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,
188     };
189
190     /*label value for withdraw message.
191     *
192     * label stack:
193     * 98       <- length 152
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
196     */
197    private static final byte[] LU_UNREACH_NLRI_IPv6_ADD_PATH = new byte[] {
198        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
199        (byte) 0x98,
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,
205    };
206
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());
211
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);
215
216     @Mock
217     private PeerSpecificParserConstraint constraint;
218     @Mock
219     private MultiPathSupport muliPathSupport;
220
221
222     @Before
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());
227     }
228
229     @Test
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())
240                 .build()).build());
241         final MpReachNlri mpReachExpected = mpBuilder.build();
242
243         //test parser
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);
248         assertEquals(mpReachExpected, testBuilder.build());
249
250         //test serializer
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));
255     }
256
257     @Test
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();
271
272         //test parser
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());
278
279         //test serializer
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));
284     }
285
286     @Test
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);
292
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())
301                 .build()).build());
302         final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
303
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())
313                 .build()).build());
314         final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
315
316         //test parser
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);
321         assertEquals(mpUnreachExpected1, testBuilder.build());
322
323         //test serializer
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));
328
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));
333     }
334
335     @Test
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);
341
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())
351                 .build()).build());
352         final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
353
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())
363                 .build()).build());
364         final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
365
366         //test parser
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());
372
373         //test serializer
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));
378
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));
383     }
384
385     @Test
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())
397             .build()).build());
398         final MpReachNlri mpReachExpected = mpBuilder.build();
399
400         //test parser
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);
405         assertEquals(mpReachExpected, testBuilder.build());
406
407         //test serializer
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));
412     }
413
414     @Test
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())
426             .build());
427         final MpReachNlri mpReachExpected = mpBuilder.build();
428
429         //test parser
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());
435
436         //test serializer
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));
441     }
442
443     @Test
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);
449
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();
459
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();
470
471         //test parser
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);
476         assertEquals(mpUnreachExpected1, testBuilder.build());
477
478         //test serializer
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));
483
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));
488     }
489
490     @Test
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);
496
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();
507
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();
519
520         //test parser
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());
526
527         //test serializer
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));
532
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));
537     }
538 }