-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
277 lines (236 loc) · 8.12 KB
/
Makefile
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# Copyright 2024 Louis Royer. All rights reserved.
# Use of this source code is governed by a MIT-style license that can be
# found in the LICENSE file.
# SPDX-License-Identifier: MIT
BUILD_DIR = build
BCOMPOSE = $(BUILD_DIR)/compose.yaml
BCONFIG = $(BUILD_DIR)/config.yaml
PROFILES = --profile debug
PROJECT_DIRECTORY = --project-directory $(BUILD_DIR)
MAKE = make --no-print-directory
$(BCOMPOSE): templates/compose.yaml.j2 scripts/jinja/customize.py $(BCONFIG)
@echo Building $(BCOMPOSE) from jinja template
@mkdir -p $$(dirname $(BCOMPOSE))
@j2 --customize scripts/jinja/customize.py -o $(BCOMPOSE) templates/compose.yaml.j2 $(BCONFIG)
$(BCONFIG): default-config.yaml
@echo Copying default-config.yaml into $(BCONFIG)
@mkdir -p $$(dirname $(BCONFIG))
@cp default-config.yaml $(BCONFIG)
.PHONY: test
test:
@$(MAKE) clean
@echo [1/4] Running linter on python scripts
@$(MAKE) test/lint/python
@echo [2/3] Running tests for Free5GC config
@$(MAKE) test/free5gc
@echo [3/4] Running tests for NextMN/UPF config
@$(MAKE) test/nextmn-upf
@echo [4/4] Running tests for NextMN/SRv6 config
@$(MAKE) test/nextmn-srv6
.PHONY: test/lint/python
test/lint/python:
@find -type f -iname '*.py' -print | parallel '(echo -n Running pylint on {} ; pylint --persistent=false -v -j 0 {})' :::
.PHONY: test/lint/yaml
test/lint/yaml:
@echo "disable_openssl_generation: true" >> $(BCONFIG)
@$(MAKE) build
@echo Running yamllint
@yamllint $(BUILD_DIR) default-config.yaml
@echo Running docker compose config
@docker compose $(PROJECT_DIRECTORY) config >/dev/null
@$(MAKE) clean
.PHONY: test/nextmn-srv6
test/nextmn-srv6:
@$(MAKE) set/dataplane/nextmn-srv6
@$(MAKE) test/lint/yaml
.PHONY: test/nextmn-upf
test/nextmn-upf:
@$(MAKE) set/dataplane/nextmn-upf
@$(MAKE) test/lint/yaml
.PHONY: test/nextmn-free5gc
test/free5gc:
@$(MAKE) set/dataplane/free5gc
@$(MAKE) test/lint/yaml
.PHONY: set/dataplane
set/dataplane/%: $(BCONFIG)
@echo Set dataplane to $(@F)
@./scripts/config_edit.py $(BCONFIG) --dataplane=$(@F)
.PHONY: set/nb-edges
set/nb-edges/%: $(BCONFIG)
@echo Set number of edges to $(@F)
@./scripts/config_edit.py $(BCONFIG) --nb-edges=$(@F)
.PHONY: set/nb-ue
set/nb-ue/%: $(BCONFIG)
@echo Set number of ue to $(@F)
@./scripts/config_edit.py $(BCONFIG) --nb-ue=$(@F)
.PHONY: set/log-level
set/log-level/%: $(BCONFIG)
@echo Set log level to $(@F)
@./scripts/config_edit.py $(BCONFIG) --log-level=$(@F)
.PHONY: set/full-debug
set/full-debug/%: $(BCONFIG)
@echo Set full-debug to $(@F)
@./scripts/config_edit.py $(BCONFIG) --full-debug=$(@F)
.PHONY: set/ran
set/ran/%: $(BCONFIG)
@echo Set ran to $(@F)
@./scripts/config_edit.py $(BCONFIG) --ran=$(@F)
.PHONY: set/handover
set/handover: $(BCONFIG)
@echo Set handover to true
@./scripts/config_edit.py $(BCONFIG) --handover=true
@$(MAKE) set/dataplane/free5gc
@$(MAKE) set/nb-ue/2
@$(MAKE) set/nb-edges/1
@$(MAKE) set/log-level/debug
@$(MAKE) set/full-debug/true
@$(MAKE) set/ran/dev
.PHONY: clean
clean:
@rm -rf $(BUILD_DIR)
.PHONY: build
build:
@$(MAKE) $(BCOMPOSE)
.PHONY: pull
pull: $(BCOMPOSE)
@echo Pulling Docker images
@docker compose $(PROFILES) $(PROJECT_DIRECTORY) pull
.PHONY: pull/all
pull/all:
@echo Pull **all** Docker images
@docker compose -f templates/images-list.yaml pull
.PHONY: u
u:
@$(MAKE) up
.PHONY: d
d:
@$(MAKE) down
.PHONY: r
r:
@$(MAKE) restart
.PHONY: up
up: $(BCOMPOSE)
@# set containers up
@docker compose $(PROFILES) $(PROJECT_DIRECTORY) up -d
.PHONY: up-fg
up-fg: $(BCOMPOSE)
@# set containers up in foreground
@docker compose $(PROFILES) $(PROJECT_DIRECTORY) up
.PHONY: ctrl
ctrl: $(BCONFIG)
@# show control plane REST API in firefox
@scripts/show_ctrl.py $(BCONFIG)
.PHONY: down
down:
@# shutdown containers
@#> don't depends on build-all because we need the old version to delete all
@docker compose $(PROFILES) $(PROJECT_DIRECTORY) down -v
.PHONY: restart
restart:
@# restart all containers
@docker compose $(PROFILES) $(PROJECT_DIRECTORY) restart
.PHONY: e
e/%:
@# enter container
docker exec -it $(@F) bash
.PHONY: ran
ran/%:
@# exec nr-cli inside container
docker exec -it $(@F) bash -c 'nr-cli $$(nr-cli --dump)'
.PHONY: db
db/%:
@# enter database of a container
docker exec -it $(@F)-db psql postgres -U postgres
.PHONY: t
t/%:
@# enter container in debug mode
docker exec -it $(@F)-debug bash
.PHONY: l
l:
@# show all logs
docker compose $(PROFILES) $(PROJECT_DIRECTORY) logs
l/%:
@# show container's logs
docker compose $(PROFILES) $(PROJECT_DIRECTORY) logs $(@F)
.PHONY: lf
lf:
@# show all logs (continuous)
docker compose $(PROFILES) $(PROJECT_DIRECTORY) logs -f
lf/%:
@# show container's logs (continuous)
docker compose $(PROFILES) $(PROJECT_DIRECTORY) logs $(@F) -f
.PHONY: ps
ps:
@# show container's status
docker compose $(PROFILES) $(PROJECT_DIRECTORY) ps
.PHONY: ping
ping/%:
@# ping from a container
@docker exec -it $(*D)-debug bash -c "ping $(@F)"
.PHONY: ue/ip
ue/ip/%:
@# show ip of ue
@docker exec -it ue$(@F)-debug bash -c "ip --brief address show uesimtun0|awk '{print \"ue$(@F):\", \$$3; exit}'"
.PHONY: ue/ping
ue/ping/%:
@# ping between ues
@# example:
@# make ue/ping/1/2
@# pings from ue1 to ue2
@TARGET=$(shell docker exec -it ue$(@F)-debug bash -c "ip --brief address show uesimtun0|awk '{print \$$3; exit}'|cut -d"/" -f 1");\
docker exec -it ue$(*D)-debug bash -c "ping $$TARGET"
.PHONY: ue/switch-edge
ue/switch-edge/%:
@# swich edge for ue
@UE_IP=$(shell docker exec ue$(@F)-debug bash -c "ip --brief address show uesimtun0|awk '{print \$$3; exit}'|cut -d"/" -f 1");\
scripts/switch.py $(BCONFIG) $$UE_IP
.PHONY: plot/policy-diff
plot/policy-diff:
@echo "[1/2] [1/6] Configuring testbed with NextMN-SRv6"
@$(MAKE) set/dataplane/nextmn-srv6
@$(MAKE) set/nb-ue/2
@$(MAKE) set/nb-edges/2
@$(MAKE) set/full-debug/false
@$(MAKE) set/log-level/info
@echo "[1/2] [2/6] Starting containers"
@$(MAKE) up
@echo "[1/2] [3/6] Adding latency on instance s0"
@docker exec s0-debug bash -c "tc qdisc add dev edge-0 root netem delay 5ms"
@sleep 2
@docker exec ue1-debug bash -c "ping -c 1 10.4.0.1 > /dev/null" # check instance is reachable
@docker exec ue2-debug bash -c "ping -c 1 10.4.0.1 > /dev/null" # check instance is reachable
@echo "[1/2] [4/6] Setting UE2 on edge 1"
@$(MAKE) ue/switch-edge/2
@echo "[1/2] [5/6] [$$(date --rfc-3339=seconds)] Starting ping from ue1 and ue2 (60s + 5s margin)"
@bash -c 'docker exec ue1-debug bash -c "ping -D -w 60 10.4.0.1 -i 0.1 > /volume/ping-policy-diff-areaA.txt"' &
@bash -c 'docker exec ue2-debug bash -c "ping -D -w 60 10.4.0.1 -i 0.1 > /volume/ping-policy-diff-areaB.txt"' &
@sleep 65
@echo "[1/2] [6/6] Stopping containers"
@$(MAKE) down
@echo "[2/2] Plotting data"
@scripts/plots/policy_diff.py $(BUILD_DIR)/volumes/ue1/ping-policy-diff-areaA.txt $(BUILD_DIR)/volumes/ue2/ping-policy-diff-areaB.txt $(BUILD_DIR)/volumes/ue1/plot-policy-diff.pdf
.PHONY: plot/latency-switch
plot/latency-switch:
@echo "[1/7] Configuring testbed with NextMN-SRv6 + Free5GC"
@$(MAKE) set/dataplane/nextmn-srv6+free5gc
@$(MAKE) set/nb-ue/1
@$(MAKE) set/nb-edges/2
@$(MAKE) set/full-debug/false
@$(MAKE) set/log-level/info
@echo "[2/7] Starting containers"
@$(MAKE) up
@echo "[3/7] Adding latency on instance s0"
@docker exec s0-debug bash -c "tc qdisc add dev edge-0 root netem delay 5ms"
@sleep 2
@docker exec ue1-debug bash -c "ping -c 1 10.4.0.1 > /dev/null" # check instance is reachable
@docker exec ue3-debug bash -c "ping -c 1 10.4.0.1 > /dev/null" # check instance is reachable
@echo "[4/7] [$$(date --rfc-3339=seconds)] Scheduling instance switch in 30s"
@bash -c 'sleep 30 && $(MAKE) ue/switch-edge/1 && echo "[5.5/7] [$$(date --rfc-3339=seconds)] Switching to edge 1"' &
@echo "[5/7] [$$(date --rfc-3339=seconds)] Start ping for 60s + 5s margin"
@bash -c 'docker exec ue3-debug bash -c "ping -D -w 60 10.4.0.1 -i 0.1 > /volume/ping-ulcl.txt"' &
@bash -c 'docker exec ue1-debug bash -c "ping -D -w 60 10.4.0.1 -i 0.1 > /volume/ping-sr4mec.txt"' &
@sleep 65
@echo "[6/7] Stopping containers"
@$(MAKE) down
@echo "[7/7] Plotting data"
@scripts/plots/latency_switch.py $(BUILD_DIR)/volumes/ue1/ping-sr4mec.txt $(BUILD_DIR)/volumes/ue3/ping-ulcl.txt $(BUILD_DIR)/volumes/ue1/plot-latency-switch.pdf