Fixes related to SDN-IP intents:
 * Use intent priority when installing multipoint-to-singlepoint intents:
   the loinger the routing prefix match, the higher the intent priority.
   This is needed to perform correctly the equivalent of longest prefix
   match in the switch.
 * Use intent priority for the point-to-point intents: the priority for
   this BGP-related control traffic is higher than the
   multipoint-to-singlepoint intents.

 * Use the appropriate Key when installing multipoint-to-singlepoint intents.
   The key is the network (destination routing) prefix address represented
   as a string.

Change-Id: Ic489a1e5f31adceb4c9d1dcea52293a2b3db0b79
diff --git a/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java b/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java
index cc65ccc..badad7f 100644
--- a/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java
+++ b/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java
@@ -32,6 +32,7 @@
 import org.onosproject.net.intent.Intent;
 import org.onosproject.net.intent.IntentService;
 import org.onosproject.net.intent.IntentState;
+import org.onosproject.net.intent.Key;
 import org.onosproject.net.intent.MultiPointToSinglePointIntent;
 import org.onosproject.net.intent.PointToPointIntent;
 import org.onosproject.routing.FibListener;
@@ -43,6 +44,7 @@
 import org.slf4j.LoggerFactory;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedList;
@@ -62,6 +64,9 @@
  * IntentService.
  */
 public class IntentSynchronizer implements FibListener {
+    private static final int PRIORITY_OFFSET = 100;
+    private static final int PRIORITY_MULTIPLIER = 5;
+
     private static final Logger log =
         LoggerFactory.getLogger(IntentSynchronizer.class);
 
@@ -332,9 +337,14 @@
             selector.matchVlanId(VlanId.ANY);
         }
 
-        return new MultiPointToSinglePointIntent(appId, selector.build(),
+        int priority =
+            prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
+        Key key = Key.of(prefix.toString(), appId);
+        return new MultiPointToSinglePointIntent(appId, key, selector.build(),
                                                  treatment.build(),
-                                                 ingressPorts, egressPort);
+                                                 ingressPorts, egressPort,
+                                                 Collections.emptyList(),
+                                                 priority);
     }
 
     @Override