Yi Tseng

[ONOS-5264] [ONOS-5242] Intents w/ FilteredConnectPoint

Change-Id: Ibe9062c904ad9a6c3ba001fe57be7cec49eb8a4d
Showing 18 changed files with 650 additions and 318 deletions
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net;
import com.google.common.base.MoreObjects;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.TrafficSelector;
import java.util.Objects;
/**
* Connection point with TrafficSelector field.
*/
public class FilteredConnectPoint {
private final ConnectPoint connectPoint;
private final TrafficSelector trafficSelector;
/**
* Creates filtered connect point with default traffic selector.
*
* @param connectPoint
*/
public FilteredConnectPoint(ConnectPoint connectPoint) {
this.connectPoint = connectPoint;
this.trafficSelector = DefaultTrafficSelector.emptySelector();
}
/**
* Creates new filtered connection point.
*
* @param connectPoint connect point
* @param trafficSelector traffic selector for this connect point
*/
public FilteredConnectPoint(ConnectPoint connectPoint, TrafficSelector trafficSelector) {
this.connectPoint = connectPoint;
this.trafficSelector = trafficSelector;
}
/**
* Returns the traffic selector for this connect point.
*
* @return Traffic selector for this connect point
*/
public TrafficSelector trafficSelector() {
return trafficSelector;
}
/**
* Returns the connection point.
* @return
*/
public ConnectPoint connectPoint() {
return connectPoint;
}
@Override
public int hashCode() {
return Objects.hash(connectPoint, trafficSelector);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("connectPoint", connectPoint)
.add("trafficSelector", trafficSelector)
.toString();
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (this == obj) {
return true;
}
if (obj instanceof FilteredConnectPoint) {
FilteredConnectPoint other = (FilteredConnectPoint) obj;
return other.connectPoint().equals(connectPoint) &&
other.trafficSelector().equals(trafficSelector());
} else {
return false;
}
}
}
......@@ -475,6 +475,23 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
}
@Override
public TrafficTreatment.Builder addTreatment(TrafficTreatment treatment) {
List<Instruction> previous = current;
deferred();
treatment.deferred().forEach(i -> add(i));
immediate();
treatment.immediate().stream()
// NOACTION will get re-added if there are no other actions
.filter(i -> i.type() != Instruction.Type.NOACTION)
.forEach(i -> add(i));
clear = treatment.clearedDeferred();
current = previous;
return this;
}
@Override
public TrafficTreatment build() {
if (deferred.size() == 0 && immediate.size() == 0
&& table == null && !clear) {
......
......@@ -397,6 +397,14 @@ public interface TrafficTreatment {
Builder extension(ExtensionTreatment extension, DeviceId deviceId);
/**
* Add all instructions from another treatment.
*
* @param treatment another treatment
* @return a treatment builder
*/
Builder addTreatment(TrafficTreatment treatment);
/**
* Builds an immutable traffic treatment descriptor.
* <p>
* If the treatment is empty when build() is called, it will add a default
......
......@@ -57,19 +57,19 @@ public final class IntentUtils {
SinglePointToMultiPointIntent intent2 = (SinglePointToMultiPointIntent) two;
return Objects.equals(intent1.selector(), intent2.selector()) &&
Objects.equals(intent1.treatment(), intent2.treatment()) &&
Objects.equals(intent1.constraints(), intent2.constraints()) &&
Objects.equals(intent1.ingressPoint(), intent2.ingressPoint()) &&
Objects.equals(intent1.egressPoints(), intent2.egressPoints());
Objects.equals(intent1.treatment(), intent2.treatment()) &&
Objects.equals(intent1.filteredIngressPoint(), intent2.filteredIngressPoint()) &&
Objects.equals(intent1.filteredEgressPoints(), intent2.filteredEgressPoints()) &&
Objects.equals(intent1.constraints(), intent2.constraints());
} else if (one instanceof MultiPointToSinglePointIntent) {
MultiPointToSinglePointIntent intent1 = (MultiPointToSinglePointIntent) one;
MultiPointToSinglePointIntent intent2 = (MultiPointToSinglePointIntent) two;
return Objects.equals(intent1.selector(), intent2.selector()) &&
Objects.equals(intent1.treatment(), intent2.treatment()) &&
Objects.equals(intent1.constraints(), intent2.constraints()) &&
Objects.equals(intent1.ingressPoints(), intent2.ingressPoints()) &&
Objects.equals(intent1.egressPoint(), intent2.egressPoint());
Objects.equals(intent1.filteredIngressPoints(), intent2.filteredIngressPoints()) &&
Objects.equals(intent1.filteredEgressPoint(), intent2.filteredEgressPoint()) &&
Objects.equals(intent1.treatment(), intent2.treatment()) &&
Objects.equals(intent1.constraints(), intent2.constraints());
} else if (one instanceof PointToPointIntent) {
PointToPointIntent intent1 = (PointToPointIntent) one;
PointToPointIntent intent2 = (PointToPointIntent) two;
......
......@@ -17,19 +17,22 @@
package org.onosproject.net.intent;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
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.FilteredConnectPoint;
import org.onosproject.net.Link;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Abstraction of a connectivity intent that is implemented by a set of path
......@@ -40,17 +43,11 @@ public final class LinkCollectionIntent extends ConnectivityIntent {
private final Set<Link> links;
private final Set<ConnectPoint> ingressPoints;
private final Set<ConnectPoint> egressPoints;
private final Set<FilteredConnectPoint> ingressPoints;
private final Set<FilteredConnectPoint> egressPoints;
private final boolean egressTreatmentFlag;
/**
* To manage multiple selectors use case.
*/
private final Map<ConnectPoint, TrafficSelector> ingressSelectors;
/**
* To manage multiple treatments use case.
*/
private final Map<ConnectPoint, TrafficTreatment> egressTreatments;
/**
* Creates a new actionable intent capable of funneling the selected
......@@ -62,13 +59,11 @@ public final class LinkCollectionIntent extends ConnectivityIntent {
* @param selector traffic match
* @param treatment action
* @param links traversed links
* @param ingressPoints ingress points
* @param egressPoints egress points
* @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 ingressSelectors map to store the association ingress to selector
* @param egressTreatments map to store the association egress to treatment
* @throws NullPointerException {@code path} is null
*/
private LinkCollectionIntent(ApplicationId appId,
......@@ -76,20 +71,16 @@ public final class LinkCollectionIntent extends ConnectivityIntent {
TrafficSelector selector,
TrafficTreatment treatment,
Set<Link> links,
Set<ConnectPoint> ingressPoints,
Set<ConnectPoint> egressPoints,
Set<FilteredConnectPoint> ingressPoints,
Set<FilteredConnectPoint> egressPoints,
List<Constraint> constraints,
int priority,
boolean egressTreatment,
Map<ConnectPoint, TrafficSelector> ingressSelectors,
Map<ConnectPoint, TrafficTreatment> egressTreatments) {
boolean egressTreatment) {
super(appId, key, resources(links), selector, treatment, constraints, priority);
this.links = links;
this.ingressPoints = ingressPoints;
this.egressPoints = egressPoints;
this.egressTreatmentFlag = egressTreatment;
this.ingressSelectors = ingressSelectors;
this.egressTreatments = egressTreatments;
}
/**
......@@ -101,8 +92,6 @@ public final class LinkCollectionIntent extends ConnectivityIntent {
this.ingressPoints = null;
this.egressPoints = null;
this.egressTreatmentFlag = false;
this.ingressSelectors = null;
this.egressTreatments = null;
}
/**
......@@ -121,12 +110,11 @@ public final class LinkCollectionIntent extends ConnectivityIntent {
* Builder of a single point to multi point intent.
*/
public static final class Builder extends ConnectivityIntent.Builder {
Set<Link> links;
Set<ConnectPoint> ingressPoints;
Set<ConnectPoint> egressPoints;
Map<ConnectPoint, TrafficSelector> ingressSelectors = ImmutableMap.of();
Map<ConnectPoint, TrafficTreatment> egressTreatments = ImmutableMap.of();
boolean egressTreatmentFlag;
private final Logger log = getLogger(getClass());
private Set<Link> links;
private Set<FilteredConnectPoint> ingressPoints;
private Set<FilteredConnectPoint> egressPoints;
private boolean egressTreatmentFlag;
private Builder() {
// Hide constructor
......@@ -169,8 +157,15 @@ public final class LinkCollectionIntent extends ConnectivityIntent {
* @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;
}
......@@ -181,30 +176,39 @@ public final class LinkCollectionIntent extends ConnectivityIntent {
* @param egressPoints egress connect points
* @return this builder
*/
@Deprecated
public Builder egressPoints(Set<ConnectPoint> egressPoints) {
this.egressPoints = ImmutableSet.copyOf(egressPoints);
if (this.egressPoints != null) {
log.warn("Egress points are already set, " +
"this will override original egress points.");
}
this.egressPoints = egressPoints.stream()
.map(FilteredConnectPoint::new)
.collect(Collectors.toSet());
return this;
}
/**
* Sets the map ingress selectors to connection points of the intent.
* Sets the filtered ingress point of the single point to multi point intent
* that will be built.
*
* @param ingressSelectors maps connection point to traffic selector
* @param ingressPoints ingress connect points
* @return this builder
*/
public Builder ingressSelectors(Map<ConnectPoint, TrafficSelector> ingressSelectors) {
this.ingressSelectors = ImmutableMap.copyOf(ingressSelectors);
public Builder filteredIngressPoints(Set<FilteredConnectPoint> ingressPoints) {
this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
return this;
}
/**
* Sets the map egress treatments to connection points of the intent.
* Sets the filtered egress points of the single point to multi point intent
* that will be built.
*
* @param egressTreatments maps connection point to traffic treatment
* @param egressPoints egress connect points
* @return this builder
*/
public Builder egressTreatments(Map<ConnectPoint, TrafficTreatment> egressTreatments) {
this.egressTreatments = ImmutableMap.copyOf(egressTreatments);
public Builder filteredEgressPoints(Set<FilteredConnectPoint> egressPoints) {
this.egressPoints = ImmutableSet.copyOf(egressPoints);
return this;
}
......@@ -250,9 +254,7 @@ public final class LinkCollectionIntent extends ConnectivityIntent {
egressPoints,
constraints,
priority,
egressTreatmentFlag,
ingressSelectors,
egressTreatments
egressTreatmentFlag
);
}
}
......@@ -273,7 +275,12 @@ public final class LinkCollectionIntent extends ConnectivityIntent {
* @return the ingress points
*/
public Set<ConnectPoint> ingressPoints() {
return ingressPoints;
if (this.ingressPoints == null) {
return null;
}
return ingressPoints.stream()
.map(FilteredConnectPoint::connectPoint)
.collect(Collectors.toSet());
}
/**
......@@ -282,23 +289,30 @@ public final class LinkCollectionIntent extends ConnectivityIntent {
* @return the egress points
*/
public Set<ConnectPoint> egressPoints() {
return egressPoints;
if (this.egressPoints == null) {
return null;
}
return egressPoints.stream()
.map(FilteredConnectPoint::connectPoint)
.collect(Collectors.toSet());
}
/**
* Returns the multiple selectors jointly with their connection points.
* @return multiple selectors
* Returns the filtered ingress points of the intent.
*
* @return the ingress points
*/
public Map<ConnectPoint, TrafficSelector> ingressSelectors() {
return ingressSelectors;
public Set<FilteredConnectPoint> filteredIngressPoints() {
return ingressPoints;
}
/**
* Returns the multiple treatments jointly with their connection points.
* @return multiple treatments
* Returns the egress points of the intent.
*
* @return the egress points
*/
public Map<ConnectPoint, TrafficTreatment> egressTreatments() {
return egressTreatments;
public Set<FilteredConnectPoint> filteredEgressPoints() {
return egressPoints;
}
/**
......@@ -323,8 +337,6 @@ public final class LinkCollectionIntent extends ConnectivityIntent {
.add("links", links())
.add("ingress", ingressPoints())
.add("egress", egressPoints())
.add("selectors", ingressSelectors())
.add("treatments", egressTreatments())
.add("treatementOnEgress", applyTreatmentOnEgress())
.toString();
}
......
......@@ -17,20 +17,21 @@ package org.onosproject.net.intent;
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 @@ import static com.google.common.base.Preconditions.checkNotNull;
@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 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
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 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
super();
this.ingressPoints = null;
this.egressPoint = null;
this.ingressSelectors = null;
}
/**
......@@ -124,9 +117,9 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
* 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 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
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 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
* @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 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
* @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 filtered ingress point of the single point to multi point intent
* that will be built.
*
* @param ingressPoints filtered ingress connect points
* @return this builder
*/
public Builder filteredIngressPoints(Set<FilteredConnectPoint> ingressPoints) {
this.ingressPoints = ImmutableSet.copyOf(ingressPoints);
return this;
}
/**
* Sets the selectors of the multi point to single point intent
* Sets the filtered egress point of the multi point to single point intent
* that will be built.
*
* @param ingressSelectors the multiple selectos
* @param egressPoint filtered egress connect point
* @return this builder
*/
public Builder selectors(Map<ConnectPoint, TrafficSelector> ingressSelectors) {
this.ingressSelectors = ImmutableMap.copyOf(ingressSelectors);
public Builder filteredEgressPoint(FilteredConnectPoint egressPoint) {
this.egressPoint = egressPoint;
return this;
}
......@@ -219,11 +237,6 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
*/
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 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
ingressPoints,
egressPoint,
constraints,
priority,
ingressSelectors
priority
);
}
}
......@@ -246,7 +258,9 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
* @return set of ingress ports
*/
public Set<ConnectPoint> ingressPoints() {
return ingressPoints;
return ingressPoints.stream()
.map(FilteredConnectPoint::connectPoint)
.collect(Collectors.toSet());
}
/**
......@@ -255,17 +269,29 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
* @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 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
.add("treatment", treatment())
.add("ingress", ingressPoints())
.add("egress", egressPoint())
.add("selectors", ingressSelectors())
.add("filteredIngressCPs", filteredIngressPoints())
.add("filteredEgressCP", filteredEgressPoint())
.add("constraints", constraints())
.toString();
}
......
......@@ -18,35 +18,31 @@ package org.onosproject.net.intent;
import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
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.flow.DefaultTrafficTreatment;
import org.onosproject.net.FilteredConnectPoint;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.slf4j.Logger;
import java.util.Map;
import java.util.Set;
import java.util.List;
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 single source, multiple destination connectivity intent.
*/
@Beta
public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
private final ConnectPoint ingressPoint;
private final Set<ConnectPoint> egressPoints;
/**
* To manage multiple treatments use case.
*/
private final Map<ConnectPoint, TrafficTreatment> egressTreatments;
private final FilteredConnectPoint ingressPoint;
private final Set<FilteredConnectPoint> egressPoints;
/**
* Creates a new single-to-multi point connectivity intent.
......@@ -59,7 +55,6 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
* @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
* @param egressTreatments map to store the association egress to treatment
* @throws NullPointerException if {@code ingressPoint} or
* {@code egressPoints} is null
* @throws IllegalArgumentException if the size of {@code egressPoints} is
......@@ -69,22 +64,20 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
Key key,
TrafficSelector selector,
TrafficTreatment treatment,
ConnectPoint ingressPoint,
Set<ConnectPoint> egressPoints,
FilteredConnectPoint ingressPoint,
Set<FilteredConnectPoint> egressPoints,
List<Constraint> constraints,
int priority,
Map<ConnectPoint, TrafficTreatment> egressTreatments) {
int priority) {
super(appId, key, ImmutableList.of(), selector, treatment, constraints,
priority);
checkNotNull(egressPoints);
checkNotNull(ingressPoint);
checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
checkArgument(!egressPoints.contains(ingressPoint),
"Set of egresses should not contain ingress (ingress: %s)", ingressPoint);
"Set of egresses should not contain ingress (ingress: %s)", ingressPoint);
this.ingressPoint = ingressPoint;
this.egressPoints = Sets.newHashSet(egressPoints);
this.egressTreatments = egressTreatments;
}
/**
......@@ -100,17 +93,42 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
}
/**
* Creates a new builder pre-populated with the information in the given
* intent.
*
* @param intent initial intent
* @return intent builder
*/
public static Builder builder(SinglePointToMultiPointIntent intent) {
return new Builder(intent);
}
/**
* Builder of a single point to multi point intent.
*/
public static final class Builder extends ConnectivityIntent.Builder {
ConnectPoint ingressPoint;
Set<ConnectPoint> egressPoints;
Map<ConnectPoint, TrafficTreatment> egressTreatments = ImmutableMap.of();
private final Logger log = getLogger(getClass());
private FilteredConnectPoint ingressPoint;
private Set<FilteredConnectPoint> egressPoints;
private Builder() {
// Hide constructor
}
/**
* Creates a new builder pre-populated with information from the given
* intent.
*
* @param intent initial intent
*/
protected Builder(SinglePointToMultiPointIntent intent) {
super(intent);
this.filteredEgressPoints(intent.filteredEgressPoints())
.filteredIngressPoint(intent.filteredIngressPoint());
}
@Override
public Builder appId(ApplicationId appId) {
return (Builder) super.appId(appId);
......@@ -148,8 +166,13 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
* @param ingressPoint ingress connect point
* @return this builder
*/
@Deprecated
public Builder ingressPoint(ConnectPoint ingressPoint) {
this.ingressPoint = ingressPoint;
if (this.ingressPoint != null) {
log.warn("Ingress point is already set, " +
"this will override original ingress point.");
}
this.ingressPoint = new FilteredConnectPoint(ingressPoint);
return this;
}
......@@ -160,23 +183,45 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
* @param egressPoints egress connect points
* @return this builder
*/
@Deprecated
public Builder egressPoints(Set<ConnectPoint> egressPoints) {
this.egressPoints = ImmutableSet.copyOf(egressPoints);
if (this.egressPoints != null) {
log.warn("Egress points are already set, " +
"this will override original egress points.");
}
Set<FilteredConnectPoint> filteredConnectPoints =
egressPoints.stream()
.map(FilteredConnectPoint::new)
.collect(Collectors.toSet());
this.egressPoints = ImmutableSet.copyOf(filteredConnectPoints);
return this;
}
/**
* Sets the treatments of the single point to multi point intent
* that will be built.
* Sets the filtered ingress point of the single point to
* multi point intent that will be built.
*
* @param ingressPoint ingress connect point
* @return this builder
*/
public Builder filteredIngressPoint(FilteredConnectPoint ingressPoint) {
this.ingressPoint = ingressPoint;
return this;
}
/**
* Sets the filtered egress points of the single point to
* multi point intent that will be built.
*
* @param egressTreatments the multiple treatments
* @param egressPoints egress connect points
* @return this builder
*/
public Builder treatments(Map<ConnectPoint, TrafficTreatment> egressTreatments) {
this.egressTreatments = ImmutableMap.copyOf(egressTreatments);
public Builder filteredEgressPoints(Set<FilteredConnectPoint> egressPoints) {
this.egressPoints = ImmutableSet.copyOf(egressPoints);
return this;
}
/**
* Builds a single point to multi point intent from the
* accumulated parameters.
......@@ -185,12 +230,6 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
*/
public SinglePointToMultiPointIntent build() {
if (treatment != null && !treatment.allInstructions().isEmpty() &&
!treatment.equals(DefaultTrafficTreatment.emptyTreatment()) &&
egressTreatments != null && !egressTreatments.isEmpty()) {
throw new IllegalArgumentException("Treatment and Multiple Treatments are both set");
}
return new SinglePointToMultiPointIntent(
appId,
key,
......@@ -199,8 +238,7 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
ingressPoint,
egressPoints,
constraints,
priority,
egressTreatments
priority
);
}
}
......@@ -212,7 +250,6 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
super();
this.ingressPoint = null;
this.egressPoints = null;
this.egressTreatments = null;
}
/**
......@@ -222,7 +259,7 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
* @return ingress port
*/
public ConnectPoint ingressPoint() {
return ingressPoint;
return ingressPoint.connectPoint();
}
/**
......@@ -231,17 +268,31 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
* @return set of egress ports
*/
public Set<ConnectPoint> egressPoints() {
return egressPoints;
return egressPoints.stream()
.map(FilteredConnectPoint::connectPoint)
.collect(Collectors.toSet());
}
/**
* Returns the multiple treatments jointly with their connection points.
* @return multiple treatments
* Returns the filtered port on which the ingress traffic should be connected to the
* egress.
*
* @return ingress port
*/
public FilteredConnectPoint filteredIngressPoint() {
return ingressPoint;
}
/**
* Returns the set of filtered ports on which the traffic should egress.
*
* @return set of egress ports
*/
public Map<ConnectPoint, TrafficTreatment> egressTreatments() {
return egressTreatments;
public Set<FilteredConnectPoint> filteredEgressPoints() {
return egressPoints;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
......@@ -254,7 +305,8 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
.add("treatment", treatment())
.add("ingress", ingressPoint)
.add("egress", egressPoints)
.add("treatments", egressTreatments)
.add("filteredIngressCPs", filteredIngressPoint())
.add("filteredEgressCP", filteredEgressPoints())
.add("constraints", constraints())
.toString();
}
......
......@@ -15,7 +15,6 @@
*/
package org.onosproject.net.intent;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
......@@ -25,6 +24,7 @@ import org.onosproject.core.ApplicationId;
import org.onosproject.TestApplicationId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.FilteredConnectPoint;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
......@@ -42,8 +42,6 @@ public abstract class ConnectivityIntentTest extends IntentTest {
public static final IntentId IID = new IntentId(123);
public static final TrafficSelector MATCH = DefaultTrafficSelector.emptySelector();
public static final TrafficTreatment NOP = DefaultTrafficTreatment.emptyTreatment();
public static final Map<ConnectPoint, TrafficSelector> MATCHES = Collections.emptyMap();
public static final Map<ConnectPoint, TrafficTreatment> TREATMENTS = Collections.emptyMap();
public static final ConnectPoint P1 = new ConnectPoint(DeviceId.deviceId("111"), PortNumber.portNumber(0x1));
public static final ConnectPoint P2 = new ConnectPoint(DeviceId.deviceId("222"), PortNumber.portNumber(0x2));
......@@ -52,6 +50,7 @@ public abstract class ConnectivityIntentTest extends IntentTest {
public static final Set<ConnectPoint> PS1 = itemSet(new ConnectPoint[]{P1, P3});
public static final Set<ConnectPoint> PS2 = itemSet(new ConnectPoint[]{P2, P3});
public static final TrafficSelector VLANMATCH1 = DefaultTrafficSelector.builder()
.matchVlanId(VlanId.vlanId("2"))
.build();
......@@ -59,6 +58,13 @@ public abstract class ConnectivityIntentTest extends IntentTest {
.matchVlanId(VlanId.vlanId("3"))
.build();
public static final FilteredConnectPoint FP1 = new FilteredConnectPoint(P1, VLANMATCH1);
public static final FilteredConnectPoint FP2 = new FilteredConnectPoint(P2, VLANMATCH1);
public static final FilteredConnectPoint FP3 = new FilteredConnectPoint(P3, VLANMATCH2);
public static final Set<FilteredConnectPoint> FPS1 = itemSet(new FilteredConnectPoint[]{FP1, FP3});
public static final Set<FilteredConnectPoint> FPS2 = itemSet(new FilteredConnectPoint[]{FP2, FP3});
public static final Map<ConnectPoint, TrafficSelector> VLANMATCHES = Maps.newHashMap();
static {
VLANMATCHES.put(P1, VLANMATCH1);
......
......@@ -26,7 +26,7 @@ import org.onosproject.net.Link;
import org.onosproject.net.NetTestTools;
import org.onosproject.net.NetworkResource;
import org.onosproject.net.Path;
import org.onosproject.net.flow.FlowRule.FlowRemoveReason;
import org.onosproject.net.device.DeviceServiceAdapter;
import org.onosproject.net.flow.FlowId;
import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.FlowRuleExtPayLoad;
......@@ -180,6 +180,67 @@ public class IntentTestsMocks {
}
}
/**
* Mock path service for creating paths within the test.
*
*/
public static class Mp2MpMockPathService
extends PathServiceAdapter {
final String[] pathHops;
final String[] reversePathHops;
/**
* Constructor that provides a set of hops to mock.
*
* @param pathHops path hops to mock
*/
public Mp2MpMockPathService(String[] pathHops) {
this.pathHops = pathHops;
String[] reversed = pathHops.clone();
Collections.reverse(Arrays.asList(reversed));
reversePathHops = reversed;
}
@Override
public Set<Path> getPaths(ElementId src, ElementId dst) {
Set<Path> result = new HashSet<>();
String[] allHops = new String[pathHops.length + 2];
allHops[0] = src.toString();
allHops[allHops.length - 1] = dst.toString();
if (pathHops.length != 0) {
System.arraycopy(pathHops, 0, allHops, 1, pathHops.length);
}
result.add(createPath(allHops));
return result;
}
@Override
public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) {
final Set<Path> paths = getPaths(src, dst);
for (Path path : paths) {
final DeviceId srcDevice = path.src().elementId() instanceof DeviceId ? path.src().deviceId() : null;
final DeviceId dstDevice = path.dst().elementId() instanceof DeviceId ? path.dst().deviceId() : null;
if (srcDevice != null && dstDevice != null) {
final TopologyVertex srcVertex = new DefaultTopologyVertex(srcDevice);
final TopologyVertex dstVertex = new DefaultTopologyVertex(dstDevice);
final Link link = link(src.toString(), 1, dst.toString(), 1);
final double weightValue = weight.weight(new DefaultTopologyEdge(srcVertex, dstVertex, link));
if (weightValue < 0) {
return new HashSet<>();
}
}
}
return paths;
}
}
public static final class MockResourceService implements ResourceService {
private final double bandwidth;
......@@ -429,4 +490,14 @@ public class IntentTestsMocks {
}
}
/**
* Mocks the device service so that a device appears available in the test.
*/
public static class MockDeviceService extends DeviceServiceAdapter {
@Override
public boolean isAvailable(DeviceId deviceId) {
return true;
}
}
}
......
......@@ -21,8 +21,10 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import com.google.common.collect.Sets;
import org.junit.Test;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.FilteredConnectPoint;
import org.onosproject.net.Link;
import org.onosproject.net.NetTestTools;
import org.onosproject.net.flow.TrafficSelector;
......@@ -49,6 +51,8 @@ public class LinkCollectionIntentTest extends IntentTest {
final ConnectPoint egress = NetTestTools.connectPoint("egress", 3);
final TrafficSelector selector = new IntentTestsMocks.MockSelector();
final IntentTestsMocks.MockTreatment treatment = new IntentTestsMocks.MockTreatment();
final FilteredConnectPoint filteredIngress = new FilteredConnectPoint(ingress);
final FilteredConnectPoint filteredEgress = new FilteredConnectPoint(egress);
/**
* Checks that the LinkCollectionIntent class is immutable.
......@@ -179,6 +183,39 @@ public class LinkCollectionIntentTest extends IntentTest {
assertThat(createdConstraints, hasSize(0));
}
/**
* Test filtered connection point for LinkCollection intent.
*/
@Test
public void testFilteredConnectedPoint() {
LinkCollectionIntent intent = createFilteredOne();
Set<Link> links = Sets.newHashSet();
links.add(link("A", 1, "B", 1));
links.add(link("A", 2, "C", 1));
assertThat(intent.appId(), is(APP_ID));
assertThat(intent.treatment(), is(treatment));
assertThat(intent.links(), is(links));
assertThat(intent.applyTreatmentOnEgress(), is(false));
assertThat(intent.filteredIngressPoints(), is(ImmutableSet.of(filteredIngress)));
assertThat(intent.filteredEgressPoints(), is(ImmutableSet.of(filteredEgress)));
intent = createAnotherFiltered();
links = Sets.newHashSet();
links.add(link("A", 1, "B", 1));
links.add(link("A", 2, "C", 1));
links.add(link("B", 2, "D", 1));
links.add(link("B", 3, "E", 1));
assertThat(intent.appId(), is(APP_ID));
assertThat(intent.treatment(), is(treatment));
assertThat(intent.links(), is(links));
assertThat(intent.applyTreatmentOnEgress(), is(true));
assertThat(intent.filteredIngressPoints(), is(ImmutableSet.of(filteredIngress)));
assertThat(intent.filteredEgressPoints(), is(ImmutableSet.of(filteredEgress)));
}
@Override
protected Intent createOne() {
HashSet<Link> links1 = new HashSet<>();
......@@ -206,4 +243,33 @@ public class LinkCollectionIntentTest extends IntentTest {
.egressPoints(ImmutableSet.of(egress))
.build();
}
protected LinkCollectionIntent createFilteredOne() {
Set<Link> links = Sets.newHashSet();
links.add(link("A", 1, "B", 1));
links.add(link("A", 2, "C", 1));
return LinkCollectionIntent.builder()
.appId(APP_ID)
.treatment(treatment)
.links(links)
.filteredIngressPoints(ImmutableSet.of(filteredIngress))
.filteredEgressPoints(ImmutableSet.of(filteredEgress))
.build();
}
protected LinkCollectionIntent createAnotherFiltered() {
Set<Link> links = Sets.newHashSet();
links.add(link("A", 1, "B", 1));
links.add(link("A", 2, "C", 1));
links.add(link("B", 2, "D", 1));
links.add(link("B", 3, "E", 1));
return LinkCollectionIntent.builder()
.appId(APP_ID)
.treatment(treatment)
.links(links)
.applyTreatmentOnEgress(true)
.filteredIngressPoints(ImmutableSet.of(filteredIngress))
.filteredEgressPoints(ImmutableSet.of(filteredEgress))
.build();
}
}
......
......@@ -16,9 +16,7 @@
package org.onosproject.net.intent;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertEquals;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
......@@ -36,6 +34,9 @@ public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest {
assertThatClassIsImmutable(MultiPointToSinglePointIntent.class);
}
/**
* Create three intents with normal connect points.
*/
@Test
public void basics() {
MultiPointToSinglePointIntent intent = createOne();
......@@ -43,40 +44,38 @@ public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest {
assertEquals("incorrect match", MATCH, intent.selector());
assertEquals("incorrect ingress", PS1, intent.ingressPoints());
assertEquals("incorrect egress", P2, intent.egressPoint());
}
@Rule
public ExpectedException wrongMultiple = ExpectedException.none();
@Test
public void multipleSelectors() {
MultiPointToSinglePointIntent intent = createFirstMultiple();
intent = createAnother();
assertEquals("incorrect id", APPID, intent.appId());
assertEquals("incorrect match", MATCH, intent.selector());
assertEquals("incorrect ingress", PS1, intent.ingressPoints());
assertEquals("incorrect egress", P2, intent.egressPoint());
assertEquals("incorrect selectors", MATCHES, intent.ingressSelectors());
assertEquals("incorrect ingress", PS2, intent.ingressPoints());
assertEquals("incorrect egress", P1, intent.egressPoint());
intent = createSecondMultiple();
intent = createVlanMatch();
assertEquals("incorrect id", APPID, intent.appId());
assertEquals("incorrect match", VLANMATCH1, intent.selector());
assertEquals("incorrect ingress", PS1, intent.ingressPoints());
assertEquals("incorrect egress", P2, intent.egressPoint());
assertEquals("incorrect selectors", MATCHES, intent.ingressSelectors());
}
intent = createThirdMultiple();
/**
* Create two intents with filtered connect points.
*/
@Test
public void filteredIntent() {
MultiPointToSinglePointIntent intent = createFilteredOne();
assertEquals("incorrect id", APPID, intent.appId());
assertEquals("incorrect match", MATCH, intent.selector());
assertEquals("incorrect ingress", PS1, intent.ingressPoints());
assertEquals("incorrect egress", P2, intent.egressPoint());
assertEquals("incorrect selectors", VLANMATCHES, intent.ingressSelectors());
assertEquals("incorrect filtered ingress", FPS1, intent.filteredIngressPoints());
assertEquals("incorrect filtered egress", FP2, intent.filteredEgressPoint());
wrongMultiple.expect(IllegalArgumentException.class);
wrongMultiple.expectMessage("Selector and Multiple Selectors are both set");
intent = createWrongMultiple();
}
intent = createAnotherFiltered();
assertEquals("incorrect id", APPID, intent.appId());
assertEquals("incorrect match", MATCH, intent.selector());
assertEquals("incorrect filtered ingress", FPS2, intent.filteredIngressPoints());
assertEquals("incorrect filtered egress", FP1, intent.filteredEgressPoint());
}
@Override
protected MultiPointToSinglePointIntent createOne() {
......@@ -100,47 +99,42 @@ public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest {
.build();
}
protected MultiPointToSinglePointIntent createFirstMultiple() {
protected MultiPointToSinglePointIntent createVlanMatch() {
return MultiPointToSinglePointIntent.builder()
.appId(APPID)
.selector(MATCH)
.selector(VLANMATCH1)
.treatment(NOP)
.ingressPoints(PS1)
.egressPoint(P2)
.selectors(MATCHES)
.build();
}
protected MultiPointToSinglePointIntent createSecondMultiple() {
protected MultiPointToSinglePointIntent createFilteredOne() {
return MultiPointToSinglePointIntent.builder()
.appId(APPID)
.selector(VLANMATCH1)
.treatment(NOP)
.ingressPoints(PS1)
.egressPoint(P2)
.selectors(MATCHES)
.filteredIngressPoints(FPS1)
.filteredEgressPoint(FP2)
.build();
}
protected MultiPointToSinglePointIntent createThirdMultiple() {
protected MultiPointToSinglePointIntent createAnotherFiltered() {
return MultiPointToSinglePointIntent.builder()
.appId(APPID)
.selector(MATCH)
.treatment(NOP)
.ingressPoints(PS1)
.egressPoint(P2)
.selectors(VLANMATCHES)
.filteredIngressPoints(FPS2)
.filteredEgressPoint(FP1)
.build();
}
protected MultiPointToSinglePointIntent createWrongMultiple() {
protected MultiPointToSinglePointIntent createWrongIntent() {
return MultiPointToSinglePointIntent.builder()
.appId(APPID)
.selector(VLANMATCH1)
.treatment(NOP)
.ingressPoints(PS1)
.egressPoint(P2)
.selectors(VLANMATCHES)
.filteredIngressPoints(FPS1)
.filteredEgressPoint(FP2)
.build();
}
......
......@@ -15,9 +15,7 @@
*/
package org.onosproject.net.intent;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.junit.Assert.assertEquals;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
......@@ -42,41 +40,28 @@ public class SinglePointToMultiPointIntentTest extends ConnectivityIntentTest {
assertEquals("incorrect match", MATCH, intent.selector());
assertEquals("incorrect ingress", P1, intent.ingressPoint());
assertEquals("incorrect egress", PS2, intent.egressPoints());
}
@Rule
public ExpectedException wrongMultiple = ExpectedException.none();
@Test
public void multipleTreatments() {
SinglePointToMultiPointIntent intent = createFirstMultiple();
intent = createAnother();
assertEquals("incorrect id", APPID, intent.appId());
assertEquals("incorrect match", MATCH, intent.selector());
assertEquals("incorrect ingress", P1, intent.ingressPoint());
assertEquals("incorrect egress", PS2, intent.egressPoints());
assertEquals("incorrect treatment", NOP, intent.treatment());
assertEquals("incorrect treatments", TREATMENTS, intent.egressTreatments());
assertEquals("incorrect ingress", P2, intent.ingressPoint());
assertEquals("incorrect egress", PS1, intent.egressPoints());
}
intent = createSecondMultiple();
@Test
public void filteredIntent() {
SinglePointToMultiPointIntent intent = createFilteredOne();
assertEquals("incorrect id", APPID, intent.appId());
assertEquals("incorrect match", MATCH, intent.selector());
assertEquals("incorrect ingress", P1, intent.ingressPoint());
assertEquals("incorrect egress", PS2, intent.egressPoints());
assertEquals("incorrect treatment", VLANACTION1, intent.treatment());
assertEquals("incorrect selectors", TREATMENTS, intent.egressTreatments());
assertEquals("incorrect filtered ingress", FP2, intent.filteredIngressPoint());
assertEquals("incorrect filtered egress", FPS1, intent.filteredEgressPoints());
intent = createThirdMultiple();
intent = createAnotherFiltered();
assertEquals("incorrect id", APPID, intent.appId());
assertEquals("incorrect match", MATCH, intent.selector());
assertEquals("incorrect ingress", P1, intent.ingressPoint());
assertEquals("incorrect egress", PS2, intent.egressPoints());
assertEquals("incorrect treatment", NOP, intent.treatment());
assertEquals("incorrect selectors", VLANACTIONS, intent.egressTreatments());
assertEquals("incorrect filtered ingress", FP1, intent.filteredIngressPoint());
assertEquals("incorrect filtered egress", FPS2, intent.filteredEgressPoints());
wrongMultiple.expect(IllegalArgumentException.class);
wrongMultiple.expectMessage("Treatment and Multiple Treatments are both set");
intent = createWrongMultiple();
}
@Override
......@@ -101,48 +86,31 @@ public class SinglePointToMultiPointIntentTest extends ConnectivityIntentTest {
.build();
}
protected SinglePointToMultiPointIntent createFirstMultiple() {
protected SinglePointToMultiPointIntent createFilteredOne() {
return SinglePointToMultiPointIntent.builder()
.appId(APPID)
.selector(MATCH)
.treatment(NOP)
.ingressPoint(P1)
.egressPoints(PS2)
.treatments(TREATMENTS)
.filteredEgressPoints(FPS1)
.filteredIngressPoint(FP2)
.build();
}
protected SinglePointToMultiPointIntent createSecondMultiple() {
protected SinglePointToMultiPointIntent createAnotherFiltered() {
return SinglePointToMultiPointIntent.builder()
.appId(APPID)
.selector(MATCH)
.treatment(VLANACTION1)
.ingressPoint(P1)
.egressPoints(PS2)
.treatments(TREATMENTS)
.build();
}
protected SinglePointToMultiPointIntent createThirdMultiple() {
return SinglePointToMultiPointIntent.builder()
.appId(APPID)
.selector(MATCH)
.treatment(NOP)
.ingressPoint(P1)
.egressPoints(PS2)
.treatments(VLANACTIONS)
.filteredEgressPoints(FPS2)
.filteredIngressPoint(FP1)
.build();
}
protected SinglePointToMultiPointIntent createWrongMultiple() {
protected SinglePointToMultiPointIntent createWrongIntent() {
return SinglePointToMultiPointIntent.builder()
.appId(APPID)
.selector(MATCH)
.treatment(VLANACTION1)
.ingressPoint(P1)
.egressPoints(PS2)
.treatments(VLANACTIONS)
.treatment(NOP)
.selector(VLANMATCH1)
.filteredEgressPoints(FPS2)
.filteredIngressPoint(FP1)
.build();
}
......
......@@ -119,12 +119,10 @@ public class MultiPointToSinglePointIntentCompiler
Intent result = LinkCollectionIntent.builder()
.appId(intent.appId())
.selector(intent.selector())
.treatment(intent.treatment())
.links(Sets.newHashSet(links.values()))
.ingressPoints(intent.ingressPoints())
.egressPoints(ImmutableSet.of(intent.egressPoint()))
.ingressSelectors(intent.ingressSelectors())
.filteredIngressPoints(intent.filteredIngressPoints())
.filteredEgressPoints(ImmutableSet.of(intent.filteredEgressPoint()))
.priority(intent.priority())
.constraints(intent.constraints())
.build();
......
......@@ -69,15 +69,13 @@ public class SinglePointToMultiPointIntentCompiler
Intent result = LinkCollectionIntent.builder()
.appId(intent.appId())
.key(intent.key())
.selector(intent.selector())
.treatment(intent.treatment())
.links(links)
.ingressPoints(ImmutableSet.of(intent.ingressPoint()))
.egressPoints(intent.egressPoints())
.filteredIngressPoints(ImmutableSet.of(intent.filteredIngressPoint()))
.filteredEgressPoints(intent.filteredEgressPoints())
.priority(intent.priority())
.applyTreatmentOnEgress(true)
.constraints(intent.constraints())
.egressTreatments(intent.egressTreatments())
.build();
return Collections.singletonList(result);
......
......@@ -15,15 +15,15 @@
*/
package org.onosproject.net.intent.impl.compiler;
import com.google.common.collect.ImmutableSet;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.onlab.packet.VlanId;
import org.onosproject.TestApplicationId;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.ElementId;
import org.onosproject.net.Path;
import org.onosproject.net.device.DeviceServiceAdapter;
import org.onosproject.net.FilteredConnectPoint;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.intent.AbstractIntentTest;
......@@ -31,7 +31,6 @@ import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentTestsMocks;
import org.onosproject.net.intent.LinkCollectionIntent;
import org.onosproject.net.intent.MultiPointToSinglePointIntent;
import org.onosproject.net.topology.PathServiceAdapter;
import java.util.HashSet;
import java.util.List;
......@@ -43,7 +42,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.onosproject.net.NetTestTools.connectPoint;
import static org.onosproject.net.NetTestTools.createPath;
import static org.onosproject.net.intent.LinksHaveEntryWithSourceDestinationPairMatcher.linksHasPath;
/**
......@@ -57,47 +55,6 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes
private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
/**
* Mock path service for creating paths within the test.
*/
private static class MockPathService extends PathServiceAdapter {
final String[] pathHops;
/**
* Constructor that provides a set of hops to mock.
*
* @param pathHops path hops to mock
*/
MockPathService(String[] pathHops) {
this.pathHops = pathHops;
}
@Override
public Set<Path> getPaths(ElementId src, ElementId dst) {
Set<Path> result = new HashSet<>();
String[] allHops = new String[pathHops.length + 1];
allHops[0] = src.toString();
if (pathHops.length != 0) {
System.arraycopy(pathHops, 0, allHops, 1, pathHops.length);
}
result.add(createPath(allHops));
return result;
}
}
/**
* Mocks the device service so that a device appears available in the test.
*/
private static class MockDeviceService extends DeviceServiceAdapter {
@Override
public boolean isAvailable(DeviceId deviceId) {
return true;
}
}
/**
* Creates a MultiPointToSinglePoint intent for a group of ingress points
* and an egress point.
*
......@@ -123,6 +80,23 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes
}
/**
* Generate MultiPointToSinglePointIntent with filtered connection point.
*
* @param ingress filtered ingress points
* @param egress filtered egress point
* @return
*/
private MultiPointToSinglePointIntent makeFilteredConnectPointIntent(Set<FilteredConnectPoint> ingress,
FilteredConnectPoint egress) {
return MultiPointToSinglePointIntent.builder()
.appId(APPID)
.treatment(treatment)
.filteredIngressPoints(ingress)
.filteredEgressPoint(egress)
.build();
}
/**
* Creates a compiler for MultiPointToSinglePoint intents.
*
* @param hops hops to use while computing paths for this intent
......@@ -131,8 +105,8 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes
private MultiPointToSinglePointIntentCompiler makeCompiler(String[] hops) {
MultiPointToSinglePointIntentCompiler compiler =
new MultiPointToSinglePointIntentCompiler();
compiler.pathService = new MockPathService(hops);
compiler.deviceService = new MockDeviceService();
compiler.pathService = new IntentTestsMocks.Mp2MpMockPathService(hops);
compiler.deviceService = new IntentTestsMocks.MockDeviceService();
return compiler;
}
......@@ -148,8 +122,7 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes
MultiPointToSinglePointIntent intent = makeIntent(ingress, egress);
assertThat(intent, is(notNullValue()));
String[] hops = {"h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8",
egress};
String[] hops = {"h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8"};
MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops);
assertThat(compiler, is(notNullValue()));
......@@ -184,7 +157,7 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes
MultiPointToSinglePointIntent intent = makeIntent(ingress, egress);
assertThat(intent, is(notNullValue()));
final String[] hops = {"inner1", "inner2", egress};
final String[] hops = {"inner1", "inner2"};
MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops);
assertThat(compiler, is(notNullValue()));
......@@ -217,7 +190,7 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes
MultiPointToSinglePointIntent intent = makeIntent(ingress, egress);
assertThat(intent, is(notNullValue()));
final String[] hops = {"n1", egress};
final String[] hops = {"n1"};
MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops);
assertThat(compiler, is(notNullValue()));
......@@ -245,12 +218,12 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes
@Test
public void testSameDeviceCompilation() {
String[] ingress = {"i1", "i2"};
String egress = "i1";
String egress = "i3";
MultiPointToSinglePointIntent intent = makeIntent(ingress, egress);
assertThat(intent, is(notNullValue()));
final String[] hops = {"i1", "i2"};
final String[] hops = {};
MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops);
assertThat(compiler, is(notNullValue()));
......@@ -264,7 +237,48 @@ public class MultiPointToSinglePointIntentCompilerTest extends AbstractIntentTes
LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent;
assertThat(linkIntent.links(), hasSize(ingress.length));
assertThat(linkIntent.links(), linksHasPath("i2", "i1"));
assertThat(linkIntent.links(), linksHasPath("i1", "i3"));
assertThat(linkIntent.links(), linksHasPath("i2", "i3"));
}
}
/**
* Tests filtered ingress and egress.
*/
@Test
public void testFilteredConnectPointIntent() {
Set<FilteredConnectPoint> ingress = ImmutableSet.of(
new FilteredConnectPoint(connectPoint("of1", 1),
DefaultTrafficSelector.builder().matchVlanId(VlanId.vlanId("100")).build()),
new FilteredConnectPoint(connectPoint("of2", 1),
DefaultTrafficSelector.builder().matchVlanId(VlanId.vlanId("200")).build())
);
FilteredConnectPoint egress = new FilteredConnectPoint(connectPoint("of4", 1));
MultiPointToSinglePointIntent intent = makeFilteredConnectPointIntent(ingress, egress);
String[] hops = {"of3"};
MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops);
assertThat(compiler, is(notNullValue()));
List<Intent> result = compiler.compile(intent, null);
assertThat(result, is(notNullValue()));
assertThat(result, hasSize(1));
Intent resultIntent = result.get(0);
assertThat(resultIntent, instanceOf(LinkCollectionIntent.class));
if (resultIntent instanceof LinkCollectionIntent) {
LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent;
assertThat(linkIntent.links(), hasSize(3));
assertThat(linkIntent.links(), linksHasPath("of1", "of3"));
assertThat(linkIntent.links(), linksHasPath("of2", "of3"));
assertThat(linkIntent.links(), linksHasPath("of3", "of4"));
}
}
}
......