added authentication to map notify and map reply, and moved the serialization process... 24/1024/8
authorDavid Goldberg <david.goldberg@contextream.com>
Sun, 4 Aug 2013 11:08:43 +0000 (14:08 +0300)
committerDavid Goldberg <david.goldberg@contextream.com>
Wed, 7 Aug 2013 16:08:21 +0000 (19:08 +0300)
Change-Id: I145eef8c1818cb1d5700e70a261409a67000121b
Signed-off-by: David Goldberg <david.goldberg@contextream.com>
51 files changed:
mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/type/lisp/MapNotify.java
mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/type/lisp/MapRegister.java
mappingservice/implementation/pom.xml
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/authentication/ILispAuthentication.java [new file with mode: 0644]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/authentication/LispAuthenticationFactory.java [new file with mode: 0644]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/authentication/LispAuthenticationUtil.java [new file with mode: 0644]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/authentication/LispKeyIDEnum.java [new file with mode: 0644]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/authentication/LispMACAuthentication.java [new file with mode: 0644]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/authentication/LispNoAuthentication.java [new file with mode: 0644]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/lisp/MapServer.java
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/lisp/exception/LispSerializationException.java [new file with mode: 0644]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/EidRecordSerializer.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/EidRecordSerializer.java with 82% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/EidToLocatorRecordSerializer.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/EidToLocatorRecordSerializer.java with 89% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/LispMessage.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/LispMessage.java with 85% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/LispMessageEnum.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/LispMessageEnum.java with 92% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/LocatorRecordSerializer.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/LocatorRecordSerializer.java with 87% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/MapNotifySerializer.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/MapNotifySerializer.java with 89% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/MapRegisterSerializer.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/MapRegisterSerializer.java with 51% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/MapReplySerializer.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/MapReplySerializer.java with 96% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/MapRequestSerializer.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/MapRequestSerializer.java with 82% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispASAddressSerializer.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/address/LispASAddressSerializer.java with 92% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispAddressSerializer.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/address/LispAddressSerializer.java with 80% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispAddressSerializerFactory.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/address/LispAddressSerializerFactory.java with 96% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispApplicationDataLCAFAddressSerializer.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/address/LispApplicationDataLCAFAddressSerializer.java with 88% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispIPAddressSerializer.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/address/LispIPAddressSerializer.java with 87% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispIpv4AddressSerializer.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/address/LispIpv4AddressSerializer.java with 93% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispIpv6AddressSerializer.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/address/LispIpv6AddressSerializer.java with 93% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispLCAFAddressSerializer.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/address/LispLCAFAddressSerializer.java with 90% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispListLCAFAddressSerializer.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/address/LispListLCAFAddressSerializer.java with 95% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispMACAddressSerializer.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/address/LispMACAddressSerializer.java with 93% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispNoAddressSerializer.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/address/LispNoAddressSerializer.java with 91% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispSegmentLCAFAddressSerializer.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/address/LispSegmentLCAFAddressSerializer.java with 85% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispSourceDestLCAFAddressSerializer.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/serializer/address/LispSourceDestLCAFAddressSerializer.java with 87% similarity]
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/util/ByteUtil.java [moved from mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/util/ByteUtil.java with 96% similarity]
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/authentication/LispAuthenticationTest.java [new file with mode: 0644]
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/lisp/MapServerTest.java
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/MapNotifySerializationTest.java [new file with mode: 0644]
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/MapRegisterSerializationTest.java [new file with mode: 0644]
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/MapReplySerializationTest.java [moved from mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/serializer/MapReplySerializationTest.java with 99% similarity]
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/MapRequestSerializationTest.java [moved from mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/serializer/MapRequestSerializationTest.java with 98% similarity]
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispApplicationDataLCAFAddressTest.java [moved from mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/serializer/address/LispApplicationDataLCAFAddressTest.java with 92% similarity]
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispIpv6AddressTest.java [moved from mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/serializer/address/LispIpv6AddressTest.java with 95% similarity]
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispListLCAFAddressTest.java [moved from mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/serializer/address/LispListLCAFAddressTest.java with 95% similarity]
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispSegmentLCAFAddressTest.java [moved from mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/serializer/address/LispSegmentLCAFAddressTest.java with 94% similarity]
mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/address/LispSourceDestLCAFAddressTest.java [moved from mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/serializer/address/LispSourceDestLCAFAddressTest.java with 93% similarity]
mappingservice/southbound/pom.xml
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/LispSouthboundPlugin.java
mappingservice/southbound/src/main/java/org/opendaylight/lispflowmapping/southbound/lisp/LispSouthboundService.java
mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/lisp/LispSouthboundServiceTest.java
mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/serializer/MapNotifySerializationTest.java [deleted file]
mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/serializer/MapRegisterSerializationTest.java [deleted file]

index dbeac0176a8ef66ff718a97414473f14b7835c79..01a02d0062998750cec44c6889a89336260cbf39 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.lispflowmapping.type.lisp;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -169,6 +170,7 @@ public class MapNotify {
         byte[] authenticationData = mapRegister.getAuthenticationData();
         if (authenticationData != null) {
             authenticationData = authenticationData.clone();
+            Arrays.fill(authenticationData, (byte)0);
         }
         setAuthenticationData(authenticationData);
 
index 5897d175c56fdeced9805a9052858912162793ed..578c2584760b644124de6cea431ec9bde235d749 100644 (file)
@@ -93,6 +93,11 @@ public class MapRegister {
      * 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.
@@ -159,6 +164,15 @@ public class MapRegister {
         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[] {};
 }
index 70ec0ab475ca3216493c85e08d5e1d4b9e081866..9e54c5e8e5be9927c281077779e267495c1d6de2 100644 (file)
@@ -22,6 +22,8 @@
                                <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
diff --git a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/authentication/ILispAuthentication.java b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/authentication/ILispAuthentication.java
new file mode 100644 (file)
index 0000000..c0e8b1c
--- /dev/null
@@ -0,0 +1,13 @@
+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
diff --git a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/authentication/LispAuthenticationFactory.java b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/authentication/LispAuthenticationFactory.java
new file mode 100644 (file)
index 0000000..57804f4
--- /dev/null
@@ -0,0 +1,27 @@
+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);
+       }
+       
+
+}
diff --git a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/authentication/LispAuthenticationUtil.java b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/authentication/LispAuthenticationUtil.java
new file mode 100644 (file)
index 0000000..1a927c2
--- /dev/null
@@ -0,0 +1,21 @@
+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);
+    }
+
+       
+
+}
diff --git a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/authentication/LispKeyIDEnum.java b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/authentication/LispKeyIDEnum.java
new file mode 100644 (file)
index 0000000..0c9d531
--- /dev/null
@@ -0,0 +1,34 @@
+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;
+    }
+}
diff --git a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/authentication/LispMACAuthentication.java b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/authentication/LispMACAuthentication.java
new file mode 100644 (file)
index 0000000..3f6b8a2
--- /dev/null
@@ -0,0 +1,71 @@
+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());
+    }
+
+}
diff --git a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/authentication/LispNoAuthentication.java b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/authentication/LispNoAuthentication.java
new file mode 100644 (file)
index 0000000..a56a0e6
--- /dev/null
@@ -0,0 +1,32 @@
+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;
+    }
+
+}
index bb5d5d00e799f6182902387c37e30b111bae33ae..21370153833309d46a4519e18351bf82638b3483 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.lispflowmapping.implementation.lisp;
 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;
@@ -35,6 +36,9 @@ public class MapServer implements 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()));
@@ -47,7 +51,9 @@ public class MapServer implements IMapServer {
         if (mapRegister.isWantMapNotify()) {
             mapNotify = new MapNotify();
             mapNotify.setFromMapRegister(mapRegister);
+            mapNotify.setAuthenticationData(LispAuthenticationUtil.getAuthenticationData(mapNotify));
         }
         return mapNotify;
     }
+    
 }
diff --git a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/lisp/exception/LispSerializationException.java b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/lisp/exception/LispSerializationException.java
new file mode 100644 (file)
index 0000000..bae12b1
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * 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);
+    }
+}
@@ -1,8 +1,8 @@
-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;
 
@@ -1,10 +1,10 @@
-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;
@@ -6,7 +6,7 @@
  * 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;
@@ -1,10 +1,10 @@
-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 {
@@ -1,4 +1,4 @@
-package org.opendaylight.lispflowmapping.southbound.serializer;
+package org.opendaylight.lispflowmapping.implementation.serializer;
 
 import java.nio.ByteBuffer;
 
@@ -34,14 +34,11 @@ public class MapNotifySerializer {
         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;
     }
@@ -1,28 +1,35 @@
-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();
 
@@ -33,7 +40,6 @@ public class MapRegisterSerializer {
             byte recordCount = registerBuffer.get();
             mapRegister.setNonce(registerBuffer.getLong());
             mapRegister.setKeyId(registerBuffer.getShort());
-
             short authenticationLength = registerBuffer.getShort();
             byte[] authenticationData = new byte[authenticationLength];
             registerBuffer.get(authenticationData);
@@ -42,19 +48,24 @@ public class MapRegisterSerializer {
             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;
     }
 }
@@ -1,10 +1,10 @@
-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;
 
 
@@ -51,7 +51,7 @@ public class MapRequestSerializer {
             }
             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);
         }
     }
        
@@ -1,8 +1,8 @@
-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;
 
@@ -35,12 +35,12 @@ public class LispAddressSerializer {
         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());
         }
     }
 
@@ -1,9 +1,9 @@
-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;
@@ -37,7 +37,7 @@ public class LispApplicationDataLCAFAddressSerializer extends LispLCAFAddressSer
         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());
     }
@@ -1,8 +1,8 @@
-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;
@@ -29,7 +29,7 @@ public class LispLCAFAddressSerializer extends LispAddressSerializer{
 
         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);
     }
@@ -1,8 +1,8 @@
-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;
 
@@ -31,7 +31,7 @@ public class LispSegmentLCAFAddressSerializer extends LispLCAFAddressSerializer{
         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());
     }
@@ -1,8 +1,8 @@
-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;
 
@@ -37,12 +37,12 @@ public class LispSourceDestLCAFAddressSerializer extends LispLCAFAddressSerializ
         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());
     }
diff --git a/mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/authentication/LispAuthenticationTest.java b/mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/authentication/LispAuthenticationTest.java
new file mode 100644 (file)
index 0000000..2d07714
--- /dev/null
@@ -0,0 +1,167 @@
+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));
+
+    }
+
+}
index 82efecf1b6d4f06c059a146c993ee6f5764a8acf..ccdcfe72d319fa81af69ba7392d4726970241efc 100644 (file)
@@ -82,14 +82,14 @@ public class MapServerTest extends BaseTestCase {
     @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);
 
@@ -99,11 +99,9 @@ public class MapServerTest extends BaseTestCase {
 
         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());
diff --git a/mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/MapNotifySerializationTest.java b/mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/MapNotifySerializationTest.java
new file mode 100644 (file)
index 0000000..d2011de
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * 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());
+       }
+}
diff --git a/mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/MapRegisterSerializationTest.java b/mappingservice/implementation/src/test/java/org/opendaylight/lispflowmapping/implementation/serializer/MapRegisterSerializationTest.java
new file mode 100644 (file)
index 0000000..cef3c02
--- /dev/null
@@ -0,0 +1,333 @@
+/*
+ * 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());
+       }
+
+}
@@ -5,7 +5,7 @@
  * 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;
 
@@ -14,8 +14,8 @@ import java.nio.ByteBuffer;
 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;
@@ -45,14 +45,14 @@ public class LispApplicationDataLCAFAddressTest extends BaseTestCase {
         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
@@ -5,7 +5,7 @@
  * 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;
 
@@ -18,7 +18,7 @@ import junitx.framework.ArrayAssert;
 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;
@@ -62,7 +62,7 @@ public class LispListLCAFAddressTest extends BaseTestCase {
         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 " + //
@@ -70,7 +70,7 @@ public class LispListLCAFAddressTest extends BaseTestCase {
                 "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 "));
@@ -5,7 +5,7 @@
  * 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;
 
@@ -14,7 +14,7 @@ import java.nio.ByteBuffer;
 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;
@@ -41,14 +41,14 @@ public class LispSegmentLCAFAddressTest extends BaseTestCase {
         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
@@ -5,7 +5,7 @@
  * 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;
 
@@ -14,7 +14,7 @@ import java.nio.ByteBuffer;
 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;
@@ -43,17 +43,16 @@ public class LispSourceDestLCAFAddressTest extends BaseTestCase {
         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
index 158958f9857300284a73f9b26492b61b188b1371..514c880bd4af40d1cfa8c31ab26a04e7260e79c8 100644 (file)
@@ -35,7 +35,9 @@
                                                        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>
index f780b31ee7942cd508a467336a9a6b3a872c8f89..273aaf03eab727deb35037cf126dabef11224115 100644 (file)
@@ -16,9 +16,9 @@ import java.net.SocketException;
 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;
index 402470603f65fdd9a796a5f4b5cbc5f5052c8795..2440ba832de21ddbab08a406d707b826fa0a43e7 100644 (file)
@@ -11,23 +11,23 @@ package org.opendaylight.lispflowmapping.southbound.lisp;
 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;
 
@@ -51,14 +51,18 @@ public class LispSouthboundService implements ILispSouthboundService{
     }
 
     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) {
@@ -80,16 +84,20 @@ public class LispSouthboundService implements ILispSouthboundService{
     }
 
     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);
         }
     }
 }
index 8f98b928387ffbdab433577d5959084c94369281..9868bfee6271d874a90ab2d236743a2603ec7d26 100644 (file)
@@ -19,16 +19,17 @@ import java.util.List;
 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;
@@ -126,8 +127,8 @@ public class LispSouthboundServiceTest extends BaseTestCase {
         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();
@@ -179,8 +180,8 @@ public class LispSouthboundServiceTest extends BaseTestCase {
         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"));
@@ -215,8 +216,8 @@ public class LispSouthboundServiceTest extends BaseTestCase {
         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"));
@@ -261,8 +262,8 @@ public class LispSouthboundServiceTest extends BaseTestCase {
         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);
@@ -277,8 +278,8 @@ public class LispSouthboundServiceTest extends BaseTestCase {
         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);
@@ -292,8 +293,8 @@ public class LispSouthboundServiceTest extends BaseTestCase {
         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);
@@ -304,6 +305,13 @@ public class LispSouthboundServiceTest extends BaseTestCase {
 
     @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);
@@ -333,9 +341,9 @@ public class LispSouthboundServiceTest extends BaseTestCase {
         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
diff --git a/mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/serializer/MapNotifySerializationTest.java b/mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/serializer/MapNotifySerializationTest.java
deleted file mode 100644 (file)
index 9cda040..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * 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());
-    }
-}
diff --git a/mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/serializer/MapRegisterSerializationTest.java b/mappingservice/southbound/src/test/java/org/opendaylight/lispflowmapping/southbound/serializer/MapRegisterSerializationTest.java
deleted file mode 100644 (file)
index f236b17..0000000
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- * 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());
-    }
-
-}