add -t option to ssh, to second sudo
[sliver-openvswitch.git] / planetlab / exp-tool / Makefile
1 include conf.mk
2
3 # proj1(x@y) = x
4 proj1=$(word 1,$(subst @, ,$(1)))
5
6 # proj2(x@y) = y
7 proj2=$(word 2,$(subst @, ,$(1)))
8
9 # get(x-y@1) = x
10 # get(x-y@2) = y
11 get=$(word $(call proj2,$(1)),$(subst -, ,$(call proj1,$(1))))
12
13 # flip(1) = 2
14 # flip(2) = 1
15 flip=$(if $(findstring 1,$(1)),2,1)
16
17 # opp(x-y@1) = x-y@2
18 # opp(x-y@2) = x-y@1
19 opp=$(call proj1,$(1))@$(call flip,$(call proj2,$(1)))
20
21 # rget(x-y@1) = y
22 # rget(x-y@2) = x
23 rget=$(call get,$(call opp,$(1)))
24
25
26 .SECONDARY:
27
28 all: $(addprefix L/,$(shell cat links))
29
30
31 cache/host.%:
32         @echo "IP lookup for host $*"
33         @host $(HOST_$*) | sed -n 's/^.*has address *//p' > $@
34
35 cache/db.%:
36         @echo "Starting db server on host $*"
37         @ssh -t -l $(SLICE) $(HOST_$*) \
38                 sudo start_ovsdb-server > $@ \
39          || { rm $@; exit 1; }
40
41 cache/switchd.%: cache/db.%
42         @echo "Starting vswitchd on host $*"
43         @ssh -t -l $(SLICE) $(HOST_$*) \
44                 sudo start_vswitchd > $@ \
45          || { rm $@; exit 1; }
46
47 cache/bridge.%: cache/switchd.%
48         @echo "Creating bridge on host $*"
49         @ssh -t -l $(SLICE) $(HOST_$*) \
50                 sudo create_bridge $(IP_$*) > $@ \
51          || { rm $@; exit 1; }
52
53
54 L/%: cache/link.%@1 cache/link.%@2
55         @touch $@
56         @echo "Created link $*"
57
58 U/%: del-iface.%@1 del-iface.%@2
59         @rm -f L/$*
60         @echo "Deleted link $*"
61
62 del-bridge.%: cache/db.%
63         @echo "Deleting bridge on host $*"
64         @if [ -f cache/bridge.$* ]; then \
65                 ssh -t -l $(SLICE) $(HOST_$*) \
66                         sudo del_bridge $$(cat cache/bridge.$*);\
67          fi
68         @rm -f cache/bridge.$* \
69               cache/iface.$*-*@1 cache/iface.*-$*@2 \
70               cache/link.$*-*@?  cache/link.*-$*@?  \
71               L/$*-*             L/*-$*
72
73 del-switchd.%: del-bridge.%
74         @echo "Shutting down switchd on host $*"
75         @if [ -f cache/switchd.$* ]; then \
76                 ssh -t -l $(SLICE) $(HOST_$*) \
77                         sudo ovs-appctl exit;\
78          fi
79         @rm -f cache/switchd.$*
80
81 del-db.%:
82         @echo "Shutting down db on host $*"
83         @if [ -f cache/db.$* ]; then \
84                 ssh -t -l $(SLICE) $(HOST_$*) \
85                         sudo ovs-appctl --target=$(VARRUN)/ovsdb-server.$$(cat cache/db.$*).ctl exit;\
86          fi
87         @rm -f cache/db.$*
88
89 shutdown: del-switches del-dbs
90
91 graph.dot:
92         ( echo "digraph $(SLICE) {"; ls L | sed 's/-/->/;s/$$/;/'; echo "}" ) > $@
93
94 graph.ps: graph.dot
95         dot -Tps < $^ > $@      
96
97 .PHONY: clean del-links graph.dot servers
98
99
100 clean: $(addprefix del-,$(notdir $(wildcard cache/bridge.*)))
101
102 del-links: $(addprefix U/,$(notdir $(wildcard L/*)))
103
104 switchds: $(wildcard cache/switchd.*)
105
106 dbs: $(wildcard cache/db.*)
107
108 del-switchds: $(addprefix del-,$(notdir $(wildcard cache/switchd.*)))
109
110 del-dbs: $(addprefix del-,$(notdir $(wildcard cache/db.*)))
111
112 .SECONDEXPANSION:
113
114 del-iface.%: cache/db.$$(call get,%)
115         @echo "Removing interface for link $(call proj1,$*) from host $(call get,$*)"
116         @ssh -t -l $(SLICE) $(HOST_$(call get,$*)) \
117                 sudo del_port L$(call proj1,$*)
118         @rm -f cache/iface.$* cache/link.$* cache/link.$(call opp,$*)
119
120
121
122 cache/iface.%: cache/bridge.$$(call get,%)
123         @echo "Creating interface for link $(call proj1,$*) on host $(call get,$*)"
124         @ssh -t -l $(SLICE) $(HOST_$(call get,$*)) \
125                 sudo create_port $$(cat $^) L$(call proj1,$*) > $@ \
126          || { rm $@; exit 1; }
127
128 cache/link.%: cache/host.$$(call rget,$$*) cache/iface.% cache/iface.$$(call opp,$$*)
129         @echo "Setting port number of link $(call proj1,$*) on host $(call get,$*)"
130         @ssh -t -l $(SLICE) $(HOST_$(call get,$*)) \
131                 sudo ovs-vsctl set interface L$(call proj1,$*) \
132                         options:remote_ip=$$(cat cache/host.$(call rget,$*)) \
133                         options:remote_port=$$(cat cache/iface.$(call opp,$*)) \
134          && touch $@
135