[ONOS-4387] Support for multiple selectors in mp2sp intents
Changes:
- Adds extension to mp2sp intents;
- Adds extension to linkcollection intents;
- Adds extension to mp2sp compiler;
- Adds extension to linkcollection compiler;
- Adds unit tests for both mp2sp and linkcollection intents;
Change-Id: I673c2b660d2364c510b1b3050ed3626ad2f37bda
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 f72354d..5a5345b 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
@@ -13,12 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.onosproject.net.intent;
+import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import com.google.common.annotations.Beta;
+import com.google.common.collect.ImmutableMap;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Link;
@@ -39,6 +43,11 @@
private final Set<ConnectPoint> ingressPoints;
private final Set<ConnectPoint> egressPoints;
+ /**
+ * To manage multiple selectors use case.
+ */
+ private final Map<ConnectPoint, TrafficSelector> ingressSelectors;
+
private final boolean egressTreatmentFlag;
/**
@@ -56,6 +65,7 @@
* @param constraints optional list of constraints
* @param priority priority to use for the flows generated by this intent
* @param egressTreatment true if treatment should be applied by the egress device
+ * @param ingressSelectors map to store the association ingress to selector
* @throws NullPointerException {@code path} is null
*/
private LinkCollectionIntent(ApplicationId appId,
@@ -66,12 +76,15 @@
Set<ConnectPoint> ingressPoints,
Set<ConnectPoint> egressPoints,
List<Constraint> constraints,
- int priority, boolean egressTreatment) {
+ int priority,
+ boolean egressTreatment,
+ Map<ConnectPoint, TrafficSelector> ingressSelectors) {
super(appId, key, resources(links), selector, treatment, constraints, priority);
this.links = links;
this.ingressPoints = ingressPoints;
this.egressPoints = egressPoints;
this.egressTreatmentFlag = egressTreatment;
+ this.ingressSelectors = ingressSelectors;
}
/**
@@ -83,6 +96,7 @@
this.ingressPoints = null;
this.egressPoints = null;
this.egressTreatmentFlag = false;
+ this.ingressSelectors = null;
}
/**
@@ -104,6 +118,7 @@
Set<Link> links;
Set<ConnectPoint> ingressPoints;
Set<ConnectPoint> egressPoints;
+ Map<ConnectPoint, TrafficSelector> ingressSelectors = Collections.emptyMap();
boolean egressTreatmentFlag;
private Builder() {
@@ -165,6 +180,17 @@
}
/**
+ * Sets the map ingress selectors to connection points of the intent.
+ *
+ * @param ingressSelectors maps connection point to traffic selector
+ * @return this builder
+ */
+ public Builder ingressSelectors(Map<ConnectPoint, TrafficSelector> ingressSelectors) {
+ this.ingressSelectors = ImmutableMap.copyOf(ingressSelectors);
+ return this;
+ }
+
+ /**
* Sets the links of the link collection intent
* that will be built.
*
@@ -206,7 +232,8 @@
egressPoints,
constraints,
priority,
- egressTreatmentFlag
+ egressTreatmentFlag,
+ ingressSelectors
);
}
}
@@ -241,6 +268,14 @@
}
/**
+ * Returns the multiple selectors jointly with their connection points.
+ * @return multiple selectors
+ */
+ public Map<ConnectPoint, TrafficSelector> ingressSelectors() {
+ return ingressSelectors;
+ }
+
+ /**
* Returns whether treatment should be applied on egress.
*
* @return the egress treatment flag
@@ -262,7 +297,8 @@
.add("links", links())
.add("ingress", ingressPoints())
.add("egress", egressPoints())
- .add("treatementOnEgress", applyTreatmentOnEgress())
+ .add("selectors", ingressSelectors())
+ .add("treatmentOnEgress", applyTreatmentOnEgress())
.toString();
}
-}
\ No newline at end of file
+}
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 0c01543..d1fe612 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
@@ -17,6 +17,7 @@
import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.onosproject.core.ApplicationId;
@@ -26,6 +27,7 @@
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import static com.google.common.base.Preconditions.checkArgument;
@@ -39,6 +41,10 @@
private final Set<ConnectPoint> ingressPoints;
private final ConnectPoint egressPoint;
+ /**
+ * To manage multiple selectors use case.
+ */
+ private final Map<ConnectPoint, TrafficSelector> ingressSelectors;
/**
* Creates a new multi-to-single point connectivity intent for the specified
@@ -52,19 +58,22 @@
* @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
+ * @param ingressSelectors map to store the association ingress to selector
* @throws NullPointerException if {@code ingressPoints} or
* {@code egressPoint} is null.
* @throws IllegalArgumentException if the size of {@code ingressPoints} is
* not more than 1
*/
private MultiPointToSinglePointIntent(ApplicationId appId,
- Key key,
- TrafficSelector selector,
- TrafficTreatment treatment,
- Set<ConnectPoint> ingressPoints,
- ConnectPoint egressPoint,
- List<Constraint> constraints,
- int priority) {
+ Key key,
+ TrafficSelector selector,
+ TrafficTreatment treatment,
+ Set<ConnectPoint> ingressPoints,
+ ConnectPoint egressPoint,
+ List<Constraint> constraints,
+ int priority,
+ Map<ConnectPoint, TrafficSelector> ingressSelectors
+ ) {
super(appId, key, Collections.emptyList(), selector, treatment, constraints,
priority);
@@ -76,6 +85,7 @@
this.ingressPoints = Sets.newHashSet(ingressPoints);
this.egressPoint = egressPoint;
+ this.ingressSelectors = ingressSelectors;
}
/**
@@ -85,6 +95,7 @@
super();
this.ingressPoints = null;
this.egressPoint = null;
+ this.ingressSelectors = null;
}
/**
@@ -116,6 +127,7 @@
public static final class Builder extends ConnectivityIntent.Builder {
Set<ConnectPoint> ingressPoints;
ConnectPoint egressPoint;
+ Map<ConnectPoint, TrafficSelector> ingressSelectors = Collections.emptyMap();
private Builder() {
// Hide constructor
@@ -189,13 +201,30 @@
}
/**
+ * Sets the selectors of the multi point to single point intent
+ * that will be built.
+ *
+ * @param ingressSelectors the multiple selectos
+ * @return this builder
+ */
+ public Builder selectors(Map<ConnectPoint, TrafficSelector> ingressSelectors) {
+ this.ingressSelectors = ImmutableMap.copyOf(ingressSelectors);
+ return this;
+ }
+
+ /**
* Builds a multi point to single point intent from the
* accumulated parameters.
*
- * @return point to point intent
+ * @return multi point to single point intent
*/
public MultiPointToSinglePointIntent build() {
+ if (selector != null && !selector.criteria().isEmpty() &&
+ ingressSelectors != null && !ingressSelectors.isEmpty()) {
+ throw new IllegalArgumentException("Selector and Multiple Selectors are both set");
+ }
+
return new MultiPointToSinglePointIntent(
appId,
key,
@@ -204,7 +233,8 @@
ingressPoints,
egressPoint,
constraints,
- priority
+ priority,
+ ingressSelectors
);
}
}
@@ -229,6 +259,14 @@
return egressPoint;
}
+ /**
+ * Returns the multiple selectors jointly with their connection points.
+ * @return multiple selectors
+ */
+ public Map<ConnectPoint, TrafficSelector> ingressSelectors() {
+ return ingressSelectors;
+ }
+
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
@@ -241,6 +279,7 @@
.add("treatment", treatment())
.add("ingress", ingressPoints())
.add("egress", egressPoint())
+ .add("selectors", ingressSelectors())
.add("constraints", constraints())
.toString();
}