--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.lispflowmapping.lisp.serializer.address;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.lisp.type.LispCanonicalAddressFormatEnum;
+import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
+import org.opendaylight.lispflowmapping.lisp.util.NumberUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana.afn.safi.rev130704.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ServicePathIdType;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ServicePathLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ServicePath;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.service.path.ServicePathBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
+
+/**
+ * @author Lorand Jakab
+ *
+ */
+public class ServicePathSerializer extends LcafSerializer {
+
+ private static final ServicePathSerializer INSTANCE = new ServicePathSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private ServicePathSerializer() {
+ }
+
+ public static ServicePathSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ protected byte getLcafType() {
+ return LispCanonicalAddressFormatEnum.SERVICE_PATH.getLispCode();
+ }
+
+ @Override
+ protected short getLcafLength(LispAddress lispAddress) {
+ return (short) (Length.SPI + Length.SI);
+ }
+
+ @Override
+ protected short getAfi() {
+ return (short) AddressFamily.LispCanonicalAddressFormat.getIntValue();
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ ServicePath sp = (ServicePath) lispAddress.getAddress();
+ buffer.put(ByteUtil.partialIntToByteArray(NumberUtil.asInt(
+ sp.getServicePath().getServicePathId().getValue().intValue()), Length.SPI));
+ buffer.put((byte) NumberUtil.asShort(sp.getServicePath().getServiceIndex()));
+ }
+
+ @Override
+ protected Eid deserializeLcafEidData(ByteBuffer buffer, byte res2, short length, LispAddressSerializerContext ctx) {
+ EidBuilder eb = new EidBuilder();
+ eb.setAddressType(ServicePathLcaf.class);
+ eb.setVirtualNetworkId(getVni(ctx));
+ eb.setAddress(deserializeData(buffer));
+ return eb.build();
+ }
+
+ private Address deserializeData(ByteBuffer buffer) {
+ ServicePathBuilder spb = new ServicePathBuilder();
+ byte[] spi = new byte[3];
+ buffer.get(spi);
+ spb.setServicePathId(new ServicePathIdType((long) ByteUtil.getPartialInt(spi)));
+ spb.setServiceIndex((short) ByteUtil.getUnsignedByte(buffer));
+ return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ServicePathBuilder()
+ .setServicePath(spb.build()).build();
+ }
+
+ private interface Length {
+ int SPI = 3;
+ int SI = 1;
+ }
+}
import org.opendaylight.lispflowmapping.lisp.serializer.address.Ipv4Serializer;
import org.opendaylight.lispflowmapping.lisp.serializer.address.MacSerializer;
import org.opendaylight.lispflowmapping.lisp.serializer.address.NoAddressSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.ServicePathSerializer;
import org.opendaylight.lispflowmapping.lisp.serializer.address.SourceDestKeySerializer;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.AfiListLcaf;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ApplicationDataLcaf;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddressFamily;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.NoAddressAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ServicePathLcaf;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SourceDestKeyLcaf;
/**
addressTypeToSerializerMap.put(ExplicitLocatorPathLcaf.class, ExplicitLocatorPathSerializer.getInstance());
addressTypeToSerializerMap.put(SourceDestKeyLcaf.class, SourceDestKeySerializer.getInstance());
addressTypeToSerializerMap.put(KeyValueAddressLcaf.class, KeyValueAddressSerializer.getInstance());
+ addressTypeToSerializerMap.put(ServicePathLcaf.class, ServicePathSerializer.getInstance());
}
public static LispAddressSerializer getSerializer(Class<? extends LispAddressFamily> clazz) {
SOURCE_DEST(12), //
TRAFFIC_ENGINEERING(10), //
KEY_VALUE(15), //
+ SERVICE_PATH(17),
UNKNOWN(-1);
private byte lispCode;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddressFamily;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.NoAddressAfi;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ServicePathLcaf;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SourceDestKeyLcaf;
SourceDestKeyLcaf.class);
lcafToAddressTypeMap.put((short) LispCanonicalAddressFormatEnum.KEY_VALUE.getLispCode(),
KeyValueAddressLcaf.class);
+ lcafToAddressTypeMap.put((short) LispCanonicalAddressFormatEnum.SERVICE_PATH.getLispCode(),
+ ServicePathLcaf.class);
// TODO
}
public static Eid asServicePathEid(long vni, long servicePathId, short serviceIndex) {
EidBuilder eb = new EidBuilder();
eb.setAddressType(ServicePathLcaf.class);
- eb.setVirtualNetworkId(new InstanceIdType(vni));
+ if (vni >= 0) {
+ eb.setVirtualNetworkId(new InstanceIdType(vni));
+ }
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.service.path.ServicePathBuilder spb = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.service.path.ServicePathBuilder();
spb.setServicePathId(new ServicePathIdType(servicePathId));
spb.setServiceIndex(serviceIndex);
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.lispflowmapping.serializer.address;
+
+import static org.junit.Assert.assertEquals;
+
+import java.nio.ByteBuffer;
+
+import junitx.framework.ArrayAssert;
+
+import org.junit.Test;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext;
+import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
+import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
+import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.ServicePathLcaf;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ServicePath;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+
+/**
+ * @author Lorand Jakab
+ *
+ */
+public class ServicePathTest extends BaseTestCase {
+
+ @Test
+ public void deserialize__Simple() throws Exception {
+ Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 " +
+ "11 00 00 04 " +
+ "AA BB CC FF"),
+ new LispAddressSerializerContext(null));
+ assertEquals(ServicePathLcaf.class, address.getAddressType());
+ ServicePath sp = (ServicePath) address.getAddress();
+
+ assertEquals(ByteUtil.getPartialInt(new byte[] { (byte) 0xAA, (byte) 0xBB, (byte) 0xCC }),
+ sp.getServicePath().getServicePathId().getValue().intValue());
+ assertEquals((byte) 0xFF, sp.getServicePath().getServiceIndex().byteValue());
+ }
+
+ @Test
+ public void serialize__Simple() throws Exception {
+ Eid eid = LispAddressUtil.asServicePathEid(-1, 1L, (short) 0xFF);
+
+ ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(eid));
+ LispAddressSerializer.getInstance().serialize(buf, eid);
+ ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " +
+ "11 00 00 04 " +
+ "00 00 01 FF");
+ ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
+ }
+}