system-common-macros: Enhance ADD_VETH to take mac and gateway.
authorGurucharan Shetty <guru@ovn.org>
Mon, 11 Jul 2016 09:55:59 +0000 (02:55 -0700)
committerGurucharan Shetty <guru@ovn.org>
Wed, 13 Jul 2016 15:04:51 +0000 (08:04 -0700)
It is useful to set the mac address and gateway while using ADD_VETH
to connect a namespace to a OVN logical topology. Upcoming commits
use this enhancement.

Signed-off-by: Gurucharan Shetty <guru@ovn.org>
Acked-by: Joe Stringer <joe@ovn.org>
tests/system-common-macros.at

index 1e3219c..27fceed 100644 (file)
@@ -56,7 +56,7 @@ m4_define([ADD_INT],
     ]
 )
 
-# ADD_VETH([port], [namespace], [ovs-br], [ip_addr])
+# ADD_VETH([port], [namespace], [ovs-br], [ip_addr] [mac_addr [gateway]])
 #
 # Add a pair of veth ports. 'port' will be added to name space 'namespace',
 # and "ovs-'port'" will be added to ovs bridge 'ovs-br'.
@@ -64,6 +64,9 @@ m4_define([ADD_INT],
 # The 'port' in 'namespace' will be brought up with static IP address
 # with 'ip_addr' in CIDR notation.
 #
+# Optionally, one can specify the 'mac_addr' for 'port' and the default
+# 'gateway'.
+#
 # The existing 'port' or 'ovs-port' will be removed before new ones are added.
 #
 m4_define([ADD_VETH],
@@ -74,6 +77,12 @@ m4_define([ADD_VETH],
       AT_CHECK([ovs-vsctl add-port $3 ovs-$1])
       NS_CHECK_EXEC([$2], [ip addr add $4 dev $1])
       NS_CHECK_EXEC([$2], [ip link set dev $1 up])
+      if test -n "$5"; then
+        NS_CHECK_EXEC([$2], [ip link set dev $1 address $5])
+      fi
+      if test -n "$6"; then
+        NS_CHECK_EXEC([$2], [ip route add default via $6])
+      fi
       on_exit 'ip link del ovs-$1'
     ]
 )