Throw exception if dscp value is not byte.

Change-Id: Iae005dda9f28fb28f1bcc9ea5de31f1bf2c65843
This commit is contained in:
Rory Savage 2020-02-18 14:35:50 -05:00 committed by Thomas Vachuska
parent bdf39a7560
commit daeb949506
4 changed files with 17 additions and 3 deletions

View File

@ -487,11 +487,11 @@ public final class Instructions {
/** /**
* Creates an IP DSCP modification. * 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 * @return a L3 modification
*/ */
public static Instruction modIpDscp(byte dscpValue) { public static Instruction modIpDscp(byte ipDscp) {
return new L3ModificationInstruction.ModDscpInstruction(L3SubType.IP_DSCP, dscpValue); return new L3ModificationInstruction.ModDscpInstruction(L3SubType.IP_DSCP, ipDscp);
} }
/** /**

View File

@ -178,6 +178,13 @@ public final class DecodeInstructionCodecHelper {
return Instructions.copyTtlOut(); return Instructions.copyTtlOut();
} else if (subType.equals(L3ModificationInstruction.L3SubType.DEC_TTL.name())) { } else if (subType.equals(L3ModificationInstruction.L3SubType.DEC_TTL.name())) {
return Instructions.decNwTtl(); 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 " throw new IllegalArgumentException("L3 Instruction subtype "
+ subType + " is not supported"); + subType + " is not supported");

View File

@ -207,6 +207,12 @@ public final class EncodeInstructionCodecHelper {
(L3ModificationInstruction.ModIPv6FlowLabelInstruction) l3Instruction; (L3ModificationInstruction.ModIPv6FlowLabelInstruction) l3Instruction;
result.put(InstructionCodec.FLOW_LABEL, modFlowLabelInstruction.flowLabel()); result.put(InstructionCodec.FLOW_LABEL, modFlowLabelInstruction.flowLabel());
break; break;
case IP_DSCP:
final L3ModificationInstruction.ModDscpInstruction
modDscpInstruction =
(L3ModificationInstruction.ModDscpInstruction) l3Instruction;
result.put(InstructionCodec.IP_DSCP, modDscpInstruction.dscp());
break;
case TTL_IN: case TTL_IN:
case TTL_OUT: case TTL_OUT:
case DEC_TTL: case DEC_TTL:

View File

@ -40,6 +40,7 @@ public final class InstructionCodec extends JsonCodec<Instruction> {
static final String MPLS_LABEL = "label"; static final String MPLS_LABEL = "label";
static final String MPLS_BOS = "bos"; static final String MPLS_BOS = "bos";
static final String IP = "ip"; static final String IP = "ip";
static final String IP_DSCP = "ipDscp";
static final String FLOW_LABEL = "flowLabel"; static final String FLOW_LABEL = "flowLabel";
static final String LAMBDA = "lambda"; static final String LAMBDA = "lambda";
static final String GRID_TYPE = "gridType"; static final String GRID_TYPE = "gridType";