import org.opendaylight.lispflowmapping.type.lisp.address.LispListLCAFAddress;
import org.opendaylight.lispflowmapping.type.lisp.address.LispSegmentLCAFAddress;
import org.opendaylight.lispflowmapping.type.lisp.address.LispSourceDestLCAFAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispTrafficEngineeringLCAFAddress;
public enum LispCanonicalAddressFormatEnum {
LIST(1, LispListLCAFAddress.class), //
SEGMENT(2, LispSegmentLCAFAddress.class), //
APPLICATION_DATA(4, LispApplicationDataLCAFAddress.class), //
SOURCE_DEST(12, LispSourceDestLCAFAddress.class), //
+ TRAFFIC_ENGINEERING(10, LispTrafficEngineeringLCAFAddress.class), //
UNKNOWN(-1, null);
private byte lispCode;
--- /dev/null
+package org.opendaylight.lispflowmapping.type.lisp.address;
+
+import java.util.List;
+
+import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
+
+public class LispTrafficEngineeringLCAFAddress extends LispLCAFAddress {
+
+ private List<ReencapHop> hops;
+
+ public LispTrafficEngineeringLCAFAddress(byte res2, List<ReencapHop> hops) {
+ super(LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING, res2);
+ this.hops = hops;
+ }
+
+ @Override
+ public String toString() {
+ return "LispTrafficEngineeringLCAFAddress#[hops=" + hops + "]" + super.toString();
+ }
+
+ public List<ReencapHop> getHops() {
+ return hops;
+ }
+
+ public void setHops(List<ReencapHop> hops) {
+ this.hops = hops;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Contextream, Inc. and others. 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.type.lisp.address;
+
+
+
+public class ReencapHop extends LispAddress{
+
+ private LispAddress hop;
+ private short resv3;
+ private boolean lookup;
+ private boolean RLOCProbe;
+ private boolean strict;
+
+ public ReencapHop(LispAddress hop, short resv3, boolean lookup, boolean RLOCProbe, boolean strict) {
+ super(hop.getAfi());
+ this.hop = hop;
+ this.resv3 = resv3;
+ this.lookup = lookup;
+ this.RLOCProbe = RLOCProbe;
+ this.strict = strict;
+ }
+
+ public LispAddress getHop() {
+ return hop;
+ }
+
+ public void setHop(LispAddress hop) {
+ this.hop = hop;
+ }
+
+ public short getResv3() {
+ return resv3;
+ }
+
+ public void setResv3(short resv3) {
+ this.resv3 = resv3;
+ }
+
+ public boolean isLookup() {
+ return lookup;
+ }
+
+ public void setLookup(boolean lookup) {
+ this.lookup = lookup;
+ }
+
+ public boolean isRLOCProbe() {
+ return RLOCProbe;
+ }
+
+ public void setRLOCProbe(boolean rLOCProbe) {
+ RLOCProbe = rLOCProbe;
+ }
+
+ public boolean isStrict() {
+ return strict;
+ }
+
+ public void setStrict(boolean strict) {
+ this.strict = strict;
+ }
+
+ @Override
+ public String toString() {
+ return "ReencapHop#[hop=" + hop + "]" + super.toString();
+ }
+
+
+
+
+}
import java.nio.ByteBuffer;
import org.opendaylight.lispflowmapping.implementation.serializer.address.LispAddressSerializer;
-import org.opendaylight.lispflowmapping.implementation.serializer.address.LispAddressSerializerFactory;
import org.opendaylight.lispflowmapping.implementation.util.ByteUtil;
import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
ByteUtil.boolToBit(record.isAuthoritative(), Flags.AUTHORITATIVE)));
replyBuffer.position(replyBuffer.position() + Length.RESERVED);
replyBuffer.putShort(record.getMapVersion());
- LispAddressSerializerFactory.getSerializer(record.getPrefix().getAfi()).serialize(replyBuffer, record.getPrefix());
+ LispAddressSerializer.getInstance().serialize(replyBuffer, record.getPrefix());
for (LocatorRecord locatorRecord : record.getLocators()) {
LocatorRecordSerializer.getInstance().serialize(replyBuffer, locatorRecord);
}
public int getSerializationSize(EidToLocatorRecord record) {
- int size = Length.HEADER_SIZE + LispAddressSerializerFactory.getSerializer(record.getPrefix().getAfi()).getAddressSize(record.getPrefix());
+ int size = Length.HEADER_SIZE + LispAddressSerializer.getInstance().getAddressSize(record.getPrefix());
for (LocatorRecord locatorRecord : record.getLocators()) {
size += LocatorRecordSerializer.getInstance().getSerializationSize(locatorRecord);
}
import java.nio.ByteBuffer;
import org.opendaylight.lispflowmapping.implementation.serializer.address.LispAddressSerializer;
-import org.opendaylight.lispflowmapping.implementation.serializer.address.LispAddressSerializerFactory;
import org.opendaylight.lispflowmapping.implementation.util.ByteUtil;
import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
replyBuffer.put((byte) (ByteUtil.boolToBit(record.isLocalLocator(), Flags.LOCAL_LOCATOR) | //
ByteUtil.boolToBit(record.isRlocProbed(), Flags.RLOC_PROBED) | //
ByteUtil.boolToBit(record.isRouted(), Flags.ROUTED)));
- LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(record.getLocator().getAfi());
- serializer.serialize(replyBuffer, record.getLocator());
+ LispAddressSerializer.getInstance().serialize(replyBuffer, record.getLocator());
}
public int getSerializationSize(LocatorRecord record) {
- LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(record.getLocator().getAfi());
- return Length.HEADER_SIZE + serializer.getAddressSize(record.getLocator());
+ return Length.HEADER_SIZE + LispAddressSerializer.getInstance().getAddressSize(record.getLocator());
}
private interface Flags {
+/*
+ * Copyright (c) 2013 Contextream, Inc. and others. 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.implementation.serializer.address;
import java.nio.ByteBuffer;
import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.factory.LispAFIAddressSerializerFactory;
import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
public static LispAddressSerializer getInstance() {
return INSTANCE;
}
+
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ throw new RuntimeException("UnImplemented");
+ }
+
+ protected LispAddress deserializeData(ByteBuffer buffer) {
+ throw new RuntimeException("UnImplemented");
+ }
public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
- throw new RuntimeException("Not implemented");
+ LispAddressSerializer serializer = LispAFIAddressSerializerFactory.getSerializer(lispAddress.getAfi());
+ if (serializer == null) {
+ throw new LispSerializationException("Unknown AFI type=" + lispAddress.getAfi());
+ }
+ serializeAFIAddressHeader(buffer, lispAddress);
+ serializer.serializeData(buffer, lispAddress);
}
- protected void internalSerialize(ByteBuffer buffer, LispAddress lispAddress) {
+ protected static void serializeAFIAddressHeader(ByteBuffer buffer, LispAddress lispAddress) {
buffer.putShort(lispAddress.getAfi().getIanaCode());
}
public int getAddressSize(LispAddress lispAddress) {
- return Length.AFI;
+ AddressFamilyNumberEnum afiType = lispAddress.getAfi();
+ LispAddressSerializer serializer = LispAFIAddressSerializerFactory.getSerializer(afiType);
+ if (serializer == null) {
+ throw new LispSerializationException("Unknown AFI type=" + afiType);
+ }
+ return Length.AFI + serializer.getAddressSize(lispAddress);
}
public LispAddress deserialize(ByteBuffer buffer) {
short afi = buffer.getShort();
AddressFamilyNumberEnum afiType = AddressFamilyNumberEnum.valueOf(afi);
- LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(afiType);
+ LispAddressSerializer serializer = LispAFIAddressSerializerFactory.getSerializer(afiType);
if (serializer == null) {
throw new LispSerializationException("Unknown AFI type=" + afiType);
}
try {
- return serializer.deserialize(buffer);
+ return serializer.deserializeData(buffer);
} catch (Exception e) {
throw new LispSerializationException(e.getMessage());
}
}
-
+
private interface Length {
int AFI = 2;
}
+
}
import java.nio.ByteBuffer;
-import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
import org.opendaylight.lispflowmapping.implementation.util.ByteUtil;
import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
import org.opendaylight.lispflowmapping.type.lisp.address.LispApplicationDataLCAFAddress;
-import org.opendaylight.lispflowmapping.type.lisp.address.LispSegmentLCAFAddress;
public class LispApplicationDataLCAFAddressSerializer extends LispLCAFAddressSerializer {
}
@Override
- public short getLcafLength(LispAddress lispAddress) {
- LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(((LispApplicationDataLCAFAddress) lispAddress).getAddress()
- .getAfi());
- return (short) (Length.ALL_FIELDS + serializer.getAddressSize(lispAddress));
+ protected short getLcafLength(LispAddress lispAddress) {
+ return (short) (Length.ALL_FIELDS + LispAddressSerializer.getInstance().getAddressSize(((LispApplicationDataLCAFAddress)lispAddress).getAddress()));
}
@Override
- public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
- super.internalSerialize(buffer, lispAddress);
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
LispApplicationDataLCAFAddress applicationDataAddress = ((LispApplicationDataLCAFAddress) lispAddress);
buffer.put(ByteUtil.partialIntToByteArray(applicationDataAddress.getIPTos(), Length.TOC));
buffer.put(applicationDataAddress.getProtocol());
buffer.putShort(applicationDataAddress.getLocalPort());
buffer.putShort(applicationDataAddress.getRemotePort());
- LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(applicationDataAddress.getAddress().getAfi());
- if (serializer == null) {
- throw new LispSerializationException("Unknown AFI type=" + ((LispSegmentLCAFAddress) lispAddress).getAddress().getAfi());
- }
- serializer.serialize(buffer, ((LispApplicationDataLCAFAddress) lispAddress).getAddress());
+ LispAddressSerializer.getInstance().serialize(buffer, ((LispApplicationDataLCAFAddress) lispAddress).getAddress());
}
@Override
- public LispApplicationDataLCAFAddress innerDeserialize(ByteBuffer buffer, byte res2, short length) {
+ protected LispApplicationDataLCAFAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
LispApplicationDataLCAFAddress applicationDataAddress = new LispApplicationDataLCAFAddress(res2);
byte[] rawIPTos = new byte[3];
@Override
- public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
LispIPAddress lispIpvAddress = (LispIPAddress)lispAddress;
- super.internalSerialize(buffer, lispAddress);
buffer.put(lispIpvAddress.getAddress().getAddress());
}
}
@Override
public int getAddressSize(LispAddress lispAddress) {
- return super.getAddressSize(lispAddress) + 4;
+ return Length.IPV4;
}
@Override
- public LispIpv4Address deserialize(ByteBuffer buffer) {
+ protected LispIpv4Address deserializeData(ByteBuffer buffer) {
byte[] ipBuffer = new byte[4];
InetAddress address = null;
buffer.get(ipBuffer);
}
return new LispIpv4Address(address);
}
+
+ private interface Length {
+ int IPV4 = 4;
+ }
@Override
public int getAddressSize(LispAddress lispAddress) {
- return super.getAddressSize(lispAddress) + 16;
+ return Length.IPV6;
}
@Override
- public LispIpv6Address deserialize(ByteBuffer buffer) {
+ protected LispIpv6Address deserializeData(ByteBuffer buffer) {
byte[] ipBuffer = new byte[16];
InetAddress address = null;
buffer.get(ipBuffer);
}
return new LispIpv6Address(address);
}
+
+ private interface Length {
+ int IPV6 = 16;
+ }
}
+/*
+ * Copyright (c) 2013 Contextream, Inc. and others. 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.implementation.serializer.address;
import java.nio.ByteBuffer;
import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.factory.LispLCAFAddressSerializerFactory;
import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
import org.opendaylight.lispflowmapping.type.lisp.address.LispLCAFAddress;
-public class LispLCAFAddressSerializer extends LispAddressSerializer{
-
- private static final LispLCAFAddressSerializer INSTANCE = new LispLCAFAddressSerializer();
+public class LispLCAFAddressSerializer extends LispAddressSerializer {
- // Private constructor prevents instantiation from other classes
- protected LispLCAFAddressSerializer() {
- }
+ private static final LispLCAFAddressSerializer INSTANCE = new LispLCAFAddressSerializer();
- public static LispLCAFAddressSerializer getInstance() {
- return INSTANCE;
- }
+ // Private constructor prevents instantiation from other classes
+ protected LispLCAFAddressSerializer() {
+ }
+
+ public static LispLCAFAddressSerializer getInstance() {
+ return INSTANCE;
+ }
- @Override
- public LispLCAFAddress deserialize(ByteBuffer buffer) {
+ @Override
+ protected LispLCAFAddress deserializeData(ByteBuffer buffer) {
buffer.position(buffer.position() + Length.RES + Length.FLAGS);
byte lispCode = buffer.get();
LispCanonicalAddressFormatEnum lcafType = LispCanonicalAddressFormatEnum.valueOf(lispCode);
byte res2 = buffer.get();
short length = buffer.getShort();
- LispLCAFAddressSerializer serializer = LispAddressSerializerFactory.getLCAFSerializer(lcafType);
+ LispLCAFAddressSerializer serializer = LispLCAFAddressSerializerFactory.getLCAFSerializer(lcafType);
if (serializer == null) {
throw new LispSerializationException("Unknown LispLCAFAddress type=" + lispCode);
}
- return serializer.innerDeserialize(buffer, res2, length);
+ return serializer.deserializeData(buffer, res2, length);
+ }
+
+ protected LispLCAFAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
+ throw new RuntimeException("Not implemented");
}
-
- public LispLCAFAddress innerDeserialize(ByteBuffer buffer, byte res2, short length) {
- throw new RuntimeException("Not implemented");
- }
@Override
public int getAddressSize(LispAddress lispAddress) {
- return super.getAddressSize(lispAddress) + Length.LCAF_HEADER + LispAddressSerializerFactory.getLCAFSerializer(((LispLCAFAddress)lispAddress).getType()).getLcafLength(lispAddress);
+ return Length.LCAF_HEADER
+ + LispLCAFAddressSerializerFactory.getLCAFSerializer(((LispLCAFAddress) lispAddress).getType()).getLcafLength(lispAddress);
}
-
- public short getLcafLength(LispAddress lispAddress) {
- throw new RuntimeException("Not implemented");
+
+ protected short getLcafLength(LispAddress lispAddress) {
+ throw new RuntimeException("Not implemented");
}
-
+
@Override
- public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
- LispLCAFAddressSerializer lcafSerializer = LispAddressSerializerFactory.getLCAFSerializer(((LispLCAFAddress)lispAddress).getType());
- lcafSerializer.serialize(buffer, lispAddress);
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ serializeLCAFAddressHeader(buffer, lispAddress);
+
+ LispLCAFAddressSerializer lcafSerializer = LispLCAFAddressSerializerFactory.getLCAFSerializer(((LispLCAFAddress) lispAddress).getType());
+ lcafSerializer.serializeData(buffer, lispAddress);
}
- @Override
- protected void internalSerialize(ByteBuffer buffer, LispAddress lispAddress) {
- super.internalSerialize(buffer, lispAddress);
- LispLCAFAddress lispLCAFAddress = (LispLCAFAddress)lispAddress;
+ private void serializeLCAFAddressHeader(ByteBuffer buffer, LispAddress lispAddress) {
+ LispLCAFAddress lispLCAFAddress = (LispLCAFAddress) lispAddress;
buffer.putShort((short) 0); // RES + Flags.
buffer.put(lispLCAFAddress.getType().getLispCode());
buffer.put(lispLCAFAddress.getRes2());
- buffer.putShort(getLcafLength(lispAddress));
+ LispLCAFAddressSerializer lcafSerializer = LispLCAFAddressSerializerFactory.getLCAFSerializer(lispLCAFAddress.getType());
+ buffer.putShort(lcafSerializer.getLcafLength(lispAddress));
}
+
private interface Length {
int RES = 1;
int FLAGS = 1;
@Override
- public short getLcafLength(LispAddress lispAddress) {
+ protected short getLcafLength(LispAddress lispAddress) {
short totalSize = 0;
for (LispAddress address : ((LispListLCAFAddress)lispAddress).getAddresses()) {
- totalSize += LispAddressSerializerFactory.getSerializer(address.getAfi()).getAddressSize(lispAddress);
+ totalSize += LispAddressSerializer.getInstance().getAddressSize(address);
}
return totalSize;
}
@Override
- public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
- super.internalSerialize(buffer, lispAddress);
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
for (LispAddress address : ((LispListLCAFAddress)lispAddress).getAddresses()) {
- LispAddressSerializerFactory.getSerializer(address.getAfi()).serialize(buffer, address);
+ LispAddressSerializer.getInstance().serialize(buffer, address);
}
}
@Override
- public LispListLCAFAddress innerDeserialize(ByteBuffer buffer, byte res2, short length) {
+ public LispListLCAFAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
List<LispAddress> addresses = new ArrayList<LispAddress>();
while (length > 0) {
LispAddress address = LispAddressSerializer.getInstance().deserialize(buffer);
- length -= LispAddressSerializerFactory.getSerializer(address.getAfi()).getAddressSize(address);
+ length -= LispAddressSerializer.getInstance().getAddressSize(address);
addresses.add(address);
}
return new LispListLCAFAddress(res2, addresses);
@Override
public int getAddressSize(LispAddress lispAddress) {
- return super.getAddressSize(lispAddress) + 6;
+ return super.getAddressSize(lispAddress) + Length.MAC;
}
@Override
- public LispMACAddress deserialize(ByteBuffer buffer) {
+ protected LispMACAddress deserializeData(ByteBuffer buffer) {
byte[] macBuffer = new byte[6];
buffer.get(macBuffer);
return new LispMACAddress(macBuffer);
}
@Override
- public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
LispMACAddress lispMACAddress = (LispMACAddress)lispAddress;
- super.internalSerialize(buffer, lispMACAddress);
buffer.put(lispMACAddress.getMAC());
}
+
+ private interface Length {
+ int MAC = 6;
+ }
}
}
@Override
- public LispNoAddress deserialize(ByteBuffer buffer) {
+ protected LispNoAddress deserializeData(ByteBuffer buffer) {
return new LispNoAddress();
}
@Override
public int getAddressSize(LispAddress lispAddress) {
- return super.getAddressSize(lispAddress);
+ return 0;
}
@Override
- public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
}
}
import java.nio.ByteBuffer;
-import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
import org.opendaylight.lispflowmapping.type.lisp.address.LispSegmentLCAFAddress;
@Override
- public short getLcafLength(LispAddress lispAddress) {
- LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(((LispSegmentLCAFAddress)lispAddress).getAddress().getAfi());
- return (short) (Length.INSTANCE + serializer.getAddressSize(((LispSegmentLCAFAddress)lispAddress).getAddress()));
+ protected short getLcafLength(LispAddress lispAddress) {
+ return (short) (Length.INSTANCE + LispAddressSerializer.getInstance().getAddressSize(((LispSegmentLCAFAddress)lispAddress).getAddress()));
}
@Override
- public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
- super.internalSerialize(buffer, lispAddress);
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
buffer.putInt(((LispSegmentLCAFAddress)lispAddress).getInstanceId());
- LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(((LispSegmentLCAFAddress)lispAddress).getAddress().getAfi());
- if (serializer == null) {
- throw new LispSerializationException("Unknown AFI type=" + ((LispSegmentLCAFAddress)lispAddress).getAddress().getAfi());
- }
- serializer.serialize(buffer, ((LispSegmentLCAFAddress)lispAddress).getAddress());
+ LispAddressSerializer.getInstance().serialize(buffer, ((LispSegmentLCAFAddress)lispAddress).getAddress());
}
@Override
- public LispSegmentLCAFAddress innerDeserialize(ByteBuffer buffer, byte res2, short length) {
+ protected LispSegmentLCAFAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
int instanceId = buffer.getInt();
LispAddress address = LispAddressSerializer.getInstance().deserialize(buffer);
import java.nio.ByteBuffer;
-import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
import org.opendaylight.lispflowmapping.type.lisp.address.LispSourceDestLCAFAddress;
}
@Override
- public short getLcafLength(LispAddress lispAddress) {
- LispAddressSerializer srcSerializer = LispAddressSerializerFactory.getSerializer(((LispSourceDestLCAFAddress) lispAddress).getSrcAddress()
- .getAfi());
- LispAddressSerializer dstSerializer = LispAddressSerializerFactory.getSerializer(((LispSourceDestLCAFAddress) lispAddress).getDstAddress()
- .getAfi());
- return (short) (Length.ALL_FIELDS + srcSerializer.getAddressSize(((LispSourceDestLCAFAddress) lispAddress).getSrcAddress()) + dstSerializer
+ protected short getLcafLength(LispAddress lispAddress) {
+ return (short) (Length.ALL_FIELDS + LispAddressSerializer.getInstance().getAddressSize(((LispSourceDestLCAFAddress) lispAddress).getSrcAddress()) + LispAddressSerializer.getInstance()
.getAddressSize(((LispSourceDestLCAFAddress) lispAddress).getDstAddress()));
}
@Override
- public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
- super.internalSerialize(buffer, lispAddress);
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
LispSourceDestLCAFAddress lispSourceDestLCAFAddress = ((LispSourceDestLCAFAddress) lispAddress);
buffer.putShort(lispSourceDestLCAFAddress.getReserved());
buffer.put(lispSourceDestLCAFAddress.getSrcMaskLength());
buffer.put(lispSourceDestLCAFAddress.getDstMaskLength());
- LispAddressSerializer srcSerializer = LispAddressSerializerFactory.getSerializer(lispSourceDestLCAFAddress.getSrcAddress().getAfi());
- if (srcSerializer == null) {
- throw new LispSerializationException("Unknown AFI type=" + lispSourceDestLCAFAddress.getSrcAddress().getAfi());
- }
- srcSerializer.serialize(buffer, lispSourceDestLCAFAddress.getSrcAddress());
- LispAddressSerializer dstSerializer = LispAddressSerializerFactory.getSerializer(lispSourceDestLCAFAddress.getDstAddress().getAfi());
- if (dstSerializer == null) {
- throw new LispSerializationException("Unknown AFI type=" + lispSourceDestLCAFAddress.getDstAddress().getAfi());
- }
- dstSerializer.serialize(buffer, lispSourceDestLCAFAddress.getDstAddress());
+ LispAddressSerializer.getInstance().serialize(buffer, lispSourceDestLCAFAddress.getSrcAddress());
+ LispAddressSerializer.getInstance().serialize(buffer, lispSourceDestLCAFAddress.getDstAddress());
}
@Override
- public LispSourceDestLCAFAddress innerDeserialize(ByteBuffer buffer, byte res2, short length) {
+ protected LispSourceDestLCAFAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
short res = buffer.getShort();
byte srcMaskLength = buffer.get();
byte dstMaskLength = buffer.get();
--- /dev/null
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opendaylight.lispflowmapping.implementation.serializer.address.factory.LispAFIAddressSerializerFactory;
+import org.opendaylight.lispflowmapping.implementation.util.ByteUtil;
+import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispTrafficEngineeringLCAFAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.ReencapHop;
+
+public class LispTrafficEngineeringLCAFAddressSerializer extends LispLCAFAddressSerializer {
+
+ private static final LispTrafficEngineeringLCAFAddressSerializer INSTANCE = new LispTrafficEngineeringLCAFAddressSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private LispTrafficEngineeringLCAFAddressSerializer() {
+ }
+
+ public static LispTrafficEngineeringLCAFAddressSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ protected short getLcafLength(LispAddress lispAddress) {
+ short totalSize = 0;
+ for (ReencapHop hop : ((LispTrafficEngineeringLCAFAddress) lispAddress).getHops()) {
+ totalSize += LispAddressSerializer.getInstance().getAddressSize(hop) + 2;
+ }
+ return totalSize;
+ }
+
+ @Override
+ protected void serializeData(ByteBuffer buffer, LispAddress lispAddress) {
+ for (ReencapHop hop : ((LispTrafficEngineeringLCAFAddress) lispAddress).getHops()) {
+ serializeAFIAddressHeader(buffer, hop);
+ buffer.put((byte) 0);
+ buffer.put((byte) (ByteUtil.boolToBit(hop.isLookup(), Flags.LOOKUP) | //
+ ByteUtil.boolToBit(hop.isRLOCProbe(), Flags.RLOC_PROBE) | //
+ ByteUtil.boolToBit(hop.isStrict(), Flags.STRICT)));
+ LispAddressSerializer serializer = LispAFIAddressSerializerFactory.getSerializer(hop.getAfi());
+ serializer.serializeData(buffer, hop.getHop());
+ }
+ }
+
+ @Override
+ protected LispTrafficEngineeringLCAFAddress deserializeData(ByteBuffer buffer, byte res2, short length) {
+ List<ReencapHop> hops = new ArrayList<ReencapHop>();
+ while (length > 0) {
+ short afi = buffer.getShort();
+ LispAddressSerializer serializer = LispAFIAddressSerializerFactory.getSerializer(AddressFamilyNumberEnum.valueOf(afi));
+ byte flags = (byte) buffer.getShort();
+ boolean lookup = ByteUtil.extractBit(flags, Flags.LOOKUP);
+ boolean RLOCProbe = ByteUtil.extractBit(flags, Flags.RLOC_PROBE);
+ boolean strict = ByteUtil.extractBit(flags, Flags.STRICT);
+ LispAddress address = serializer.deserializeData(buffer);
+ ReencapHop hop = new ReencapHop(address, (short) 0, lookup, RLOCProbe, strict);
+ length -= LispAddressSerializer.getInstance().getAddressSize(hop) + 2;
+ hops.add(hop);
+ }
+ return new LispTrafficEngineeringLCAFAddress(res2, hops);
+ }
+
+ private interface Flags {
+ int LOOKUP = 0x04;
+ int RLOC_PROBE = 0x02;
+ int STRICT = 0x01;
+ }
+
+}
-package org.opendaylight.lispflowmapping.implementation.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.serializer.address.factory;
import java.util.HashMap;
import java.util.Map;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispASAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispIpv4AddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispIpv6AddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispLCAFAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispMACAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispNoAddressSerializer;
import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
-public class LispAddressSerializerFactory {
+public class LispAFIAddressSerializerFactory {
private static Map<AddressFamilyNumberEnum, LispAddressSerializer> afiToSearializerMap;
- private static Map<LispCanonicalAddressFormatEnum, LispLCAFAddressSerializer> lcafToSearializerMap;
private static void initializeMap() {
afiToSearializerMap = new HashMap<AddressFamilyNumberEnum, LispAddressSerializer>();
afiToSearializerMap.put(AddressFamilyNumberEnum.MAC, LispMACAddressSerializer.getInstance());
afiToSearializerMap.put(AddressFamilyNumberEnum.RESERVED, LispNoAddressSerializer.getInstance());
- lcafToSearializerMap = new HashMap<LispCanonicalAddressFormatEnum, LispLCAFAddressSerializer>();
- lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.LIST, LispListLCAFAddressSerializer.getInstance());
- lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.SEGMENT, LispSegmentLCAFAddressSerializer.getInstance());
- lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.APPLICATION_DATA, LispApplicationDataLCAFAddressSerializer.getInstance());
- lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.SOURCE_DEST, LispSourceDestLCAFAddressSerializer.getInstance());
}
public static LispAddressSerializer getSerializer(AddressFamilyNumberEnum afi) {
return afiToSearializerMap.get(afi);
}
- public static LispLCAFAddressSerializer getLCAFSerializer(LispCanonicalAddressFormatEnum lcaf) {
- if (lcafToSearializerMap == null) {
- initializeMap();
- }
- return lcafToSearializerMap.get(lcaf);
- }
-
}
--- /dev/null
+package org.opendaylight.lispflowmapping.implementation.serializer.address.factory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispApplicationDataLCAFAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispLCAFAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispListLCAFAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispSegmentLCAFAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispSourceDestLCAFAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispTrafficEngineeringLCAFAddressSerializer;
+import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
+
+public class LispLCAFAddressSerializerFactory {
+
+ private static Map<LispCanonicalAddressFormatEnum, LispLCAFAddressSerializer> lcafToSearializerMap;
+
+ private static void initializeMap() {
+
+ lcafToSearializerMap = new HashMap<LispCanonicalAddressFormatEnum, LispLCAFAddressSerializer>();
+ lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.LIST, LispListLCAFAddressSerializer.getInstance());
+ lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.SEGMENT, LispSegmentLCAFAddressSerializer.getInstance());
+ lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.APPLICATION_DATA, LispApplicationDataLCAFAddressSerializer.getInstance());
+ lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING, LispTrafficEngineeringLCAFAddressSerializer.getInstance());
+ lcafToSearializerMap.put(LispCanonicalAddressFormatEnum.SOURCE_DEST, LispSourceDestLCAFAddressSerializer.getInstance());
+ }
+
+ public static LispLCAFAddressSerializer getLCAFSerializer(LispCanonicalAddressFormatEnum lcaf) {
+ if (lcafToSearializerMap == null) {
+ initializeMap();
+ }
+ return lcafToSearializerMap.get(lcaf);
+ }
+
+
+}
address.setLocalPort((short) 0xA6A1);
address.setRemotePort((short) 0xFFDD);
address.setAddress(new LispIpv4Address(0x11223344));
- ByteBuffer buf = ByteBuffer.allocate(LispApplicationDataLCAFAddressSerializer.getInstance().getAddressSize(address));
- LispApplicationDataLCAFAddressSerializer.getInstance().serialize(buf, address);
+ ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(address));
+ LispAddressSerializer.getInstance().serialize(buf, address);
ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
"04 20 00 0E " + //
"AA BB CC DD " + // IPTOS & protocol
LispIpv6Address lispIpv6Address = new LispIpv6Address("::0");
assertEquals(AddressFamilyNumberEnum.IP6, lispIpv6Address.getAfi());
- assertEquals(18, LispIpv6AddressSerializer.getInstance().getAddressSize(lispIpv6Address));
+ assertEquals(18, LispAddressSerializer.getInstance().getAddressSize(lispIpv6Address));
assertEquals("0:0:0:0:0:0:0:0", lispIpv6Address.toString());
}
LispIpv6Address lispIpv6Address = new LispIpv6Address(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 });
assertEquals(AddressFamilyNumberEnum.IP6, lispIpv6Address.getAfi());
- assertEquals(18, LispIpv6AddressSerializer.getInstance().getAddressSize(lispIpv6Address));
+ assertEquals(18, LispAddressSerializer.getInstance().getAddressSize(lispIpv6Address));
assertEquals("0:0:0:0:0:0:0:1", lispIpv6Address.toString());
}
}
addressList.add(new LispIpv6Address("1222:3344:1122:3344:1122:3344:1122:3344"));
LispListLCAFAddress address = new LispListLCAFAddress((byte) 0, addressList);
- ByteBuffer buf = ByteBuffer.allocate(LispListLCAFAddressSerializer.getInstance().getAddressSize(address));
- LispListLCAFAddressSerializer.getInstance().serialize(buf,address);
+ ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(address));
+ LispAddressSerializer.getInstance().serialize(buf,address);
ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
"01 00 00 18 " + //
"00 01 AA BB CC DD " + // IPv4
public void serialize__NoAddresses() throws Exception {
LispListLCAFAddress address = new LispListLCAFAddress((byte) 0, new ArrayList<LispAddress>());
- ByteBuffer buf = ByteBuffer.allocate(LispListLCAFAddressSerializer.getInstance().getAddressSize(address));
- LispListLCAFAddressSerializer.getInstance().serialize(buf,address);
+ ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(address));
+ LispAddressSerializer.getInstance().serialize(buf,address);
ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
"01 00 00 00");
ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
@Test
public void serialize__Simple() throws Exception {
LispSegmentLCAFAddress address = new LispSegmentLCAFAddress((byte) 0x06, 0x01020304, new LispIpv4Address(0x11223344));
- ByteBuffer buf = ByteBuffer.allocate(LispSegmentLCAFAddressSerializer.getInstance().getAddressSize(address));
- LispSegmentLCAFAddressSerializer.getInstance().serialize(buf,address);
+ ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(address));
+ LispAddressSerializer.getInstance().serialize(buf,address);
ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
"02 06 00 0A " + //
"01 02 03 04 " + // instance ID
@Test
public void serialize__Recursive_Segment() throws Exception {
LispSegmentLCAFAddress address = new LispSegmentLCAFAddress((byte) 0x06, 0x01020304, new LispSegmentLCAFAddress((byte) 0x06, 0x01020305, new LispIpv4Address(0x11223344)));
- ByteBuffer buf = ByteBuffer.allocate(LispSegmentLCAFAddressSerializer.getInstance().getAddressSize(address));
- LispSegmentLCAFAddressSerializer.getInstance().serialize(buf,address);
+ ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(address));
+ LispAddressSerializer.getInstance().serialize(buf,address);
ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
"02 06 00 16 " + //
"01 02 03 04 " + // instance ID
@Test
public void serialize__Simple() throws Exception {
LispSourceDestLCAFAddress address = new LispSourceDestLCAFAddress((byte) 0x20, (short)0x0000, (byte) 0xCC, (byte) 0xDD, new LispIpv4Address(0x11223344), new LispIpv4Address(0x22334455));
- ByteBuffer buf = ByteBuffer.allocate(LispSourceDestLCAFAddressSerializer.getInstance().getAddressSize(address));
- LispSourceDestLCAFAddressSerializer.getInstance().serialize(buf,address);
+ ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(address));
+ LispAddressSerializer.getInstance().serialize(buf,address);
ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
"0C 20 00 10 " + //
"00 00 CC DD " + // reserved + masks
--- /dev/null
+/*
+ * Copyright (c) 2013 Contextream, Inc. and others. 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.implementation.serializer.address;
+
+import static junit.framework.Assert.assertEquals;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import junitx.framework.ArrayAssert;
+
+import org.junit.Test;
+import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
+import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
+import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispTrafficEngineeringLCAFAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.ReencapHop;
+
+public class LispTrafficEngineeringLCAFAddressTest extends BaseTestCase {
+
+ @Test
+ public void deserialize__Simple() throws Exception {
+ LispAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
+ "0A 00 00 10 " + //
+ "00 01 00 00 AA BB CC DD " + // IPv4
+ "00 01 00 00 11 22 33 44")); // IPv4
+
+ assertEquals(AddressFamilyNumberEnum.LCAF, address.getAfi());
+ LispTrafficEngineeringLCAFAddress trafficEngineering = (LispTrafficEngineeringLCAFAddress) address;
+
+ assertEquals(LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING, trafficEngineering.getType());
+
+ List<ReencapHop> hops = trafficEngineering.getHops();
+ assertEquals(2, hops.size());
+
+ assertEquals(new LispIpv4Address(0xAABBCCDD), hops.get(0).getHop());
+ assertEquals(new LispIpv4Address(0x11223344), hops.get(1).getHop());
+ }
+
+ @Test
+ public void deserialize__Bits() throws Exception {
+ LispAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
+ "0A 00 00 10 " + //
+ "00 01 00 05 AA BB CC DD " + // IPv4
+ "00 01 00 02 11 22 33 44")); // IPv4
+
+ assertEquals(AddressFamilyNumberEnum.LCAF, address.getAfi());
+ LispTrafficEngineeringLCAFAddress trafficEngineering = (LispTrafficEngineeringLCAFAddress) address;
+
+ assertEquals(LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING, trafficEngineering.getType());
+
+ List<ReencapHop> hops = trafficEngineering.getHops();
+ assertEquals(2, hops.size());
+
+ assertEquals(new LispIpv4Address(0xAABBCCDD), hops.get(0).getHop());
+ assertEquals(true, hops.get(0).isLookup());
+ assertEquals(false, hops.get(0).isRLOCProbe());
+ assertEquals(true, hops.get(0).isStrict());
+ assertEquals(new LispIpv4Address(0x11223344), hops.get(1).getHop());
+ assertEquals(false, hops.get(1).isLookup());
+ assertEquals(true, hops.get(1).isRLOCProbe());
+ assertEquals(false, hops.get(1).isStrict());
+ }
+
+ @Test
+ public void deserialize__NoAddresses() throws Exception {
+ LispAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
+ "0A 00 00 00 "));
+
+ assertEquals(AddressFamilyNumberEnum.LCAF, address.getAfi());
+ LispTrafficEngineeringLCAFAddress trafficEngineering = (LispTrafficEngineeringLCAFAddress) address;
+
+ assertEquals(LispCanonicalAddressFormatEnum.TRAFFIC_ENGINEERING, trafficEngineering.getType());
+
+ List<ReencapHop> hops = trafficEngineering.getHops();
+ assertEquals(0, hops.size());
+ }
+
+ @Test(expected = LispSerializationException.class)
+ public void deserialize__ShorterBuffer() throws Exception {
+ LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
+ "0A 00 00 18 " + //
+ "00 01 AA BB CC DD " + // IPv4
+ "00 02 11 22 33 44 11 22 33 44 11 22 33 44"));
+ }
+
+ @Test(expected = LispSerializationException.class)
+ public void deserialize__ShorterBuffer2() throws Exception {
+ LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
+ "0A 00 00 18 "));
+ }
+
+ @Test
+ public void serialize__Simple() throws Exception {
+ List<ReencapHop> hops = new ArrayList<ReencapHop>();
+ hops.add(new ReencapHop(new LispIpv4Address(0xAABBCCDD), (short)0, false, false, false));
+ hops.add(new ReencapHop(new LispIpv4Address(0x11223344), (short)0, false, false, false));
+ LispTrafficEngineeringLCAFAddress address = new LispTrafficEngineeringLCAFAddress((byte) 0, hops);
+
+ ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(address));
+ LispAddressSerializer.getInstance().serialize(buf,address);
+ ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
+ "0A 00 00 10 " + //
+ "00 01 00 00 AA BB CC DD " + // IPv4
+ "00 01 00 00 11 22 33 44"); // IPv4
+ ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
+ }
+
+ @Test
+ public void serialize__NoAddresses() throws Exception {
+ LispTrafficEngineeringLCAFAddress address = new LispTrafficEngineeringLCAFAddress((byte) 0, new ArrayList<ReencapHop>());
+
+ ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(address));
+ LispAddressSerializer.getInstance().serialize(buf,address);
+ ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
+ "0A 00 00 00");
+ ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
+ }
+}