[ONOS-5264] [ONOS-5242] Intents w/ FilteredConnectPoint
Change-Id: Ibe9062c904ad9a6c3ba001fe57be7cec49eb8a4d
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 2b8398f..3048aac 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,20 +17,21 @@
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;
import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.FilteredConnectPoint;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
+import org.slf4j.Logger;
import java.util.List;
-import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
/**
* Abstraction of multiple source to single destination connectivity intent.
@@ -38,26 +39,21 @@
@Beta
public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
- private final Set<ConnectPoint> ingressPoints;
- private final ConnectPoint egressPoint;
- /**
- * To manage multiple selectors use case.
- */
- private final Map<ConnectPoint, TrafficSelector> ingressSelectors;
+ private final Set<FilteredConnectPoint> ingressPoints;
+ private final FilteredConnectPoint egressPoint;
/**
* Creates a new multi-to-single point connectivity intent for the specified
- * traffic selector and treatment.
+ * traffic selector and treatment with filtered connect point.
*
* @param appId application identifier
* @param key intent key
* @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 ingressPoints set of filtered ports from which ingress traffic originates
+ * @param egressPoint filtered 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
@@ -67,24 +63,22 @@
Key key,
TrafficSelector selector,
TrafficTreatment treatment,
- Set<ConnectPoint> ingressPoints,
- ConnectPoint egressPoint,
+ Set<FilteredConnectPoint> ingressPoints,
+ FilteredConnectPoint egressPoint,
List<Constraint> constraints,
- int priority,
- Map<ConnectPoint, TrafficSelector> ingressSelectors
- ) {
+ int priority
+ ) {
super(appId, key, ImmutableSet.of(), selector, treatment, constraints,
- priority);
+ priority);
checkNotNull(ingressPoints);
checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
checkNotNull(egressPoint);
checkArgument(!ingressPoints.contains(egressPoint),
- "Set of ingresses should not contain egress (egress: %s)", egressPoint);
+ "Set of ingresses should not contain egress (egress: %s)", egressPoint);
- this.ingressPoints = Sets.newHashSet(ingressPoints);
+ this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
this.egressPoint = egressPoint;
- this.ingressSelectors = ingressSelectors;
}
/**
@@ -94,7 +88,6 @@
super();
this.ingressPoints = null;
this.egressPoint = null;
- this.ingressSelectors = null;
}
/**
@@ -124,9 +117,9 @@
* Builder of a multi point to single point intent.
*/
public static final class Builder extends ConnectivityIntent.Builder {
- Set<ConnectPoint> ingressPoints;
- ConnectPoint egressPoint;
- Map<ConnectPoint, TrafficSelector> ingressSelectors = ImmutableMap.of();
+ private final Logger log = getLogger(getClass());
+ private Set<FilteredConnectPoint> ingressPoints;
+ private FilteredConnectPoint egressPoint;
private Builder() {
// Hide constructor
@@ -141,8 +134,9 @@
protected Builder(MultiPointToSinglePointIntent intent) {
super(intent);
- this.ingressPoints(intent.ingressPoints())
- .egressPoint(intent.egressPoint());
+ this.filteredIngressPoints(intent.filteredIngressPoints())
+ .filteredEgressPoint(intent.filteredEgressPoint());
+
}
@Override
@@ -182,8 +176,15 @@
* @param ingressPoints ingress connect points
* @return this builder
*/
+ @Deprecated
public Builder ingressPoints(Set<ConnectPoint> ingressPoints) {
- this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
+ if (this.ingressPoints != null) {
+ log.warn("Ingress points are already set, " +
+ "this will override original ingress points.");
+ }
+ this.ingressPoints = ingressPoints.stream()
+ .map(FilteredConnectPoint::new)
+ .collect(Collectors.toSet());
return this;
}
@@ -194,20 +195,37 @@
* @param egressPoint egress connect point
* @return this builder
*/
+ @Deprecated
public Builder egressPoint(ConnectPoint egressPoint) {
- this.egressPoint = egressPoint;
+ if (this.egressPoint != null) {
+ log.warn("Egress point is already set, " +
+ "this will override original egress point.");
+ }
+ this.egressPoint = new FilteredConnectPoint(egressPoint);
return this;
}
/**
- * Sets the selectors of the multi point to single point intent
+ * Sets the filtered ingress point of the single point to multi point intent
* that will be built.
*
- * @param ingressSelectors the multiple selectos
+ * @param ingressPoints filtered ingress connect points
* @return this builder
*/
- public Builder selectors(Map<ConnectPoint, TrafficSelector> ingressSelectors) {
- this.ingressSelectors = ImmutableMap.copyOf(ingressSelectors);
+ public Builder filteredIngressPoints(Set<FilteredConnectPoint> ingressPoints) {
+ this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
+ return this;
+ }
+
+ /**
+ * Sets the filtered egress point of the multi point to single 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;
}
@@ -219,11 +237,6 @@
*/
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,
@@ -232,8 +245,7 @@
ingressPoints,
egressPoint,
constraints,
- priority,
- ingressSelectors
+ priority
);
}
}
@@ -246,7 +258,9 @@
* @return set of ingress ports
*/
public Set<ConnectPoint> ingressPoints() {
- return ingressPoints;
+ return ingressPoints.stream()
+ .map(FilteredConnectPoint::connectPoint)
+ .collect(Collectors.toSet());
}
/**
@@ -255,17 +269,29 @@
* @return egress port
*/
public ConnectPoint egressPoint() {
- return egressPoint;
+ return egressPoint.connectPoint();
}
/**
- * Returns the multiple selectors jointly with their connection points.
- * @return multiple selectors
+ * Returns the set of ports on which ingress traffic should be connected to
+ * the egress port.
+ *
+ * @return set of ingress ports
*/
- public Map<ConnectPoint, TrafficSelector> ingressSelectors() {
- return ingressSelectors;
+ public Set<FilteredConnectPoint> filteredIngressPoints() {
+ return ingressPoints;
}
+ /**
+ * Returns the port on which the traffic should egress.
+ *
+ * @return egress port
+ */
+ public FilteredConnectPoint filteredEgressPoint() {
+ return egressPoint;
+ }
+
+
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
@@ -278,7 +304,8 @@
.add("treatment", treatment())
.add("ingress", ingressPoints())
.add("egress", egressPoint())
- .add("selectors", ingressSelectors())
+ .add("filteredIngressCPs", filteredIngressPoints())
+ .add("filteredEgressCP", filteredEgressPoint())
.add("constraints", constraints())
.toString();
}