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=3ec9f8443a1264063ef79c4f192c0a9c9ea727ca;hb=aed009bd999c94f0b82cba822f6eb1936616c832;hp=ba69c8a3d29f8286f2d4f3157f6547a8f54c717b;hpb=d07c39a5f9e77c8e6f4293ee23eae53b7d6b525c;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 ba69c8a3d2..3ec9f8443a 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 @@ -13,7 +13,6 @@ import java.net.Inet6Address; import java.net.InetAddress; import java.util.ArrayList; import java.util.List; -import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -26,6 +25,7 @@ import org.opendaylight.controller.sal.action.Action; import org.opendaylight.controller.sal.action.ActionType; import org.opendaylight.controller.sal.action.Controller; import org.opendaylight.controller.sal.action.Drop; +import org.opendaylight.controller.sal.action.Enqueue; import org.opendaylight.controller.sal.action.Flood; import org.opendaylight.controller.sal.action.HwPath; import org.opendaylight.controller.sal.action.Loopback; @@ -188,13 +188,13 @@ public class FlowConfig implements Serializable { public boolean installInHw() { if (installInHw == null) { // backward compatibility - installInHw = "true"; + installInHw = Boolean.toString(true); } - return installInHw.equals("true"); + return Boolean.valueOf(installInHw); } public void setInstallInHw(boolean inHw) { - installInHw = inHw ? "true" : "false"; + installInHw = String.valueOf(inHw); } public String getInstallInHw() { @@ -609,25 +609,13 @@ public class FlowConfig implements Serializable { return true; } - public boolean isPortValid(Switch sw, Short port) { - if (port < 1) { - log.debug("port {} is not valid", port); - return false; - } - + public boolean isPortValid(Switch sw, String port) { if (sw == null) { log.debug("switch info is not available. Skip checking if port is part of a switch or not."); return true; } - - Set nodeConnectorSet = sw.getNodeConnectors(); - for (NodeConnector nodeConnector : nodeConnectorSet) { - if (((Short) nodeConnector.getID()).equals(port)) { - return true; - } - } - log.debug("port {} is not a valid port of node {}", port, sw.getNode()); - return false; + NodeConnector nc = NodeConnectorCreator.createNodeConnector(port, sw.getNode()); + return sw.getNodeConnectors().contains(nc); } public boolean isVlanIdValid(String vlanId) { @@ -655,6 +643,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())) { @@ -730,9 +723,8 @@ public class FlowConfig implements Serializable { } if (ingressPort != null) { - Short port = Short.decode(ingressPort); - if (isPortValid(sw, port) == false) { - String msg = String.format("Ingress port %d is not valid for the Switch", port); + if (!isPortValid(sw, ingressPort)) { + String msg = String.format("Ingress port %s is not valid for the Switch", ingressPort); if (!containerName.equals(GlobalConstants.DEFAULT.toString())) { msg += " in Container " + containerName; } @@ -762,6 +754,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)); @@ -840,17 +836,30 @@ public class FlowConfig implements Serializable { 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 (t != null) { + if (!isPortValid(sw, t)) { + String msg = String.format("Output port %s is not valid for this switch", t); + if (!containerName.equals(GlobalConstants.DEFAULT.toString())) { + msg += " in Container " + containerName; } + return new Status(StatusCode.BADREQUEST, msg); + } + } + } + continue; + } + // check enqueue + sstr = Pattern.compile("ENQUEUE=(.*)").matcher(actiongrp); + if (sstr.matches()) { + for (String t : sstr.group(1).split(",")) { + if (t != null) { + String port = t.split(":")[0]; + if (!isPortValid(sw, port)) { + 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); } } } @@ -978,7 +987,7 @@ public class FlowConfig implements Serializable { if (this.ingressPort != null) { match.setField(MatchType.IN_PORT, - NodeConnectorCreator.createOFNodeConnector(Short.parseShort(ingressPort), getNode())); + NodeConnector.fromString(String.format("%s|%s@%s", node.getType(), ingressPort, node.toString()))); } if (this.dlSrc != null) { match.setField(MatchType.DL_SRC, HexEncode.bytesFromHexString(this.dlSrc)); @@ -1021,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) { @@ -1063,7 +1072,7 @@ public class FlowConfig implements Serializable { } public void toggleInstallation() { - installInHw = (installInHw == null) ? "true" : (installInHw.equals("true")) ? "false" : "true"; + installInHw = (installInHw == null) ? Boolean.toString(false) : Boolean.toString(!Boolean.valueOf(installInHw)); } /* @@ -1080,12 +1089,25 @@ public class FlowConfig implements Serializable { sstr = Pattern.compile(ActionType.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 ofPort = Short.parseShort(n.group(1)); - actionList.add(new Output(NodeConnectorCreator.createOFNodeConnector(ofPort, - this.getNode()))); + if (t != null) { + String nc = String.format("%s|%s@%s", node.getType(), t, node.toString()); + actionList.add(new Output(NodeConnector.fromString(nc))); + } + } + continue; + } + + sstr = Pattern.compile(ActionType.ENQUEUE + "=(.*)").matcher(actiongrp); + if (sstr.matches()) { + for (String t : sstr.group(1).split(",")) { + if (t != null) { + String parts[] = t.split(":"); + String nc = String.format("%s|%s@%s", node.getType(), parts[0], node.toString()); + if (parts.length == 1) { + actionList.add(new Enqueue(NodeConnector.fromString(nc))); + } else { + actionList + .add(new Enqueue(NodeConnector.fromString(nc), Integer.parseInt(parts[1]))); } } }