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