[ONOS-4595] Harmonize the sb of the Intent Framework
Changes:
- Moves PointToPointIntent to LinkCollectionIntent;
- Moves PointToPointIntent to the new FilteredConnectPoint API;
- Updates unit tests;
Change-Id: Iade5090b9289c5b2d9f4ee41aa0d2d01b5e3699c
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 0893528..11f9f77 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
@@ -46,8 +46,45 @@
private final Set<FilteredConnectPoint> ingressPoints;
private final Set<FilteredConnectPoint> egressPoints;
private final boolean egressTreatmentFlag;
+ private final double cost;
+ private static final int DEFAULT_COST = 1;
-
+ /**
+ * Creates a new actionable intent capable of funneling the selected
+ * traffic along the specified convergent tree and out the given egress
+ * point satisfying the specified constraints.
+ *
+ * @param appId application identifier
+ * @param key key to use for the intent
+ * @param selector traffic match
+ * @param treatment action
+ * @param links traversed links
+ * @param ingressPoints filtered ingress points
+ * @param egressPoints filtered egress points
+ * @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 cost the cost of the links
+ * @throws NullPointerException {@code path} is null
+ */
+ private LinkCollectionIntent(ApplicationId appId,
+ Key key,
+ TrafficSelector selector,
+ TrafficTreatment treatment,
+ Set<Link> links,
+ Set<FilteredConnectPoint> ingressPoints,
+ Set<FilteredConnectPoint> egressPoints,
+ List<Constraint> constraints,
+ int priority,
+ boolean egressTreatment,
+ double cost) {
+ super(appId, key, resources(links), selector, treatment, constraints, priority);
+ this.links = links;
+ this.ingressPoints = ingressPoints;
+ this.egressPoints = egressPoints;
+ this.egressTreatmentFlag = egressTreatment;
+ this.cost = cost;
+ }
/**
* Creates a new actionable intent capable of funneling the selected
@@ -76,22 +113,19 @@
List<Constraint> constraints,
int priority,
boolean egressTreatment) {
- super(appId, key, resources(links), selector, treatment, constraints, priority);
- this.links = links;
- this.ingressPoints = ingressPoints;
- this.egressPoints = egressPoints;
- this.egressTreatmentFlag = egressTreatment;
+ this(appId, key, selector, treatment, links, ingressPoints, egressPoints, constraints,
+ priority, egressTreatment, DEFAULT_COST);
}
/**
* Constructor for serializer.
*/
protected LinkCollectionIntent() {
- super();
this.links = null;
this.ingressPoints = null;
this.egressPoints = null;
this.egressTreatmentFlag = false;
+ this.cost = DEFAULT_COST;
}
/**
@@ -115,6 +149,8 @@
private Set<FilteredConnectPoint> ingressPoints;
private Set<FilteredConnectPoint> egressPoints;
private boolean egressTreatmentFlag;
+ private double cost;
+
private Builder() {
// Hide constructor
@@ -237,6 +273,17 @@
}
/**
+ * Sets the cost for the links of the Intent.
+ *
+ * @param cost the cost of the links
+ * @return this builder
+ */
+ public Builder cost(double cost) {
+ this.cost = cost;
+ return this;
+ }
+
+ /**
* Builds a single point to multi point intent from the
* accumulated parameters.
*
@@ -254,7 +301,8 @@
egressPoints,
constraints,
priority,
- egressTreatmentFlag
+ egressTreatmentFlag,
+ cost
);
}
}
@@ -324,6 +372,15 @@
return egressTreatmentFlag;
}
+ /**
+ * Returns the cost of the links of this intent.
+ *
+ * @return the cost of the links
+ */
+ public double cost() {
+ return cost;
+ }
+
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
@@ -338,6 +395,7 @@
.add("ingress", ingressPoints())
.add("egress", egressPoints())
.add("treatementOnEgress", applyTreatmentOnEgress())
+ .add("cost", cost())
.toString();
}
}
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 6e205e1..ba3b2c2 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
@@ -21,6 +21,7 @@
import com.google.common.annotations.Beta;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.FilteredConnectPoint;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
@@ -35,8 +36,8 @@
@Beta
public final class PointToPointIntent extends ConnectivityIntent {
- private final ConnectPoint ingressPoint;
- private final ConnectPoint egressPoint;
+ private final FilteredConnectPoint ingressPoint;
+ private final FilteredConnectPoint egressPoint;
/**
* Returns a new point to point intent builder. The application id,
@@ -54,8 +55,8 @@
* Builder of a point to point intent.
*/
public static final class Builder extends ConnectivityIntent.Builder {
- ConnectPoint ingressPoint;
- ConnectPoint egressPoint;
+ FilteredConnectPoint ingressPoint;
+ FilteredConnectPoint egressPoint;
private Builder() {
// Hide constructor
@@ -97,8 +98,9 @@
* @param ingressPoint ingress connect point
* @return this builder
*/
+ @Deprecated
public Builder ingressPoint(ConnectPoint ingressPoint) {
- this.ingressPoint = ingressPoint;
+ this.ingressPoint = new FilteredConnectPoint(ingressPoint);
return this;
}
@@ -108,11 +110,37 @@
* @param egressPoint egress connect point
* @return this builder
*/
+ @Deprecated
public Builder egressPoint(ConnectPoint egressPoint) {
+ this.egressPoint = new FilteredConnectPoint(egressPoint);
+ return this;
+ }
+
+ /**
+ * Sets the filtered ingress point of the point to
+ * point intent that will be built.
+ *
+ * @param ingressPoint filtered ingress connect point
+ * @return this builder
+ */
+ public Builder filteredIngressPoint(FilteredConnectPoint ingressPoint) {
+ this.ingressPoint = ingressPoint;
+ return this;
+ }
+
+ /**
+ * Sets the filtered egress point of the point to
+ * point intent that will be built.
+ *
+ * @param egressPoint filtered egress connect point
+ * @return this builder
+ */
+ public Builder filteredEgressPoint(FilteredConnectPoint egressPoint) {
this.egressPoint = egressPoint;
return this;
}
+
/**
* Builds a point to point intent from the accumulated parameters.
*
@@ -143,8 +171,8 @@
* @param key key of the intent
* @param selector traffic selector
* @param treatment treatment
- * @param ingressPoint ingress port
- * @param egressPoint egress port
+ * @param ingressPoint filtered ingress port
+ * @param egressPoint filtered 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
@@ -154,8 +182,8 @@
Key key,
TrafficSelector selector,
TrafficTreatment treatment,
- ConnectPoint ingressPoint,
- ConnectPoint egressPoint,
+ FilteredConnectPoint ingressPoint,
+ FilteredConnectPoint egressPoint,
List<Constraint> constraints,
int priority) {
super(appId, key, Collections.emptyList(), selector, treatment, constraints,
@@ -183,8 +211,9 @@
*
* @return ingress port
*/
+ @Deprecated
public ConnectPoint ingressPoint() {
- return ingressPoint;
+ return ingressPoint.connectPoint();
}
/**
@@ -192,7 +221,27 @@
*
* @return egress port
*/
+ @Deprecated
public ConnectPoint egressPoint() {
+ return egressPoint.connectPoint();
+ }
+
+ /**
+ * Returns the filtered port on which the ingress traffic should be connected to the
+ * egress.
+ *
+ * @return ingress port
+ */
+ public FilteredConnectPoint filteredIngressPoint() {
+ return ingressPoint;
+ }
+
+ /**
+ * Return the filtered port on which the traffic should exit.
+ *
+ * @return egress port
+ */
+ public FilteredConnectPoint filteredEgressPoint() {
return egressPoint;
}
@@ -206,8 +255,8 @@
.add("resources", resources())
.add("selector", selector())
.add("treatment", treatment())
- .add("ingress", ingressPoint)
- .add("egress", egressPoint)
+ .add("ingress", filteredIngressPoint())
+ .add("egress", filteredEgressPoint())
.add("constraints", constraints())
.toString();
}