adding EthType to secure handling ether types
this will also pretty print ethertypes in flow output
Change-Id: I9363070ad308f3c756735e29b3992c500e503636
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 a163cea..f285496 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
@@ -15,6 +15,7 @@
*/
package org.onosproject.net.flow.criteria;
+import org.onlab.packet.EthType;
import org.onosproject.net.IndexedLambda;
import org.onosproject.net.Lambda;
import org.onosproject.net.OchSignal;
@@ -101,6 +102,16 @@
}
/**
+ * Creates a match on ETH_TYPE field using the specified value.
+ *
+ * @param ethType eth type value
+ * @return match criterion
+ */
+ public static Criterion matchEthType(EthType ethType) {
+ return new EthTypeCriterion(ethType);
+ }
+
+ /**
* Creates a match on VLAN ID field using the specified value.
*
* @param vlanId vlan id value
diff --git a/core/api/src/main/java/org/onosproject/net/flow/criteria/EthTypeCriterion.java b/core/api/src/main/java/org/onosproject/net/flow/criteria/EthTypeCriterion.java
index a42d8d3..465de6b 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/criteria/EthTypeCriterion.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/criteria/EthTypeCriterion.java
@@ -15,6 +15,8 @@
*/
package org.onosproject.net.flow.criteria;
+import org.onlab.packet.EthType;
+
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
@@ -24,7 +26,7 @@
*/
public final class EthTypeCriterion implements Criterion {
private static final int MASK = 0xffff;
- private final int ethType; // Ethernet type value: 16 bits
+ private final EthType ethType; // Ethernet type value: 16 bits
/**
* Constructor.
@@ -33,7 +35,16 @@
* integer)
*/
EthTypeCriterion(int ethType) {
- this.ethType = ethType & MASK;
+ this.ethType = new EthType(ethType & MASK);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param ethType the Ethernet frame type to match
+ */
+ EthTypeCriterion(EthType ethType) {
+ this.ethType = ethType;
}
@Override
@@ -46,14 +57,14 @@
*
* @return the Ethernet frame type to match (16 bits unsigned integer)
*/
- public int ethType() {
+ public EthType ethType() {
return ethType;
}
@Override
public String toString() {
return toStringHelper(type().toString())
- .add("ethType", Long.toHexString(ethType))
+ .add("ethType", ethType.toString())
.toString();
}
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 bad60a0..4733cb9 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
@@ -16,6 +16,7 @@
package org.onosproject.net.flow.criteria;
import org.junit.Test;
+import org.onlab.packet.EthType;
import org.onosproject.net.ChannelSpacing;
import org.onosproject.net.GridType;
import org.onosproject.net.Lambda;
@@ -418,8 +419,8 @@
*/
@Test
public void testMatchEthTypeMethod() {
- int ethType = 12;
- Criterion matchEthType = Criteria.matchEthType(ethType);
+ EthType ethType = new EthType(12);
+ Criterion matchEthType = Criteria.matchEthType(new EthType(12));
EthTypeCriterion ethTypeCriterion =
checkAndConvert(matchEthType,
Criterion.Type.ETH_TYPE,