This repository has been archived by the owner on Nov 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.iotlab
83 lines (66 loc) · 3.16 KB
/
Makefile.iotlab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
.PHONY: iotlab-running iotlab-submit iotlab-stop iotlab-reset
# Experiment parameters
IOTLAB_SITE ?= grenoble
IOTLAB_NODES ?= 2
IOTLAB_DURATION ?= 30
IOTLAB_ARCHI ?= m3:at86rf231
IOTLAB_NAME ?= $(IOTLAB_TYPE)-exp
IOTLAB_ID ?= $(shell iotlab-experiment get -l --state Running | grep -m 1 '"id"' | grep -Eo '[[:digit:]]+')
IOTLAB_TYPE = $(firstword $(subst :, ,$(IOTLAB_ARCHI)))
IOTLAB_RESOURCES ?= $(if $(IOTLAB_ID),\
$(shell iotlab-experiment get -ri -i $(IOTLAB_ID) | \
grep -i '"$(IOTLAB_TYPE)"' | sed -E 's/.*"([-\+0-9]+)"/\1/'\
)\
)
IOTLAB_WAIT ?= 60
IOTLAB_PROFILE ?= battery
# Authentication parameters
IOTLAB_CONFIG = $(HOME)/.iotlabrc
IOTLAB_USER ?= $(shell cut -f 1 -d : $(IOTLAB_CONFIG))
# For ssh
IOTLAB_AUTH = "$(IOTLAB_USER)@$(IOTLAB_SITE).iot-lab.info"
# Variables to perform remote commands
IOTLAB_SITE_SSH = ssh -tt $(IOTLAB_AUTH) "(bash -l -c 'cd ~/$(1); $(2)')"
IOTLAB_SITE_RSYNC = rsync -azP $(1) $(IOTLAB_AUTH):$(2) $(3)
IOTLAB_A8_SSH = ssh -tt root@node-a8-$(1).$(IOTLAB_SITE).iot-lab.info "(bash -l -c 'cd ~/$(2); $(3)')"
IOTLAB_A8_TUNNEL = ssh -q -f -L 222$(1):node-a8-$(1).$(IOTLAB_SITE).iot-lab.info:22 $(IOTLAB_AUTH) "sleep 1"
IOTLAB_A8_TUNNEL_SSH = $(call IOTLAB_A8_TUNNEL,$(1)); ssh -o StrictHostKeyChecking=no -p 222$(1) -tt root@localhost "(bash -l -c 'cd ~/$(2);$(3)')"
# For split and join operations
null :=
space := $(null) #
comma := ,
# Alias resource selection by default
IOTLAB_NODES_LIST = "$(IOTLAB_NODES),archi=$(IOTLAB_ARCHI)+site=$(IOTLAB_SITE),,$(IOTLAB_PROFILE)"
ifneq (,$(IOTLAB_RESOURCES))
IOTLAB_NODES_LIST = $(IOTLAB_SITE),$(IOTLAB_TYPE),$(IOTLAB_RESOURCES),,$(IOTLAB_PROFILE)
endif
IOTLAB_NODE_ID_LIST = $(if $(IOTLAB_ID),$(shell iotlab-experiment get -r -i $(IOTLAB_ID) | \
grep '"network_address"' | \
sed -E 's/.*$(IOTLAB_TYPE)-([0-9]+)\.$(IOTLAB_SITE)\.iot-lab\.info.*/\1/'))
# Dependencies for iot lab
COMMANDS += iotlab-auth iotlab-experiment iotlab-node
$(IOTLAB_CONFIG):
iotlab-auth -u $(IOTLAB_USER)
iotlab-id: iotlab-experiment $(IOTLAB_CONFIG)
@echo $(if $(IOTLAB_ID),$(IOTLAB_ID),$(error No experiment running))
iotlab-running: iotlab-experiment $(IOTLAB_CONFIG)
$(if $(IOTLAB_ID),,$(error No experiment running))
iotlab-submit: iotlab-experiment $(IOTLAB_CONFIG)
$(if $(IOTLAB_ID),$(error Found experiment running with id $(IOTLAB_ID)))
$(if $(Q),,$(info "iotlab-experiment submit \
-n $(IOTLAB_NAME) \
-d $(IOTLAB_DURATION) \
-l $(IOTLAB_NODES_LIST)"))
$(eval IOTLAB_ID := $(shell iotlab-experiment submit \
-n $(IOTLAB_NAME) \
-d $(IOTLAB_DURATION) \
-l $(IOTLAB_NODES_LIST) | \
grep -m 1 '"id"' | grep -Eo '[[:digit:]]+'))
$(if $(shell iotlab-experiment wait -i $(IOTLAB_ID) --timeout $(IOTLAB_WAIT)),, \
$(error Failed to launch experiment $(shell iotlab-experiment stop -i $(IOTLAB_ID) | grep -m 1 '"id"' | grep -Eo '[[:digit:]]+')))
$(info OK)
iotlab-stop: iotlab-experiment iotlab-running
$(Q)iotlab-experiment stop -i $(IOTLAB_ID)
iotlab-reset: iotlab-node iotlab-running
# TODO: this doesn't work if IOTLAB_TYPE=a8
iotlab-node --reset -i $(IOTLAB_ID) -l $(IOTLAB_SITE),$(IOTLAB_TYPE),$(IOTLAB_RESOURCES)