4 proj1=$(word 1,$(subst @, ,$(1)))
7 proj2=$(word 2,$(subst @, ,$(1)))
11 get=$(word $(call proj2,$(1)),$(subst -, ,$(call proj1,$(1))))
15 flip=$(if $(findstring 1,$(1)),2,1)
19 opp=$(call proj1,$(1))@$(call flip,$(call proj2,$(1)))
23 rget=$(call get,$(call opp,$(1)))
28 all: $(addprefix L/,$(shell cat links))
32 @echo "IP lookup for host $*"
33 @host $(HOST_$*) | sed -n 's/^.*has address *//p' > $@
36 @echo "Starting db server on host $*"
37 @ssh -t -l $(SLICE) $(HOST_$*) \
38 sudo start_ovsdb-server > $@ \
41 cache/switchd.%: cache/db.%
42 @echo "Starting vswitchd on host $*"
43 @ssh -t -l $(SLICE) $(HOST_$*) \
44 sudo start_vswitchd > $@ \
47 cache/bridge.%: cache/switchd.%
48 @echo "Creating bridge on host $*"
49 @ssh -t -l $(SLICE) $(HOST_$*) \
50 sudo create_bridge $(IP_$*) > $@ \
54 L/%: cache/link.%@1 cache/link.%@2
56 @echo "Created link $*"
58 U/%: del-iface.%@1 del-iface.%@2
60 @echo "Deleted link $*"
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.$*);\
68 @rm -f cache/bridge.$* \
69 cache/iface.$*-*@1 cache/iface.*-$*@2 \
70 cache/link.$*-*@? cache/link.*-$*@? \
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;\
79 @rm -f cache/switchd.$*
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;\
89 shutdown: del-switches del-dbs
92 ( echo "digraph $(SLICE) {"; ls L | sed 's/-/->/;s/$$/;/'; echo "}" ) > $@
97 .PHONY: clean del-links graph.dot servers
100 clean: $(addprefix del-,$(notdir $(wildcard cache/bridge.*)))
102 del-links: $(addprefix U/,$(notdir $(wildcard L/*)))
104 switchds: $(wildcard cache/switchd.*)
106 dbs: $(wildcard cache/db.*)
108 del-switchds: $(addprefix del-,$(notdir $(wildcard cache/switchd.*)))
110 del-dbs: $(addprefix del-,$(notdir $(wildcard cache/db.*)))
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,$*)
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; }
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,$*)) \