Create common parent for extensions families
[bgpcep.git] / bgp / extensions / l3vpn / src / test / java / org / opendaylight / protocol / bgp / l3vpn / unicast / ipv4 / VpnIpv4NextHopTest.java
1 /*
2  * Copyright (c) 2016 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.l3vpn.unicast.ipv4;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
16 import org.junit.Test;
17 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
18 import org.opendaylight.protocol.util.ByteArray;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.CNextHop;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
24
25 public class VpnIpv4NextHopTest {
26
27     private static final VpnIpv4NextHopParserSerializer HANDLER = new VpnIpv4NextHopParserSerializer();
28
29     @Test
30     public void testSerializeIpv4NextHopCase() throws BGPParsingException {
31         final ByteBuf buffer = Unpooled.buffer();
32         final byte[] nextHop = {0, 0, 0, 0, 0, 0, 0, 0, 42, 42, 42, 42};
33         final CNextHop hop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder()
34                 .setGlobal(new Ipv4Address("42.42.42.42")).build()).build();
35
36         HANDLER.serializeNextHop(hop, buffer);
37         assertArrayEquals(nextHop, ByteArray.readAllBytes(buffer));
38
39         final CNextHop parsedHop = HANDLER.parseNextHop(Unpooled.wrappedBuffer(nextHop));
40         assertTrue(hop instanceof Ipv4NextHopCase);
41         assertEquals(hop, parsedHop);
42     }
43 }