Support to encode and decode group id in InstructionCodec
Change-Id: Icd0947f494f572831e8b5c8d82d47c85eb074824
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 a6871c8..2ed7a82 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
@@ -15,11 +15,13 @@
*/
package org.onosproject.codec.impl;
+import com.fasterxml.jackson.databind.JsonNode;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeDiagnosingMatcher;
import org.onlab.util.HexString;
import org.onosproject.net.OduSignalId;
import org.onosproject.net.flow.instructions.Instruction;
+import org.onosproject.net.flow.instructions.Instructions.GroupInstruction;
import org.onosproject.net.flow.instructions.Instructions.NoActionInstruction;
import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction;
@@ -33,8 +35,6 @@
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
-import com.fasterxml.jackson.databind.JsonNode;
-
/**
* Hamcrest matcher for instructions.
*/
@@ -123,6 +123,33 @@
}
/**
+ * Matches the contents of a group instruction.
+ *
+ * @param instructionJson JSON instruction to match
+ * @param description Description object used for recording errors
+ * @return true if contents match, false otherwise
+ */
+ private boolean matchGroupInstruction(JsonNode instructionJson,
+ Description description) {
+ final String jsonType = instructionJson.get("type").textValue();
+ GroupInstruction instructionToMatch = (GroupInstruction) instruction;
+ if (!instructionToMatch.type().name().equals(jsonType)) {
+ description.appendText("type was " + jsonType);
+ return false;
+ }
+
+ if (instructionJson.get("groupId").isInt()) {
+ final int jsonGroupId = instructionJson.get("groupId").asInt();
+ if (instructionToMatch.groupId().id() != jsonGroupId) {
+ description.appendText("groupId was " + jsonGroupId);
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
* Matches the contents of a mod lambda instruction.
*
* @param instructionJson JSON instruction to match
@@ -453,6 +480,8 @@
return matchPushHeaderInstruction(jsonInstruction, description);
} else if (instruction instanceof OutputInstruction) {
return matchOutputInstruction(jsonInstruction, description);
+ } else if (instruction instanceof GroupInstruction) {
+ return matchGroupInstruction(jsonInstruction, description);
} else if (instruction instanceof ModLambdaInstruction) {
return matchModLambdaInstruction(jsonInstruction, description);
} else if (instruction instanceof ModOchSignalInstruction) {