2 * Copyright (c) 2014 Contextream, 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.lispflowmapping.serializer.address;
10 import static org.junit.Assert.assertEquals;
12 import java.nio.ByteBuffer;
14 import junitx.framework.ArrayAssert;
16 import org.junit.Test;
17 import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
18 import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext;
19 import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
20 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
21 import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
27 public class InstanceIdSerializerTest extends BaseTestCase {
30 public void deserialize__Simple() throws Exception {
31 Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
33 "00 BB CC DD " + // instance ID
34 "00 01 11 22 33 44"), // AFI=1, IP=0x11223344
35 new LispAddressSerializerContext(null));
37 assertEquals(Ipv4Afi.class, address.getAddressType());
38 Ipv4 ipv4 = (Ipv4) address.getAddress();
40 assertEquals("17.34.51.68", ipv4.getIpv4().getValue());
41 assertEquals(0x00BBCCDD, address.getVirtualNetworkId().getValue().longValue());
44 @Test(expected = LispSerializationException.class)
45 public void deserialize__ShorterBuffer() throws Exception {
46 LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
49 new LispAddressSerializerContext(null));
52 @Test(expected = LispSerializationException.class)
53 public void deserialize__UnknownLCAFType() throws Exception {
54 LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
55 "AA 20 00 0A " + // Type AA is unknown
56 "00 BB CC DD " + // instance ID
57 "00 01 11 22 33 44"), // AFI=1, IP=0x11223344
58 new LispAddressSerializerContext(null));
61 @Test(expected = LispSerializationException.class)
62 public void deserialize__LongInstanceID() throws Exception {
63 LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
64 "02 20 00 0A " + // Type AA is unknown
65 "AA BB CC DD " + // instance ID
66 "00 01 11 22 33 44"), // AFI=1, IP=0x11223344
67 new LispAddressSerializerContext(null));
71 public void deserialize__Ipv6() throws Exception {
72 Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " + //
74 "00 BB CC DD " + // instance ID
75 "00 02 11 22 33 44 55 66 77 88 99 AA BB CC AA BB CC DD"), // AFI=2,
76 new LispAddressSerializerContext(null));
79 assertEquals("1122:3344:5566:7788:99aa:bbcc:aabb:ccdd", ((Ipv6) address.getAddress()).getIpv6().getValue());
84 public void serialize__Simple() throws Exception {
85 Eid eid = LispAddressUtil.asIpv4Eid("17.34.51.68", (long) 0x00020304);
87 ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(eid));
88 LispAddressSerializer.getInstance().serialize(buf, eid);
89 ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
91 "00 02 03 04 " + // instance ID
93 ArrayAssert.assertEquals(expectedBuf.array(), buf.array());