forked from servalproject/serval-dna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routing
executable file
·973 lines (923 loc) · 31.1 KB
/
routing
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
#!/bin/bash
# Tests for Route discovery
#
# Copyright 2012 Serval Project, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
source "${0%/*}/../testframework.sh"
source "${0%/*}/../testdefs.sh"
interface_up() {
$GREP "Interface .* is up" $instance_servald_log || return 1
return 0
}
link_matches() {
local interface_ex=".*"
local link_type="\(BROADCAST\|UNICAST\)"
local via="0*"
local sid=""
while [ $# -ne 0 ]; do
case "$1" in
--interface) interface_ex="$2"; shift 2;;
--broadcast) link_type="BROADCAST"; shift;;
--unicast) link_type="UNICAST"; shift;;
--via) link_type="INDIRECT"; via="$2"; interface_ex=""; shift 2;;
--any) via=".*"; link_type=".*"; shift;;
*) break;;
esac
done
sid="$1"
tfw_log "Looking for link ${sid}, ${link_type}, ${interface_ex}, ${via}"
if ! grep "^${sid}:${link_type}:${interface_ex}:${via}\$" $_tfw_tmp/stdout; then
tfw_log "Link not found"
return 1
fi
}
has_link() {
executeOk_servald route print
link_matches $@
}
has_no_link() {
has_link --any $@ || return 0
return 1
}
path_exists() {
local dest
eval dest=\$$#
local dest_sidvar=SID${dest#+}
local first_inst=$1
local next_inst=$first_inst
shift
local I
for I; do
local sidvar=SID${I#+}
[ -n "${!sidvar}" ] || break
set_instance $next_inst
executeOk_servald route print
link_matches ${!sidvar} || return 1
[ $I = $dest ] && break
link_matches --via ${!sidvar} ${!dest_sidvar} || return 1
next_inst=$I
done
# so we think this path should exist, check that it works
set_instance $first_inst
executeOk_servald mdp trace --timeout=20 "${!dest_sidvar}"
# assertStdoutGrep "^[0-9]+:${!dest_sidvar}\$"
tfw_cat --stdout
return 0
}
configure_servald_server() {
executeOk_servald config \
set debug.mdprequests yes \
set debug.linkstate yes \
set debug.verbose yes \
set debug.overlayrouting yes \
set log.console.level debug \
set log.console.show_pid on \
set log.console.show_time on \
set rhizome.enable no
}
log_routing_table() {
executeOk_servald route print
tfw_cat --stdout --stderr
}
teardown() {
foreach_instance_with_pidfile log_routing_table
stop_all_servald_servers
kill_all_servald_processes
assert_no_servald_processes
report_all_servald_servers
}
doc_single_link="Start 2 instances on one link"
setup_single_link() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +A +B start_servald_server
}
test_single_link() {
wait_until --timeout=10 path_exists +A +B
wait_until --timeout=5 path_exists +B +A
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDA 1
tfw_cat --stdout --stderr
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
}
doc_multiple_ids="Route between multiple identities"
setup_multiple_ids() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_identities 2
SIDA=$SIDA1
SIDB=$SIDB1
foreach_instance +A +B add_servald_interface 1
foreach_instance +A +B start_servald_server
}
test_multiple_ids() {
wait_until path_exists +A +B
set_instance +A
wait_until has_link --via $SIDB1 $SIDB2
wait_until path_exists +B +A
set_instance +B
wait_until has_link --via $SIDA1 $SIDA2
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB2 1
tfw_cat --stdout --stderr
executeOk_servald route print
link_matches $SIDB1
link_matches --via $SIDB1 $SIDB2
set_instance +B
executeOk_servald mdp ping --timeout=3 $SIDA2 1
tfw_cat --stdout --stderr
executeOk_servald route print
link_matches $SIDA1
link_matches --via $SIDA1 $SIDA2
}
doc_unlock_ids="Routes appear and disappear as identities are [un]locked"
setup_unlock_ids() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface 1
set_instance +A
executeOk_servald keyring add 'entry-pin'
extract_stdout_keyvalue SIDX sid "$rexp_sid"
foreach_instance +A +B start_servald_server
}
test_unlock_ids() {
wait_until path_exists +A +B
wait_until path_exists +B +A
set_instance +A
executeOk_servald id enter pin 'entry-pin'
set_instance +B
wait_until has_link --via $SIDA $SIDX
set_instance +A
executeOk_servald id relinquish pin 'entry-pin'
set_instance +B
wait_until --timeout=30 has_no_link $SIDX
}
doc_migrate_id="Unlocking the same identity triggers migration"
setup_migrate_id() {
setup_servald
assert_no_servald_processes
set_instance +A
executeOk_servald keyring add 'entry-pin'
extract_stdout_keyvalue SIDX sid "$rexp_sid"
executeOk_servald keyring dump --entry-pin=entry-pin --secret sidx
tfw_cat sidx
set_instance +B
executeOk_servald keyring load sidx 'entry-pin'
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +A +B start_servald_server
}
test_migrate_id() {
wait_until --timeout=10 path_exists +A +B
wait_until --timeout=10 path_exists +B +A
set_instance +A
executeOk_servald id enter pin 'entry-pin'
set_instance +B
wait_until --timeout=10 has_link --via $SIDA $SIDX
set_instance +B
executeOk_servald id enter pin 'entry-pin'
set_instance +A
wait_until --timeout=10 has_link --via $SIDB $SIDX
}
doc_single_mdp="Use single MDP per packet encapsulation"
setup_single_mdp() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +A +B executeOk_servald config \
set interfaces.1.broadcast.encapsulation single \
set interfaces.1.unicast.encapsulation single
foreach_instance +A +B start_servald_server
}
test_single_mdp() {
wait_until path_exists +A +B
wait_until path_exists +B +A
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
}
doc_mismatched_encap="Mismatched MDP packet encapsulation"
setup_mismatched_encap() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +A executeOk_servald config \
set interfaces.1.broadcast.encapsulation single \
set interfaces.1.unicast.encapsulation single
foreach_instance +A +B start_servald_server
}
test_mismatched_encap() {
wait_until path_exists +A +B
wait_until path_exists +B +A
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
}
doc_single_p2p="Start 2 instances on a point to point link"
setup_single_p2p() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +A +B \
executeOk_servald config \
set interfaces.1.broadcast.encapsulation single \
set interfaces.1.unicast.send off \
set interfaces.1.point_to_point on
foreach_instance +A +B start_servald_server
}
test_single_p2p() {
wait_until path_exists +A +B
wait_until path_exists +B +A
assertGrep "$instance_servald_log" 'Established point to point link'
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
}
start_fakeradio() {
$servald_build_root/fakeradio 4 1 > "$SERVALD_VAR/radioout" 2> "$SERVALD_VAR/radioerr" &
FAKERADIO_PID=$!
wait_until $GREP "^right:" "$SERVALD_VAR/radioout"
local _line=`head "$SERVALD_VAR/radioout" -n 1`
END1="${_line#*:}"
_line=`tail "$SERVALD_VAR/radioout" -n 1`
END2="${_line#*:}"
tfw_log "Started fakeradio pid=$FAKERADIO_PID, end1=$END1, end2=$END2"
}
doc_simulate_extender="Simulate a mesh extender radio link"
setup_simulate_extender() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
start_fakeradio
set_instance +A
executeOk_servald config \
set interfaces.1.file "$END1"
set_instance +B
executeOk_servald config \
set interfaces.1.file "$END2"
foreach_instance +A +B \
executeOk_servald config \
set debug.packetradio on \
set debug.radio_link on \
set interfaces.1.type CATEAR \
set interfaces.1.broadcast.tick_ms 5000 \
set interfaces.1.socket_type STREAM \
set interfaces.1.broadcast.encapsulation SINGLE \
set interfaces.1.point_to_point on
foreach_instance +A +B start_servald_server
}
test_simulate_extender() {
wait_until path_exists +A +B
wait_until path_exists +B +A
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
}
teardown_simulate_extender() {
teardown
tfw_log "Killing fakeradio, pid=$FAKERADIO_PID"
kill $FAKERADIO_PID
tfw_cat "$SERVALD_VAR/radioerr"
}
doc_lowband_broadcast="Link detection over low bandwith links"
setup_lowband_broadcast() {
setup_servald
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +A +B executeOk_servald config \
set interfaces.1.broadcast.packet_interval 2000000 \
set interfaces.1.broadcast.transmit_timeout_ms 6200 \
set interfaces.1.broadcast.tick_ms 15000 \
set interfaces.1.broadcast.mtu 210 \
set interfaces.1.broadcast.route off \
set interfaces.1.unicast.send off
foreach_instance +A +B start_servald_server
}
test_lowband_broadcast() {
set_instance +A
executeOk_servald mdp ping --interval=3 --timeout=6 $SIDB 3
tfw_cat --stdout --stderr
}
_simulator() {
# TODO timeout & failure reporting?
executeOk --error-on-fail $servald_build_root/simulator <$SIM_IN
tfw_cat --stdout --stderr
rm $SIM_IN
}
start_simulator() {
SIM_IN="$PWD/SIM_IN"
mkfifo "$SIM_IN"
exec 8<>"$SIM_IN" # stop fifo from blocking
fork %simulator _simulator
}
simulator_command() {
tfw_log "$@"
assert_fork_is_running %simulator
echo "$@" >>"$SIM_IN"
}
simulator_quit() {
simulator_command quit
fork_wait %simulator
}
doc_multiple_nodes="Multiple nodes on one link"
setup_multiple_nodes() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B +C +D create_single_identity
foreach_instance +A +B +C +D add_servald_interface 1
start_simulator
simulator_command create "net" "$SERVALD_VAR/dummy1/"
# note if we need to force broadcast packets so that the routes stabilise quickly
foreach_instance +A +B +C +D executeOk_servald config \
set interfaces.1.prefer_unicast 0
foreach_instance +A +B +C +D start_servald_server
}
test_multiple_nodes() {
simulator_command set "net" "latency" "100"
simulator_command up "net"
wait_until --timeout=10 path_exists +A +B
wait_until --timeout=5 path_exists +A +C
wait_until --timeout=5 path_exists +A +D
wait_until --timeout=5 path_exists +B +A
wait_until --timeout=5 path_exists +C +A
wait_until --timeout=5 path_exists +D +A
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
simulator_command set "net" "latency" "150"
executeOk_servald mdp ping --timeout=3 $SIDC 1
tfw_cat --stdout --stderr
simulator_command set "net" "latency" "200"
executeOk_servald mdp ping --timeout=3 $SIDD 1
tfw_cat --stdout --stderr
}
finally_multiple_nodes() {
simulator_quit
}
doc_scan="Network scan with isolated clients"
setup_scan() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B +C create_single_identity
foreach_instance +A +B +C add_servald_interface --file 1
foreach_instance +A +B +C \
executeOk_servald config \
set interfaces.1.broadcast.drop on
foreach_instance +A +B +C start_servald_server
foreach_instance +A +B +C \
wait_until interface_up
}
test_scan() {
set_instance +A
executeOk_servald scan
wait_until --timeout=10 scan_completed
wait_until --timeout=10 has_seen_instances +B +C
executeOk_servald route print
link_matches --unicast $SIDB
link_matches --unicast $SIDC
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
set_instance +B
executeOk_servald route print
link_matches --unicast $SIDA
link_matches --via $SIDA $SIDC
executeOk_servald mdp ping --timeout=3 $SIDC 1
tfw_cat --stdout --stderr
}
doc_scan_one="Network scan a single address"
setup_scan_one() {
setup_scan
}
test_scan_one() {
set_instance +A
executeOk_servald scan 127.0.1.2
wait_until scan_completed
wait_until --timeout=10 has_seen_instances +B
executeOk_servald route print
link_matches --unicast $SIDB
assertStdoutGrep --matches=0 "^$SIDC:"
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
}
scan_completed() {
grep "Scan completed" $instance_servald_log || return 1
return 0
}
doc_single_filter="Single device with a broadcast filter"
setup_single_filter() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface --file 1
set_instance +B
executeOk_servald config \
set interfaces.1.broadcast.drop on
set_instance +A
executeOk_servald config \
set interfaces.1.unicast.drop on
foreach_instance +A +B start_servald_server
}
test_single_filter() {
set_instance +A
wait_until --timeout=10 has_link --unicast $SIDB
set_instance +B
wait_until --timeout=5 has_link --broadcast $SIDA
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
}
doc_broadcast_only="Broadcast packets only"
setup_broadcast_only() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface 1
start_simulator
simulator_command create "net" "$SERVALD_VAR/dummy1/"
simulator_command set "net" "drop_unicast" "1"
foreach_instance +A +B start_servald_server
}
test_broadcast_only() {
simulator_command up "net"
set_instance +A
wait_until has_link --broadcast $SIDB
set_instance +B
wait_until has_link --broadcast $SIDA
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
}
finally_broadcast_only() {
simulator_quit
}
doc_prefer_unicast="Prefer unicast packets"
setup_prefer_unicast() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +A +B \
executeOk_servald config \
set interfaces.1.prefer_unicast 1 \
set debug.overlayframes 1
foreach_instance +A +B start_servald_server
}
test_prefer_unicast() {
set_instance +A
wait_until has_link --unicast $SIDB
set_instance +B
wait_until has_link --unicast $SIDA
wait_until path_exists +A +B
wait_until path_exists +B +A
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
}
doc_prefer_broadcast="Prefer broadcast packets"
setup_prefer_broadcast() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +A +B \
executeOk_servald config \
set interfaces.1.prefer_unicast 0 \
set debug.overlayframes 1
foreach_instance +A +B start_servald_server
}
test_prefer_broadcast() {
set_instance +A
wait_until has_link --broadcast $SIDB
set_instance +B
wait_until has_link --broadcast $SIDA
wait_until path_exists +A +B
wait_until path_exists +B +A
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDB 1
tfw_cat --stdout --stderr
}
doc_multihop_linear="Start 4 instances in a linear arrangement"
setup_multihop_linear() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B +C +D create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +B +C add_servald_interface 2
foreach_instance +C +D add_servald_interface 3
foreach_instance +A +B +C +D start_servald_server
}
test_multihop_linear() {
wait_until path_exists +A +B +C +D
wait_until path_exists +D +C +B +A
set_instance +A
executeOk_servald --stdout --stderr mdp ping --timeout=3 $SIDD 1
tfw_cat --stdout --stderr
executeOk_servald mdp trace $SIDD
tfw_cat --stdout --stderr
assertStdoutGrep --matches=1 "^0:$SIDA\$"
assertStdoutGrep --matches=1 "^1:$SIDB\$"
assertStdoutGrep --matches=1 "^2:$SIDC\$"
assertStdoutGrep --matches=1 "^3:$SIDD\$"
assertStdoutGrep --matches=1 "^4:$SIDC\$"
assertStdoutGrep --matches=1 "^5:$SIDB\$"
assertStdoutGrep --matches=1 "^6:$SIDA\$"
}
doc_unicast_route="Route across unicast links"
setup_unicast_route() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B +C +D create_single_identity
foreach_instance +A +B add_servald_interface --file 1
foreach_instance +B +C add_servald_interface --file 2
foreach_instance +C +D add_servald_interface --file 3
set_instance +A
executeOk_servald config \
set interfaces.1.broadcast.drop on
set_instance +C
executeOk_servald config \
set interfaces.2.broadcast.drop on \
set interfaces.3.broadcast.drop on
foreach_instance +A +B +C +D start_servald_server
}
test_unicast_route() {
wait_until --timeout=20 path_exists +A +B +C +D
wait_until --timeout=5 path_exists +D +C +B +A
set_instance +A
executeOk_servald mdp ping --timeout=3 $SIDD 1
tfw_cat --stdout --stderr
}
setup_offline() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B +C +D create_single_identity
foreach_instance +A +B +C add_servald_interface 1
foreach_instance +A +B +D add_servald_interface 2
foreach_instance +A +B +C +D start_servald_server
}
instance_offline() {
local I N
for I; do
[ $I = $instance_arg ] && continue
for ((N=1; 1; ++N)); do
local sidvar=SID${I#+}$N
[ -n "${!sidvar}" ] || break
tfw_log "Checking if $I is offline for $instance_arg"
has_no_link ${!sidvar} || return 1
done
done
}
doc_offline="One node going offline"
test_offline() {
foreach_instance +A +B +C +D \
wait_until has_seen_instances +A +B +C +D
stop_servald_server +C
foreach_instance +A +B +D \
wait_until --timeout=30 instance_offline +C
}
doc_lose_neighbours="Lose and regain neighbours due to turning off"
setup_lose_neighbours() {
setup_servald
assert_no_servald_processes
start_simulator
simulator_command create "net1" "$SERVALD_VAR/dummy1/"
simulator_command create "net2" "$SERVALD_VAR/dummy2/"
foreach_instance +A +B +C create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +B +C add_servald_interface 2
foreach_instance +A +B +C start_servald_server
}
test_lose_neighbours() {
simulator_command up "net1" "net2"
wait_until path_exists +A +B +C
wait_until path_exists +C +B +A
simulator_command down "net1" "net2"
foreach_instance +A +C \
wait_until --timeout=30 instance_offline +B
set_instance +A
wait_until --timeout=30 instance_offline +C
simulator_command up "net1" "net2"
wait_until --timeout=20 path_exists +A +B +C
wait_until --timeout=20 path_exists +C +B +A
}
finally_lose_neighbours() {
simulator_quit
}
doc_interfaceBounce="Lose and regain neighbours due to disabling interface"
setup_interfaceBounce() {
setup_servald
assert_no_servald_processes
start_simulator
simulator_command create "net1" "$SERVALD_VAR/dummy1/"
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +A +B start_servald_server
}
test_interfaceBounce() {
simulator_command up "net1"
wait_until path_exists +A +B
wait_until path_exists +B +A
set_instance +A
executeOk_servald config set interfaces.1.exclude on sync
wait_until --timeout=30 instance_offline +B
set_instance +B
wait_until --timeout=30 instance_offline +A
set_instance +A
executeOk_servald config del interfaces.1.exclude sync
wait_until path_exists +A +B
wait_until path_exists +B +A
}
finally_interfaceBounce() {
simulator_quit
}
setup_multi_interface() {
setup_servald
assert_no_servald_processes
start_simulator
simulator_command create "wlan0" "$SERVALD_VAR/dummy1/"
simulator_command create "eth0" "$SERVALD_VAR/dummy2/"
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface --wifi 1
foreach_instance +A +B add_servald_interface --ethernet 2
foreach_instance +A +B start_servald_server
}
doc_multi_interface="Multiple links of different types to the same neighbour"
test_multi_interface() {
simulator_command up "wlan0" "eth0"
set_instance +A
wait_until has_link --interface "dummy2.*" $SIDB
set_instance +B
wait_until has_link --interface "dummy2.*" $SIDA
set_instance +A
simulator_command down "eth0"
wait_until has_link --interface "dummy1.*" $SIDB
set_instance +B
wait_until has_link --interface "dummy1.*" $SIDA
set_instance +A
simulator_command up "eth0"
wait_until has_link --interface "dummy2.*" $SIDB
set_instance +B
wait_until has_link --interface "dummy2.*" $SIDA
}
finally_multi_interface() {
simulator_quit
}
doc_ping_unreliable_1hop="Ping over a 1-hop unreliable link"
setup_ping_unreliable_1hop() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface 1
start_simulator
simulator_command create "net" "$SERVALD_VAR/dummy1/"
simulator_command set "net" "drop_packets" "40"
foreach_instance +A +B start_servald_server
}
test_ping_unreliable_1hop() {
simulator_command up "net"
wait_until --timeout=10 path_exists +A +B
wait_until --timeout=5 path_exists +B +A
set_instance +A
executeOk_servald mdp ping --interval=0.100 --timeout=3 --wait-for-duplicates $SIDB 100
tfw_cat --stdout --stderr
received=$(sed -n -e 's/.*\<\([0-9]\+\) packets received.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
duplicates=$(sed -n -e 's/.*\<\([0-9]\+\) duplicates.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
assert [ "$received" -ge 98 ]
assert [ "$duplicates" -le 2 ]
}
finally_ping_unreliable_1hop() {
simulator_quit
}
doc_ping_unreliable_2hop="Ping over a 2-hop unreliable link"
setup_ping_unreliable_2hop() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B +C create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +B +C add_servald_interface 2
start_simulator
simulator_command create "net1" "$SERVALD_VAR/dummy1/"
simulator_command set "net1" "drop_packets" "40"
simulator_command create "net2" "$SERVALD_VAR/dummy2/"
simulator_command set "net2" "drop_packets" "40"
foreach_instance +A +B +C start_servald_server
}
test_ping_unreliable_2hop() {
simulator_command up "net1" "net2"
wait_until path_exists +A +B +C
wait_until path_exists +C +B +A
set_instance +A
executeOk_servald mdp ping --interval=0.100 --timeout=3 --wait-for-duplicates $SIDC 100
tfw_cat --stdout --stderr
received=$(sed -n -e 's/.*\<\([0-9]\+\) packets received.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
duplicates=$(sed -n -e 's/.*\<\([0-9]\+\) duplicates.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
assert [ "$received" -ge 98 ]
assert [ "$duplicates" -le 5 ]
}
finally_ping_unreliable_2hop() {
simulator_quit
}
# TODO implement congestion control, use this test as a basis for improving...
doc_ping_congested="Ping flood over an unreliable and congested link"
setup_ping_congested() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface 1
start_simulator
simulator_command create "net1" "$SERVALD_VAR/dummy1/"
simulator_command set "net1" \
"drop_packets" "20" \
"latency" "20" \
"rate" "20000"
foreach_instance +A +B +C start_servald_server
}
test_ping_congested() {
simulator_command up "net1"
wait_until --timeout=10 path_exists +A +B
wait_until --timeout=5 path_exists +B +A
set_instance +A
executeOk_servald mdp ping --interval=0.100 --timeout=3 $SIDB 100
tfw_cat --stdout --stderr
}
finally_ping_congested() {
simulator_quit
}
doc_brping_unreliable_1hop="Broadcast ping over a 1-hop unreliable link"
setup_brping_unreliable_1hop() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
foreach_instance +A +B add_servald_interface 1
start_simulator
simulator_command create "net" "$SERVALD_VAR/dummy1/"
simulator_command set "net" "drop_packets" "20"
foreach_instance +A +B start_servald_server
}
test_brping_unreliable_1hop() {
simulator_command up "net"
wait_until path_exists +A +B
wait_until path_exists +B +A
set_instance +A
executeOk_servald mdp ping --interval=0.100 --timeout=2 --wait-for-duplicates broadcast 100
tfw_cat --stdout --stderr
}
finally_brping_unreliable_1hop() {
simulator_quit
}
doc_unreliable_links="Prefer a longer, better path vs an unreliable link"
setup_unreliable_links() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B +C create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +B +C add_servald_interface 2
foreach_instance +A +C add_servald_interface 3
start_simulator
simulator_command create "net1" "$SERVALD_VAR/dummy1/"
simulator_command create "net2" "$SERVALD_VAR/dummy2/"
simulator_command create "net3" "$SERVALD_VAR/dummy3/"
simulator_command set "net1" "drop_packets" "5"
simulator_command set "net2" "drop_packets" "5"
simulator_command set "net3" "drop_packets" "70"
foreach_instance +A +B +C start_servald_server
}
test_unreliable_links() {
simulator_command up "net1" "net2" "net3"
wait_until path_exists +A +B +C
wait_until path_exists +C +B +A
set_instance +A
executeOk_servald mdp ping --interval=0.100 --timeout=3 --wait-for-duplicates $SIDC 100
tfw_cat --stdout --stderr
received=$(sed -n -e 's/.*\<\([0-9]\+\) packets received.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
duplicates=$(sed -n -e 's/.*\<\([0-9]\+\) duplicates.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
assert [ "$received" -ge 98 ]
assert [ "$duplicates" -le 2 ]
# make sure the path is still there.
wait_until path_exists +A +B +C
wait_until path_exists +C +B +A
}
finally_unreliable_links() {
simulator_quit
}
doc_unreliable_links2="Choose the best multihop path with some unreliable links"
setup_unreliable_links2() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B +C +D create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +A +C add_servald_interface 2
foreach_instance +A +D add_servald_interface 3
foreach_instance +B +C add_servald_interface 4
foreach_instance +B +D add_servald_interface 5
foreach_instance +C +D add_servald_interface 6
start_simulator
simulator_command create "net1" "$SERVALD_VAR/dummy1/"
simulator_command create "net2" "$SERVALD_VAR/dummy2/"
simulator_command create "net3" "$SERVALD_VAR/dummy3/"
simulator_command create "net4" "$SERVALD_VAR/dummy4/"
simulator_command create "net5" "$SERVALD_VAR/dummy5/"
simulator_command create "net6" "$SERVALD_VAR/dummy6/"
simulator_command set "net1" "drop_packets" "5"
simulator_command set "net2" "drop_packets" "60"
simulator_command set "net3" "drop_packets" "90"
simulator_command set "net4" "drop_packets" "5"
simulator_command set "net5" "drop_packets" "60"
simulator_command set "net6" "drop_packets" "5"
foreach_instance +A +B +C +D start_servald_server
}
test_unreliable_links2() {
simulator_command up "net1" "net2" "net3" "net4" "net5" "net6"
wait_until --timeout=20 path_exists +A +B +C +D
wait_until --timeout=20 path_exists +D +C +B +A
set_instance +A
executeOk_servald mdp ping --interval=0.100 --timeout=3 --wait-for-duplicates $SIDD 100
tfw_cat --stdout --stderr
received=$(sed -n -e 's/.*\<\([0-9]\+\) packets received.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
duplicates=$(sed -n -e 's/.*\<\([0-9]\+\) duplicates.*/\1/p' "$TFWSTDOUT") || error "malformed ping output"
assert [ "$received" -ge 98 ]
assert [ "$duplicates" -le 2 ]
wait_until --timeout=20 path_exists +A +B +C +D
wait_until --timeout=20 path_exists +D +C +B +A
}
finally_unreliable_links2() {
simulator_quit
}
setup_circle() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B +C +D +E +F +G +H create_single_identity
foreach_instance +A +B add_servald_interface 1
foreach_instance +B +C add_servald_interface 2
foreach_instance +C +D add_servald_interface 3
foreach_instance +D +E add_servald_interface 4
foreach_instance +E +F add_servald_interface 5
foreach_instance +F +G add_servald_interface 6
foreach_instance +G +H add_servald_interface 7
foreach_instance +H +A add_servald_interface 8
foreach_instance +A +B +C +D +E +F +G +H start_servald_server
}
doc_circle="Circle of nodes with one going offline"
test_circle() {
foreach_instance +A +B +C +D +E +F +G +H \
wait_until has_seen_instances +A +B +C +D +E +F +G +H
wait_until path_exists +A +B +C
wait_until path_exists +C +B +A
set_instance +A
executeOk_servald mdp ping --timeout=3 --wait-for-duplicates $SIDC 1
tfw_cat --stdout --stderr
stop_servald_server +B
foreach_instance +A +C \
wait_until --timeout=10 instance_offline +B
wait_until path_exists +A +H +G +F +E +D +C
wait_until path_exists +C +D +E +F +G +H +A
set_instance +A
executeOk_servald mdp ping --timeout=3 --wait-for-duplicates $SIDC 1
tfw_cat --stdout --stderr
}
setup_crowded_mess() {
setup_servald
assert_no_servald_processes
# BCDE & DEFG form squares, ABC & FGH form triangles
foreach_instance +A +B +C +D +E +F +G +H create_single_identity
foreach_instance +A +B +C add_servald_interface 1
foreach_instance +B +D add_servald_interface 2
foreach_instance +C +E add_servald_interface 3
foreach_instance +D +E add_servald_interface 4
foreach_instance +D +F add_servald_interface 5
foreach_instance +E +G add_servald_interface 6
foreach_instance +F +G +H add_servald_interface 7
foreach_instance +A +B +C +D +E +F +G +H start_servald_server
}
doc_crowded_mess="Multiple possible paths"
test_crowded_mess() {
set_instance +H
wait_until has_link --via "[0-9A-F]*" $SIDA
set_instance +A
wait_until has_link --via "[0-9A-F]*" $SIDH
executeOk_servald mdp trace $SIDD
assertStdoutGrep --matches=1 "^[0-9]:${SIDD}\$"
tfw_cat --stdout
executeOk_servald mdp ping --timeout=3 --wait-for-duplicates $SIDH 1
tfw_cat --stdout --stderr
}
runTests "$@"