Sho SHIMIZU
Committed by Jonathan Hart

Guard malformed intent by pre-condition check on instantiation

Change-Id: I90ca0fac2e3b68c4ca5b464777b0cdaa2227c2e5
......@@ -71,6 +71,8 @@ public final class HostToHostIntent extends ConnectivityIntent {
super(id(HostToHostIntent.class, min(one, two), max(one, two),
selector, treatment, constraints),
appId, null, selector, treatment, constraints);
// TODO: consider whether the case one and two are same is allowed
this.one = checkNotNull(one);
this.two = checkNotNull(two);
......
......@@ -86,9 +86,12 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
checkNotNull(ingressPoints);
checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
checkNotNull(egressPoint);
checkArgument(!ingressPoints.contains(egressPoint),
"Set of ingresses should not contain egress (egress: %s)", egressPoint);
this.ingressPoints = Sets.newHashSet(ingressPoints);
this.egressPoint = checkNotNull(egressPoint);
this.egressPoint = egressPoint;
}
/**
......
......@@ -26,6 +26,7 @@ import org.onlab.onos.net.intent.constraint.LinkTypeConstraint;
import java.util.List;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
/**
......@@ -75,8 +76,14 @@ public class PointToPointIntent extends ConnectivityIntent {
super(id(PointToPointIntent.class, selector, treatment,
ingressPoint, egressPoint, constraints),
appId, null, selector, treatment, constraints);
this.ingressPoint = checkNotNull(ingressPoint);
this.egressPoint = checkNotNull(egressPoint);
checkNotNull(ingressPoint);
checkNotNull(egressPoint);
checkArgument(!ingressPoint.equals(egressPoint),
"ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint);
this.ingressPoint = ingressPoint;
this.egressPoint = egressPoint;
}
/**
......
......@@ -56,8 +56,12 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent {
super(id(SinglePointToMultiPointIntent.class, selector, treatment,
ingressPoint, egressPoints), appId, null, selector, treatment);
checkNotNull(egressPoints);
checkNotNull(ingressPoint);
checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
this.ingressPoint = checkNotNull(ingressPoint);
checkArgument(!egressPoints.contains(ingressPoint),
"Set of egresses should not contain ingress (ingress: %s)", ingressPoint);
this.ingressPoint = ingressPoint;
this.egressPoints = Sets.newHashSet(egressPoints);
}
......