Charles Chan
Committed by Gerrit Code Review

Support more instruction type in EncodeInstructionCodecHelper

Change-Id: Ifb790f0b1e2afb0396633034d1f6d62a120a9a46
......@@ -125,25 +125,21 @@ public final class EncodeInstructionCodecHelper {
(L2ModificationInstruction.ModEtherInstruction) l2Instruction;
result.put(InstructionCodec.MAC, modEtherInstruction.mac().toString());
break;
case VLAN_ID:
final L2ModificationInstruction.ModVlanIdInstruction modVlanIdInstruction =
(L2ModificationInstruction.ModVlanIdInstruction) l2Instruction;
result.put(InstructionCodec.VLAN_ID, modVlanIdInstruction.vlanId().toShort());
break;
case VLAN_PCP:
final L2ModificationInstruction.ModVlanPcpInstruction modVlanPcpInstruction =
(L2ModificationInstruction.ModVlanPcpInstruction) l2Instruction;
result.put(InstructionCodec.VLAN_PCP, modVlanPcpInstruction.vlanPcp());
break;
case MPLS_LABEL:
final L2ModificationInstruction.ModMplsLabelInstruction modMplsLabelInstruction =
(L2ModificationInstruction.ModMplsLabelInstruction) l2Instruction;
result.put(InstructionCodec.MPLS_LABEL, modMplsLabelInstruction.label().toInt());
break;
case MPLS_PUSH:
final L2ModificationInstruction.PushHeaderInstructions pushHeaderInstructions =
(L2ModificationInstruction.PushHeaderInstructions) l2Instruction;
......@@ -151,13 +147,18 @@ public final class EncodeInstructionCodecHelper {
result.put(InstructionCodec.ETHERNET_TYPE,
pushHeaderInstructions.ethernetType().toShort());
break;
case TUNNEL_ID:
final L2ModificationInstruction.ModTunnelIdInstruction modTunnelIdInstruction =
(L2ModificationInstruction.ModTunnelIdInstruction) l2Instruction;
result.put(InstructionCodec.TUNNEL_ID, modTunnelIdInstruction.tunnelId());
break;
case MPLS_BOS:
final L2ModificationInstruction.ModMplsBosInstruction modMplsBosInstruction =
(L2ModificationInstruction.ModMplsBosInstruction) l2Instruction;
result.put(InstructionCodec.MPLS_BOS, modMplsBosInstruction.mplsBos());
case MPLS_POP:
case DEC_MPLS_TTL:
break;
default:
log.info("Cannot convert L2 subtype of {}", l2Instruction.subtype());
break;
......@@ -181,14 +182,16 @@ public final class EncodeInstructionCodecHelper {
(L3ModificationInstruction.ModIPInstruction) l3Instruction;
result.put(InstructionCodec.IP, modIPInstruction.ip().toString());
break;
case IPV6_FLABEL:
final L3ModificationInstruction.ModIPv6FlowLabelInstruction
modFlowLabelInstruction =
(L3ModificationInstruction.ModIPv6FlowLabelInstruction) l3Instruction;
result.put(InstructionCodec.FLOW_LABEL, modFlowLabelInstruction.flowLabel());
break;
case TTL_IN:
case TTL_OUT:
case DEC_TTL:
break;
default:
log.info("Cannot convert L3 subtype of {}", l3Instruction.subtype());
break;
......@@ -210,14 +213,12 @@ public final class EncodeInstructionCodecHelper {
(L4ModificationInstruction.ModTransportPortInstruction) l4Instruction;
result.put(InstructionCodec.TCP_PORT, modTcpPortInstruction.port().toInt());
break;
case UDP_DST:
case UDP_SRC:
final L4ModificationInstruction.ModTransportPortInstruction modUdpPortInstruction =
(L4ModificationInstruction.ModTransportPortInstruction) l4Instruction;
result.put(InstructionCodec.UDP_PORT, modUdpPortInstruction.port().toInt());
break;
default:
log.info("Cannot convert L4 subtype of {}", l4Instruction.subtype());
break;
......@@ -225,6 +226,16 @@ public final class EncodeInstructionCodecHelper {
}
/**
* Encode a extension instruction.
*
* @param result json node that the instruction attributes are added to
*/
private void encodeExtension(ObjectNode result) {
// TODO Support extension in REST API
log.info("Cannot convert instruction type of EXTENSION");
}
/**
* Encodes the given instruction into JSON.
*
* @return JSON object node representing the instruction
......@@ -283,6 +294,10 @@ public final class EncodeInstructionCodecHelper {
encodeL4(result);
break;
case EXTENSION:
encodeExtension(result);
break;
default:
log.info("Cannot convert instruction type of {}", instruction.type());
break;
......
......@@ -38,6 +38,7 @@ public final class InstructionCodec extends JsonCodec<Instruction> {
protected static final String VLAN_ID = "vlanId";
protected static final String VLAN_PCP = "vlanPcp";
protected static final String MPLS_LABEL = "label";
protected static final String MPLS_BOS = "bos";
protected static final String IP = "ip";
protected static final String FLOW_LABEL = "flowLabel";
protected static final String LAMBDA = "lambda";
......