From: Giuseppe Lettieri Date: Tue, 11 Sep 2012 13:36:45 +0000 (+0200) Subject: Merge branch 'master' of ssh://git.onelab.eu/git/sliver-openvswitch X-Git-Tag: sliver-openvswitch-1.8.90-0~16 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=a03fa095f61bf789af770dff2616ab382327b470;hp=4a40a064745e87fad6c6b16b38b41394ed3ac743;p=sliver-openvswitch.git Merge branch 'master' of ssh://git.onelab.eu/git/sliver-openvswitch Conflicts: planetlab/exp-tool/Makefile planetlab/scripts/sliver-ovs --- diff --git a/planetlab/exp-tool/Makefile b/planetlab/exp-tool/Makefile index c89f197b3..ae2700866 100644 --- a/planetlab/exp-tool/Makefile +++ b/planetlab/exp-tool/Makefile @@ -206,9 +206,9 @@ cache/iface.%: cache/bridge.$$(call get,%) # iface2=cache/iface.$(call opp,%) cache/link.%: cache/host.$$(call get,%) cache/iface.% cache/iface.$$(call opp,%) @echo "Setting port number of link $(call linkpart,$(*F)) on $(call display,$(call get,$(*F))) - logs in $@.log" - @$(SSH) $(call solve,$(call get,$(*F))) $(SUDO) ovs-vsctl set interface L$(call linkpart,$(*F)) \ - options:remote_ip=$$(cat cache/host.$(call get,$(*F))) \ - options:remote_port=$$(cat cache/iface.$(call opp,$(*F))) 2> $@.log \ + @$(SSH) $(call solve,$(call get,$(*F))) $(SUDO) sliver-ovs set-remote-endpoint L$(call linkpart,$(*F)) \ + $$(cat cache/host.$(call rget,$(*F))) \ + $$(cat cache/iface.$(call opp,$(*F))) 2> $@.log \ && touch $@ #################### diff --git a/planetlab/scripts/sliver-ovs b/planetlab/scripts/sliver-ovs index 6a7319843..87f173e2b 100755 --- a/planetlab/scripts/sliver-ovs +++ b/planetlab/scripts/sliver-ovs @@ -30,10 +30,25 @@ function error { exit 1 } +function get_params { + params=$1; shift + err_msg="$COMMAND $SUBCOMMAND $(echo $params | perl -pe 's/\S+/<$&>/g')" + for p in $(echo $params); do + [[ -z "$@" ]] && error "$err_msg" + pname=$(echo -n $p|perl -pe 's/\W/_/g') + eval $pname="$1"; shift + done + [[ -n "$@" ]] && error "$err_msg" +} + function is_switch_running { ovs-appctl --target=$SWITCH_SOCKET version >& /dev/null } +function is_db_running { + ovs-appctl --target=$DB_CTRL_SOCKET version >& /dev/null +} + function tapname () { IP=$1; shift echo $(ip addr show to "$IP/32" | perl -ne '/^\s*\d+:\s*([\w-]+):/ && print $1') @@ -71,8 +86,7 @@ function wait_device () { ######################################## startup function start_db () { - - [[ -n "$@" ]] && error "Usage: $COMMAND start-db" + get_params "" "$@" ## init conf conf_dir=$(dirname $DB_CONF_FILE) @@ -95,6 +109,7 @@ function start_db () { --bootstrap-ca-cert=db:SSL,ca_cert \ --pidfile=$DB_PID_FILE \ --log-file=$DB_LOG \ + --unixctl=$DB_CTRL_SOCKET \ --detach >& /dev/null else echo 'ovsdb-server appears to be running already, *not* starting' @@ -104,8 +119,10 @@ function start_db () { } function start_switch () { + get_params "" "$@" - [[ -n "$@" ]] && error "Usage: $COMMAND start-switch" + # ensure ovsdb-server is running + is_db_running || { echo "ovsdb-server not running" >&2 ; exit 1 ; } if [ ! -f "$SWITCH_PID_FILE" ] ; then ovs-vswitchd \ @@ -150,12 +167,10 @@ function stop () { #################### create functions function create_bridge () { - [[ -z "$@" ]] && error "Usage: ${COMMAND} create-bridge " - ip_prefix=$1; shift - [[ -n "$@" ]] && error "Usage: ${COMMAND} create-bridge " + get_params "IP/PREFIX" "$@" - IP=${ip_prefix%/*} - PREFIX=${ip_prefix#*/} + IP=${IP_PREFIX%/*} + PREFIX=${IP_PREFIX#*/} set -e # ensure ovs-vswitchd is running @@ -174,6 +189,7 @@ function create_bridge () { # we're clear TAPNAME=$(pltap-ovs) + trap kill_pltap_ovs EXIT # xxx wouldn't that be safer if left-aligned ? vsysc vif_up << EOF $TAPNAME @@ -188,11 +204,10 @@ EOF function create_port () { - [[ -z "$@" ]] && error "$COMMAND create-port " - bridge=$1; shift - [[ -z "$@" ]] && error "$COMMAND create-port " - port=$1; shift - [[ -n "$@" ]] && error "$COMMAND create-port " + get_params "bridge port" "$@" + + # ensure ovs-vswitchd is running + is_switch_running || { echo "ovs-vswitchd not running" >&2 ; exit 1 ; } set -e if ! ovs-vsctl --db=unix:$DB_SOCKET list-ports "$bridge" | grep -q "^$port\$"; then @@ -202,15 +217,32 @@ function create_port () { return 0 } +function set_remote_endpoint () { + + get_params "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 $local_port \ + options:remote_ip=$remote_ip \ + options:remote_port=$remote_UDP_port + return 0 +} + #################### del functions function del_bridge () { - [[ -z "$@" ]] && error "Usage: ${COMMAND} del-bridge " - bridge_name=$1; shift - [[ -n "$@" ]] && error "Usage: ${COMMAND} del-bridge " + get_params "bridge_name" "$@" W= - is_switch_running || W="--no-wait" + if ! is_switch_running; then + # we can delete the bridge even if ovs-vswitchd is not running, + # but we need a running ovsdb-server + is_db_running || { echo "ovsdb-server not running" >&2; exit 1; } + W="--no-wait" + fi if ovs-vsctl --db=unix:$DB_SOCKET br-exists "$bridge_name"; then ovs-vsctl --db=unix:$DB_SOCKET $W del-br $bridge_name @@ -219,21 +251,38 @@ function del_bridge () { } function del_port () { - [[ -z "$@" ]] && error "Usage: ${COMMAND} del-port " - bridge_name=$1; shift - [[ -n "$@" ]] && error "Usage: ${COMMAND} del-port " + + get_params "port" "$@" + + W= + if ! is_switch_running; then + # we can delete the port even if ovs-vswitchd is not running, + # but we need a running ovsdb-server + is_db_running || { echo "ovsdb-server not running" >&2; exit 1; } + W="--no-wait" + fi set -e - if ovs-vsctl --db=unix:$DB_SOCKET port-to-br "$1" >/dev/null 2>&1; then - ovs-vsctl --db=unix:$DB_SOCKET del-port "$1" + if ovs-vsctl --db=unix:$DB_SOCKET port-to-br "$port" >/dev/null 2>&1; then + ovs-vsctl --db=unix:$DB_SOCKET $W del-port "$port" fi return 0 } +function show () { + + get_params "" "$@" + + is_db_running || { echo "ovsdb-server not running" >&2; exit 1; } + + ovs-vsctl --db=unix:$DB_SOCKET show +} + #################### 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 +show set_remote_endpoint" function main () { message="Usage: $COMMAND ... @@ -241,15 +290,15 @@ Supported subcommands are (dash or underscore is the same): $SUPPORTED_SUBCOMMANDS" [[ -z "$@" ]] && error "$message" - subcommand=$1; shift + SUBCOMMAND=$1; shift # support dashes instead of underscores - subcommand=$(echo $subcommand | sed -e s,-,_,) + SUBCOMMAND=$(echo $SUBCOMMAND | sed -e s,-,_,g) found="" - for supported in $SUPPORTED_SUBCOMMANDS; do [ "$subcommand" = "$supported" ] && found=yes; done + for supported in $SUPPORTED_SUBCOMMANDS; do [ "$SUBCOMMAND" = "$supported" ] && found=yes; done [ -z "$found" ] && error $message - $subcommand "$@" + $SUBCOMMAND "$@" } main "$@"