Fix: Store router identifier combines with scheme as a DeviceId

Use hashcode of mapping key as an unique mapping identifier.

Change-Id: I7ed602467e889b70279cb9fabdc6340fa4f42f99
diff --git a/providers/lisp/mapping/src/main/java/org/onosproject/provider/lisp/mapping/impl/LispMappingProvider.java b/providers/lisp/mapping/src/main/java/org/onosproject/provider/lisp/mapping/impl/LispMappingProvider.java
index eb985c3..b4fd841 100644
--- a/providers/lisp/mapping/src/main/java/org/onosproject/provider/lisp/mapping/impl/LispMappingProvider.java
+++ b/providers/lisp/mapping/src/main/java/org/onosproject/provider/lisp/mapping/impl/LispMappingProvider.java
@@ -42,6 +42,8 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.List;
 
 import static org.onosproject.mapping.MappingStore.Type.MAP_CACHE;
@@ -137,7 +139,7 @@
                 return;
             }
 
-            DeviceId deviceId = DeviceId.deviceId(routerId.toString());
+            DeviceId deviceId = getDeviceId(routerId.toString());
             switch (msg.getType()) {
 
                 case LISP_MAP_REQUEST:
@@ -162,7 +164,7 @@
                 return;
             }
 
-            DeviceId deviceId = DeviceId.deviceId(routerId.toString());
+            DeviceId deviceId = getDeviceId(routerId.toString());
             switch (msg.getType()) {
 
                 case LISP_MAP_REPLY:
@@ -197,4 +199,19 @@
             });
         }
     }
+
+    /**
+     * Obtains the DeviceId contains IP address of LISP router.
+     *
+     * @param ip IP address
+     * @return DeviceId device identifier
+     */
+    private DeviceId getDeviceId(String ip) {
+        try {
+            return DeviceId.deviceId(new URI(SCHEME_NAME, ip, null));
+        } catch (URISyntaxException e) {
+            throw new IllegalArgumentException("Unable to build deviceID for device "
+                    + ip, e);
+        }
+    }
 }
diff --git a/providers/lisp/mapping/src/main/java/org/onosproject/provider/lisp/mapping/util/MappingEntryBuilder.java b/providers/lisp/mapping/src/main/java/org/onosproject/provider/lisp/mapping/util/MappingEntryBuilder.java
index 9f78e80..10162cd 100644
--- a/providers/lisp/mapping/src/main/java/org/onosproject/provider/lisp/mapping/util/MappingEntryBuilder.java
+++ b/providers/lisp/mapping/src/main/java/org/onosproject/provider/lisp/mapping/util/MappingEntryBuilder.java
@@ -52,7 +52,6 @@
 import org.slf4j.LoggerFactory;
 
 import java.util.List;
-import java.util.UUID;
 
 import static org.onosproject.mapping.addresses.ExtensionMappingAddressType.ExtensionMappingAddressTypes.*;
 
@@ -112,12 +111,8 @@
     public MappingEntry build() {
         Mapping.Builder builder;
 
-        // we assign leastSignificantBits of UUID as the mapping identifier for now
-        // id generation scheme can be changed later
-        UUID uuid = UUID.randomUUID();
-
         builder = DefaultMapping.builder()
-                .withId(uuid.getLeastSignificantBits())
+                .withId(buildKey().hashCode())
                 .forDevice(deviceId)
                 .withKey(buildKey())
                 .withValue(buildValue());