ovs-docker: Add the ability to set the mac address.
authorGurucharan Shetty <gshetty@nicira.com>
Mon, 25 May 2015 07:50:01 +0000 (00:50 -0700)
committerGurucharan Shetty <gshetty@nicira.com>
Wed, 27 May 2015 15:06:05 +0000 (08:06 -0700)
For testing OVN, it is useful to set the mac address
of the container. Since ovs-docker hasn't been part
of any released versions of OVS, it is probably OK
to change the options style.

Signed-off-by: Gurucharan Shetty <shettyg@nicira.com>
INSTALL.Docker.md
utilities/ovs-docker

index 6bd5660..b505a9b 100644 (file)
@@ -55,9 +55,13 @@ and then attaches it to the Open vSwitch bridge 'br-int'.  This is done by
 creating a veth pair.  One end of the interface becomes 'eth1' inside the
 container and the other end attaches to 'br-int'.
 
-The script also lets one to add an IP address to the interface.  e.g.:
+The script also lets one to add IP address, MAC address and Gateway address to
+the interface.  e.g.:
 
-`% ovs-docker add-port br-int eth1 $CONTAINER_ID 192.168.1.1/24`
+```
+% ovs-docker add-port br-int eth1 $CONTAINER_ID --ipaddress=192.168.1.2/24 \
+--macaddress=a2:c3:0d:49:7f:f8 --gateway=192.168.1.1
+```
 
 * A previously added network interface can be deleted.  e.g.:
 
index dd2aef1..12c3246 100755 (executable)
@@ -65,14 +65,34 @@ add_port () {
     BRIDGE="$1"
     INTERFACE="$2"
     CONTAINER="$3"
-    ADDRESS="$4"
-    GATEWAY="$5"
 
-    if [ "$#" -lt 3 ]; then
-        usage
+    if [ -z "$BRIDGE" ] || [ -z "$INTERFACE" ] || [ -z "$CONTAINER" ]; then
+        echo >&2 "$UTIL add-port: not enough arguments (use --help for help)"
         exit 1
     fi
 
+    shift 3
+    while [ $# -ne 0 ]; do
+        case $1 in
+            --ipaddress=*)
+                ADDRESS=`expr X"$1" : 'X[^=]*=\(.*\)'`
+                shift
+                ;;
+            --macaddress=*)
+                MACADDRESS=`expr X"$1" : 'X[^=]*=\(.*\)'`
+                shift
+                ;;
+            --gateway=*)
+                GATEWAY=`expr X"$1" : 'X[^=]*=\(.*\)'`
+                shift
+                ;;
+            *)
+                echo >&2 "$UTIL add-port: unknown option \"$1\""
+                exit 1
+                ;;
+        esac
+    done
+
     # Check if a port is already attached for the given container and interface
     PORT=`get_port_for_container_interface "$CONTAINER" "$INTERFACE" \
             2>/dev/null`
@@ -121,6 +141,10 @@ add_port () {
         ip netns exec "$PID" ip addr add "$ADDRESS" dev "$INTERFACE"
     fi
 
+    if [ -n "$MACADDRESS" ]; then
+        ip netns exec "$PID" ip link set dev "$INTERFACE" address "$MACADDRESS"
+    fi
+
     if [ -n "$GATEWAY" ]; then
         ip netns exec "$PID" ip route add default via "$GATEWAY"
     fi
@@ -190,14 +214,16 @@ ${UTIL}: Performs integration of Open vSwitch with Docker.
 usage: ${UTIL} COMMAND
 
 Commands:
-  add-port BRIDGE INTERFACE CONTAINER [ADDRESS [GATEWAY]]
+  add-port BRIDGE INTERFACE CONTAINER [--ipaddress="ADDRESS"]
+                    [--gateway=GATEWAY] [--macaddress="MACADDRESS"]
                     Adds INTERFACE inside CONTAINER and connects it as a port
                     in Open vSwitch BRIDGE. Optionally, sets ADDRESS on
                     INTERFACE. ADDRESS can include a '/' to represent network
-                    prefix length. Along with ADDRESS, optionally set the
-                    default gateway for the container. e.g.:
-                    ${UTIL} add-port br-int eth1 c474a0e2830e 192.168.1.2/24 \
-                        192.168.1.1
+                    prefix length. Optionally, sets a GATEWAY and a MACADDRESS.
+                    e.g.:
+                    ${UTIL} add-port br-int eth1 c474a0e2830e
+                    --ipaddress=192.168.1.2/24 --gateway=192.168.1.1
+                    --macaddress="a2:c3:0d:49:7f:f8"
   del-port BRIDGE INTERFACE CONTAINER
                     Deletes INTERFACE inside CONTAINER and removes its
                     connection to Open vSwitch BRIDGE. e.g.: