Setting tag sliver-openvswitch-2.2.90-1
[sliver-openvswitch.git] / planetlab / exp-tool / Makefile
1 # see README
2 # conf.mk is expected to define
3 # HOST_<id> and IP_<id> for all nodes involved, as well as 
4 # LINKS as a list of <node_id>-<node_id> elements
5
6 # should work with any shell, but we have only tested bash
7 SHELL=/bin/bash
8
9 .DELETE_ON_ERROR:
10
11 # run make CONF=anotherconfig.mk if you need several configs
12
13 CONF ?= conf.mk
14 include $(CONF)
15
16 # if undefined in the conf file, use single dash
17 SEP?=-
18
19 # bridge name (XXX the same on all nodes)
20 BRIDGE?=$(SLICE)
21
22 ### helper functions
23 # flip(1) = 2
24 # flip(2) = 1
25 flip=$(if $(findstring 1,$(1)),2,1)
26 # cutsep (x-y)-> x y
27 cutsep=$(subst $(SEP), ,$(1))
28 # leftnode (x-y) -> x
29 leftnode=$(word 1,$(call cutsep,$(1)))
30 # rightnode (x-y) -> y
31 rightnode=$(word 2,$(call cutsep,$(1)))
32 # linkpart(x@y) = x
33 linkpart=$(word 1,$(subst @, ,$(1)))
34 # endpart(x@y) = y
35 endpart=$(word 2,$(subst @, ,$(1)))
36 # get(x-y@1) = x
37 # get(x-y@2) = y
38 get=$(word $(call endpart,$(1)),$(call cutsep,$(call linkpart,$(1))))
39 # opp(x-y@1) = x-y@2
40 # opp(x-y@2) = x-y@1
41 opp=$(call linkpart,$(1))@$(call flip,$(call endpart,$(1)))
42 # rget(x-y@1) = y
43 # rget(x-y@2) = x
44 rget=$(call get,$(call opp,$(1)))
45 ###
46 default=$(if $($(1)_$(2)),$($(1)_$(2)),$($(1)))
47 solve=$(HOST_$(1))
48 solve_ip=$(IP_$(1))
49 # can be redefined in conf.mk if that's not the expected behaviour
50 display?=host $(1) aka $(call solve,$(1))
51
52 # log file name
53 log=$(addprefix log/,$(notdir $(1)))
54
55 #################### set variables after conf.mk
56 ifeq "$(SSH_KEY)" ""
57 SSH_KEY_OPTION ?=
58 else
59 SSH_KEY_OPTION ?= -i $(SSH_KEY)
60 endif
61
62 SSH_OPTIONS ?= $(SSH_KEY_OPTION) -l $(SLICE)
63 SSH = ssh $(SSH_OPTIONS)
64
65 SUDO ?= sudo -S
66
67 ALL_NODE_IDS=$(sort $(foreach link,$(LINKS),$(call leftnode,$(link))) $(foreach link,$(LINKS),$(call rightnode,$(link))))
68 ALL_NODE_HOSTS=$(foreach id,$(ALL_NODE_IDS),$(call solve,$(id)))
69 ALL_LINK_IDS=$(addsuffix @1,$(LINKS)) $(addsuffix @2,$(LINKS))
70 CONF_NODE_IDS=$(subst HOST_,,$(filter HOST_%,$(.VARIABLES)))
71
72 ####################
73 init_all: init all
74 init:
75         @[ -d L ] || ( echo Creating tmp dir L; mkdir L)
76         @[ -d log ] || (echo Creating tmp dir log; mkdir log)
77         @[ -d cache ] || ( echo Creating tmp dir cache; mkdir cache)
78 .PHONY: init_all init
79
80 FORCE:
81
82 .SECONDARY:
83
84 LINKTARGETS=$(addprefix L/,$(LINKS))
85 all: $(LINKTARGETS)
86 .PHONY: all
87
88 # could also do make ++SLICE
89 showslice: ++SLICE FORCE
90
91 shownodes:
92         @$(foreach id,$(ALL_NODE_IDS),echo $(id)=$(call display,$(id));)
93 showhostnames: ++ALL_NODE_HOSTS
94 # xxx missing: something that outputs raw python stuff like
95 # SEND_IP="10.0.16.1"
96 # that would belong in the export to OF
97 showips:
98         @$(foreach id,$(ALL_NODE_IDS),echo $(id)=$(call display,$(id)) has ip/network set to $(IP_$(id));)
99 showlinks:
100         @$(foreach link,$(LINKS), echo $(call display,$(call leftnode,$(link))) '====>' $(call display,$(call rightnode,$(link)));)
101 showcontrollers:
102         @$(foreach id,$(ALL_NODE_IDS), echo $(call display,$(id)) has controller $(call default,CONTROLLER,$(id));)
103 .PHONY: shownodes showhostnames showips showlinks showcontrollers
104
105 sshchecks: $(foreach id,$(ALL_NODE_IDS),sshcheck-$(id))
106 .PHONY: sshchecks
107 ovsversions: $(foreach id,$(ALL_NODE_IDS),ovsversion-$(id))
108 .PHONY: ovsversions
109 # more general form; run with  make sshs SSH-COMMAND="bla bla bla"
110 sshs: $(foreach id,$(ALL_NODE_IDS),ssh-$(id))
111 .PHONY: sshs
112 showdpids: $(foreach id,$(ALL_NODE_IDS),showdpid-$(id))
113 .PHONY: showdpids
114 showmacs: $(foreach id,$(ALL_NODE_IDS),showmac-$(id))
115 .PHONY: showmacs
116 showports: $(foreach id,$(ALL_NODE_IDS),showports-$(id))
117 .PHONY: showports
118
119 DBS=$(foreach id,$(ALL_NODE_IDS),cache/db.$(id))
120 dbs: $(DBS)
121 .PHONY: dbs
122
123 SWITCHS=$(foreach id,$(ALL_NODE_IDS),cache/switch.$(id))
124 switchs: $(SWITCHS)
125 .PHONY: switchs
126
127 start: dbs switchs
128 .PHONY: start
129
130 stop:$(foreach id,$(ALL_NODE_IDS),cache/stop.$(id))
131 .PHONY: stop
132
133 status:$(foreach id,$(ALL_NODE_IDS),cache/status.$(id))
134 .PHONY: status
135
136 BRIDGES=$(foreach id,$(ALL_NODE_IDS),cache/bridge.$(id))
137 bridges: $(BRIDGES)
138 .PHONY: bridges
139
140 CONTROLLERS=$(foreach id,$(ALL_NODE_IDS),cache/controller.$(id))
141 controllers: $(CONTROLLERS)
142 .PHONY: controllers
143
144 del-controllers: $(foreach id,$(ALL_NODE_IDS),del-controller-$(id))
145 .PHONY: del-controllers
146
147 ### node-oriented targets
148 # check ssh connectivity
149 sshcheck-%: FORCE
150         @if $(SSH) $(HOST_$*) hostname > /dev/null 2>&1; then echo "ssh on" $(call display,$*) "OK" ; \
151          else echo "ssh on" $(call display,$*) "KO !!!"; fi
152
153 ovsversion-%: FORCE
154         @OVSVERSION=$$($(SSH) $(HOST_$*) rpm -q sliver-openvswitch); echo $(call display,$*) has $$OVSVERSION
155
156 ssh-%: FORCE
157         @$(SSH) $(HOST_$*) $(SUDO) $(SSH-COMMAND)
158
159 showdpid-%: FORCE
160         @echo $*_DPID=0x$$( $(SSH) $(HOST_$*) $(SUDO) ovs-vsctl get bridge $(BRIDGE) datapath_id | sed -e 's,",,g')
161
162 showmac-%: FORCE
163         @echo $*_MAC=\"$$( $(SSH) $(HOST_$*) $(SUDO) sliver-ovs get-mac $(BRIDGE))\"
164
165 showports-%: FORCE
166         @$(SSH) $(HOST_$*) $(SUDO) ovs-ofctl show $(BRIDGE) \
167                 | perl -nle '/(\d+)\(L(.*?)\Q$(SEP)\E(.*?)\):/ && \
168                         print "PORT_".("$$2" eq "$*" ? "$$2_$$3" : "$$3_$$2")."=$$1"'
169 # should probably replace sshcheck
170 cache/status.%: FORCE
171         @echo "=== DB and SWITCH processes on $(call display,$*)"
172         @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs status ||:
173
174 cache/host.%:
175         @echo "IP lookup for $(call display,$*) - logs in $(call log,$@)"
176         @host $(HOST_$*) | sed -n 's/^.*has address *//p' > $@ 2> $(call log,$@)
177
178 cache/db.%:
179         @echo "Starting db server on $(call display,$*) - logs in $(call log,$@)"
180         @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs start-db > $(call log,$@) 2>&1
181         @touch $@
182
183 cache/switch.%: | cache/db.%
184         @echo "Starting vswitchd on $(call display,$*) - logs in $(call log,$@)"
185         @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs start-switch > $(call log,$@) 2>&1
186         @touch $@
187
188 cache/bridge.%: | cache/db.%
189         @echo "Creating bridge on $(call display,$*) - logs in $(call log,$@)"
190         @$(SSH) $(HOST_$*) $(SUDO) \
191                 sliver-ovs create-bridge $(BRIDGE) $(IP_$*) $(call default,BROPTIONS,$*) > $(call log,$@) 2>&1
192         @{ echo "IP_$*=$(IP_$*)"; echo "BROPTIONS_$*=$(call default,BROPTIONS,$*)"; } > $@
193
194 cache/controller.%: cache/bridge.%
195         @echo "Setting controller $(call default,CONTROLLER,$*) on $(call display,$*) - logs in $(call log,$@)"
196         @$(SSH) $(HOST_$*) $(SUDO) ovs-vsctl set-controller $(BRIDGE) $(call default,CONTROLLER,$*) > $(call log,$@) 2>&1
197         @echo "CONTROLLER_$*=$(call default,CONTROLLER,$*)" > $@
198
199 # xxx this probably needs a more thorough cleanup in cache/
200 cache/stop.%: del-bridge.%
201         @echo "Stopping switch & db on $(call display,$*)"
202         @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs stop && rm cache/switch.$* cache/db.$*
203
204 ### link-oriented targets
205 # L/<nodeid1>-<node_id2>:
206 #       Establish a link between nodes <node_id1> and <node_id2>
207 L/%: cache/endpoint.%@1 cache/endpoint.%@2
208         @touch $@
209         @echo "Link $* is up"
210
211 # U/<node_id1>-<node_id2>
212 #       Tear down the link between nodes <node_id1> and <node_id2>
213 U/%: del-iface.%@1 del-iface.%@2
214         @rm -f L/$*
215         @echo "Deleted link $*"
216
217 # del-bridge.<node_id>: Delete the bridge on node <node_id>.
218 #
219 # We can do this only if the db on node <node_id> is running, but
220 # we don't need to re-delete if the db is restarted (hence the
221 # order-only dependency).
222 #
223 # Deleting a bridge also deletes all interfaces of the bridge
224 # as a side effect. This in turn invalidates local tunnel
225 # port numbers and endpoint info on both sides of each affected tunnel.
226 # The corresponding links obviously go down. 
227 # Controller information is also lost.
228 # We invalidate the cache accordingly.
229 del-bridge.%: | cache/db.%
230         @echo "Deleting bridge on $(call display,$*)"
231         @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs del-bridge $(BRIDGE)
232         @rm -f cache/bridge.$* \
233               cache/iface.$*$(SEP)*@1 cache/iface.*$(SEP)$*@2 \
234               cache/port.$*$(SEP)*@1  cache/port.*$(SEP)$*@2  \
235               cache/endpoint.$*$(SEP)*@?  cache/endpoint.*$(SEP)$*@?  \
236               L/$*$(SEP)*             L/*$(SEP)$* \
237               cache/controller.$*
238
239 # del-switch.<node_id>: Stops the switch daemon on <node_id>.
240 #
241 # As a side effect, the local port numbers of the tunnels
242 # are no longer valid (they will change when the daemon is restarted)
243 # and, therefore, the endpoint info on the remote side of
244 # the tunnels must be invalidated. The links also go down.
245 # Controller information is also lost.
246 # We invalidate the cache accordingly.
247 del-switch.%:
248         @echo "Shutting down switch on $(call display,$*)"
249         @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs stop-switch
250         @rm -f cache/switch.$* \
251                cache/port.$*$(SEP)*@1  cache/port.*$(SEP)$*@2  \
252                cache/endpoint.$*$(SEP)*@2  cache/endpoint.*$(SEP)$*@1  \
253                L/$*$(SEP)*            L/*$(SEP)$* \
254                cache/controller.$*
255
256 # del-db.<node_id>: Stops the db daemon on <node_id>.
257 #
258 # This has no additional side effects.
259 del-db.%:
260         @echo "Shutting down db on $(call display,$*)"
261         @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs stop-db
262         @rm -f cache/db.$*
263
264 # del-controller.<node_id>:
265 #       Detaches <node_id> from the controller.
266 #
267 # This has no additional side effects.
268 del-controller-%: | cache/db.%
269         @echo "Removing controller for $(call display,$*)"
270         @$(SSH) $(HOST_$*) $(SUDO) sliver-ovs del-controller $(BRIDGE)
271         @rm -f cache/controller.$*
272
273 # del-links: Shortcut to delete all currently up links.
274 del-links: $(addprefix U/,$(notdir $(wildcard L/*)))
275
276 # del-switchs: Shortcut to stop all currently running switch daemons.
277 del-switchs: $(addprefix del-,$(notdir $(wildcard cache/switch.*)))
278
279 # del-dbs: Shortcut to stop all currently running db daemona.s
280 del-dbs: $(addprefix del-,$(notdir $(wildcard cache/db.*)))
281
282 # shutdown: Shortcut to stop all currently running daemons.
283 shutdown: del-switchs del-dbs
284
285 .PHONY: del-links del-switchs del-dbs shutdown
286
287
288 ### snapshots
289 snapshot:
290         @echo BRIDGE=$(BRIDGE)
291         @cat cache/bridge.* 2>/dev/null || :
292         @cat cache/controller.* 2>/dev/null || :
293         @ls L | sed 's/^/LINKS += /'
294
295 remote-snapshot: remote-snapshot-ips remote-snapshot-links
296         @true
297
298 remote-snapshot-ips: $(addprefix cache/rsnap.ip.,$(CONF_NODE_IDS))
299         @cat /dev/null $^
300
301 remote-snapshot-links: $(addprefix cache/rsnap.links.,$(CONF_NODE_IDS))
302         @sort -u /dev/null $^
303
304 .PHONY: remote-snapshot remote-snapshot-ips remote-snapshot-links
305
306
307 cache/rsnap.ip.%: FORCE
308         @$(SSH) $(HOST_$*) $(SUDO) \
309                 sliver-ovs get-local-ip $(BRIDGE) | sed 's/^/IP_$*=/' > $@ 
310
311 cache/rsnap.links.%: FORCE
312         @$(SSH) $(HOST_$*) $(SUDO) \
313                 sliver-ovs get-local-links $(BRIDGE) | sed -n 's/^L/LINKS += /p' > $@
314
315 ### update sliver-ovs
316 update: $(addprefix update-,$(CONF_NODE_IDS))
317         @true
318
319 update-%: FORCE
320         @[ -n "$(SLIVER_OVS)" ] || { echo "SLIVER_OVS not set" >&2; exit 1; }
321         @[ -f "$(SLIVER_OVS)" ] || { echo "$(SLIVER_OVS) not found" >&2; exit 1; }
322         @echo "Sending $(SLIVER_OVS) to $(call display,$*)"
323         @scp $(SSH_KEY_OPTION) -q $(SLIVER_OVS) $(SLICE)@$(call solve,$*):
324         @$(SSH) $(call solve,$*) $(SUDO) mv $(notdir $(SLIVER_OVS)) /usr/sbin/sliver-ovs
325
326 .SECONDEXPANSION:
327
328 # del-iface.<node_id>-<node_id>@<endpoint>:
329 #       Deletes the interface of link <node_id1>-<node_id2> on either
330 #       <node_id1> or <node_id2>, according to <endpoint>.
331
332 # We need a running db daemon to do this, but we do not have to
333 # redo the delete if the db daemon is restarted.
334 #
335 # This also invalidates the local port of the tunnel and the endpoint
336 # info on both sides of the tunnel. The link goes down.
337 del-iface.%: | cache/db.$$(call get,%)
338         @echo "Removing interface for link $(call linkpart,$*) from $(call get,$*)"
339         @$(SSH) $(HOST_$(call get,$*)) \
340                 $(SUDO) sliver-ovs del-port L$(call linkpart,$*)
341         @rm -f cache/iface.$* \
342                cache/port.$* cache/endpoint.$* cache/endpoint.$(call opp,$*) \
343                L/$(call linkpart,$*)
344
345
346 ### '%' here is leftid-rightid@{1,2}
347 # we retrieve % as $(*F)
348 #linkid=$(call linkpart,%)
349 #nodeid=$(call get,%)
350 #bridgefile=cache/bridge.$(nodeid)
351
352 # cache/iface.<node_id1>-<node_id2>@<endpoint>:
353 #       Creates the interface for link <node_id1>-<node_id2> on
354 #       <node_id<endpoint>>. 
355 #
356 # The bridge of the local node must already exist, and we need to create
357 # the interface again if the bridge is re-created.
358 # We also need a running db daemon, but we do not need to do anything
359 # if the db daemon is restarted.
360 cache/iface.%: cache/bridge.$$(call get,%) | cache/db.$$(call get,%)
361         @echo "Creating interface for link $(call linkpart,$(*F)) on $(call display,$(call get,$(*F))) - logs in $(call log,$@)"
362         @$(SSH) $(call solve,$(call get,$(*F))) $(SUDO) sliver-ovs create-port $(BRIDGE) \
363                 L$(call linkpart,$(*F)) > $(call log,$@) 2>&1
364         @touch $@
365
366 # cache/port.<node_id1>-<node_id2>@<endpoint>:
367 #       Retrieves the local port of link <node_id1>-<node_id2> on
368 #       node <node_id<endpoint>>.
369 #
370 # The local interface must have been created already and the
371 # switch daemon must be running. We need to retrieve the port
372 # number again if the interface is re-created, or the switch
373 # daemon is restarted.
374 cache/port.%: cache/iface.% cache/switch.$$(call get,%)
375         @echo "Getting port number for link $(call linkpart,$(*F)) on $(call display,$(call get,$(*F))) - logs in $(call log,$@)"
376         @$(SSH) $(call solve,$(call get,$(*F))) $(SUDO) \
377                 sliver-ovs get-local-endpoint L$(call linkpart,$(*F)) > $@ 2> $(call log,$@)
378
379
380 # linkid=$(call linkpart,%)
381 # nodeid=$(call get,%)
382 # iface1=cache/iface.%
383 # iface2=cache/iface.$(call opp,%)
384
385 # cache/endpoint.<node_id1>-<node_id2>@<endpoint>:
386 #       Sets the other side (IP address, UDP port) info for link <node_id1>-<node_id2>
387 #       on <node_id<endpoint>>.
388 #
389 # We need the IP address and the UDP port of the other side and the interace of this side.
390 # We need to set the info again if any of these change.
391 cache/endpoint.%: cache/host.$$(call rget,%) cache/port.$$(call opp,%) cache/iface.% | cache/db.$$(call get,%)
392         @echo "Setting port number of link $(call linkpart,$(*F)) on $(call display,$(call get,$(*F))) - logs in $(call log,$@)"
393         @$(SSH) $(call solve,$(call get,$(*F))) $(SUDO) sliver-ovs set-remote-endpoint L$(call linkpart,$(*F)) \
394                         $$(cat cache/host.$(call rget,$(*F))) \
395                         $$(cat cache/port.$(call opp,$(*F))) 2> $(call log,$@)
396         @touch $@
397
398
399 ######################
400 # testing
401 ######################
402
403 test: $(foreach l,$(LINKS),test-$(l))
404
405 test-%: ping-% ping-$$(call get,$$*@2)$(SEP)$$(call get,$$*@1)
406         @true
407
408 ping-%: FORCE
409         @echo "Testing connectivity $(call get,$*@1) ===> $(call get,$*@2) - logs in $(call log,$@)"
410         @$(SSH) $(call solve,$(call get,$*@1)) ping -c 1 $(call solve_ip_addr,$(call get,$*@2)) > $(call log,$@) 2>&1
411         @echo "Connectivity $(call get,$*@1) ===> $(call get,$*@2) OK"
412
413 ####################
414 CLEANTARGETS=$(addprefix del-,$(notdir $(wildcard cache/bridge.*)))
415 clean: $(CLEANTARGETS)
416 distclean:
417         rm -rf L log cache
418 .PHONY: clean distclean
419
420 ####################
421 graph.dot:
422         ( echo "digraph $(SLICE) {"; ls L | sed 's/$(SEP)/->/;s/$$/;/'; echo "}" ) > $@
423 graph.ps: graph.dot
424         dot -Tps < $^ > $@      
425
426 ####################
427 # googlemap stuff
428 # Uses:
429 # GMAP_SERVER, the hostname that runs an ndnmap instance
430 # GMAP_PROBES, a list of tuples of the form
431 # <linkid>=<nodeid>=<internal_linkid>=<frequency>
432 # e.g.
433 # SENDER-MUX=SENDER=3=0.5
434 # which would mean, the link 'SENDER-MUX' should be monitored at the 'SENDER' node and is coded 
435 # in links.json with id=3, every half second
436 # sliver-ovs gmap-probe is designed to run in background,
437 # and so that a new run will kill any previously running instance
438 gprobes: $(foreach probe,$(GMAP_PROBES),gprobe-$(probe))
439
440 gprobe-%: FORCE
441         $(SSH) -n $(call solve,$(word 2,$(subst @, ,$(*F)))) $(SUDO) \
442         sliver-ovs gmap-probe L$(word 1,$(subst @, ,$(*F))) $(GMAP_SERVER) $(word 3,$(subst @, ,$(*F))) $(word 4,$(subst @, ,$(*F)))
443
444 jsons: routers.json links.json geocode.json
445 .PHONE: jsons
446
447 routers.json: $(CONF)
448         @{  echo "[";   \
449             sep="  ";   \
450             for n in $(CONF_NODE_IDS); do \
451                 echo "    $$sep\"$$n\"";  \
452                 sep=", "; \
453             done; \
454             echo "]"; \
455           } > $@
456
457 links.json: $(foreach l,$(LINKS),cache/json.$(l))
458         @{  echo "["; \
459             cat $^ | sed '2,$$s/^/, /'; \
460             echo "]"; \
461          } > $@
462
463 cache/json.%: $(CONF)
464         @echo "{\"id\": $($*_linkid), \"start\": \"$(call get,$*@1)\", \"end\": \"$(call get,$*@2)\"}" > $@
465
466 geocode.json: $(foreach n,$(CONF_NODE_IDS),cache/geocode.$(n))
467         @{  echo "{"; \
468             sep="  "; \
469             for f in $^; do \
470                 echo -n "$$sep"; \
471                 cat $$f; \
472                 sep=", "; \
473             done; \
474             echo "}"; \
475          } > $@
476              
477 cache/geocode.%: cache/loc.% $(CONF)
478         @{  echo "\"$*\": {"; \
479             echo "    \"name\": \"$(HOST_$*)\","; \
480             echo "    \"shortname\": \"$*\","; \
481             echo "    \"site\": \"\","; \
482             echo "    \"backbone\": false,"; \
483             echo "    \"position\": [ $(shell cat cache/loc.$*) ]"; \
484             echo "   }"; \
485          } > $@
486
487 cache/loc.%: $(CONF)
488         @wget -O - 'http://freegeoip.net/csv/$(HOST_$*)' | \
489             awk -F'", *"' '{ printf "\"%s\", \"%s\"\n", $$8, $$9 }' > $@
490
491 ####################
492 # 'virtual' targets in that there's no real file attached
493 define node_shortcuts
494 sshcheck.$(1): sshcheck-$(1) FORCE
495 db.$(1): cache/db.$(1) FORCE
496 switch.$(1): cache/switch.$(1) FORCE
497 start.$(1): cache/start.$(1) FORCE
498 stop.$(1): cache/stop.$(1) FORCE
499 status.$(1): cache/status.$(1) FORCE
500 bridge.$(1): cache/bridge.$(1) FORCE
501 host.$(1): cache/host.$(1) FORCE
502 controller.$(1): cache/controller.$(1) FORCE
503 # switch already depends on db, but well
504 cache/start.$(1): cache/db.$(1) cache/switch.$(1) FORCE
505 endef
506
507 $(foreach id,$(ALL_NODE_IDS), $(eval $(call node_shortcuts,$(id))))
508
509 define link_shortcuts
510 iface.%: cache/iface.%
511 endpoint.%: cache/endpoint.%
512 endef
513
514 $(foreach id,$(ALL_LINK_IDS), $(eval $(call link_shortcuts,$(id))))
515
516 help:
517         @cat Makefile.help
518
519 #################### convenience, for debugging only
520 # make +foo : prints the value of $(foo)
521 # make ++foo : idem but verbose, i.e. foo=$(foo)
522 ++%: varname=$(subst +,,$@)
523 ++%:
524         @echo "$(varname)=$($(varname))"
525 +%: varname=$(subst +,,$@)
526 +%:
527         @echo "$($(varname))"
528
529 # external nodes and links
530 #
531 ALL_LINKS := $(LINKS) $(patsubst L/%,%,$(filter L/%,$(MAKECMDGOALS)))
532 EXTERNAL_LINKS := $(filter $(foreach host,$(EXTERNAL_HOSTS),%-$(host)),$(ALL_LINKS))
533
534 $(foreach host,$(EXTERNAL_HOSTS),sshcheck-$(host)): ;
535 $(foreach host,$(EXTERNAL_HOSTS),ovsversion-$(host)): ;
536 $(foreach host,$(EXTERNAL_HOSTS),showdpid-$(host)): ;
537 $(foreach host,$(EXTERNAL_HOSTS),showmac-$(host)): ;
538 $(foreach host,$(EXTERNAL_HOSTS),showports-$(host)): ;
539 $(foreach host,$(EXTERNAL_HOSTS),update-$(host)): ;
540 $(foreach host,$(EXTERNAL_HOSTS),del-controller-$(host)): ;
541 $(foreach host,$(EXTERNAL_HOSTS),cache/status.$(host)): ;
542 $(foreach host,$(EXTERNAL_HOSTS),cache/controller.$(host)): ;
543
544 $(foreach host,$(EXTERNAL_HOSTS),cache/rsnap.ip.$(host)): ;
545         @touch $@
546
547 $(foreach host,$(EXTERNAL_HOSTS),cache/rsnap.links.$(host)): ;
548         @touch $@
549
550 $(foreach host,$(EXTERNAL_HOSTS),cache/db.$(host)):
551         @touch $@
552
553 $(foreach host,$(EXTERNAL_HOSTS),del-db.$(host)): del-db.%:
554         @rm cache/db.$*
555
556 $(foreach host,$(EXTERNAL_HOSTS),cache/switch.$(host)): ;
557         @touch $@
558
559 $(foreach host,$(EXTERNAL_HOSTS),del-switch.$(host)): del-switch.%:
560         @rm -f cache/switch.$* \
561                cache/port.$*$(SEP)*@1  cache/port.*$(SEP)$*@2  \
562                cache/endpoint.$*$(SEP)*@2  cache/endpoint.*$(SEP)$*@1  \
563                L/$*$(SEP)*            L/*$(SEP)$* \
564                cache/controller.$*
565
566 .SECONDEXPANSION:
567
568 $(foreach host,$(EXTERNAL_HOSTS),cache/bridge.$(host)): cache/bridge.%: | cache/db.%
569         @echo "Creating fake bridge on external host $(call display,$*)"
570         @touch $@
571
572 $(foreach link,$(EXTERNAL_LINKS),cache/iface.$(link)@2): cache/iface.%: cache/bridge.$$(call get,%) | cache/db.$$(call get,%)
573         @echo "Creating fake interface for link $(call linkpart,$*) on external host $(call get,$*)"
574         @touch $@
575
576 $(foreach link,$(EXTERNAL_LINKS),cache/port.$(link)@2): cache/port.%: cache/iface.% cache/switch.$$(call get,%)
577         @echo "Getting port number for link $(call linkpart,$(*F)) on external host $(call display,$(call get,$(*F)))"
578         @echo $(call default,EXTERNAL_PORT,$(call rightnode,$*)) > $@
579
580
581 $(foreach link,$(EXTERNAL_LINKS),del-iface.$(link)@2): del-iface.%: | cache/db.$$(call get,%)
582         @echo "Removing fake interface for link $(call linkpart,$*) from external host $(call get,$*)"
583         @rm -f cache/iface.$* \
584                cache/port.$* cache/endpoint.$* cache/endpoint.$(call opp,$*) \
585                L/$(call linkpart,$*)
586
587 $(foreach host,$(EXTERNAL_HOSTS),del-bridge.$(host)): del-bridge.%: | cache/db.%
588         @echo "Deleting fake bridge on external host $(call display,$*)"
589         @rm -f cache/bridge.$* \
590               cache/iface.$*$(SEP)*@1 cache/iface.*$(SEP)$*@2 \
591               cache/port.$*$(SEP)*@1  cache/port.*$(SEP)$*@2  \
592               cache/endpoint.$*$(SEP)*@?  cache/endpoint.*$(SEP)$*@?  \
593               L/$*$(SEP)*             L/*$(SEP)$* \
594               cache/controller.$*
595
596 $(foreach link,$(EXTERNAL_LINKS),ping-$(call get,$(link)@2)$(SEP)$(call get,$(link)@1)): ping-%: FORCE
597         @echo "Test from external host $(call get,$*@1) to $(call get,$*@2) skipped"
598
599 # we assume that a program called tunproxy is available on the
600 # external nodes.  
601 $(foreach link,$(EXTERNAL_LINKS),cache/endpoint.$(link)@2): cache/endpoint.%@2: cache/port.%@1 cache/host.$$(call leftnode,%)
602         @#echo $* [$<] [$^] $(call rightnode,$*)
603         @echo "===>" $(call rightnode,$*): \
604            ./tunproxy -t $$(cat cache/host.$(call leftnode,$*)):$$(cat cache/port.$*@1) \
605            -p $(call default,EXTERNAL_PORT,$(call rightnode,$*)) -e -d
606
607 # reporting
608 .PHONY: report
609 report: 
610         @echo SHELL=$(SHELL)
611         @echo "===> Configuration ($(CONF)):"
612         @cat $(CONF)
613         @for f in log/*; do \
614              echo "===> Log file $$(basename $$f):"; \
615              cat $$f; \
616          done