set SHELL=/bin/bash, the only shell we have tested
[sliver-openvswitch.git] / planetlab / exp-tool / Makefile
index 2f251df..2ec1bc1 100644 (file)
@@ -3,6 +3,9 @@
 # HOST_<id> and IP_<id> for all nodes involved, as well as 
 # LINKS as a list of <node_id>-<node_id> elements
 
+# should work with any shell, but we have only tested bash
+SHELL=/bin/bash
+
 # run make CONF=anotherconfig.mk if you need several configs
 
 CONF ?= conf.mk
@@ -86,6 +89,9 @@ showslice: ++SLICE FORCE
 shownodes:
        @$(foreach id,$(ALL_NODE_IDS),echo $(id)=$(call display,$(id));)
 showhostnames: ++ALL_NODE_HOSTS
+# xxx missing: something that outputs raw python stuff like
+# SEND_IP="10.0.16.1"
+# that would belong in the export to OF
 showips:
        @$(foreach id,$(ALL_NODE_IDS),echo $(id)=$(call display,$(id)) has ip/network set to $(IP_$(id));)
 showlinks:
@@ -103,6 +109,10 @@ sshs: $(foreach id,$(ALL_NODE_IDS),ssh-$(id))
 .PHONY: sshs
 showdpids: $(foreach id,$(ALL_NODE_IDS),showdpid-$(id))
 .PHONY: showdpids
+showmacs: $(foreach id,$(ALL_NODE_IDS),showmac-$(id))
+.PHONY: showmacs
+showports: $(foreach id,$(ALL_NODE_IDS),showports-$(id))
+.PHONY: showports
 
 DBS=$(foreach id,$(ALL_NODE_IDS),cache/db.$(id))
 dbs: $(DBS)
@@ -135,7 +145,7 @@ del-controllers: $(foreach id,$(ALL_NODE_IDS),del-controller-$(id))
 ### node-oriented targets
 # check ssh connectivity
 sshcheck-%: FORCE
-       @if $(SSH) $(HOST_$*) hostname &> /dev/null; then echo "ssh on" $(call display,$*) "OK" ; \
+       @if $(SSH) $(HOST_$*) hostname > /dev/null 2>&1; then echo "ssh on" $(call display,$*) "OK" ; \
         else echo "ssh on" $(call display,$*) "KO !!!"; fi
 
 ovsversion-%: FORCE
@@ -147,6 +157,13 @@ ssh-%: FORCE
 showdpid-%: FORCE
        @echo $*_DPID=0x$$( $(SSH) $(HOST_$*) $(SUDO) ovs-vsctl get bridge $(BRIDGE) datapath_id | sed -e 's,",,g')
 
+showmac-%: FORCE
+       @echo $*_MAC=\"$$( $(SSH) $(HOST_$*) $(SUDO) sliver-ovs show-mac)\"
+
+showports-%: FORCE
+       @$(SSH) $(HOST_$*) $(SUDO) ovs-ofctl show $(BRIDGE) \
+               | perl -nle '/(\d+)\(L(.*?)\Q$(SEP)\E(.*?)\):/ && \
+                       print "PORT_".("$$2" eq "$*" ? "$$2_$$3" : "$$3_$$2")."=$$1"'
 # should probably replace sshcheck
 cache/status.%: FORCE
        @echo "=== DB and SWITCH processes on $(call display,$*)"
@@ -158,22 +175,22 @@ cache/host.%:
 
 cache/db.%:
        @echo "Starting db server on $(call display,$*) - logs in $(call log,$@)"
-       @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs start-db &> $(call log,$@) && touch $@
+       @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs start-db > $(call log,$@) 2>&1 && touch $@
 
 cache/switch.%: | cache/db.%
        @echo "Starting vswitchd on $(call display,$*) - logs in $(call log,$@)"
-       @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs start-switch &> $(call log,$@) && touch $@
+       @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs start-switch > $(call log,$@) 2>&1 && touch $@
 
 cache/bridge.%: | cache/db.%
        @echo "Creating bridge on $(call display,$*) - logs in $(call log,$@)"
        @$(SSH) $(HOST_$*) $(SUDO) \
-               sliver-ovs create-bridge $(BRIDGE) $(IP_$*) $(call default,BROPTIONS,$*) &> $(call log,$@) \
-        && touch $@
+               sliver-ovs create-bridge $(BRIDGE) $(IP_$*) $(call default,BROPTIONS,$*) > $(call log,$@) 2>&1 \
+        && { echo "IP_$*=$(IP_$*)"; echo "BROPTIONS_$*=$(call default,BROPTIONS,$*)"; } > $@
 
 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,$@) \
-        && touch $@
+       @$(SSH) $(HOST_$*) $(SUDO) ovs-vsctl set-controller $(BRIDGE) $(call default,CONTROLLER,$*) > $(call log,$@) 2>&1 \
+        && echo "CONTROLLER_$*=$(call default,CONTROLLER,$*)" > $@
 
 # xxx this probably needs a more thorough cleanup in cache/
 cache/stop.%: del-bridge.%
@@ -265,6 +282,12 @@ shutdown: del-switchs del-dbs
 
 
 ### snapshots
+snapshot:
+       @echo BRIDGE=$(BRIDGE)
+       @cat cache/bridge.* 2>/dev/null || :
+       @cat cache/controller.* 2>/dev/null || :
+       @ls L | sed 's/^/LINKS += /'
+
 remote-snapshot: remote-snapshot-ips remote-snapshot-links
        @true
 
@@ -295,7 +318,7 @@ update-%: FORCE
        @[ -n "$(SLIVER_OVS)" ] || { echo "SLIVER_OVS not set" >&2; exit 1; }
        @[ -f "$(SLIVER_OVS)" ] || { echo "$(SLIVER_OVS) not found" >&2; exit 1; }
        @echo "Sending $(SLIVER_OVS) to $(call display,$*)"
-       @scp -q $(SLIVER_OVS) $(SLICE)@$(call solve,$*):
+       @scp $(SSH_KEY_OPTION) -q $(SLIVER_OVS) $(SLICE)@$(call solve,$*):
        @$(SSH) $(call solve,$*) $(SUDO) mv $(notdir $(SLIVER_OVS)) /usr/sbin/sliver-ovs
 
 .SECONDEXPANSION:
@@ -335,7 +358,7 @@ del-iface.%: | cache/db.$$(call get,%)
 cache/iface.%: cache/bridge.$$(call get,%) | cache/db.$$(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)) &> $(call log,$@) \
+               L$(call linkpart,$(*F)) > $(call log,$@) 2>&1 \
         && touch $@
 
 # cache/port.<node_id1>-<node_id2>@<endpoint>:
@@ -402,6 +425,53 @@ gprobe-%: FORCE
        $(SSH) -n $(call solve,$(word 2,$(subst @, ,$(*F)))) $(SUDO) \
        sliver-ovs gmap-probe L$(word 1,$(subst @, ,$(*F))) $(GMAP_SERVER) $(word 3,$(subst @, ,$(*F))) $(word 4,$(subst @, ,$(*F)))
 
+jsons: routers.json links.json geocode.json
+.PHONE: jsons
+
+routers.json: $(CONF)
+       @{  echo "[";   \
+           sep="  ";   \
+           for n in $(CONF_NODE_IDS); do \
+               echo "    $$sep\"$$n\"";  \
+               sep=", "; \
+           done; \
+           echo "]"; \
+         } > $@
+
+links.json: $(foreach l,$(LINKS),cache/json.$(l))
+       @{  echo "["; \
+           cat $^ | sed '2,$$s/^/, /'; \
+           echo "]"; \
+        } > $@
+
+cache/json.%: $(CONF)
+       @echo "{\"id\": $($*_linkid), \"start\": \"$(call get,$*@1)\", \"end\": \"$(call get,$*@2)\"}" > $@
+
+geocode.json: $(foreach n,$(CONF_NODE_IDS),cache/geocode.$(n))
+       @{  echo "{"; \
+           sep="  "; \
+           for f in $^; do \
+               echo -n "$$sep"; \
+               cat $$f; \
+               sep=", "; \
+           done; \
+           echo "}"; \
+        } > $@
+            
+cache/geocode.%: cache/loc.% $(CONF)
+       @{  echo "\"$*\": {"; \
+           echo "    \"name\": \"$(HOST_$*)\","; \
+           echo "    \"shortname\": \"$*\","; \
+           echo "    \"site\": \"\","; \
+           echo "    \"backbone\": false,"; \
+           echo "    \"position\": [ $(shell cat cache/loc.$*) ]"; \
+           echo "   }"; \
+        } > $@
+
+cache/loc.%: $(CONF)
+       @wget -O - 'http://freegeoip.net/csv/$(HOST_$*)' | \
+           awk -F, '{ printf "%s, %s\n", $$8, $$9 }' > $@
+
 ####################
 # 'virtual' targets in that there's no real file attached
 define node_shortcuts