Support to encode and decode group id in InstructionCodec
Change-Id: Icd0947f494f572831e8b5c8d82d47c85eb074824
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/DecodeInstructionCodecHelper.java b/core/common/src/main/java/org/onosproject/codec/impl/DecodeInstructionCodecHelper.java
index 105924e..57e73ed 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/DecodeInstructionCodecHelper.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/DecodeInstructionCodecHelper.java
@@ -22,6 +22,8 @@
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onlab.util.HexString;
+import org.onosproject.core.DefaultGroupId;
+import org.onosproject.core.GroupId;
import org.onosproject.net.ChannelSpacing;
import org.onosproject.net.GridType;
import org.onosproject.net.Lambda;
@@ -261,6 +263,10 @@
} else if (type.equals(Instruction.Type.TABLE.name())) {
return Instructions.transition(nullIsIllegal(json.get(InstructionCodec.TABLE_ID)
.asInt(), InstructionCodec.TABLE_ID + InstructionCodec.MISSING_MEMBER_MESSAGE));
+ } else if (type.equals(Instruction.Type.GROUP.name())) {
+ GroupId groupId = new DefaultGroupId(nullIsIllegal(json.get(InstructionCodec.GROUP_ID)
+ .asInt(), InstructionCodec.GROUP_ID + InstructionCodec.MISSING_MEMBER_MESSAGE));
+ return Instructions.createGroup(groupId);
} else if (type.equals(Instruction.Type.L0MODIFICATION.name())) {
return decodeL0();
} else if (type.equals(Instruction.Type.L1MODIFICATION.name())) {
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/EncodeInstructionCodecHelper.java b/core/common/src/main/java/org/onosproject/codec/impl/EncodeInstructionCodecHelper.java
index 5db7c6d..eccbddb 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/EncodeInstructionCodecHelper.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/EncodeInstructionCodecHelper.java
@@ -15,6 +15,7 @@
*/
package org.onosproject.codec.impl;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onlab.util.HexString;
import org.onosproject.codec.CodecContext;
import org.onosproject.net.OchSignal;
@@ -29,8 +30,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
/**
* JSON encoding of Instructions.
*/
@@ -249,6 +248,12 @@
case NOACTION:
break;
+ case GROUP:
+ final Instructions.GroupInstruction groupInstruction =
+ (Instructions.GroupInstruction) instruction;
+ result.put(InstructionCodec.GROUP_ID, groupInstruction.groupId().toString());
+ break;
+
case L0MODIFICATION:
encodeL0(result);
break;
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/InstructionCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/InstructionCodec.java
index 0b5e8ad..ab60909 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/InstructionCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/InstructionCodec.java
@@ -50,6 +50,7 @@
protected static final String TCP_PORT = "tcpPort";
protected static final String UDP_PORT = "udpPort";
protected static final String TABLE_ID = "tableId";
+ protected static final String GROUP_ID = "groupId";
protected static final String TRIBUTARY_PORT_NUMBER = "tributaryPortNumber";
protected static final String TRIBUTARY_SLOT_LEN = "tributarySlotLength";
protected static final String TRIBUTARY_SLOT_BITMAP = "tributarySlotBitmap";