Support to encode and decode setqueue id in InstructionCodec

Change-Id: I911e14b750d5264755687a9eff322502ba9ed118
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 20d6fac..c8b6f26 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
@@ -233,6 +233,32 @@
     }
 
     /**
+     * Extracts port number of the given json node.
+     *
+     * @param jsonNode json node
+     * @return port number
+     */
+    private PortNumber getPortNumber(ObjectNode jsonNode) {
+        PortNumber portNumber;
+        if (jsonNode.get(InstructionCodec.PORT).isLong() || jsonNode.get(InstructionCodec.PORT).isInt()) {
+            portNumber = PortNumber
+                    .portNumber(nullIsIllegal(jsonNode.get(InstructionCodec.PORT)
+                            .asLong(), InstructionCodec.PORT
+                            + InstructionCodec.MISSING_MEMBER_MESSAGE));
+        } else if (jsonNode.get(InstructionCodec.PORT).isTextual()) {
+            portNumber = PortNumber
+                    .fromString(nullIsIllegal(jsonNode.get(InstructionCodec.PORT)
+                            .textValue(), InstructionCodec.PORT
+                            + InstructionCodec.MISSING_MEMBER_MESSAGE));
+        } else {
+            throw new IllegalArgumentException("Port value "
+                    + jsonNode.get(InstructionCodec.PORT).toString()
+                    + " is not supported");
+        }
+        return portNumber;
+    }
+
+    /**
      * Decodes the JSON into an instruction object.
      *
      * @return Criterion object
@@ -242,23 +268,7 @@
         String type = json.get(InstructionCodec.TYPE).asText();
 
         if (type.equals(Instruction.Type.OUTPUT.name())) {
-            PortNumber portNumber;
-            if (json.get(InstructionCodec.PORT).isLong() || json.get(InstructionCodec.PORT).isInt()) {
-                portNumber = PortNumber
-                        .portNumber(nullIsIllegal(json.get(InstructionCodec.PORT)
-                                                          .asLong(), InstructionCodec.PORT
-                                                          + InstructionCodec.MISSING_MEMBER_MESSAGE));
-            } else if (json.get(InstructionCodec.PORT).isTextual()) {
-                portNumber = PortNumber
-                        .fromString(nullIsIllegal(json.get(InstructionCodec.PORT)
-                                                          .textValue(), InstructionCodec.PORT
-                                                          + InstructionCodec.MISSING_MEMBER_MESSAGE));
-            } else {
-                throw new IllegalArgumentException("Port value "
-                                                           + json.get(InstructionCodec.PORT).toString()
-                                                           + " is not supported");
-            }
-            return Instructions.createOutput(portNumber);
+            return Instructions.createOutput(getPortNumber(json));
         } else if (type.equals(Instruction.Type.NOACTION.name())) {
             return Instructions.createNoAction();
         } else if (type.equals(Instruction.Type.TABLE.name())) {
@@ -272,6 +282,10 @@
             MeterId meterId = MeterId.meterId(nullIsIllegal(json.get(InstructionCodec.METER_ID)
                     .asLong(), InstructionCodec.METER_ID + InstructionCodec.MISSING_MEMBER_MESSAGE));
             return Instructions.meterTraffic(meterId);
+        } else if (type.equals(Instruction.Type.QUEUE.name())) {
+            long queueId = nullIsIllegal(json.get(InstructionCodec.QUEUE_ID)
+                    .asLong(), InstructionCodec.QUEUE_ID + InstructionCodec.MISSING_MEMBER_MESSAGE);
+            return Instructions.setQueue(queueId, getPortNumber(json));
         } 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 fc6935d..e025475 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
@@ -256,6 +256,13 @@
                 result.put(InstructionCodec.METER_ID, meterInstruction.meterId().toString());
                 break;
 
+            case QUEUE:
+                final Instructions.SetQueueInstruction setQueueInstruction =
+                        (Instructions.SetQueueInstruction) instruction;
+                result.put(InstructionCodec.QUEUE_ID, setQueueInstruction.queueId());
+                result.put(InstructionCodec.PORT, setQueueInstruction.port().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 2d646b0..7e1c96a 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
@@ -52,6 +52,7 @@
     protected static final String TABLE_ID = "tableId";
     protected static final String GROUP_ID = "groupId";
     protected static final String METER_ID = "meterId";
+    protected static final String QUEUE_ID = "queueId";
     protected static final String TRIBUTARY_PORT_NUMBER = "tributaryPortNumber";
     protected static final String TRIBUTARY_SLOT_LEN = "tributarySlotLength";
     protected static final String TRIBUTARY_SLOT_BITMAP = "tributarySlotBitmap";