-
Notifications
You must be signed in to change notification settings - Fork 0
/
fl
executable file
·2015 lines (1757 loc) · 43.9 KB
/
fl
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
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#############################################################################
#
# CONFIG FUNCTIONS
#
#
SOURCE_DIR=$(dirname "$BASH_SOURCE[0]")
# config_files emits names of the config files
config_files() {
local exclude_regex="$1"
# end of params
for f in $SOURCE_DIR/config/fl_*; do
[[ $exclude_regex && $f =~ $exclude_regex ]] || echo "$f"
done
}
# source includes
if [ -d "$SOURCE_DIR/config" ]; then
for f in $(config_files); do
. "$f"
done
fi
#############################################################################
#
# GLOBALS
#
#
# fl.sh ssh destinations
FL_SSH=($MGMT_SSH $SCE_CLI_SSH $L4S_CLI_SSH)
# clients
CLIENTS_SSH=($SCE_CLI_SSH $L4S_CLI_SSH)
# push config
PUSH_RSYNC_DEST="$PUSH_SSH_DEST:$ARCHIVE_DIR"
#############################################################################
#
# PLOT FUNCTIONS
#
#
# plot_tattr emits a title attribute
plot_tattr() {
local key="$1"
local tattrs=($2)
# end of params
for a in "${tattrs[@]}"; do
IFS=":" read k v <<< "$a"
if [ "$key" == "$k" ]; then
echo "$v"
return 0
fi
done
}
# plot_rtt_scale emits the plot's RTT scale from the base RTT
plot_rtt_scale() {
case $1 in
20ms) echo "20,70" ;;
10ms) echo "10,60" ;;
80ms) echo "80,150" ;;
160ms) echo "160,260" ;;
500ms) echo "500,1000" ;;
*) echo "0,200" ;;
esac
}
# plot_bandwidth_scale emits the plot's bandwidth scale from the bandwidth
plot_bandwidth_scale() {
case $1 in
1Mbit) echo "0,1.2" ;;
5Mbit) echo "0,6" ;;
10Mbit) echo "0,12" ;;
25Mbit) echo "0,30" ;;
50Mbit) echo "0,55" ;;
250Mbit) echo "0,260" ;;
*) echo "0,1000" ;;
esac
}
# plot_cc_algo_title emits the title of a CC algo from its key string
plot_cc_algo_title() {
case $1 in
cubic) echo "CUBIC" ;;
cubic-sce) echo "CUBIC-SCE" ;;
reno) echo "Reno" ;;
reno-sce) echo "Reno-SCE" ;;
dctcp) echo "DCTCP" ;;
dctcp-sce) echo "DCTCP-SCE" ;;
prague) echo "Prague" ;;
bbr) echo "BBR" ;;
*) echo "UnknownCC" ;;
esac
}
plot_vs_title() {
case $1 in
cubic-vs-cubic-sce) echo "CUBIC vs CUBIC-SCE" ;;
cubic-vs-prague) echo "CUBIC vs Prague" ;;
bbr-vs-cubic-sce) echo "BBR vs CUBIC-SCE" ;;
bbr-vs-prague) echo "BBR vs Prague" ;;
*) echo "UnknownVS" ;;
esac
}
# plot_arch_title emits the title of the architecture from its key string
plot_arch_title() {
case $1 in
sce) echo "SCE" ;;
l4s) echo "L4S" ;;
*) echo "UnknownArch" ;;
esac
}
# plot_qdisc_title emits the qdisc title from its key string
plot_qdisc_title() {
case $1 in
*cake*) echo "Cake FQ" ;;
*cnq_codel_af*) echo "CNQ-CodelAF" ;;
*twin_codel_af*) echo "Twin-CodelAF" ;;
*lfq_cobalt*) echo "LFQ-COBALT" ;;
*dualpi2*) echo "DualPI2" ;;
*pie*) echo "PIE" ;;
*) echo "$1" ;;
esac
}
# plot_file generates one plot
plot_file() {
local arch="$1"
local in="$2"
local plot="$3"
local visitor=$4
# end of params
# jq_test_param emits a test parameter value from a .flent.gz file
jq_test_param() {
gzip -dc $in | jq -r ".metadata.TEST_PARAMETERS.$1"
}
# jq_title emits the metadata title from a .flent.gz file
jq_title() {
gzip -dc $in | jq -r ".metadata.TITLE"
}
# jq_batch_name emits the metadata batch name from a .flent.gz file
jq_batch_name() {
gzip -dc $in | jq -r ".metadata.BATCH_NAME"
}
# jq_scale_rtt emits the max RTT Y value calculated from the data values
jq_scale_rtt() {
gzip -dc "$in" | \
jq "(.results.\"Ping (ms) ICMP\"+.results.\"TCP upload::tcp_rtt\"|max-$rttval)*3+$rttval"
}
# read params from flent file
local cc_algo=$(jq_test_param cc_algo)
local cc_algos=$(jq_test_param cc_algos)
local subtitle=$(jq_title)
local batch_name=$(jq_batch_name)
local rtt=$(plot_tattr rtt "$subtitle")
local rttval=${rtt//[!0-9]/}
local bandwidth=$(plot_tattr bandwidth "$subtitle")
local vs=$(plot_tattr vs "$subtitle")
local qdisc=$(plot_tattr qdisc "$subtitle")
# output path
local outdir=$(dirname "$in")
local outfile=$(basename "$in")
outfile="${outfile#"batch-"}"
outfile="${outfile%".flent.gz"}"
outfile+="_$plot"
local outpath="$outdir/$outfile.$PLOT_FORMAT"
# further calculated params
local rtt_scale=$(plot_rtt_scale $rtt)
local bandwidth_scale=$(plot_bandwidth_scale $bandwidth)
local cc_title=$(plot_cc_algo_title $cc_algo)
local arch_title=$(plot_arch_title $arch)
local vs_title=$(plot_vs_title $vs)
local colors
[[ $COLORS ]] && colors="--colours $COLORS"
# visitor assigned params
local title
local subtitle2
# other locals
local tput_name
local tput_abbrev
local tput_title
if [[ $plot =~ delivery ]]; then
tput_name="delivery rate"
tput_abbrev="delivery"
tput_title="Delivery Rate"
else
tput_name="throughput"
tput_abbrev="thruput"
tput_title="Throughput"
fi
# start empty array for arguments
local fl_args=()
# visitor assigns title and additional arguments
$visitor
# common args
fl_args+=( "-i" "$in" )
fl_args+=( "-p" "$plot" )
fl_args+=( "-o" "$outpath" )
fl_args+=( "--figure-width" "$PLOT_WIDTH" )
fl_args+=( "--figure-height" "$PLOT_HEIGHT" )
[[ $colors ]] && fl_args+=("--colours" "$colors" )
fl_args+=( "--fallback-layout" )
# plot-specific args
case $plot in
tcp_delivery_with_rtt)
fl_args+=( "--bounds-y" "$bandwidth_scale" )
fl_args+=( "--bounds-y" "$rtt_scale" )
fl_args+=( "--label-y" "Mbps" )
fl_args+=( "--label-y" "ms" )
;;
esac
local final_title=$(printf "%s\n\n%s" "$title" "$subtitle")
if [[ $subtitle2 ]]; then
final_title=$(printf "%s\n%s" "$final_title" "$subtitle2")
fi
fl_args+=( "--override-title" "$final_title" )
flent "${fl_args[@]}"
}
# s1_visitor is the plot visitor for scenario 1
s1_visitor() {
title="$arch_title: Single Flow $cc_title"
fl_args+=( "--override-label" "$cc_algo $tput_name" )
fl_args+=( "--override-label" "ICMP RTT" )
fl_args+=( "--override-label" "TCP RTT" )
}
# s2_visitor is the plot visitor for scenario 2
s2_visitor() {
local IFS=,
local cca
if [[ $qdisc =~ (^pfifo|pie\(noecn\)) ]]; then
rtt_scale="$rttval,$(jq_scale_rtt)"
fi
fl_args+=( "--override-label" "" )
fl_args+=( "--override-label" "" )
for cca in $cc_algos; do
fl_args+=( "--override-label" "$(plot_cc_algo_title $cca) $tput_name" )
done
fl_args+=( "--override-label" "ICMP RTT" )
fl_args+=( "--override-label" "" )
fl_args+=( "--override-label" "" )
for cca in $cc_algos; do
fl_args+=( "--override-label" "$(plot_cc_algo_title $cca) TCP RTT" )
done
title="$arch_title: $(plot_qdisc_title $qdisc), $vs_title"
}
# s3_visitor is the plot visitor for scenario 3
s3_visitor() {
title="$arch_title: Bottleneck Shift for $cc_title"
fl_args+=( "--override-label" "$cc_algo $tput_name" )
fl_args+=( "--override-label" "ICMP RTT" )
fl_args+=( "--override-label" "TCP RTT" )
}
# s4_visitor is the plot visitor for scenario 4
s4_visitor() {
title="$arch_title: Capacity Reduction for $cc_title"
fl_args+=( "--override-label" "$cc_algo $tput_name" )
fl_args+=( "--override-label" "ICMP RTT" )
fl_args+=( "--override-label" "TCP RTT" )
}
# s5_visitor is the plot visitor for scenario 5
s5_visitor() {
title="$arch_title: WiFi Burstiness with $cc_title"
fl_args+=( "--override-label" "$cc_algo $tput_name" )
fl_args+=( "--override-label" "ICMP RTT" )
fl_args+=( "--override-label" "TCP RTT" )
}
# s6_visitor is the plot visitor for scenario 6
s6_visitor() {
title="$arch_title: Jitter with $cc_title"
fl_args+=( "--override-label" "$cc_algo $tput_name" )
fl_args+=( "--override-label" "ICMP RTT" )
fl_args+=( "--override-label" "TCP RTT" )
}
#s2_visitor_bar_combine() {
# local IFS=,
#
# for cca in $cc_algos; do
# fl_args+=( "--override-label" "$(plot_cc_algo_title $cca)" )
# done
#
# fl_args+=( "--label-y" "Mbps" )
# fl_args+=( "--no-labels" )
#
# title+="$cc_mix_title"
# title+=" Competition w/$(plot_queue_title $queue),"
# case $rtt in
# 20ms) title+=" 60 Second Mean" ;;
# 160ms) title+=" 120 Second Mean" ;;
# esac
# title+=" $tput_title"
#}
#
#s2_visitor_tcp_delivery_with_rtt() {
# local IFS=,
# local cca
#
# fl_args+=( "--override-label" "" )
# fl_args+=( "--override-label" "" )
#
# for cca in $cc_algos; do
# fl_args+=( "--override-label" "$(plot_cc_algo_title $cca) $tput_name" )
# done
#
# fl_args+=( "--override-label" "ICMP RTT" )
#
# fl_args+=( "--override-label" "" )
# fl_args+=( "--override-label" "" )
#
# for cca in $cc_algos; do
# fl_args+=( "--override-label" "$(plot_cc_algo_title $cca) TCP RTT" )
# done
#
# title+="$cc_mix_title"
# title+=" Competition w/$(plot_queue_title $queue),"
# title+=" $tput_title"
#}
#
#remote_plot $DIR/s2-fiveflow \
# bar_combine s2_visitor_bar_combine \
# tcp_delivery_with_rtt s2_visitor_tcp_delivery_with_rtt
#############################################################################
#
# UTILITY FUNCTIONS
#
#
# fl_ssh runs fl remotely via ssh
fl_ssh() {
local dest=$1; shift # ssh destination
local root=$1; shift # true|false
local background=$1; shift # true|false
local args="$@"
# end of params
local sudo_args
[[ $root == true ]] && sudo_args='$([[ $EUID != 0 ]] && echo sudo)'
local args_esc
args_esc=$(printf %q "$args")
# run directly on hosts with fl script, or via stdout on hosts without
if array_contains $dest "${FL_SSH[@]}"; then
if [[ $background == true ]]; then
ssh $dest cd $SCRIPT_DIR\; nohup $sudo_args ./fl $args_esc \&\>log.txt \&
else
ssh $dest cd $SCRIPT_DIR\; $sudo_args ./fl $args_esc 2>&1 | \
sed "s/^/$dest: /"
return ${PIPESTATUS[0]}
fi
else
if [[ $background == true ]]; then
cat $(config_files "local") fl | \
ssh $dest $sudo_args nohup bash -s $args_esc \&\> \
\$\(mktemp /tmp/fl.log.XXXXXXXX\) \&
else
cat $(config_files "local") fl | \
ssh $dest $sudo_args bash -s $args_esc || return $?
fi
fi
}
# fl_node runs fl either via netns or remotely via ssh
fl_node() {
local arch=$1; shift
local net=$1; shift
local node=$1; shift
local args="$@"
# end of params
case $net in
phys)
fl_ssh $(node_ssh $arch $node) true false $args || return $?
;;
ns)
nsx $node ./fl $args || return $?
;;
*)
>&2 echo "unknown net: $net"
return 1
esac
}
# fl_node_pull copies files from a node's directory to a local directory
fl_node_pull() {
local arch=$1
local net=$2
local node=$3
local src_dir="$4"
local dst_dir="$5"
# end of params
case $net in
phys)
ev scp \"$(node_ssh $arch $node):$src_dir/*\" "$dst_dir" || return $?
;;
ns)
ev cp "$src_dir/*" "$dst_dir" || return $?
;;
*)
>&2 echo "unknown net: $net"
return 1
esac
}
# send_pushover sends a pushover message
send_pushover() {
local sound="$1"
local msg="$2"
# end of params
if [[ $PUSHOVER_USER ]]; then
response=$(/usr/bin/curl -s \
--retry 3 \
--form-string token=$PUSHOVER_TOKEN \
--form-string user=$PUSHOVER_USER \
--form-string "sound=$sound" \
--form-string "message=$msg" \
https://api.pushover.net/1/messages.json)
[[ ! "$response" == *"\"status\":1"* ]] && echo "$response" >&2
fi
}
# set_offloads enables or disables offloads for an eth iface
set_offloads() {
local iface="$1"
local state="$2" # on|off
local ns="$3"
# end of params
local cmd
cmd="sudo"
[[ $ns ]] && cmd+=" ip netns exec $ns"
cmd+=" ethtool -K $iface"
cmd+=" rx $state tx $state"
cmd+=" sg $state tso $state"
cmd+=" gso $state gro $state"
cmd+=" rxvlan $state txvlan $state"
$cmd
}
# wait_for_pids waits for processes to exit and returns a count of failures
wait_for_pids() {
local pids=("$@")
# end of params
local errs=0
local p
for p in ${pids[@]}; do
wait $p || ((errs++))
done
return $errs
}
# array_contains succeeds if an array contains an element
array_contains() {
local elem="$1"; shift
local arr=("$@")
# end of params
local e
for e in "${arr[@]}"; do
[[ $e == $elem ]] && return 0
done
return 1
}
# ifb emits the ifb interface name for an interface
ifb() {
local iface=$1
echo "ifb4$iface"
}
# ev emits and evaluates a command
ev() {
local r=0
echo "+ $@"
eval "$@"
r=$?
if [[ $DEBUG == 1 && $r != 0 ]]; then
>&2 echo "command failed with status $r: $@"
fi
echo
return $r
}
# evs runs eval separately for each command separated by ;
evs() {
IFS=';' read -r -a cmds <<< "$@"
local c
local r
for c in "${cmds[@]}"; do
# remove leading and trailing whitespace
c=$(echo $c | awk '{$1=$1};1')
eval $c
r=$?
if (( r != 0 )); then
>&2 echo "command failed with status $r: $c"
return $r
fi
done
}
# ev evaluates a command and only emits it if DEBUG is 1
evq() {
local r
[[ $DEBUG == 1 ]] && echo "+ $@"
eval "$@" &>/dev/null
r=$?
if [[ $DEBUG == 1 && $r != 0 ]]; then
>&2 echo "command failed with status $r: $@"
fi
return $r
}
# split splits a string by comma
split() {
local s=(${1//,/ })
echo "${s[@]}"
}
#############################################################################
#
# NAMESPACES FUNCTIONS
#
#
# nsx executes a command in a namespace
nsx() {
local ns="$1"; shift
local args="$@"
# end of fixed args
# client is run in default namespace
if [[ $ns == cli ]]; then
$args
else
sudo ip netns exec $ns $args
fi
}
# ns_setup sets up the netns environment
ns_setup() {
local arch=$1
# end of params
# srv
sudo ip netns add srv || return $?
sudo ip link add dev $NS_SRV_LEFT type veth peer name $NS_MID_RIGHT || return $?
sudo ip link set dev $NS_SRV_LEFT netns srv || return $?
nsx srv ip addr add $NS_SRV_IP dev $NS_SRV_LEFT || return $?
nsx srv ip link set $NS_SRV_LEFT up || return $?
if [[ $NS_OFFLOADS == off ]]; then
set_offloads $NS_SRV_LEFT off srv || return $?
fi
if [[ $arch == "sce" ]]; then
nsx srv sysctl -qw net.ipv4.tcp_sce=1 || return $?
nsx srv sysctl -qw net.ipv4.tcp_ecn=1 || return $?
elif [[ $arch == "l4s" ]]; then
nsx srv sysctl -qw net.ipv4.tcp_ecn=3 || return $?
fi
# mid
sudo ip netns add mid || return $?
sudo ip link set dev $NS_MID_RIGHT netns mid || return $?
if [[ $NS_OFFLOADS == off ]]; then
set_offloads $NS_MID_RIGHT off mid || return $?
fi
nsx mid ip link set $NS_MID_RIGHT up || return $?
sudo ip link add dev $NS_MID_LEFT type veth peer name $NS_CLI_RIGHT || return $?
sudo ip link set dev $NS_MID_LEFT netns mid || return $?
if [[ $NS_OFFLOADS == off ]]; then
set_offloads $NS_MID_LEFT off mid || return $?
fi
nsx mid ip link set $NS_MID_LEFT up || return $?
nsx mid ip link add name mid.b type bridge || return $?
nsx mid ip link set dev $NS_MID_RIGHT master mid.b || return $?
nsx mid ip link set dev $NS_MID_LEFT master mid.b || return $?
nsx mid ip link set dev mid.b up || return $?
# cli uses default namespace
sudo ip addr add $NS_CLI_IP dev $NS_CLI_RIGHT || return $?
sudo ip link set $NS_CLI_RIGHT up || return $?
if [[ $NS_OFFLOADS == off ]]; then
set_offloads $NS_CLI_RIGHT off || return $?
fi
if [[ $arch == "sce" ]]; then
sudo sysctl -qw net.ipv4.tcp_sce=1 || return $? >/dev/null
sudo sysctl -qw net.ipv4.tcp_ecn=1 || return $? >/dev/null
elif [[ $arch == "l4s" ]]; then
sudo sysctl -qw net.ipv4.tcp_ecn=3 || return $? >/dev/null
fi
# start netserver (with -d for debug so it doesn't change perms on /dev/null)
if ! command -v netserver >&/dev/null; then
>&2 echo "netserver not found"
return 1
fi
nsx srv netserver -d >&/dev/null
# start irtt
if ! command -v irtt >&/dev/null; then
>&2 echo "irtt not found"
return 1
fi
nsx srv irtt server -i 0 --syslog=local: >&/dev/null &
}
# ns_teardown tears down the netns environment
ns_teardown() {
# stop services
sudo pkill irtt || true
sudo pkill netserver || true
# delete namespaces
sudo ip netns del srv || true
sudo ip netns del mid || true
}
#############################################################################
#
# REMOTE FUNCTIONS
#
#
# remote_run_flent runs flent
remote_run_flent() {
local arch="$1"
local batch_title="$2"
local pattern="$3"
local dry="$4"
# end of params
local fl_args=""
local bcount=0
# cleans up after flent run
run_flent_cleanup() {
ns_teardown || true
local u=$(whoami)
local g=$(groups | cut -f1 -d " ")
for d in $(find . -mindepth 1 -maxdepth 1 -type d); do
sudo chown -R $u:$g "$d" || true
done
}
# build flent args
for b in $(sed -rn 's/^\[Batch::(.*)\]$/\1/p' < $BATCH_FILE); do
if [[ $b =~ ^$arch ]]; then
if [[ $pattern =~ "all" ]] || [[ $b =~ $pattern ]]; then
fl_args+=" -b $b"
((bcount++))
fi
fi
done
[[ $dry == true ]] && fl_args+=" --batch-dry-run"
# run flent if any batches matched
if (( bcount > 0 )); then
trap run_flent_cleanup EXIT
ns_setup $arch || return $?
sudo flent \
--batch-no-timestamp \
--batch-title $batch_title \
-B $BATCH_FILE \
$fl_args \
--batch-no-shuffle || return $?
else
echo "No matching tests to perform."
fi
}
# remote_clear_setup is called to clear the setup on a node
remote_clear_setup() {
for d in $(tc qdisc | awk '$3!="0:" && !x[$5]++ {print $5}'); do
evq tc qdisc del dev $d root || true
[[ $d != ifb* ]] && evq tc qdisc del dev $d ingress || true
done
for l in `ip link show | sed -rn 's/.* (ifb\S+):.*/\1/p'`; do
evq tc qdisc del dev $l root || true
evq ip link del dev $l || true
done
evq iptables -t mangle -F POSTROUTING || true
evq ip tcp_metrics flush || true
}
# remote_setup_command is called to set up or tear down a node
remote_setup_command() {
local command=$1; shift # setup or teardown
local arch=$1; shift
local net=$1; shift
local node=$1; shift
local cmd="$@"
local r
on_fail() {
eval "PHASE=teardown; $cmd"
}
case $command in
setup)
rm -fr "$(data_dir $node)" || return $?
mkdir -p "$(data_dir $node)" || return $?
evs "PHASE=init; $cmd" || { r=$?; on_fail; return $r; }
evs "PHASE=setup; $cmd" || { r=$?; on_fail; return $r; }
evs "PHASE=show_setup; $cmd; kernel_info" || { r=$?; on_fail; return $r; }
;;
teardown)
evs "PHASE=show_teardown; $cmd" || { r=$?; on_fail; return $r; }
evs "PHASE=teardown; $cmd" || { r=$?; on_fail; return $r; }
;;
*)
>&2 echo "command $command not implemented"
on_fail
return 1
;;
esac
}
# remote_plot plots all files in all directories in parallel
remote_plot() {
local arch="$1"
local spec="$2"
plot_dir() {
local pdir="$1"
local plot="$2"
local visitor="$3"
if [[ -d $pdir ]]; then
echo "Plotting directory $pdir."
rm -f $pdir/*.png $pdir/*.svg
local pids=()
local f
for f in $pdir/*.flent.gz; do
if [[ -f $f ]]; then
plot_file $arch "$f" $plot $visitor &
pids+=($!)
fi
done
wait_for_pids ${pids[@]} || return $?
else
echo "Skipping plot for non-existent directory $pdir."
fi
}
local dir
for dir in "${spec[@]}"; do
if [[ -d $dir ]]; then
plot_dir $dir/$arch-s1-oneflow \
tcp_delivery_with_rtt s1_visitor || return $?
plot_dir $dir/$arch-s2-twoflow \
tcp_delivery_with_rtt s2_visitor || return $?
plot_dir $dir/$arch-s3-bottleneck-shift \
tcp_delivery_with_rtt s3_visitor || return $?
plot_dir $dir/$arch-s4-capacity-reduction \
tcp_delivery_with_rtt s4_visitor || return $?
plot_dir $dir/$arch-s5-burstiness \
tcp_delivery_with_rtt s5_visitor || return $?
plot_dir $dir/$arch-s6-jitter \
tcp_delivery_with_rtt s6_visitor || return $?
fi
done
}
# remote_push_result pushes results to the archive
remote_push_result() {
local spec="$1"
# end of params
[[ $spec ]] || spec="$BATCH-*"
echo "Pushing $spec to $PUSH_RSYNC_DEST"
rsync -rt --ignore-missing-args \
"$PUSH_RSYNC_ARGS" \
$spec \
"$PUSH_RSYNC_DEST"
}
# remote_clean removes result directories
remote_clean() {
rm -fr $BATCH_OUT_SPEC
}
# remote_list lists result directories
remote_list() {
local dir
for dir in $BATCH-*; do
[[ -d $dir ]] && echo $dir
done
}
# remote_hello emits message for testing
remote_hello() {
echo Hello from fl on $(hostname)!
}
#############################################################################
#
# FLENT HARNESS ENTRY POINT FUNCTIONS
#
#
# flent_clear is the flent hook for clearing the setup
flent_clear() {
local arch=$1
local net=$2
# end of params
# clear all ssh dests for phys, or all namespaces for netns
local pids=()
case $net in
phys)
local d
for d in "${CLEAR_SSH_DESTS[@]}"; do
fl_ssh $d true false remote_clear_setup &
pids+=($!)
done
;;
ns)
local n
for n in "${CLEAR_NODES[@]}"; do
fl_node $arch $net $n remote_clear_setup &
pids+=($!)
done
;;
*)
echo "unknown net: $net"
return -1
esac
wait_for_pids ${pids[@]}
}
# flent_setup is the flent hook for node setup
flent_setup() {
flent_setup_teardown setup "$@"
}
# flent_teardown is the flent hook for node teardown
flent_teardown() {
flent_setup_teardown teardown "$@"
}
# flent_setup_teardown implements the flent setup and teardown hooks
flent_setup_teardown() {
local command=$1; shift # setup|teardown
local arch=$1; shift
local net=$1; shift
local data_filename="$1"; shift
local end=$(( $# / 2 ))
# end of params
# log_file returns the log file name for a node
log_file() {
echo "$(log_dir $1)/$1.log"
}
# execute commands for each node in parallel
local nodes=()
local pids=()
local i
local n
local c
for (( i = 0; i < $end; i++ )); do
n=$1; shift
c="$1"; shift
rm -fr "$(log_dir $n)" || return $?
mkdir -p "$(log_dir $n)" || return $?
(
local r
fl_node $arch $net $n \
remote_setup_command $command $arch $net $n $(printf %q "$c") &> $(log_file $n)
r=$?
if (( r != 0 )); then
>&2 echo "remote_setup_command failed, arch:$arch, node:$n, status:$r"
>&2 echo "failed command: \"$command\""
fi
exit $r
) &
nodes+=($n)
pids+=($!)
done
# wait for setup pids
local errs
wait_for_pids ${pids[@]}
errs=$?
# concatenate output from each node into one file for the command
(
for n in ${nodes[@]}; do
echo $n
echo "${n//?/-}"
echo
cat $(log_file $n)
echo
rm $(log_file $n)
rmdir "$(log_dir $n)"
done
) 2>&1 | tee "${data_filename}.$command.log"
return $errs
}
# flent_process is the flent hook for processing results
flent_process() {
local arch=$1; shift
local net=$1; shift
local fname="$1"; shift # data filename
local end=$(( $# / 2 ))
# end of params
# data filename base without extension
local fbase
fbase=$(basename $fname)
fbase="${fbase%.*}"
(
# pull output data files from node
local cmds=()
local n
local i
for (( i = 0; i < $end; i++ )); do
n=$1; shift
cmds+=("$1"); shift
fl_node_pull $arch $net $n $(data_dir $n) $(dirname $fname) || true
done
# prepend standard prefix to output files without it
local f
local b
for f in $(dirname $fname)/*; do
b=$(basename $f)
if [[ $b != batch-* ]]; then
mv "$f" "$(dirname $fname)/$fbase.$b" || exit 1
fi
done
# run process hooks serially in case hooks depend on one another
local c
for c in "${cmds[@]}"; do
eval "PHASE=process; $c" || exit 1
done