Fix Connection manager to retrieve inventory when is up
[controller.git] / opendaylight / forwardingrulesmanager / api / src / main / java / org / opendaylight / controller / forwardingrulesmanager / FlowConfig.java
index 8a77825d7943c12e8be971687cb4f3e8ac187b72..0304af493d9fe64abab2df516bc5b3c2e63c098c 100644 (file)
@@ -71,9 +71,11 @@ import org.slf4j.LoggerFactory;
 public class FlowConfig implements Serializable {
     private static final long serialVersionUID = 1L;
     private static final Logger log = LoggerFactory.getLogger(FlowConfig.class);
-    public static final String staticFlowsGroup = "**StaticFlows";
-    public static final String internalStaticFlowsGroup = "**InternalStaticFlows";
-    public static final String internalStaticFlowBegin = "**";
+    private static final String NAMEREGEX = "^[a-zA-Z0-9]+$";
+    public static final String STATICFLOWGROUP = "__StaticFlows__";
+    public static final String INTERNALSTATICFLOWGROUP = "__InternalStaticFlows__";
+    public static final String INTERNALSTATICFLOWBEGIN = "__";
+    public static final String INTERNALSTATICFLOWEND = "__";
     private boolean dynamic;
     private String status;
 
@@ -200,8 +202,9 @@ public class FlowConfig implements Serializable {
     }
 
     public boolean isInternalFlow() {
-        // Controller generated static flows have name starting with "**"
-        return (this.name != null && this.name.startsWith(FlowConfig.internalStaticFlowBegin));
+        return (this.name != null &&
+                this.name.startsWith(FlowConfig.INTERNALSTATICFLOWBEGIN) &&
+                this.name.endsWith(FlowConfig.INTERNALSTATICFLOWEND));
     }
 
     public String getName() {
@@ -644,7 +647,7 @@ public class FlowConfig implements Serializable {
 
     public boolean isTpPortValid(String tpPort) {
         int port = Integer.decode(tpPort);
-        return ((port > 0) && (port <= 0xffff));
+        return ((port >= 0) && (port <= 0xffff));
     }
 
     public boolean isTimeoutValid(String timeout) {
@@ -692,7 +695,7 @@ public class FlowConfig implements Serializable {
 
         Switch sw = null;
         try {
-            if (name == null || name.trim().isEmpty()) {
+            if (name == null || name.trim().isEmpty() || !name.matches(FlowConfig.NAMEREGEX)) {
                 return new Status(StatusCode.BADREQUEST, "Invalid name");
             }
 
@@ -730,8 +733,8 @@ public class FlowConfig implements Serializable {
                 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 ((container != null) && !container.getName().equals(GlobalConstants.DEFAULT.toString())) {
-                        msg += " in Container " + container.getName();
+                    if (!containerName.equals(GlobalConstants.DEFAULT.toString())) {
+                        msg += " in Container " + containerName;
                     }
                     return new Status(StatusCode.BADREQUEST, msg);
                 }
@@ -841,9 +844,8 @@ public class FlowConfig implements Serializable {
                                     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 ((container != null)
-                                                && !container.getName().equals(GlobalConstants.DEFAULT.toString())) {
-                                            msg += " in Container " + container.getName();
+                                        if (!containerName.equals(GlobalConstants.DEFAULT.toString())) {
+                                            msg += " in Container " + containerName;
                                         }
                                         return new Status(StatusCode.BADREQUEST, msg);
                                     }
@@ -855,9 +857,9 @@ public class FlowConfig implements Serializable {
                     // Check src IP
                     sstr = Pattern.compile(ActionType.FLOOD.toString()).matcher(actiongrp);
                     if (sstr.matches()) {
-                        if (container != null) {
+                        if (!containerName.equals(GlobalConstants.DEFAULT.toString())) {
                             return new Status(StatusCode.BADREQUEST, String.format(
-                                    "flood is not allowed in container %s", container.getName()));
+                                    "flood is not allowed in container %s", containerName));
                         }
                         continue;
                     }
@@ -955,7 +957,7 @@ public class FlowConfig implements Serializable {
             }
             // Check against the container flow
             Status status;
-            if ((container != null) && !(status = conflictWithContainerFlow(container)).isSuccess()) {
+            if (!containerName.equals(GlobalConstants.DEFAULT.toString()) && !(status = conflictWithContainerFlow(container)).isSuccess()) {
                 return status;
             }
         } catch (NumberFormatException e) {
@@ -966,7 +968,8 @@ public class FlowConfig implements Serializable {
     }
 
     public FlowEntry getFlowEntry() {
-        return new FlowEntry(FlowConfig.staticFlowsGroup, this.name, this.getFlow(), this.getNode());
+        String group = this.isInternalFlow() ? FlowConfig.INTERNALSTATICFLOWGROUP : FlowConfig.STATICFLOWGROUP;
+        return new FlowEntry(group, this.name, this.getFlow(), this.getNode());
     }
 
     public Flow getFlow() {