--- /dev/null
+implementation/META-INF
+api/META-INF
+northbound/META-INF
+southbound/META-INF
<configuration>
<instructions>
<Export-Package>
- org.opendaylight.lispflowmapping,
- org.opendaylight.lispflowmapping.dao,
- org.opendaylight.lispflowmapping.lisp,
- org.opendaylight.lispflowmapping.type.exception,
+ org.opendaylight.lispflowmapping.interfaces.dao,
+ org.opendaylight.lispflowmapping.interfaces.lisp,
+ org.opendaylight.lispflowmapping.type,
org.opendaylight.lispflowmapping.type.lisp,
- org.opendaylight.lispflowmapping.type.lisp.address,
- org.opendaylight.lispflowmapping.util
+ org.opendaylight.lispflowmapping.type.lisp.address
</Export-Package>
<Bundle-Activator>
</Bundle-Activator>
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.dao;
+package org.opendaylight.lispflowmapping.interfaces.dao;
import java.util.Map;
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.dao;
+package org.opendaylight.lispflowmapping.interfaces.dao;
public interface ILispTypeConverter<UserType, DbType> {
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.dao;
+package org.opendaylight.lispflowmapping.interfaces.dao;
public interface IQueryAll {
public void getAll(IRowVisitor visitor);
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.dao;
+package org.opendaylight.lispflowmapping.interfaces.dao;
public interface IRowVisitor {
void visitRow(Class<?> keyType, Object keyId, String valueKey, Object value);
--- /dev/null
+package org.opendaylight.lispflowmapping.interfaces.lisp;
+
+public interface IFlowMapping extends IMapResolver, IMapServer {
+}
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.lisp;
+package org.opendaylight.lispflowmapping.interfaces.lisp;
import org.opendaylight.lispflowmapping.type.lisp.MapReply;
import org.opendaylight.lispflowmapping.type.lisp.MapRequest;
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.lisp;
+package org.opendaylight.lispflowmapping.interfaces.lisp;
import org.opendaylight.lispflowmapping.type.lisp.MapNotify;
import org.opendaylight.lispflowmapping.type.lisp.MapRegister;
import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv6Address;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispLCAFAddress;
import org.opendaylight.lispflowmapping.type.lisp.address.LispMACAddress;
import org.opendaylight.lispflowmapping.type.lisp.address.LispNoAddress;
-import org.opendaylight.lispflowmapping.type.lisp.address.LispSegmentLCAFAddress;
public enum AddressFamilyNumberEnum {
RESERVED(0, LispNoAddress.class), //
IP(1, LispIpv4Address.class), //
IP6(2, LispIpv6Address.class), //
AS(18, LispASAddress.class), //
- LCAF(16387, LispSegmentLCAFAddress.class), //
+ LCAF(16387, LispLCAFAddress.class), //
MAC(16389, LispMACAddress.class), //
UNKNOWN(-1, null);
package org.opendaylight.lispflowmapping.type.lisp;
-import java.nio.ByteBuffer;
-
import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
import org.opendaylight.lispflowmapping.type.lisp.address.LispNoAddress;
this.prefix = (prefix != null) ? prefix : NO_PREFIX;
}
- public static EidRecord deserialize(ByteBuffer requestBuffer) {
- /* byte reserved = */requestBuffer.get();
- byte maskLength = requestBuffer.get();
- LispAddress prefix = LispAddress.valueOf(requestBuffer);
- return new EidRecord(maskLength, prefix);
- }
private static LispAddress NO_PREFIX = new LispNoAddress();
}
package org.opendaylight.lispflowmapping.type.lisp;
-import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
import org.opendaylight.lispflowmapping.type.lisp.address.LispNoAddress;
-import org.opendaylight.lispflowmapping.util.ByteUtil;
/**
* <pre>
return this;
}
- protected static EidToLocatorRecord deserialize(ByteBuffer buffer) {
- EidToLocatorRecord eidToLocatorRecord = new EidToLocatorRecord();
- eidToLocatorRecord.setRecordTtl(buffer.getInt());
- byte locatorCount = buffer.get();
- eidToLocatorRecord.setMaskLength(buffer.get());
- byte actionAndAuthoritative = buffer.get();
- eidToLocatorRecord.setAction(MapReplyAction.valueOf(actionAndAuthoritative >> 5));
- eidToLocatorRecord.setAuthoritative(ByteUtil.extractBit(actionAndAuthoritative, Flags.AUTHORITATIVE));
- buffer.position(buffer.position() + Length.RESERVED);
- eidToLocatorRecord.setMapVersion(buffer.getShort());
-
- eidToLocatorRecord.setPrefix(LispAddress.valueOf(buffer));
- for (int i = 0; i < locatorCount; i++) {
- eidToLocatorRecord.addLocator(LocatorRecord.deserialize(buffer));
- }
-
- return eidToLocatorRecord;
- }
-
- public void serialize(ByteBuffer replyBuffer) {
- replyBuffer.putInt(getRecordTtl());
- replyBuffer.put((byte) getLocators().size());
- replyBuffer.put((byte) getMaskLength());
- replyBuffer.put((byte) ((getAction().getCode() << 5) | //
- ByteUtil.boolToBit(isAuthoritative(), Flags.AUTHORITATIVE)));
- replyBuffer.position(replyBuffer.position() + Length.RESERVED);
- replyBuffer.putShort(getMapVersion());
- getPrefix().serialize(replyBuffer);
-
- for (LocatorRecord locatorRecord : getLocators()) {
- locatorRecord.serialize(replyBuffer);
- }
- }
-
- public int getSerializationSize() {
- int size = Length.HEADER_SIZE + getPrefix().getAddressSize();
- for (LocatorRecord locatorRecord : getLocators()) {
- size += locatorRecord.getSerializationSize();
- }
- return size;
- }
public EidToLocatorRecord clone() {
EidToLocatorRecord cloned = new EidToLocatorRecord();
return cloned;
}
- private interface Flags {
- int AUTHORITATIVE = 0x10;
- }
-
- private interface Length {
- int HEADER_SIZE = 10;
- int RESERVED = 1;
- }
@Override
public int hashCode() {
package org.opendaylight.lispflowmapping.type.lisp;
-import java.nio.ByteBuffer;
-
import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
-import org.opendaylight.lispflowmapping.util.ByteUtil;
/**
* <pre>
return this;
}
- protected static LocatorRecord deserialize(ByteBuffer buffer) {
- LocatorRecord record = new LocatorRecord();
- record.setPriority(buffer.get());
- record.setWeight(buffer.get());
- record.setMulticastPriority(buffer.get());
- record.setMulticastWeight(buffer.get());
- byte flags = (byte) buffer.getShort();
- record.setLocalLocator(ByteUtil.extractBit(flags, Flags.LOCAL_LOCATOR));
- record.setRlocProbed(ByteUtil.extractBit(flags, Flags.RLOC_PROBED));
- record.setRouted(ByteUtil.extractBit(flags, Flags.ROUTED));
- record.setLocator(LispAddress.valueOf(buffer));
- return record;
- }
-
- public void serialize(ByteBuffer replyBuffer) {
- replyBuffer.put(getPriority());
- replyBuffer.put(getWeight());
- replyBuffer.put(getMulticastPriority());
- replyBuffer.put(getMulticastWeight());
- replyBuffer.position(replyBuffer.position() + Length.UNUSED_FLAGS);
- replyBuffer.put((byte) (ByteUtil.boolToBit(isLocalLocator(), Flags.LOCAL_LOCATOR) | //
- ByteUtil.boolToBit(isRlocProbed(), Flags.RLOC_PROBED) | //
- ByteUtil.boolToBit(isRouted(), Flags.ROUTED)));
- getLocator().serialize(replyBuffer);
- }
-
- public int getSerializationSize() {
- return Length.HEADER_SIZE + getLocator().getAddressSize();
- }
public LocatorRecord clone() {
LocatorRecord cloned = new LocatorRecord();
return cloned;
}
- private interface Flags {
- int LOCAL_LOCATOR = 0x04;
- int RLOC_PROBED = 0x02;
- int ROUTED = 0x01;
- }
-
- private interface Length {
- int HEADER_SIZE = 6;
- int UNUSED_FLAGS = 1;
- }
@Override
public int hashCode() {
package org.opendaylight.lispflowmapping.type.lisp;
-import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
setAuthenticationData(null);
}
- public ByteBuffer serialize() {
- int size = Length.HEADER_SIZE + getAuthenticationData().length;
- for (EidToLocatorRecord eidToLocatorRecord : getEidToLocatorRecords()) {
- size += eidToLocatorRecord.getSerializationSize();
- }
-
- ByteBuffer replyBuffer = ByteBuffer.allocate(size);
- replyBuffer.put((byte) (LispMessageEnum.MapNotify.getValue() << 4));
- replyBuffer.position(replyBuffer.position() + Length.RES);
- replyBuffer.put((byte) getEidToLocatorRecords().size());
- replyBuffer.putLong(getNonce());
- replyBuffer.putShort(getKeyId());
- replyBuffer.putShort((short) getAuthenticationData().length);
- if (getAuthenticationData() != null) {
- replyBuffer.put(getAuthenticationData());
- }
-
- for (EidToLocatorRecord eidToLocatorRecord : getEidToLocatorRecords()) {
- eidToLocatorRecord.serialize(replyBuffer);
- }
-
- replyBuffer.clear();
- return replyBuffer;
- }
-
public boolean isProxyMapReply() {
return proxyMapReply;
}
eidToLocatorRecords.add(record);
}
- private interface Length {
- int HEADER_SIZE = 16;
- int RES = 2;
- }
+
public void setFromMapRegister(MapRegister mapRegister) {
setNonce(mapRegister.getNonce());
package org.opendaylight.lispflowmapping.type.lisp;
-import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
-import org.opendaylight.lispflowmapping.type.exception.LispMalformedPacketException;
-import org.opendaylight.lispflowmapping.util.ByteUtil;
-
/**
* <pre>
* 0 1 2 3
return this;
}
- public static MapRegister deserialize(ByteBuffer registerBuffer) {
- try {
- MapRegister mapRegister = new MapRegister();
-
- mapRegister.setProxyMapReply(ByteUtil.extractBit(registerBuffer.get(), Flags.PROXY));
-
- registerBuffer.position(registerBuffer.position() + Length.RES);
- mapRegister.setWantMapNotify(ByteUtil.extractBit(registerBuffer.get(), Flags.WANT_MAP_REPLY));
- byte recordCount = registerBuffer.get();
- mapRegister.setNonce(registerBuffer.getLong());
- mapRegister.setKeyId(registerBuffer.getShort());
-
- short authenticationLength = registerBuffer.getShort();
- byte[] authenticationData = new byte[authenticationLength];
- registerBuffer.get(authenticationData);
- mapRegister.setAuthenticationData(authenticationData);
-
- for (int i = 0; i < recordCount; i++) {
- mapRegister.addEidToLocator(EidToLocatorRecord.deserialize(registerBuffer));
- }
- return mapRegister;
- } catch (RuntimeException re) {
- throw new LispMalformedPacketException("Couldn't deserialize Map-Register (len=" + registerBuffer.capacity() + ")", re);
- }
-
- }
-
- private interface Flags {
- byte PROXY = 0x08;
- byte WANT_MAP_REPLY = 0x01;
- }
-
- private interface Length {
- int RES = 1;
- }
-
private static byte[] NO_AUTHENTICATION_DATA = new byte[] {};
}
package org.opendaylight.lispflowmapping.type.lisp;
-import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
this.eidToLocatorRecords = eidToLocatorRecords;
}
- public ByteBuffer serialize() {
- int size = Length.HEADER_SIZE;
- for (EidToLocatorRecord eidToLocatorRecord : getEidToLocatorRecords()) {
- size += eidToLocatorRecord.getSerializationSize();
- }
-
- ByteBuffer replyBuffer = ByteBuffer.allocate(size);
-
- replyBuffer.put((byte) ((LispMessageEnum.MapReply.getValue() << 4) | //
- (isProbe() ? Flags.PROBE : 0x00) | //
- (isEchoNonceEnabled() ? Flags.ECHO_NONCE_ENABLED : 0x00)));
-
- replyBuffer.position(replyBuffer.position() + Length.RES);
- replyBuffer.put((byte) getEidToLocatorRecords().size());
- replyBuffer.putLong(getNonce());
- for (EidToLocatorRecord eidToLocatorRecord : getEidToLocatorRecords()) {
- eidToLocatorRecord.serialize(replyBuffer);
- }
- return replyBuffer;
- }
-
- private interface Length {
- int RES = 2;
- int HEADER_SIZE = 12;
- }
-
- private interface Flags {
- int PROBE = 0x08;
- int ECHO_NONCE_ENABLED = 0x04;
- }
+
}
package org.opendaylight.lispflowmapping.type.lisp;
-import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
-import org.opendaylight.lispflowmapping.type.exception.LispMalformedPacketException;
import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
-import org.opendaylight.lispflowmapping.util.ByteUtil;
/**
* <pre>
return itrRlocs;
}
- public static MapRequest deserialize(ByteBuffer requestBuffer) {
- try {
- MapRequest mapRequest = new MapRequest();
-
- byte typeAndFlags = requestBuffer.get();
- mapRequest.setAuthoritative(ByteUtil.extractBit(typeAndFlags, Flags.AUTHORITATIVE));
- mapRequest.setMapDataPresent(ByteUtil.extractBit(typeAndFlags, Flags.MAP_DATA_PRESENT));
- mapRequest.setProbe(ByteUtil.extractBit(typeAndFlags, Flags.PROBE));
- mapRequest.setSmr(ByteUtil.extractBit(typeAndFlags, Flags.SMR));
-
- byte moreFlags = requestBuffer.get();
- mapRequest.setPitr(ByteUtil.extractBit(moreFlags, Flags.PITR));
- mapRequest.setSmrInvoked(ByteUtil.extractBit(moreFlags, Flags.SMR_INVOKED));
-
- int itrCount = requestBuffer.get() + 1;
- int recordCount = requestBuffer.get();
- mapRequest.setNonce(requestBuffer.getLong());
- mapRequest.setSourceEid(LispAddress.valueOf(requestBuffer));
-
- for (int i = 0; i < itrCount; i++) {
- mapRequest.addItrRloc(LispAddress.valueOf(requestBuffer));
- }
-
- for (int i = 0; i < recordCount; i++) {
- mapRequest.addEidRecord(EidRecord.deserialize(requestBuffer));
- }
- return mapRequest;
- } catch (RuntimeException re) {
- throw new LispMalformedPacketException("Couldn't deserialize Map-Request (len=" + requestBuffer.capacity() + ")", re);
- }
- }
-
- public interface Flags {
- byte AUTHORITATIVE = 0x08;
- byte MAP_DATA_PRESENT = 0x04;
- byte PROBE = 0x02;
- byte SMR = 0x01;
-
- byte PITR = (byte) 0x80;
- byte SMR_INVOKED = 0x40;
- }
+
}
package org.opendaylight.lispflowmapping.type.lisp.address;
-import java.nio.ByteBuffer;
-
import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
public class LispASAddress extends LispAddress {
this.asNum = num;
}
- public static LispASAddress valueOf(ByteBuffer buffer) {
- throw new RuntimeException("Not implemented");
- }
public int getAS() {
return asNum;
}
- @Override
- public int getAddressSize() {
- throw new RuntimeException("Not implemented");
-
- }
-
- @Override
- public void serialize(ByteBuffer buffer) {
- throw new RuntimeException("Not implemented");
- }
@Override
public int hashCode() {
package org.opendaylight.lispflowmapping.type.lisp.address;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.nio.ByteBuffer;
-
import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.type.exception.LispMalformedPacketException;
public abstract class LispAddress {
private AddressFamilyNumberEnum afi;
public AddressFamilyNumberEnum getAfi() {
return afi;
}
-
- public int getAddressSize() {
- return Length.AFI;
- }
-
- abstract public void serialize(ByteBuffer buffer);
-
- protected void internalSerialize(ByteBuffer buffer) {
- buffer.putShort(getAfi().getIanaCode());
- }
-
- public static LispAddress valueOf(ByteBuffer buffer) {
- short afi = buffer.getShort();
- AddressFamilyNumberEnum afiType = AddressFamilyNumberEnum.valueOf(afi);
- Class<? extends LispAddress> addressClass = afiType.getLispAddressClass();
- Throwable t = null;
- try {
- Method valueOfMethod = addressClass.getMethod("valueOf", ByteBuffer.class);
- return (LispAddress) valueOfMethod.invoke(null, buffer);
- } catch (NoSuchMethodException e) {
- t = e;
- } catch (SecurityException e) {
- t = e;
- } catch (ClassCastException e) {
- t = e;
- } catch (IllegalAccessException e) {
- t = e;
- } catch (IllegalArgumentException e) {
- t = e;
- } catch (InvocationTargetException e) {
- t = e;
- }
- throw new LispMalformedPacketException("Couldn't parse LispAddress afi=" + afi, t);
- }
+
+
@Override
public int hashCode() {
return true;
}
- private interface Length {
- int AFI = 2;
- }
}
--- /dev/null
+package org.opendaylight.lispflowmapping.type.lisp.address;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
+
+public abstract class LispIPAddress extends LispAddress{
+
+ protected InetAddress address;
+
+ protected LispIPAddress(InetAddress address, AddressFamilyNumberEnum afi) {
+ super(afi);
+ this.address = address;
+ }
+
+ protected LispIPAddress(int address, AddressFamilyNumberEnum afi) {
+ super(afi);
+ try {
+ this.address = InetAddress.getByAddress(ByteBuffer.allocate(4).putInt(address).array());
+ } catch (UnknownHostException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ protected LispIPAddress(byte[] address, AddressFamilyNumberEnum afi) {
+ super(afi);
+ try {
+
+ this.address = InetAddress.getByAddress(address);
+ } catch (UnknownHostException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ protected LispIPAddress(String name, AddressFamilyNumberEnum afi) {
+ super(afi);
+ try {
+ this.address = InetAddress.getByName(name);
+ } catch (UnknownHostException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ public InetAddress getAddress() {
+ return address;
+ }
+
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((address == null) ? 0 : address.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ LispIPAddress other = (LispIPAddress) obj;
+ if (address == null) {
+ if (other.address != null)
+ return false;
+ } else if (!address.equals(other.address))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return address.getHostAddress();
+ }
+
+}
package org.opendaylight.lispflowmapping.type.lisp.address;
import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.nio.ByteBuffer;
import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
-public class LispIpv4Address extends LispAddress {
- private InetAddress address;
+public class LispIpv4Address extends LispIPAddress {
public LispIpv4Address(InetAddress address) {
- super(AddressFamilyNumberEnum.IP);
- this.address = address;
+ super(address, AddressFamilyNumberEnum.IP);
}
public LispIpv4Address(int address) {
- super(AddressFamilyNumberEnum.IP);
- try {
- this.address = InetAddress.getByAddress(ByteBuffer.allocate(4).putInt(address).array());
- } catch (UnknownHostException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ super(address, AddressFamilyNumberEnum.IP);
}
public LispIpv4Address(String name) {
- super(AddressFamilyNumberEnum.IP);
- try {
- this.address = InetAddress.getByName(name);
- } catch (UnknownHostException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ super(name, AddressFamilyNumberEnum.IP);
}
- public static LispIpv4Address valueOf(ByteBuffer buffer) {
- byte[] ipBuffer = new byte[4];
- InetAddress address = null;
- buffer.get(ipBuffer);
- try {
- address = InetAddress.getByAddress(ipBuffer);
- } catch (UnknownHostException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return new LispIpv4Address(address);
- }
-
- public InetAddress getAddress() {
- return address;
- }
-
- @Override
- public int getAddressSize() {
- return super.getAddressSize() + 4;
- }
-
- @Override
- public void serialize(ByteBuffer buffer) {
- super.internalSerialize(buffer);
- buffer.put(address.getAddress());
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + ((address == null) ? 0 : address.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (!super.equals(obj))
- return false;
- if (getClass() != obj.getClass())
- return false;
- LispIpv4Address other = (LispIpv4Address) obj;
- if (address == null) {
- if (other.address != null)
- return false;
- } else if (!address.equals(other.address))
- return false;
- return true;
- }
-
- @Override
- public String toString() {
- return address.getHostAddress();
- }
}
package org.opendaylight.lispflowmapping.type.lisp.address;
-import java.net.Inet6Address;
import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.nio.ByteBuffer;
import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
-public class LispIpv6Address extends LispAddress {
- private InetAddress address;
+public class LispIpv6Address extends LispIPAddress {
- private LispIpv6Address(InetAddress address) {
- super(AddressFamilyNumberEnum.IP6);
- this.address = address;
+ public LispIpv6Address(InetAddress address) {
+ super(address, AddressFamilyNumberEnum.IP6);
}
public LispIpv6Address(byte[] address) {
- super(AddressFamilyNumberEnum.IP6);
- try {
-
- this.address = Inet6Address.getByAddress(address);
- } catch (UnknownHostException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ super(address, AddressFamilyNumberEnum.IP6);
}
public LispIpv6Address(String name) {
- super(AddressFamilyNumberEnum.IP6);
- try {
- this.address = InetAddress.getByName(name);
- } catch (UnknownHostException e) {
- e.printStackTrace();
- }
- }
-
- public static LispIpv6Address valueOf(ByteBuffer buffer) {
- byte[] ipBuffer = new byte[16];
- InetAddress address = null;
- buffer.get(ipBuffer);
- try {
- address = InetAddress.getByAddress(ipBuffer);
- } catch (UnknownHostException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return new LispIpv6Address(address);
+ super(name, AddressFamilyNumberEnum.IP6);
}
- @Override
- public String toString() {
- return address.getHostAddress();
- }
-
- @Override
- public int getAddressSize() {
- return super.getAddressSize() + 16;
- }
- @Override
- public void serialize(ByteBuffer buffer) {
- super.internalSerialize(buffer);
- buffer.put(address.getAddress());
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + ((address == null) ? 0 : address.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (!super.equals(obj))
- return false;
- if (getClass() != obj.getClass())
- return false;
- LispIpv6Address other = (LispIpv6Address) obj;
- if (address == null) {
- if (other.address != null)
- return false;
- } else if (!address.equals(other.address))
- return false;
- return true;
- }
}
*/
package org.opendaylight.lispflowmapping.type.lisp.address;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.nio.ByteBuffer;
-
import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
-import org.opendaylight.lispflowmapping.type.exception.LispMalformedPacketException;
public abstract class LispLCAFAddress extends LispAddress {
protected LispCanonicalAddressFormatEnum lcafType;
protected byte res2;
- protected LispLCAFAddress(ByteBuffer buffer) {
- super(AddressFamilyNumberEnum.LCAF);
- }
-
public LispLCAFAddress(LispCanonicalAddressFormatEnum lcafType, byte res2) {
super(AddressFamilyNumberEnum.LCAF);
this.lcafType = lcafType;
this.res2 = res2;
}
- public static LispLCAFAddress valueOf(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();
-
- Class<? extends LispAddress> addressClass = lcafType.getLcafClass();
- if (addressClass == null) {
- throw new LispMalformedPacketException("Unknown LispLCAFAddress type=" + lispCode);
- }
- Method valueOfMethod;
- Throwable t = null;
- try {
- valueOfMethod = addressClass.getMethod("valueOf", byte.class, short.class, ByteBuffer.class);
- return (LispLCAFAddress) valueOfMethod.invoke(null, res2, length, buffer);
- } catch (NoSuchMethodException e) {
- t = e;
- } catch (SecurityException e) {
- t = e;
- } catch (IllegalAccessException e) {
- t = e;
- } catch (IllegalArgumentException e) {
- t = e;
- } catch (InvocationTargetException e) {
- t = e;
- }
- throw new LispMalformedPacketException("Couldn't parse LispLCAFAddress type=" + lispCode, t);
- }
-
- @Override
- public final int getAddressSize() {
- return super.getAddressSize() + Length.LCAF_HEADER + getLcafLength();
- }
-
- public abstract short getLcafLength();
-
- @Override
- protected void internalSerialize(ByteBuffer buffer) {
- super.internalSerialize(buffer);
- buffer.putShort((short) 0); // RES + Flags.
- buffer.put(lcafType.getLispCode());
- buffer.put(getRes2());
- buffer.putShort(getLcafLength());
- }
public LispCanonicalAddressFormatEnum getType() {
return lcafType;
return "[lcafType=" + lcafType + ", res2=" + res2 + "]";
}
- private interface Length {
- int RES = 1;
- int FLAGS = 1;
-
- int LCAF_HEADER = 6;
- }
}
package org.opendaylight.lispflowmapping.type.lisp.address;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
import java.util.List;
import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
public class LispListLCAFAddress extends LispLCAFAddress {
- List<LispAddress> addresses;
+ List<? extends LispAddress> addresses;
- public LispListLCAFAddress(byte res2, List<LispAddress> addresses) {
+ public LispListLCAFAddress(byte res2, List<? extends LispAddress> addresses) {
super(LispCanonicalAddressFormatEnum.LIST, res2);
this.addresses = addresses;
}
- @Override
- public void serialize(ByteBuffer buffer) {
- super.internalSerialize(buffer);
- for (LispAddress address : addresses) {
- address.serialize(buffer);
- }
- }
-
- @Override
- public short getLcafLength() {
- short totalSize = 0;
- for (LispAddress address : addresses) {
- totalSize += address.getAddressSize();
- }
- return totalSize;
- }
- public List<LispAddress> getAddresses() {
+ public List<? extends LispAddress> getAddresses() {
return addresses;
}
- public static LispListLCAFAddress valueOf(byte res2, short length, ByteBuffer buffer) {
- List<LispAddress> addresses = new ArrayList<LispAddress>();
- while (length > 0) {
- LispAddress address = LispAddress.valueOf(buffer);
- length -= address.getAddressSize();
- addresses.add(address);
- }
- return new LispListLCAFAddress(res2, addresses);
- }
@Override
public int hashCode() {
package org.opendaylight.lispflowmapping.type.lisp.address;
-import java.nio.ByteBuffer;
import java.util.Arrays;
import javax.xml.bind.DatatypeConverter;
System.arraycopy(mac, 0, this.mac, 0, 6);
}
- public static LispMACAddress valueOf(ByteBuffer buffer) {
- throw new RuntimeException("Not implemented");
- }
public byte[] getMAC() {
return mac;
}
- @Override
- public int getAddressSize() {
- throw new RuntimeException("Not implemented");
-
- }
-
- @Override
- public void serialize(ByteBuffer buffer) {
- throw new RuntimeException("Not implemented");
- }
@Override
public String toString() {
package org.opendaylight.lispflowmapping.type.lisp.address;
-import java.nio.ByteBuffer;
-
import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
public class LispNoAddress extends LispAddress {
super(AddressFamilyNumberEnum.RESERVED);
}
- public static LispNoAddress valueOf(ByteBuffer buffer) {
- return new LispNoAddress();
- }
-
- @Override
- public int getAddressSize() {
- return super.getAddressSize();
- }
-
- @Override
- public void serialize(ByteBuffer buffer) {
- }
}
*/
package org.opendaylight.lispflowmapping.type.lisp.address;
-import java.nio.ByteBuffer;
-
import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
public class LispSegmentLCAFAddress extends LispLCAFAddress {
this.instanceId = instanceId;
}
- public static LispSegmentLCAFAddress valueOf(byte res2, short length, ByteBuffer buffer) {
- int instanceId = buffer.getInt();
- LispAddress address = LispAddress.valueOf(buffer);
-
- return new LispSegmentLCAFAddress(res2, instanceId, address);
- }
-
- @Override
- public void serialize(ByteBuffer buffer) {
- super.internalSerialize(buffer);
- buffer.putInt(getInstanceId());
- address.serialize(buffer);
- }
public LispAddress getAddress() {
return address;
return getRes2();
}
- @Override
- public short getLcafLength() {
- return (short) (Length.INSTANCE + getAddress().getAddressSize());
- }
@Override
public int hashCode() {
return "LispSegmentLCAFAddress#[address=" + address + ", instanceId=" + instanceId + "]" + super.toString();
}
- private interface Length {
- int INSTANCE = 4;
- }
}
<configuration>
<instructions>
<Export-Package>
- org.opendaylight.lispflowmapping.implementation
</Export-Package>
<Import-Package>
org.opendaylight.controller.sal.core,
org.slf4j,
org.eclipse.osgi.framework.console,
org.osgi.framework,
- org.opendaylight.lispflowmapping,
- org.opendaylight.lispflowmapping.dao,
- org.opendaylight.lispflowmapping.lisp,
- org.opendaylight.lispflowmapping.type.exception,
+ org.opendaylight.lispflowmapping.interfaces.dao,
+ org.opendaylight.lispflowmapping.interfaces.lisp,
org.opendaylight.lispflowmapping.type.lisp,
org.opendaylight.lispflowmapping.type.lisp.address,
- org.opendaylight.lispflowmapping.util,
org.opendaylight.controller.clustering.services
</Import-Package>
<Bundle-Activator>
import org.apache.felix.dm.Component;
import org.opendaylight.controller.clustering.services.IClusterContainerServices;
import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
-import org.opendaylight.lispflowmapping.ILispMapping;
-import org.opendaylight.lispflowmapping.dao.ILispDAO;
import org.opendaylight.lispflowmapping.implementation.dao.ClusterDAOService;
-import org.opendaylight.lispflowmapping.lisp.IMapResolver;
-import org.opendaylight.lispflowmapping.lisp.IMapServer;
+import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
+import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// export the service
Dictionary<String, String> props = new Hashtable<String, String>();
props.put("name", "mappingservice");
- c.setInterface(new String[] { ILispMapping.class.getName(), IMapResolver.class.getName(), IMapServer.class.getName() }, props);
+ c.setInterface(new String[] { IFlowMapping.class.getName() }, props);
c.add(createContainerServiceDependency(containerName).setService(ILispDAO.class).setCallbacks("setLispDao", "unsetLispDao").setRequired(
true));
} else if (imp.equals(ClusterDAOService.class)) {
package org.opendaylight.lispflowmapping.implementation;
-import java.io.IOException;
-import java.net.DatagramPacket;
-import java.net.DatagramSocket;
-import java.net.InetSocketAddress;
-import java.net.SocketException;
-import java.net.SocketTimeoutException;
-
import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider;
-import org.opendaylight.lispflowmapping.ILispMapping;
-import org.opendaylight.lispflowmapping.dao.ILispDAO;
-import org.opendaylight.lispflowmapping.dao.ILispTypeConverter;
-import org.opendaylight.lispflowmapping.dao.IQueryAll;
-import org.opendaylight.lispflowmapping.dao.IRowVisitor;
import org.opendaylight.lispflowmapping.implementation.dao.InMemoryDAO;
-import org.opendaylight.lispflowmapping.implementation.lisp.LispService;
import org.opendaylight.lispflowmapping.implementation.lisp.MapResolver;
import org.opendaylight.lispflowmapping.implementation.lisp.MapServer;
-import org.opendaylight.lispflowmapping.lisp.IMapResolver;
-import org.opendaylight.lispflowmapping.lisp.IMapServer;
-import org.opendaylight.lispflowmapping.type.lisp.LispMessage;
+import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
+import org.opendaylight.lispflowmapping.interfaces.dao.ILispTypeConverter;
+import org.opendaylight.lispflowmapping.interfaces.dao.IQueryAll;
+import org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor;
+import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
+import org.opendaylight.lispflowmapping.interfaces.lisp.IMapResolver;
+import org.opendaylight.lispflowmapping.interfaces.lisp.IMapServer;
import org.opendaylight.lispflowmapping.type.lisp.MapNotify;
import org.opendaylight.lispflowmapping.type.lisp.MapRegister;
import org.opendaylight.lispflowmapping.type.lisp.MapReply;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class LispMappingService implements ILispMapping, CommandProvider, IMapResolver, IMapServer {
+public class LispMappingService implements CommandProvider, IFlowMapping {
protected static final Logger logger = LoggerFactory.getLogger(LispMappingService.class);
- private LispIoThread thread;
private ILispDAO lispDao = null;
- private LispService service;
private IMapResolver mapResolver;
private IMapServer mapServer;
LispMappingService serv = new LispMappingService();
serv.setLispDao(new InMemoryDAO());
serv.init();
- serv.thread.start();
- while (true) {
- Thread.sleep(1000);
- }
}
class LispIpv4AddressInMemoryConverter implements ILispTypeConverter<LispIpv4Address, Integer> {
lispDao = dao;
mapResolver = new MapResolver(dao);
mapServer = new MapServer(dao);
- service = new LispService(mapResolver, mapServer);
logger.debug("Registering LispIpv4Address");
lispDao.register(LispIpv4AddressInMemoryConverter.class);
logger.debug("Registering LispIpv6Address");
void unsetLispDao(ILispDAO dao) {
logger.debug("LispDAO was unset in LispMappingService");
- service = null;
mapServer = null;
mapResolver = null;
lispDao = null;
public void init() {
logger.debug("LISP (RFC6830) Mapping Service is initialized!");
- thread = new LispIoThread();
- }
-
- public void start() {
- logger.info("LISP (RFC6830) Mapping Service is up!");
- thread.start();
-
- // OSGI console
registerWithOSGIConsole();
}
bundleContext.registerService(CommandProvider.class.getName(), this, null);
}
- public void stop() {
- thread.stopRunning();
- logger.info("LISP (RFC6830) Mapping Service is down!");
- }
public void destroy() {
logger.debug("LISP (RFC6830) Mapping Service is destroyed!");
- thread = null;
- service = null;
mapResolver = null;
mapServer = null;
}
- private class LispIoThread extends Thread {
- private boolean running;
-
- public LispIoThread() {
- super("Lisp Thread");
- running = true;
- }
-
- @Override
- public void run() {
- DatagramSocket socket;
- int lispPortNumber = LispMessage.PORT_NUM;
- int lispReceiveTimeout = 1000;
- String lispBindAddress = "0.0.0.0";
- logger.info("LISP (RFC6830) Mapping Service is running and listening on " + lispBindAddress);
- try {
- socket = new DatagramSocket(new InetSocketAddress(lispBindAddress, lispPortNumber));
- socket.setSoTimeout(lispReceiveTimeout);
- } catch (SocketException e) {
- logger.warn("Cannot open socket on UDP port " + lispPortNumber, e);
- return;
- }
-
- while (running) {
- byte[] buffer = new byte[4096];
- DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
- try {
- socket.receive(packet);
- } catch (SocketTimeoutException ste) {
- continue;
- } catch (IOException e) {
- // TODO: log
- }
- logger.debug("Handling packet from {}:{} (len={})", packet.getAddress().getHostAddress(), packet.getPort(), packet.getLength());
- try {
- DatagramPacket reply = service.handlePacket(packet);
-
- if (reply == null) {
- continue;
- }
-
- reply.setAddress(packet.getAddress());
- try {
- logger.debug("sending reply to {}:{} (len={})", reply.getAddress().getHostAddress(), reply.getPort(), reply.getLength());
- socket.send(reply);
- } catch (IOException e) {
- // TODO: log
- }
- } catch (RuntimeException e) {
- logger.warn("", e);
- }
- }
-
- socket.close();
- }
-
- public void stopRunning() {
- running = false;
- }
- }
public void _removeEid(final CommandInterpreter ci) {
lispDao.remove(new LispIpv4Address(ci.nextArgument()));
return;
}
- public static String intToIpv4(int address) {
- return ((address >> 24) & 0xff) + "." + //
- ((address >> 16) & 0xff) + "." + //
- ((address >> 8) & 0xff) + "." + //
- ((address >> 0) & 0xff);
- }
public String getHelp() {
StringBuffer help = new StringBuffer();
import org.opendaylight.controller.clustering.services.CacheExistException;
import org.opendaylight.controller.clustering.services.IClusterContainerServices;
import org.opendaylight.controller.clustering.services.IClusterServices;
-import org.opendaylight.lispflowmapping.dao.ILispDAO;
-import org.opendaylight.lispflowmapping.dao.ILispTypeConverter;
-import org.opendaylight.lispflowmapping.dao.IQueryAll;
-import org.opendaylight.lispflowmapping.dao.IRowVisitor;
+import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
+import org.opendaylight.lispflowmapping.interfaces.dao.ILispTypeConverter;
+import org.opendaylight.lispflowmapping.interfaces.dao.IQueryAll;
+import org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
-import org.opendaylight.lispflowmapping.dao.ILispDAO;
-import org.opendaylight.lispflowmapping.dao.ILispTypeConverter;
-import org.opendaylight.lispflowmapping.dao.IQueryAll;
-import org.opendaylight.lispflowmapping.dao.IRowVisitor;
+import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
+import org.opendaylight.lispflowmapping.interfaces.dao.ILispTypeConverter;
+import org.opendaylight.lispflowmapping.interfaces.dao.IQueryAll;
+import org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor;
public class InMemoryDAO implements ILispDAO, IQueryAll {
private Map<Class<?>, Map<Object, Map<String, Object>>> typeToKeysToValues;
import java.util.Map;
-import org.opendaylight.lispflowmapping.dao.ILispDAO;
-import org.opendaylight.lispflowmapping.lisp.IMapResolver;
+import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
+import org.opendaylight.lispflowmapping.interfaces.lisp.IMapResolver;
import org.opendaylight.lispflowmapping.type.lisp.EidRecord;
import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
import java.util.ArrayList;
import java.util.List;
-import org.opendaylight.lispflowmapping.dao.ILispDAO;
-import org.opendaylight.lispflowmapping.dao.ILispDAO.MappingEntry;
-import org.opendaylight.lispflowmapping.lisp.IMapServer;
+import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
+import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO.MappingEntry;
+import org.opendaylight.lispflowmapping.interfaces.lisp.IMapServer;
import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
import org.opendaylight.lispflowmapping.type.lisp.MapNotify;
import org.jmock.api.Invocation;
import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.lispflowmapping.dao.IRowVisitor;
import org.opendaylight.lispflowmapping.implementation.dao.InMemoryDAO;
+import org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor;
import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
import org.opendaylight.lispflowmapping.tools.junit.MockCommandInterpreter;
import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.lispflowmapping.dao.ILispDAO.MappingEntry;
-import org.opendaylight.lispflowmapping.dao.ILispDAO.MappingValueKey;
-import org.opendaylight.lispflowmapping.dao.ILispTypeConverter;
+import org.opendaylight.lispflowmapping.interfaces.dao.ILispTypeConverter;
+import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO.MappingEntry;
+import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO.MappingValueKey;
import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.lispflowmapping.dao.ILispDAO;
+import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
import org.opendaylight.lispflowmapping.type.lisp.EidRecord;
import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.lispflowmapping.dao.ILispDAO;
-import org.opendaylight.lispflowmapping.dao.ILispDAO.MappingEntry;
+import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
+import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO.MappingEntry;
import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
import org.opendaylight.lispflowmapping.type.lisp.MapNotify;
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.opendaylight.lispflowmapping</groupId>
+ <artifactId>mappingservice-parent</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>mappingservice.northbound</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ </Export-Package>
+ <Import-Package>
+ org.opendaylight.lispflowmapping.interfaces.lisp,
+ org.opendaylight.lispflowmapping.type,
+ org.opendaylight.lispflowmapping.type.lisp,
+ org.opendaylight.lispflowmapping.type.lisp.address
+ </Import-Package>
+ <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>
+ <Service-Component>
+ </Service-Component>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.lispflowmapping</groupId>
+ <artifactId>mappingservice.api</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+</project>
--- /dev/null
+package org.opendaylight.lispflowmapping.northbound;
+
+public interface INorthboundService {
+
+}
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping;
+package org.opendaylight.lispflowmapping.northbound;
+
+
+public class NorthboundService implements INorthboundService {
+
+
-public interface ILispMapping {
}
<modules>
<module>api</module>
<module>implementation</module>
+ <module>southbound</module>
+ <module>northbound</module>
</modules>
<dependencies>
<dependency>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.opendaylight.lispflowmapping</groupId>
+ <artifactId>mappingservice-parent</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>mappingservice.southbound</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <!--version>2.3.6</version-->
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ </Export-Package>
+ <Import-Package>
+ org.opendaylight.controller.sal.core,
+ org.apache.felix.dm,
+ org.apache.commons.lang3.builder,
+ org.osgi.service.component,
+ org.slf4j,
+ org.eclipse.osgi.framework.console,
+ org.osgi.framework,
+ org.opendaylight.lispflowmapping.interfaces.lisp,
+ org.opendaylight.lispflowmapping.type,
+ org.opendaylight.lispflowmapping.type.lisp,
+ org.opendaylight.lispflowmapping.type.lisp.address,
+ org.opendaylight.controller.clustering.services
+ </Import-Package>
+ <Bundle-Activator>
+ org.opendaylight.lispflowmapping.southbound.Activator
+ </Bundle-Activator>
+ <Service-Component>
+ </Service-Component>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.lispflowmapping</groupId>
+ <artifactId>mappingservice.api</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+</project>
--- /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.southbound;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.felix.dm.Component;
+import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
+import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Main application activator class for registering the dependencies and
+ * initialising the Mapping Service application.
+ *
+ */
+
+public class Activator extends ComponentActivatorAbstractBase {
+
+ /*
+ * Logger instance
+ */
+ protected static final Logger logger = LoggerFactory.getLogger(Activator.class);
+
+ /**
+ * Function called when the activator starts just after some initializations
+ * are done by the ComponentActivatorAbstractBase.
+ *
+ */
+ @Override
+ public void init() {
+ }
+
+ /**
+ * Function called when the activator stops just before the cleanup done by
+ * ComponentActivatorAbstractBase
+ *
+ */
+ @Override
+ public void destroy() {
+ }
+
+ /**
+ * Function that is used to communicate to dependency manager the list of
+ * known implementations for services inside a container
+ *
+ *
+ * @return An array containing all the CLASS objects that will be
+ * instantiated in order to get an fully working implementation
+ * Object
+ */
+ @Override
+ public Object[] getImplementations() {
+ Object[] res = { LispSouthboundPlugin.class };
+ return res;
+ }
+
+ /**
+ * Function that is called when configuration of the dependencies is
+ * required.
+ *
+ * @param c
+ * dependency manager Component object, used for configuring the
+ * dependencies exported and imported
+ * @param imp
+ * Implementation class that is being configured, needed as long
+ * as the same routine can configure multiple implementations
+ * @param containerName
+ * The containerName being configured, this allow also optional
+ * per-container different behavior if needed, usually should not
+ * be the case though.
+ */
+ @Override
+ public void configureInstance(Component c, Object imp, String containerName) {
+ if (imp.equals(LispSouthboundPlugin.class)) {
+ // export the service
+ Dictionary<String, String> props = new Hashtable<String, String>();
+ props.put("name", "mappingservice");
+ c.setInterface(new String[] { ILispSouthboundPlugin.class.getName() }, props);
+ c.add(createContainerServiceDependency(containerName).setService(IFlowMapping.class).setCallbacks("setFlowMappingService", "unsetFlowMappingService")
+ .setRequired(true));
+ }
+ }
+
+ /**
+ * Method which tells how many Global implementations are supported by the
+ * bundle. This way we can tune the number of components created. This
+ * components will be created ONLY at the time of bundle startup and will be
+ * destroyed only at time of bundle destruction, this is the major
+ * difference with the implementation retrieved via getImplementations where
+ * all of them are assumed to be in a container !
+ *
+ *
+ * @return The list of implementations the bundle will support, in Global
+ * version
+ */
+ @Override
+ protected Object[] getGlobalImplementations() {
+ return null;
+ }
+
+ /**
+ * Configure the dependency for a given instance Global
+ *
+ * @param c
+ * Component assigned for this instance, this will be what will
+ * be used for configuration
+ * @param imp
+ * implementation to be configured
+ * @param containerName
+ * container on which the configuration happens
+ */
+ @Override
+ protected void configureGlobalInstance(Component c, Object imp) {
+
+ }
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound;
+
+
+public interface ILispSouthboundPlugin {
+}
--- /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.southbound;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetSocketAddress;
+import java.net.SocketException;
+import java.net.SocketTimeoutException;
+
+import org.eclipse.osgi.framework.console.CommandProvider;
+import org.opendaylight.lispflowmapping.interfaces.lisp.IFlowMapping;
+import org.opendaylight.lispflowmapping.southbound.lisp.LispSouthboundService;
+import org.opendaylight.lispflowmapping.southbound.serializer.LispMessage;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LispSouthboundPlugin implements ILispSouthboundPlugin {
+ protected static final Logger logger = LoggerFactory.getLogger(LispSouthboundPlugin.class);
+
+ private LispIoThread thread;
+ private LispSouthboundService service;
+
+
+ void setFlowMappingService(IFlowMapping mappingService) {
+ logger.debug("FlowMapping set in LispSouthbound");
+ service = new LispSouthboundService(mappingService, mappingService);
+ logger.debug("Registering LispIpv4Address");
+ logger.debug("Registering LispIpv6Address");
+ }
+
+ void unsetFlowMappingService(IFlowMapping mappingService) {
+ logger.debug("LispDAO was unset in LispMappingService");
+ service = null;
+ }
+
+ public void init() {
+ logger.debug("LISP (RFC6830) Mapping Service is initialized!");
+ thread = new LispIoThread();
+ }
+
+ public void start() {
+ logger.info("LISP (RFC6830) Mapping Service is up!");
+ thread.start();
+
+ // OSGI console
+ registerWithOSGIConsole();
+ }
+
+ private void registerWithOSGIConsole() {
+ BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
+ bundleContext.registerService(CommandProvider.class.getName(), this, null);
+ }
+
+ public void stop() {
+ thread.stopRunning();
+ logger.info("LISP (RFC6830) Mapping Service is down!");
+ }
+
+ public void destroy() {
+ logger.debug("LISP (RFC6830) Mapping Service is destroyed!");
+ thread = null;
+ service = null;
+ }
+
+ private class LispIoThread extends Thread {
+ private boolean running;
+
+ public LispIoThread() {
+ super("Lisp Thread");
+ running = true;
+ }
+
+ @Override
+ public void run() {
+ DatagramSocket socket;
+ int lispPortNumber = LispMessage.PORT_NUM;
+ int lispReceiveTimeout = 1000;
+ String lispBindAddress = "0.0.0.0";
+ logger.info("LISP (RFC6830) Mapping Service is running and listening on " + lispBindAddress);
+ try {
+ socket = new DatagramSocket(new InetSocketAddress(lispBindAddress, lispPortNumber));
+ socket.setSoTimeout(lispReceiveTimeout);
+ } catch (SocketException e) {
+ logger.warn("Cannot open socket on UDP port " + lispPortNumber, e);
+ return;
+ }
+
+ while (running) {
+ byte[] buffer = new byte[4096];
+ DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
+ try {
+ socket.receive(packet);
+ } catch (SocketTimeoutException ste) {
+ continue;
+ } catch (IOException e) {
+ // TODO: log
+ }
+ logger.debug("Handling packet from {}:{} (len={})", packet.getAddress().getHostAddress(), packet.getPort(), packet.getLength());
+ try {
+ DatagramPacket reply = service.handlePacket(packet);
+
+ if (reply == null) {
+ continue;
+ }
+
+ reply.setAddress(packet.getAddress());
+ try {
+ logger.debug("sending reply to {}:{} (len={})", reply.getAddress().getHostAddress(), reply.getPort(), reply.getLength());
+ socket.send(reply);
+ } catch (IOException e) {
+ // TODO: log
+ }
+ } catch (RuntimeException e) {
+ logger.warn("", e);
+ }
+ }
+
+ socket.close();
+ }
+
+ public void stopRunning() {
+ running = false;
+ }
+ }
+
+
+ public static String intToIpv4(int address) {
+ return ((address >> 24) & 0xff) + "." + //
+ ((address >> 16) & 0xff) + "." + //
+ ((address >> 8) & 0xff) + "." + //
+ ((address >> 0) & 0xff);
+ }
+
+ public String getHelp() {
+ StringBuffer help = new StringBuffer();
+ help.append("---LISP Southbound Plugin---\n");
+ return help.toString();
+ }
+
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound.lisp;
+
+import java.net.DatagramPacket;
+
+public interface ILispSouthboundService {
+
+ public DatagramPacket handlePacket(DatagramPacket packet);
+
+}
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.implementation.lisp;
-
-import static org.opendaylight.lispflowmapping.util.ByteUtil.getUnsignedByte;
+package org.opendaylight.lispflowmapping.southbound.lisp;
import java.net.DatagramPacket;
import java.nio.ByteBuffer;
-import org.opendaylight.lispflowmapping.lisp.IMapResolver;
-import org.opendaylight.lispflowmapping.lisp.IMapServer;
-import org.opendaylight.lispflowmapping.type.exception.LispMalformedPacketException;
-import org.opendaylight.lispflowmapping.type.lisp.LispMessage;
-import org.opendaylight.lispflowmapping.type.lisp.LispMessageEnum;
+import org.opendaylight.lispflowmapping.interfaces.lisp.IMapResolver;
+import org.opendaylight.lispflowmapping.interfaces.lisp.IMapServer;
+import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
+import org.opendaylight.lispflowmapping.southbound.lisp.network.PacketHeader;
+import org.opendaylight.lispflowmapping.southbound.serializer.LispMessage;
+import org.opendaylight.lispflowmapping.southbound.serializer.LispMessageEnum;
+import org.opendaylight.lispflowmapping.southbound.serializer.MapNotifySerializer;
+import org.opendaylight.lispflowmapping.southbound.serializer.MapRegisterSerializer;
+import org.opendaylight.lispflowmapping.southbound.serializer.MapReplySerializer;
+import org.opendaylight.lispflowmapping.southbound.serializer.MapRequestSerializer;
+import org.opendaylight.lispflowmapping.southbound.util.ByteUtil;
import org.opendaylight.lispflowmapping.type.lisp.MapNotify;
import org.opendaylight.lispflowmapping.type.lisp.MapRegister;
import org.opendaylight.lispflowmapping.type.lisp.MapReply;
import org.opendaylight.lispflowmapping.type.lisp.MapRequest;
-import org.opendaylight.lispflowmapping.type.network.PacketHeader;
-public class LispService {
+public class LispSouthboundService implements ILispSouthboundService{
private IMapResolver mapResolver;
private IMapServer mapServer;
- public LispService(IMapResolver mapResolver, IMapServer mapServer) {
+ public LispSouthboundService(IMapResolver mapResolver, IMapServer mapServer) {
this.mapResolver = mapResolver;
this.mapServer = mapServer;
}
public DatagramPacket handlePacket(DatagramPacket packet) {
ByteBuffer inBuffer = ByteBuffer.wrap(packet.getData(), 0, packet.getLength());
- Object lispType = LispMessageEnum.valueOf((byte) (getUnsignedByte(inBuffer, LispMessage.Pos.TYPE) >> 4));
+ Object lispType = LispMessageEnum.valueOf((byte) (ByteUtil.getUnsignedByte(inBuffer, LispMessage.Pos.TYPE) >> 4));
if (lispType == LispMessageEnum.EncapsulatedControlMessage) {
return handleMapRequest(inBuffer);
} else {
private DatagramPacket handleMapRequest(ByteBuffer inBuffer) {
int encapsulatedSourcePort = extractEncapsulatedSourcePort(inBuffer);
- MapRequest request = MapRequest.deserialize(inBuffer);
+ MapRequest request = MapRequestSerializer.getInstance().deserialize(inBuffer);
MapReply mapReply = mapResolver.handleMapRequest(request);
- ByteBuffer outBuffer = mapReply.serialize();
+ ByteBuffer outBuffer = MapReplySerializer.getInstance().serialize(mapReply);
DatagramPacket replyPacket = new DatagramPacket(outBuffer.array(), outBuffer.capacity());
replyPacket.setPort(encapsulatedSourcePort);
}
private DatagramPacket handleMapRegister(ByteBuffer inBuffer) {
- MapRegister mapRegister = MapRegister.deserialize(inBuffer);
+ MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(inBuffer);
MapNotify mapNotify = mapServer.handleMapRegister(mapRegister);
if (mapNotify != null) {
- ByteBuffer outBuffer = mapNotify.serialize();
+ ByteBuffer outBuffer = MapNotifySerializer.getInstance().serialize(mapNotify);
DatagramPacket notify = new DatagramPacket(outBuffer.array(), outBuffer.limit());
notify.setPort(LispMessage.PORT_NUM);
return notify;
* 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.exception;
+package org.opendaylight.lispflowmapping.southbound.lisp.exception;
public class LispMalformedPacketException extends RuntimeException {
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.type.network;
+package org.opendaylight.lispflowmapping.southbound.lisp.network;
public interface PacketHeader {
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound.serializer;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.southbound.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.type.lisp.EidRecord;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
+
+public class EidRecordSerializer {
+
+ private static final EidRecordSerializer INSTANCE = new EidRecordSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private EidRecordSerializer() {
+ }
+
+ public static EidRecordSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ public EidRecord deserialize(ByteBuffer requestBuffer) {
+ /* byte reserved = */requestBuffer.get();
+ byte maskLength = requestBuffer.get();
+ LispAddress prefix = LispAddressSerializer.getInstance().deserialize(requestBuffer);
+ return new EidRecord(maskLength, prefix);
+ }
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound.serializer;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.southbound.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.southbound.serializer.address.LispAddressSerializerFactory;
+import org.opendaylight.lispflowmapping.southbound.util.ByteUtil;
+import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
+import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
+import org.opendaylight.lispflowmapping.type.lisp.MapReplyAction;
+
+public class EidToLocatorRecordSerializer {
+
+ private static final EidToLocatorRecordSerializer INSTANCE = new EidToLocatorRecordSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private EidToLocatorRecordSerializer() {
+ }
+
+ public static EidToLocatorRecordSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ public EidToLocatorRecord deserialize(ByteBuffer buffer) {
+ EidToLocatorRecord eidToLocatorRecord = new EidToLocatorRecord();
+ eidToLocatorRecord.setRecordTtl(buffer.getInt());
+ byte locatorCount = buffer.get();
+ eidToLocatorRecord.setMaskLength(buffer.get());
+ byte actionAndAuthoritative = buffer.get();
+ eidToLocatorRecord.setAction(MapReplyAction.valueOf(actionAndAuthoritative >> 5));
+ eidToLocatorRecord.setAuthoritative(ByteUtil.extractBit(actionAndAuthoritative, Flags.AUTHORITATIVE));
+ buffer.position(buffer.position() + Length.RESERVED);
+ eidToLocatorRecord.setMapVersion(buffer.getShort());
+
+ eidToLocatorRecord.setPrefix(LispAddressSerializer.getInstance().deserialize(buffer));
+ for (int i = 0; i < locatorCount; i++) {
+ eidToLocatorRecord.addLocator(LocatorRecordSerializer.getInstance().deserialize(buffer));
+ }
+
+ return eidToLocatorRecord;
+ }
+
+ public void serialize(ByteBuffer replyBuffer, EidToLocatorRecord record) {
+ replyBuffer.putInt(record.getRecordTtl());
+ replyBuffer.put((byte) record.getLocators().size());
+ replyBuffer.put((byte) record.getMaskLength());
+ replyBuffer.put((byte) ((record.getAction().getCode() << 5) | //
+ 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());
+
+ 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());
+ for (LocatorRecord locatorRecord : record.getLocators()) {
+ size += LocatorRecordSerializer.getInstance().getSerializationSize(locatorRecord);
+ }
+ return size;
+ }
+
+ private interface Flags {
+ int AUTHORITATIVE = 0x10;
+ }
+
+ private interface Length {
+ int HEADER_SIZE = 10;
+ int RESERVED = 1;
+ }
+}
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.type.lisp;
+package org.opendaylight.lispflowmapping.southbound.serializer;
public interface LispMessage {
- int PORT_NUM = 4342;
+ int PORT_NUM = 4342;
interface Pos {
int TYPE = 0;
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.type.lisp;
+package org.opendaylight.lispflowmapping.southbound.serializer;
public enum LispMessageEnum {
MapRequest((byte) 1), //
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound.serializer;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.southbound.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.southbound.serializer.address.LispAddressSerializerFactory;
+import org.opendaylight.lispflowmapping.southbound.util.ByteUtil;
+import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
+
+public class LocatorRecordSerializer {
+
+ private static final LocatorRecordSerializer INSTANCE = new LocatorRecordSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private LocatorRecordSerializer() {
+ }
+
+ public static LocatorRecordSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ protected LocatorRecord deserialize(ByteBuffer buffer) {
+ LocatorRecord record = new LocatorRecord();
+ record.setPriority(buffer.get());
+ record.setWeight(buffer.get());
+ record.setMulticastPriority(buffer.get());
+ record.setMulticastWeight(buffer.get());
+ byte flags = (byte) buffer.getShort();
+ record.setLocalLocator(ByteUtil.extractBit(flags, Flags.LOCAL_LOCATOR));
+ record.setRlocProbed(ByteUtil.extractBit(flags, Flags.RLOC_PROBED));
+ record.setRouted(ByteUtil.extractBit(flags, Flags.ROUTED));
+ record.setLocator(LispAddressSerializer.getInstance().deserialize(buffer));
+ return record;
+ }
+
+ public void serialize(ByteBuffer replyBuffer, LocatorRecord record) {
+ replyBuffer.put(record.getPriority());
+ replyBuffer.put(record.getWeight());
+ replyBuffer.put(record.getMulticastPriority());
+ replyBuffer.put(record.getMulticastWeight());
+ replyBuffer.position(replyBuffer.position() + Length.UNUSED_FLAGS);
+ 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());
+ }
+
+ public int getSerializationSize(LocatorRecord record) {
+ LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(record.getLocator().getAfi());
+ return Length.HEADER_SIZE + serializer.getAddressSize(record.getLocator());
+ }
+
+ private interface Flags {
+ int LOCAL_LOCATOR = 0x04;
+ int RLOC_PROBED = 0x02;
+ int ROUTED = 0x01;
+ }
+
+ private interface Length {
+ int HEADER_SIZE = 6;
+ int UNUSED_FLAGS = 1;
+ }
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound.serializer;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
+import org.opendaylight.lispflowmapping.type.lisp.MapNotify;
+
+/**
+ * This class deals with serializing map notify from the java object to udp.
+ */
+public class MapNotifySerializer {
+
+ private static final MapNotifySerializer INSTANCE = new MapNotifySerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private MapNotifySerializer() {
+ }
+
+ public static MapNotifySerializer getInstance() {
+ return INSTANCE;
+ }
+
+
+ public ByteBuffer serialize(MapNotify mapNotify) {
+ int size = Length.HEADER_SIZE + mapNotify.getAuthenticationData().length;
+ for (EidToLocatorRecord eidToLocatorRecord : mapNotify.getEidToLocatorRecords()) {
+ size += EidToLocatorRecordSerializer.getInstance().getSerializationSize(eidToLocatorRecord);
+ }
+
+ ByteBuffer replyBuffer = ByteBuffer.allocate(size);
+ replyBuffer.put((byte) (LispMessageEnum.MapNotify.getValue() << 4));
+ replyBuffer.position(replyBuffer.position() + Length.RES);
+ replyBuffer.put((byte) mapNotify.getEidToLocatorRecords().size());
+ replyBuffer.putLong(mapNotify.getNonce());
+ replyBuffer.putShort(mapNotify.getKeyId());
+ replyBuffer.putShort((short) mapNotify.getAuthenticationData().length);
+ if (mapNotify.getAuthenticationData() != null) {
+ replyBuffer.put(mapNotify.getAuthenticationData());
+ }
+
+ for (EidToLocatorRecord eidToLocatorRecord : mapNotify.getEidToLocatorRecords()) {
+ EidToLocatorRecordSerializer.getInstance().serialize(replyBuffer, eidToLocatorRecord);
+ }
+
+ replyBuffer.clear();
+ return replyBuffer;
+ }
+
+ private interface Length {
+ int HEADER_SIZE = 16;
+ int RES = 2;
+ }
+
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound.serializer;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
+import org.opendaylight.lispflowmapping.southbound.util.ByteUtil;
+import org.opendaylight.lispflowmapping.type.lisp.MapRegister;
+
+
+/**
+ * This class deals with deserializing map register from udp to the java object.
+ */
+public class MapRegisterSerializer {
+
+ private static final MapRegisterSerializer INSTANCE = new MapRegisterSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private MapRegisterSerializer() {
+ }
+
+ public static MapRegisterSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ public MapRegister deserialize(ByteBuffer registerBuffer) {
+ try {
+ MapRegister mapRegister = new MapRegister();
+
+ mapRegister.setProxyMapReply(ByteUtil.extractBit(registerBuffer.get(), Flags.PROXY));
+
+ registerBuffer.position(registerBuffer.position() + Length.RES);
+ mapRegister.setWantMapNotify(ByteUtil.extractBit(registerBuffer.get(), Flags.WANT_MAP_REPLY));
+ byte recordCount = registerBuffer.get();
+ mapRegister.setNonce(registerBuffer.getLong());
+ mapRegister.setKeyId(registerBuffer.getShort());
+
+ short authenticationLength = registerBuffer.getShort();
+ byte[] authenticationData = new byte[authenticationLength];
+ registerBuffer.get(authenticationData);
+ mapRegister.setAuthenticationData(authenticationData);
+
+ for (int i = 0; i < recordCount; i++) {
+ mapRegister.addEidToLocator(EidToLocatorRecordSerializer.getInstance().deserialize(registerBuffer));
+ }
+ return mapRegister;
+ } catch (RuntimeException re) {
+ throw new LispMalformedPacketException("Couldn't deserialize Map-Register (len=" + registerBuffer.capacity() + ")", re);
+ }
+
+ }
+
+ private interface Flags {
+ byte PROXY = 0x08;
+ byte WANT_MAP_REPLY = 0x01;
+ }
+
+ private interface Length {
+ int RES = 1;
+ }
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound.serializer;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
+import org.opendaylight.lispflowmapping.type.lisp.MapReply;
+
+
+/**
+ * This class deals with serializing map reply from the java object to udp.
+ */
+public class MapReplySerializer {
+
+ private static final MapReplySerializer INSTANCE = new MapReplySerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private MapReplySerializer() {
+ }
+
+ public static MapReplySerializer getInstance() {
+ return INSTANCE;
+ }
+
+ public ByteBuffer serialize(MapReply mapReply) {
+ int size = Length.HEADER_SIZE;
+ for (EidToLocatorRecord eidToLocatorRecord : mapReply.getEidToLocatorRecords()) {
+ size += EidToLocatorRecordSerializer.getInstance().getSerializationSize(eidToLocatorRecord);
+ }
+
+ ByteBuffer replyBuffer = ByteBuffer.allocate(size);
+
+ replyBuffer.put((byte) ((LispMessageEnum.MapReply.getValue() << 4) | //
+ (mapReply.isProbe() ? Flags.PROBE : 0x00) | //
+ (mapReply.isEchoNonceEnabled() ? Flags.ECHO_NONCE_ENABLED : 0x00)));
+
+ replyBuffer.position(replyBuffer.position() + Length.RES);
+ replyBuffer.put((byte) mapReply.getEidToLocatorRecords().size());
+ replyBuffer.putLong(mapReply.getNonce());
+ for (EidToLocatorRecord eidToLocatorRecord : mapReply.getEidToLocatorRecords()) {
+ EidToLocatorRecordSerializer.getInstance().serialize(replyBuffer, eidToLocatorRecord);
+ }
+ return replyBuffer;
+ }
+
+ private interface Length {
+ int RES = 2;
+ int HEADER_SIZE = 12;
+ }
+
+ private interface Flags {
+ int PROBE = 0x08;
+ int ECHO_NONCE_ENABLED = 0x04;
+ }
+
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound.serializer;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
+import org.opendaylight.lispflowmapping.southbound.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.southbound.util.ByteUtil;
+import org.opendaylight.lispflowmapping.type.lisp.MapRequest;
+
+
+/**
+ * This class deals with deserializing map request from udp to the java object.
+ */
+public class MapRequestSerializer {
+
+ private static final MapRequestSerializer INSTANCE = new MapRequestSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private MapRequestSerializer() {
+ }
+
+ public static MapRequestSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ public MapRequest deserialize(ByteBuffer requestBuffer) {
+ try {
+ MapRequest mapRequest = new MapRequest();
+
+ byte typeAndFlags = requestBuffer.get();
+ mapRequest.setAuthoritative(ByteUtil.extractBit(typeAndFlags, Flags.AUTHORITATIVE));
+ mapRequest.setMapDataPresent(ByteUtil.extractBit(typeAndFlags, Flags.MAP_DATA_PRESENT));
+ mapRequest.setProbe(ByteUtil.extractBit(typeAndFlags, Flags.PROBE));
+ mapRequest.setSmr(ByteUtil.extractBit(typeAndFlags, Flags.SMR));
+
+ byte moreFlags = requestBuffer.get();
+ mapRequest.setPitr(ByteUtil.extractBit(moreFlags, Flags.PITR));
+ mapRequest.setSmrInvoked(ByteUtil.extractBit(moreFlags, Flags.SMR_INVOKED));
+
+ int itrCount = requestBuffer.get() + 1;
+ int recordCount = requestBuffer.get();
+ mapRequest.setNonce(requestBuffer.getLong());
+ mapRequest.setSourceEid(LispAddressSerializer.getInstance().deserialize(requestBuffer));
+
+ for (int i = 0; i < itrCount; i++) {
+ mapRequest.addItrRloc(LispAddressSerializer.getInstance().deserialize(requestBuffer));
+ }
+
+ for (int i = 0; i < recordCount; i++) {
+ mapRequest.addEidRecord(EidRecordSerializer.getInstance().deserialize(requestBuffer));
+ }
+ return mapRequest;
+ } catch (RuntimeException re) {
+ throw new LispMalformedPacketException("Couldn't deserialize Map-Request (len=" + requestBuffer.capacity() + ")", re);
+ }
+ }
+
+ public interface Flags {
+ byte AUTHORITATIVE = 0x08;
+ byte MAP_DATA_PRESENT = 0x04;
+ byte PROBE = 0x02;
+ byte SMR = 0x01;
+
+ byte PITR = (byte) 0x80;
+ byte SMR_INVOKED = 0x40;
+ }
+
+
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound.serializer.address;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.type.lisp.address.LispASAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
+
+public class LispASAddressSerializer extends LispAddressSerializer {
+
+ private static final LispASAddressSerializer INSTANCE = new LispASAddressSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private LispASAddressSerializer() {
+ }
+
+ public static LispASAddressSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ public static LispASAddress valueOf(ByteBuffer buffer) {
+ throw new RuntimeException("Not implemented");
+ }
+
+ @Override
+ public int getAddressSize(LispAddress lispAddress) {
+ throw new RuntimeException("Not implemented");
+
+ }
+
+ @Override
+ public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
+ throw new RuntimeException("Not implemented");
+ }
+
+
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound.serializer.address;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
+import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
+
+public class LispAddressSerializer {
+
+ private static final LispAddressSerializer INSTANCE = new LispAddressSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ protected LispAddressSerializer() {
+ }
+
+ public static LispAddressSerializer getInstance() {
+ return INSTANCE;
+ }
+
+
+ public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
+ throw new RuntimeException("Not implemented");
+ }
+
+ protected void internalSerialize(ByteBuffer buffer, LispAddress lispAddress) {
+ buffer.putShort(lispAddress.getAfi().getIanaCode());
+ }
+
+ public int getAddressSize(LispAddress lispAddress) {
+ return Length.AFI;
+ }
+
+ public LispAddress deserialize(ByteBuffer buffer) {
+ short afi = buffer.getShort();
+ AddressFamilyNumberEnum afiType = AddressFamilyNumberEnum.valueOf(afi);
+ LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(afiType);
+ if (serializer == null) {
+ throw new LispMalformedPacketException("Unknown AFI type=" + afiType);
+ }
+ try {
+ return serializer.deserialize(buffer);
+ } catch (Exception e) {
+ throw new LispMalformedPacketException(e.getMessage());
+ }
+ }
+
+ private interface Length {
+ int AFI = 2;
+ }
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound.serializer.address;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
+import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
+
+public class LispAddressSerializerFactory {
+
+ private static Map<AddressFamilyNumberEnum, LispAddressSerializer> afiToSearializerMap;
+ private static Map<LispCanonicalAddressFormatEnum, LispLCAFAddressSerializer> lcafToSearializerMap;
+
+ private static void initializeMap() {
+ afiToSearializerMap = new HashMap<AddressFamilyNumberEnum, LispAddressSerializer>();
+ afiToSearializerMap.put(AddressFamilyNumberEnum.AS, LispASAddressSerializer.getInstance());
+ afiToSearializerMap.put(AddressFamilyNumberEnum.IP, LispIpv4AddressSerializer.getInstance());
+ afiToSearializerMap.put(AddressFamilyNumberEnum.IP6, LispIpv6AddressSerializer.getInstance());
+ afiToSearializerMap.put(AddressFamilyNumberEnum.LCAF, LispLCAFAddressSerializer.getInstance());
+ 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());
+ }
+
+ public static LispAddressSerializer getSerializer(AddressFamilyNumberEnum afi) {
+ if (afiToSearializerMap == null) {
+ initializeMap();
+ }
+ return afiToSearializerMap.get(afi);
+ }
+
+ public static LispLCAFAddressSerializer getLCAFSerializer(LispCanonicalAddressFormatEnum lcaf) {
+ if (lcafToSearializerMap == null) {
+ initializeMap();
+ }
+ return lcafToSearializerMap.get(lcaf);
+ }
+
+
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound.serializer.address;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispIPAddress;
+
+public abstract class LispIPAddressSerializer extends LispAddressSerializer{
+
+
+ @Override
+ public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
+ LispIPAddress lispIpvAddress = (LispIPAddress)lispAddress;
+ super.internalSerialize(buffer, lispAddress);
+ buffer.put(lispIpvAddress.getAddress().getAddress());
+ }
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound.serializer.address;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
+
+
+public class LispIpv4AddressSerializer extends LispIPAddressSerializer{
+
+ private static final LispIpv4AddressSerializer INSTANCE = new LispIpv4AddressSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private LispIpv4AddressSerializer() {
+ }
+
+ public static LispIpv4AddressSerializer getInstance() {
+ return INSTANCE;
+ }
+
+
+ @Override
+ public int getAddressSize(LispAddress lispAddress) {
+ return super.getAddressSize(lispAddress) + 4;
+ }
+
+ @Override
+ public LispIpv4Address deserialize(ByteBuffer buffer) {
+ byte[] ipBuffer = new byte[4];
+ InetAddress address = null;
+ buffer.get(ipBuffer);
+ try {
+ address = InetAddress.getByAddress(ipBuffer);
+ } catch (UnknownHostException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return new LispIpv4Address(address);
+ }
+
+
+
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound.serializer.address;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv6Address;
+
+
+public class LispIpv6AddressSerializer extends LispIPAddressSerializer{
+
+
+ private static final LispIpv6AddressSerializer INSTANCE = new LispIpv6AddressSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private LispIpv6AddressSerializer() {
+ }
+
+ public static LispIpv6AddressSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public int getAddressSize(LispAddress lispAddress) {
+ return super.getAddressSize(lispAddress) + 16;
+ }
+
+ @Override
+ public LispIpv6Address deserialize(ByteBuffer buffer) {
+ byte[] ipBuffer = new byte[16];
+ InetAddress address = null;
+ buffer.get(ipBuffer);
+ try {
+ address = InetAddress.getByAddress(ipBuffer);
+ } catch (UnknownHostException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return new LispIpv6Address(address);
+ }
+
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound.serializer.address;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
+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();
+
+ // Private constructor prevents instantiation from other classes
+ protected LispLCAFAddressSerializer() {
+ }
+
+ public static LispLCAFAddressSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public LispLCAFAddress deserialize(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);
+ if (serializer == null) {
+ throw new LispMalformedPacketException("Unknown LispLCAFAddress type=" + lispCode);
+ }
+ return serializer.innerDeserialize(buffer, res2, length);
+ }
+
+ 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 + getLcafLength(lispAddress);
+ }
+
+ public 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);
+ }
+
+ @Override
+ protected void internalSerialize(ByteBuffer buffer, LispAddress lispAddress) {
+ super.internalSerialize(buffer, lispAddress);
+ LispLCAFAddress lispLCAFAddress = (LispLCAFAddress)lispAddress;
+ buffer.putShort((short) 0); // RES + Flags.
+ buffer.put(lispLCAFAddress.getType().getLispCode());
+ buffer.put(lispLCAFAddress.getRes2());
+ buffer.putShort(getLcafLength(lispAddress));
+ }
+ private interface Length {
+ int RES = 1;
+ int FLAGS = 1;
+
+ int LCAF_HEADER = 6;
+ }
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound.serializer.address;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispListLCAFAddress;
+
+public class LispListLCAFAddressSerializer extends LispLCAFAddressSerializer{
+
+ private static final LispListLCAFAddressSerializer INSTANCE = new LispListLCAFAddressSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private LispListLCAFAddressSerializer() {
+ }
+
+ public static LispListLCAFAddressSerializer getInstance() {
+ return INSTANCE;
+ }
+
+
+ @Override
+ public short getLcafLength(LispAddress lispAddress) {
+ short totalSize = 0;
+ for (LispAddress address : ((LispListLCAFAddress)lispAddress).getAddresses()) {
+ totalSize += LispAddressSerializerFactory.getSerializer(address.getAfi()).getAddressSize(lispAddress);
+ }
+ return totalSize;
+ }
+
+ @Override
+ public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
+ super.internalSerialize(buffer, lispAddress);
+ for (LispAddress address : ((LispListLCAFAddress)lispAddress).getAddresses()) {
+ LispAddressSerializerFactory.getSerializer(address.getAfi()).serialize(buffer, address);
+ }
+ }
+
+ @Override
+ public LispListLCAFAddress innerDeserialize(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);
+ addresses.add(address);
+ }
+ return new LispListLCAFAddress(res2, addresses);
+ }
+
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound.serializer.address;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispMACAddress;
+
+public class LispMACAddressSerializer extends LispAddressSerializer{
+
+ private static final LispMACAddressSerializer INSTANCE = new LispMACAddressSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private LispMACAddressSerializer() {
+ }
+
+ public static LispMACAddressSerializer getInstance() {
+ return INSTANCE;
+ }
+
+
+ @Override
+ public int getAddressSize(LispAddress lispAddress) {
+ return super.getAddressSize(lispAddress) + 6;
+
+ }
+
+ @Override
+ public LispMACAddress deserialize(ByteBuffer buffer) {
+ byte[] macBuffer = new byte[6];
+ buffer.get(macBuffer);
+ return new LispMACAddress(macBuffer);
+ }
+
+ @Override
+ public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
+ LispMACAddress lispMACAddress = (LispMACAddress)lispAddress;
+ super.internalSerialize(buffer, lispMACAddress);
+ buffer.put(lispMACAddress.getMAC());
+ }
+
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound.serializer.address;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispNoAddress;
+
+public class LispNoAddressSerializer extends LispAddressSerializer{
+
+ private static final LispNoAddressSerializer INSTANCE = new LispNoAddressSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private LispNoAddressSerializer() {
+ }
+
+ public static LispNoAddressSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public LispNoAddress deserialize(ByteBuffer buffer) {
+ return new LispNoAddress();
+ }
+
+ @Override
+ public int getAddressSize(LispAddress lispAddress) {
+ return super.getAddressSize(lispAddress);
+ }
+
+ @Override
+ public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
+ }
+
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.southbound.serializer.address;
+
+import java.nio.ByteBuffer;
+
+import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispSegmentLCAFAddress;
+
+public class LispSegmentLCAFAddressSerializer extends LispLCAFAddressSerializer{
+
+ private static final LispSegmentLCAFAddressSerializer INSTANCE = new LispSegmentLCAFAddressSerializer();
+
+ // Private constructor prevents instantiation from other classes
+ private LispSegmentLCAFAddressSerializer() {
+ }
+
+ public static LispSegmentLCAFAddressSerializer getInstance() {
+ return INSTANCE;
+ }
+
+
+ @Override
+ public short getLcafLength(LispAddress lispAddress) {
+ LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(((LispSegmentLCAFAddress)lispAddress).getAddress().getAfi());
+ return (short) (Length.INSTANCE + serializer.getAddressSize(lispAddress));
+ }
+
+ @Override
+ public void serialize(ByteBuffer buffer, LispAddress lispAddress) {
+ super.internalSerialize(buffer, lispAddress);
+ buffer.putInt(((LispSegmentLCAFAddress)lispAddress).getInstanceId());
+ LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(((LispSegmentLCAFAddress)lispAddress).getAddress().getAfi());
+ if (serializer == null) {
+ throw new LispMalformedPacketException("Unknown AFI type=" + ((LispSegmentLCAFAddress)lispAddress).getAddress().getAfi());
+ }
+ serializer.serialize(buffer, ((LispSegmentLCAFAddress)lispAddress).getAddress());
+ }
+
+ @Override
+ public LispSegmentLCAFAddress innerDeserialize(ByteBuffer buffer, byte res2, short length) {
+ int instanceId = buffer.getInt();
+ LispAddress address = LispAddressSerializer.getInstance().deserialize(buffer);
+
+ return new LispSegmentLCAFAddress(res2, instanceId, address);
+ }
+
+ private interface Length {
+ int INSTANCE = 4;
+ }
+}
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.util;
+package org.opendaylight.lispflowmapping.southbound.util;
import java.nio.ByteBuffer;
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.implementation.lisp;
+package org.opendaylight.lispflowmapping.southbound.lisp;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
-import static org.opendaylight.lispflowmapping.util.ByteUtil.getShort;
import java.net.DatagramPacket;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
-import org.opendaylight.lispflowmapping.lisp.IMapResolver;
-import org.opendaylight.lispflowmapping.lisp.IMapServer;
+import org.opendaylight.lispflowmapping.interfaces.lisp.IMapResolver;
+import org.opendaylight.lispflowmapping.interfaces.lisp.IMapServer;
+import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
+import org.opendaylight.lispflowmapping.southbound.serializer.LispMessage;
+import org.opendaylight.lispflowmapping.southbound.serializer.LispMessageEnum;
+import org.opendaylight.lispflowmapping.southbound.util.ByteUtil;
+import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
-import org.opendaylight.lispflowmapping.type.exception.LispMalformedPacketException;
import org.opendaylight.lispflowmapping.type.lisp.EidRecord;
import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
-import org.opendaylight.lispflowmapping.type.lisp.LispMessage;
-import org.opendaylight.lispflowmapping.type.lisp.LispMessageEnum;
import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
import org.opendaylight.lispflowmapping.type.lisp.MapNotify;
import org.opendaylight.lispflowmapping.type.lisp.MapRegister;
import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv6Address;
-import org.opendaylight.lispflowmapping.util.ByteUtil;
-import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-public class LispServiceTest extends BaseTestCase {
+public class LispSouthboundServiceTest extends BaseTestCase {
- private LispService testedLispService;
+ private LispSouthboundService testedLispService;
private IMapResolver mapResolver;
private IMapServer mapServer;
private byte[] mapRequestPacket;
super.before();
mapResolver = context.mock(IMapResolver.class);
mapServer = context.mock(IMapServer.class);
- testedLispService = new LispService(mapResolver, mapServer);
+ testedLispService = new LispSouthboundService(mapResolver, mapServer);
mapRegisterSaver = new ValueSaverAction<MapRegister>();
mapRequestSaver = new ValueSaverAction<MapRequest>();
assertEquals(expectedRecordCount, result[MapReplyIpv4SingleLocatorPos.RECORD_COUNT]);
assertEquals(eidToLocator.getMaskLength(), result[MapReplyIpv4SingleLocatorPos.EID_MASK_LEN]);
- assertEquals(AddressFamilyNumberEnum.IP.getIanaCode(), getShort(result, MapReplyIpv4SingleLocatorPos.AFI_TYPE));
+ assertEquals(AddressFamilyNumberEnum.IP.getIanaCode(), ByteUtil.getShort(result, MapReplyIpv4SingleLocatorPos.AFI_TYPE));
assertEquals(0x0a0014c8, ByteUtil.getInt(result, MapReplyIpv4SingleLocatorPos.EID_PREFIX));
}
assertEquals(expectedRecordCount, result[MapReplyIpv4SingleLocatorPos.RECORD_COUNT]);
assertEquals(eidToLocator.getMaskLength(), result[MapReplyIpv4SingleLocatorPos.EID_MASK_LEN]);
- assertEquals(AddressFamilyNumberEnum.IP6.getIanaCode(), getShort(result, MapReplyIpv4SingleLocatorPos.AFI_TYPE));
+ assertEquals(AddressFamilyNumberEnum.IP6.getIanaCode(), ByteUtil.getShort(result, MapReplyIpv4SingleLocatorPos.AFI_TYPE));
byte[] expectedIpv6 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
ArrayAssert.assertEquals(expectedIpv6, Arrays.copyOfRange(result, 24, 40));
byte expectedLocCount = 1;
assertEquals(expectedLocCount, result[MapReplyIpv4SingleLocatorPos.LOCATOR_COUNT]);
- assertEquals(AddressFamilyNumberEnum.IP.getIanaCode(), getShort(result, MapReplyIpv4SingleLocatorPos.LOC_AFI));
+ assertEquals(AddressFamilyNumberEnum.IP.getIanaCode(), ByteUtil.getShort(result, MapReplyIpv4SingleLocatorPos.LOC_AFI));
assertEquals(0x04030201, ByteUtil.getInt(result, MapReplyIpv4SingleLocatorPos.LOCATOR));
assertEquals(0x01, result[MapReplyIpv4SingleLocatorPos.LOCATOR_RBIT] & 0x01);
assertEquals(2, result[MapReplyIpv4SingleLocatorPos.LOCATOR_COUNT]);
- assertEquals(AddressFamilyNumberEnum.IP.getIanaCode(), getShort(result, MapReplyIpv4SingleLocatorPos.LOC_AFI));
+ assertEquals(AddressFamilyNumberEnum.IP.getIanaCode(), ByteUtil.getShort(result, MapReplyIpv4SingleLocatorPos.LOC_AFI));
assertEquals(0x04030201, ByteUtil.getInt(result, MapReplyIpv4SingleLocatorPos.LOCATOR));
assertEquals(0x01, result[MapReplyIpv4SingleLocatorPos.LOCATOR_RBIT] & 0x01);
- assertEquals(AddressFamilyNumberEnum.IP6.getIanaCode(), getShort(result, MapReplyIpv4SecondLocatorPos.LOC_AFI));
+ assertEquals(AddressFamilyNumberEnum.IP6.getIanaCode(), ByteUtil.getShort(result, MapReplyIpv4SecondLocatorPos.LOC_AFI));
byte[] expectedIpv6Rloc = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
ArrayAssert.assertEquals(expectedIpv6Rloc, Arrays.copyOfRange(result, MapReplyIpv4SecondLocatorPos.LOCATOR,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.lisp;
+package org.opendaylight.lispflowmapping.southbound.serializer;
import static junit.framework.Assert.assertEquals;
import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
import org.opendaylight.lispflowmapping.type.lisp.address.LispNoAddress;
-public class MapNotifyTest extends BaseTestCase {
+public class MapNotifySerializationTest extends BaseTestCase {
@Test
public void serialize__Fields() throws Exception {
byte[] authenticationData = new byte[] { 0x03, 0x01, 0x04, 0x01, 0x05, 0x09, 0x02, 0x06 };
mn.setAuthenticationData(authenticationData);
- ByteBuffer bb = mn.serialize();
+ ByteBuffer bb = MapNotifySerializer.getInstance().serialize(mn);
assertHexEquals((byte) 0x40, bb.get()); // Type + MSByte of reserved
assertEquals(0, bb.getShort()); // Rest of reserved
assertEquals(2, bb.get()); // Record Count
MapNotify mn = new MapNotify();
mn.addEidToLocator(new EidToLocatorRecord().setPrefix(new LispIpv4Address(1)).setRecordTtl(55));
- ByteBuffer bb = mn.serialize();
+ ByteBuffer bb = MapNotifySerializer.getInstance().serialize(mn);
bb.position(bb.position() + 14); // jump to AuthenticationDataLength
assertEquals(0, bb.getShort());
assertEquals(55, bb.getInt());
mn.setAuthenticationData(null);
- bb = mn.serialize();
+ bb = MapNotifySerializer.getInstance().serialize(mn);
bb.position(bb.position() + 14); // jump to AuthenticationDataLength
assertEquals(0, bb.getShort());
assertEquals(55, bb.getInt());
mn.setAuthenticationData(new byte[0]);
- bb = mn.serialize();
+ bb = MapNotifySerializer.getInstance().serialize(mn);
bb.position(bb.position() + 14); // jump to AuthenticationDataLength
assertEquals(0, bb.getShort());
assertEquals(55, bb.getInt());
mn.addEidToLocator(new EidToLocatorRecord().setPrefix(null));
mn.addEidToLocator(new EidToLocatorRecord().setPrefix(new LispNoAddress()));
- ByteBuffer bb = mn.serialize();
+ ByteBuffer bb = MapNotifySerializer.getInstance().serialize(mn);
bb.position(bb.position() + 26); // jump to first record prefix AFI
assertEquals(0, bb.getShort());
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.type.lisp;
+package org.opendaylight.lispflowmapping.southbound.serializer;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import junitx.framework.ArrayAssert;
import org.junit.Test;
-import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
+import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
+import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
+import org.opendaylight.lispflowmapping.type.lisp.MapRegister;
+import org.opendaylight.lispflowmapping.type.lisp.MapReplyAction;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
-public class MapRegisterTest extends BaseTestCase {
+public class MapRegisterSerializationTest extends BaseTestCase {
@Test
public void deserialize__AllFields() throws Exception {
// Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
// Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
//
- MapRegister mr = MapRegister.deserialize(hexToByteBuffer("38 00 01 01 FF BB " //
+ MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB " //
+ "00 00 00 00 00 00 00 01 00 14 e8 f5 0b c5 c5 f2 " //
+ "b0 21 27 a8 21 41 04 f3 46 5a a5 68 89 ec 00 00 " //
+ "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
// Local RLOCs: 192.168.136.10 -- 192.168.136.11 -- 192.168.136.12 --
// 192.168.136.13
//
- MapRegister mr = MapRegister.deserialize(hexToByteBuffer("38 00 01 " //
+ MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 " //
+ "04 " // Record count
+ "FF BB 00 00 00 00 00 00 00 01 00 14 e8 f5 0b c5 " //
+ "c5 f2 b0 21 27 a8 21 41 04 f3 46 5a a5 68 89 ec " //
@Test
public void deserialize__Locators() throws Exception {
- MapRegister mr = MapRegister.deserialize(hexToByteBuffer("38 00 01 01 " //
+ MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 " //
+ "FF BB 00 00 00 00 00 00 00 01 00 14 e8 f5 0b c5 " //
+ "c5 f2 b0 21 27 a8 21 41 04 f3 46 5a a5 68 89 ec " //
+ "00 00 00 0a " //
// Local RLOCs: 192.168.136.10 -- 192.168.136.11 -- 192.168.136.12 --
// 192.168.136.13
//
- MapRegister mr = MapRegister.deserialize(hexToByteBuffer("38 00 01 " //
+ MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 " //
+ "04 " // Record count
+ "FF BB 00 00 00 00 00 00 00 01 00 14 e8 f5 0b c5 " //
+ "c5 f2 b0 21 27 a8 21 41 04 f3 46 5a a5 68 89 ec " //
@Test
public void deserialize__IllegalAction() throws Exception {
- MapRegister mr = MapRegister.deserialize(hexToByteBuffer("38 00 01 01 FF BB " //
+ MapRegister mr = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB " //
+ "00 00 00 00 00 00 00 01 00 14 e8 f5 0b c5 c5 f2 " //
+ "b0 21 27 a8 21 41 04 f3 46 5a a5 68 89 ec 00 00 " //
+ "00 0a 01 20 F0 00 00 00 00 01 99 10 fe 01 01 64 " //
* and is availabl at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.type.lisp;
+package org.opendaylight.lispflowmapping.southbound.serializer;
import static org.junit.Assert.assertEquals;
import org.junit.Ignore;
import org.junit.Test;
+import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
+import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
+import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
+import org.opendaylight.lispflowmapping.type.lisp.MapReply;
+import org.opendaylight.lispflowmapping.type.lisp.MapReplyAction;
import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv6Address;
-import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-public class MapReplyTest extends BaseTestCase {
+public class MapReplySerializationTest extends BaseTestCase {
@Test
@Ignore
mr.setProbe(true);
mr.setEchoNonceEnabled(false);
- ByteBuffer packet = mr.serialize();
+ ByteBuffer packet = MapReplySerializer.getInstance().serialize(mr);
byte firstByte = packet.get(0);
assertHexEquals((byte) 0x28, firstByte);
mr.setProbe(false);
mr.setEchoNonceEnabled(true);
- packet = mr.serialize();
+ packet = MapReplySerializer.getInstance().serialize(mr);
firstByte = packet.get(0);
assertHexEquals((byte) 0x24, firstByte);
}
mr.addEidToLocator(new EidToLocatorRecord().setPrefix(new LispIpv6Address("::8")));
mr.addEidToLocator(new EidToLocatorRecord().setPrefix(new LispIpv4Address(0x08020405)));
- ByteBuffer packet = mr.serialize();
+ ByteBuffer packet = MapReplySerializer.getInstance().serialize(mr);
assertEquals(2, packet.get(3));
packet.position(24); /* EID in first record */
eidToLocator.setPrefix(new LispIpv4Address(1));
mr.addEidToLocator(eidToLocator);
- ByteBuffer packet = mr.serialize();
+ ByteBuffer packet = MapReplySerializer.getInstance().serialize(mr);
packet.position(18);
assertHexEquals((byte) 0x00, packet.get()); // MapReplyAction.NoAction
eidToLocator.setAction(null);
mr.addEidToLocator(eidToLocator);
- ByteBuffer packet = mr.serialize();
+ ByteBuffer packet = MapReplySerializer.getInstance().serialize(mr);
packet.position(18);
assertHexEquals((byte) 0x00, packet.get()); // MapReplyAction.NoAction
eidToLocator2.setMapVersion((short) 29);
mr.addEidToLocator(eidToLocator2);
- ByteBuffer packet = mr.serialize();
+ ByteBuffer packet = MapReplySerializer.getInstance().serialize(mr);
packet.position(12); /* First record */
assertEquals(7, packet.getInt());
mr.addEidToLocator(eidToLocator);
- ByteBuffer packet = mr.serialize();
+ ByteBuffer packet = MapReplySerializer.getInstance().serialize(mr);
packet.position(12 + 16); /* First locator record */
assertHexEquals((byte) 0xF3, packet.get());
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.type.lisp;
+package org.opendaylight.lispflowmapping.southbound.serializer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
+import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
+import org.opendaylight.lispflowmapping.type.lisp.EidRecord;
+import org.opendaylight.lispflowmapping.type.lisp.MapRequest;
import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv6Address;
import org.opendaylight.lispflowmapping.type.lisp.address.LispNoAddress;
-import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-public class MapRequestTest extends BaseTestCase {
+public class MapRequestSerializationTest extends BaseTestCase {
@Test
public void prefix__NoPrefix() throws Exception {
@Test
public void deserialize__FlagsInFirstByte() throws Exception {
- MapRequest mr = MapRequest.deserialize(hexToByteBuffer("16 00 00 01 3d 8d " //
+ MapRequest mr = MapRequestSerializer.getInstance().deserialize(hexToByteBuffer("16 00 00 01 3d 8d " //
+ "2a cd 39 c8 d6 08 00 00 00 01 c0 a8 88 0a 00 20 " //
+ "00 01 01 02 03 04"));
assertFalse(mr.isAuthoritative());
assertTrue(mr.isProbe());
assertFalse(mr.isSmr());
- mr = MapRequest.deserialize(hexToByteBuffer("19 00 00 01 3d 8d " //
+ mr = MapRequestSerializer.getInstance().deserialize(hexToByteBuffer("19 00 00 01 3d 8d " //
+ "2a cd 39 c8 d6 08 00 00 00 01 c0 a8 88 0a 00 20 " //
+ "00 01 01 02 03 04"));
assertTrue(mr.isAuthoritative());
assertFalse(mr.isProbe());
assertTrue(mr.isSmr());
- mr = MapRequest.deserialize(hexToByteBuffer("1C 00 00 01 3d 8d " //
+ mr = MapRequestSerializer.getInstance().deserialize(hexToByteBuffer("1C 00 00 01 3d 8d " //
+ "2a cd 39 c8 d6 08 00 00 00 01 c0 a8 88 0a 00 20 " //
+ "00 01 01 02 03 04"));
assertTrue(mr.isAuthoritative());
@Test
public void deserialize__FlagsInSecondByte() throws Exception {
- MapRequest mr = MapRequest.deserialize(hexToByteBuffer("16 80 00 01 3d 8d " //
+ MapRequest mr = MapRequestSerializer.getInstance().deserialize(hexToByteBuffer("16 80 00 01 3d 8d " //
+ "2a cd 39 c8 d6 08 00 00 00 01 c0 a8 88 0a 00 20 " //
+ "00 01 01 02 03 04"));
assertTrue(mr.isPitr());
assertFalse(mr.isSmrInvoked());
- mr = MapRequest.deserialize(hexToByteBuffer("19 40 00 01 3d 8d " //
+ mr = MapRequestSerializer.getInstance().deserialize(hexToByteBuffer("19 40 00 01 3d 8d " //
+ "2a cd 39 c8 d6 08 00 00 00 01 c0 a8 88 0a 00 20 " //
+ "00 01 01 02 03 04"));
assertFalse(mr.isPitr());
@Test
public void deserialize__SingleEidRecord() throws Exception {
- MapRequest mr = MapRequest.deserialize(hexToByteBuffer("16 80 00 " //
+ MapRequest mr = MapRequestSerializer.getInstance().deserialize(hexToByteBuffer("16 80 00 " //
+ "01 " // single record
+ "3d 8d 2a cd 39 c8 d6 08 00 00 00 01 c0 a8 88 0a " //
+ "00 20 00 01 01 02 03 04"));
@Test
public void deserialize__MultipleEidRecord() throws Exception {
- MapRequest mr = MapRequest.deserialize(hexToByteBuffer("16 80 00 " //
+ MapRequest mr = MapRequestSerializer.getInstance().deserialize(hexToByteBuffer("16 80 00 " //
+ "02 " // 2 records
+ "3d 8d 2a cd 39 c8 d6 08 00 00 00 01 c0 a8 88 0a " //
+ "00 20 00 01 01 02 03 04 " //
@Test
public void deserialize__SingleItrRloc() throws Exception {
- MapRequest mr = MapRequest.deserialize(hexToByteBuffer("10 00 " //
+ MapRequest mr = MapRequestSerializer.getInstance().deserialize(hexToByteBuffer("10 00 " //
+ "00 " // This means 1 ITR-RLOC
+ "01 3d 8d 2a cd 39 c8 d6 08 00 00 " //
+ "00 01 c0 a8 88 0a " // IPv4 (ITR-RLOC #1 of 1)
@Test
public void deserialize__MultipleItrRlocs() throws Exception {
- MapRequest mr = MapRequest.deserialize(hexToByteBuffer("10 00 " //
+ MapRequest mr = MapRequestSerializer.getInstance().deserialize(hexToByteBuffer("10 00 " //
+ "02 " // This means 3 ITR - RLOCs
+ "01 3d 8d 2a cd 39 c8 d6 08 00 00 " //
+ "00 01 c0 a8 88 0a " // IPv4 (ITR-RLOC #1 of 3)
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.type.lisp.address;
+package org.opendaylight.lispflowmapping.southbound.serializer.address;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
-import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
+import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv6Address;
public class LispIpv6AddressTest extends BaseTestCase {
LispIpv6Address lispIpv6Address = new LispIpv6Address("::0");
assertEquals(AddressFamilyNumberEnum.IP6, lispIpv6Address.getAfi());
- assertEquals(18, lispIpv6Address.getAddressSize());
+ assertEquals(18, LispIpv6AddressSerializer.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, lispIpv6Address.getAddressSize());
+ assertEquals(18, LispIpv6AddressSerializer.getInstance().getAddressSize(lispIpv6Address));
assertEquals("0:0:0:0:0:0:0:1", lispIpv6Address.toString());
}
}
* 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;
+package org.opendaylight.lispflowmapping.southbound.serializer.address;
import static junit.framework.Assert.assertEquals;
import junitx.framework.Assert;
import org.junit.Test;
+import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
+import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
-import org.opendaylight.lispflowmapping.type.exception.LispMalformedPacketException;
-import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv6Address;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispListLCAFAddress;
public class LispListLCAFAddressTest extends BaseTestCase {
@Test
public void deserialize__Simple() throws Exception {
- LispAddress address = LispAddress.valueOf(hexToByteBuffer("40 03 00 00 " + //
+ LispAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
"01 00 00 18 " + //
"00 01 AA BB CC DD " + // IPv4
"00 02 11 22 33 44 11 22 33 44 11 22 33 44 11 22 33 44")); // IPv6
assertEquals(LispCanonicalAddressFormatEnum.LIST, lcafList.getType());
- List<LispAddress> addressList = lcafList.getAddresses();
+ List<? extends LispAddress> addressList = lcafList.getAddresses();
assertEquals(2, addressList.size());
assertEquals(new LispIpv4Address(0xAABBCCDD), addressList.get(0));
@Test
public void deserialize__NoAddresses() throws Exception {
- LispAddress address = LispAddress.valueOf(hexToByteBuffer("40 03 00 00 " + //
+ LispAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
"01 00 00 00 "));
assertEquals(AddressFamilyNumberEnum.LCAF, address.getAfi());
assertEquals(LispCanonicalAddressFormatEnum.LIST, lcafList.getType());
- List<LispAddress> addressList = lcafList.getAddresses();
+ List<? extends LispAddress> addressList = lcafList.getAddresses();
assertEquals(0, addressList.size());
}
@Test(expected = LispMalformedPacketException.class)
public void deserialize__ShorterBuffer() throws Exception {
- LispAddress.valueOf(hexToByteBuffer("40 03 00 00 " + //
+ LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
"01 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 = LispMalformedPacketException.class)
public void deserialize__ShorterBuffer2() throws Exception {
- LispAddress.valueOf(hexToByteBuffer("40 03 00 00 " + //
+ LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
"01 00 00 18 "));
}
addressList.add(new LispIpv6Address("1222:3344:1122:3344:1122:3344:1122:3344"));
LispListLCAFAddress address = new LispListLCAFAddress((byte) 0, addressList);
- ByteBuffer buf = ByteBuffer.allocate(address.getAddressSize());
- address.serialize(buf);
+ ByteBuffer buf = ByteBuffer.allocate(LispListLCAFAddressSerializer.getInstance().getAddressSize(address));
+ LispListLCAFAddressSerializer.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(address.getAddressSize());
- address.serialize(buf);
+ ByteBuffer buf = ByteBuffer.allocate(LispListLCAFAddressSerializer.getInstance().getAddressSize(address));
+ LispListLCAFAddressSerializer.getInstance().serialize(buf,address);
ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
"01 00 00 00");
ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
* 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;
+package org.opendaylight.lispflowmapping.southbound.serializer.address;
import static junit.framework.Assert.assertEquals;
import java.nio.ByteBuffer;
import junitx.framework.ArrayAssert;
-import junitx.framework.Assert;
import org.junit.Test;
+import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
+import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
-import org.opendaylight.lispflowmapping.type.exception.LispMalformedPacketException;
-import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv6Address;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispSegmentLCAFAddress;
public class LispSegmentLCAFAddressTest extends BaseTestCase {
@Test
public void deserialize__Simple() throws Exception {
- LispAddress address = LispAddress.valueOf(hexToByteBuffer("40 03 00 00 " + //
+ LispAddress address = LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
"02 20 00 0A " + //
"AA BB CC DD " + // instance ID
"00 01 11 22 33 44")); // AFI=1, IP=0x11223344
@Test(expected = LispMalformedPacketException.class)
public void deserialize__ShorterBuffer() throws Exception {
- LispAddress.valueOf(hexToByteBuffer("40 03 00 00 " + //
+ LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
"02 20 00 0A " + //
"AA BB "));
}
@Test(expected = LispMalformedPacketException.class)
public void deserialize__UnknownLCAFType() throws Exception {
- LispAddress.valueOf(hexToByteBuffer("40 03 00 00 " + //
+ LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
"AA 20 00 0A " + // Type AA is unknown
"AA BB CC DD " + // instance ID
"00 01 11 22 33 44")); // AFI=1, IP=0x11223344
@Test
public void deserialize__Ipv6() throws Exception {
- LispSegmentLCAFAddress segAddress = (LispSegmentLCAFAddress) LispAddress.valueOf(hexToByteBuffer("40 03 00 00 " + //
+ LispSegmentLCAFAddress segAddress = (LispSegmentLCAFAddress) LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
"02 20 00 0A " + //
"AA BB CC DD " + // instance ID
"00 02 11 22 33 44 55 66 77 88 99 AA BB CC AA BB CC DD")); // AFI=2,
@Test
public void serialize__Simple() throws Exception {
LispSegmentLCAFAddress address = new LispSegmentLCAFAddress((byte) 0x06, 0x01020304, new LispIpv4Address(0x11223344));
- ByteBuffer buf = ByteBuffer.allocate(address.getAddressSize());
- address.serialize(buf);
+ ByteBuffer buf = ByteBuffer.allocate(LispSegmentLCAFAddressSerializer.getInstance().getAddressSize(address));
+ LispSegmentLCAFAddressSerializer.getInstance().serialize(buf,address);
ByteBuffer expectedBuf = hexToByteBuffer("40 03 00 00 " + //
"02 06 00 0A " + //
"01 02 03 04 " + // instance ID
"00 01 11 22 33 44");
ArrayAssert.assertEquals(expectedBuf.array(), buf.array());
}
-
- @Test
- public void equals__Simple() throws Exception {
- LispSegmentLCAFAddress address1 = new LispSegmentLCAFAddress((byte) 0x06, 0x01020304, new LispIpv4Address(0x11223344));
- LispSegmentLCAFAddress address2 = new LispSegmentLCAFAddress((byte) 0x06, 0x01020304, new LispIpv4Address(0x11223344));
- LispSegmentLCAFAddress address3 = new LispSegmentLCAFAddress((byte) 0x06, 0x01020305, new LispIpv4Address(0x11223344));
- LispSegmentLCAFAddress address4 = new LispSegmentLCAFAddress((byte) 0x05, 0x01020304, new LispIpv4Address(0x11223344));
- LispSegmentLCAFAddress address5 = new LispSegmentLCAFAddress((byte) 0x06, 0x01020304, new LispIpv4Address(0x11223343));
-
- assertEquals(address1, address2);
- assertEquals(address1, address1);
- Assert.assertNotEquals(address1, address3);
- Assert.assertNotEquals(address1, address4);
- Assert.assertNotEquals(address1, address5);
- Assert.assertNotEquals(address3, address4);
- Assert.assertNotEquals(address3, address5);
- Assert.assertNotEquals(address4, address5);
- }
}