Throw exception if dscp value is not byte.
Change-Id: Iae005dda9f28fb28f1bcc9ea5de31f1bf2c65843
diff --git a/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java b/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
index e0c58d3..d1fc61f 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
@@ -487,11 +487,11 @@
/**
* Creates an IP DSCP modification.
*
- * @param dscpValue the DSCP value to modify to
+ * @param ipDscp the DSCP value to modify to
* @return a L3 modification
*/
- public static Instruction modIpDscp(byte dscpValue) {
- return new L3ModificationInstruction.ModDscpInstruction(L3SubType.IP_DSCP, dscpValue);
+ public static Instruction modIpDscp(byte ipDscp) {
+ return new L3ModificationInstruction.ModDscpInstruction(L3SubType.IP_DSCP, ipDscp);
}
/**
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 2730c38..8ad11f1 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
@@ -178,6 +178,13 @@
return Instructions.copyTtlOut();
} else if (subType.equals(L3ModificationInstruction.L3SubType.DEC_TTL.name())) {
return Instructions.decNwTtl();
+ } else if (subType.equals(L3ModificationInstruction.L3SubType.IP_DSCP.name())) {
+ int ipDscp = nullIsIllegal(json.get(InstructionCodec.IP_DSCP),
+ InstructionCodec.IP_DSCP + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt();
+ if ((ipDscp < Byte.MIN_VALUE) || (ipDscp > Byte.MAX_VALUE)) {
+ throw new IllegalArgumentException("Value " + ipDscp + " must be single byte");
+ }
+ return Instructions.modIpDscp((byte) ipDscp);
}
throw new IllegalArgumentException("L3 Instruction subtype "
+ subType + " is not supported");
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 0f3c125..102b9ca 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
@@ -207,6 +207,12 @@
(L3ModificationInstruction.ModIPv6FlowLabelInstruction) l3Instruction;
result.put(InstructionCodec.FLOW_LABEL, modFlowLabelInstruction.flowLabel());
break;
+ case IP_DSCP:
+ final L3ModificationInstruction.ModDscpInstruction
+ modDscpInstruction =
+ (L3ModificationInstruction.ModDscpInstruction) l3Instruction;
+ result.put(InstructionCodec.IP_DSCP, modDscpInstruction.dscp());
+ break;
case TTL_IN:
case TTL_OUT:
case DEC_TTL:
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 df7ff1c..ca2df49 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
@@ -40,6 +40,7 @@
static final String MPLS_LABEL = "label";
static final String MPLS_BOS = "bos";
static final String IP = "ip";
+ static final String IP_DSCP = "ipDscp";
static final String FLOW_LABEL = "flowLabel";
static final String LAMBDA = "lambda";
static final String GRID_TYPE = "gridType";