ONOS-3562 Changing the flow instructions port to human readable format

Change-Id: Ia6b1a755bc400295600f4112cb3ebe676e533eb2
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 14555b3..4878c17 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
@@ -240,9 +240,22 @@
         String type = json.get(InstructionCodec.TYPE).asText();
 
         if (type.equals(Instruction.Type.OUTPUT.name())) {
-            PortNumber portNumber =
-                    PortNumber.portNumber(nullIsIllegal(json.get(InstructionCodec.PORT),
-                            InstructionCodec.PORT + InstructionCodec.MISSING_MEMBER_MESSAGE).asLong());
+            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);
         } else if (type.equals(Instruction.Type.DROP.name())) {
             return Instructions.createDrop();
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 2ec301d..268d110 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
@@ -87,8 +87,6 @@
      * Encode an L1 modification instruction.
      *
      * @param result json node that the instruction attributes are added to
-     * @param instruction The L1 instruction
-     * @param context context of the request
      */
     private void encodeL1(ObjectNode result) {
         L1ModificationInstruction instruction =
@@ -244,7 +242,7 @@
             case OUTPUT:
                 final Instructions.OutputInstruction outputInstruction =
                         (Instructions.OutputInstruction) instruction;
-                result.put(InstructionCodec.PORT, outputInstruction.port().toLong());
+                result.put(InstructionCodec.PORT, outputInstruction.port().toString());
                 break;
 
             case DROP:
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 9ffb3c3..4c49d64 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
@@ -93,18 +93,31 @@
      */
     private boolean matchOutputInstruction(JsonNode instructionJson,
                                            Description description) {
-        OutputInstruction instructionToMatch = (OutputInstruction) instruction;
-
         final String jsonType = instructionJson.get("type").textValue();
+        OutputInstruction instructionToMatch = (OutputInstruction) instruction;
         if (!instructionToMatch.type().name().equals(jsonType)) {
             description.appendText("type was " + jsonType);
             return false;
         }
 
-        final long jsonPort = instructionJson.get("port").asLong();
-        if (instructionToMatch.port().toLong() != jsonPort) {
-            description.appendText("port was " + jsonPort);
-            return false;
+        if (instructionJson.get("port").isLong() ||
+                instructionJson.get("port").isInt()) {
+            final long jsonPort = instructionJson.get("port").asLong();
+            if (instructionToMatch.port().toLong() != (jsonPort)) {
+                description.appendText("port was " + jsonPort);
+                return false;
+            }
+        } else if (instructionJson.get("port").isTextual()) {
+            final String jsonPort = instructionJson.get("port").textValue();
+            if (!instructionToMatch.port().toString().equals(jsonPort)) {
+                description.appendText("port was " + jsonPort);
+                return false;
+            }
+        } else {
+            final String jsonPort = instructionJson.get("port").toString();
+            description.appendText("Unmathcing types ");
+            description.appendText("instructionToMatch " + instructionToMatch.port().toString());
+            description.appendText("jsonPort " + jsonPort);
         }
 
         return true;