small fixes to ethtype pattern
Change-Id: Ic58c426821952f66aa21bc828d36fd4f83d8da0d
diff --git a/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java b/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java
index fead3bd..e8a131b 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java
@@ -19,6 +19,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.apache.commons.collections.ListUtils;
+import org.onlab.packet.EthType;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
@@ -309,6 +310,11 @@
@Override
public Builder popMpls(int etherType) {
+ return add(Instructions.popMpls(new EthType(etherType)));
+ }
+
+ @Override
+ public Builder popMpls(EthType etherType) {
return add(Instructions.popMpls(etherType));
}
diff --git a/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java b/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java
index a82919f..ba82e92 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.net.flow;
+import org.onlab.packet.EthType;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
@@ -197,9 +198,18 @@
* @param etherType an ether type
* @return a treatment builder.
*/
+ @Deprecated
Builder popMpls(int etherType);
/**
+ * Pops MPLS ether type and set the new ethertype.
+ *
+ * @param etherType an ether type
+ * @return a treatment builder.
+ */
+ Builder popMpls(EthType etherType);
+
+ /**
* Sets the mpls label.
*
* @param mplsLabel MPLS label.
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 465de6b..b2666d4 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
@@ -25,8 +25,9 @@
* Implementation of Ethernet type criterion (16 bits unsigned integer).
*/
public final class EthTypeCriterion implements Criterion {
- private static final int MASK = 0xffff;
- private final EthType ethType; // Ethernet type value: 16 bits
+
+
+ private final EthType ethType;
/**
* Constructor.
@@ -35,7 +36,7 @@
* integer)
*/
EthTypeCriterion(int ethType) {
- this.ethType = new EthType(ethType & MASK);
+ this.ethType = new EthType(ethType);
}
/**
diff --git a/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java b/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
index 500ac1c..9703e1c 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
@@ -15,7 +15,7 @@
*/
package org.onosproject.net.flow.instructions;
-import org.onlab.packet.Ethernet;
+import org.onlab.packet.EthType;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
@@ -265,7 +265,7 @@
public static Instruction pushMpls() {
return new L2ModificationInstruction.PushHeaderInstructions(
L2ModificationInstruction.L2SubType.MPLS_PUSH,
- Ethernet.MPLS_UNICAST);
+ EthType.EtherType.MPLS_UNICAST.ethType());
}
/**
@@ -276,7 +276,7 @@
public static Instruction popMpls() {
return new L2ModificationInstruction.PushHeaderInstructions(
L2ModificationInstruction.L2SubType.MPLS_POP,
- Ethernet.MPLS_UNICAST);
+ EthType.EtherType.MPLS_UNICAST.ethType());
}
/**
@@ -285,9 +285,23 @@
* @param etherType Ethernet type to set
* @return a L2 modification.
*/
+ @Deprecated
public static Instruction popMpls(int etherType) {
checkNotNull(etherType, "Ethernet type cannot be null");
return new L2ModificationInstruction.PushHeaderInstructions(
+ L2ModificationInstruction.L2SubType.MPLS_POP, new EthType(etherType));
+ }
+
+
+ /**
+ * Creates a pop MPLS header instruction with a particular ethertype.
+ *
+ * @param etherType Ethernet type to set
+ * @return a L2 modification.
+ */
+ public static Instruction popMpls(EthType etherType) {
+ checkNotNull(etherType, "Ethernet type cannot be null");
+ return new L2ModificationInstruction.PushHeaderInstructions(
L2ModificationInstruction.L2SubType.MPLS_POP, etherType);
}
@@ -308,7 +322,8 @@
*/
public static Instruction pushVlan() {
return new L2ModificationInstruction.PushHeaderInstructions(
- L2ModificationInstruction.L2SubType.VLAN_PUSH, Ethernet.TYPE_VLAN);
+ L2ModificationInstruction.L2SubType.VLAN_PUSH,
+ EthType.EtherType.VLAN.ethType());
}
/**
diff --git a/core/api/src/main/java/org/onosproject/net/flow/instructions/L2ModificationInstruction.java b/core/api/src/main/java/org/onosproject/net/flow/instructions/L2ModificationInstruction.java
index b993848..2fd809f 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/instructions/L2ModificationInstruction.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/instructions/L2ModificationInstruction.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.net.flow.instructions;
+import org.onlab.packet.EthType;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.VlanId;
@@ -145,16 +146,16 @@
public static final class PushHeaderInstructions extends
L2ModificationInstruction {
- private static final int MASK = 0xffff;
- private final L2SubType subtype;
- private final int ethernetType; // Ethernet type value: 16 bits
- PushHeaderInstructions(L2SubType subType, int ethernetType) {
+ private final L2SubType subtype;
+ private final EthType ethernetType; // Ethernet type value: 16 bits
+
+ PushHeaderInstructions(L2SubType subType, EthType ethernetType) {
this.subtype = subType;
- this.ethernetType = ethernetType & MASK;
+ this.ethernetType = ethernetType;
}
- public int ethernetType() {
+ public EthType ethernetType() {
return ethernetType;
}
@@ -166,7 +167,7 @@
@Override
public String toString() {
return toStringHelper(subtype().toString())
- .add("ethernetType", String.format("0x%04x", ethernetType()))
+ .add("ethernetType", ethernetType())
.toString();
}
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/EncodeInstructionCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/EncodeInstructionCodec.java
index 7fb56fd..20de446 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/EncodeInstructionCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/EncodeInstructionCodec.java
@@ -119,7 +119,8 @@
final L2ModificationInstruction.PushHeaderInstructions pushHeaderInstructions =
(L2ModificationInstruction.PushHeaderInstructions) instruction;
- result.put(InstructionCodec.ETHERNET_TYPE, pushHeaderInstructions.ethernetType());
+ result.put(InstructionCodec.ETHERNET_TYPE,
+ pushHeaderInstructions.ethernetType().toShort());
break;
default:
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/FlowRuleCodecTest.java b/core/common/src/test/java/org/onosproject/codec/impl/FlowRuleCodecTest.java
index 2a93b55..9c778fb 100644
--- a/core/common/src/test/java/org/onosproject/codec/impl/FlowRuleCodecTest.java
+++ b/core/common/src/test/java/org/onosproject/codec/impl/FlowRuleCodecTest.java
@@ -247,15 +247,15 @@
instruction = getInstruction(Instruction.Type.L2MODIFICATION,
L2ModificationInstruction.L2SubType.MPLS_PUSH.name());
assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
- assertThat((short) ((L2ModificationInstruction.PushHeaderInstructions) instruction)
- .ethernetType(),
+ assertThat(((L2ModificationInstruction.PushHeaderInstructions) instruction)
+ .ethernetType().toShort(),
is(Ethernet.MPLS_UNICAST));
instruction = getInstruction(Instruction.Type.L2MODIFICATION,
L2ModificationInstruction.L2SubType.MPLS_POP.name());
assertThat(instruction.type(), is(Instruction.Type.L2MODIFICATION));
- assertThat((short) ((L2ModificationInstruction.PushHeaderInstructions) instruction)
- .ethernetType(),
+ assertThat(((L2ModificationInstruction.PushHeaderInstructions) instruction)
+ .ethernetType().toShort(),
is(Ethernet.MPLS_UNICAST));
instruction = getInstruction(Instruction.Type.L2MODIFICATION,
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/InstructionJsonMatcher.java b/core/common/src/test/java/org/onosproject/codec/impl/InstructionJsonMatcher.java
index 7281ed5..dbb3bd0 100644
--- a/core/common/src/test/java/org/onosproject/codec/impl/InstructionJsonMatcher.java
+++ b/core/common/src/test/java/org/onosproject/codec/impl/InstructionJsonMatcher.java
@@ -66,7 +66,7 @@
return false;
}
- if (instructionToMatch.ethernetType() != ethJson.asInt()) {
+ if (instructionToMatch.ethernetType().toShort() != ethJson.asInt()) {
description.appendText("ethernetType was " + ethJson);
return false;
}