From: Giuseppe Lettieri <g.lettieri@iet.unipi.it>
Date: Tue, 11 Sep 2012 07:56:29 +0000 (+0200)
Subject: add set-remote-endpoint action to sliver-ovs
X-Git-Tag: sliver-openvswitch-1.8.90-0~22
X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=9ceb2057ac7c99c87eb3ba0f3a2a6e01ef5abe62;p=sliver-openvswitch.git

add set-remote-endpoint action to sliver-ovs

Now all makefile targets call a sliver-ovs action.
This is required to centralize checks (is_{switch,db}_running and
possibly more to come) and to make all
sliver-openvwitch configuration variables (DB_SOCK and the like)
available to all actions.
---

diff --git a/planetlab/exp-tool/Makefile b/planetlab/exp-tool/Makefile
index d25a4400f..804918246 100644
--- a/planetlab/exp-tool/Makefile
+++ b/planetlab/exp-tool/Makefile
@@ -140,14 +140,14 @@ del-bridge.%: cache/db.%
 del-switch.%: del-bridge.%
 	@echo "Shutting down switch on $(call display,$*)"
 	@if [ -f cache/switch.$* ]; then \
-		$(SSH) $(HOST_$*) $(SUDO) ovs-appctl exit;\
+		$(SSH) $(HOST_$*) $(SUDO) sliver-ovs stop-switch
 	 fi
 	@rm -f cache/switch.$*
 
 del-db.%:
 	@echo "Shutting down db on $(call display,$*)"
 	@if [ -f cache/db.$* ]; then \
-		$(SSH) $(HOST_$*) $(SUDO) ovs-appctl --target=$(VARRUN)/ovsdb-server.$$(cat cache/db.$*).ctl exit;\
+		$(SSH) $(HOST_$*) $(SUDO) sliver-ovs stop-db
 	 fi
 	@rm -f cache/db.$*
 
@@ -193,9 +193,9 @@ cache/iface.%: cache/bridge.$$(call get,%)
 cache/link.%: cache/host.$$(call rget,$$*) cache/iface.% cache/iface.$$(call opp,$$*)
 	@echo "Setting port number of link $(call proj1,$*) on $(call get,$*)"
 	@$(SSH) $(HOST_$(call get,$*)) \
-		$(SUDO) ovs-vsctl set interface L$(call proj1,$*) \
-			options:remote_ip=$$(cat cache/host.$(call rget,$*)) \
-			options:remote_port=$$(cat cache/iface.$(call opp,$*)) \
+		$(SUDO) sliver-ovs set-remote-endpoint L$(call proj1,$*) \
+			$$(cat cache/host.$(call rget,$*)) \
+			$$(cat cache/iface.$(call opp,$*)) \
 	 && touch $@
 
 ####################
diff --git a/planetlab/scripts/sliver-ovs b/planetlab/scripts/sliver-ovs
index 44ad3f969..5b888bd18 100755
--- a/planetlab/scripts/sliver-ovs
+++ b/planetlab/scripts/sliver-ovs
@@ -188,6 +188,7 @@ EOF
 
 function create_port () {
 
+    [[ -z "$@" ]] || error "$COMMAND create-port <bridge> <port>"
     bridge=$1; shift
     [[ -z "$@" ]] || error "$COMMAND create-port <bridge> <port>"
     port=$1; shift
@@ -204,6 +205,26 @@ function create_port () {
     return 0
 }
 
+function set_remote_endpoint () {
+
+    [[ -z "$@" ]] || error "$COMMAND set-remote-endpoint <local_port> <remote_ip> <remote_UDP_port>"
+    port=$1; shift
+    [[ -z "$@" ]] || error "$COMMAND set-remote-endpoint <local_port> <remote_ip> <remote_UDP_port>"
+    remote_ip=$1; shift
+    [[ -z "$@" ]] || error "$COMMAND set-remote-endpoint <local_port> <remote_ip> <remote_UDP_port>"
+    remote_port=$1; shift
+    [[ -n "$@" ]] || error "$COMMAND set-remote-endpoint <local_port> <remote_ip> <remote_UDP_port>"
+
+    # ensure ovs-vswitchd is running
+    is_switch_running || { echo "ovs-vswitchd not running" >&2 ; exit 1 ; }
+
+    set -e
+    ovs-vsctl --db=unix:$DB_SOCKET set interface "$port" \
+        options:remote_ip=$remote_ip \
+	options:remote_port=$remote_port
+    return 0
+}
+
 #################### del functions
 function del_bridge () {
     
@@ -248,7 +269,8 @@ function del_port () {
 ####################
 SUPPORTED_SUBCOMMANDS="start stop status 
 start_db stop_db start_switch stop_switch
-create_bridge create_port del_bridge del_port"
+create_bridge create_port del_bridge del_port
+set-remote-endpoint"
 
 function main () {
 	message="Usage: $COMMAND <subcommand> ...