[ovs-dev] [PATCH 3/3] ovs-docker: Add the ability to set VLANs.

Gurucharan Shetty shettyg at nicira.com
Fri Dec 12 09:56:24 UTC 2014


For containers containing multiple ports and spawned by
orchestrators without openflow flows configured, it can be quite
useful to distinguish their traffic with vlans. This can be useful
when containers are spawned inside VMs instead of hypervisors.

Signed-off-by: Gurucharan Shetty <gshetty at nicira.com>
---
 utilities/ovs-docker | 47 ++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 42 insertions(+), 5 deletions(-)

diff --git a/utilities/ovs-docker b/utilities/ovs-docker
index 6b17b87..1f121b7 100755
--- a/utilities/ovs-docker
+++ b/utilities/ovs-docker
@@ -42,6 +42,20 @@ delete_netns_link () {
     rm -f /var/run/netns/"$PID"
 }
 
+get_port_for_container_interface () {
+    CONTAINER="$1"
+    INTERFACE="$2"
+
+    PORT=`ovs_vsctl --data=bare --no-heading --columns=name find interface \
+             external_ids:container_id="$CONTAINER"  \
+             external_ids:container_iface="$INTERFACE"`
+    if [ -z "$PORT" ]; then
+        echo >&2 "$UTIL: Failed to find any attached port" \
+                 "for CONTAINER=$CONTAINER and INTERFACE=$INTERFACE"
+    fi
+    echo "$PORT"
+}
+
 add_port () {
     BRIDGE="$1"
     INTERFACE="$2"
@@ -97,6 +111,24 @@ add_port () {
     fi
 }
 
+add_vlan () {
+    BRIDGE="$1"
+    INTERFACE="$2"
+    CONTAINER_ID="$3"
+    VLAN="$4"
+
+    if [ "$#" -lt 4 ]; then
+        usage
+        exit 1
+    fi
+
+    PORT=`get_port_for_container_interface "$CONTAINER_ID" "$INTERFACE"`
+    if [ -z "$PORT" ]; then
+        exit 1
+    fi
+    ovs_vsctl set port "$PORT" tag="$VLAN"
+}
+
 del_port () {
     BRIDGE="$1"
     INTERFACE="$2"
@@ -107,12 +139,8 @@ del_port () {
         exit 1
     fi
 
-    PORT=`ovs_vsctl --data=bare --no-heading --columns=name find interface \
-             external_ids:container_id="$CONTAINER"  \
-             external_ids:container_iface="$INTERFACE"`
+    PORT=`get_port_for_container_interface "$CONTAINER" "$INTERFACE"`
     if [ -z "$PORT" ]; then
-        echo >&2 "$UTIL: Failed to find any attached port in $BRIDGE" \
-                 "for CONTAINER=$CONTAINER and INTERFACE=$INTERFACE"
         exit 1
     fi
 
@@ -155,6 +183,10 @@ Commands:
                     default gateway for the container. e.g.:
                     ${UTIL} add-port br-int eth1 c474a0e2830e 192.168.1.2/24 \
                         192.168.1.1
+  add-vlan BRIDGE INTERFACE CONTAINER VLAN
+                    Configures the INTERFACE of CONTAINER attached to BRIDGE
+                    to become a access port of VLAN. e.g.:
+                    ${UTIL} add-vlan br-int eth1 c474a0e2830e 5
   del-port BRIDGE INTERFACE CONTAINER
                     Deletes INTERFACE inside CONTAINER and removes its
                     connection to Open vSwitch BRIDGE. e.g.:
@@ -187,6 +219,11 @@ case $1 in
         add_port "$@"
         exit 0
         ;;
+    "add-vlan")
+        shift
+        add_vlan "$@"
+        exit 0
+        ;;
     "del-port")
         shift
         del_port "$@"
-- 
1.9.1




More information about the dev mailing list