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 8613101152..8060626786 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 @@ public class IntentPerfInstaller { 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 69feb35181..abc0c4ba95 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 @@ public class AddMultiPointToSinglePointIntentCommand extends ConnectivityIntentC 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 980acfe46e..3c93fa6789 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 @@ public class AddPointToPointIntentCommand extends ConnectivityIntentCommand { 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 8ac8186b8a..b6193fa2f0 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.Constraint; 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 @@ public class AddSinglePointToMultiPointIntentCommand extends ConnectivityIntentC 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 a8a28e24b5..848b3a8219 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.DefaultTrafficSelector; 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 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { 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 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { } 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 109f669bf9..6a61295a31 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 @@ public class IntentCycleCommand extends AbstractShellCommand 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 d140f978cf..20af27d48e 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 @@ public class IntentPushTestCommand extends AbstractShellCommand 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 305d103831..23e6c02c88 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 @@ public abstract class ConnectivityIntent extends Intent { Collection 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 @@ public abstract class ConnectivityIntent extends Intent { Collection 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 @@ public abstract class ConnectivityIntent extends Intent { * @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 @@ public abstract class ConnectivityIntent extends Intent { Collection resources, TrafficSelector selector, TrafficTreatment treatment, - List constraints) { - super(appId, key, resources); + List constraints, + int priority) { + super(appId, key, resources, priority); this.selector = checkNotNull(selector); this.treatment = checkNotNull(treatment); this.constraints = checkNotNull(constraints); @@ -126,6 +130,7 @@ public abstract class ConnectivityIntent extends Intent { * @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 @@ public abstract class ConnectivityIntent extends Intent { Collection resources, TrafficSelector selector, TrafficTreatment treatment, - List constraints) { - super(appId, null, resources); + List 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 d47594a8ac..d9a1feb02c 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 @@ public final class HostToHostIntent extends ConnectivityIntent { TrafficSelector selector, TrafficTreatment treatment, List 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 @@ public final class HostToHostIntent extends ConnectivityIntent { .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 4cca45d85f..7621c7d298 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 org.onosproject.net.NetworkResource; 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 @@ public abstract class Intent { 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 resources; private static IdGenerator idGenerator; @@ -50,6 +56,7 @@ public abstract class Intent { this.appId = null; this.key = null; this.resources = null; + this.priority = DEFAULT_INTENT_PRIORITY; } /** @@ -60,7 +67,7 @@ public abstract class Intent { */ protected Intent(ApplicationId appId, Collection resources) { - this(appId, null, resources); + this(appId, null, resources, DEFAULT_INTENT_PRIORITY); } /** @@ -72,11 +79,14 @@ public abstract class Intent { */ protected Intent(ApplicationId appId, Key key, - Collection resources) { + Collection 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); } @@ -98,6 +108,15 @@ public abstract class Intent { return appId; } + /** + * Returns the priority of the intent. + * + * @return intent priority + */ + public int priority() { + return priority; + } + /** * Returns the collection of resources required for this intent. * 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 55c0cfbbdf..17451cbaaa 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 @@ public final class LinkCollectionIntent extends ConnectivityIntent { ConnectPoint ingressPoint, ConnectPoint egressPoint) { this(appId, selector, treatment, links, ingressPoint, egressPoint, - Collections.emptyList()); + Collections.emptyList(), DEFAULT_INTENT_PRIORITY); } /** @@ -74,6 +74,7 @@ public final class LinkCollectionIntent extends ConnectivityIntent { * @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 @@ public final class LinkCollectionIntent extends ConnectivityIntent { Set links, ConnectPoint ingressPoint, ConnectPoint egressPoint, - List constraints) { - super(appId, resources(links), selector, treatment, constraints); + List 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 @@ public final class LinkCollectionIntent extends ConnectivityIntent { * @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 @@ public final class LinkCollectionIntent extends ConnectivityIntent { Set links, Set ingressPoints, Set egressPoints, - List constraints) { - super(appId, resources(links), selector, treatment, constraints); + List constraints, + int priority) { + super(appId, resources(links), selector, treatment, constraints, priority); this.links = links; this.ingressPoints = ImmutableSet.copyOf(ingressPoints); @@ -166,6 +170,7 @@ public final class LinkCollectionIntent extends ConnectivityIntent { .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 0c13e3f655..d7f8535802 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 @@ public final class MplsIntent extends ConnectivityIntent { Optional egressLabel, List 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 @@ public final class MplsIntent extends ConnectivityIntent { 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 f6602c9230..2102dba467 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 final class MplsPathIntent extends PathIntent { public MplsPathIntent(ApplicationId appId, TrafficSelector selector, TrafficTreatment treatment, Path path, Optional ingressLabel, Optional egressLabel, List 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 19fcc7c9da..721ff176ce 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 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { TrafficTreatment treatment, Set 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 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { * @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 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { TrafficTreatment treatment, Set ingressPoints, ConnectPoint egressPoint, - List constraints) { - super(appId, key, Collections.emptyList(), selector, treatment, constraints); + List 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 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { * @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 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { TrafficTreatment treatment, Set ingressPoints, ConnectPoint egressPoint, - List constraints) { - this(appId, null, selector, treatment, ingressPoints, egressPoint, constraints); + List constraints, + int priority) { + this(appId, null, selector, treatment, ingressPoints, egressPoint, + constraints, priority); } /** @@ -152,6 +159,7 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { .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 d51abbb059..091ebc54d3 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 final class OpticalConnectivityIntent extends Intent { 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 e307e2e896..13fa61e164 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 class PathIntent extends ConnectivityIntent { */ 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 @@ public class PathIntent extends ConnectivityIntent { * @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 constraints) { - super(appId, resources(path.links()), selector, treatment, constraints); + TrafficTreatment treatment, Path path, List constraints, + int priority) { + super(appId, resources(path.links()), selector, treatment, constraints, + priority); PathIntent.validate(path.links()); this.path = path; } @@ -123,6 +127,7 @@ public class PathIntent extends ConnectivityIntent { 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 d8434ad26a..2df7b8b0b1 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 @@ public final class PointToPointIntent extends ConnectivityIntent { * @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 @@ public final class PointToPointIntent extends ConnectivityIntent { TrafficTreatment treatment, ConnectPoint ingressPoint, ConnectPoint egressPoint, - List constraints) { - super(appId, key, Collections.emptyList(), selector, treatment, constraints); + List constraints, + int priority) { + super(appId, key, Collections.emptyList(), selector, treatment, constraints, + priority); checkNotNull(ingressPoint); checkNotNull(egressPoint); @@ -85,7 +88,8 @@ public final class PointToPointIntent extends ConnectivityIntent { 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 @@ public final class PointToPointIntent extends ConnectivityIntent { * @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 constraints) { - super(appId, null, Collections.emptyList(), selector, treatment, constraints); + List constraints, + int priority) { + super(appId, null, Collections.emptyList(), selector, treatment, + constraints, priority); checkNotNull(ingressPoint); checkNotNull(egressPoint); @@ -150,6 +157,7 @@ public final class PointToPointIntent extends ConnectivityIntent { .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 2531faea01..129c4a6bd2 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 final class SinglePointToMultiPointIntent extends ConnectivityIntent { public SinglePointToMultiPointIntent(ApplicationId appId, TrafficSelector selector, TrafficTreatment treatment, ConnectPoint ingressPoint, Set 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 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { * @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 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { Key key, TrafficSelector selector, TrafficTreatment treatment, ConnectPoint ingressPoint, Set egressPoints, - List constraints) { - super(appId, key, Collections.emptyList(), selector, treatment, constraints); + List 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 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent { .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 b6d0246c30..118e137fa9 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 @@ public final class TwoWayP2PIntent extends ConnectivityIntent { TrafficSelector selector, TrafficTreatment treatment, List 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 @@ public final class TwoWayP2PIntent extends ConnectivityIntent { .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 03273907fa..a9ae782fca 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 @@ public class LinkCollectionIntentTest extends IntentTest { links1, ingress, egress, - constraints); + constraints, + 8888); final Set 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 df8ef04fc0..60306b2a2e 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 @@ public class HostToHostIntentCompiler 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 b4889f47f7..6403019c12 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 @@ public class MultiPointToSinglePointIntentCompiler } } + Set 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 9371586913..0f897a42e0 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 @@ public class PointToPointIntentCompiler 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 8360820f02..4b2260e111 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 @@ public class SinglePointToMultiPointIntentCompiler 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 6c5b7f3743..af603d550e 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 @@ public class TwoWayP2PIntentCompiler 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 54ff5fce93..e715b87b98 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 @@ public class LinkCollectionIntentInstaller 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 dbe9233718..bb38fa5b28 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 @@ public class MplsPathIntentInstaller implements IntentInstaller 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 52307367a5..7a0602408e 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 @@ public class PathIntentInstaller implements IntentInstaller { .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 @@ public class PathIntentInstaller implements IntentInstaller { (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 b651bebe23..aedc124f8a 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 @@ public class PointToPointIntentCompilerTest extends AbstractIntentTest { 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 0ae59037eb..d0bb8435b3 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 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { private PathIntent createPathIntent(List links, List 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 39febcc489..695f115c64 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 @@ public class PathIntentInstallerTest extends IntentInstallerTest { 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 ac7ae53591..dbd824c192 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 @@ public final class ConnectivityIntentCodec extends JsonCodec 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 e4a1373724..811e87a687 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.flow.TrafficTreatment; 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 @@ public class IntentCodecTest extends AbstractIntentTest { 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 intentCodec =