update sliver-ovs to new ovsdb syntax
[sliver-openvswitch.git] / planetlab / scripts / sliver-ovs.in
index 3e060d1..edda196 100755 (executable)
@@ -67,10 +67,10 @@ function wait_server () {
 }
 
 function wait_device () {
-    tapname=$1; shift
-    timeout=$1; shift
+    local tapname=$1; shift
+    local timeout=$1; shift
 
-    expire=$(($(date +%s) + $timeout))
+    local expire=$(($(date +%s) + $timeout))
 
     while ! ip link show up | egrep -q "^[0-9]+: +$tapname:"; do
        echo "Waiting for $tapname to come UP...$(($expire - $(date +%s)))s left" >&2
@@ -100,10 +100,10 @@ function start_db () {
     if [ ! -f "$RUN_DIR/ovsdb-server.pid" ]; then
        ovsdb-server $DB_CONF_FILE \
            --remote=punix:$DB_SOCKET \
-           --remote=db:Open_vSwitch,manager_options \
-           --private-key=db:SSL,private_key \
-           --certificate=db:SSL,certificate \
-           --bootstrap-ca-cert=db:SSL,ca_cert \
+           --remote=db:Open_vSwitch,Open_vSwitch,manager_options \
+           --private-key=db:Open_vSwitch,SSL,private_key \
+           --certificate=db:Open_vSwitch,SSL,certificate \
+           --bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert \
            --pidfile \
            --log-file=$DB_LOG \
            --detach >& /dev/null
@@ -177,6 +177,12 @@ function create_bridge () {
        -- set bridge "$bridge" datapath_type=planetlab \
        -- set interface "$bridge" options:local_ip="$IP" option:local_netmask="$PREFIX" \
        -- "$@"
+
+    # check that the bridge has actually been created
+    if [ -z "$W" ]; then
+           local tap=$(ovs-appctl netdev-pltap/get-tapname "$bridge")
+           wait_device $tap 10
+    fi
 }
 
 function create_port () {
@@ -196,6 +202,16 @@ function create_port () {
         -- set interface "$port" type=tunnel
 }
 
+function get_local_endpoint () {
+
+    get_params "local_port" "$@"
+
+    is_switch_running || { echo "ovs-vswitchd not running" >&2; exit 1; }
+
+    set -e
+    ovs-appctl --target=ovs-vswitchd netdev-tunnel/get-port "$local_port"
+}
+
 function set_remote_endpoint () {
 
     get_params "local_port remote_ip remote_UDP_port" "$@"
@@ -276,6 +292,35 @@ function show () {
     ovs-vsctl --db=unix:$DB_SOCKET show
 }
 
+function get_local_ip () {
+
+    get_params "bridge" "$@"
+
+    set -e
+    ovs-vsctl --db=unix:$DB_SOCKET br-exists "$bridge" || return
+    local ip=$(ovs-vsctl get interface "$bridge" options:local_ip)
+    local netmask=$(ovs-vsctl get interface "$bridge" options:local_netmask)
+    eval echo $ip/$netmask
+}
+
+function get_local_links () {
+
+    get_params "bridge" "$@"
+
+    set -e
+    ovs-vsctl --db=unix:$DB_SOCKET br-exists "$bridge" || return
+    ovs-vsctl --db=unix:$DB_SOCKET list-ifaces "$bridge"
+}
+
+function get_mac () {
+
+    get_params "bridge" "$@"
+
+    set -e
+    local tap=$(ovs-appctl netdev-pltap/get-tapname "$bridge")
+    ifconfig "$tap" | awk '/HWaddr/ { print $5 }'
+}
+
 ### for demos - connect to an ndnmap deployment to visualize links bandwidth
 # this expects 3 arguments
 # an interface name, L<id1>-<id2> based on your ids in conf.mk
@@ -327,7 +372,9 @@ function gmap_probe () {
 SUPPORTED_SUBCOMMANDS="start stop status 
 start_db stop_db start_switch stop_switch
 create_bridge create_port del_bridge del_port
-show set_remote_endpoint set_controller del_controller gmap_probe"
+show get_local_endpoint set_remote_endpoint
+set_controller del_controller gmap_probe
+get_local_ip get_local_links get_mac"
 
 function main () {
        message="Usage: $COMMAND <subcommand> ...