Add vlan to container flow (container flow-spec) 54/2254/2
authorAlessandro Boch <aboch@cisco.com>
Tue, 29 Oct 2013 17:30:35 +0000 (10:30 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 29 Oct 2013 21:58:44 +0000 (21:58 +0000)
Change-Id: If18530dc407e3fc64329d8aa251b148b30bd5a8e
Signed-off-by: Alessandro Boch <aboch@cisco.com>
opendaylight/containermanager/api/src/main/java/org/opendaylight/controller/containermanager/ContainerFlowConfig.java
opendaylight/northbound/containermanager/src/main/java/org/opendaylight/controller/containermanager/northbound/ContainerManagerNorthbound.java

index 2520172d8959a62f5a7fb2af37826c0a27a59dd9..c9b5dab8080f36d96a301db894845abafa1ca028 100644 (file)
@@ -55,6 +55,10 @@ public class ContainerFlowConfig implements Serializable {
     @XmlElement
     private String name;
 
+    /** The vlan. */
+    @XmlElement
+    private String dlVlan;
+
     /** The network Source. */
     @XmlElement
     private String nwSrc;
@@ -101,6 +105,7 @@ public class ContainerFlowConfig implements Serializable {
     public ContainerFlowConfig(String name, String srcIP, String dstIP, String proto, String srcPort,
             String dstPort) {
         this.name = name;
+        this.dlVlan = null;
         this.nwSrc = srcIP;
         this.nwDst = dstIP;
         this.protocol = proto;
@@ -112,6 +117,7 @@ public class ContainerFlowConfig implements Serializable {
 
     public ContainerFlowConfig(ContainerFlowConfig containerFlowConfig) {
         this.name = containerFlowConfig.name;
+        this.dlVlan = containerFlowConfig.dlVlan;
         this.nwSrc = containerFlowConfig.nwSrc;
         this.nwDst = containerFlowConfig.nwDst;
         this.protocol = containerFlowConfig.protocol;
@@ -130,6 +136,15 @@ public class ContainerFlowConfig implements Serializable {
         return name;
     }
 
+    /**
+     * Returns the vlan id.
+     *
+     * @return the Vlan Id
+     */
+    public String getVlan() {
+        return (dlVlan == null || dlVlan.isEmpty()) ? null : dlVlan;
+    }
+
     /**
      * Returns the Source IP Address.
      *
@@ -192,6 +207,7 @@ public class ContainerFlowConfig implements Serializable {
         result = prime * result
                 + ((protocol == null) ? 0 : protocol.hashCode());
         result = prime * result + ((name == null) ? 0 : name.hashCode());
+        result = prime * result + ((dlVlan == null) ? 0 : dlVlan.hashCode());
         result = prime * result + ((nwDst == null) ? 0 : nwDst.hashCode());
         result = prime * result + ((tpDst == null) ? 0 : tpDst.hashCode());
         result = prime * result + ((nwSrc == null) ? 0 : nwSrc.hashCode());
@@ -221,7 +237,7 @@ public class ContainerFlowConfig implements Serializable {
             return false;
         }
         ContainerFlowConfig other = (ContainerFlowConfig) obj;
-        if (matchName(other) && matchSrcIP(other)
+        if (matchName(other) && matchDlVlan(other) && matchSrcIP(other)
                 && matchDstIP(other) && matchProtocol(other)
                 && matchSrcPort(other) && matchDstPort(other)) {
             return true;
@@ -280,6 +296,21 @@ public class ContainerFlowConfig implements Serializable {
         return name.equals(flowSpec.name);
     }
 
+    /**
+     * Match Source IP Address.
+     *
+     * @param flowSpec Flow Specification
+     * @return true, if successful
+     */
+    private boolean matchDlVlan(ContainerFlowConfig flowSpec) {
+        if (dlVlan == flowSpec.dlVlan) {
+            return true;
+        }
+        if (dlVlan == null || flowSpec.dlVlan == null) {
+            return false;
+        }
+        return dlVlan.equals(flowSpec.dlVlan);
+    }
 
     /**
      * Match Source IP Address.
@@ -361,6 +392,21 @@ public class ContainerFlowConfig implements Serializable {
         return this.tpDst.equals(flowSpec.tpDst);
     }
 
+    /**
+     * Returns the vlan id number
+     *
+     * @return the vlan id number
+     */
+    public Short getVlanId() {
+        Short vlan = 0;
+        try {
+            vlan = Short.parseShort(dlVlan);
+        } catch (NumberFormatException e) {
+
+        }
+        return vlan;
+    }
+
     /**
      * Returns the Source IP Address mask length.
      *
@@ -522,7 +568,11 @@ public class ContainerFlowConfig implements Serializable {
         if (!hasValidName()) {
             return new Status(StatusCode.BADREQUEST, "Invalid name");
         }
-        Status status = validateIPs();
+        Status status = validateVlan();
+        if (!status.isSuccess()) {
+            return status;
+        }
+        status = validateIPs();
         if (!status.isSuccess()) {
             return status;
         }
@@ -547,6 +597,26 @@ public class ContainerFlowConfig implements Serializable {
         return (name != null && !name.isEmpty() && name.matches(regexName));
     }
 
+    /**
+     * Validates the vlan number
+     *
+     * @return the result of the check as Status object
+     */
+    private Status validateVlan() {
+        if (dlVlan != null) {
+            short vlanId = 0;
+            try {
+                vlanId = Short.parseShort(dlVlan);
+            } catch (NumberFormatException e) {
+                return new Status(StatusCode.BADREQUEST, "Invalid vlan id");
+            }
+            if (vlanId < 0 || vlanId > 0xfff) {
+                return new Status(StatusCode.BADREQUEST, "Invalid vlan id");
+            }
+        }
+        return new Status(StatusCode.SUCCESS);
+    }
+
     /**
      * Validates the network addresses, checks syntax and semantic
      *
index 77c3004c76b6928fb57631ffd1a4c99e4740a067..518fc4692f0d6e11c7a24a0f0551803791708945 100644 (file)
@@ -9,7 +9,6 @@
 
 package org.opendaylight.controller.containermanager.northbound;
 
-import java.security.Principal;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -364,6 +363,7 @@ public class ContainerManagerNorthbound {
      * Response body in XML:
      * &lt;flow-spec-config&gt;
      *  &#x20;&#x20;&#x20;&#x20;&lt;name&gt;ssh&lt;/name&gt;
+     *  &#x20;&#x20;&#x20;&#x20;&lt;dlVlan&gt;52&lt;/dlVlan&gt;
      *  &#x20;&#x20;&#x20;&#x20;&lt;nwSrc&gt;10.0.0.101&lt;/nwSrc&gt;
      *  &#x20;&#x20;&#x20;&#x20;&lt;nwDst&gt;10.0.0.102&lt;/nwDst&gt;
      *  &#x20;&#x20;&#x20;&#x20;&lt;protocol&gt;IPv4&lt;/protocol&gt;
@@ -374,6 +374,7 @@ public class ContainerManagerNorthbound {
      * Response body in JSON:
      * {
      *    "protocol" : "IPv4",
+     *    "dlVlan" : "52",
      *    "nwDst" : "10.0.0.102",
      *    "name" : "ssh",
      *    "nwSrc" : "10.0.0.101",
@@ -429,6 +430,7 @@ public class ContainerManagerNorthbound {
      * &lt;flow-spec-configs&gt;
      *   &#x20;&#x20;&#x20;&#x20;&lt;flow-spec-config&gt;
      *     &#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&lt;name&gt;ssh&lt;/name&gt;
+     *     &#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&lt;dlVlan&gt;52&lt;/dlVlan&gt;
      *     &#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&lt;nwSrc&gt;10.0.0.101&lt;/nwSrc&gt;
      *     &#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&lt;nwDst&gt;10.0.0.102&lt;/nwDst&gt;
      *     &#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&lt;protocol&gt;IPv4&lt;/protocol&gt;
@@ -437,6 +439,7 @@ public class ContainerManagerNorthbound {
      *   &#x20;&#x20;&#x20;&#x20;&lt;/flow-spec-config&gt;
      *   &#x20;&#x20;&#x20;&#x20;&lt;flow-spec-config&gt;
      *     &#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&lt;name&gt;http2&lt;/name&gt;
+     *     &#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&lt;dlVlan&gt;123&lt;/dlVlan&gt;
      *     &#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&lt;nwSrc&gt;10.0.0.201&lt;/nwSrc&gt;
      *     &#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&lt;nwDst&gt;10.0.0.202&lt;/nwDst&gt;
      *     &#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&lt;protocol&gt;&lt;/protocol&gt;
@@ -450,6 +453,7 @@ public class ContainerManagerNorthbound {
      *   "flow-spec-config": [
      *     {
      *       "name": "http",
+     *       "dlVlan" : "52",
      *       "nwSrc": "10.0.0.201",
      *       "nwDst": "10.0.0.202",
      *       "protocol": "",
@@ -458,6 +462,7 @@ public class ContainerManagerNorthbound {
      *     },
      *     {
      *       "name": "ssh",
+     *       "dlVlan" : "123",
      *       "nwSrc": "10.0.0.101",
      *       "nwDst": "10.0.0.102",
      *       "protocol": "IPv4",
@@ -511,6 +516,7 @@ public class ContainerManagerNorthbound {
      * Request body in XML:
      *   &lt;flow-spec-config&gt;
      *     &#x20;&#x20;&#x20;&#x20;&lt;name&gt;http&lt;/name&gt;
+     *     &#x20;&#x20;&#x20;&#x20;&lt;dlVlan&gt;25&lt;/dlVlan&gt;
      *     &#x20;&#x20;&#x20;&#x20;&lt;nwSrc&gt;10.0.0.101&lt;/nwSrc&gt;
      *     &#x20;&#x20;&#x20;&#x20;&lt;nwDst&gt;10.0.0.102&lt;/nwDst&gt;
      *     &#x20;&#x20;&#x20;&#x20;&lt;protocol&gt;&lt;/protocol&gt;
@@ -520,10 +526,11 @@ public class ContainerManagerNorthbound {
      *
      * Request body in JSON:
      * {
-     *    "protocol" : "",
-     *    "nwDst" : "10.0.0.102",
      *    "name" : "http",
+     *    "dlVlan" : "25",
      *    "nwSrc" : "10.0.0.101",
+     *    "nwDst" : "10.0.0.102",
+     *    "protocol" : "",
      *    "tpSrc" : "80",
      *    "tpDst" : "100"
      * }