Guard malformed intent by pre-condition check on instantiation
Change-Id: I90ca0fac2e3b68c4ca5b464777b0cdaa2227c2e5
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/HostToHostIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/HostToHostIntent.java
index e09767a..b9baf10 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/HostToHostIntent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/HostToHostIntent.java
@@ -71,6 +71,8 @@
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);
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntent.java
index 8c8cbb0..15afedd 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntent.java
@@ -86,9 +86,12 @@
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;
}
/**
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/PointToPointIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/PointToPointIntent.java
index e480ee2..b07a3a6 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/PointToPointIntent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/PointToPointIntent.java
@@ -26,6 +26,7 @@
import java.util.List;
+import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
/**
@@ -75,8 +76,14 @@
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;
}
/**
diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/SinglePointToMultiPointIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/SinglePointToMultiPointIntent.java
index bb38846..efe96e2 100644
--- a/core/api/src/main/java/org/onlab/onos/net/intent/SinglePointToMultiPointIntent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/intent/SinglePointToMultiPointIntent.java
@@ -56,8 +56,12 @@
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);
}