2 * Copyright (c) 2015 Cisco Systems, Inc. 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.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
13 import java.nio.ByteBuffer;
14 import org.junit.Test;
15 import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
16 import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext;
17 import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
18 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
19 import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ServicePathLcaf;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ServicePath;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
25 * Test class for Service Path Serializer.
27 * @author Lorand Jakab
29 public class ServicePathTest extends BaseTestCase {
32 public void deserialize__Simple() throws Exception {
33 Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 "
36 new LispAddressSerializerContext(null));
37 assertEquals(ServicePathLcaf.VALUE, address.getAddressType());
38 ServicePath sp = (ServicePath) address.getAddress();
40 assertEquals(ByteUtil.getPartialInt(new byte[] { (byte) 0xAA, (byte) 0xBB, (byte) 0xCC }),
41 sp.getServicePath().getServicePathId().getValue().intValue());
42 assertEquals((byte) 0xFF, sp.getServicePath().getServiceIndex().byteValue());
46 public void serialize__Simple() throws Exception {
47 Eid eid = LispAddressUtil.asServicePathEid(-1, 1L, (short) 0xFF);
49 ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(eid));
50 LispAddressSerializer.getInstance().serialize(buf, eid);
51 ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 "
54 assertArrayEquals(expectedBuf.array(), buf.array());