Add priority to Intents

Change-Id: Ibe63356f5b15a6aa6ca7731dba3382c3317a95ec
diff --git a/apps/intent-perf/src/main/java/org/onosproject/intentperf/IntentPerfInstaller.java b/apps/intent-perf/src/main/java/org/onosproject/intentperf/IntentPerfInstaller.java
index 8613101..80606267 100644
--- a/apps/intent-perf/src/main/java/org/onosproject/intentperf/IntentPerfInstaller.java
+++ b/apps/intent-perf/src/main/java/org/onosproject/intentperf/IntentPerfInstaller.java
@@ -210,7 +210,8 @@
             Intent intent = new PointToPointIntent(appId, key,
                                                    selector, treatment,
                                                    ingress, egress,
-                                                   Collections.emptyList());
+                                                   Collections.emptyList(),
+                                                   Intent.DEFAULT_INTENT_PRIORITY);
             result.add(intent);
 
             // Bump up the counter and remember this as the last key used.
diff --git a/cli/src/main/java/org/onosproject/cli/net/AddMultiPointToSinglePointIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddMultiPointToSinglePointIntentCommand.java
index 69feb35..abc0c4b 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddMultiPointToSinglePointIntentCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddMultiPointToSinglePointIntentCommand.java
@@ -75,7 +75,8 @@
         Intent intent = new MultiPointToSinglePointIntent(appId(), key(),
                                                           selector, treatment,
                                                           ingressPoints, egress,
-                                                          constraints);
+                                                          constraints,
+                                                          priority());
         service.submit(intent);
         print("Multipoint to single point intent submitted:\n%s", intent.toString());
     }
diff --git a/cli/src/main/java/org/onosproject/cli/net/AddPointToPointIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddPointToPointIntentCommand.java
index 980acfe..3c93fa6 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddPointToPointIntentCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddPointToPointIntentCommand.java
@@ -70,7 +70,8 @@
         Intent intent = new PointToPointIntent(appId(),
                 key(),
                 selector, treatment,
-                ingress, egress, constraints);
+                ingress, egress, constraints,
+                priority());
         service.submit(intent);
         print("Point to point intent submitted:\n%s", intent.toString());
     }
diff --git a/cli/src/main/java/org/onosproject/cli/net/AddSinglePointToMultiPointIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/AddSinglePointToMultiPointIntentCommand.java
index 8ac8186..b6193fa 100644
--- a/cli/src/main/java/org/onosproject/cli/net/AddSinglePointToMultiPointIntentCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/AddSinglePointToMultiPointIntentCommand.java
@@ -15,6 +15,10 @@
  */
 package org.onosproject.cli.net;
 
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.onosproject.net.ConnectPoint;
@@ -27,10 +31,6 @@
 import org.onosproject.net.intent.IntentService;
 import org.onosproject.net.intent.SinglePointToMultiPointIntent;
 
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
 import static org.onosproject.net.DeviceId.deviceId;
 import static org.onosproject.net.PortNumber.portNumber;
 
@@ -79,7 +79,8 @@
                         treatment,
                         ingressPoint,
                         egressPoints,
-                        constraints);
+                        constraints,
+                        priority());
         service.submit(intent);
         print("Single point to multipoint intent submitted:\n%s", intent.toString());
     }
diff --git a/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java b/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java
index a8a28e2..848b3a8 100644
--- a/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java
@@ -28,6 +28,7 @@
 import org.onosproject.net.flow.TrafficSelector;
 import org.onosproject.net.flow.TrafficTreatment;
 import org.onosproject.net.intent.Constraint;
+import org.onosproject.net.intent.Intent;
 import org.onosproject.net.intent.Key;
 import org.onosproject.net.intent.constraint.BandwidthConstraint;
 import org.onosproject.net.intent.constraint.LambdaConstraint;
@@ -96,6 +97,11 @@
             required = false, multiValued = false)
     private String setEthDstString = null;
 
+    // Priorities
+    @Option(name = "-p", aliases = "--priority", description = "Priority",
+            required = false, multiValued = false)
+    private int priority = Intent.DEFAULT_INTENT_PRIORITY;
+
     /**
      * Constructs a traffic selector based on the command line arguments
      * presented to the command.
@@ -200,4 +206,13 @@
         }
         return key;
     }
+
+    /**
+     * Gets the priority to use for the intent.
+     *
+     * @return priority
+     */
+    protected int priority() {
+        return priority;
+    }
 }
diff --git a/cli/src/main/java/org/onosproject/cli/net/IntentCycleCommand.java b/cli/src/main/java/org/onosproject/cli/net/IntentCycleCommand.java
index 109f669..6a61295 100644
--- a/cli/src/main/java/org/onosproject/cli/net/IntentCycleCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/IntentCycleCommand.java
@@ -130,7 +130,8 @@
             intents.add(new PointToPointIntent(appId(), Key.of(i + keyOffset, appId()),
                                                selector, treatment,
                                                ingress, egress,
-                                               Collections.emptyList()));
+                                               Collections.emptyList(),
+                                               Intent.DEFAULT_INTENT_PRIORITY));
 
         }
         return intents;
diff --git a/cli/src/main/java/org/onosproject/cli/net/IntentPushTestCommand.java b/cli/src/main/java/org/onosproject/cli/net/IntentPushTestCommand.java
index d140f97..20af27d 100644
--- a/cli/src/main/java/org/onosproject/cli/net/IntentPushTestCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/IntentPushTestCommand.java
@@ -139,7 +139,8 @@
             intents.add(new PointToPointIntent(appId(), Key.of(i + keyOffset, appId()),
                                                selector, treatment,
                                                ingress, egress,
-                                               Collections.emptyList()));
+                                               Collections.emptyList(),
+                                               Intent.DEFAULT_INTENT_PRIORITY));
 
         }
         return intents;
diff --git a/core/api/src/main/java/org/onosproject/net/intent/ConnectivityIntent.java b/core/api/src/main/java/org/onosproject/net/intent/ConnectivityIntent.java
index 305d103..23e6c02 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/ConnectivityIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/ConnectivityIntent.java
@@ -61,7 +61,8 @@
                                  Collection<NetworkResource> resources,
                                  TrafficSelector selector,
                                  TrafficTreatment treatment) {
-        this(appId, null, resources, selector, treatment, Collections.emptyList());
+        this(appId, null, resources, selector, treatment, Collections.emptyList(),
+                DEFAULT_INTENT_PRIORITY);
     }
 
     /**
@@ -83,7 +84,8 @@
                                  Collection<NetworkResource> resources,
                                  TrafficSelector selector,
                                  TrafficTreatment treatment) {
-        this(appId, key, resources, selector, treatment, Collections.emptyList());
+        this(appId, key, resources, selector, treatment, Collections.emptyList(),
+                DEFAULT_INTENT_PRIORITY);
     }
 
     /**
@@ -99,6 +101,7 @@
      * @param selector    traffic selector
      * @param treatment   treatment
      * @param constraints optional prioritized list of constraints
+     * @param priority    priority to use for flows generated by this intent
      * @throws NullPointerException if the selector or treatment is null
      */
 
@@ -107,8 +110,9 @@
                                  Collection<NetworkResource> resources,
                                  TrafficSelector selector,
                                  TrafficTreatment treatment,
-                                 List<Constraint> constraints) {
-        super(appId, key, resources);
+                                 List<Constraint> constraints,
+                                 int priority) {
+        super(appId, key, resources, priority);
         this.selector = checkNotNull(selector);
         this.treatment = checkNotNull(treatment);
         this.constraints = checkNotNull(constraints);
@@ -126,6 +130,7 @@
      * @param selector    traffic selector
      * @param treatment   treatment
      * @param constraints optional prioritized list of constraints
+     * @param priority    priority to use for flows generated by this intent
      * @throws NullPointerException if the selector or treatment is null
      */
 
@@ -133,8 +138,9 @@
                                  Collection<NetworkResource> resources,
                                  TrafficSelector selector,
                                  TrafficTreatment treatment,
-                                 List<Constraint> constraints) {
-        super(appId, null, resources);
+                                 List<Constraint> constraints,
+                                 int priority) {
+        super(appId, null, resources, priority);
         this.selector = checkNotNull(selector);
         this.treatment = checkNotNull(treatment);
         this.constraints = checkNotNull(constraints);
diff --git a/core/api/src/main/java/org/onosproject/net/intent/HostToHostIntent.java b/core/api/src/main/java/org/onosproject/net/intent/HostToHostIntent.java
index d47594a..d9a1feb 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/HostToHostIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/HostToHostIntent.java
@@ -106,7 +106,8 @@
                             TrafficSelector selector,
                             TrafficTreatment treatment,
                             List<Constraint> constraints) {
-        super(appId, key, Collections.emptyList(), selector, treatment, constraints);
+        super(appId, key, Collections.emptyList(), selector, treatment, constraints,
+                DEFAULT_INTENT_PRIORITY);
 
         // TODO: consider whether the case one and two are same is allowed
         this.one = checkNotNull(one);
@@ -146,6 +147,7 @@
                 .add("id", id())
                 .add("key", key())
                 .add("appId", appId())
+                .add("priority", priority())
                 .add("resources", resources())
                 .add("selector", selector())
                 .add("treatment", treatment())
diff --git a/core/api/src/main/java/org/onosproject/net/intent/Intent.java b/core/api/src/main/java/org/onosproject/net/intent/Intent.java
index 4cca45d..7621c7d 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/Intent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/Intent.java
@@ -22,6 +22,7 @@
 import java.util.Collection;
 import java.util.Objects;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
 
@@ -38,6 +39,11 @@
     private final ApplicationId appId;
     private final Key key;
 
+    private final int priority;
+    public static final int DEFAULT_INTENT_PRIORITY = 100;
+    public static final int MAX_PRIORITY = (1 << 16) - 1;
+    public static final int MIN_PRIORITY = 1;
+
     private final Collection<NetworkResource> resources;
 
     private static IdGenerator idGenerator;
@@ -50,6 +56,7 @@
         this.appId = null;
         this.key = null;
         this.resources = null;
+        this.priority = DEFAULT_INTENT_PRIORITY;
     }
 
     /**
@@ -60,7 +67,7 @@
      */
     protected Intent(ApplicationId appId,
                      Collection<NetworkResource> resources) {
-        this(appId, null, resources);
+        this(appId, null, resources, DEFAULT_INTENT_PRIORITY);
     }
 
         /**
@@ -72,11 +79,14 @@
          */
     protected Intent(ApplicationId appId,
                      Key key,
-                     Collection<NetworkResource> resources) {
+                     Collection<NetworkResource> resources,
+                     int priority) {
         checkState(idGenerator != null, "Id generator is not bound.");
+        checkArgument(priority <= MAX_PRIORITY && priority >= MIN_PRIORITY);
         this.id = IntentId.valueOf(idGenerator.getNewId());
         this.appId = checkNotNull(appId, "Application ID cannot be null");
         this.key = (key != null) ? key : Key.of(id.fingerprint(), appId);
+        this.priority = priority;
         this.resources = checkNotNull(resources);
     }
 
@@ -99,6 +109,15 @@
     }
 
     /**
+     * Returns the priority of the intent.
+     *
+     * @return intent priority
+     */
+    public int priority() {
+        return priority;
+    }
+
+    /**
      * Returns the collection of resources required for this intent.
      *
      * @return collection of resources; may be null
diff --git a/core/api/src/main/java/org/onosproject/net/intent/LinkCollectionIntent.java b/core/api/src/main/java/org/onosproject/net/intent/LinkCollectionIntent.java
index 55c0cfb..17451cb 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/LinkCollectionIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/LinkCollectionIntent.java
@@ -59,7 +59,7 @@
                                 ConnectPoint ingressPoint,
                                 ConnectPoint egressPoint) {
         this(appId, selector, treatment, links, ingressPoint, egressPoint,
-             Collections.emptyList());
+             Collections.emptyList(), DEFAULT_INTENT_PRIORITY);
     }
 
     /**
@@ -74,6 +74,7 @@
      * @param ingressPoint ingress point
      * @param egressPoint egress point
      * @param constraints optional list of constraints
+     * @param priority    priority to use for the flows generated by this intent
      * @throws NullPointerException {@code path} is null
      */
     public LinkCollectionIntent(ApplicationId appId,
@@ -82,8 +83,9 @@
                                 Set<Link> links,
                                 ConnectPoint ingressPoint,
                                 ConnectPoint egressPoint,
-                                List<Constraint> constraints) {
-        super(appId, resources(links), selector, treatment, constraints);
+                                List<Constraint> constraints,
+                                int priority) {
+        super(appId, resources(links), selector, treatment, constraints, priority);
         this.links = links;
         this.ingressPoints = ImmutableSet.of(ingressPoint);
         this.egressPoints = ImmutableSet.of(egressPoint);
@@ -101,6 +103,7 @@
      * @param ingressPoints Set of ingress points
      * @param egressPoints Set of egress points
      * @param constraints  the constraints
+     * @param priority     priority to use for the flows generated by this intent
      * @throws NullPointerException {@code path} is null
      */
     public LinkCollectionIntent(ApplicationId appId,
@@ -109,8 +112,9 @@
                                 Set<Link> links,
                                 Set<ConnectPoint> ingressPoints,
                                 Set<ConnectPoint> egressPoints,
-                                List<Constraint> constraints) {
-        super(appId, resources(links), selector, treatment, constraints);
+                                List<Constraint> constraints,
+                                int priority) {
+        super(appId, resources(links), selector, treatment, constraints, priority);
 
         this.links = links;
         this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
@@ -166,6 +170,7 @@
                 .add("id", id())
                 .add("key", key())
                 .add("appId", appId())
+                .add("priority", priority())
                 .add("resources", resources())
                 .add("selector", selector())
                 .add("treatment", treatment())
diff --git a/core/api/src/main/java/org/onosproject/net/intent/MplsIntent.java b/core/api/src/main/java/org/onosproject/net/intent/MplsIntent.java
index 0c13e3f..d7f8535 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/MplsIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/MplsIntent.java
@@ -74,7 +74,8 @@
                               Optional<MplsLabel> egressLabel,
                               List<Constraint> constraints) {
 
-        super(appId, Collections.emptyList(), selector, treatment, constraints);
+        super(appId, Collections.emptyList(), selector, treatment, constraints,
+                DEFAULT_INTENT_PRIORITY);
 
         checkNotNull(ingressPoint);
         checkNotNull(egressPoint);
@@ -144,6 +145,7 @@
         return MoreObjects.toStringHelper(getClass())
                 .add("id", id())
                 .add("appId", appId())
+                .add("priority", priority())
                 .add("selector", selector())
                 .add("treatment", treatment())
                 .add("ingressPoint", ingressPoint)
diff --git a/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java b/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java
index f6602c9..2102dba 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java
@@ -59,7 +59,8 @@
     public MplsPathIntent(ApplicationId appId, TrafficSelector selector,
             TrafficTreatment treatment, Path path, Optional<MplsLabel> ingressLabel,
             Optional<MplsLabel> egressLabel, List<Constraint> constraints) {
-        super(appId, selector, treatment, path, constraints);
+        super(appId, selector, treatment, path, constraints,
+                DEFAULT_INTENT_PRIORITY);
 
         checkNotNull(ingressLabel);
         checkNotNull(egressLabel);
diff --git a/core/api/src/main/java/org/onosproject/net/intent/MultiPointToSinglePointIntent.java b/core/api/src/main/java/org/onosproject/net/intent/MultiPointToSinglePointIntent.java
index 19fcc7c..721ff17 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/MultiPointToSinglePointIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/MultiPointToSinglePointIntent.java
@@ -56,7 +56,8 @@
                                          TrafficTreatment treatment,
                                          Set<ConnectPoint> ingressPoints,
                                          ConnectPoint egressPoint) {
-        this(appId, selector, treatment, ingressPoints, egressPoint, Collections.emptyList());
+        this(appId, selector, treatment, ingressPoints, egressPoint,
+                Collections.emptyList(), DEFAULT_INTENT_PRIORITY);
     }
 
     /**
@@ -70,6 +71,7 @@
      * @param ingressPoints set of ports from which ingress traffic originates
      * @param egressPoint   port to which traffic will egress
      * @param constraints   constraints to apply to the intent
+     * @param priority      priority to use for flows generated by this intent
      * @throws NullPointerException     if {@code ingressPoints} or
      *                                  {@code egressPoint} is null.
      * @throws IllegalArgumentException if the size of {@code ingressPoints} is
@@ -81,8 +83,10 @@
                                          TrafficTreatment treatment,
                                          Set<ConnectPoint> ingressPoints,
                                          ConnectPoint egressPoint,
-                                         List<Constraint> constraints) {
-        super(appId, key, Collections.emptyList(), selector, treatment, constraints);
+                                         List<Constraint> constraints,
+                                         int priority) {
+        super(appId, key, Collections.emptyList(), selector, treatment, constraints,
+                priority);
 
         checkNotNull(ingressPoints);
         checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
@@ -104,6 +108,7 @@
      * @param ingressPoints set of ports from which ingress traffic originates
      * @param egressPoint   port to which traffic will egress
      * @param constraints   constraints to apply to the intent
+     * @param priority      priority to use for flows generated by this intent
      * @throws NullPointerException     if {@code ingressPoints} or
      *                                  {@code egressPoint} is null.
      * @throws IllegalArgumentException if the size of {@code ingressPoints} is
@@ -114,8 +119,10 @@
                                          TrafficTreatment treatment,
                                          Set<ConnectPoint> ingressPoints,
                                          ConnectPoint egressPoint,
-                                         List<Constraint> constraints) {
-        this(appId, null, selector, treatment, ingressPoints, egressPoint, constraints);
+                                         List<Constraint> constraints,
+                                         int priority) {
+        this(appId, null, selector, treatment, ingressPoints, egressPoint,
+                constraints, priority);
     }
 
     /**
@@ -152,6 +159,7 @@
                 .add("id", id())
                 .add("key", key())
                 .add("appId", appId())
+                .add("priority", priority())
                 .add("resources", resources())
                 .add("selector", selector())
                 .add("treatment", treatment())
diff --git a/core/api/src/main/java/org/onosproject/net/intent/OpticalConnectivityIntent.java b/core/api/src/main/java/org/onosproject/net/intent/OpticalConnectivityIntent.java
index d51abbb..091ebc5 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/OpticalConnectivityIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/OpticalConnectivityIntent.java
@@ -54,7 +54,7 @@
     public OpticalConnectivityIntent(ApplicationId appId,
                                      Key key,
                                      ConnectPoint src, ConnectPoint dst) {
-        super(appId, key, Collections.emptyList());
+        super(appId, key, Collections.emptyList(), DEFAULT_INTENT_PRIORITY);
         this.src = src;
         this.dst = dst;
     }
diff --git a/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java b/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java
index e307e2e..13fa61e 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java
@@ -48,7 +48,8 @@
      */
     public PathIntent(ApplicationId appId, TrafficSelector selector,
                       TrafficTreatment treatment, Path path) {
-        this(appId, selector, treatment, path, Collections.emptyList());
+        this(appId, selector, treatment, path, Collections.emptyList(),
+                DEFAULT_INTENT_PRIORITY);
     }
 
     /**
@@ -60,11 +61,14 @@
      * @param treatment treatment
      * @param path      traversed links
      * @param constraints  optional list of constraints
+     * @param priority  priority to use for the generated flows
      * @throws NullPointerException {@code path} is null
      */
     public PathIntent(ApplicationId appId, TrafficSelector selector,
-                      TrafficTreatment treatment, Path path, List<Constraint> constraints) {
-        super(appId, resources(path.links()), selector, treatment, constraints);
+                      TrafficTreatment treatment, Path path, List<Constraint> constraints,
+                      int priority) {
+        super(appId, resources(path.links()), selector, treatment, constraints,
+                priority);
         PathIntent.validate(path.links());
         this.path = path;
     }
@@ -123,6 +127,7 @@
         return MoreObjects.toStringHelper(getClass())
                 .add("id", id())
                 .add("appId", appId())
+                .add("priority", priority())
                 .add("resources", resources())
                 .add("selector", selector())
                 .add("treatment", treatment())
diff --git a/core/api/src/main/java/org/onosproject/net/intent/PointToPointIntent.java b/core/api/src/main/java/org/onosproject/net/intent/PointToPointIntent.java
index d8434ad..2df7b8b 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/PointToPointIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/PointToPointIntent.java
@@ -49,6 +49,7 @@
      * @param ingressPoint ingress port
      * @param egressPoint  egress port
      * @param constraints  optional list of constraints
+     * @param priority     priority to use for flows generated by this intent
      * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
      */
     public PointToPointIntent(ApplicationId appId,
@@ -57,8 +58,10 @@
                               TrafficTreatment treatment,
                               ConnectPoint ingressPoint,
                               ConnectPoint egressPoint,
-                              List<Constraint> constraints) {
-        super(appId, key, Collections.emptyList(), selector, treatment, constraints);
+                              List<Constraint> constraints,
+                              int priority) {
+        super(appId, key, Collections.emptyList(), selector, treatment, constraints,
+                priority);
 
         checkNotNull(ingressPoint);
         checkNotNull(egressPoint);
@@ -85,7 +88,8 @@
                               ConnectPoint ingressPoint,
                               ConnectPoint egressPoint) {
         this(appId, null, selector, treatment, ingressPoint, egressPoint,
-             ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)));
+             ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)),
+                DEFAULT_INTENT_PRIORITY);
     }
 
     /**
@@ -98,14 +102,17 @@
      * @param ingressPoint ingress port
      * @param egressPoint  egress port
      * @param constraints  optional list of constraints
+     * @param priority     priority to use for flows generated by this intent
      * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
      */
     public PointToPointIntent(ApplicationId appId, TrafficSelector selector,
                               TrafficTreatment treatment,
                               ConnectPoint ingressPoint,
                               ConnectPoint egressPoint,
-                              List<Constraint> constraints) {
-        super(appId, null, Collections.emptyList(), selector, treatment, constraints);
+                              List<Constraint> constraints,
+                              int priority) {
+        super(appId, null, Collections.emptyList(), selector, treatment,
+                constraints, priority);
 
         checkNotNull(ingressPoint);
         checkNotNull(egressPoint);
@@ -150,6 +157,7 @@
                 .add("id", id())
                 .add("key", key())
                 .add("appId", appId())
+                .add("priority", priority())
                 .add("resources", resources())
                 .add("selector", selector())
                 .add("treatment", treatment())
diff --git a/core/api/src/main/java/org/onosproject/net/intent/SinglePointToMultiPointIntent.java b/core/api/src/main/java/org/onosproject/net/intent/SinglePointToMultiPointIntent.java
index 2531fae..129c4a6 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/SinglePointToMultiPointIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/SinglePointToMultiPointIntent.java
@@ -54,7 +54,9 @@
     public SinglePointToMultiPointIntent(ApplicationId appId,
             TrafficSelector selector, TrafficTreatment treatment,
             ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints) {
-        this(appId, null, selector, treatment, ingressPoint, egressPoints, Collections.emptyList());
+        this(appId, null, selector, treatment, ingressPoint, egressPoints,
+                Collections.emptyList(),
+                DEFAULT_INTENT_PRIORITY);
     }
 
     /**
@@ -67,6 +69,7 @@
      * @param ingressPoint port on which traffic will ingress
      * @param egressPoints set of ports on which traffic will egress
      * @param constraints constraints to apply to the intent
+     * @param priority priority to use for flows generated by this intent
      * @throws NullPointerException if {@code ingressPoint} or
      *             {@code egressPoints} is null
      * @throws IllegalArgumentException if the size of {@code egressPoints} is
@@ -76,8 +79,10 @@
             Key key,
             TrafficSelector selector, TrafficTreatment treatment,
             ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints,
-            List<Constraint> constraints) {
-        super(appId, key, Collections.emptyList(), selector, treatment, constraints);
+            List<Constraint> constraints,
+            int priority) {
+        super(appId, key, Collections.emptyList(), selector, treatment, constraints,
+                priority);
         checkNotNull(egressPoints);
         checkNotNull(ingressPoint);
         checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
@@ -122,6 +127,7 @@
                 .add("id", id())
                 .add("key", key())
                 .add("appId", appId())
+                .add("priority", priority())
                 .add("resources", resources())
                 .add("selector", selector())
                 .add("treatment", treatment())
diff --git a/core/api/src/main/java/org/onosproject/net/intent/TwoWayP2PIntent.java b/core/api/src/main/java/org/onosproject/net/intent/TwoWayP2PIntent.java
index b6d0246..118e137 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/TwoWayP2PIntent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/TwoWayP2PIntent.java
@@ -107,7 +107,8 @@
                            TrafficSelector selector,
                            TrafficTreatment treatment,
                            List<Constraint> constraints) {
-        super(appId, key, Collections.emptyList(), selector, treatment, constraints);
+        super(appId, key, Collections.emptyList(), selector, treatment, constraints,
+                DEFAULT_INTENT_PRIORITY);
 
         // TODO: consider whether the case one and two are same is allowed
         this.one = checkNotNull(one);
@@ -147,6 +148,7 @@
                 .add("id", id())
                 .add("key", key())
                 .add("appId", appId())
+                .add("priority", priority())
                 .add("resources", resources())
                 .add("selector", selector())
                 .add("treatment", treatment())
diff --git a/core/api/src/test/java/org/onosproject/net/intent/LinkCollectionIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/LinkCollectionIntentTest.java
index 0327390..a9ae782 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/LinkCollectionIntentTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/LinkCollectionIntentTest.java
@@ -134,7 +134,8 @@
                         links1,
                         ingress,
                         egress,
-                        constraints);
+                        constraints,
+                        8888);
 
         final Set<Link> createdLinks = collectionIntent.links();
         assertThat(createdLinks, hasSize(1));
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
index df8ef04..60306b2 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
@@ -98,7 +98,8 @@
         TrafficSelector selector = builder(intent.selector())
                 .matchEthSrc(src.mac()).matchEthDst(dst.mac()).build();
         return new PathIntent(intent.appId(), selector, intent.treatment(),
-                              path, intent.constraints());
+                              path, intent.constraints(),
+                              intent.priority());
     }
 
 }
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
index b4889f4..6403019 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
@@ -89,12 +89,14 @@
             }
         }
 
+        Set<ConnectPoint> egress = ImmutableSet.of(intent.egressPoint());
         Intent result = new LinkCollectionIntent(intent.appId(),
                                                  intent.selector(), intent.treatment(),
                                                  Sets.newHashSet(links.values()),
                                                  intent.ingressPoints(),
                                                  ImmutableSet.of(intent.egressPoint()),
-                                                 Collections.emptyList());
+                                                 Collections.emptyList(),
+                                                 intent.priority());
         return Arrays.asList(result);
     }
 
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
index 9371586..0f897a4 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
@@ -93,7 +93,8 @@
                                     PointToPointIntent intent) {
         return new PathIntent(intent.appId(),
                               intent.selector(), intent.treatment(), path,
-                              intent.constraints());
+                              intent.constraints(),
+                              intent.priority());
     }
 
 }
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java
index 8360820..4b2260e 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java
@@ -70,7 +70,9 @@
                                                  intent.selector(),
                                                  intent.treatment(), links,
                                                  ImmutableSet.of(intent.ingressPoint()),
-                                                 intent.egressPoints(), Collections.emptyList());
+                                                 intent.egressPoints(),
+                                                 Collections.emptyList(),
+                                                 intent.priority());
 
         return Arrays.asList(result);
     }
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/TwoWayP2PIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/TwoWayP2PIntentCompiler.java
index 6c5b7f3..af603d5 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/TwoWayP2PIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/TwoWayP2PIntentCompiler.java
@@ -51,11 +51,11 @@
                 new PointToPointIntent(intent.appId(), intent.key(),
                                        intent.selector(), intent.treatment(),
                                        intent.one(), intent.two(),
-                                       intent.constraints()),
+                                       intent.constraints(), Intent.DEFAULT_INTENT_PRIORITY),
                 new PointToPointIntent(intent.appId(), intent.key(),
                                        intent.selector(), intent.treatment(),
                                        intent.two(), intent.one(),
-                                       intent.constraints()));
+                                       intent.constraints(), Intent.DEFAULT_INTENT_PRIORITY));
 
     }
 }
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/installer/LinkCollectionIntentInstaller.java b/core/net/src/main/java/org/onosproject/net/intent/impl/installer/LinkCollectionIntentInstaller.java
index 54ff5fc..e715b87 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/installer/LinkCollectionIntentInstaller.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/installer/LinkCollectionIntentInstaller.java
@@ -186,7 +186,7 @@
                 treatment = intentTreatment;
             }
             FlowRule rule = new DefaultFlowRule(deviceId,
-                selector, treatment, 123, appId,
+                selector, treatment, intent.priority(), appId,
                 new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)),
                 0, true);
             result.add(new FlowRuleOperation(rule, operation));
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/installer/MplsPathIntentInstaller.java b/core/net/src/main/java/org/onosproject/net/intent/impl/installer/MplsPathIntentInstaller.java
index dbe9233..bb38fa5 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/installer/MplsPathIntentInstaller.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/installer/MplsPathIntentInstaller.java
@@ -280,7 +280,7 @@
                                             deviceId,
                                             selector,
                                             treat,
-                                            123, // FIXME 123
+                                            intent.priority(),
                                             appId,
                                             0,
                                             true);
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/installer/PathIntentInstaller.java b/core/net/src/main/java/org/onosproject/net/intent/impl/installer/PathIntentInstaller.java
index 5230736..7a06024 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/installer/PathIntentInstaller.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/installer/PathIntentInstaller.java
@@ -99,7 +99,7 @@
                     .setOutput(link.src().port()).build();
 
             FlowRule rule = new DefaultFlowRule(link.src().deviceId(),
-                    builder.build(), treatment, 123, //FIXME 123
+                    builder.build(), treatment, intent.priority(),
                     appId,
                     new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)),
                     0, true);
@@ -127,7 +127,7 @@
                     (links.hasNext() ? builder() : builder(intent.treatment()))
                             .setOutput(link.src().port()).build();
             FlowRule rule = new DefaultFlowRule(link.src().deviceId(),
-                    builder.build(), treatment, 123, appId,
+                    builder.build(), treatment, intent.priority(), appId,
                     new DefaultGroupId((short) (intent.id().fingerprint() & 0xffff)),
                     0, true);
             rules.add(new FlowRuleOperation(rule, FlowRuleOperation.Type.REMOVE));
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java
index b651beb..aedc124 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java
@@ -90,7 +90,7 @@
         return new PointToPointIntent(APPID, selector, treatment,
                 connectPoint(ingressIdString, 1),
                 connectPoint(egressIdString, 1),
-                constraints);
+                constraints, Intent.DEFAULT_INTENT_PRIORITY);
     }
 
     /**
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathConstraintCalculationTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathConstraintCalculationTest.java
index 0ae5903..d0bb843 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathConstraintCalculationTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathConstraintCalculationTest.java
@@ -74,7 +74,7 @@
     private PathIntent createPathIntent(List<Link> links, List<Constraint> constraints) {
         int hops = links.size() - 1;
         return new PathIntent(APP_ID, selector, treatment,
-                              new DefaultPath(PID, links, hops), constraints);
+                              new DefaultPath(PID, links, hops), constraints, 333);
     }
 
     /**
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathIntentInstallerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathIntentInstallerTest.java
index 39febcc..695f115 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathIntentInstallerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/installer/PathIntentInstallerTest.java
@@ -62,7 +62,8 @@
         installer.coreService = testCoreService;
         installer.intentManager = new MockIntentManager(PathIntent.class);
         intent = new PathIntent(APP_ID, selector, treatment,
-                new DefaultPath(PID, links, hops), ImmutableList.of());
+                new DefaultPath(PID, links, hops), ImmutableList.of(),
+                77);
     }
 
     /**
diff --git a/web/api/src/main/java/org/onosproject/codec/impl/ConnectivityIntentCodec.java b/web/api/src/main/java/org/onosproject/codec/impl/ConnectivityIntentCodec.java
index ac7ae53..dbd824c 100644
--- a/web/api/src/main/java/org/onosproject/codec/impl/ConnectivityIntentCodec.java
+++ b/web/api/src/main/java/org/onosproject/codec/impl/ConnectivityIntentCodec.java
@@ -52,6 +52,8 @@
             result.set("treatment", treatmentCodec.encode(intent.treatment(), context));
         }
 
+        result.put("priority", intent.priority());
+
         if (intent.constraints() != null) {
             final ArrayNode jsonConstraints = result.putArray("constraints");
 
diff --git a/web/api/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java b/web/api/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java
index e4a1373..811e87a 100644
--- a/web/api/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java
+++ b/web/api/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java
@@ -38,6 +38,7 @@
 import org.onosproject.net.intent.Constraint;
 import org.onosproject.net.intent.HostToHostIntent;
 import org.onosproject.net.intent.AbstractIntentTest;
+import org.onosproject.net.intent.Intent;
 import org.onosproject.net.intent.PointToPointIntent;
 import org.onosproject.net.intent.constraint.AnnotationConstraint;
 import org.onosproject.net.intent.constraint.AsymmetricPathConstraint;
@@ -147,7 +148,8 @@
 
         final PointToPointIntent intent =
                 new PointToPointIntent(appId, selector, treatment,
-                                       ingress, egress, constraints);
+                                       ingress, egress, constraints,
+                                       Intent.DEFAULT_INTENT_PRIORITY);
 
         final CodecContext context = new MockCodecContext();
         final JsonCodec<PointToPointIntent> intentCodec =