package org.opendaylight.lispflowmapping.type.lisp;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
byte[] authenticationData = mapRegister.getAuthenticationData();
if (authenticationData != null) {
authenticationData = authenticationData.clone();
+ Arrays.fill(authenticationData, (byte)0);
}
setAuthenticationData(authenticationData);
* RECOMMENDED.
*/
private byte[] authenticationData;
+
+ /**
+ * The representation in bytes of the map register.
+ */
+ private byte[] mapRegisterBytes;
/**
* Record Count: This is the number of records in this Map-Register message.
this.keyId = keyId;
return this;
}
+
+ public byte[] getMapRegisterBytes() {
+ return mapRegisterBytes;
+ }
+
+ public MapRegister setMapRegisterBytes(byte[] mapRegisterBytes) {
+ this.mapRegisterBytes = mapRegisterBytes;
+ return this;
+ }
private static byte[] NO_AUTHENTICATION_DATA = new byte[] {};
}
<configuration>
<instructions>
<Export-Package>
+ org.opendaylight.mappingservice.implementation.serializer,
+ org.opendaylight.mappingservice.implementation.util
</Export-Package>
<Import-Package>
org.opendaylight.controller.sal.core,
org.osgi.framework,
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.controller.clustering.services
+ org.opendaylight.controller.clustering.services,
+ javax.crypto,
+ javax.crypto.spec,
+ org.apache.tomcat.util.buf
</Import-Package>
<Bundle-Activator>
org.opendaylight.lispflowmapping.implementation.Activator
--- /dev/null
+package org.opendaylight.lispflowmapping.implementation.authentication;
+
+import org.opendaylight.lispflowmapping.type.lisp.MapNotify;
+import org.opendaylight.lispflowmapping.type.lisp.MapRegister;
+
+
+public interface ILispAuthentication {
+ public boolean validate(MapRegister mapRegister);
+ public byte[] getAuthenticationData(MapNotify mapNotify);
+ public int getAuthenticationLength();
+ public static final int MAP_REGISTER_AND_NOTIFY_AUTHENTICATION_POSITION = 16;
+
+}
\ No newline at end of file
--- /dev/null
+package org.opendaylight.lispflowmapping.implementation.authentication;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class LispAuthenticationFactory {
+
+ private static Map<LispKeyIDEnum, ILispAuthentication> keyIDToAuthenticationMap;
+
+ private static void initializeMap() {
+ keyIDToAuthenticationMap = new HashMap<LispKeyIDEnum, ILispAuthentication>();
+ keyIDToAuthenticationMap.put(LispKeyIDEnum.NONE, LispNoAuthentication.getInstance());
+ keyIDToAuthenticationMap.put(LispKeyIDEnum.SHA1, new LispMACAuthentication(LispKeyIDEnum.SHA1.getAuthenticationName()));
+ keyIDToAuthenticationMap.put(LispKeyIDEnum.SHA256, new LispMACAuthentication(LispKeyIDEnum.SHA256.getAuthenticationName()));
+ keyIDToAuthenticationMap.put(LispKeyIDEnum.UNKNOWN, LispNoAuthentication.getInstance());
+
+ }
+
+ public static ILispAuthentication getAuthentication(LispKeyIDEnum keyID) {
+ if (keyIDToAuthenticationMap == null) {
+ initializeMap();
+ }
+ return keyIDToAuthenticationMap.get(keyID);
+ }
+
+
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.implementation.authentication;
+
+import org.opendaylight.lispflowmapping.type.lisp.MapNotify;
+import org.opendaylight.lispflowmapping.type.lisp.MapRegister;
+
+public class LispAuthenticationUtil {
+
+
+ public static boolean validate(MapRegister mapRegister) {
+ ILispAuthentication authentication = LispAuthenticationFactory.getAuthentication(LispKeyIDEnum.valueOf(mapRegister.getKeyId()));
+ return authentication.validate(mapRegister);
+ }
+
+ public static byte[] getAuthenticationData(MapNotify mapNotify) {
+ ILispAuthentication authentication = LispAuthenticationFactory.getAuthentication(LispKeyIDEnum.valueOf(mapNotify.getKeyId()));
+ return authentication.getAuthenticationData(mapNotify);
+ }
+
+
+
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.implementation.authentication;
+
+
+public enum LispKeyIDEnum {
+ NONE(0, null), //
+ SHA1(1, "HmacSHA1"), //
+ SHA256(2, "HmacSHA256"), //
+ UNKNOWN(-1, null);
+
+ private short keyID;
+ private String authenticationName;
+
+ private LispKeyIDEnum(int keyID, String authenticationName) {
+ this.keyID = (short) keyID;
+ this.authenticationName = authenticationName;
+ }
+
+ public String getAuthenticationName() {
+ return authenticationName;
+ }
+
+ public short getKeyID() {
+ return keyID;
+ }
+
+ public static LispKeyIDEnum valueOf(short keyID) {
+ for (LispKeyIDEnum val : values()) {
+ if (val.getKeyID() == keyID) {
+ return val;
+ }
+ }
+ return UNKNOWN;
+ }
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.implementation.authentication;
+
+import java.nio.ByteBuffer;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.Arrays;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+
+import org.opendaylight.lispflowmapping.implementation.serializer.MapNotifySerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.MapRegisterSerializer;
+import org.opendaylight.lispflowmapping.type.lisp.MapNotify;
+import org.opendaylight.lispflowmapping.type.lisp.MapRegister;
+
+public class LispMACAuthentication implements ILispAuthentication {
+
+ private static String KEY = "password";
+ protected String algorithem;
+ protected Mac mac;
+ private byte[] tempAuthenticationData;
+
+ public LispMACAuthentication(String algorithem) {
+ this.algorithem = algorithem;
+ try {
+ byte[] keyBytes = KEY.getBytes();
+ SecretKeySpec signingKey = new SecretKeySpec(keyBytes, algorithem);
+
+ mac = Mac.getInstance(algorithem);
+ mac.init(signingKey);
+ tempAuthenticationData = new byte[mac.getMacLength()];
+ Arrays.fill(tempAuthenticationData, (byte) 0);
+
+ } catch (NoSuchAlgorithmException e) {
+ } catch (InvalidKeyException e) {
+ }
+ }
+
+ public boolean validate(MapRegister mapRegister) {
+ ByteBuffer mapRegisterBuffer = MapRegisterSerializer.getInstance().serialize(mapRegister);
+ if (mapRegisterBuffer == null) {
+ return true;
+ }
+
+ mapRegisterBuffer.position(MAP_REGISTER_AND_NOTIFY_AUTHENTICATION_POSITION);
+ mapRegisterBuffer.put(tempAuthenticationData);
+ mapRegisterBuffer.position(0);
+ return Arrays.equals(getAuthenticationData(mapRegisterBuffer.array()),mapRegister.getAuthenticationData());
+ }
+
+ protected byte[] getAuthenticationData(byte[] data) {
+ return mac.doFinal(data);
+ }
+
+ public int getAuthenticationLength() {
+ return mac.getMacLength();
+ }
+
+ public String getAlgorithem() {
+ return algorithem;
+ }
+
+ public void setAlgorithem(String algorithem) {
+ this.algorithem = algorithem;
+ }
+
+ public byte[] getAuthenticationData(MapNotify mapNotify) {
+ return getAuthenticationData(MapNotifySerializer.getInstance().serialize(mapNotify).array());
+ }
+
+}
--- /dev/null
+package org.opendaylight.lispflowmapping.implementation.authentication;
+
+import org.opendaylight.lispflowmapping.type.lisp.MapNotify;
+import org.opendaylight.lispflowmapping.type.lisp.MapRegister;
+
+public class LispNoAuthentication implements ILispAuthentication {
+
+ private static final LispNoAuthentication INSTANCE = new LispNoAuthentication();
+
+ private static byte[] authenticationData;
+
+ public static LispNoAuthentication getInstance() {
+ return INSTANCE;
+ }
+
+ private LispNoAuthentication() {
+ authenticationData = new byte[0];
+ }
+
+ public int getAuthenticationLength() {
+ return 0;
+ }
+
+ public byte[] getAuthenticationData(MapNotify mapNotify) {
+ return authenticationData;
+ }
+
+ public boolean validate(MapRegister mapRegister) {
+ return true;
+ }
+
+}
import java.util.ArrayList;
import java.util.List;
+import org.opendaylight.lispflowmapping.implementation.authentication.LispAuthenticationUtil;
import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO;
import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO.MappingEntry;
import org.opendaylight.lispflowmapping.interfaces.lisp.IMapServer;
logger.warn("handleMapRegister called while dao is uninitialized");
return null;
}
+ if (!LispAuthenticationUtil.validate(mapRegister)) {
+ return null;
+ }
EidToLocatorRecord eidRecord = mapRegister.getEidToLocatorRecords().get(0);
List<MappingEntry<?>> rlocs = new ArrayList<ILispDAO.MappingEntry<?>>();
rlocs.add(new MappingEntry<Integer>("NumRLOCs", eidRecord.getLocators().size()));
if (mapRegister.isWantMapNotify()) {
mapNotify = new MapNotify();
mapNotify.setFromMapRegister(mapRegister);
+ mapNotify.setAuthenticationData(LispAuthenticationUtil.getAuthenticationData(mapNotify));
}
return mapNotify;
}
+
}
--- /dev/null
+/*
+ * Copyright (c) 2013 Contextream, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.lispflowmapping.implementation.lisp.exception;
+
+public class LispSerializationException extends RuntimeException {
+
+ private static final long serialVersionUID = 73639582991861261L;
+
+ public LispSerializationException(String message) {
+ super(message);
+ }
+
+ public LispSerializationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
-package org.opendaylight.lispflowmapping.southbound.serializer;
+package org.opendaylight.lispflowmapping.implementation.serializer;
import java.nio.ByteBuffer;
-import org.opendaylight.lispflowmapping.southbound.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispAddressSerializer;
import org.opendaylight.lispflowmapping.type.lisp.EidRecord;
import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
-package org.opendaylight.lispflowmapping.southbound.serializer;
+package org.opendaylight.lispflowmapping.implementation.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.implementation.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispAddressSerializerFactory;
+import org.opendaylight.lispflowmapping.implementation.util.ByteUtil;
import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
import org.opendaylight.lispflowmapping.type.lisp.MapReplyAction;
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.southbound.serializer;
+package org.opendaylight.lispflowmapping.implementation.serializer;
public interface LispMessage {
int PORT_NUM = 4342;
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.southbound.serializer;
+package org.opendaylight.lispflowmapping.implementation.serializer;
public enum LispMessageEnum {
MapRequest((byte) 1), //
-package org.opendaylight.lispflowmapping.southbound.serializer;
+package org.opendaylight.lispflowmapping.implementation.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.implementation.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispAddressSerializerFactory;
+import org.opendaylight.lispflowmapping.implementation.util.ByteUtil;
import org.opendaylight.lispflowmapping.type.lisp.LocatorRecord;
public class LocatorRecordSerializer {
-package org.opendaylight.lispflowmapping.southbound.serializer;
+package org.opendaylight.lispflowmapping.implementation.serializer;
import java.nio.ByteBuffer;
replyBuffer.putLong(mapNotify.getNonce());
replyBuffer.putShort(mapNotify.getKeyId());
replyBuffer.putShort((short) mapNotify.getAuthenticationData().length);
- if (mapNotify.getAuthenticationData() != null) {
- replyBuffer.put(mapNotify.getAuthenticationData());
- }
+ replyBuffer.put(mapNotify.getAuthenticationData());
for (EidToLocatorRecord eidToLocatorRecord : mapNotify.getEidToLocatorRecords()) {
EidToLocatorRecordSerializer.getInstance().serialize(replyBuffer, eidToLocatorRecord);
}
-
replyBuffer.clear();
return replyBuffer;
}
-package org.opendaylight.lispflowmapping.southbound.serializer;
+package org.opendaylight.lispflowmapping.implementation.serializer;
import java.nio.ByteBuffer;
-import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
-import org.opendaylight.lispflowmapping.southbound.util.ByteUtil;
+import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.implementation.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() {
- }
+ private static final MapRegisterSerializer INSTANCE = new MapRegisterSerializer();
- public static MapRegisterSerializer getInstance() {
- return INSTANCE;
- }
+ // Private constructor prevents instantiation from other classes
+ private MapRegisterSerializer() {
+ }
- public MapRegister deserialize(ByteBuffer registerBuffer) {
+ public static MapRegisterSerializer getInstance() {
+ return INSTANCE;
+ }
+
+ public ByteBuffer serialize(MapRegister mapRegister) {
+ if (mapRegister.getMapRegisterBytes() != null)
+ return ByteBuffer.wrap(mapRegister.getMapRegisterBytes());
+ else {
+ return null;
+ }
+ }
+
+ public MapRegister deserialize(ByteBuffer registerBuffer) {
try {
MapRegister mapRegister = new MapRegister();
byte recordCount = registerBuffer.get();
mapRegister.setNonce(registerBuffer.getLong());
mapRegister.setKeyId(registerBuffer.getShort());
-
short authenticationLength = registerBuffer.getShort();
byte[] authenticationData = new byte[authenticationLength];
registerBuffer.get(authenticationData);
for (int i = 0; i < recordCount; i++) {
mapRegister.addEidToLocator(EidToLocatorRecordSerializer.getInstance().deserialize(registerBuffer));
}
+ registerBuffer.limit(registerBuffer.position());
+ byte[] mapRegisterBytes = new byte[registerBuffer.position()];
+ registerBuffer.position(0);
+ registerBuffer.get(mapRegisterBytes);
+ mapRegister.setMapRegisterBytes(mapRegisterBytes);
return mapRegister;
} catch (RuntimeException re) {
- throw new LispMalformedPacketException("Couldn't deserialize Map-Register (len=" + registerBuffer.capacity() + ")", re);
+ throw new LispSerializationException("Couldn't deserialize Map-Register (len=" + registerBuffer.capacity() + ")", re);
}
}
-
- private interface Flags {
+
+ private interface Flags {
byte PROXY = 0x08;
byte WANT_MAP_REPLY = 0x01;
}
- private interface Length {
+ private interface Length {
int RES = 1;
}
}
-package org.opendaylight.lispflowmapping.southbound.serializer;
+package org.opendaylight.lispflowmapping.implementation.serializer;
import java.nio.ByteBuffer;
-package org.opendaylight.lispflowmapping.southbound.serializer;
+package org.opendaylight.lispflowmapping.implementation.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.implementation.lisp.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.implementation.serializer.address.LispAddressSerializer;
+import org.opendaylight.lispflowmapping.implementation.util.ByteUtil;
import org.opendaylight.lispflowmapping.type.lisp.MapRequest;
}
return mapRequest;
} catch (RuntimeException re) {
- throw new LispMalformedPacketException("Couldn't deserialize Map-Request (len=" + requestBuffer.capacity() + ")", re);
+ throw new LispSerializationException("Couldn't deserialize Map-Request (len=" + requestBuffer.capacity() + ")", re);
}
}
-package org.opendaylight.lispflowmapping.southbound.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
import java.nio.ByteBuffer;
-package org.opendaylight.lispflowmapping.southbound.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
import java.nio.ByteBuffer;
-import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
+import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
AddressFamilyNumberEnum afiType = AddressFamilyNumberEnum.valueOf(afi);
LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(afiType);
if (serializer == null) {
- throw new LispMalformedPacketException("Unknown AFI type=" + afiType);
+ throw new LispSerializationException("Unknown AFI type=" + afiType);
}
try {
return serializer.deserialize(buffer);
} catch (Exception e) {
- throw new LispMalformedPacketException(e.getMessage());
+ throw new LispSerializationException(e.getMessage());
}
}
-package org.opendaylight.lispflowmapping.southbound.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
import java.util.HashMap;
import java.util.Map;
-package org.opendaylight.lispflowmapping.southbound.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
import java.nio.ByteBuffer;
-import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
-import org.opendaylight.lispflowmapping.southbound.util.ByteUtil;
+import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.implementation.util.ByteUtil;
import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
import org.opendaylight.lispflowmapping.type.lisp.address.LispApplicationDataLCAFAddress;
import org.opendaylight.lispflowmapping.type.lisp.address.LispSegmentLCAFAddress;
buffer.putShort(applicationDataAddress.getRemotePort());
LispAddressSerializer serializer = LispAddressSerializerFactory.getSerializer(applicationDataAddress.getAddress().getAfi());
if (serializer == null) {
- throw new LispMalformedPacketException("Unknown AFI type=" + ((LispSegmentLCAFAddress) lispAddress).getAddress().getAfi());
+ throw new LispSerializationException("Unknown AFI type=" + ((LispSegmentLCAFAddress) lispAddress).getAddress().getAfi());
}
serializer.serialize(buffer, ((LispApplicationDataLCAFAddress) lispAddress).getAddress());
}
-package org.opendaylight.lispflowmapping.southbound.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
import java.nio.ByteBuffer;
-package org.opendaylight.lispflowmapping.southbound.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
import java.net.InetAddress;
import java.net.UnknownHostException;
-package org.opendaylight.lispflowmapping.southbound.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
import java.net.InetAddress;
import java.net.UnknownHostException;
-package org.opendaylight.lispflowmapping.southbound.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
import java.nio.ByteBuffer;
-import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
+import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
import org.opendaylight.lispflowmapping.type.lisp.address.LispLCAFAddress;
LispLCAFAddressSerializer serializer = LispAddressSerializerFactory.getLCAFSerializer(lcafType);
if (serializer == null) {
- throw new LispMalformedPacketException("Unknown LispLCAFAddress type=" + lispCode);
+ throw new LispSerializationException("Unknown LispLCAFAddress type=" + lispCode);
}
return serializer.innerDeserialize(buffer, res2, length);
}
-package org.opendaylight.lispflowmapping.southbound.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
import java.nio.ByteBuffer;
import java.util.ArrayList;
-package org.opendaylight.lispflowmapping.southbound.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
import java.nio.ByteBuffer;
-package org.opendaylight.lispflowmapping.southbound.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
import java.nio.ByteBuffer;
-package org.opendaylight.lispflowmapping.southbound.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
import java.nio.ByteBuffer;
-import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
+import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
import org.opendaylight.lispflowmapping.type.lisp.address.LispSegmentLCAFAddress;
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());
+ throw new LispSerializationException("Unknown AFI type=" + ((LispSegmentLCAFAddress)lispAddress).getAddress().getAfi());
}
serializer.serialize(buffer, ((LispSegmentLCAFAddress)lispAddress).getAddress());
}
-package org.opendaylight.lispflowmapping.southbound.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
import java.nio.ByteBuffer;
-import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
+import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
import org.opendaylight.lispflowmapping.type.lisp.address.LispAddress;
import org.opendaylight.lispflowmapping.type.lisp.address.LispSourceDestLCAFAddress;
buffer.put(lispSourceDestLCAFAddress.getDstMaskLength());
LispAddressSerializer srcSerializer = LispAddressSerializerFactory.getSerializer(lispSourceDestLCAFAddress.getSrcAddress().getAfi());
if (srcSerializer == null) {
- throw new LispMalformedPacketException("Unknown AFI type=" + lispSourceDestLCAFAddress.getSrcAddress().getAfi());
+ throw new LispSerializationException("Unknown AFI type=" + lispSourceDestLCAFAddress.getSrcAddress().getAfi());
}
srcSerializer.serialize(buffer, lispSourceDestLCAFAddress.getSrcAddress());
LispAddressSerializer dstSerializer = LispAddressSerializerFactory.getSerializer(lispSourceDestLCAFAddress.getDstAddress().getAfi());
if (dstSerializer == null) {
- throw new LispMalformedPacketException("Unknown AFI type=" + lispSourceDestLCAFAddress.getDstAddress().getAfi());
+ throw new LispSerializationException("Unknown AFI type=" + lispSourceDestLCAFAddress.getDstAddress().getAfi());
}
dstSerializer.serialize(buffer, lispSourceDestLCAFAddress.getDstAddress());
}
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.southbound.util;
+package org.opendaylight.lispflowmapping.implementation.util;
import java.nio.ByteBuffer;
--- /dev/null
+package org.opendaylight.lispflowmapping.implementation.authentication;
+
+import static junit.framework.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import junitx.framework.ArrayAssert;
+
+import org.apache.tomcat.util.buf.HexUtils;
+import org.junit.Test;
+import org.opendaylight.lispflowmapping.implementation.serializer.MapRegisterSerializer;
+import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
+import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
+import org.opendaylight.lispflowmapping.type.lisp.MapNotify;
+import org.opendaylight.lispflowmapping.type.lisp.MapRegister;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
+
+public class LispAuthenticationTest extends BaseTestCase{
+
+
+ @Test
+ public void validate_WrongAuthentication() throws Exception {
+ // LISP(Type = 3 Map-Register, P=1, M=1
+ // Record Counter: 1
+ // Nonce: (something)
+ // Key ID: 0x0001
+ // AuthDataLength: 20 Data:
+ // e8:f5:0b:c5:c5:f2:b0:21:27:a8:21:41:04:f3:46:5a:5a:5b:5c:5d
+ // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
+ // No-Action
+ // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
+ // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
+ //
+ MapRegister mapRegister = 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 5a 5b 5c 5d 00 00 " //
+ + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
+ + "ff 00 00 05 00 01 c0 a8 88 0a"));
+
+ assertFalse(LispAuthenticationUtil.validate(mapRegister));
+ }
+
+ @Test
+ public void validate__SHA1() throws Exception {
+ // LISP(Type = 3 Map-Register, P=1, M=1
+ // Record Counter: 1
+ // Nonce: (something)
+ // Key ID: 0x0001
+ // AuthDataLength: 20 Data:
+ // b2:dd:1a:25:c0:60:b1:46:e8:dc:6d:a6:ae:2e:92:92:a6:ca:b7:9d
+ // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
+ // No-Action
+ // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
+ // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
+ //
+ MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(
+ hexToByteBuffer("38 00 01 01 FF BB " //
+ + "00 00 00 00 00 00 00 01 00 14 2c 61 b9 c9 9a 20 " //
+ + "ba d8 f5 40 d3 55 6f 5f 6e 5a b2 0a bf b5 00 00 " //
+ + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
+ + "ff 00 00 05 00 01 c0 a8 88 0a"));
+
+ assertTrue(LispAuthenticationUtil.validate(mapRegister));
+ }
+
+ @Test
+ public void validate__SHA256() throws Exception {
+ // LISP(Type = 3 Map-Register, P=1, M=1
+ // Record Counter: 1
+ // Nonce: (something)
+ // Key ID: 0x0002
+ // AuthDataLength: 32 Data:
+ // 70 30 d4 c6 10 44 0d 83 be 4d bf fd a9 8c 57 6d 68 a5 bf 32 11 c9 7b 58 c4 b9 9f 06 11 23 b9 38
+ // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
+ // No-Action
+ // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
+ // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
+ //
+ MapRegister mapRegister = MapRegisterSerializer
+ .getInstance()
+ .deserialize(
+ hexToByteBuffer("38 00 01 01 FF BB " //
+ + "00 00 00 00 00 00 00 02 00 20 70 30 d4 c6 10 44 0d 83 be 4d bf fd a9 8c 57 6d 68 a5 bf 32 " //
+ + "11 c9 7b 58 c4 b9 9f 06 11 23 b9 38 00 00 " //
+ + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
+ + "ff 00 00 05 00 01 c0 a8 88 0a"));
+
+ assertTrue(LispAuthenticationUtil.validate(mapRegister));
+ }
+
+ @Test
+ public void validate__NoAuthentication() throws Exception {
+ // LISP(Type = 3 Map-Register, P=1, M=1
+ // Record Counter: 1
+ // Nonce: (something)
+ // Key ID: 0x0000
+ // AuthDataLength: 0:
+ // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
+ // No-Action
+ // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
+ // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
+ //
+ MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(
+ hexToByteBuffer("38 00 01 01 FF BB " //
+ + "00 00 00 00 00 00 00 00 00 00 " //
+ + "00 00 " //
+ + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
+ + "ff 00 00 05 00 01 c0 a8 88 0a"));
+
+ assertTrue(LispAuthenticationUtil.validate(mapRegister));
+ }
+
+ @Test
+ public void authenticate__MapNotifySHA1() throws Exception {
+ MapNotify mapNotify = new MapNotify();
+ mapNotify.addEidToLocator(new EidToLocatorRecord()
+ .setPrefix(new LispIpv4Address(1)));
+
+ mapNotify.addEidToLocator(new EidToLocatorRecord()
+ .setPrefix(new LispIpv4Address(73)));
+ mapNotify.setNonce(6161616161L);
+ mapNotify.setKeyId((short) 0x0001);
+ byte[] wantedAuthenticationData = new byte[] { (byte) 0x66, (byte) 0x69,
+ (byte) 0x2c, (byte) 0xb8, (byte) 0xb8, (byte) 0x58,
+ (byte) 0x7c, (byte) 0x8f, (byte) 0x4c, (byte) 0xd4,
+ (byte) 0x8b, (byte) 0x77, (byte) 0x46, (byte) 0xf0,
+ (byte) 0x6b, (byte) 0x9f, (byte) 0x66, (byte) 0xd2,
+ (byte) 0xaa, (byte) 0x2c };
+ System.out.println(HexUtils.toHexString(LispAuthenticationUtil.getAuthenticationData(mapNotify)));
+ ArrayAssert.assertEquals(wantedAuthenticationData, LispAuthenticationUtil.getAuthenticationData(mapNotify));
+
+ }
+
+ @Test
+ public void authenticate__MapNotifySHA256() throws Exception {
+ MapNotify mapNotify = new MapNotify();
+ mapNotify.addEidToLocator(new EidToLocatorRecord()
+ .setPrefix(new LispIpv4Address(1)));
+
+ mapNotify.addEidToLocator(new EidToLocatorRecord()
+ .setPrefix(new LispIpv4Address(73)));
+ mapNotify.setNonce(6161616161L);
+ mapNotify.setKeyId((short) 0x0002);
+ byte[] wantedAuthenticationData = new byte[] { (byte) 0x4c, (byte) 0xf1,
+ (byte) 0x5a, (byte) 0x4c, (byte) 0xdb, (byte) 0x8d,
+ (byte) 0x88, (byte) 0x47, (byte) 0xf1, (byte) 0x7f,
+ (byte) 0x27, (byte) 0x81, (byte) 0x1e, (byte) 0xbf,
+ (byte) 0x22, (byte) 0xc7, (byte) 0xe6, (byte) 0x70,
+ (byte) 0x16, (byte) 0x5e, (byte) 0xa1, (byte) 0x59,
+ (byte) 0xe4, (byte) 0x06, (byte) 0x3f, (byte) 0xc2,
+ (byte) 0x6a, (byte) 0x1c, (byte) 0x86, (byte) 0xa5,
+ (byte) 0x8d, (byte) 0x63 };
+ System.out.println(HexUtils.toHexString(LispAuthenticationUtil.getAuthenticationData(mapNotify)));
+ ArrayAssert.assertEquals(wantedAuthenticationData, LispAuthenticationUtil.getAuthenticationData(mapNotify));
+
+ }
+
+ @Test
+ public void authenticate__MapNotifyNoAuthenticationData() throws Exception {
+ MapNotify mapNotify = new MapNotify();
+ mapNotify.setKeyId((short)0x0000);
+ mapNotify.addEidToLocator(new EidToLocatorRecord().setPrefix(
+ new LispIpv4Address(1)).setRecordTtl(55));
+ ArrayAssert.assertEquals(new byte[0], LispAuthenticationUtil.getAuthenticationData(mapNotify));
+
+ }
+
+}
@Test
public void handleMapRegisterIpv4__CloneNotOwnYouClown() throws Exception {
mapRegister = new MapRegister();
- byte[] originalAuthenticationData = new byte[] { 0x1, 0x2, 0x3, 0x4 };
- mapRegister.setAuthenticationData(originalAuthenticationData);
+ mapRegister.setKeyId((byte)0);
mapRegister.setWantMapNotify(true);
EidToLocatorRecord eidToLocator = new EidToLocatorRecord();
eid = new LispIpv4Address(1);
eidToLocator.setPrefix(eid);
LocatorRecord locator = new LocatorRecord();
+ locator.setLocator(new LispIpv4Address(2));
locator.setPriority((byte) 55);
eidToLocator.addLocator(locator);
MapNotify mapNotify = testedMapServer.handleMapRegister(mapRegister);
- originalAuthenticationData[1] = 0x77;
mapRegister.getEidToLocatorRecords().get(0).setPrefix(new LispIpv4Address(55));
mapRegister.getEidToLocatorRecords().get(0).getLocators().get(0).setPriority((byte) 1);
- ArrayAssert.assertEquals(new byte[] { 0x1, 0x2, 0x3, 0x4 }, mapNotify.getAuthenticationData());
EidToLocatorRecord actualEidToLocator = mapNotify.getEidToLocatorRecords().get(0);
assertEquals(new LispIpv4Address(1), actualEidToLocator.getPrefix());
assertEquals((byte) 55, actualEidToLocator.getLocators().get(0).getPriority());
--- /dev/null
+/*
+ * Copyright (c) 2013 Contextream, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.lispflowmapping.implementation.serializer;
+
+import static junit.framework.Assert.assertEquals;
+
+import java.nio.ByteBuffer;
+
+import junitx.framework.ArrayAssert;
+
+import org.junit.Test;
+import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
+import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
+import org.opendaylight.lispflowmapping.type.lisp.MapNotify;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
+import org.opendaylight.lispflowmapping.type.lisp.address.LispNoAddress;
+
+public class MapNotifySerializationTest extends BaseTestCase {
+
+ @Test
+ public void serialize__Fields() throws Exception {
+ MapNotify mn = new MapNotify();
+ mn.addEidToLocator(new EidToLocatorRecord()
+ .setPrefix(new LispIpv4Address(1)));
+
+ mn.addEidToLocator(new EidToLocatorRecord()
+ .setPrefix(new LispIpv4Address(73)));
+ mn.setNonce(6161616161L);
+ mn.setKeyId((short) 0x0001);
+ byte[] authenticationData = new byte[] { (byte) 0x16, (byte) 0x98,
+ (byte) 0x96, (byte) 0xeb, (byte) 0x88, (byte) 0x2d,
+ (byte) 0x4d, (byte) 0x22, (byte) 0xe5, (byte) 0x8f,
+ (byte) 0xe6, (byte) 0x89, (byte) 0x64, (byte) 0xb9,
+ (byte) 0x17, (byte) 0xa4, (byte) 0xba, (byte) 0x4e,
+ (byte) 0x8c, (byte) 0x41 };
+ mn.setAuthenticationData(authenticationData);
+
+ 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
+ assertEquals(6161616161L, bb.getLong()); // Nonce
+ assertHexEquals((short) 0x0001, bb.getShort()); // Key ID
+ assertEquals(authenticationData.length, bb.getShort());
+
+ byte[] actualAuthenticationData = new byte[20];
+ bb.get(actualAuthenticationData);
+ ArrayAssert.assertEquals(authenticationData, actualAuthenticationData);
+
+ bb.position(bb.position() + 12); /* EID in first record */
+ assertEquals(0x1, bb.getInt());
+
+ bb.position(bb.position() + 12); /* EID in second record */
+ assertEquals(73, bb.getInt());
+
+ assertEquals(bb.position(), bb.capacity());
+ }
+
+ @Test
+ public void serialize__NoAuthenticationData() throws Exception {
+ MapNotify mn = new MapNotify();
+ mn.addEidToLocator(new EidToLocatorRecord().setPrefix(
+ new LispIpv4Address(1)).setRecordTtl(55));
+
+ 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 = 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 = MapNotifySerializer.getInstance().serialize(mn);
+ bb.position(bb.position() + 14); // jump to AuthenticationDataLength
+ assertEquals(0, bb.getShort());
+ assertEquals(55, bb.getInt());
+ }
+
+ @Test
+ public void serialize__NoPrefixInEidToLocator() throws Exception {
+ MapNotify mn = new MapNotify();
+ mn.addEidToLocator(new EidToLocatorRecord());
+ mn.addEidToLocator(new EidToLocatorRecord().setPrefix(null));
+ mn.addEidToLocator(new EidToLocatorRecord()
+ .setPrefix(new LispNoAddress()));
+
+ ByteBuffer bb = MapNotifySerializer.getInstance().serialize(mn);
+ bb.position(bb.position() + 26); // jump to first record prefix AFI
+ assertEquals(0, bb.getShort());
+
+ bb.position(bb.position() + 10); // jump to second record prefix AFI
+ assertEquals(0, bb.getShort());
+
+ bb.position(bb.position() + 10); // jump to third record prefix AFI
+ assertEquals(0, bb.getShort());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Contextream, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.lispflowmapping.implementation.serializer;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+import junitx.framework.ArrayAssert;
+
+import org.junit.Test;
+import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
+import org.opendaylight.lispflowmapping.type.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 MapRegisterSerializationTest extends BaseTestCase {
+
+ @Test
+ public void deserialize__AllFields() throws Exception {
+ // LISP(Type = 3 Map-Register, P=1, M=1
+ // Record Counter: 1
+ // Nonce: (something)
+ // Key ID: 0x0000
+ // AuthDataLength: 00 Data:
+ // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
+ // No-Action
+ // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
+ // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
+ //
+ MapRegister mr = MapRegisterSerializer.getInstance().deserialize(
+ hexToByteBuffer("38 00 01 01 FF BB " //
+ + "00 00 00 00 00 00 00 00 00 00 00 00 " //
+ + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
+ + "ff 00 00 05 00 01 c0 a8 88 0a"));
+
+ assertTrue(mr.isProxyMapReply());
+ assertTrue(mr.isWantMapNotify());
+
+ assertEquals(1, mr.getEidToLocatorRecords().size());
+ assertEquals(0xFFBB000000000000L, mr.getNonce());
+ assertEquals(0x0000, mr.getKeyId());
+ byte[] expectedAuthenticationData = {};
+ ArrayAssert.assertEquals(expectedAuthenticationData,
+ mr.getAuthenticationData());
+ }
+
+ @Test
+ public void deserialize__MultipleRecords() throws Exception {
+ // LISP(Type = 3 Map-Register, P=1, M=1
+ // Record Counter: 4
+ // EID prefixes: 153.16.254.1 -- 152.16.254.1 -- 151.16.254.1 --
+ // 150.16.254.1
+ // Local RLOCs: 192.168.136.10 -- 192.168.136.11 -- 192.168.136.12 --
+ // 192.168.136.13
+ //
+ MapRegister mr = MapRegisterSerializer
+ .getInstance()
+ .deserialize(
+ hexToByteBuffer("38 00 01 " //
+ + "04 " // Record count
+ + "FF BB 00 00 00 00 00 00 00 01 00 14 87 c1 33 cd " //
+ + "d1 1e bc 80 fd 3e 71 11 81 17 40 74 26 25 44 bd " //
+ + "00 00 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " // Record
+ // 1
+ + "ff 00 00 05 00 01 c0 a8 88 0a " // contd
+ + "00 00 00 0a 01 20 10 00 00 00 00 01 98 10 fe 01 01 64 " // Record
+ // 2
+ + "ff 00 00 05 00 01 c0 a8 88 0b " // contd
+ + "00 00 00 0a 01 20 10 00 00 00 00 01 97 10 fe 01 01 64 " // Record
+ // 3
+ + "ff 00 00 05 00 01 c0 a8 88 0c " // contd
+ + "00 00 00 0a 01 20 10 00 00 00 00 01 96 10 fe 01 01 64 " // Record
+ // 4
+ + "ff 00 00 05 00 01 c0 a8 88 0d " // contd
+ ));
+
+ assertEquals(4, mr.getEidToLocatorRecords().size());
+ assertEquals(new LispIpv4Address("153.16.254.1"), mr
+ .getEidToLocatorRecords().get(0).getPrefix());
+ assertEquals(new LispIpv4Address("151.16.254.1"), mr
+ .getEidToLocatorRecords().get(2).getPrefix());
+ assertEquals(new LispIpv4Address("192.168.136.11"), mr
+ .getEidToLocatorRecords().get(1).getLocators().get(0)
+ .getLocator());
+ assertEquals(new LispIpv4Address("192.168.136.13"), mr
+ .getEidToLocatorRecords().get(3).getLocators().get(0)
+ .getLocator());
+ }
+
+ @Test
+ public void deserialize__Locators() throws Exception {
+ MapRegister mr = MapRegisterSerializer.getInstance().deserialize(
+ hexToByteBuffer("38 00 01 01 " //
+ + "FF BB 00 00 00 00 00 00 00 01 00 14 f1 b8 ab f0 " //
+ + "66 bb 2e ef 12 70 74 46 6f 6b 8e ca bf 1e 68 40 " //
+ + "00 00 00 0a " //
+ + "03 " // Locator Count
+ + "20 10 00 00 00 00 01 99 10 fe 01 "
+ // Locator 1
+ + "01 64 1f 00 " // priorities + weights
+ + "00 05 " // Flags
+ + "00 01 c0 a8 88 0a " // Locator
+ // Locator 2
+ + "67 00 30 34 " // priorities + weights
+ + "00 02 " // Flags
+ + "00 01 cc aa AA 11 " // Locator
+ // Locator 3
+ + "60 11 34 A4 " // priorities + weights
+ + "00 03 " // Flags
+ + "00 01 c0 a8 88 0a " // Locator
+ ));
+
+ assertEquals(1, mr.getEidToLocatorRecords().size());
+ EidToLocatorRecord eidToLocator = mr.getEidToLocatorRecords().get(0);
+ assertEquals(3, eidToLocator.getLocators().size());
+ LocatorRecord loc0 = eidToLocator.getLocators().get(0);
+ LocatorRecord loc1 = eidToLocator.getLocators().get(1);
+ LocatorRecord loc2 = eidToLocator.getLocators().get(2);
+ assertEquals((byte) 0x01, loc0.getPriority());
+ assertEquals((byte) 0x67, loc1.getPriority());
+ assertEquals((byte) 0x60, loc2.getPriority());
+
+ assertEquals((byte) 0x64, loc0.getWeight());
+ assertEquals((byte) 0x00, loc1.getWeight());
+ assertEquals((byte) 0x11, loc2.getWeight());
+
+ assertEquals((byte) 0x1F, loc0.getMulticastPriority());
+ assertEquals((byte) 0x30, loc1.getMulticastPriority());
+ assertEquals((byte) 0x34, loc2.getMulticastPriority());
+
+ assertEquals((byte) 0x00, loc0.getMulticastWeight());
+ assertEquals((byte) 0x34, loc1.getMulticastWeight());
+ assertEquals((byte) 0xA4, loc2.getMulticastWeight());
+
+ assertTrue(loc0.isLocalLocator());
+ assertFalse(loc1.isLocalLocator());
+ assertFalse(loc2.isLocalLocator());
+
+ assertFalse(loc0.isRlocProbed());
+ assertTrue(loc1.isRlocProbed());
+ assertTrue(loc2.isRlocProbed());
+
+ assertTrue(loc0.isRouted());
+ assertFalse(loc1.isRouted());
+ assertTrue(loc2.isRouted());
+
+ assertEquals(new LispIpv4Address(0xC0A8880A), loc0.getLocator());
+ assertEquals(new LispIpv4Address(0xCCAAAA11), loc1.getLocator());
+ }
+
+ @Test
+ public void deserialize__SomeEidToLocatorFiels() throws Exception {
+ // LISP(Type = 3 Map-Register, P=1, M=1
+ // Record Counter: 4
+ // EID prefixes: 153.16.254.1 -- 152.16.254.1 -- 151.16.254.1 --
+ // 150.16.254.1
+ // Local RLOCs: 192.168.136.10 -- 192.168.136.11 -- 192.168.136.12 --
+ // 192.168.136.13
+ //
+ MapRegister mr = MapRegisterSerializer
+ .getInstance()
+ .deserialize(
+ hexToByteBuffer("38 00 01 " //
+ + "04 " // Record count
+ + "FF BB 00 00 00 00 00 00 00 01 00 14 b9 cd 7b 89 " //
+ + "65 c2 56 03 be dd 81 20 47 e5 c3 4f 56 02 e1 59 " //
+ + "00 00 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " // Record
+ // 0
+ + "ff 00 00 05 00 01 c0 a8 88 0a " // contd
+ + "00 00 00 0b 01 17 50 00 01 11 00 01 98 10 fe 01 01 64 " // Record
+ // 1
+ + "ff 00 00 05 00 01 c0 a8 88 0b " // contd
+ + "00 00 00 0c 01 20 00 00 02 22 00 01 97 10 fe 01 01 64 " // Record
+ // 2
+ + "ff 00 00 05 00 01 c0 a8 88 0c " // contd
+ + "00 00 00 0d 01 20 20 00 03 33 00 01 96 10 fe 01 01 64 " // Record
+ // 3
+ + "ff 00 00 05 00 01 c0 a8 88 0d " // contd
+ ));
+
+ assertEquals(4, mr.getEidToLocatorRecords().size());
+
+ EidToLocatorRecord record0 = mr.getEidToLocatorRecords().get(0);
+ EidToLocatorRecord record1 = mr.getEidToLocatorRecords().get(1);
+ EidToLocatorRecord record2 = mr.getEidToLocatorRecords().get(2);
+ EidToLocatorRecord record3 = mr.getEidToLocatorRecords().get(3);
+
+ assertEquals(10, record0.getRecordTtl());
+ assertEquals(13, record3.getRecordTtl());
+
+ assertEquals(32, record0.getMaskLength());
+ assertEquals(23, record1.getMaskLength());
+
+ assertEquals(MapReplyAction.NoAction, record0.getAction());
+ assertEquals(MapReplyAction.SendMapRequest, record1.getAction());
+ assertEquals(MapReplyAction.NoAction, record2.getAction());
+ assertEquals(MapReplyAction.NativelyForward, record3.getAction());
+
+ assertTrue(record0.isAuthoritative());
+ assertTrue(record1.isAuthoritative());
+ assertFalse(record2.isAuthoritative());
+ assertFalse(record3.isAuthoritative());
+
+ assertEquals(0x000, record0.getMapVersion());
+ assertEquals(0x111, record1.getMapVersion());
+ assertEquals(0x222, record2.getMapVersion());
+ assertEquals(0x333, record3.getMapVersion());
+ }
+
+ @Test
+ public void deserialize__IllegalAction() throws Exception {
+ MapRegister mr = MapRegisterSerializer.getInstance().deserialize(
+ hexToByteBuffer("38 00 01 01 FF BB " //
+ + "00 00 00 00 00 00 00 01 00 14 ec 47 1e 53 25 91 " //
+ + "2f 68 10 75 13 dd 2c e8 6e 3c ac 94 ed e4 00 00 " //
+ + "00 0a 01 20 F0 00 00 00 00 01 99 10 fe 01 01 64 " //
+ + "ff 00 00 05 00 01 c0 a8 88 0a"));
+
+ assertEquals(1, mr.getEidToLocatorRecords().size());
+ assertEquals(MapReplyAction.NoAction, mr.getEidToLocatorRecords()
+ .get(0).getAction());
+ }
+
+ @Test(expected = LispSerializationException.class)
+ public void deserialize_WrongAuthenticationLength() throws Exception {
+ // LISP(Type = 3 Map-Register, P=1, M=1
+ // Record Counter: 1
+ // Nonce: (something)
+ // Key ID: 0x0000
+ // AuthDataLength: 20 Data:
+ // e8:f5:0b:c5:c5:f2:b0:21:27:a8:a5:68:89:ec
+ // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
+ // No-Action
+ // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
+ // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
+ //
+ MapRegisterSerializer.getInstance().deserialize(
+ hexToByteBuffer("38 00 01 01 FF BB " //
+ + "00 00 00 00 00 00 00 00 00 14 e8 f5 0b c5 c5 f2 " //
+ + "b0 21 27 a8 21 a5 68 89 ec 00 00 " //
+ + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
+ + "ff 00 00 05 00 01 c0 a8 88 0a"));
+ }
+
+
+ @Test
+ public void deserialize__SHA1() throws Exception {
+ // LISP(Type = 3 Map-Register, P=1, M=1
+ // Record Counter: 1
+ // Nonce: (something)
+ // Key ID: 0x0001
+ // AuthDataLength: 20 Data:
+ // b2:dd:1a:25:c0:60:b1:46:e8:dc:6d:a6:ae:2e:92:92:a6:ca:b7:9d
+ // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
+ // No-Action
+ // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
+ // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
+ //
+ MapRegister mr = MapRegisterSerializer.getInstance().deserialize(
+ hexToByteBuffer("38 00 01 01 FF BB " //
+ + "00 00 00 00 00 00 00 01 00 14 2c 61 b9 c9 9a 20 " //
+ + "ba d8 f5 40 d3 55 6f 5f 6e 5a b2 0a bf b5 00 00 " //
+ + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
+ + "ff 00 00 05 00 01 c0 a8 88 0a"));
+
+ assertTrue(mr.isProxyMapReply());
+ assertTrue(mr.isWantMapNotify());
+
+ assertEquals(1, mr.getEidToLocatorRecords().size());
+ assertEquals(0xFFBB000000000000L, mr.getNonce());
+ assertEquals(0x0001, mr.getKeyId());
+ byte[] expectedAuthenticationData = { (byte) 0x2c, (byte) 0x61,
+ (byte) 0xb9, (byte) 0xc9, (byte) 0x9a, (byte) 0x20,
+ (byte) 0xba,
+ (byte) 0xd8, //
+ (byte) 0xf5, (byte) 0x40, (byte) 0xd3, (byte) 0x55,
+ (byte) 0x6f, (byte) 0x5f, (byte) 0x6e, (byte) 0x5a, //
+ (byte) 0xb2, (byte) 0x0a, (byte) 0xbf, (byte) 0xb5 };
+ ArrayAssert.assertEquals(expectedAuthenticationData,
+ mr.getAuthenticationData());
+ }
+
+ @Test
+ public void deserialize__SHA256() throws Exception {
+ // LISP(Type = 3 Map-Register, P=1, M=1
+ // Record Counter: 1
+ // Nonce: (something)
+ // Key ID: 0x0002
+ // AuthDataLength: 32 Data:
+ // 70 30 d4 c6 10 44 0d 83 be 4d bf fd a9 8c 57 6d 68 a5 bf 32 11 c9 7b 58 c4 b9 9f 06 11 23 b9 38
+ // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
+ // No-Action
+ // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
+ // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
+ //
+ MapRegister mr = MapRegisterSerializer
+ .getInstance()
+ .deserialize(
+ hexToByteBuffer("38 00 01 01 FF BB " //
+ + "00 00 00 00 00 00 00 02 00 20 70 30 d4 c6 10 44 0d 83 be 4d bf fd a9 8c 57 6d 68 a5 bf 32 " //
+ + "11 c9 7b 58 c4 b9 9f 06 11 23 b9 38 00 00 " //
+ + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
+ + "ff 00 00 05 00 01 c0 a8 88 0a"));
+
+ assertTrue(mr.isProxyMapReply());
+ assertTrue(mr.isWantMapNotify());
+
+ assertEquals(1, mr.getEidToLocatorRecords().size());
+ assertEquals(0xFFBB000000000000L, mr.getNonce());
+ assertEquals(0x0002, mr.getKeyId());
+ byte[] expectedAuthenticationData = { (byte) 0x70, (byte) 0x30,
+ (byte) 0xd4, (byte) 0xc6, (byte) 0x10, (byte) 0x44,
+ (byte) 0x0d, (byte) 0x83, (byte) 0xbe, (byte) 0x4d,
+ (byte) 0xbf, (byte) 0xfd, (byte) 0xa9, (byte) 0x8c,
+ (byte) 0x57, (byte) 0x6d, (byte) 0x68, (byte) 0xa5,
+ (byte) 0xbf, (byte) 0x32, (byte) 0x11, (byte) 0xc9,
+ (byte) 0x7b, (byte) 0x58, (byte) 0xc4, (byte) 0xb9,
+ (byte) 0x9f, (byte) 0x06, (byte) 0x11, (byte) 0x23,
+ (byte) 0xb9, (byte) 0x38 };
+ ArrayAssert.assertEquals(expectedAuthenticationData,
+ mr.getAuthenticationData());
+ }
+
+}
* and is availabl at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.southbound.serializer;
+package org.opendaylight.lispflowmapping.implementation.serializer;
import static org.junit.Assert.assertEquals;
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.southbound.serializer;
+package org.opendaylight.lispflowmapping.implementation.serializer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
* 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.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
import static junit.framework.Assert.assertEquals;
import junitx.framework.ArrayAssert;
import org.junit.Test;
-import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
-import org.opendaylight.lispflowmapping.southbound.util.ByteUtil;
+import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
+import org.opendaylight.lispflowmapping.implementation.util.ByteUtil;
import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
assertEquals(LispCanonicalAddressFormatEnum.APPLICATION_DATA, appAddress.getType());
}
- @Test(expected = LispMalformedPacketException.class)
+ @Test(expected = LispSerializationException.class)
public void deserialize__ShorterBuffer() throws Exception {
LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
"04 20 00 0A " + //
"AA BB "));
}
- @Test(expected = LispMalformedPacketException.class)
+ @Test(expected = LispSerializationException.class)
public void deserialize__UnknownLCAFType() throws Exception {
LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
"AA 20 00 0A " + // Type AA is unknown
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.lispflowmapping.southbound.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
import static org.junit.Assert.assertEquals;
* 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.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.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.implementation.lisp.exception.LispSerializationException;
import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
assertEquals(0, addressList.size());
}
- @Test(expected = LispMalformedPacketException.class)
+ @Test(expected = LispSerializationException.class)
public void deserialize__ShorterBuffer() throws Exception {
LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
"01 00 00 18 " + //
"00 02 11 22 33 44 11 22 33 44 11 22 33 44"));
}
- @Test(expected = LispMalformedPacketException.class)
+ @Test(expected = LispSerializationException.class)
public void deserialize__ShorterBuffer2() throws Exception {
LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
"01 00 00 18 "));
* 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.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
import static junit.framework.Assert.assertEquals;
import junitx.framework.ArrayAssert;
import org.junit.Test;
-import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
+import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
assertEquals(LispCanonicalAddressFormatEnum.SEGMENT, segAddress.getType());
}
- @Test(expected = LispMalformedPacketException.class)
+ @Test(expected = LispSerializationException.class)
public void deserialize__ShorterBuffer() throws Exception {
LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
"02 20 00 0A " + //
"AA BB "));
}
- @Test(expected = LispMalformedPacketException.class)
+ @Test(expected = LispSerializationException.class)
public void deserialize__UnknownLCAFType() throws Exception {
LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
"AA 20 00 0A " + // Type AA is unknown
* 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.serializer.address;
+package org.opendaylight.lispflowmapping.implementation.serializer.address;
import static junit.framework.Assert.assertEquals;
import junitx.framework.ArrayAssert;
import org.junit.Test;
-import org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException;
+import org.opendaylight.lispflowmapping.implementation.lisp.exception.LispSerializationException;
import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
import org.opendaylight.lispflowmapping.type.LispCanonicalAddressFormatEnum;
assertEquals(new LispIpv4Address(0x11223344), srcDestAddress.getSrcAddress());
assertEquals(new LispIpv4Address(0x22334455), srcDestAddress.getDstAddress());
assertEquals(LispCanonicalAddressFormatEnum.SOURCE_DEST, srcDestAddress.getType());
- System.out.println(address);
}
- @Test(expected = LispMalformedPacketException.class)
+ @Test(expected = LispSerializationException.class)
public void deserialize__ShorterBuffer() throws Exception {
LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
"02 20 00 0A " + //
"AA BB "));
}
- @Test(expected = LispMalformedPacketException.class)
+ @Test(expected = LispSerializationException.class)
public void deserialize__UnknownLCAFType() throws Exception {
LispAddressSerializer.getInstance().deserialize(hexToByteBuffer("40 03 00 00 " + //
"AA 20 00 0A " + // Type AA is unknown
org.opendaylight.lispflowmapping.type,
org.opendaylight.lispflowmapping.type.lisp,
org.opendaylight.lispflowmapping.type.lisp.address,
- org.opendaylight.controller.clustering.services
+ org.opendaylight.controller.clustering.services,
+ org.opendaylight.lispflowmapping.implementation.serializer,
+ org.opendaylight.lispflowmapping.implementation.util
</Import-Package>
<Bundle-Activator>
org.opendaylight.lispflowmapping.southbound.Activator
<artifactId>mappingservice.api</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.lispflowmapping</groupId>
+ <artifactId>mappingservice.implementation</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ </dependency>
</dependencies>
</project>
import java.net.SocketTimeoutException;
import org.eclipse.osgi.framework.console.CommandProvider;
+import org.opendaylight.lispflowmapping.implementation.serializer.LispMessage;
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 java.net.DatagramPacket;
import java.nio.ByteBuffer;
+import org.opendaylight.lispflowmapping.implementation.serializer.LispMessage;
+import org.opendaylight.lispflowmapping.implementation.serializer.LispMessageEnum;
+import org.opendaylight.lispflowmapping.implementation.serializer.MapNotifySerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.MapRegisterSerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.MapReplySerializer;
+import org.opendaylight.lispflowmapping.implementation.serializer.MapRequestSerializer;
+import org.opendaylight.lispflowmapping.implementation.util.ByteUtil;
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;
-public class LispSouthboundService implements ILispSouthboundService{
+public class LispSouthboundService implements ILispSouthboundService {
private IMapResolver mapResolver;
private IMapServer mapServer;
}
private DatagramPacket handleMapRequest(ByteBuffer inBuffer) {
- int encapsulatedSourcePort = extractEncapsulatedSourcePort(inBuffer);
- MapRequest request = MapRequestSerializer.getInstance().deserialize(inBuffer);
- MapReply mapReply = mapResolver.handleMapRequest(request);
- ByteBuffer outBuffer = MapReplySerializer.getInstance().serialize(mapReply);
+ try {
+ int encapsulatedSourcePort = extractEncapsulatedSourcePort(inBuffer);
+ MapRequest request = MapRequestSerializer.getInstance().deserialize(inBuffer);
+ MapReply mapReply = mapResolver.handleMapRequest(request);
+ ByteBuffer outBuffer = MapReplySerializer.getInstance().serialize(mapReply);
- DatagramPacket replyPacket = new DatagramPacket(outBuffer.array(), outBuffer.capacity());
- replyPacket.setPort(encapsulatedSourcePort);
- return replyPacket;
+ DatagramPacket replyPacket = new DatagramPacket(outBuffer.array(), outBuffer.capacity());
+ replyPacket.setPort(encapsulatedSourcePort);
+ return replyPacket;
+ } catch (RuntimeException re) {
+ throw new LispMalformedPacketException("Couldn't deserialize Map-Request (len=" + inBuffer.capacity() + ")", re);
+ }
}
private int extractEncapsulatedSourcePort(ByteBuffer inBuffer) {
}
private DatagramPacket handleMapRegister(ByteBuffer inBuffer) {
- MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(inBuffer);
- MapNotify mapNotify = mapServer.handleMapRegister(mapRegister);
+ try {
+ MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(inBuffer);
+ MapNotify mapNotify = mapServer.handleMapRegister(mapRegister);
- if (mapNotify != null) {
- ByteBuffer outBuffer = MapNotifySerializer.getInstance().serialize(mapNotify);
- DatagramPacket notify = new DatagramPacket(outBuffer.array(), outBuffer.limit());
- notify.setPort(LispMessage.PORT_NUM);
- return notify;
- } else {
- return null;
+ if (mapNotify != null) {
+ ByteBuffer outBuffer = MapNotifySerializer.getInstance().serialize(mapNotify);
+ DatagramPacket notify = new DatagramPacket(outBuffer.array(), outBuffer.limit());
+ notify.setPort(LispMessage.PORT_NUM);
+ return notify;
+ } else {
+ return null;
+ }
+ } catch (RuntimeException re) {
+ throw new LispMalformedPacketException("Couldn't deserialize Map-Register (len=" + inBuffer.capacity() + ")", re);
}
}
}
import junitx.framework.ArrayAssert;
import junitx.framework.Assert;
+import org.apache.commons.lang3.ArrayUtils;
import org.jmock.api.Invocation;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
+import org.opendaylight.lispflowmapping.implementation.serializer.LispMessage;
+import org.opendaylight.lispflowmapping.implementation.serializer.LispMessageEnum;
+import org.opendaylight.lispflowmapping.implementation.util.ByteUtil;
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.lisp.EidRecord;
mapRegisterPacket = extractWSUdpByteArray(new String("0000 00 50 56 ee d1 4f 00 0c 29 7a ce 79 08 00 45 00 " //
+ "0010 00 5c 00 00 40 00 40 11 d4 db c0 a8 88 0a 80 df "
+ "0020 9c 23 d6 40 10 f6 00 48 59 a4 38 00 01 01 00 00 "
- + "0030 00 00 00 00 00 00 00 01 00 14 e8 f5 0b c5 c5 f2 "
- + "0040 b0 21 27 a8 21 41 04 f3 46 5a a5 68 89 ec 00 00 "
+ + "0030 00 00 00 00 00 00 00 01 00 14 0e a4 c6 d8 a4 06 "
+ + "0040 71 7c 33 a4 5c 4a 83 1c de 74 53 03 0c ad 00 00 "
+ "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
+ "0060 ff 00 00 05 00 01 c0 a8 88 0a"));
mapNotify = new MapNotify();
mapRegisterPacket = extractWSUdpByteArray(new String("0000 00 0c 29 7a ce 8d 00 0c 29 e4 ef 70 08 00 45 00 "
+ "0010 00 68 00 00 40 00 40 11 26 15 0a 01 00 6e 0a 01 " //
+ "0020 00 01 10 f6 10 f6 00 54 03 3b 38 00 01 01 00 00 " //
- + "0030 00 00 00 00 00 00 00 01 00 14 f8 3c d8 9d 92 8b " //
- + "0040 67 20 2c 63 82 63 c5 38 7b 74 b8 70 01 dd 00 00 " //
+ + "0030 00 00 00 00 00 00 00 01 00 14 ae d8 7b d4 9c 59 " //
+ + "0040 e9 35 75 6e f1 29 27 a3 45 20 96 06 c2 e1 00 00 " //
+ "0050 00 0a 02 20 10 00 00 00 00 01 ac 01 01 02 01 64 " //
+ "0060 ff 00 00 05 00 01 0a 01 00 6e 06 64 ff 00 00 05 " //
+ "0070 00 01 c0 a8 88 33"));
mapRegisterPacket = extractWSUdpByteArray(new String("0000 00 0c 29 34 3e 1b 00 0c 29 f6 d6 0d 08 00 45 00 " //
+ "0010 00 68 00 00 40 00 40 11 ea c3 0a 00 3a 9c 0a 00 " //
+ "0020 01 26 10 f6 10 f6 00 54 f5 9a 38 00 03 01 00 00 " //
- + "0030 00 00 00 00 00 00 00 01 00 14 5b c4 d4 4a 57 e2 " //
- + "0040 a5 5d 57 7a 6f 89 77 9c 00 4f 5d a7 13 fb 00 00 " //
+ + "0030 00 00 00 00 00 00 00 01 00 14 22 97 ff 61 ec d8 " //
+ + "0040 0f 91 c6 c4 01 ef 7f bb 77 58 39 5c 92 23 00 00 " //
+ "0050 00 0a 01 80 10 00 00 00 00 02 26 10 00 d0 ff ff " //
+ "0060 01 92 00 00 00 00 00 00 00 01 01 64 ff 00 00 05 " //
+ "0070 00 01 0a 00 3a 9c"));
byte[] registerWithNonSetMBit = extractWSUdpByteArray(new String("0000 00 50 56 ee d1 4f 00 0c 29 7a ce 79 08 00 45 00 " //
+ "0010 00 5c 00 00 40 00 40 11 d4 db c0 a8 88 0a 80 df " //
+ "0020 9c 23 d6 40 10 f6 00 48 59 a4 38 00 00 01 00 00 "
- + "0030 00 00 00 00 00 00 00 01 00 14 e8 f5 0b c5 c5 f2 "
- + "0040 b0 21 27 a8 21 41 04 f3 46 5a a5 68 89 ec 00 00 " //
+ + "0030 00 00 00 00 00 00 00 01 00 14 79 d1 44 66 19 99 "
+ + "0040 83 63 a7 79 6e f0 40 97 54 26 3a 44 b4 eb 00 00 " //
+ "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
+ "0060 ff 00 00 05 00 01 c0 a8 88 0a"));
stubMapRegister(true);
byte[] registerWithNonSetMBit = extractWSUdpByteArray(new String("0000 00 50 56 ee d1 4f 00 0c 29 7a ce 79 08 00 45 00 " //
+ "0010 00 5c 00 00 40 00 40 11 d4 db c0 a8 88 0a 80 df "
+ "0020 9c 23 d6 40 10 f6 00 48 59 a4 38 00 02 01 00 00 "
- + "0030 00 00 00 00 00 00 00 01 00 14 e8 f5 0b c5 c5 f2 "
- + "0040 b0 21 27 a8 21 41 04 f3 46 5a a5 68 89 ec 00 00 "
+ + "0030 00 00 00 00 00 00 00 01 00 14 c0 c7 c5 2f 57 f6 "
+ + "0040 e7 20 25 3d e8 b2 07 e2 63 de 62 2b 7a 20 00 00 "
+ "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
+ "0060 ff 00 00 05 00 01 c0 a8 88 0a"));
stubMapRegister(true);
byte[] registerWithNonSetMBit = extractWSUdpByteArray(new String("0000 00 50 56 ee d1 4f 00 0c 29 7a ce 79 08 00 45 00 " //
+ "0010 00 5c 00 00 40 00 40 11 d4 db c0 a8 88 0a 80 df "
+ "0020 9c 23 d6 40 10 f6 00 48 59 a4 38 00 03 01 00 00 "
- + "0030 00 00 00 00 00 00 00 01 00 14 e8 f5 0b c5 c5 f2 "
- + "0040 b0 21 27 a8 21 41 04 f3 46 5a a5 68 89 ec 00 00 "
+ + "0030 00 00 00 00 00 00 00 01 00 14 a2 72 40 7b 1a ae "
+ + "0040 4e 6b e2 e5 e1 01 40 8a c9 e1 d1 80 cb 72 00 00 "
+ "0050 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
+ "0060 ff 00 00 05 00 01 c0 a8 88 0a"));
stubMapRegister(true);
@Test
public void mapRegisterAndNotify__ValidExtraDataParsedSuccessfully() throws Exception {
+ mapRequestPacket = extractWSUdpByteArray(new String("0000 00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00 " //
+ + "0010 00 58 00 00 40 00 40 11 3c 93 7f 00 00 01 7f 00 "
+ + "0020 00 01 e4 c0 10 f6 00 44 fe 57 80 00 00 00 45 00 "
+ + "0030 00 38 d4 31 00 00 ff 11 56 f3 c0 a8 88 0a 01 02 "
+ + "0040 03 04 dd b4 10 f6 00 24 ef 3a 10 00 00 01 3d 8d "
+ + "0050 2a cd 39 c8 d6 08 00 00 00 01 c0 a8 88 0a 00 20 " //
+ + "0060 00 01 01 02 03 04"));
byte[] extraDataPacket = new byte[mapRegisterPacket.length + 3];
extraDataPacket[mapRegisterPacket.length] = 0x9;
System.arraycopy(mapRegisterPacket, 0, extraDataPacket, 0, mapRegisterPacket.length);
assertHexEquals((byte) 0x00, result[1]);
assertHexEquals((byte) 0x00, result[2]);
- byte[] registerWithoutType = Arrays.copyOfRange(mapRegisterPacket, 3, mapRegisterPacket.length);
- byte[] notifyWithoutType = Arrays.copyOfRange(result, 3, result.length);
- ArrayAssert.assertEquals(registerWithoutType, notifyWithoutType);
+ byte[] registerWithoutTypeWithoutAuthenticationData = ArrayUtils.addAll(Arrays.copyOfRange(mapRegisterPacket, 3, 16),Arrays.copyOfRange(mapRegisterPacket, 36, mapRegisterPacket.length));
+ byte[] notifyWithoutTypeWithOutAuthenticationData = ArrayUtils.addAll(Arrays.copyOfRange(result, 3, 16), Arrays.copyOfRange(result, 36, result.length));
+ ArrayAssert.assertEquals(registerWithoutTypeWithoutAuthenticationData, notifyWithoutTypeWithOutAuthenticationData);
}
@Test
+++ /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.serializer;
-
-import static junit.framework.Assert.assertEquals;
-
-import java.nio.ByteBuffer;
-
-import junitx.framework.ArrayAssert;
-
-import org.junit.Test;
-import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-import org.opendaylight.lispflowmapping.type.lisp.EidToLocatorRecord;
-import org.opendaylight.lispflowmapping.type.lisp.MapNotify;
-import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
-import org.opendaylight.lispflowmapping.type.lisp.address.LispNoAddress;
-
-public class MapNotifySerializationTest extends BaseTestCase {
-
- @Test
- public void serialize__Fields() throws Exception {
- MapNotify mn = new MapNotify();
- mn.addEidToLocator(new EidToLocatorRecord().setPrefix(new LispIpv4Address(1)));
-
- mn.addEidToLocator(new EidToLocatorRecord().setPrefix(new LispIpv4Address(73)));
- mn.setNonce(6161616161L);
- mn.setKeyId((short) 0xABCD);
- byte[] authenticationData = new byte[] { 0x03, 0x01, 0x04, 0x01, 0x05, 0x09, 0x02, 0x06 };
- mn.setAuthenticationData(authenticationData);
-
- 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
- assertEquals(6161616161L, bb.getLong()); // Nonce
- assertHexEquals((short) 0xABCD, bb.getShort()); // Key ID
- assertEquals(authenticationData.length, bb.getShort());
-
- byte[] actualAuthenticationData = new byte[8];
- bb.get(actualAuthenticationData);
- ArrayAssert.assertEquals(authenticationData, actualAuthenticationData);
-
- bb.position(bb.position() + 12); /* EID in first record */
- assertEquals(0x1, bb.getInt());
-
- bb.position(bb.position() + 12); /* EID in second record */
- assertEquals(73, bb.getInt());
-
- assertEquals(bb.position(), bb.capacity());
- }
-
- @Test
- public void serialize__NoAuthenticationData() throws Exception {
- MapNotify mn = new MapNotify();
- mn.addEidToLocator(new EidToLocatorRecord().setPrefix(new LispIpv4Address(1)).setRecordTtl(55));
-
- 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 = 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 = MapNotifySerializer.getInstance().serialize(mn);
- bb.position(bb.position() + 14); // jump to AuthenticationDataLength
- assertEquals(0, bb.getShort());
- assertEquals(55, bb.getInt());
- }
-
- @Test
- public void serialize__NoPrefixInEidToLocator() throws Exception {
- MapNotify mn = new MapNotify();
- mn.addEidToLocator(new EidToLocatorRecord());
- mn.addEidToLocator(new EidToLocatorRecord().setPrefix(null));
- mn.addEidToLocator(new EidToLocatorRecord().setPrefix(new LispNoAddress()));
-
- ByteBuffer bb = MapNotifySerializer.getInstance().serialize(mn);
- bb.position(bb.position() + 26); // jump to first record prefix AFI
- assertEquals(0, bb.getShort());
-
- bb.position(bb.position() + 10); // jump to second record prefix AFI
- assertEquals(0, bb.getShort());
-
- bb.position(bb.position() + 10); // jump to third record prefix AFI
- assertEquals(0, bb.getShort());
- }
-}
+++ /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.serializer;
-
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.assertTrue;
-import junitx.framework.ArrayAssert;
-
-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.MapRegister;
-import org.opendaylight.lispflowmapping.type.lisp.MapReplyAction;
-import org.opendaylight.lispflowmapping.type.lisp.address.LispIpv4Address;
-
-public class MapRegisterSerializationTest extends BaseTestCase {
-
- @Test
- public void deserialize__AllFields() throws Exception {
- // LISP(Type = 3 Map-Register, P=1, M=1
- // Record Counter: 1
- // Nonce: (something)
- // Key ID: 0x0001
- // AuthDataLength: 20 Data:
- // e8:f5:0b:c5:c5:f2:b0:21:27:a8:21:41:04:f3:46:5a:a5:68:89:ec
- // EID prefix: 153.16.254.1/32 (EID=0x9910FE01), TTL: 10, Authoritative,
- // No-Action
- // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
- // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
- //
- 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 " //
- + "ff 00 00 05 00 01 c0 a8 88 0a"));
-
- assertTrue(mr.isProxyMapReply());
- assertTrue(mr.isWantMapNotify());
-
- assertEquals(1, mr.getEidToLocatorRecords().size());
- assertEquals(0xFFBB000000000000L, mr.getNonce());
- assertEquals(0x0001, mr.getKeyId());
- byte[] expectedAuthenticationData = { (byte) 0xe8, (byte) 0xf5, (byte) 0x0b, (byte) 0xc5, (byte) 0xc5, (byte) 0xf2, (byte) 0xb0, (byte) 0x21, //
- (byte) 0x27, (byte) 0xa8, (byte) 0x21, (byte) 0x41, (byte) 0x04, (byte) 0xf3, (byte) 0x46, (byte) 0x5a, //
- (byte) 0xa5, (byte) 0x68, (byte) 0x89, (byte) 0xec };
- ArrayAssert.assertEquals(expectedAuthenticationData, mr.getAuthenticationData());
- }
-
- @Test
- public void deserialize__MultipleRecords() throws Exception {
- // LISP(Type = 3 Map-Register, P=1, M=1
- // Record Counter: 4
- // EID prefixes: 153.16.254.1 -- 152.16.254.1 -- 151.16.254.1 --
- // 150.16.254.1
- // Local RLOCs: 192.168.136.10 -- 192.168.136.11 -- 192.168.136.12 --
- // 192.168.136.13
- //
- 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 " //
- + "00 00 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " // Record
- // 1
- + "ff 00 00 05 00 01 c0 a8 88 0a " // contd
- + "00 00 00 0a 01 20 10 00 00 00 00 01 98 10 fe 01 01 64 " // Record
- // 2
- + "ff 00 00 05 00 01 c0 a8 88 0b " // contd
- + "00 00 00 0a 01 20 10 00 00 00 00 01 97 10 fe 01 01 64 " // Record
- // 3
- + "ff 00 00 05 00 01 c0 a8 88 0c " // contd
- + "00 00 00 0a 01 20 10 00 00 00 00 01 96 10 fe 01 01 64 " // Record
- // 4
- + "ff 00 00 05 00 01 c0 a8 88 0d " // contd
- ));
-
- assertEquals(4, mr.getEidToLocatorRecords().size());
- assertEquals(new LispIpv4Address("153.16.254.1"), mr.getEidToLocatorRecords().get(0).getPrefix());
- assertEquals(new LispIpv4Address("151.16.254.1"), mr.getEidToLocatorRecords().get(2).getPrefix());
- assertEquals(new LispIpv4Address("192.168.136.11"), mr.getEidToLocatorRecords().get(1).getLocators().get(0).getLocator());
- assertEquals(new LispIpv4Address("192.168.136.13"), mr.getEidToLocatorRecords().get(3).getLocators().get(0).getLocator());
- }
-
- @Test
- public void deserialize__Locators() throws Exception {
- 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 " //
- + "03 " // Locator Count
- + "20 10 00 00 00 00 01 99 10 fe 01 "
- // Locator 1
- + "01 64 1f 00 " // priorities + weights
- + "00 05 " // Flags
- + "00 01 c0 a8 88 0a " // Locator
- // Locator 2
- + "67 00 30 34 " // priorities + weights
- + "00 02 " // Flags
- + "00 01 cc aa AA 11 " // Locator
- // Locator 3
- + "60 11 34 A4 " // priorities + weights
- + "00 03 " // Flags
- + "00 01 c0 a8 88 0a " // Locator
- ));
-
- assertEquals(1, mr.getEidToLocatorRecords().size());
- EidToLocatorRecord eidToLocator = mr.getEidToLocatorRecords().get(0);
- assertEquals(3, eidToLocator.getLocators().size());
- LocatorRecord loc0 = eidToLocator.getLocators().get(0);
- LocatorRecord loc1 = eidToLocator.getLocators().get(1);
- LocatorRecord loc2 = eidToLocator.getLocators().get(2);
- assertEquals((byte) 0x01, loc0.getPriority());
- assertEquals((byte) 0x67, loc1.getPriority());
- assertEquals((byte) 0x60, loc2.getPriority());
-
- assertEquals((byte) 0x64, loc0.getWeight());
- assertEquals((byte) 0x00, loc1.getWeight());
- assertEquals((byte) 0x11, loc2.getWeight());
-
- assertEquals((byte) 0x1F, loc0.getMulticastPriority());
- assertEquals((byte) 0x30, loc1.getMulticastPriority());
- assertEquals((byte) 0x34, loc2.getMulticastPriority());
-
- assertEquals((byte) 0x00, loc0.getMulticastWeight());
- assertEquals((byte) 0x34, loc1.getMulticastWeight());
- assertEquals((byte) 0xA4, loc2.getMulticastWeight());
-
- assertTrue(loc0.isLocalLocator());
- assertFalse(loc1.isLocalLocator());
- assertFalse(loc2.isLocalLocator());
-
- assertFalse(loc0.isRlocProbed());
- assertTrue(loc1.isRlocProbed());
- assertTrue(loc2.isRlocProbed());
-
- assertTrue(loc0.isRouted());
- assertFalse(loc1.isRouted());
- assertTrue(loc2.isRouted());
-
- assertEquals(new LispIpv4Address(0xC0A8880A), loc0.getLocator());
- assertEquals(new LispIpv4Address(0xCCAAAA11), loc1.getLocator());
- }
-
- @Test
- public void deserialize__SomeEidToLocatorFiels() throws Exception {
- // LISP(Type = 3 Map-Register, P=1, M=1
- // Record Counter: 4
- // EID prefixes: 153.16.254.1 -- 152.16.254.1 -- 151.16.254.1 --
- // 150.16.254.1
- // Local RLOCs: 192.168.136.10 -- 192.168.136.11 -- 192.168.136.12 --
- // 192.168.136.13
- //
- 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 " //
- + "00 00 00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " // Record
- // 0
- + "ff 00 00 05 00 01 c0 a8 88 0a " // contd
- + "00 00 00 0b 01 17 50 00 01 11 00 01 98 10 fe 01 01 64 " // Record
- // 1
- + "ff 00 00 05 00 01 c0 a8 88 0b " // contd
- + "00 00 00 0c 01 20 00 00 02 22 00 01 97 10 fe 01 01 64 " // Record
- // 2
- + "ff 00 00 05 00 01 c0 a8 88 0c " // contd
- + "00 00 00 0d 01 20 20 00 03 33 00 01 96 10 fe 01 01 64 " // Record
- // 3
- + "ff 00 00 05 00 01 c0 a8 88 0d " // contd
- ));
-
- assertEquals(4, mr.getEidToLocatorRecords().size());
-
- EidToLocatorRecord record0 = mr.getEidToLocatorRecords().get(0);
- EidToLocatorRecord record1 = mr.getEidToLocatorRecords().get(1);
- EidToLocatorRecord record2 = mr.getEidToLocatorRecords().get(2);
- EidToLocatorRecord record3 = mr.getEidToLocatorRecords().get(3);
-
- assertEquals(10, record0.getRecordTtl());
- assertEquals(13, record3.getRecordTtl());
-
- assertEquals(32, record0.getMaskLength());
- assertEquals(23, record1.getMaskLength());
-
- assertEquals(MapReplyAction.NoAction, record0.getAction());
- assertEquals(MapReplyAction.SendMapRequest, record1.getAction());
- assertEquals(MapReplyAction.NoAction, record2.getAction());
- assertEquals(MapReplyAction.NativelyForward, record3.getAction());
-
- assertTrue(record0.isAuthoritative());
- assertTrue(record1.isAuthoritative());
- assertFalse(record2.isAuthoritative());
- assertFalse(record3.isAuthoritative());
-
- assertEquals(0x000, record0.getMapVersion());
- assertEquals(0x111, record1.getMapVersion());
- assertEquals(0x222, record2.getMapVersion());
- assertEquals(0x333, record3.getMapVersion());
- }
-
- @Test
- public void deserialize__IllegalAction() throws Exception {
- 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 " //
- + "ff 00 00 05 00 01 c0 a8 88 0a"));
-
- assertEquals(1, mr.getEidToLocatorRecords().size());
- assertEquals(MapReplyAction.NoAction, mr.getEidToLocatorRecords().get(0).getAction());
- }
-
-}