-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmosaic-cefore.py
executable file
·877 lines (759 loc) · 32.9 KB
/
mosaic-cefore.py
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
#!/usr/bin/env python3
# pylint: disable=c0103, c0111, r0912, r0913, r0914
# This script is derived from r2lab-demos/openair/mosaic-demo.py
### standard library
import os
import time
import readline
from itertools import chain, cycle
from pathlib import Path
from collections import defaultdict
from argparse import (ArgumentParser, ArgumentDefaultsHelpFormatter,
RawTextHelpFormatter)
### nepi-ng
from asynciojobs import Scheduler, PrintJob
from apssh import SshNode, SshJob, Run, RunScript, Pull
from apssh import TimeColonFormatter
from apssh import Service
### r2lab - for illustration purposes
# testbed preparation
from r2lab import prepare_testbed_scheduler
# utils
from r2lab import r2lab_hostname, r2lab_parse_slice, find_local_embedded_script
# argument parsing
from r2lab import ListOfChoices, ListOfChoicesNullReset
# include the set of utility scripts that are included by the r2lab kit
INCLUDES = [find_local_embedded_script(x) for x in (
"r2labutils.sh", "nodes.sh", "mosaic-common.sh",
)]
### harware map
# the python code for interacting with sidecar is too fragile for now
# to be invoked every time; plus, it takes time; so:
def hardwired_hardware_map():
return {
'E3372-UE': (2, 26),
'OAI-UE': (6, 19),
}
# build our hardware map: we compute the ids of the nodes
# that have the characteristics that we want
def probe_hardware_map():
# import here so depend on socketIO_client only if needed
from r2lab import SidecarSyncClient
import ssl
ssl_context = ssl.SSLContext()
ssl_context.verify_mode = ssl.CERT_NONE
with SidecarSyncClient(ssl=ssl_context) as sidecar:
nodes_hash = sidecar.nodes_status()
if not nodes_hash:
print("Could not probe testbed status - exiting")
exit(1)
# debug
#for id in sorted(nodes_hash.keys()):
# print(f"node[{id}] = {nodes_hash[id]}")
# we search for the nodes that have usrp_type == 'e3372'
e3372_ids = [id for id, node in nodes_hash.items()
if node['usrp_type'] == 'e3372']
# and here the ones that have a b210 with a 'for UE' duplexer
oaiue_ids = [id for id, node in nodes_hash.items()
if node['usrp_type'] == 'b210'
and 'ue' in node['usrp_duplexer'].lower()]
return {
'E3372-UE' : e3372_ids,
'OAI-UE' : oaiue_ids,
}
def show_hardware_map(hw_map):
print("Nodes that can be used as E3372 UEs (suitable for -E/-e):",
', '.join([str(id) for id in sorted(hw_map['E3372-UE'])]))
print("Nodes that can be used as OpenAirInterface UEs (suitable for -U/-u)",
', '.join([str(id) for id in sorted(hw_map['OAI-UE'])]))
# make sure to store data in $HOME on the remote box
tcpdump_cn_pcap = "data-network.pcap"
tcpdump_cn_service = Service(
command=f"tcpdump -n -U -i data -w ~/{tcpdump_cn_pcap}",
service_id="tcpdump-data",
verbose=True,
)
############################## first stage
def run(*, # pylint: disable=r0912, r0914, r0915
# the pieces to use
slicename, cn, ran, phones,
e3372_ues, oai_ues, gnuradios,
e3372_ue_xterms, gnuradio_xterms, ns3,
# boolean flags
load_nodes, reset_usb, oscillo, tcp_streaming,
# the images to load
image_cn, image_ran, image_oai_ue, image_e3372_ue, image_gnuradio, image_T_tracer, image_ns3,
# miscell
n_rb, nodes_left_alone, T_tracer, publisher_ip, verbose, dry_run):
"""
##########
# 3 methods to get nodes ready
# (*) load images
# (*) reset nodes that are known to have the right image
# (*) do nothing, proceed to experiment
expects e.g.
* slicename : s.t like inria_mosaic@faraday.inria.fr
* cn : 7
* ran : 23
* ns3 : 32
* phones: list of indices of phones to use
* e3372_ues : list of nodes to use as a UE using e3372
* oai_ues : list of nodes to use as a UE using OAI
* gnuradios : list of nodes to load with a gnuradio image
* T_tracer : list of nodes to load with a tracer image
* image_* : the name of the images to load on the various nodes
Plus
* load_nodes: whether to load images or not - in which case
image_cn, image_ran and image_*
are used to tell the image names
* reset_usb : the USRP board will be reset when this is set
* tcp_streaming : set up TCP streaming scenario
* publisher_ip : IP address of the publisher
"""
# what argparse knows as a slice actually is about the gateway (user + host)
gwuser, gwhost = r2lab_parse_slice(slicename)
gwnode = SshNode(hostname=gwhost, username=gwuser,
formatter=TimeColonFormatter(verbose=verbose), debug=verbose)
hostnames = [r2lab_hostname(x) for x in (cn, ran)]
cnnode, rannode = [
SshNode(gateway=gwnode, hostname=hostname, username='root',
formatter=TimeColonFormatter(verbose=verbose), debug=verbose)
for hostname in hostnames
]
scheduler = Scheduler(verbose=verbose, label="CORE EXP")
########## prepare the image-loading phase
# focus on the experiment, and use
# prepare_testbed_scheduler later on to prepare testbed
# all we need to do at this point is compute a mapping dict
# image -> list-of-nodes
images_to_load = defaultdict(list)
images_to_load[image_cn] += [cn]
images_to_load[image_ran] += [ran]
if e3372_ues:
images_to_load[image_e3372_ue] += e3372_ues
if e3372_ue_xterms:
images_to_load[image_e3372_ue] += e3372_ue_xterms
if oai_ues:
images_to_load[image_oai_ue] += oai_ues
if gnuradios:
images_to_load[image_gnuradio] += gnuradios
if gnuradio_xterms:
images_to_load[image_gnuradio] += gnuradio_xterms
if T_tracer:
images_to_load[image_T_tracer] += T_tracer
if ns3:
images_to_load[image_ns3] += [ns3]
# start core network
job_start_cn = SshJob(
node=cnnode,
commands=[
RunScript(find_local_embedded_script("nodes.sh"),
"git-pull-r2lab",
includes=INCLUDES),
RunScript(find_local_embedded_script("mosaic-cn.sh"),
"journal --vacuum-time=1s",
includes=INCLUDES),
RunScript(find_local_embedded_script("mosaic-cn.sh"), "configure",
includes=INCLUDES),
RunScript(find_local_embedded_script("mosaic-cn.sh"), "start",
includes=INCLUDES),
tcpdump_cn_service.start_command(),
],
label="start CN service",
scheduler=scheduler,
)
# prepare enodeb
reset_option = "-u" if reset_usb else ""
job_warm_ran = SshJob(
node=rannode,
commands=[
RunScript(find_local_embedded_script("nodes.sh"),
"git-pull-r2lab",
includes=INCLUDES),
RunScript(find_local_embedded_script("mosaic-ran.sh"),
"journal --vacuum-time=1s",
includes=INCLUDES),
RunScript(find_local_embedded_script("mosaic-ran.sh"),
"warm-up", reset_option,
includes=INCLUDES),
RunScript(find_local_embedded_script("mosaic-ran.sh"),
"configure -b", n_rb, cn,
includes=INCLUDES),
],
label="Configure eNB",
scheduler=scheduler,
)
ran_requirements = [job_start_cn, job_warm_ran]
###
if oai_ues:
# prepare OAI UEs
for ue in oai_ues:
ue_node = SshNode(gateway=gwnode, hostname=r2lab_hostname(ue), username='root',
formatter=TimeColonFormatter(verbose=verbose), debug=verbose)
job_warm_ues = [
SshJob(
node=ue_node,
commands=[
RunScript(find_local_embedded_script("nodes.sh"),
"git-pull-r2lab",
includes=INCLUDES),
RunScript(find_local_embedded_script("mosaic-oai-ue.sh"),
"journal --vacuum-time=1s",
includes=INCLUDES),
RunScript(find_local_embedded_script("mosaic-oai-ue.sh"),
"warm-up", reset_option,
includes=INCLUDES),
RunScript(find_local_embedded_script("mosaic-oai-ue.sh"),
"configure -b", n_rb,
includes=INCLUDES),
],
label=f"Configure OAI UE on fit{ue:02d}",
scheduler=scheduler)
]
ran_requirements.append(job_warm_ues)
###
if not load_nodes and phones:
job_turn_off_phones = SshJob(
node=gwnode,
commands=[
RunScript(find_local_embedded_script("faraday.sh"),
f"macphone{phone} phone-off")
for phone in phones],
scheduler=scheduler,
)
ran_requirements.append(job_turn_off_phones)
# wait for everything to be ready, and add an extra grace delay
grace = 5
grace_delay = PrintJob(
f"Allowing grace of {grace} seconds",
sleep=grace,
required=ran_requirements,
scheduler=scheduler,
label=f"settle for {grace}s",
)
# optionally start T_tracer
if T_tracer:
job_start_T_tracer = SshJob( # pylint: disable=w0612
node=SshNode(
gateway=gwnode, hostname=r2lab_hostname(T_tracer[0]), username='root',
formatter=TimeColonFormatter(verbose=verbose), debug=verbose),
commands=[
Run(f"/root/trace {ran}",
x11=True),
],
label="start T_tracer service",
required=ran_requirements,
scheduler=scheduler,
)
# ran_requirements.append(job_start_T_tracer)
# start services
graphical_option = "-x" if oscillo else ""
graphical_message = "graphical" if oscillo else "regular"
tracer_option = " -T" if T_tracer else ""
# we use a Python variable for consistency
# although it not used down the road
_job_service_ran = SshJob(
node=rannode,
commands=[
RunScript(find_local_embedded_script("mosaic-ran.sh"),
"start", graphical_option, tracer_option,
includes=INCLUDES,
x11=oscillo,
),
],
label=f"start {graphical_message} softmodem on eNB",
required=grace_delay,
scheduler=scheduler,
)
########## run experiment per se
# Manage phone(s) and OAI UE(s)
# this starts at the same time as the eNB, but some
# headstart is needed so that eNB actually is ready to serve
sleeps = [20, 30]
phone_msgs = [f"wait for {sleep}s for eNB to start up before waking up phone{id}"
for sleep, id in zip(sleeps, phones)]
wait_commands = [f"echo {msg}; sleep {sleep}"
for msg, sleep in zip(phone_msgs, sleeps)]
job_start_phones = [
SshJob(
node=gwnode,
commands=[
Run(wait_command),
RunScript(find_local_embedded_script("faraday.sh"), f"macphone{id}",
"r2lab-embedded/shell/macphone.sh", "phone-on",
includes=INCLUDES),
RunScript(find_local_embedded_script("faraday.sh"), f"macphone{id}",
"r2lab-embedded/shell/macphone.sh", "phone-start-app",
includes=INCLUDES),
],
label=f"turn off airplace mode on phone {id}",
required=grace_delay,
scheduler=scheduler)
for id, wait_command in zip(phones, wait_commands)]
if oai_ues:
delay = 25
for ue in oai_ues:
msg = f"wait for {delay}s for eNB to start up before running UE on node fit{ue:02d}"
wait_command = f"echo {msg}; sleep {delay}"
ue_node = SshNode(gateway=gwnode, hostname=r2lab_hostname(ue), username='root',
formatter=TimeColonFormatter(verbose=verbose), debug=verbose)
job_start_ues = [
SshJob(
node=ue_node,
commands=[
Run(wait_command),
RunScript(find_local_embedded_script("mosaic-oai-ue.sh"),
"start",
includes=INCLUDES),
],
label=f"Start OAI UE on fit{ue:02d}",
required=grace_delay,
scheduler=scheduler)
]
delay += 20
for ue in oai_ues:
environ = {'USER': 'root'}
cefnet_ue_service = Service("cefnetd", service_id="cefnet", environ=environ)
ue_node = SshNode(gateway=gwnode, hostname=r2lab_hostname(ue), username='root',
formatter=TimeColonFormatter(verbose=verbose), debug=verbose)
msg = f"Wait 60s and then ping faraday gateway from UE on fit{ue:02d}"
ue_commands = f"echo {msg}; sleep 60; ping -c 5 -I oip1 faraday.inria.fr"
if tcp_streaming:
# TCP streaming scenario
if load_nodes:
ue_commands += "sysctl -w net.ipv4.ip_forward=1;"
ue_commands += f"ip route add {publisher_ip}/32 dev oip1;"
ue_commands += "ip route add 10.1.1.0/24 via 192.168.2.32 dev data;"
ue_commands += "iptables -t nat -A POSTROUTING -s 10.1.1.2/32 -j SNAT --to-source 172.16.0.2;"
ue_commands += "iptables -t nat -A PREROUTING -d 172.16.0.2 -j DNAT --to-destination 10.1.1.2;"
ue_commands += "iptables -A FORWARD -d 10.1.1.2/32 -i oip1 -j ACCEPT;"
ue_commands += f"iptables -A FORWARD -d {publisher_ip}/32 -i data -j ACCEPT;"
ue_commands += "ip rule del from all to 172.16.0.2 lookup 201;"
ue_commands += "ip rule del from 172.16.0.2 lookup 201;"
ue_commands += "ip rule add from 10.1.1.2 lookup lte prio 32760;"
ue_commands += "ip rule add from all to 172.16.0.2 lookup lte prio 32761;"
ue_commands += "ip rule add from all fwmark 0x1 lookup lte prio 32762;"
ue_commands += "ip route add table lte 10.1.1.0/24 via 192.168.2.32 dev data;"
ue_commands += "sysctl -w net.ipv4.ip_forward=1;"
else:
ue_commands += "killall cefnetd || true"
job_setup_ue = [
SshJob(
node=ue_node,
commands=[
Run(ue_commands,label="test UE link and set up routing for TCP streaming"),
],
label=f"ping faraday gateway from UE on fit{ue:02d} and set up routing for the TCP streaming scenario",
critical=True,
required=job_start_ues,
scheduler=scheduler)
]
else:
# Cefore streaming scenario
if load_nodes:
ue_commands += "sysctl -w net.ipv4.ip_forward=1;"
ue_commands += "ip route add 10.1.1.0/24 via 192.168.2.32 dev data;"
else:
ue_commands += "killall cefnetd || true"
job_setup_ue = [
SshJob(
node=ue_node,
commands=[
Run(ue_commands,label="test UE link and set up routing for Cefore streaming"),
cefnet_ue_service.start_command(),
],
label=f"ping faraday gateway from fit{ue:02d} UE and set up routing for the Cefore streaming scenario",
critical=True,
required=job_start_ues,
scheduler=scheduler)
]
if ns3:
ns3_node = SshNode(gateway=gwnode, hostname=r2lab_hostname(ns3), username='root',
formatter=TimeColonFormatter(verbose=verbose), debug=verbose)
msg = f"Wait for the UE node to be ready before running the streaming scenario with ns-3 on fit{ns3}"
if load_nodes:
job_prepare_ns3_node = [
SshJob(
node=ns3_node,
commands=[
Run("turn-on-data"),
Run("ifconfig data promisc up"),
Run("ip route del default via 192.168.3.100 dev control"),
Run("ip route add default via 192.168.2.6 dev data || true"),
Run("sysctl -w net.ipv4.ip_forward=1"),
],
label=f"setup routing on ns-3 fit{ns3:02d} node",
critical=True,
required=job_setup_ue,
scheduler=scheduler)
]
ns3_requirements = job_prepare_ns3_node
else:
ns3_requirements = job_setup_ue
if not tcp_streaming:
environ = {'USER': 'root'}
cefnet_ns3_service = Service("cefnetd", service_id="cefnet", environ=environ)
job_start_cefnet_on_cn = [
SshJob(
node=cnnode,
commands=[
Run(f"echo 'ccn:/streaming tcp {publisher_ip}:80' > /usr/local/cefore/cefnetd.fib"),
Run("killall cefnetd || true"),
cefnet_ns3_service.start_command(),
],
label=f"Start Cefnet on EPC running at fit{cn:02d}",
critical=True,
required=ns3_requirements,
scheduler=scheduler,
)
]
# ditto
_job_ping_phones_from_cn = [
SshJob(
node=cnnode,
commands=[
Run("sleep 20"),
Run(f"ping -c 100 -s 100 -i .05 172.16.0.{id+1} &> /root/ping-phone{id}"),
],
label=f"ping phone {id} from core network",
critical=False,
required=job_start_phones,
scheduler=scheduler)
for id in phones]
########## xterm nodes
colors = ("wheat", "gray", "white", "darkolivegreen")
xterms = e3372_ue_xterms + gnuradio_xterms
for xterm, color in zip(xterms, cycle(colors)):
xterm_node = SshNode(
gateway=gwnode, hostname=r2lab_hostname(xterm), username='root',
formatter=TimeColonFormatter(verbose=verbose), debug=verbose)
SshJob(
node=xterm_node,
command=Run(f"xterm -fn -*-fixed-medium-*-*-*-20-*-*-*-*-*-*-*",
f" -bg {color} -geometry 90x10",
x11=True),
label=f"xterm on node {xterm_node.hostname}",
scheduler=scheduler,
# don't set forever; if we do, then these xterms get killed
# when all other tasks have completed
# forever = True,
)
# remove dangling requirements - if any
# should not be needed but won't hurt either
scheduler.sanitize()
##########
print(10*"*", "nodes usage summary")
if load_nodes:
for image, nodes in images_to_load.items():
for node in nodes:
print(f"node fit{node:02d} : {image}")
else:
print("NODES ARE USED AS IS (no image loaded, no reset)")
print(10*"*", "phones usage summary")
if phones:
for phone in phones:
print(f"Using phone{phone}")
else:
print("No phone involved")
if nodes_left_alone:
print(f"Ignore following fit nodes: {nodes_left_alone}")
print(f"Publisher IP is {publisher_ip}")
if tcp_streaming:
print("Run streaming scenario with TCP")
else:
print("Run streaming scenario with Cefore")
# wrap scheduler into global scheduler that prepares the testbed
scheduler = prepare_testbed_scheduler(
gwnode, load_nodes, scheduler, images_to_load, nodes_left_alone)
scheduler.check_cycles()
# Update the .dot and .png file for illustration purposes
name = "cefore-load" if load_nodes else "cefore"
print(10*'*', 'See main scheduler in',
scheduler.export_as_pngfile(name))
if verbose:
scheduler.list()
if dry_run:
return True
if verbose:
input('OK ? - press control C to abort ? ')
if not scheduler.orchestrate():
print(f"RUN KO : {scheduler.why()}")
scheduler.debrief()
return False
print("RUN OK")
print(80*'*')
if tcp_streaming:
# TCP streaming scenario
print(f"Now it's time to run the ns-3 script on node fit{ns3:02d}")
print(f"root@fit{ns3:02d}:~# /root/NS3/source/ns-3-dce/waf --run dce-tcp-test")
print("Then, run iperf on the publisher host:")
print("yourlogin@publisher:~# iperf -s -P 1 -p 80")
print(f"The log file used to plot figures will be available on fit{ns3:02d} at:")
print(" /root/NS3/source/ns-3-dce/files-4/var/log/56884/stdout")
else:
# Cefore streaming scenario
print("Now, if not already done, copy cefnetd and cefputfile binaries on your publisher host")
print("login@your_host:r2lab-demos/cefore# scp bin/cefnetd yourlogin@publisher_node:/usr/local/sbin")
print("login@your_host:r2lab-demos/cefore# scp bin/cefputfile yourlogin@publisher_node:/user/local/bin")
print(f"After that, run on the ns-3 fit{ns3:02d} node the following command:")
print(f"root@fit{ns3:02d}:~# /root/NS3/source/ns-3-dce/waf --run dce-cefore-test [--onlyRGI=1]")
print("Then, run on the publisher host:")
print("yourlogin@publisher:~# killall cefnetd; cefnetdstart")
print("yourlogin@publisher:~# cefputfile ccn:/streaming/test -f ./[file-name] -r [1 <= streaming_rate <= 32 (Mbps)]")
print(f"The log file used to plot figures will be available on fit{ns3:02d} at:")
print(" /root/NS3/source/ns-3-dce/files-3/tmp/cefgetstream-thuputLog-126230400110000")
print(80*'*')
return True
# use the same signature in addition to run_name by convenience
def collect(run_name, slicename, cn, ran, oai_ues, verbose, dry_run):
"""
retrieves all relevant logs under a common name
otherwise, same signature as run() for convenience
retrieved stuff will be made of
* one pcap file for the CN
* compressed tgz files, one per node, gathering logs and configs and datas
* for convenience the tgz files are unwrapped in run_name/id0
"""
# the local dir to store incoming raw files. mostly tar files
local_path = Path(f"{run_name}")
if not local_path.exists():
print(f"Creating directory {local_path}")
local_path.mkdir()
gwuser, gwhost = r2lab_parse_slice(slicename)
gwnode = SshNode(hostname=gwhost, username=gwuser,
formatter=TimeColonFormatter(verbose=verbose),
debug=verbose)
functions = ["cn", "ran"]
hostnames = [r2lab_hostname(x) for x in (cn, ran)]
node_cn, node_ran = nodes = [
SshNode(gateway=gwnode, hostname=hostname, username='root',
formatter=TimeColonFormatter(verbose=verbose), debug=verbose)
for hostname in hostnames
]
if oai_ues:
hostnames_ue = [r2lab_hostname(x) for x in oai_ues]
nodes_ue = [
SshNode(gateway=gwnode, hostname=hostname, username='root',
formatter=TimeColonFormatter(verbose=verbose), debug=verbose)
for hostname in hostnames_ue]
# all nodes involved are managed in the same way
# node: a SshNode instance
# id: the fit number
# function, a string like 'cn' or 'ran' or 'oai-ue'
local_nodedirs_tars = []
scheduler = Scheduler(verbose=verbose)
for (node, id, function) in zip(
chain(nodes, nodes_ue),
chain( [cn, ran], oai_ues),
chain(functions, cycle(["oai-ue"]))):
# nodes on 2 digits
id0 = f"{id:02d}"
# node-dep collect dir
node_dir = local_path / id0
node_dir.exists() or node_dir.mkdir()
local_tar = f"{local_path}/{function}-{id0}.tgz"
SshJob(
node=node,
commands=[
# first run a 'capture-all' function remotely
# to gather all the relevant files and commands remotely
RunScript(
find_local_embedded_script(f"mosaic-{function}.sh"),
f"capture-all", f"{run_name}-{function}",
includes=INCLUDES),
# and retrieve it locally
Pull(
remotepaths=f"{run_name}-{function}.tgz",
localpath=local_tar),
],
scheduler=scheduler)
local_nodedirs_tars.append((node_dir, local_tar))
# retrieve tcpdump on CN
SshJob(
node=node_cn,
commands=[
tcpdump_cn_service.stop_command(),
Pull(remotepaths=[tcpdump_cn_pcap],
localpath=local_path),
],
scheduler=scheduler
)
print(10*'*', 'See collect scheduler in',
scheduler.export_as_pngfile("cefore-collect"))
if verbose:
scheduler.list()
if dry_run:
return
if not scheduler.run():
print("KO")
scheduler.debrief()
return
# unwrap
for node_dir, tar in local_nodedirs_tars:
print(f"Untaring {tar} in {node_dir}/")
os.system(f"tar -C {node_dir} -xzf {tar}")
# raw formatting (for -x mostly) + show defaults
class RawAndDefaultsFormatter(ArgumentDefaultsHelpFormatter,
RawTextHelpFormatter):
pass
def main(): # pylint: disable=r0914, r0915
hardware_map = hardwired_hardware_map()
def_slicename = "inria_cefore@faraday.inria.fr"
# WARNING: the core network box needs its data interface !
# so boxes with a USRP N210 are not suitable for that job
def_cn, def_ran = 7, 23
def_ns3 = 32
# def_image_cn = "mosaic-cn"
def_image_cn = "cefore-cn"
# def_image_ran = "mosaic-ran"
def_image_ran = "/var/lib/rhubarbe-images/mosaic-ran-2019-02-25.ndz"
def_image_gnuradio = "gnuradio"
def_image_T_tracer = "oai-trace"
# def_image_oai_ue = "mosaic-ue"
def_image_oai_ue = "cefore-ue"
def_image_e3372_ue = "e3372-ue"
def_image_ns3 = "cefore-dce-ns3.26-1.9-cefore-demo"
parser = ArgumentParser(formatter_class=RawAndDefaultsFormatter)
parser.add_argument(
"-s", "--slice", dest='slicename', default=def_slicename,
help="slice to use for entering")
parser.add_argument(
"--cn", default=def_cn,
help="id of the node that runs the core network")
parser.add_argument(
"--ran", default=def_ran,
help="""id of the node that runs the eNodeB,
requires a USRP b210 and 'duplexer for eNodeB""")
parser.add_argument(
"--ns3", default=def_ns3,
help="""id of the node that runs ns-3""")
parser.add_argument(
"-p", "--phones", dest='phones',
action=ListOfChoicesNullReset, type=int, choices=(1, 2, 0),
default=[],
help='Commercial phones to use; use -p 0 to choose no phone')
e3372_nodes = hardware_map['E3372-UE']
parser.add_argument(
"-E", "--e3372", dest='e3372_ues', default=[],
action=ListOfChoices, type=int, choices=e3372_nodes,
help=f"""id(s) of nodes to be used as a E3372-based UE
choose among {e3372_nodes}""")
parser.add_argument(
"-e", "--e3372-xterm", dest='e3372_ue_xterms', default=[],
action=ListOfChoices, type=int, choices=e3372_nodes,
help="""likewise, with an xterm on top""")
oaiue_nodes = hardware_map['OAI-UE']
parser.add_argument(
"-U", "--oai-ue", dest='oai_ues', default=[6],
action=ListOfChoices, type=int, choices=oaiue_nodes,
help=f"""id(s) of nodes to be used as a OAI-based UE
choose among {oaiue_nodes} - note that these notes are also
suitable for scrambling the 2.54 GHz uplink""")
parser.add_argument(
"-G", "--gnuradio", dest='gnuradios', default=[], action='append',
help="""id(s) of nodes intended to run gnuradio;
prefer using fit10 and fit11 (B210 without duplexer)""")
parser.add_argument(
"-g", "--gnuradio-xterm", dest='gnuradio_xterms', default=[], action='append',
help="""likewise, with an xterm on top""")
parser.add_argument(
"-l", "--load", dest='load_nodes', action='store_true', default=False,
help='load images as well')
parser.add_argument(
"-r", "--reset", dest="reset_usb",
default=True, action='store_false',
help="""Reset the USB board if set (always done with --load)""")
parser.add_argument(
"-o", "--oscillo", dest='oscillo',
action='store_true', default=False,
help='run eNB with oscillo function; no oscillo by default')
parser.add_argument(
"-t", "--tcp-streaming", dest='tcp_streaming',
action='store_true', default=False,
help='run Cefore scenario with TCP streaming option; no tcp-streaming by default')
parser.add_argument(
"-T", "--T_tracer", dest='T_tracer', default=[], action='append',
help="id of the node to run the GUI eNB tracer")
parser.add_argument(
"--image-cn", default=def_image_cn,
help="image to load in hss and epc nodes")
parser.add_argument(
"--image-ns3", default=def_image_ns3,
help="image to load for the ns-3 node")
parser.add_argument(
"--image-ran", default=def_image_ran,
help="image to load in ran node")
parser.add_argument(
"--image-e3372-ue", default=def_image_e3372_ue,
help="image to load in e3372 UE nodes")
parser.add_argument(
"--image-oai-ue", default=def_image_oai_ue,
help="image to load in OAI UE nodes")
parser.add_argument(
"--image-gnuradio", default=def_image_gnuradio,
help="image to load in gnuradio nodes")
parser.add_argument(
"--image-T-tracer", default=def_image_T_tracer,
help="image to load on the eNB tracer node")
parser.add_argument(
"-P", "--publisher-ip", default="",
help="IP address of the publisher for the Cefore scenario")
parser.add_argument(
"-N", "--n-rb", dest='n_rb',
default=25,
type=int,
choices=[25, 50],
help="specify the Number of Resource Blocks (NRB) for the downlink")
parser.add_argument(
"-m", "--map", default=False, action='store_true',
help="""Probe the testbed to get an updated hardware map
that shows the nodes that currently embed the
capabilities to run as either E3372- and
OpenAirInterface-based UE. Does nothing else.""")
parser.add_argument(
"-i", "--nodes-left-alone", dest='nodes_left_alone',
default=[4,15], action=ListOfChoices, type=int,
help="ignore (do not switch off) those nodes")
parser.add_argument(
"-v", "--verbose", action='store_true', default=False)
parser.add_argument(
"-n", "--dry-run", action='store_true', default=False)
args = parser.parse_args()
if not args.publisher_ip:
parser.error('Publisher IP address not given, use -P a.b.c.d option')
if args.map:
show_hardware_map(probe_hardware_map())
exit(0)
# map is not a recognized parameter in run()
delattr(args, 'map')
# we pass to run exactly the set of arguments known to parser
# build a dictionary with all the values in the args
kwds = args.__dict__.copy()
# actually run it
now = time.strftime("%H:%M:%S")
print(f"Experiment STARTING at {now}")
if not run(**kwds):
print("exiting")
return
if args.dry_run:
run_name = '<your-run-name>'
else:
run_name = None
print(f"Experiment READY at {now}")
# then prompt for when we're ready to collect
while True:
try:
run_name = input("type capture name when ready : ")
if not run_name:
raise KeyboardInterrupt
elif Path(run_name).exists():
print(f"{run_name} already exists - pick another one")
else:
break
except KeyboardInterrupt:
print("OK, skipped collection, bye")
return
if run_name:
collect(run_name, args.slicename,
args.cn, args.ran, args.oai_ues, args.verbose, args.dry_run)
main()