2 * Copyright (c) 2016 Brocade Communications Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.bgp.l3vpn.unicast.ipv6;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
16 import java.net.Inet6Address;
17 import org.junit.Test;
18 import org.opendaylight.bgp.concepts.RouteDistinguisherUtil;
19 import org.opendaylight.protocol.util.ByteArray;
20 import org.opendaylight.protocol.util.Ipv6Util;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.CNextHop;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv6NextHopCase;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv6NextHopCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.ipv6.next.hop._case.Ipv6NextHopBuilder;
27 public class VpnIpv6NextHopTest {
29 private static final VpnIpv6NextHopParserSerializer HANDLER = new VpnIpv6NextHopParserSerializer();
32 public void testSerializeIpv6NextHopCase() throws Exception {
33 final String TEST_IPV6 = "2001::1234:5678:90ab:cdef"; // put some random valid IPv6 address here
35 final ByteBuf buffer = Unpooled.buffer();
36 final byte[] nextHop = new byte[Ipv6Util.IPV6_LENGTH + RouteDistinguisherUtil.RD_LENGTH];
37 // now copy the IPv6 address to the byte array
38 System.arraycopy(Inet6Address.getByName(TEST_IPV6).getAddress(), 0, nextHop,
39 RouteDistinguisherUtil.RD_LENGTH, Ipv6Util.IPV6_LENGTH);
40 final CNextHop hop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder()
41 .setGlobal(new Ipv6Address(TEST_IPV6)).build()).build();
43 HANDLER.serializeNextHop(hop, buffer);
44 assertArrayEquals(nextHop, ByteArray.readAllBytes(buffer));
46 final CNextHop parsedHop = HANDLER.parseNextHop(Unpooled.wrappedBuffer(nextHop));
47 assertTrue(hop instanceof Ipv6NextHopCase);
48 assertEquals(hop, parsedHop);