YANG revision dates mass-update
[bgpcep.git] / bgp / extensions / l3vpn / src / test / java / org / opendaylight / protocol / bgp / l3vpn / mcast / nlri / L3vpnMcastNlriSerializerTest.java
1 /*
2  * Copyright (c) 2018 AT&T Intellectual Property. 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
9 package org.opendaylight.protocol.bgp.l3vpn.mcast.nlri;
10
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
13
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
16 import java.util.Arrays;
17 import java.util.Collection;
18 import java.util.Collections;
19 import java.util.List;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.junit.runners.Parameterized;
23 import org.opendaylight.protocol.util.ByteArray;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.destination.L3vpnMcastDestination;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.l3vpn.mcast.rev180417.l3vpn.mcast.destination.L3vpnMcastDestinationBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RdIpv4;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.RouteDistinguisher;
31
32 @RunWith(Parameterized.class)
33 public class L3vpnMcastNlriSerializerTest {
34     private static final byte[] IPV4_EXPECTED = new byte[]{
35         32, //length
36         0, 1, 1, 2, 3, 4, 1, 2, //RD
37         24, (byte) 0xac, 17, 1, 0,// Prefix
38         0, 0, 0//trailing bits
39     };
40     private static final byte[] IPV6_EXPECTED = new byte[]{
41         (byte) 0x80, //length
42         0, 1, 1, 2, 3, 4, 1, 2, //RD
43         64, 32, 1, 13, (byte) 0xb8, 0, 1, 0, 2,// Prefix
44         0, 0, 0, 0, 0, 0, 0 //trailing bits
45     };
46     private static final RouteDistinguisher RD = new RouteDistinguisher(new RdIpv4("1.2.3.4:258"));
47     private static final IpPrefix IPV6_PREFIX = new IpPrefix(new Ipv6Prefix("2001:db8:1:2::/64"));
48     private static final IpPrefix IPV4_PREFIX = new IpPrefix(new Ipv4Prefix("172.17.1.0/24"));
49     private static final L3vpnMcastDestination MCAST_IPV4_L3VPN_DESTINATION = new L3vpnMcastDestinationBuilder()
50             .setRouteDistinguisher(RD)
51             .setPrefix(IPV4_PREFIX)
52             .build();
53     private static final L3vpnMcastDestination MCAST_IPV6_L3VPN_DESTINATION = new L3vpnMcastDestinationBuilder()
54             .setRouteDistinguisher(RD)
55             .setPrefix(IPV6_PREFIX)
56             .build();
57     private final byte[] expectedArray;
58     private final List<L3vpnMcastDestination> destination;
59
60     public L3vpnMcastNlriSerializerTest(final byte[] expectedArray, final List<L3vpnMcastDestination> destination) {
61         this.expectedArray = expectedArray;
62         this.destination = destination;
63     }
64
65     @Parameterized.Parameters
66     public static Collection<Object[]> data() {
67         return Arrays.asList(new Object[][]{
68                 {IPV4_EXPECTED, Collections.singletonList(MCAST_IPV4_L3VPN_DESTINATION)},
69                 {IPV6_EXPECTED, Collections.singletonList(MCAST_IPV6_L3VPN_DESTINATION)},
70         });
71     }
72
73     @Test
74     public void testL3vpnMcastNlriSerializer() {
75         ByteBuf actual = Unpooled.buffer();
76         L3vpnMcastNlriSerializer.serializeNlri(this.destination, actual);
77         assertArrayEquals(this.expectedArray, ByteArray.getAllBytes(actual));
78         assertEquals(this.destination,
79                 L3vpnMcastNlriSerializer.extractDest(Unpooled.copiedBuffer(this.expectedArray), false));
80     }
81 }