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/web/api/src/main/java/org/onosproject/codec/impl/InstructionCodec.java b/web/api/src/main/java/org/onosproject/codec/impl/InstructionCodec.java
index 57f95bd..913fc8b 100644
--- a/web/api/src/main/java/org/onosproject/codec/impl/InstructionCodec.java
+++ b/web/api/src/main/java/org/onosproject/codec/impl/InstructionCodec.java
@@ -15,7 +15,6 @@
*/
package org.onosproject.codec.impl;
-import org.onlab.packet.Ethernet;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
import org.onosproject.net.flow.instructions.Instruction;
@@ -100,11 +99,7 @@
final L2ModificationInstruction.PushHeaderInstructions pushHeaderInstructions =
(L2ModificationInstruction.PushHeaderInstructions) instruction;
- final JsonCodec<Ethernet> ethernetCodec =
- context.codec(Ethernet.class);
- result.set("ethernetType",
- ethernetCodec.encode(pushHeaderInstructions.ethernetType(),
- context));
+ result.put("ethernetType", pushHeaderInstructions.ethernetType());
break;
default:
diff --git a/web/api/src/test/java/org/onosproject/codec/impl/InstructionJsonMatcher.java b/web/api/src/test/java/org/onosproject/codec/impl/InstructionJsonMatcher.java
index 001a865..0086255 100644
--- a/web/api/src/test/java/org/onosproject/codec/impl/InstructionJsonMatcher.java
+++ b/web/api/src/test/java/org/onosproject/codec/impl/InstructionJsonMatcher.java
@@ -16,13 +16,11 @@
package org.onosproject.codec.impl;
import org.hamcrest.Description;
-import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeDiagnosingMatcher;
import org.onosproject.net.flow.instructions.Instruction;
import com.fasterxml.jackson.databind.JsonNode;
-import static org.onosproject.codec.impl.EthernetJsonMatcher.matchesEthernet;
import static org.onosproject.net.flow.instructions.Instructions.*;
import static org.onosproject.net.flow.instructions.L0ModificationInstruction.*;
import static org.onosproject.net.flow.instructions.L2ModificationInstruction.*;
@@ -67,13 +65,11 @@
return false;
}
- final Matcher ethernetMatcher =
- matchesEthernet(instructionToMatch.ethernetType());
- final boolean ethernetMatches = ethernetMatcher.matches(ethJson);
- if (!ethernetMatches) {
- ethernetMatcher.describeMismatch(ethernetMatcher, description);
+ if (instructionToMatch.ethernetType() != ethJson.asInt()) {
+ description.appendText("ethernetType was " + ethJson);
return false;
}
+
return true;
}
diff --git a/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java b/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java
index fc28624..a02690f 100644
--- a/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java
@@ -45,8 +45,7 @@
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.instructions.Instruction;
-import org.onosproject.net.flow.instructions.L0ModificationInstruction;
-
+import org.onosproject.net.flow.instructions.Instructions;
import com.eclipsesource.json.JsonArray;
import com.eclipsesource.json.JsonObject;
import com.google.common.collect.ImmutableSet;
@@ -187,6 +186,7 @@
return false;
}
+ @Override
public Type type() {
return Type.DEFAULT;
}
@@ -197,10 +197,8 @@
*/
private void setupMockFlows() {
flow2.treatment = DefaultTrafficTreatment.builder()
- .add(new L0ModificationInstruction.ModLambdaInstruction(
- L0ModificationInstruction.L0SubType.LAMBDA, (short) 4))
- .add(new L0ModificationInstruction.ModLambdaInstruction(
- L0ModificationInstruction.L0SubType.LAMBDA, (short) 5))
+ .add(Instructions.modL0Lambda((short) 4))
+ .add(Instructions.modL0Lambda((short) 5))
.setEthDst(MacAddress.BROADCAST)
.build();
flow2.selector = DefaultTrafficSelector.builder()
@@ -208,8 +206,7 @@
.matchIPProtocol((byte) 9)
.build();
flow4.treatment = DefaultTrafficTreatment.builder()
- .add(new L0ModificationInstruction.ModLambdaInstruction(
- L0ModificationInstruction.L0SubType.LAMBDA, (short) 6))
+ .add(Instructions.modL0Lambda((short) 6))
.build();
final Set<FlowEntry> flows1 = new HashSet<>();
flows1.add(flow1);