ONOS-509: Match IPV6_SRC, IPV6_DST criteria
* Following classes have been extended to match IPV6_SRC and IPV6_DST criteria:
- Criteria
- DefaultTrafficSelector
- FlowEntryBuilder
- FlowModBuilder
* Not included in this submission
- Match of other IPv6-related criteria
- Set of all IPv6-related criteria (action)
Change-Id: I115829a480356d2037e0fc809595f7a5eec25874
diff --git a/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficSelector.java b/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficSelector.java
index 1caed8e..756fdd7 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficSelector.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficSelector.java
@@ -184,6 +184,16 @@
}
@Override
+ public Builder matchIPv6Src(IpPrefix ip) {
+ return add(Criteria.matchIPv6Src(ip));
+ }
+
+ @Override
+ public Builder matchIPv6Dst(IpPrefix ip) {
+ return add(Criteria.matchIPv6Dst(ip));
+ }
+
+ @Override
public Builder matchMplsLabel(Integer mplsLabel) {
return add(Criteria.matchMplsLabel(mplsLabel));
}
diff --git a/core/api/src/main/java/org/onosproject/net/flow/TrafficSelector.java b/core/api/src/main/java/org/onosproject/net/flow/TrafficSelector.java
index d9b91f6..267fb51 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/TrafficSelector.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/TrafficSelector.java
@@ -115,7 +115,7 @@
public Builder matchIPProtocol(Byte proto);
/**
- * Matches a l3 address.
+ * Matches a l3 IPv4 address.
*
* @param ip a l3 address
* @return a selection builder
@@ -123,7 +123,7 @@
public Builder matchIPSrc(IpPrefix ip);
/**
- * Matches a l3 address.
+ * Matches a l3 IPv4 address.
*
* @param ip a l3 address
* @return a selection builder
@@ -146,6 +146,21 @@
*/
public Builder matchTcpDst(Short tcpPort);
+ /**
+ * Matches a l3 IPv6 address.
+ *
+ * @param ip a l3 IPv6 address
+ * @return a selection builder
+ */
+ public Builder matchIPv6Src(IpPrefix ip);
+
+ /**
+ * Matches a l3 IPv6 address.
+ *
+ * @param ip a l3 IPv6 address
+ * @return a selection builder
+ */
+ public Builder matchIPv6Dst(IpPrefix ip);
/**
* Matches on a MPLS label .
diff --git a/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java b/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java
index dcc7edc..e725143 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java
@@ -18,7 +18,6 @@
import static com.google.common.base.MoreObjects.toStringHelper;
import java.util.Objects;
-
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.criteria.Criterion.Type;
import org.onlab.packet.IpPrefix;
@@ -109,9 +108,9 @@
}
/**
- * Creates a match on IP source field using the specified value.
+ * Creates a match on IPv4 source field using the specified value.
*
- * @param ip ip source value
+ * @param ip ipv4 source value
* @return match criterion
*/
public static Criterion matchIPSrc(IpPrefix ip) {
@@ -119,9 +118,9 @@
}
/**
- * Creates a match on IP destination field using the specified value.
+ * Creates a match on IPv4 destination field using the specified value.
*
- * @param ip ip source value
+ * @param ip ipv4 source value
* @return match criterion
*/
public static Criterion matchIPDst(IpPrefix ip) {
@@ -149,6 +148,26 @@
}
/**
+ * Creates a match on IPv6 source field using the specified value.
+ *
+ * @param ip ipv6 source value
+ * @return match criterion
+ */
+ public static Criterion matchIPv6Src(IpPrefix ip) {
+ return new IPCriterion(ip, Type.IPV6_SRC);
+ }
+
+ /**
+ * Creates a match on IPv6 destination field using the specified value.
+ *
+ * @param ip ipv6 source value
+ * @return match criterion
+ */
+ public static Criterion matchIPv6Dst(IpPrefix ip) {
+ return new IPCriterion(ip, Type.IPV6_DST);
+ }
+
+ /**
* Creates a match on MPLS label.
* @param mplsLabel MPLS label
* @return match criterion
diff --git a/core/api/src/test/java/org/onosproject/net/flow/DefaultTrafficSelectorTest.java b/core/api/src/test/java/org/onosproject/net/flow/DefaultTrafficSelectorTest.java
index a1ce3d9..651773f 100644
--- a/core/api/src/test/java/org/onosproject/net/flow/DefaultTrafficSelectorTest.java
+++ b/core/api/src/test/java/org/onosproject/net/flow/DefaultTrafficSelectorTest.java
@@ -129,6 +129,7 @@
final short shortValue = 33;
final byte byteValue = 44;
final IpPrefix ipPrefixValue = IpPrefix.valueOf("192.168.1.0/24");
+ final IpPrefix ipv6PrefixValue = IpPrefix.valueOf("fe80::1/64");
selector = DefaultTrafficSelector.builder()
.matchInport(PortNumber.portNumber(11)).build();
@@ -175,6 +176,14 @@
assertThat(selector, hasCriterionWithType(Type.TCP_DST));
selector = DefaultTrafficSelector.builder()
+ .matchIPv6Src(ipv6PrefixValue).build();
+ assertThat(selector, hasCriterionWithType(Type.IPV6_SRC));
+
+ selector = DefaultTrafficSelector.builder()
+ .matchIPv6Dst(ipv6PrefixValue).build();
+ assertThat(selector, hasCriterionWithType(Type.IPV6_DST));
+
+ selector = DefaultTrafficSelector.builder()
.matchMplsLabel(3).build();
assertThat(selector, hasCriterionWithType(Type.MPLS_LABEL));
diff --git a/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java b/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java
index 0fc5d30..a11b227 100644
--- a/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java
+++ b/core/api/src/test/java/org/onosproject/net/flow/criteria/CriteriaTest.java
@@ -84,11 +84,18 @@
private static final String IP1 = "1.2.3.4/24";
private static final String IP2 = "5.6.7.8/24";
+ private static final String IPV61 = "fe80::1/64";
+ private static final String IPV62 = "fc80::2/64";
private IpPrefix ip1 = IpPrefix.valueOf(IP1);
private IpPrefix ip2 = IpPrefix.valueOf(IP2);
+ private IpPrefix ipv61 = IpPrefix.valueOf(IPV61);
+ private IpPrefix ipv62 = IpPrefix.valueOf(IPV62);
Criterion matchIp1 = Criteria.matchIPSrc(ip1);
Criterion sameAsMatchIp1 = Criteria.matchIPSrc(ip1);
Criterion matchIp2 = Criteria.matchIPSrc(ip2);
+ Criterion matchIpv61 = Criteria.matchIPSrc(ipv61);
+ Criterion sameAsMatchIpv61 = Criteria.matchIPSrc(ipv61);
+ Criterion matchIpv62 = Criteria.matchIPSrc(ipv62);
short lambda1 = 1;
short lambda2 = 2;
@@ -384,6 +391,32 @@
}
/**
+ * Test the matchIPSrc method.
+ */
+ @Test
+ public void testMatchIPv6SrcMethod() {
+ Criterion matchIpv6Src = Criteria.matchIPv6Src(ipv61);
+ Criteria.IPCriterion ipCriterion =
+ checkAndConvert(matchIpv6Src,
+ Criterion.Type.IPV6_SRC,
+ Criteria.IPCriterion.class);
+ assertThat(ipCriterion.ip(), is(ipv61));
+ }
+
+ /**
+ * Test the matchIPDst method.
+ */
+ @Test
+ public void testMatchIPv6DstMethod() {
+ Criterion matchIPv6Dst = Criteria.matchIPv6Dst(ipv61);
+ Criteria.IPCriterion ipCriterion =
+ checkAndConvert(matchIPv6Dst,
+ Criterion.Type.IPV6_DST,
+ Criteria.IPCriterion.class);
+ assertThat(ipCriterion.ip(), is(equalTo(ipv61)));
+ }
+
+ /**
* Test the equals() method of the IpCriterion class.
*/
@Test
@@ -392,6 +425,11 @@
.addEqualityGroup(matchIp1, sameAsMatchIp1)
.addEqualityGroup(matchIp2)
.testEquals();
+
+ new EqualsTester()
+ .addEqualityGroup(matchIpv61, sameAsMatchIpv61)
+ .addEqualityGroup(matchIpv62)
+ .testEquals();
}
// LambdaCriterion class