better dependencies for external links
[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 show-mac)\"
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,$*)"
176         @host $(HOST_$*) | sed -n 's/^.*has address *//p' > $@
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.%
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 CLEANTARGETS=$(addprefix del-,$(notdir $(wildcard cache/bridge.*)))
400 clean: $(CLEANTARGETS)
401 distclean:
402         rm -rf L log cache
403 .PHONY: clean distclean
404
405 ####################
406 graph.dot:
407         ( echo "digraph $(SLICE) {"; ls L | sed 's/$(SEP)/->/;s/$$/;/'; echo "}" ) > $@
408 graph.ps: graph.dot
409         dot -Tps < $^ > $@      
410
411 ####################
412 # googlemap stuff
413 # Uses:
414 # GMAP_SERVER, the hostname that runs an ndnmap instance
415 # GMAP_PROBES, a list of tuples of the form
416 # <linkid>=<nodeid>=<internal_linkid>=<frequency>
417 # e.g.
418 # SENDER-MUX=SENDER=3=0.5
419 # which would mean, the link 'SENDER-MUX' should be monitored at the 'SENDER' node and is coded 
420 # in links.json with id=3, every half second
421 # sliver-ovs gmap-probe is designed to run in background,
422 # and so that a new run will kill any previously running instance
423 gprobes: $(foreach probe,$(GMAP_PROBES),gprobe-$(probe))
424
425 gprobe-%: FORCE
426         $(SSH) -n $(call solve,$(word 2,$(subst @, ,$(*F)))) $(SUDO) \
427         sliver-ovs gmap-probe L$(word 1,$(subst @, ,$(*F))) $(GMAP_SERVER) $(word 3,$(subst @, ,$(*F))) $(word 4,$(subst @, ,$(*F)))
428
429 jsons: routers.json links.json geocode.json
430 .PHONE: jsons
431
432 routers.json: $(CONF)
433         @{  echo "[";   \
434             sep="  ";   \
435             for n in $(CONF_NODE_IDS); do \
436                 echo "    $$sep\"$$n\"";  \
437                 sep=", "; \
438             done; \
439             echo "]"; \
440           } > $@
441
442 links.json: $(foreach l,$(LINKS),cache/json.$(l))
443         @{  echo "["; \
444             cat $^ | sed '2,$$s/^/, /'; \
445             echo "]"; \
446          } > $@
447
448 cache/json.%: $(CONF)
449         @echo "{\"id\": $($*_linkid), \"start\": \"$(call get,$*@1)\", \"end\": \"$(call get,$*@2)\"}" > $@
450
451 geocode.json: $(foreach n,$(CONF_NODE_IDS),cache/geocode.$(n))
452         @{  echo "{"; \
453             sep="  "; \
454             for f in $^; do \
455                 echo -n "$$sep"; \
456                 cat $$f; \
457                 sep=", "; \
458             done; \
459             echo "}"; \
460          } > $@
461              
462 cache/geocode.%: cache/loc.% $(CONF)
463         @{  echo "\"$*\": {"; \
464             echo "    \"name\": \"$(HOST_$*)\","; \
465             echo "    \"shortname\": \"$*\","; \
466             echo "    \"site\": \"\","; \
467             echo "    \"backbone\": false,"; \
468             echo "    \"position\": [ $(shell cat cache/loc.$*) ]"; \
469             echo "   }"; \
470          } > $@
471
472 cache/loc.%: $(CONF)
473         @wget -O - 'http://freegeoip.net/csv/$(HOST_$*)' | \
474             awk -F, '{ printf "%s, %s\n", $$8, $$9 }' > $@
475
476 ####################
477 # 'virtual' targets in that there's no real file attached
478 define node_shortcuts
479 sshcheck.$(1): sshcheck-$(1) FORCE
480 db.$(1): cache/db.$(1) FORCE
481 switch.$(1): cache/switch.$(1) FORCE
482 start.$(1): cache/start.$(1) FORCE
483 stop.$(1): cache/stop.$(1) FORCE
484 status.$(1): cache/status.$(1) FORCE
485 bridge.$(1): cache/bridge.$(1) FORCE
486 host.$(1): cache/host.$(1) FORCE
487 controller.$(1): cache/controller.$(1) FORCE
488 # switch already depends on db, but well
489 cache/start.$(1): cache/db.$(1) cache/switch.$(1) FORCE
490 endef
491
492 $(foreach id,$(ALL_NODE_IDS), $(eval $(call node_shortcuts,$(id))))
493
494 define link_shortcuts
495 iface.%: cache/iface.%
496 endpoint.%: cache/endpoint.%
497 endef
498
499 $(foreach id,$(ALL_LINK_IDS), $(eval $(call link_shortcuts,$(id))))
500
501 help:
502         @cat Makefile.help
503
504 #################### convenience, for debugging only
505 # make +foo : prints the value of $(foo)
506 # make ++foo : idem but verbose, i.e. foo=$(foo)
507 ++%: varname=$(subst +,,$@)
508 ++%:
509         @echo "$(varname)=$($(varname))"
510 +%: varname=$(subst +,,$@)
511 +%:
512         @echo "$($(varname))"
513
514 # external nodes and links
515 #
516 ALL_LINKS := $(LINKS) $(patsubst L/%,%,$(filter L/%,$(MAKECMDGOALS)))
517 EXTERNAL_LINKS := $(filter $(foreach host,$(EXTERNAL_HOSTS),%-$(host)),$(ALL_LINKS))
518
519 $(foreach host,$(EXTERNAL_HOSTS),sshcheck-$(host)): ;
520 $(foreach host,$(EXTERNAL_HOSTS),ovsversion-$(host)): ;
521 $(foreach host,$(EXTERNAL_HOSTS),showdpid-$(host)): ;
522 $(foreach host,$(EXTERNAL_HOSTS),showmac-$(host)): ;
523 $(foreach host,$(EXTERNAL_HOSTS),showports-$(host)): ;
524 $(foreach host,$(EXTERNAL_HOSTS),update-$(host)): ;
525 $(foreach host,$(EXTERNAL_HOSTS),del-controller-$(host)): ;
526 $(foreach host,$(EXTERNAL_HOSTS),cache/status.$(host)): ;
527 $(foreach host,$(EXTERNAL_HOSTS),cache/db.$(host)): ;
528 $(foreach host,$(EXTERNAL_HOSTS),cache/bridge.$(host)): ;
529 $(foreach host,$(EXTERNAL_HOSTS),cache/switch.$(host)): ;
530 $(foreach host,$(EXTERNAL_HOSTS),cache/controller.$(host)): ;
531 $(foreach link,$(EXTERNAL_LINKS),cache/iface.$(link)@2): ;
532 $(foreach link,$(EXTERNAL_LINKS),cache/port.$(link)@2): ;
533 $(foreach link,$(EXTERNAL_LINKS),del-iface.$(link)@2): ;
534
535 # we assume that a program called tunproxy is available on the
536 # external nodes.  
537
538 .SECONDEXPANSION:
539 $(foreach link,$(EXTERNAL_LINKS),cache/endpoint.$(link)@2): cache/endpoint.%@2: cache/port.%@1 cache/host.$$(call leftnode,%)
540         @#echo $* [$<] [$^] $(call rightnode,$*)
541         @echo $(call default,EXTERNAL_PORT,$(call rightnode,$*)) > $@
542         @echo "===>" $(call rightnode,$*): \
543            ./tunproxy -t $$(cat cache/host.$(call leftnode,$*)):$$(cat cache/port.$*@1) \
544            -p $(call default,EXTERNAL_PORT,$(call rightnode,$*)) -e -d
545