ONOS-2578 Added codec for mod tcp/udp port instructions
Change-Id: Iab1eac26afe47e0b1c13ce94e152826b0828e455
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 6927680..8a4dfa5 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
@@ -22,6 +22,7 @@
import org.onosproject.net.flow.instructions.L0ModificationInstruction;
import org.onosproject.net.flow.instructions.L2ModificationInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction;
+import org.onosproject.net.flow.instructions.L4ModificationInstruction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -168,6 +169,36 @@
}
/**
+ * Encode a L4 modification instruction.
+ *
+ * @param result json node that the instruction attributes are added to
+ */
+ private void encodeL4(ObjectNode result) {
+ L4ModificationInstruction instruction =
+ (L4ModificationInstruction) this.instruction;
+ result.put(InstructionCodec.SUBTYPE, instruction.subtype().name());
+ switch (instruction.subtype()) {
+ case TCP_DST:
+ case TCP_SRC:
+ final L4ModificationInstruction.ModTransportPortInstruction modTcpPortInstruction =
+ (L4ModificationInstruction.ModTransportPortInstruction) instruction;
+ result.put(InstructionCodec.TCP_PORT, modTcpPortInstruction.port().toInt());
+ break;
+
+ case UDP_DST:
+ case UDP_SRC:
+ final L4ModificationInstruction.ModTransportPortInstruction modUdpPortInstruction =
+ (L4ModificationInstruction.ModTransportPortInstruction) instruction;
+ result.put(InstructionCodec.UDP_PORT, modUdpPortInstruction.port().toInt());
+ break;
+
+ default:
+ log.info("Cannot convert L4 subtype of {}", instruction.subtype());
+ break;
+ }
+ }
+
+ /**
* Encodes the given instruction into JSON.
*
* @return JSON object node representing the instruction
@@ -198,6 +229,10 @@
encodeL3(result);
break;
+ case L4MODIFICATION:
+ encodeL4(result);
+ break;
+
default:
log.info("Cannot convert instruction type of {}", instruction.type());
break;