Code Clean Up
[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 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;
52
53 public class LUNlriParserTest {
54
55     /*label stacks with multiple labels.
56      *
57      * label stack:
58      * 60       <- length 96
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
64      * 1        <- bottomBit 1
65      * 22 01 16 <- prefixType IPV4=34.1.22.0/24
66      */
67     private static final byte[] LU_REACH_NLRI_IPv4 = new byte[]{
68         (byte) 0x60,
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,
73     };
74
75     /*label value for withdraw message.
76     *
77     * label stack:
78     * 30       <- length 48
79     * 80 00 00 <- labelValue for withdraw
80     * 22 01 16 <- prefixType IPV4=34.1.22.0/24
81     */
82    private static final byte[] LU_UNREACH_NLRI_IPv4 = new byte[] {
83        (byte) 0x30,
84        (byte) 0x80, (byte) 0x00, (byte) 0x00,
85        (byte) 0x22, (byte) 0x01, (byte) 0x16,
86    };
87
88     /*label stacks with multiple labels.
89     *
90     * label stack:
91     * 1        <- Path Id
92     * 60       <- length 96
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
98     * 1        <- bottomBit 1
99     * 22 01 16 <- prefixType IPV4=34.1.22.0/24
100     */
101     private static final byte[] LU_REACH_NLRI_IPv4_ADD_PATH = new byte[]{
102         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
103         (byte) 0x60,
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,
108     };
109
110     /*label value for withdraw message.
111     *
112     * label stack:
113     * 1        <- Path Id
114     * 30       <- length 48
115     * 80 00 00 <- labelValue for withdraw
116     * 22 01 16 <- prefixType IPV4=34.1.22.0/24
117     */
118     private static final byte[] LU_UNREACH_NLRI_IPv4_ADD_PATH = new byte[] {
119         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
120         (byte) 0x30,
121         (byte) 0x80, (byte) 0x00, (byte) 0x00,
122         (byte) 0x22, (byte) 0x01, (byte) 0x16,
123     };
124
125     /*label stacks with multiple labels.
126      *
127      * label stack:
128      * C8       <- length 200
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
134      * 1        <- bottomBit 1
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
136      */
137     private static final byte[] LU_REACH_NLRI_IPv6 = new byte[]{
138         (byte) 0xC8,
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,
146     };
147
148     /*label value for withdraw message.
149     *
150     * label stack:
151     * 98       <- length 152
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
154     */
155    private static final byte[] LU_UNREACH_NLRI_IPv6 = new byte[] {
156        (byte) 0x98,
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,
162    };
163
164     /*label stacks with multiple labels.
165      *
166      * label stack:
167      * C8       <- length 200
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
173      * 1        <- bottomBit 1
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
175      */
176     private static final byte[] LU_REACH_NLRI_IPv6_ADD_PATH = new byte[]{
177         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
178         (byte) 0xC8,
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,
186     };
187
188     /*label value for withdraw message.
189     *
190     * label stack:
191     * 98       <- length 152
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
194     */
195    private static final byte[] LU_UNREACH_NLRI_IPv6_ADD_PATH = new byte[] {
196        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
197        (byte) 0x98,
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,
203    };
204
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());
209
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);
213
214     @Mock
215     private PeerSpecificParserConstraint constraint;
216     @Mock
217     private MultiPathSupport muliPathSupport;
218
219
220     @Before
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());
225     }
226
227     @Test
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();
238
239         //test parser
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());
245
246         //test serializer
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));
251     }
252
253     @Test
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();
265
266         //test parser
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());
272
273         //test serializer
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));
278     }
279
280     @Test
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);
286
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())
291                 .build()).build());
292         final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
293
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())
298                 .build()).build());
299         final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
300
301         //test parser
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());
307
308         //test serializer
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));
313
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));
318     }
319
320     @Test
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);
326
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())
331                 .build()).build());
332         final MpUnreachNlri mpUnreachExpected1 = mpBuilder.build();
333
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())
338                 .build()).build());
339         final MpUnreachNlri mpUnreachExpected2 = mpBuilder.build();
340
341         //test parser
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());
347
348         //test serializer
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));
353
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));
358     }
359
360     @Test
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())
369             .build()).build());
370         final MpReachNlri mpReachExpected = mpBuilder.build();
371
372         //test parser
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());
378
379         //test serializer
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));
384     }
385
386     @Test
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())
396                 .build())
397             .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_ADD_PATH), testBuilder, this.constraint);
405         Assert.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         Assert.assertArrayEquals(LU_REACH_NLRI_IPv6_ADD_PATH, ByteArray.readAllBytes(output));
412     }
413
414     @Test
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);
420
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();
429
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();
438
439         //test parser
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());
445
446         //test serializer
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));
451
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));
456     }
457
458     @Test
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);
464
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();
473
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();
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_ADD_PATH), testBuilder, this.constraint);
489         Assert.assertEquals(mpUnreachExpected1, testBuilder.build());
490
491         //test serializer
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));
496
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));
501     }
502 }