Yi Tseng

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

Change-Id: Ibe9062c904ad9a6c3ba001fe57be7cec49eb8a4d
Showing 18 changed files with 1636 additions and 758 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
......
......@@ -58,18 +58,18 @@ public final class IntentUtils {
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.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.filteredIngressPoints(), intent2.filteredIngressPoints()) &&
Objects.equals(intent1.filteredEgressPoint(), intent2.filteredEgressPoint()) &&
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.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,11 +63,10 @@ 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);
......@@ -82,9 +77,8 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
checkArgument(!ingressPoints.contains(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 set of ports on which ingress traffic should be connected to
* the egress port.
*
* @return set of ingress ports
*/
public Set<FilteredConnectPoint> filteredIngressPoints() {
return ingressPoints;
}
/**
* Returns the multiple selectors jointly with their connection points.
* @return multiple selectors
* Returns the port on which the traffic should egress.
*
* @return egress port
*/
public Map<ConnectPoint, TrafficSelector> ingressSelectors() {
return ingressSelectors;
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,11 +64,10 @@ 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);
......@@ -84,7 +78,6 @@ public final class SinglePointToMultiPointIntent extends ConnectivityIntent {
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();
}
......
......@@ -17,32 +17,39 @@
package org.onosproject.net.intent.impl.compiler;
import com.google.common.collect.SetMultimap;
import com.google.common.collect.Sets;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpPrefix;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.PortNumber;
import org.onosproject.net.FilteredConnectPoint;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.criteria.MplsCriterion;
import org.onosproject.net.flow.criteria.TunnelIdCriterion;
import org.onosproject.net.flow.criteria.VlanIdCriterion;
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.flow.instructions.L0ModificationInstruction;
import org.onosproject.net.flow.instructions.L1ModificationInstruction;
import org.onosproject.net.flow.instructions.L2ModificationInstruction;
import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsBosInstruction;
import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction;
import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnelIdInstruction;
import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction;
import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction;
import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction;
import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsBosInstruction;
import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnelIdInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpIPInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpOpInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpIPInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpOpInstruction;
import org.onosproject.net.flow.instructions.L4ModificationInstruction;
import org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction;
import org.onosproject.net.intent.IntentCompilationException;
......@@ -53,11 +60,19 @@ import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import static org.onosproject.net.flow.criteria.Criterion.Type.MPLS_LABEL;
import static org.onosproject.net.flow.criteria.Criterion.Type.TUNNEL_ID;
import static org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID;
/**
* Shared APIs and implementations for Link Collection compilers.
*/
public class LinkCollectionCompiler<T> {
private static final Set<Criterion.Type> TAG_CRITERION_TYPES =
Sets.immutableEnumSet(VLAN_VID, MPLS_LABEL, TUNNEL_ID);
/**
* Helper class to encapsulate treatment and selector.
*/
......@@ -107,13 +122,13 @@ public class LinkCollectionCompiler<T> {
for (ConnectPoint egressPoint : intent.egressPoints()) {
outputPorts.put(egressPoint.deviceId(), egressPoint.port());
}
}
/**
* Helper method to compute ingress and egress ports.
* Gets ingress and egress port number of specific device.
*
* @param intent the related intents
* @param intent the related
* @param deviceId device Id
* @param ingressPorts the ingress ports to compute
* @param egressPorts the egress ports to compute
*/
......@@ -156,11 +171,11 @@ public class LinkCollectionCompiler<T> {
* in the flow representation (Rule, Objective).
*
* @param intent the intent to compile
* @param inPort the input port
* @param inPort the input port of this device
* @param deviceId the current device
* @param outPorts the output ports
* @param ingressPorts the ingress ports
* @param egressPorts the egress ports
* @param outPorts the output ports of this device
* @param ingressPorts intent ingress ports of this device
* @param egressPorts intent egress ports of this device
* @return the forwarding instruction object which encapsulates treatment and selector
*/
protected ForwardingInstructions createForwardingInstructions(LinkCollectionIntent intent,
......@@ -170,119 +185,214 @@ public class LinkCollectionCompiler<T> {
Set<PortNumber> ingressPorts,
Set<PortNumber> egressPorts) {
TrafficTreatment.Builder defaultTreatmentBuilder = DefaultTrafficTreatment.builder();
outPorts.forEach(defaultTreatmentBuilder::setOutput);
TrafficTreatment outputOnlyTreatment = defaultTreatmentBuilder.build();
TrafficSelector.Builder selectorBuilder;
TrafficTreatment treatment;
TrafficTreatment intentTreatment;
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(intent.selector());
selectorBuilder.matchInPort(inPort);
if (!intent.applyTreatmentOnEgress()) {
TrafficTreatment.Builder ingressTreatmentBuilder = DefaultTrafficTreatment.builder(intent.treatment());
outPorts.forEach(ingressTreatmentBuilder::setOutput);
intentTreatment = ingressTreatmentBuilder.build();
if (ingressPorts.contains(inPort)) {
if (intent.ingressSelectors() != null && !intent.ingressSelectors().isEmpty()) {
/**
* We iterate on the ingress points looking for the connect point
* associated to inPort.
*/
Optional<ConnectPoint> connectPoint = intent.ingressPoints()
.stream()
.filter(ingressPoint -> ingressPoint.port().equals(inPort)
&& ingressPoint.deviceId().equals(deviceId))
.findFirst();
if (connectPoint.isPresent()) {
selectorBuilder = DefaultTrafficSelector
.builder(intent.ingressSelectors().get(connectPoint.get()));
// FIXME: currently, we assume this intent is compile from mp2sp intent
Optional<FilteredConnectPoint> filteredIngressPoint =
getFilteredConnectPointFromIntent(deviceId, inPort, intent);
Optional<FilteredConnectPoint> filteredEgressPoint =
intent.filteredEgressPoints().stream().findFirst();
if (filteredIngressPoint.isPresent()) {
// Ingress device
intent.treatment().allInstructions().stream()
.filter(inst -> inst.type() != Instruction.Type.NOACTION)
.forEach(treatmentBuilder::add);
if (filteredEgressPoint.isPresent()) {
// Apply selector from ingress point
filteredIngressPoint.get()
.trafficSelector()
.criteria()
.forEach(selectorBuilder::add);
TrafficTreatment forwardingTreatment =
forwardingTreatment(filteredIngressPoint.get(),
filteredEgressPoint.get());
forwardingTreatment.allInstructions().stream()
.filter(inst -> inst.type() != Instruction.Type.NOACTION)
.forEach(treatmentBuilder::add);
} else {
throw new IntentCompilationException("Looking for connect point associated to the selector." +
"inPort not in IngressPoints");
throw new IntentCompilationException("Can't find filtered connection point");
}
} else {
selectorBuilder = DefaultTrafficSelector.builder(intent.selector());
// Not ingress device, won't apply treatments.
// Use selector by treatment from intent.
updateBuilder(selectorBuilder, intent.treatment());
// Selector should be overridden by selector from connect point.
if (filteredEgressPoint.isPresent()) {
filteredEgressPoint.get()
.trafficSelector()
.criteria()
.forEach(selectorBuilder::add);
}
treatment = this.updateBuilder(ingressTreatmentBuilder, selectorBuilder.build()).build();
} else {
selectorBuilder = this.createSelectorFromFwdInstructions(
new ForwardingInstructions(intentTreatment, intent.selector())
);
treatment = outputOnlyTreatment;
}
outPorts.forEach(treatmentBuilder::setOutput);
} else {
if (outPorts.stream().allMatch(egressPorts::contains)) {
TrafficTreatment.Builder egressTreatmentBuilder = DefaultTrafficTreatment.builder();
if (intent.egressTreatments() != null && !intent.egressTreatments().isEmpty()) {
for (PortNumber outPort : outPorts) {
Optional<ConnectPoint> connectPoint = intent.egressPoints()
.stream()
.filter(egressPoint -> egressPoint.port().equals(outPort)
&& egressPoint.deviceId().equals(deviceId))
.findFirst();
if (connectPoint.isPresent()) {
TrafficTreatment egressTreatment = intent.egressTreatments().get(connectPoint.get());
this.addTreatment(egressTreatmentBuilder, egressTreatment);
egressTreatmentBuilder = this.updateBuilder(egressTreatmentBuilder, intent.selector());
egressTreatmentBuilder.setOutput(outPort);
// FIXME: currently, we assume this intent is compile from sp2mp intent
Optional<FilteredConnectPoint> filteredIngressPoint =
intent.filteredIngressPoints().stream().findFirst();
if (filteredIngressPoint.isPresent()) {
// Apply selector from ingress point
filteredIngressPoint.get()
.trafficSelector()
.criteria()
.forEach(selectorBuilder::add);
} else {
throw new IntentCompilationException("Looking for connect point associated to " +
"the treatment. outPort not in egressPoints");
throw new IntentCompilationException(
"Filtered connection point for ingress" +
"point does not exist");
}
for (PortNumber outPort : outPorts) {
Optional<FilteredConnectPoint> filteredEgressPoint =
getFilteredConnectPointFromIntent(deviceId, outPort, intent);
if (filteredEgressPoint.isPresent()) {
// Egress port, apply treatment + forwarding treatment
intent.treatment().allInstructions().stream()
.filter(inst -> inst.type() != Instruction.Type.NOACTION)
.forEach(treatmentBuilder::add);
TrafficTreatment forwardingTreatment =
forwardingTreatment(filteredIngressPoint.get(),
filteredEgressPoint.get());
forwardingTreatment.allInstructions().stream()
.filter(inst -> inst.type() != Instruction.Type.NOACTION)
.forEach(treatmentBuilder::add);
}
} else {
egressTreatmentBuilder = this
.updateBuilder(DefaultTrafficTreatment.builder(intent.treatment()), intent.selector());
outPorts.forEach(egressTreatmentBuilder::setOutput);
}
selectorBuilder = DefaultTrafficSelector.builder(intent.selector());
treatment = egressTreatmentBuilder.build();
} else {
selectorBuilder = DefaultTrafficSelector.builder(intent.selector());
treatment = outputOnlyTreatment;
treatmentBuilder.setOutput(outPort);
}
}
TrafficSelector selector = selectorBuilder.matchInPort(inPort).build();
return new ForwardingInstructions(treatment, selector);
return new ForwardingInstructions(treatmentBuilder.build(), selectorBuilder.build());
}
/**
* Update a builder using a treatment.
* @param builder the builder to update
* @param treatment the treatment to add
* @return the new builder
* Get FilteredConnectPoint from LinkCollectionIntent.
* @param deviceId device Id for connect point
* @param portNumber port number
* @param intent source intent
* @return filtered connetion point
*/
private TrafficTreatment.Builder addTreatment(TrafficTreatment.Builder builder, TrafficTreatment treatment) {
builder.deferred();
for (Instruction instruction : treatment.deferred()) {
builder.add(instruction);
}
builder.immediate();
for (Instruction instruction : treatment.immediate()) {
builder.add(instruction);
private Optional<FilteredConnectPoint> getFilteredConnectPointFromIntent(DeviceId deviceId,
PortNumber portNumber,
LinkCollectionIntent intent) {
Set<FilteredConnectPoint> filteredConnectPoints =
Sets.union(intent.filteredIngressPoints(), intent.filteredEgressPoints());
return filteredConnectPoints.stream()
.filter(port -> port.connectPoint().deviceId().equals(deviceId))
.filter(port -> port.connectPoint().port().equals(portNumber))
.findFirst();
}
return builder;
/**
* Get tag criterion from selector.
* The criterion should be one of type in tagCriterionTypes.
*
* @param selector selector
* @return Criterion that matched, if there is no tag criterion, return null
*/
private Criterion getTagCriterion(TrafficSelector selector) {
return selector.criteria().stream()
.filter(criterion -> TAG_CRITERION_TYPES.contains(criterion.type()))
.findFirst()
.orElse(Criteria.dummy());
}
/**
* Update the original builder with the necessary operations
* to have a correct forwarding given an ingress selector.
* TODO
* This means that if the ingress selectors match on different vlanids and
* the egress treatment rewrite the vlanid the forwarding works
* but if we need to push for example an mpls label at the egress
* we need to implement properly this method.
* Compares tag type between ingress and egress point and generate
* treatment for egress point of intent.
*
* @param treatmentBuilder the builder to modify
* @param intentSelector the intent selector to use as input
* @return the new treatment created
* @param ingress ingress point for the intent
* @param egress egress point for the intent
* @return Builder of TrafficTreatment
*/
private TrafficTreatment forwardingTreatment(FilteredConnectPoint ingress,
FilteredConnectPoint egress) {
if (ingress.trafficSelector().equals(egress.trafficSelector())) {
return DefaultTrafficTreatment.emptyTreatment();
}
TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
/*
* "null" means there is no tag for the port
* Tag criterion will be null if port is normal connection point
*/
Criterion ingressTagCriterion = getTagCriterion(ingress.trafficSelector());
Criterion egressTagCriterion = getTagCriterion(egress.trafficSelector());
if (ingressTagCriterion.type() != egressTagCriterion.type()) {
/*
* Tag type of ingress port and egress port are different.
* Need to remove tag from ingress, then add new tag for egress.
* Remove nothing if ingress port use VXLAN or there is no tag
* on ingress port.
*/
switch (ingressTagCriterion.type()) {
case VLAN_VID:
builder.popVlan();
break;
case MPLS_LABEL:
builder.popMpls();
break;
default:
break;
}
/*
* Push new tag for egress port.
*/
private TrafficTreatment.Builder updateBuilder(TrafficTreatment.Builder treatmentBuilder,
TrafficSelector intentSelector) {
return treatmentBuilder;
switch (egressTagCriterion.type()) {
case VLAN_VID:
builder.pushVlan();
break;
case MPLS_LABEL:
builder.pushMpls();
break;
default:
break;
}
}
switch (egressTagCriterion.type()) {
case VLAN_VID:
VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) egressTagCriterion;
builder.setVlanId(vlanIdCriterion.vlanId());
break;
case MPLS_LABEL:
MplsCriterion mplsCriterion = (MplsCriterion) egressTagCriterion;
builder.setMpls(mplsCriterion.label());
break;
case TUNNEL_ID:
TunnelIdCriterion tunnelIdCriterion = (TunnelIdCriterion) egressTagCriterion;
builder.setTunnelId(tunnelIdCriterion.tunnelId());
break;
default:
break;
}
return builder.build();
}
/**
......@@ -467,30 +577,29 @@ public class LinkCollectionCompiler<T> {
}
/**
* Computes the new traffic selector using the
* forwarding instructions.
* Update selector builder by using treatment.
*
* @param fwInstructions it encapsulates the instructions to compute the new selector
* @return the traffic selector builder
* @param builder builder to update
* @param treatment traffic treatment
*/
private TrafficSelector.Builder createSelectorFromFwdInstructions(ForwardingInstructions fwInstructions) {
TrafficSelector.Builder defaultSelectorBuilder = DefaultTrafficSelector.builder(fwInstructions.selector());
fwInstructions.treatment().allInstructions().forEach(instruction -> {
private void updateBuilder(TrafficSelector.Builder builder, TrafficTreatment treatment) {
treatment.allInstructions().forEach(instruction -> {
switch (instruction.type()) {
case L0MODIFICATION:
updateBuilder(defaultSelectorBuilder, (L0ModificationInstruction) instruction);
updateBuilder(builder, (L0ModificationInstruction) instruction);
break;
case L1MODIFICATION:
updateBuilder(defaultSelectorBuilder, (L1ModificationInstruction) instruction);
updateBuilder(builder, (L1ModificationInstruction) instruction);
break;
case L2MODIFICATION:
updateBuilder(defaultSelectorBuilder, (L2ModificationInstruction) instruction);
updateBuilder(builder, (L2ModificationInstruction) instruction);
break;
case L3MODIFICATION:
updateBuilder(defaultSelectorBuilder, (L3ModificationInstruction) instruction);
updateBuilder(builder, (L3ModificationInstruction) instruction);
break;
case L4MODIFICATION:
updateBuilder(defaultSelectorBuilder, (L4ModificationInstruction) instruction);
updateBuilder(builder, (L4ModificationInstruction) instruction);
break;
case NOACTION:
case OUTPUT:
......@@ -506,7 +615,7 @@ public class LinkCollectionCompiler<T> {
throw new IntentCompilationException("Unknown instruction type");
}
});
return defaultSelectorBuilder;
}
}
......
......@@ -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);
......
......@@ -16,10 +16,11 @@
package org.onosproject.net.intent.impl.compiler;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.TestApplicationId;
import org.onosproject.cfg.ComponentConfigAdapter;
......@@ -28,14 +29,15 @@ import org.onosproject.core.CoreService;
import org.onosproject.core.IdGenerator;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.DeviceId;
import org.onosproject.net.FilteredConnectPoint;
import org.onosproject.net.Link;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.criteria.Criteria;
import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.intent.FlowRuleIntent;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentExtensionService;
......@@ -45,20 +47,19 @@ import org.onosproject.net.intent.MockIdGenerator;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.onosproject.net.Link.Type.DIRECT;
import static org.onosproject.net.NetTestTools.APP_ID;
import static org.onosproject.net.NetTestTools.PID;
import static org.onosproject.net.NetTestTools.connectPoint;
import static org.onosproject.net.NetTestTools.*;
public class LinkCollectionIntentCompilerTest {
......@@ -67,87 +68,66 @@ public class LinkCollectionIntentCompilerTest {
private final ConnectPoint d1p1 = connectPoint("s1", 1);
private final ConnectPoint d2p0 = connectPoint("s2", 0);
private final ConnectPoint d2p1 = connectPoint("s2", 1);
private final ConnectPoint d2p2 = connectPoint("s2", 2);
private final ConnectPoint d2p3 = connectPoint("s2", 3);
private final ConnectPoint d3p1 = connectPoint("s3", 1);
private final ConnectPoint d3p2 = connectPoint("s3", 9);
private final ConnectPoint d3p0 = connectPoint("s3", 10);
private final ConnectPoint d1p0 = connectPoint("s1", 10);
private final ConnectPoint d4p1 = connectPoint("s4", 1);
private final ConnectPoint d4p0 = connectPoint("s4", 10);
private final DeviceId of1Id = DeviceId.deviceId("of:of1");
private final DeviceId of2Id = DeviceId.deviceId("of:of2");
private final DeviceId of3Id = DeviceId.deviceId("of:of3");
private final DeviceId of4Id = DeviceId.deviceId("of:of4");
private final ConnectPoint of1p1 = connectPoint("of1", 1);
private final ConnectPoint of1p2 = connectPoint("of1", 2);
private final ConnectPoint of2p1 = connectPoint("of2", 1);
private final ConnectPoint of2p2 = connectPoint("of2", 2);
private final ConnectPoint of2p3 = connectPoint("of2", 3);
private final ConnectPoint of3p1 = connectPoint("of3", 1);
private final ConnectPoint of3p2 = connectPoint("of3", 2);
private final ConnectPoint of4p1 = connectPoint("of4", 1);
private final ConnectPoint of4p2 = connectPoint("of4", 2);
private final Set<Link> links = ImmutableSet.of(
DefaultLink.builder().providerId(PID).src(d1p1).dst(d2p0).type(DIRECT).build(),
DefaultLink.builder().providerId(PID).src(d2p1).dst(d3p1).type(DIRECT).build(),
DefaultLink.builder().providerId(PID).src(d1p1).dst(d3p1).type(DIRECT).build());
private final Set<Link> linksMultiple = ImmutableSet.of(
DefaultLink.builder().providerId(PID).src(d3p1).dst(d2p0).type(DIRECT).build());
private final Set<Link> linksMultiple2 = ImmutableSet.of(
DefaultLink.builder().providerId(PID).src(d2p0).dst(d1p1).type(DIRECT).build(),
DefaultLink.builder().providerId(PID).src(d2p1).dst(d3p1).type(DIRECT).build(),
DefaultLink.builder().providerId(PID).src(d2p2).dst(d4p1).type(DIRECT).build());
private final TrafficSelector selector = DefaultTrafficSelector.builder().build();
private final TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
private final VlanId ingressVlan1 = VlanId.vlanId("10");
private final TrafficSelector selectorVlan1 = DefaultTrafficSelector
.builder()
.matchVlanId(ingressVlan1)
.build();
private final VlanId ingressVlan2 = VlanId.vlanId("20");
private final TrafficSelector selectorVlan2 = DefaultTrafficSelector
.builder()
.matchVlanId(ingressVlan2)
.build();
private final VlanId egressVlan = VlanId.vlanId("666");
private final TrafficTreatment vlanTreatment = DefaultTrafficTreatment
.builder()
.setVlanId(egressVlan)
private final TrafficSelector vlan100Selector = DefaultTrafficSelector.builder()
.matchVlanId(VlanId.vlanId("100"))
.build();
private final VlanId ingressVlan = VlanId.vlanId("10");
private final TrafficSelector vlanSelector = DefaultTrafficSelector
.builder()
.matchVlanId(ingressVlan)
private final TrafficSelector vlan200Selector = DefaultTrafficSelector.builder()
.matchVlanId(VlanId.vlanId("200"))
.build();
private final VlanId egressVlan1 = VlanId.vlanId("20");
private final TrafficTreatment vlanTreatment1 = DefaultTrafficTreatment
.builder()
.setVlanId(egressVlan1)
private final TrafficSelector ipPrefixSelector = DefaultTrafficSelector.builder()
.matchIPDst(IpPrefix.valueOf("192.168.100.0/24"))
.build();
private final VlanId egressVlan2 = VlanId.vlanId("666");
private final TrafficTreatment vlanTreatment2 = DefaultTrafficTreatment
.builder()
.setVlanId(egressVlan2)
private final TrafficTreatment ethDstTreatment = DefaultTrafficTreatment.builder()
.setEthDst(MacAddress.valueOf("C0:FF:EE:C0:FF:EE"))
.build();
private final VlanId egressVlan3 = VlanId.vlanId("69");
private final TrafficTreatment vlanTreatment3 = DefaultTrafficTreatment
.builder()
.setVlanId(egressVlan3)
.build();
private CoreService coreService;
private IntentExtensionService intentExtensionService;
private IntentConfigurableRegistrator registrator;
private IdGenerator idGenerator = new MockIdGenerator();
private LinkCollectionIntent intent;
private LinkCollectionIntent intentMultipleSelectors;
private LinkCollectionIntent intentMultipleTreatments;
private LinkCollectionIntent intentMultipleTreatments2;
private LinkCollectionIntentCompiler sut;
private List<FlowRule> getFlowRulesByDevice(DeviceId deviceId, Collection<FlowRule> flowRules) {
return flowRules.stream()
.filter(fr -> fr.deviceId().equals(deviceId))
.collect(Collectors.toList());
}
@Before
public void setUp() {
sut = new LinkCollectionIntentCompiler();
......@@ -166,32 +146,6 @@ private final VlanId ingressVlan = VlanId.vlanId("10");
.ingressPoints(ImmutableSet.of(d1p1))
.egressPoints(ImmutableSet.of(d3p1))
.build();
intentMultipleSelectors = LinkCollectionIntent.builder()
.appId(APP_ID)
.treatment(vlanTreatment)
.links(linksMultiple)
.ingressPoints(ImmutableSet.of(d3p0, d3p2))
.egressPoints(ImmutableSet.of(d2p1))
.ingressSelectors(this.createIngressSelectors())
.build();
intentMultipleTreatments = LinkCollectionIntent.builder()
.appId(APP_ID)
.selector(vlanSelector)
.links(linksMultiple)
.ingressPoints(ImmutableSet.of(d3p0))
.egressPoints(ImmutableSet.of(d2p1, d2p2))
.egressTreatments(this.createEgressTreatments())
.applyTreatmentOnEgress(true)
.build();
intentMultipleTreatments2 = LinkCollectionIntent.builder()
.appId(APP_ID)
.selector(vlanSelector)
.links(linksMultiple2)
.ingressPoints(ImmutableSet.of(d2p3))
.egressPoints(ImmutableSet.of(d1p0, d3p0, d4p0))
.egressTreatments(this.createEgressTreatments2())
.applyTreatmentOnEgress(true)
.build();
intentExtensionService = createMock(IntentExtensionService.class);
intentExtensionService.registerCompiler(LinkCollectionIntent.class, sut);
......@@ -205,10 +159,13 @@ private final VlanId ingressVlan = VlanId.vlanId("10");
sut.registrator = registrator;
replay(coreService, intentExtensionService);
}
@After
public void tearDown() {
Intent.unbindIdGenerator(idGenerator);
}
......@@ -262,299 +219,486 @@ private final VlanId ingressVlan = VlanId.vlanId("10");
sut.deactivate();
}
@Test
public void testCompileMultipleSelectors() {
/**
* Single point to multi point case.
* -1 of1 2-1 of2 2--1 of3 2-
* 3
* `-1 of4 2-
*/
@Test
public void testFilteredConnectPoint1() {
sut.activate();
Set<Link> testLinks = ImmutableSet.of(
DefaultLink.builder().providerId(PID).src(of1p2).dst(of2p1).type(DIRECT).build(),
DefaultLink.builder().providerId(PID).src(of2p2).dst(of3p1).type(DIRECT).build(),
DefaultLink.builder().providerId(PID).src(of2p3).dst(of4p1).type(DIRECT).build()
);
TrafficSelector expectOf1Selector = DefaultTrafficSelector.builder(vlan100Selector)
.matchInPort(PortNumber.portNumber(1))
.build();
List<Intent> compiled = sut.compile(intentMultipleSelectors, Collections.emptyList());
assertThat(compiled, hasSize(1));
TrafficTreatment expectOf1Treatment = DefaultTrafficTreatment.builder()
.setOutput(PortNumber.portNumber(2))
.build();
TrafficSelector expectOf2Selector = DefaultTrafficSelector.builder(vlan100Selector)
.matchInPort(PortNumber.portNumber(1))
.build();
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize((linksMultiple.size()) + intentMultipleSelectors.ingressPoints().size()));
TrafficTreatment expectOf2Treatment = DefaultTrafficTreatment.builder()
.setOutput(PortNumber.portNumber(2))
.setOutput(PortNumber.portNumber(3))
.build();
Set<FlowRule> d3Rules = rules
.parallelStream()
.filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
.collect(Collectors.toSet());
assertThat(d3Rules, hasSize(intentMultipleSelectors.ingressPoints().size()));
TrafficSelector expectOf3Selector = DefaultTrafficSelector.builder(vlan100Selector)
.matchInPort(PortNumber.portNumber(1))
.build();
FlowRule rule1 = rules.stream()
.filter(rule -> rule.deviceId().equals(d3p0.deviceId())
&&
rule.selector().getCriterion(Criterion.Type.IN_PORT).equals(Criteria.matchInPort(d3p0.port())))
.findFirst()
.get();
assertThat(rule1.selector(), is(
DefaultTrafficSelector
.builder(intentMultipleSelectors.selector())
.matchInPort(d3p0.port())
.matchVlanId(ingressVlan1)
.build()
));
assertThat(rule1.treatment(), is(
DefaultTrafficTreatment
.builder(intentMultipleSelectors.treatment())
.setOutput(d3p1.port())
.build()
));
assertThat(rule1.priority(), is(intentMultipleSelectors.priority()));
TrafficTreatment expectOf3Treatment = DefaultTrafficTreatment.builder()
.setOutput(PortNumber.portNumber(2))
.build();
FlowRule rule2 = rules.stream()
.filter(rule -> rule.deviceId().equals(d3p0.deviceId())
&&
rule.selector().getCriterion(Criterion.Type.IN_PORT).equals(Criteria.matchInPort(d3p2.port())))
.findFirst()
.get();
assertThat(rule2.selector(), is(
DefaultTrafficSelector
.builder(intentMultipleSelectors.selector())
.matchInPort(d3p2.port())
.matchVlanId(ingressVlan2)
.build()
));
assertThat(rule2.treatment(), is(
DefaultTrafficTreatment
.builder(intentMultipleSelectors.treatment())
.setOutput(d3p1.port())
.build()
));
assertThat(rule2.priority(), is(intentMultipleSelectors.priority()));
TrafficSelector expectOf4Selector = DefaultTrafficSelector.builder(vlan100Selector)
.matchInPort(PortNumber.portNumber(1))
.build();
Set<FlowRule> d2Rules = rules
.parallelStream()
.filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
.collect(Collectors.toSet());
assertThat(d2Rules, hasSize(intentMultipleSelectors.egressPoints().size()));
TrafficTreatment expectOf4Treatment = DefaultTrafficTreatment.builder()
.setVlanId(VlanId.vlanId("200"))
.setOutput(PortNumber.portNumber(2))
.build();
// We do not need in_port filter
FlowRule rule3 = rules.stream()
.filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
.findFirst()
.get();
assertThat(rule3.selector(), is(
DefaultTrafficSelector
.builder(intentMultipleSelectors.selector())
.matchInPort(d2p0.port())
.matchVlanId(egressVlan)
.build()
));
assertThat(rule3.treatment(), is(
DefaultTrafficTreatment
.builder()
.setOutput(d2p1.port())
.build()
));
assertThat(rule3.priority(), is(intentMultipleSelectors.priority()));
Set<FilteredConnectPoint> ingress = ImmutableSet.of(
new FilteredConnectPoint(of1p1, vlan100Selector)
);
Set<FilteredConnectPoint> egress = ImmutableSet.of(
new FilteredConnectPoint(of3p2, vlan100Selector),
new FilteredConnectPoint(of4p2, vlan200Selector)
);
intent = LinkCollectionIntent.builder()
.appId(APP_ID)
.filteredIngressPoints(ingress)
.filteredEgressPoints(egress)
.treatment(treatment)
.applyTreatmentOnEgress(true)
.links(testLinks)
.build();
assertThat(sut, is(notNullValue()));
List<Intent> result = sut.compile(intent, Collections.emptyList());
assertThat(result, is(notNullValue()));
assertThat(result, hasSize(1));
Intent resultIntent = result.get(0);
assertThat(resultIntent, instanceOf(FlowRuleIntent.class));
if (resultIntent instanceof FlowRuleIntent) {
FlowRuleIntent frIntent = (FlowRuleIntent) resultIntent;
assertThat(frIntent.flowRules(), hasSize(4));
List<FlowRule> deviceFlowRules;
FlowRule flowRule;
// Of1
deviceFlowRules = getFlowRulesByDevice(of1Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(1));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf1Selector));
assertThat(flowRule.treatment(), is(expectOf1Treatment));
// Of2
deviceFlowRules = getFlowRulesByDevice(of2Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(1));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf2Selector));
assertThat(flowRule.treatment(), is(expectOf2Treatment));
// Of3
deviceFlowRules = getFlowRulesByDevice(of3Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(1));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf3Selector));
assertThat(flowRule.treatment(), is(expectOf3Treatment));
// Of4
deviceFlowRules = getFlowRulesByDevice(of4Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(1));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf4Selector));
assertThat(flowRule.treatment(), is(expectOf4Treatment));
}
sut.deactivate();
}
/**
* Multi point to single point intent with filtered connect point.
*
* -1 of1 2-1 of2 2-1 of4 2-
* 3
* -1 of3 2---/
*/
@Test
public void testCompileMultipleTreatments() {
public void testFilteredConnectPoint2() {
sut.activate();
Set<Link> testlinks = ImmutableSet.of(
DefaultLink.builder().providerId(PID).src(of1p2).dst(of2p1).type(DIRECT).build(),
DefaultLink.builder().providerId(PID).src(of3p2).dst(of2p3).type(DIRECT).build(),
DefaultLink.builder().providerId(PID).src(of2p2).dst(of4p1).type(DIRECT).build()
);
Set<FilteredConnectPoint> ingress = ImmutableSet.of(
new FilteredConnectPoint(of1p1, vlan100Selector),
new FilteredConnectPoint(of3p1, vlan100Selector)
);
Set<FilteredConnectPoint> egress = ImmutableSet.of(
new FilteredConnectPoint(of4p2, vlan200Selector)
);
TrafficSelector expectOf1Selector = DefaultTrafficSelector.builder(vlan100Selector)
.matchInPort(PortNumber.portNumber(1))
.build();
List<Intent> compiled = sut.compile(intentMultipleTreatments, Collections.emptyList());
assertThat(compiled, hasSize(1));
TrafficTreatment expectOf1Treatment = DefaultTrafficTreatment.builder()
.setVlanId(VlanId.vlanId("200"))
.setOutput(PortNumber.portNumber(2))
.build();
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(2));
TrafficSelector expectOf2Selector1 = DefaultTrafficSelector.builder(vlan200Selector)
.matchInPort(PortNumber.portNumber(1))
.build();
Set<FlowRule> d3Rules = rules
.parallelStream()
.filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
.collect(Collectors.toSet());
assertThat(d3Rules, hasSize(intentMultipleTreatments.ingressPoints().size()));
TrafficSelector expectOf2Selector2 = DefaultTrafficSelector.builder(vlan200Selector)
.matchInPort(PortNumber.portNumber(3))
.build();
FlowRule rule1 = rules.stream()
.filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
.findFirst()
.get();
assertThat(rule1.selector(), is(
DefaultTrafficSelector
.builder(intentMultipleTreatments.selector())
.matchInPort(d3p0.port())
.matchVlanId(ingressVlan)
.build()
));
assertThat(rule1.treatment(), is(
DefaultTrafficTreatment
.builder(intentMultipleTreatments.treatment())
.setOutput(d3p1.port())
.build()
));
assertThat(rule1.priority(), is(intentMultipleTreatments.priority()));
TrafficTreatment expectOf2Treatment = DefaultTrafficTreatment.builder()
.setOutput(PortNumber.portNumber(2))
.build();
Set<FlowRule> d2Rules = rules
.parallelStream()
.filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
.collect(Collectors.toSet());
assertThat(d2Rules, hasSize(1));
TrafficSelector expectOf3Selector = DefaultTrafficSelector.builder(vlan100Selector)
.matchInPort(PortNumber.portNumber(1))
.build();
FlowRule rule2 = rules.stream()
.filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
.findFirst()
.get();
assertThat(rule2.selector(), is(
DefaultTrafficSelector
.builder(intentMultipleTreatments.selector())
.matchInPort(d2p0.port())
.matchVlanId(ingressVlan)
.build()
));
assertThat(rule2.treatment(), is(
DefaultTrafficTreatment
.builder(intentMultipleTreatments.treatment())
.setVlanId(egressVlan1)
.setOutput(d2p1.port())
.setVlanId(egressVlan2)
.setOutput(d2p2.port())
.build()
));
assertThat(rule2.priority(), is(intentMultipleTreatments.priority()));
TrafficTreatment expectOf3Treatment = DefaultTrafficTreatment.builder()
.setVlanId(VlanId.vlanId("200"))
.setOutput(PortNumber.portNumber(2))
.build();
TrafficSelector expectOf4Selector = DefaultTrafficSelector.builder(vlan100Selector)
.matchInPort(PortNumber.portNumber(1))
.matchVlanId(VlanId.vlanId("200"))
.build();
TrafficTreatment expectOf4Treatment = DefaultTrafficTreatment.builder()
.setOutput(PortNumber.portNumber(2))
.build();
intent = LinkCollectionIntent.builder()
.appId(APP_ID)
.filteredIngressPoints(ingress)
.filteredEgressPoints(egress)
.treatment(treatment)
.links(testlinks)
.build();
List<Intent> result = sut.compile(intent, Collections.emptyList());
assertThat(result, is(notNullValue()));
assertThat(result, hasSize(1));
Intent resultIntent = result.get(0);
assertThat(resultIntent, instanceOf(FlowRuleIntent.class));
if (resultIntent instanceof FlowRuleIntent) {
FlowRuleIntent frIntent = (FlowRuleIntent) resultIntent;
assertThat(frIntent.flowRules(), hasSize(5));
List<FlowRule> deviceFlowRules;
FlowRule flowRule;
// Of1
deviceFlowRules = getFlowRulesByDevice(of1Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(1));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf1Selector));
assertThat(flowRule.treatment(), is(expectOf1Treatment));
// Of2 (has 2 flows)
deviceFlowRules = getFlowRulesByDevice(of2Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(2));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf2Selector1));
assertThat(flowRule.treatment(), is(expectOf2Treatment));
flowRule = deviceFlowRules.get(1);
assertThat(flowRule.selector(), is(expectOf2Selector2));
assertThat(flowRule.treatment(), is(expectOf2Treatment));
// Of3
deviceFlowRules = getFlowRulesByDevice(of3Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(1));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf3Selector));
assertThat(flowRule.treatment(), is(expectOf3Treatment));
// Of4
deviceFlowRules = getFlowRulesByDevice(of4Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(1));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf4Selector));
assertThat(flowRule.treatment(), is(expectOf4Treatment));
}
sut.deactivate();
}
/**
* Single point to multi point without filtered connect point case.
* -1 of1 2-1 of2 2--1 of3 2-
* 3
* `-1 of4 2-
*/
@Test
public void testCompileMultipleTreatments2() {
public void nonTrivialTranslation1() {
sut.activate();
Set<Link> testLinks = ImmutableSet.of(
DefaultLink.builder().providerId(PID).src(of1p2).dst(of2p1).type(DIRECT).build(),
DefaultLink.builder().providerId(PID).src(of2p2).dst(of3p1).type(DIRECT).build(),
DefaultLink.builder().providerId(PID).src(of2p3).dst(of4p1).type(DIRECT).build()
);
TrafficSelector expectOf1Selector = DefaultTrafficSelector.builder(ipPrefixSelector)
.matchInPort(PortNumber.portNumber(1))
.build();
List<Intent> compiled = sut.compile(intentMultipleTreatments2, Collections.emptyList());
assertThat(compiled, hasSize(1));
TrafficTreatment expectOf1Treatment = DefaultTrafficTreatment.builder()
.setOutput(PortNumber.portNumber(2))
.build();
TrafficSelector expectOf2Selector = DefaultTrafficSelector.builder(ipPrefixSelector)
.matchInPort(PortNumber.portNumber(1))
.build();
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(4));
TrafficTreatment expectOf2Treatment = DefaultTrafficTreatment.builder()
.setOutput(PortNumber.portNumber(2))
.setOutput(PortNumber.portNumber(3))
.build();
TrafficSelector expectOf3Selector = DefaultTrafficSelector.builder(ipPrefixSelector)
.matchInPort(PortNumber.portNumber(1))
.build();
Set<FlowRule> d2Rules = rules
.parallelStream()
.filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
.collect(Collectors.toSet());
assertThat(d2Rules, hasSize(1));
TrafficTreatment expectOf3Treatment = DefaultTrafficTreatment.builder(ethDstTreatment)
.setOutput(PortNumber.portNumber(2))
.build();
TrafficSelector expectOf4Selector = DefaultTrafficSelector.builder(ipPrefixSelector)
.matchInPort(PortNumber.portNumber(1))
.build();
FlowRule rule1 = rules.stream()
.filter(rule -> rule.deviceId().equals(d2p0.deviceId()))
.findFirst()
.get();
assertThat(rule1.selector(), is(
DefaultTrafficSelector
.builder(intentMultipleTreatments.selector())
.matchInPort(d2p3.port())
.matchVlanId(ingressVlan)
.build()
));
assertThat(rule1.treatment(), is(
DefaultTrafficTreatment
.builder(intentMultipleTreatments.treatment())
.setOutput(d2p0.port())
.setOutput(d2p1.port())
.setOutput(d2p2.port())
.build()
));
assertThat(rule1.priority(), is(intentMultipleTreatments.priority()));
TrafficTreatment expectOf4Treatment = DefaultTrafficTreatment.builder(ethDstTreatment)
.setOutput(PortNumber.portNumber(2))
.build();
Set<FlowRule> d1Rules = rules
.parallelStream()
.filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
.collect(Collectors.toSet());
assertThat(d1Rules, hasSize(1));
FlowRule rule2 = rules.stream()
.filter(rule -> rule.deviceId().equals(d1p0.deviceId()))
.findFirst()
.get();
assertThat(rule2.selector(), is(
DefaultTrafficSelector
.builder(intentMultipleTreatments2.selector())
.matchInPort(d1p1.port())
.matchVlanId(ingressVlan)
.build()
));
assertThat(rule2.treatment(), is(
DefaultTrafficTreatment
.builder(intentMultipleTreatments2.treatment())
.setVlanId(egressVlan1)
.setOutput(d1p0.port())
.build()
));
assertThat(rule2.priority(), is(intentMultipleTreatments.priority()));
Set<FlowRule> d3Rules = rules
.parallelStream()
.filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
.collect(Collectors.toSet());
assertThat(d3Rules, hasSize(1));
Set<ConnectPoint> ingress = ImmutableSet.of(
of1p1
);
FlowRule rule3 = rules.stream()
.filter(rule -> rule.deviceId().equals(d3p0.deviceId()))
.findFirst()
.get();
assertThat(rule3.selector(), is(
DefaultTrafficSelector
.builder(intentMultipleTreatments2.selector())
.matchInPort(d3p1.port())
.matchVlanId(ingressVlan)
.build()
));
assertThat(rule3.treatment(), is(
DefaultTrafficTreatment
.builder(intentMultipleTreatments2.treatment())
.setVlanId(egressVlan2)
.setOutput(d3p0.port())
.build()
));
assertThat(rule3.priority(), is(intentMultipleTreatments.priority()));
Set<ConnectPoint> egress = ImmutableSet.of(
of3p2,
of4p2
);
Set<FlowRule> d4Rules = rules
.parallelStream()
.filter(rule -> rule.deviceId().equals(d4p0.deviceId()))
.collect(Collectors.toSet());
assertThat(d4Rules, hasSize(1));
intent = LinkCollectionIntent.builder()
.appId(APP_ID)
.selector(ipPrefixSelector)
.treatment(ethDstTreatment)
.ingressPoints(ingress)
.egressPoints(egress)
.applyTreatmentOnEgress(true)
.links(testLinks)
.build();
FlowRule rule4 = rules.stream()
.filter(rule -> rule.deviceId().equals(d4p0.deviceId()))
.findFirst()
.get();
assertThat(rule4.selector(), is(
DefaultTrafficSelector
.builder(intentMultipleTreatments2.selector())
.matchInPort(d4p1.port())
.matchVlanId(ingressVlan)
.build()
));
assertThat(rule4.treatment(), is(
DefaultTrafficTreatment
.builder(intentMultipleTreatments2.treatment())
.setVlanId(egressVlan3)
.setOutput(d4p0.port())
.build()
));
assertThat(rule4.priority(), is(intentMultipleTreatments.priority()));
assertThat(sut, is(notNullValue()));
}
List<Intent> result = sut.compile(intent, Collections.emptyList());
public Map<ConnectPoint, TrafficTreatment> createEgressTreatments() {
Map<ConnectPoint, TrafficTreatment> mapToReturn = Maps.newHashMap();
mapToReturn.put(d2p1, vlanTreatment1);
mapToReturn.put(d2p2, vlanTreatment2);
return mapToReturn;
}
assertThat(result, is(notNullValue()));
assertThat(result, hasSize(1));
Intent resultIntent = result.get(0);
assertThat(resultIntent, instanceOf(FlowRuleIntent.class));
if (resultIntent instanceof FlowRuleIntent) {
FlowRuleIntent frIntent = (FlowRuleIntent) resultIntent;
assertThat(frIntent.flowRules(), hasSize(4));
List<FlowRule> deviceFlowRules;
FlowRule flowRule;
// Of1
deviceFlowRules = getFlowRulesByDevice(of1Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(1));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf1Selector));
assertThat(flowRule.treatment(), is(expectOf1Treatment));
// Of2
deviceFlowRules = getFlowRulesByDevice(of2Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(1));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf2Selector));
assertThat(flowRule.treatment(), is(expectOf2Treatment));
public Map<ConnectPoint, TrafficTreatment> createEgressTreatments2() {
Map<ConnectPoint, TrafficTreatment> mapToReturn = Maps.newHashMap();
mapToReturn.put(d1p0, vlanTreatment1);
mapToReturn.put(d3p0, vlanTreatment2);
mapToReturn.put(d4p0, vlanTreatment3);
return mapToReturn;
// Of3
deviceFlowRules = getFlowRulesByDevice(of3Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(1));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf3Selector));
assertThat(flowRule.treatment(), is(expectOf3Treatment));
// Of4
deviceFlowRules = getFlowRulesByDevice(of4Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(1));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf4Selector));
assertThat(flowRule.treatment(), is(expectOf4Treatment));
}
sut.deactivate();
}
public Map<ConnectPoint, TrafficSelector> createIngressSelectors() {
Map<ConnectPoint, TrafficSelector> mapToReturn = Maps.newHashMap();
mapToReturn.put(d3p0, selectorVlan1);
mapToReturn.put(d3p2, selectorVlan2);
return mapToReturn;
/**
* Multi point to single point intent without filtered connect point.
*
* -1 of1 2-1 of2 2-1 of4 2-
* 3
* -1 of3 2---/
*/
@Test
public void nonTrivialTranslation2() {
sut.activate();
Set<Link> testlinks = ImmutableSet.of(
DefaultLink.builder().providerId(PID).src(of1p2).dst(of2p1).type(DIRECT).build(),
DefaultLink.builder().providerId(PID).src(of3p2).dst(of2p3).type(DIRECT).build(),
DefaultLink.builder().providerId(PID).src(of2p2).dst(of4p1).type(DIRECT).build()
);
Set<ConnectPoint> ingress = ImmutableSet.of(
of1p1,
of3p1
);
Set<ConnectPoint> egress = ImmutableSet.of(
of4p2
);
TrafficSelector expectOf1Selector = DefaultTrafficSelector.builder(ipPrefixSelector)
.matchInPort(PortNumber.portNumber(1))
.build();
TrafficTreatment expectOf1Treatment = DefaultTrafficTreatment.builder(ethDstTreatment)
.setOutput(PortNumber.portNumber(2))
.build();
TrafficSelector expectOf2Selector1 = DefaultTrafficSelector.builder(ipPrefixSelector)
.matchInPort(PortNumber.portNumber(1))
.matchEthDst(MacAddress.valueOf("C0:FF:EE:C0:FF:EE"))
.build();
TrafficSelector expectOf2Selector2 = DefaultTrafficSelector.builder(ipPrefixSelector)
.matchEthDst(MacAddress.valueOf("C0:FF:EE:C0:FF:EE"))
.matchInPort(PortNumber.portNumber(3))
.build();
TrafficTreatment expectOf2Treatment = DefaultTrafficTreatment.builder()
.setOutput(PortNumber.portNumber(2))
.build();
TrafficSelector expectOf3Selector = DefaultTrafficSelector.builder(ipPrefixSelector)
.matchInPort(PortNumber.portNumber(1))
.build();
TrafficTreatment expectOf3Treatment = DefaultTrafficTreatment.builder(ethDstTreatment)
.setOutput(PortNumber.portNumber(2))
.build();
TrafficSelector expectOf4Selector = DefaultTrafficSelector.builder(ipPrefixSelector)
.matchEthDst(MacAddress.valueOf("C0:FF:EE:C0:FF:EE"))
.matchInPort(PortNumber.portNumber(1))
.build();
TrafficTreatment expectOf4Treatment = DefaultTrafficTreatment.builder()
.setOutput(PortNumber.portNumber(2))
.build();
intent = LinkCollectionIntent.builder()
.appId(APP_ID)
.selector(ipPrefixSelector)
.ingressPoints(ingress)
.egressPoints(egress)
.treatment(ethDstTreatment)
.links(testlinks)
.build();
List<Intent> result = sut.compile(intent, Collections.emptyList());
assertThat(result, is(notNullValue()));
assertThat(result, hasSize(1));
Intent resultIntent = result.get(0);
assertThat(resultIntent, instanceOf(FlowRuleIntent.class));
if (resultIntent instanceof FlowRuleIntent) {
FlowRuleIntent frIntent = (FlowRuleIntent) resultIntent;
assertThat(frIntent.flowRules(), hasSize(5));
List<FlowRule> deviceFlowRules;
FlowRule flowRule;
// Of1
deviceFlowRules = getFlowRulesByDevice(of1Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(1));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf1Selector));
assertThat(flowRule.treatment(), is(expectOf1Treatment));
// Of2 (has 2 flows)
deviceFlowRules = getFlowRulesByDevice(of2Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(2));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf2Selector1));
assertThat(flowRule.treatment(), is(expectOf2Treatment));
flowRule = deviceFlowRules.get(1);
assertThat(flowRule.selector(), is(expectOf2Selector2));
assertThat(flowRule.treatment(), is(expectOf2Treatment));
// Of3
deviceFlowRules = getFlowRulesByDevice(of3Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(1));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf3Selector));
assertThat(flowRule.treatment(), is(expectOf3Treatment));
// Of4
deviceFlowRules = getFlowRulesByDevice(of4Id, frIntent.flowRules());
assertThat(deviceFlowRules, hasSize(1));
flowRule = deviceFlowRules.get(0);
assertThat(flowRule.selector(), is(expectOf4Selector));
assertThat(flowRule.treatment(), is(expectOf4Treatment));
}
sut.deactivate();
}
}
......
......@@ -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"));
}
}
}
......
/*
* 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.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.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;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentTestsMocks;
import org.onosproject.net.intent.LinkCollectionIntent;
import org.onosproject.net.intent.SinglePointToMultiPointIntent;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.notNullValue;
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.intent.LinksHaveEntryWithSourceDestinationPairMatcher.linksHasPath;
/**
* Unit tests for SinglePointToMultiPointIntentCompiler.
*/
public class SinglePointToMultiPointIntentCompilerTest extends AbstractIntentTest {
private static final ApplicationId APPID = new TestApplicationId("foo");
private TrafficSelector selector = new IntentTestsMocks.MockSelector();
private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
/**
* Creates a SinglePointToMultiPoint intent for an ingress point
* and a group of egress points.
*
* @param ingressId device id of the ingress point
* @param egressIds array of egress device ids
* @return MultiPointToSinglePoint intent
*/
private SinglePointToMultiPointIntent makeIntent(String ingressId, String[] egressIds) {
ConnectPoint ingressPoint = connectPoint(ingressId, 2);
Set<ConnectPoint> egressPoints = new HashSet<>();
for (String egressId : egressIds) {
egressPoints.add(connectPoint(egressId, 1));
}
return SinglePointToMultiPointIntent.builder()
.appId(APPID)
.selector(selector)
.treatment(treatment)
.ingressPoint(ingressPoint)
.egressPoints(egressPoints)
.build();
}
/**
* Generate SinglePointToMultiPointIntent with filtered connection point.
*
* @param ingress filtered ingress point
* @param egress filtered egress point
* @return
*/
private SinglePointToMultiPointIntent makeFilteredConnectPointIntent(FilteredConnectPoint ingress,
Set<FilteredConnectPoint> egress) {
return SinglePointToMultiPointIntent.builder()
.appId(APPID)
.treatment(treatment)
.filteredIngressPoint(ingress)
.filteredEgressPoints(egress)
.build();
}
/**
* Creates a compiler for SinglePointToMultiPoint intents.
*
* @param hops hops to use while computing paths for this intent
* @return SinglePointToMultiPoint intent
*/
private SinglePointToMultiPointIntentCompiler makeCompiler(String[] hops) {
SinglePointToMultiPointIntentCompiler compiler =
new SinglePointToMultiPointIntentCompiler();
compiler.pathService = new IntentTestsMocks.Mp2MpMockPathService(hops);
return compiler;
}
/**
* Tests a single ingress point with 8 hops to its egress point.
*/
@Test
public void testSingleLongPathCompilation() {
String ingress = "ingress";
String[] egress = {"egress"};
SinglePointToMultiPointIntent intent = makeIntent(ingress, egress);
assertThat(intent, is(notNullValue()));
String[] hops = {"h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8"};
SinglePointToMultiPointIntentCompiler compiler = makeCompiler(hops);
assertThat(compiler, is(notNullValue()));
List<Intent> result = compiler.compile(intent, null);
assertThat(result, is(Matchers.notNullValue()));
assertThat(result, hasSize(1));
Intent resultIntent = result.get(0);
assertThat(resultIntent instanceof LinkCollectionIntent, is(true));
if (resultIntent instanceof LinkCollectionIntent) {
LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent;
assertThat(linkIntent.links(), hasSize(9));
assertThat(linkIntent.links(), linksHasPath("ingress", "h1"));
assertThat(linkIntent.links(), linksHasPath("h1", "h2"));
assertThat(linkIntent.links(), linksHasPath("h2", "h3"));
assertThat(linkIntent.links(), linksHasPath("h4", "h5"));
assertThat(linkIntent.links(), linksHasPath("h5", "h6"));
assertThat(linkIntent.links(), linksHasPath("h7", "h8"));
assertThat(linkIntent.links(), linksHasPath("h8", "egress"));
}
}
/**
* Tests a simple topology where two egress points share some path segments
* and some path segments are not shared.
*/
@Test
public void testTwoIngressCompilation() {
String ingress = "ingress";
String[] egress = {"egress1", "egress2"};
SinglePointToMultiPointIntent intent = makeIntent(ingress, egress);
assertThat(intent, is(notNullValue()));
final String[] hops = {"inner1", "inner2"};
SinglePointToMultiPointIntentCompiler 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, is(true));
if (resultIntent instanceof LinkCollectionIntent) {
LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent;
assertThat(linkIntent.links(), hasSize(4));
assertThat(linkIntent.links(), linksHasPath("ingress", "inner1"));
assertThat(linkIntent.links(), linksHasPath("inner1", "inner2"));
assertThat(linkIntent.links(), linksHasPath("inner2", "egress1"));
assertThat(linkIntent.links(), linksHasPath("inner2", "egress2"));
}
}
/**
* Tests a large number of ingress points that share a common path to the
* egress point.
*/
@Test
public void testMultiIngressCompilation() {
String ingress = "i";
String[] egress = {"e1", "e2", "e3", "e4", "e5",
"e6", "e7", "e8", "e9", "e10"};
SinglePointToMultiPointIntent intent = makeIntent(ingress, egress);
assertThat(intent, is(notNullValue()));
final String[] hops = {"n1"};
SinglePointToMultiPointIntentCompiler 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, is(true));
if (resultIntent instanceof LinkCollectionIntent) {
LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent;
assertThat(linkIntent.links(), hasSize(egress.length + 1));
for (String egressToCheck : egress) {
assertThat(linkIntent.links(), linksHasPath("n1", egressToCheck));
}
assertThat(linkIntent.links(), linksHasPath(ingress, "n1"));
}
}
/**
* Tests ingress and egress on the same device.
*/
@Test
public void testSameDeviceCompilation() {
String ingress = "i1";
String[] egress = {"i2", "i3"};
SinglePointToMultiPointIntent intent = makeIntent(ingress, egress);
assertThat(intent, is(notNullValue()));
final String[] hops = {};
SinglePointToMultiPointIntentCompiler 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(egress.length));
assertThat(linkIntent.links(), linksHasPath("i1", "i2"));
assertThat(linkIntent.links(), linksHasPath("i1", "i3"));
}
}
/**
* Tests filtered ingress and egress.
*/
@Test
public void testFilteredConnectPointIntent() {
FilteredConnectPoint ingress = new FilteredConnectPoint(connectPoint("of1", 1));
Set<FilteredConnectPoint> egress = ImmutableSet.of(
new FilteredConnectPoint(connectPoint("of3", 1),
DefaultTrafficSelector.builder().matchVlanId(VlanId.vlanId("100")).build()),
new FilteredConnectPoint(connectPoint("of4", 1),
DefaultTrafficSelector.builder().matchVlanId(VlanId.vlanId("200")).build())
);
SinglePointToMultiPointIntent intent = makeFilteredConnectPointIntent(ingress, egress);
String[] hops = {"of2"};
SinglePointToMultiPointIntentCompiler 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", "of2"));
assertThat(linkIntent.links(), linksHasPath("of2", "of3"));
assertThat(linkIntent.links(), linksHasPath("of2", "of4"));
Set<FilteredConnectPoint> ingressPoints = linkIntent.filteredIngressPoints();
assertThat("Link collection ingress points do not match base intent",
ingressPoints.size() == 1 && ingressPoints.contains(intent.filteredIngressPoint()));
assertThat("Link collection egress points do not match base intent",
linkIntent.filteredEgressPoints().equals(intent.filteredEgressPoints()));
}
}
}