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 { ...@@ -71,6 +71,8 @@ public final class HostToHostIntent extends ConnectivityIntent {
71 super(id(HostToHostIntent.class, min(one, two), max(one, two), 71 super(id(HostToHostIntent.class, min(one, two), max(one, two),
72 selector, treatment, constraints), 72 selector, treatment, constraints),
73 appId, null, selector, treatment, constraints); 73 appId, null, selector, treatment, constraints);
74 +
75 + // TODO: consider whether the case one and two are same is allowed
74 this.one = checkNotNull(one); 76 this.one = checkNotNull(one);
75 this.two = checkNotNull(two); 77 this.two = checkNotNull(two);
76 78
......
...@@ -86,9 +86,12 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { ...@@ -86,9 +86,12 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
86 86
87 checkNotNull(ingressPoints); 87 checkNotNull(ingressPoints);
88 checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty"); 88 checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
89 + checkNotNull(egressPoint);
90 + checkArgument(!ingressPoints.contains(egressPoint),
91 + "Set of ingresses should not contain egress (egress: %s)", egressPoint);
89 92
90 this.ingressPoints = Sets.newHashSet(ingressPoints); 93 this.ingressPoints = Sets.newHashSet(ingressPoints);
91 - this.egressPoint = checkNotNull(egressPoint); 94 + this.egressPoint = egressPoint;
92 } 95 }
93 96
94 /** 97 /**
......
...@@ -26,6 +26,7 @@ import org.onlab.onos.net.intent.constraint.LinkTypeConstraint; ...@@ -26,6 +26,7 @@ import org.onlab.onos.net.intent.constraint.LinkTypeConstraint;
26 26
27 import java.util.List; 27 import java.util.List;
28 28
29 +import static com.google.common.base.Preconditions.checkArgument;
29 import static com.google.common.base.Preconditions.checkNotNull; 30 import static com.google.common.base.Preconditions.checkNotNull;
30 31
31 /** 32 /**
...@@ -75,8 +76,14 @@ public class PointToPointIntent extends ConnectivityIntent { ...@@ -75,8 +76,14 @@ public class PointToPointIntent extends ConnectivityIntent {
75 super(id(PointToPointIntent.class, selector, treatment, 76 super(id(PointToPointIntent.class, selector, treatment,
76 ingressPoint, egressPoint, constraints), 77 ingressPoint, egressPoint, constraints),
77 appId, null, selector, treatment, constraints); 78 appId, null, selector, treatment, constraints);
78 - this.ingressPoint = checkNotNull(ingressPoint); 79 +
79 - this.egressPoint = checkNotNull(egressPoint); 80 + checkNotNull(ingressPoint);
81 + checkNotNull(egressPoint);
82 + checkArgument(!ingressPoint.equals(egressPoint),
83 + "ingress and egress should be different (ingress: %s, egress: %s)", ingressPoint, egressPoint);
84 +
85 + this.ingressPoint = ingressPoint;
86 + this.egressPoint = egressPoint;
80 } 87 }
81 88
82 /** 89 /**
......
...@@ -56,8 +56,12 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent { ...@@ -56,8 +56,12 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent {
56 super(id(SinglePointToMultiPointIntent.class, selector, treatment, 56 super(id(SinglePointToMultiPointIntent.class, selector, treatment,
57 ingressPoint, egressPoints), appId, null, selector, treatment); 57 ingressPoint, egressPoints), appId, null, selector, treatment);
58 checkNotNull(egressPoints); 58 checkNotNull(egressPoints);
59 + checkNotNull(ingressPoint);
59 checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty"); 60 checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
60 - this.ingressPoint = checkNotNull(ingressPoint); 61 + checkArgument(!egressPoints.contains(ingressPoint),
62 + "Set of egresses should not contain ingress (ingress: %s)", ingressPoint);
63 +
64 + this.ingressPoint = ingressPoint;
61 this.egressPoints = Sets.newHashSet(egressPoints); 65 this.egressPoints = Sets.newHashSet(egressPoints);
62 } 66 }
63 67
......