return ((to >= 0) && (to <= 0xffff));
}
+ public boolean isProtocolValid(String protocol) {
+ int protocol_number = IPProtocols.getProtocolNumberInt(protocol);
+ if (protocol_number < 1 || protocol_number > 255) {
+ return false;
+ }
+ return true;
+ }
+
private Status conflictWithContainerFlow(IContainer container) {
// Return true if it's default container
if (container.getName().equals(GlobalConstants.DEFAULT.toString())) {
}
}
+ if ((protocol != null) && !isProtocolValid(protocol)) {
+ return new Status(StatusCode.BADREQUEST, String.format("Protocol %s is not valid", protocol));
+ }
+
if ((tosBits != null) && !isTOSBitsValid(tosBits)) {
return new Status(StatusCode.BADREQUEST, String.format("IP ToS bits %s is not in the range 0 - 63",
tosBits));
WESP("WESP",141),
ROHC("ROHC",142);
*/
- private static final String regexNumberString = "^[0-9]+$";
+ private static final String regexDecimalString = "^[0-9]{3}$";
+ private static final String regexHexString = "^(0(x|X))[0-9a-fA-F]{2}$";
private String protocolName;
private int protocolNumber;
}
public static short getProtocolNumberShort(String name) {
- if (name.matches(regexNumberString)) {
+ if (name.matches(regexHexString)) {
+ return Short.valueOf(Short.decode(name));
+ }
+ if (name.matches(regexDecimalString)) {
return Short.valueOf(name);
}
for (IPProtocols proto : IPProtocols.values()) {
}
public static int getProtocolNumberInt(String name) {
- if (name.matches(regexNumberString)) {
+ if (name.matches(regexHexString)) {
+ return Integer.valueOf(Integer.decode(name));
+ }
+ if (name.matches(regexDecimalString)) {
return Integer.valueOf(name);
}
for (IPProtocols proto : IPProtocols.values()) {
}
public static byte getProtocolNumberByte(String name) {
- if (name.matches(regexNumberString)) {
+ if (name.matches(regexHexString)) {
+ return Integer.valueOf(Integer.decode(name)).byteValue();
+ }
+ if (name.matches(regexDecimalString)) {
return Integer.valueOf(name).byteValue();
}
for (IPProtocols proto : IPProtocols.values()) {