Instruction related fixes
- Fixed PushHeaderInstructions bug, where half-baked Ethernet instace was used
only to hold ethernetType. (ONOS-987)
Change-Id: I330a862c8a18206250befbd4e22ee6d189beed83
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 df4a695..8141c9a 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
@@ -194,7 +194,7 @@
*/
public static Instruction pushMpls() {
return new PushHeaderInstructions(L2SubType.MPLS_PUSH,
- new Ethernet().setEtherType(Ethernet.MPLS_UNICAST));
+ Ethernet.MPLS_UNICAST);
}
/**
@@ -203,7 +203,7 @@
*/
public static Instruction popMpls() {
return new PushHeaderInstructions(L2SubType.MPLS_POP,
- new Ethernet().setEtherType(Ethernet.MPLS_UNICAST));
+ Ethernet.MPLS_UNICAST);
}
/**
@@ -214,8 +214,7 @@
*/
public static Instruction popMpls(Short etherType) {
checkNotNull(etherType, "Ethernet type cannot be null");
- return new PushHeaderInstructions(L2SubType.MPLS_POP,
- new Ethernet().setEtherType(etherType));
+ return new PushHeaderInstructions(L2SubType.MPLS_POP, etherType);
}
/*
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 c6dd282..723bbe6 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
@@ -19,7 +19,6 @@
import java.util.Objects;
-import org.onlab.packet.Ethernet;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
@@ -140,15 +139,15 @@
L2ModificationInstruction {
private final L2SubType subtype;
- private final Ethernet ethernetType;
+ private final short ethernetType; // uint16_t
- public PushHeaderInstructions(L2SubType subType, Ethernet ethernetType) {
+ PushHeaderInstructions(L2SubType subType, short ethernetType) {
this.subtype = subType;
this.ethernetType = ethernetType;
}
- public Ethernet ethernetType() {
- return ethernetType;
+ public int ethernetType() {
+ return Short.toUnsignedInt(ethernetType);
}
@Override
@@ -158,12 +157,14 @@
@Override
public String toString() {
- return toStringHelper(subtype().toString()).toString();
+ return toStringHelper(subtype().toString())
+ .add("ethernetType", String.format("0x%04x", ethernetType()))
+ .toString();
}
@Override
public int hashCode() {
- return Objects.hash(type(), subtype);
+ return Objects.hash(type(), subtype, ethernetType);
}
@Override
@@ -173,9 +174,8 @@
}
if (obj instanceof PushHeaderInstructions) {
PushHeaderInstructions that = (PushHeaderInstructions) obj;
- return Objects.equals(this.type(), that.type()) &&
- Objects.equals(subtype, that.subtype);
-
+ return Objects.equals(subtype, that.subtype) &&
+ Objects.equals(this.ethernetType, that.ethernetType);
}
return false;
}