X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fforwardingrulesmanager%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fforwardingrulesmanager%2FFlowConfig.java;h=e0b8e9a786878fe6af6b67dd04aeee52958118db;hb=65ab4ccadb216b12d773ec4113ae241be30d3eb7;hp=0304af493d9fe64abab2df516bc5b3c2e63c098c;hpb=36737d75a800d7646f140b3b58b1a47aa8d8c993;p=controller.git diff --git a/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowConfig.java b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowConfig.java index 0304af493d..e0b8e9a786 100644 --- a/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowConfig.java +++ b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowConfig.java @@ -655,6 +655,11 @@ public class FlowConfig implements Serializable { return ((to >= 0) && (to <= 0xffff)); } + public boolean isProtocolValid(String protocol) { + IPProtocols proto = IPProtocols.fromString(protocol); + return (proto != null); + } + private Status conflictWithContainerFlow(IContainer container) { // Return true if it's default container if (container.getName().equals(GlobalConstants.DEFAULT.toString())) { @@ -762,6 +767,10 @@ public class FlowConfig implements Serializable { } } + 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)); @@ -832,127 +841,128 @@ public class FlowConfig implements Serializable { } Matcher sstr; - if (actions != null && !actions.isEmpty()) { - for (String actiongrp : actions) { - // check output ports - sstr = Pattern.compile("OUTPUT=(.*)").matcher(actiongrp); - if (sstr.matches()) { - for (String t : sstr.group(1).split(",")) { - Matcher n = Pattern.compile("(?:(\\d+))").matcher(t); - if (n.matches()) { - if (n.group(1) != null) { - Short port = Short.parseShort(n.group(1)); - if (isPortValid(sw, port) == false) { - String msg = String.format("Output port %d is not valid for this switch", port); - if (!containerName.equals(GlobalConstants.DEFAULT.toString())) { - msg += " in Container " + containerName; - } - return new Status(StatusCode.BADREQUEST, msg); + if (actions == null || actions.isEmpty()) { + return new Status(StatusCode.BADREQUEST, "Actions value is null or empty"); + } + for (String actiongrp : actions) { + // check output ports + sstr = Pattern.compile("OUTPUT=(.*)").matcher(actiongrp); + if (sstr.matches()) { + for (String t : sstr.group(1).split(",")) { + Matcher n = Pattern.compile("(?:(\\d+))").matcher(t); + if (n.matches()) { + if (n.group(1) != null) { + Short port = Short.parseShort(n.group(1)); + if (isPortValid(sw, port) == false) { + String msg = String.format("Output port %d is not valid for this switch", port); + if (!containerName.equals(GlobalConstants.DEFAULT.toString())) { + msg += " in Container " + containerName; } + return new Status(StatusCode.BADREQUEST, msg); } } } - continue; } - // Check src IP - sstr = Pattern.compile(ActionType.FLOOD.toString()).matcher(actiongrp); - if (sstr.matches()) { - if (!containerName.equals(GlobalConstants.DEFAULT.toString())) { - return new Status(StatusCode.BADREQUEST, String.format( - "flood is not allowed in container %s", containerName)); - } - continue; + continue; + } + // Check src IP + sstr = Pattern.compile(ActionType.FLOOD.toString()).matcher(actiongrp); + if (sstr.matches()) { + if (!containerName.equals(GlobalConstants.DEFAULT.toString())) { + return new Status(StatusCode.BADREQUEST, String.format( + "flood is not allowed in container %s", containerName)); } - // Check src IP - sstr = Pattern.compile(ActionType.SET_NW_SRC.toString() + "=(.*)").matcher(actiongrp); - if (sstr.matches()) { - if (!NetUtils.isIPv4AddressValid(sstr.group(1))) { - return new Status(StatusCode.BADREQUEST, String.format("IP source address %s is not valid", - sstr.group(1))); - } - continue; + continue; + } + // Check src IP + sstr = Pattern.compile(ActionType.SET_NW_SRC.toString() + "=(.*)").matcher(actiongrp); + if (sstr.matches()) { + if (!NetUtils.isIPv4AddressValid(sstr.group(1))) { + return new Status(StatusCode.BADREQUEST, String.format("IP source address %s is not valid", + sstr.group(1))); } - // Check dst IP - sstr = Pattern.compile(ActionType.SET_NW_DST.toString() + "=(.*)").matcher(actiongrp); - if (sstr.matches()) { - if (!NetUtils.isIPv4AddressValid(sstr.group(1))) { - return new Status(StatusCode.BADREQUEST, String.format( - "IP destination address %s is not valid", sstr.group(1))); - } - continue; + continue; + } + // Check dst IP + sstr = Pattern.compile(ActionType.SET_NW_DST.toString() + "=(.*)").matcher(actiongrp); + if (sstr.matches()) { + if (!NetUtils.isIPv4AddressValid(sstr.group(1))) { + return new Status(StatusCode.BADREQUEST, String.format( + "IP destination address %s is not valid", sstr.group(1))); } + continue; + } - sstr = Pattern.compile(ActionType.SET_VLAN_ID.toString() + "=(.*)").matcher(actiongrp); - if (sstr.matches()) { - if ((sstr.group(1) != null) && !isVlanIdValid(sstr.group(1))) { - return new Status(StatusCode.BADREQUEST, String.format( - "Vlan ID %s is not in the range 0 - 4095", sstr.group(1))); - } - continue; + sstr = Pattern.compile(ActionType.SET_VLAN_ID.toString() + "=(.*)").matcher(actiongrp); + if (sstr.matches()) { + if ((sstr.group(1) != null) && !isVlanIdValid(sstr.group(1))) { + return new Status(StatusCode.BADREQUEST, String.format( + "Vlan ID %s is not in the range 0 - 4095", sstr.group(1))); } + continue; + } - sstr = Pattern.compile(ActionType.SET_VLAN_PCP.toString() + "=(.*)").matcher(actiongrp); - if (sstr.matches()) { - if ((sstr.group(1) != null) && !isVlanPriorityValid(sstr.group(1))) { - return new Status(StatusCode.BADREQUEST, String.format( - "Vlan priority %s is not in the range 0 - 7", sstr.group(1))); - } - continue; + sstr = Pattern.compile(ActionType.SET_VLAN_PCP.toString() + "=(.*)").matcher(actiongrp); + if (sstr.matches()) { + if ((sstr.group(1) != null) && !isVlanPriorityValid(sstr.group(1))) { + return new Status(StatusCode.BADREQUEST, String.format( + "Vlan priority %s is not in the range 0 - 7", sstr.group(1))); } + continue; + } - sstr = Pattern.compile(ActionType.SET_DL_SRC.toString() + "=(.*)").matcher(actiongrp); - if (sstr.matches()) { - if ((sstr.group(1) != null) && !isL2AddressValid(sstr.group(1))) { - return new Status(StatusCode.BADREQUEST, String.format( - "Ethernet source address %s is not valid. Example: 00:05:b9:7c:81:5f", - sstr.group(1))); - } - continue; + sstr = Pattern.compile(ActionType.SET_DL_SRC.toString() + "=(.*)").matcher(actiongrp); + if (sstr.matches()) { + if ((sstr.group(1) != null) && !isL2AddressValid(sstr.group(1))) { + return new Status(StatusCode.BADREQUEST, String.format( + "Ethernet source address %s is not valid. Example: 00:05:b9:7c:81:5f", + sstr.group(1))); } - sstr = Pattern.compile(ActionType.SET_DL_DST.toString() + "=(.*)").matcher(actiongrp); - if (sstr.matches()) { - if ((sstr.group(1) != null) && !isL2AddressValid(sstr.group(1))) { - return new Status(StatusCode.BADREQUEST, String.format( - "Ethernet destination address %s is not valid. Example: 00:05:b9:7c:81:5f", - sstr.group(1))); - } - continue; + continue; + } + sstr = Pattern.compile(ActionType.SET_DL_DST.toString() + "=(.*)").matcher(actiongrp); + if (sstr.matches()) { + if ((sstr.group(1) != null) && !isL2AddressValid(sstr.group(1))) { + return new Status(StatusCode.BADREQUEST, String.format( + "Ethernet destination address %s is not valid. Example: 00:05:b9:7c:81:5f", + sstr.group(1))); } + continue; + } - sstr = Pattern.compile(ActionType.SET_NW_TOS.toString() + "=(.*)").matcher(actiongrp); - if (sstr.matches()) { - if ((sstr.group(1) != null) && !isTOSBitsValid(sstr.group(1))) { - return new Status(StatusCode.BADREQUEST, String.format( - "IP ToS bits %s is not in the range 0 - 63", sstr.group(1))); - } - continue; + sstr = Pattern.compile(ActionType.SET_NW_TOS.toString() + "=(.*)").matcher(actiongrp); + if (sstr.matches()) { + if ((sstr.group(1) != null) && !isTOSBitsValid(sstr.group(1))) { + return new Status(StatusCode.BADREQUEST, String.format( + "IP ToS bits %s is not in the range 0 - 63", sstr.group(1))); } + continue; + } - sstr = Pattern.compile(ActionType.SET_TP_SRC.toString() + "=(.*)").matcher(actiongrp); - if (sstr.matches()) { - if ((sstr.group(1) != null) && !isTpPortValid(sstr.group(1))) { - return new Status(StatusCode.BADREQUEST, String.format( - "Transport source port %s is not valid", sstr.group(1))); - } - continue; + sstr = Pattern.compile(ActionType.SET_TP_SRC.toString() + "=(.*)").matcher(actiongrp); + if (sstr.matches()) { + if ((sstr.group(1) != null) && !isTpPortValid(sstr.group(1))) { + return new Status(StatusCode.BADREQUEST, String.format( + "Transport source port %s is not valid", sstr.group(1))); } + continue; + } - sstr = Pattern.compile(ActionType.SET_TP_DST.toString() + "=(.*)").matcher(actiongrp); - if (sstr.matches()) { - if ((sstr.group(1) != null) && !isTpPortValid(sstr.group(1))) { - return new Status(StatusCode.BADREQUEST, String.format( - "Transport destination port %s is not valid", sstr.group(1))); - } - continue; + sstr = Pattern.compile(ActionType.SET_TP_DST.toString() + "=(.*)").matcher(actiongrp); + if (sstr.matches()) { + if ((sstr.group(1) != null) && !isTpPortValid(sstr.group(1))) { + return new Status(StatusCode.BADREQUEST, String.format( + "Transport destination port %s is not valid", sstr.group(1))); } - sstr = Pattern.compile(ActionType.SET_NEXT_HOP.toString() + "=(.*)").matcher(actiongrp); - if (sstr.matches()) { - if (!NetUtils.isIPAddressValid(sstr.group(1))) { - return new Status(StatusCode.BADREQUEST, String.format( - "IP destination address %s is not valid", sstr.group(1))); - } - continue; + continue; + } + sstr = Pattern.compile(ActionType.SET_NEXT_HOP.toString() + "=(.*)").matcher(actiongrp); + if (sstr.matches()) { + if (!NetUtils.isIPAddressValid(sstr.group(1))) { + return new Status(StatusCode.BADREQUEST, String.format( + "IP destination address %s is not valid", sstr.group(1))); } + continue; } } // Check against the container flow @@ -1020,7 +1030,7 @@ public class FlowConfig implements Serializable { mask = NetUtils.getInetNetworkMask(maskLen, ip instanceof Inet6Address); match.setField(MatchType.NW_DST, ip, mask); } - if (this.protocol != null) { + if (IPProtocols.fromString(this.protocol) != IPProtocols.ANY) { match.setField(MatchType.NW_PROTO, IPProtocols.getProtocolNumberByte(this.protocol)); } if (this.tosBits != null) {