Add keys to intents
- use Key class rather than String for intent keys
- add CLI option to specify a string key
- add key field to constructors for connectivity intents
- translate id into a key if no key is specified
Change-Id: I69ffbad93bc3daddf06a67cb0cffa2130e781b37
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 50f639c..305d103 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,57 @@
Collection<NetworkResource> resources,
TrafficSelector selector,
TrafficTreatment treatment) {
- this(appId, resources, selector, treatment, Collections.emptyList());
+ this(appId, null, resources, selector, treatment, Collections.emptyList());
+ }
+
+ /**
+ * Creates a connectivity intent that matches on the specified selector
+ * and applies the specified treatment.
+ * <p>
+ * Path will be chosen without any constraints.
+ * </p>
+ *
+ * @param appId application identifier
+ * @param key intent key
+ * @param resources required network resources (optional)
+ * @param selector traffic selector
+ * @param treatment treatment
+ * @throws NullPointerException if the selector or treatment is null
+ */
+ protected ConnectivityIntent(ApplicationId appId,
+ Key key,
+ Collection<NetworkResource> resources,
+ TrafficSelector selector,
+ TrafficTreatment treatment) {
+ this(appId, key, resources, selector, treatment, Collections.emptyList());
+ }
+
+ /**
+ * Creates a connectivity intent that matches on the specified selector
+ * and applies the specified treatment.
+ * <p>
+ * Path will be optimized based on the first constraint if one is given.
+ * </p>
+ *
+ * @param appId application identifier
+ * @param key explicit key to use for intent
+ * @param resources required network resources (optional)
+ * @param selector traffic selector
+ * @param treatment treatment
+ * @param constraints optional prioritized list of constraints
+ * @throws NullPointerException if the selector or treatment is null
+ */
+
+ protected ConnectivityIntent(ApplicationId appId,
+ Key key,
+ Collection<NetworkResource> resources,
+ TrafficSelector selector,
+ TrafficTreatment treatment,
+ List<Constraint> constraints) {
+ super(appId, key, resources);
+ this.selector = checkNotNull(selector);
+ this.treatment = checkNotNull(treatment);
+ this.constraints = checkNotNull(constraints);
}
/**
@@ -78,12 +128,13 @@
* @param constraints optional prioritized list of constraints
* @throws NullPointerException if the selector or treatment is null
*/
+
protected ConnectivityIntent(ApplicationId appId,
Collection<NetworkResource> resources,
TrafficSelector selector,
TrafficTreatment treatment,
List<Constraint> constraints) {
- super(appId, resources);
+ super(appId, null, resources);
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 5550ffe..b965967 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
@@ -87,7 +87,26 @@
TrafficSelector selector,
TrafficTreatment treatment,
List<Constraint> constraints) {
- super(appId, Collections.emptyList(), selector, treatment, constraints);
+ this(appId, null, one, two, selector, treatment, constraints);
+ }
+ /**
+ * Creates a new host-to-host intent with the supplied host pair.
+ *
+ * @param appId application identifier
+ * @param key intent key
+ * @param one first host
+ * @param two second host
+ * @param selector action
+ * @param treatment ingress port
+ * @param constraints optional prioritized list of path selection constraints
+ * @throws NullPointerException if {@code one} or {@code two} is null.
+ */
+ public HostToHostIntent(ApplicationId appId, Key key,
+ HostId one, HostId two,
+ TrafficSelector selector,
+ TrafficTreatment treatment,
+ List<Constraint> constraints) {
+ super(appId, key, Collections.emptyList(), selector, treatment, constraints);
// TODO: consider whether the case one and two are same is allowed
this.one = checkNotNull(one);
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 6630ce9..4cca45d 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
@@ -36,7 +36,7 @@
private final IntentId id;
private final ApplicationId appId;
- private final String key; // TODO make this a class
+ private final Key key;
private final Collection<NetworkResource> resources;
@@ -71,12 +71,12 @@
* @param resources required network resources (optional)
*/
protected Intent(ApplicationId appId,
- String key,
+ Key key,
Collection<NetworkResource> resources) {
checkState(idGenerator != null, "Id generator is not bound.");
this.id = IntentId.valueOf(idGenerator.getNewId());
this.appId = checkNotNull(appId, "Application ID cannot be null");
- this.key = (key != null) ? key : id.toString(); //FIXME
+ this.key = (key != null) ? key : Key.of(id.fingerprint(), appId);
this.resources = checkNotNull(resources);
}
@@ -156,7 +156,7 @@
}
}
- public String key() {
+ public Key key() {
return key;
}
}
diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentData.java b/core/api/src/main/java/org/onosproject/net/intent/IntentData.java
index 0f2bd84..3eea0d5 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/IntentData.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/IntentData.java
@@ -52,7 +52,7 @@
return state;
}
- public String key() {
+ public Key key() {
return intent.key();
}
diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentOperation.java b/core/api/src/main/java/org/onosproject/net/intent/IntentOperation.java
index 7eed841..ef16a69 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/IntentOperation.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/IntentOperation.java
@@ -73,7 +73,12 @@
return intent.id();
}
- public String key() {
+ /**
+ * Returns the key for this intent.
+ *
+ * @return key value
+ */
+ public Key key() {
return intent.key();
}
diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentStore.java b/core/api/src/main/java/org/onosproject/net/intent/IntentStore.java
index 55892c3..e5942f1 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/IntentStore.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/IntentStore.java
@@ -92,7 +92,7 @@
* @param key key
* @return intent or null if not found
*/
- default Intent getIntent(String key) { //FIXME remove when impl.
+ default Intent getIntent(Key key) { //FIXME remove when impl.
return null;
}
@@ -102,7 +102,7 @@
* @param key key to look up
* @return intent data object
*/
- default IntentData getIntentData(String key) { //FIXME remove when impl.
+ default IntentData getIntentData(Key key) { //FIXME remove when impl.
return null;
}
diff --git a/core/api/src/main/java/org/onosproject/net/intent/Key.java b/core/api/src/main/java/org/onosproject/net/intent/Key.java
index eb3c4f8..44c36e0 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/Key.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/Key.java
@@ -32,7 +32,7 @@
private final long hash;
private static final HashFunction HASH_FN = Hashing.md5();
- private Key(long hash) {
+ protected Key(long hash) {
this.hash = hash;
}
@@ -48,7 +48,7 @@
return new LongKey(key, appId);
}
- private final static class StringKey extends Key {
+ private static final class StringKey extends Key {
private final ApplicationId appId;
private final String key;
@@ -87,7 +87,7 @@
}
}
- private final static class LongKey extends Key {
+ private static final class LongKey extends Key {
private final ApplicationId appId;
private static long key;
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 f519dd4..7de52a5 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
@@ -75,12 +75,13 @@
* not more than 1
*/
public MultiPointToSinglePointIntent(ApplicationId appId,
+ Key key,
TrafficSelector selector,
TrafficTreatment treatment,
Set<ConnectPoint> ingressPoints,
ConnectPoint egressPoint,
List<Constraint> constraints) {
- super(appId, Collections.emptyList(), selector, treatment, constraints);
+ super(appId, key, Collections.emptyList(), selector, treatment, constraints);
checkNotNull(ingressPoints);
checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
@@ -93,6 +94,30 @@
}
/**
+ * Creates a new multi-to-single point connectivity intent for the specified
+ * traffic selector and treatment.
+ *
+ * @param appId application identifier
+ * @param selector traffic selector
+ * @param treatment treatment
+ * @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
+ * @throws NullPointerException if {@code ingressPoints} or
+ * {@code egressPoint} is null.
+ * @throws IllegalArgumentException if the size of {@code ingressPoints} is
+ * not more than 1
+ */
+ public MultiPointToSinglePointIntent(ApplicationId appId,
+ TrafficSelector selector,
+ TrafficTreatment treatment,
+ Set<ConnectPoint> ingressPoints,
+ ConnectPoint egressPoint,
+ List<Constraint> constraints) {
+ this(appId, null, selector, treatment, ingressPoints, egressPoint, constraints);
+ }
+
+ /**
* Constructor for serializer.
*/
protected MultiPointToSinglePointIntent() {
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 332f430..676b712 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
@@ -38,11 +38,28 @@
*/
public OpticalConnectivityIntent(ApplicationId appId,
ConnectPoint src, ConnectPoint dst) {
- super(appId, Collections.emptyList());
+
+ this(appId, null, src, dst);
+ }
+
+ /**
+ * Creates an optical connectivity intent between the specified
+ * connection points.
+ *
+ * @param appId application identification
+ * @param key intent key
+ * @param src the source transponder port
+ * @param dst the destination transponder port
+ */
+ public OpticalConnectivityIntent(ApplicationId appId,
+ Key key,
+ ConnectPoint src, ConnectPoint dst) {
+ super(appId, key, Collections.emptyList());
this.src = src;
this.dst = dst;
}
+
/**
* Constructor for serializer.
*/
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 31d4337..3312587 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
@@ -40,6 +40,37 @@
/**
* Creates a new point-to-point intent with the supplied ingress/egress
+ * ports and constraints.
+ *
+ * @param appId application identifier
+ * @param key key of the intent
+ * @param selector traffic selector
+ * @param treatment treatment
+ * @param ingressPoint ingress port
+ * @param egressPoint egress port
+ * @param constraints optional list of constraints
+ * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
+ */
+ public PointToPointIntent(ApplicationId appId,
+ Key key,
+ TrafficSelector selector,
+ TrafficTreatment treatment,
+ ConnectPoint ingressPoint,
+ ConnectPoint egressPoint,
+ List<Constraint> constraints) {
+ super(appId, key, Collections.emptyList(), selector, treatment, constraints);
+
+ checkNotNull(ingressPoint);
+ checkNotNull(egressPoint);
+ checkArgument(!ingressPoint.equals(egressPoint),
+ "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint);
+
+ this.ingressPoint = ingressPoint;
+ this.egressPoint = egressPoint;
+ }
+
+ /**
+ * Creates a new point-to-point intent with the supplied ingress/egress
* ports and with built-in link type constraint to avoid optical links.
*
* @param appId application identifier
@@ -53,7 +84,7 @@
TrafficTreatment treatment,
ConnectPoint ingressPoint,
ConnectPoint egressPoint) {
- this(appId, selector, treatment, ingressPoint, egressPoint,
+ this(appId, null, selector, treatment, ingressPoint, egressPoint,
ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)));
}
@@ -74,7 +105,7 @@
ConnectPoint ingressPoint,
ConnectPoint egressPoint,
List<Constraint> constraints) {
- super(appId, Collections.emptyList(), selector, treatment, constraints);
+ super(appId, null, Collections.emptyList(), selector, treatment, constraints);
checkNotNull(ingressPoint);
checkNotNull(egressPoint);
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 0de4ba4..03aca96 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,13 +54,14 @@
public SinglePointToMultiPointIntent(ApplicationId appId,
TrafficSelector selector, TrafficTreatment treatment,
ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints) {
- this(appId, selector, treatment, ingressPoint, egressPoints, Collections.emptyList());
+ this(appId, null, selector, treatment, ingressPoint, egressPoints, Collections.emptyList());
}
/**
* Creates a new single-to-multi point connectivity intent.
*
* @param appId application identifier
+ * @param key intent key
* @param selector traffic selector
* @param treatment treatment
* @param ingressPoint port on which traffic will ingress
@@ -72,10 +73,11 @@
* not more than 1
*/
public SinglePointToMultiPointIntent(ApplicationId appId,
+ Key key,
TrafficSelector selector, TrafficTreatment treatment,
ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints,
List<Constraint> constraints) {
- super(appId, Collections.emptyList(), selector, treatment, constraints);
+ super(appId, key, Collections.emptyList(), selector, treatment, constraints);
checkNotNull(egressPoints);
checkNotNull(ingressPoint);
checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");