From 6d3d3c72dc24ba730488a0e84e3083436460ed57 Mon Sep 17 00:00:00 2001 From: Giuseppe Lettieri Date: Fri, 5 Oct 2012 12:25:31 +0200 Subject: [PATCH] better handling of dependencies Now bridges and interfaces survive a shutdown of the daemons. Only port numbers are re-exchanged as needed on daemon restart. This also fixes the 'make -j shutdown' bug. Now, L/n1-n2 should mean that a link between node n1 and n2 has been established in the db *and* it is also up (i.e., the daemons are running). TODO: - there is some redundancy between start/stop and {del-,}{db,switch}s --- planetlab/exp-tool/Makefile | 58 ++++++++++++++++++++------------- planetlab/scripts/sliver-ovs.in | 13 +++++--- 2 files changed, 44 insertions(+), 27 deletions(-) diff --git a/planetlab/exp-tool/Makefile b/planetlab/exp-tool/Makefile index 8f5f29c31..d58e9f18f 100644 --- a/planetlab/exp-tool/Makefile +++ b/planetlab/exp-tool/Makefile @@ -155,18 +155,19 @@ cache/db.%: @echo "Starting db server on $(call display,$*) - logs in $(call log,$@)" @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs start-db &> $(call log,$@) && touch $@ -cache/switch.%: cache/db.% +cache/switch.%: | cache/db.% @echo "Starting vswitchd on $(call display,$*) - logs in $(call log,$@)" @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs start-switch &> $(call log,$@) && touch $@ -cache/bridge.%: cache/switch.% +cache/bridge.%: | cache/db.% @echo "Creating bridge on $(call display,$*) - logs in $(call log,$@)" - @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs create-bridge $(BRIDGE) $(IP_$*) > $@ 2> $(call log,$@) || { rm $@; exit 1; } - @echo Created bridge with tap $$(cat $@) on $(call display,$*) + @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs create-bridge $(BRIDGE) $(IP_$*) &> $(call log,$@) \ + && touch $@ cache/controller.%: cache/bridge.% @echo "Setting controller $(call default,CONTROLLER,$*) on $(call display,$*) - logs in $(call log,$@)" - @$(SSH) $(HOST_$*) $(SUDO) ovs-vsctl set-controller $(BRIDGE) $(call default,CONTROLLER,$*) &> $(call log,$@) || { rm $@; exit 1; } + @$(SSH) $(HOST_$*) $(SUDO) ovs-vsctl set-controller $(BRIDGE) $(call default,CONTROLLER,$*) &> $(call log,$@) \ + && touch $@ # xxx this probably needs a more thorough cleanup in cache/ cache/stop.%: del-bridge.% @@ -175,42 +176,46 @@ cache/stop.%: del-bridge.% ### link-oriented targets # L/- -L/%: cache/link.%@1 cache/link.%@2 +L/%: cache/endpoint.%@1 cache/endpoint.%@2 @touch $@ - @echo "Created link $*" + @echo "Link $* is up" U/%: del-iface.%@1 del-iface.%@2 @rm -f L/$* @echo "Deleted link $*" -del-bridge.%: cache/db.% +del-bridge.%: | cache/db.% @echo "Deleting bridge on $(call display,$*)" @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs del-bridge $(BRIDGE); @rm -f cache/bridge.$* \ cache/iface.$*$(SEP)*@1 cache/iface.*$(SEP)$*@2 \ - cache/link.$*$(SEP)*@? cache/link.*$(SEP)$*@? \ + cache/port.$*$(SEP)*@1 cache/port.*$(SEP)$*@2 \ + cache/endpoint.$*$(SEP)*@? cache/endpoint.*$(SEP)$*@? \ L/$*$(SEP)* L/*$(SEP)$* -del-switch.%: del-bridge.% +del-switch.%: @echo "Shutting down switch on $(call display,$*)" @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs stop-switch - @rm -f cache/switch.$* + @rm -f cache/switch.$* \ + cache/port.$*$(SEP)*@1 cache/port.*$(SEP)$*@2 \ + cache/endpoint.$*$(SEP)*@2 cache/endpoint.*$(SEP)$*@1 \ + L/$*$(SEP)* L/*$(SEP)$* del-db.%: @echo "Shutting down db on $(call display,$*)" @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs stop-db @rm -f cache/db.$* -del-controller-%: +del-controller-%: | cache/db.% @echo "Removing controller for $(call display,$*)" @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs del-controller $(BRIDGE) @rm -f cache/controller.$* -del-links: $(addprefix U/,$(notdir $(filter-out %.log,$(wildcard L/*)))) +del-links: $(addprefix U/,$(notdir $(wildcard L/*))) -del-switchs: $(addprefix del-,$(notdir $(filter-out %.log,$(wildcard cache/switch.*)))) +del-switchs: $(addprefix del-,$(notdir $(wildcard cache/switch.*))) -del-dbs: $(addprefix del-,$(notdir $(filter-out %.log,$(wildcard cache/db.*)))) +del-dbs: $(addprefix del-,$(notdir $(wildcard cache/db.*))) shutdown: del-switchs del-dbs @@ -253,11 +258,11 @@ cache/rsnap.links.%: .SECONDEXPANSION: -del-iface.%: cache/db.$$(call get,%) +del-iface.%: @echo "Removing interface for link $(call linkpart,$*) from $(call get,$*)" @$(SSH) $(HOST_$(call get,$*)) \ $(SUDO) sliver-ovs del-port L$(call linkpart,$*) - @rm -f cache/iface.$* cache/link.$* cache/link.$(call opp,$*) + @rm -f cache/iface.$* cache/port.$* cache/endpoint.$* cache/endpoint.$(call opp,$*) ### '%' here is leftid-rightid@{1,2} @@ -265,25 +270,32 @@ del-iface.%: cache/db.$$(call get,%) #linkid=$(call linkpart,%) #nodeid=$(call get,%) #bridgefile=cache/bridge.$(nodeid) -cache/iface.%: cache/bridge.$$(call get,%) +cache/iface.%: cache/bridge.$$(call get,%) | cache/switch.$$(call get,%) @echo "Creating interface for link $(call linkpart,$(*F)) on $(call display,$(call get,$(*F))) - logs in $(call log,$@)" @$(SSH) $(call solve,$(call get,$(*F))) $(SUDO) sliver-ovs create-port $(BRIDGE) \ - L$(call linkpart,$(*F)) > $@ 2> $(call log,$@) || { rm $@; exit 1; } + L$(call linkpart,$(*F)) &> $(call log,$@) \ + && touch $@ + +cache/port.%: cache/iface.% cache/switch.$$(call get,%) + @echo "Getting port number for link $(call linkpart,$(*F)) on $(call display,$(call get,$(*F))) - logs in $(call log,$@)" + @$(SSH) $(call solve,$(call get,$(*F))) $(SUDO) \ + ovs-appctl netdev-tunnel/get-port L$(call linkpart,$(*F)) > $@ 2> $(call log,$@) \ + || { rm $@; exit 1; } # linkid=$(call linkpart,%) # nodeid=$(call get,%) # iface1=cache/iface.% # iface2=cache/iface.$(call opp,%) -cache/link.%: cache/host.$$(call rget,%) cache/iface.% cache/iface.$$(call opp,%) +cache/endpoint.%: cache/host.$$(call rget,%) cache/port.$$(call opp,%) cache/iface.% @echo "Setting port number of link $(call linkpart,$(*F)) on $(call display,$(call get,$(*F))) - logs in $(call 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> $(call log,$@) \ + $$(cat cache/port.$(call opp,$(*F))) 2> $(call log,$@) \ && touch $@ #################### -CLEANTARGETS=$(addprefix del-,$(notdir $(filter-out %.log,$(wildcard cache/bridge.*)))) +CLEANTARGETS=$(addprefix del-,$(notdir $(wildcard cache/bridge.*))) clean: $(CLEANTARGETS) distclean: rm -rf L log cache @@ -315,7 +327,7 @@ $(foreach id,$(ALL_NODE_IDS), $(eval $(call node_shortcuts,$(id)))) define link_shortcuts iface.%: cache/iface.% -link.%: cache/link.% +endpoint.%: cache/endpoint.% endef $(foreach id,$(ALL_LINK_IDS), $(eval $(call link_shortcuts,$(id)))) diff --git a/planetlab/scripts/sliver-ovs.in b/planetlab/scripts/sliver-ovs.in index d58c1d2d1..0bf2fc337 100755 --- a/planetlab/scripts/sliver-ovs.in +++ b/planetlab/scripts/sliver-ovs.in @@ -162,14 +162,19 @@ function create_bridge () { IP=${IP_PREFIX%/*} PREFIX=${IP_PREFIX#*/} - # ensure ovs-vswitchd is running - is_switch_running || { echo "ovs-vswitchd not running" >&2 ; exit 1 ; } + W= + if ! is_switch_running; then + # we can create 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 + set -e - ovs-vsctl --db=unix:$DB_SOCKET -- --may-exist add-br "$bridge" \ + ovs-vsctl --db=unix:$DB_SOCKET $W -- --may-exist add-br "$bridge" \ -- set bridge "$bridge" datapath_type=planetlab \ -- set interface "$bridge" options:local_ip="$IP" option:local_netmask="$PREFIX" - ovs-appctl netdev-pltap/get-tapname "$bridge" } function create_port () { -- 2.43.0