fix: several error handling issues in send/recv
[sliver-openvswitch.git] / planetlab / scripts / 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 -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 -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 -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 del.%: del-iface.%@1 del-iface.%@2
59         @rm -f L/$*
60         @echo "Deleted link $*"
61
62 del-iface.%:
63         @echo "Removing interface for link $(call proj1,$*) from host $(call get,$*)"
64         @ssh -l $(SLICE) $(HOST_$(call get,$*)) \
65                 sudo ovs-vsctl del-port L$(call proj1,$*)
66         @rm -f cache/iface.$* cache/link.$* cache/link.$(call opp,$*)
67
68 del-bridge.%:
69         @echo "Deleting bridge on host $*"
70         @if [ -f cache/bridge.$* ]; then \
71                 ssh -l $(SLICE) $(HOST_$*) \
72                         sudo del_bridge $$(cat cache/bridge.$*);\
73          fi
74         @rm -f cache/bridge.$* \
75               cache/iface.$*-*@1 cache/iface.*-$*@2 \
76               cache/link.$*-*@?  cache/link.*-$*@?  \
77               L/$*-*             L/*-$*
78
79 graph.dot:
80         ( echo "digraph $(SLICE) {"; ls L | sed 's/-/->/;s/$$/;/'; echo "}" ) > $@
81
82 graph.ps: graph.dot
83         dot -Tps < $^ > $@      
84
85 .PHONY: clean del-links graph.dot
86
87
88 clean: $(addprefix del-,$(notdir $(wildcard cache/bridge.*)))
89
90 del-links: $(addprefix del.,$(notdir $(wildcard L/*)))
91
92 .SECONDEXPANSION:
93
94 cache/iface.%: cache/bridge.$$(call get,%)
95         @echo "Creating iterface for link $(call proj1,$*) on host $(call get,$*)"
96         @ssh -l $(SLICE) $(HOST_$(call get,$*)) \
97                 sudo create_port $$(cat $^) L$(call proj1,$*) > $@ \
98          || { rm $@; exit 1; }
99
100 cache/link.%: cache/host.$$(call rget,$$*) cache/iface.% cache/iface.$$(call opp,$$*)
101         @echo "Setting port number of link $(call proj1,$*) on host $(call get,$*)"
102         @ssh -l $(SLICE) $(HOST_$(call get,$*)) \
103                 sudo ovs-vsctl set interface L$(call proj1,$*) \
104                         options:remote_ip=$$(cat cache/host.$(call rget,$*)) \
105                         options:remote_port=$$(cat cache/iface.$(call opp,$*)) \
106          && touch $@
107