blob: eb7e8dbb05b967d16464f5a2d2e33c64bb0c2ae0 [file] [log] [blame]
Yanbiao Li7112c892016-01-24 15:48:10 -08001#!/usr/bin/env bash
2source ../multi-host.conf
3workDir=$(pwd)
4logDir=$workDir/logs
5hubIP=$CTRL_B
6testLog=$logDir/auto-prefix-propagate.log
7hostSh=A.sh
8hubSh=B.sh
9
10echo "TEST AUTOMATIC PREFIX PROPAGATE START" > $testLog
11
12LOG () {
13 echo $1; echo $1 >>$testLog
14}
15
16run_hub_cmd () {
17 ssh $hubIP "$1" 2>&1
18}
19
20run_scp_to_hub () {
21 scp $1 $hubIP:$workDir/$1 2>&1
22}
23
24set_hub_trust_anchor () {
25 LOG "set the trust anchor to $1 on the hub."
26 anchor=$(sh $hostSh -a $1)
27 echo $anchor > anchor.cert
28 run_scp_to_hub anchor.cert && rm anchor.cert
29}
30
31run_host_ping_server() {
32 ndnpingserver $1 >>$testLog 2>&1 &
33}
34
35end_test() {
36 scp $hubIP:$workDir/hub.nfd.log hub.nfd.log 2>&1
37 scp $hubIP:$workDir/hub.test.log hub.test.log 2>&1
38 cat host.nfd.log hub.nfd.log > nfd.log
39 cat host.test.log hub.test.log > test.log
40 cat nfd.log test.log >> $testLog
41
42 bash $hostSh -c && run_hub_cmd "cd $workDir && bash $hubSh -c"
43 run_hub_cmd "[[ -d $workDir ]] && sudo rm -rf $workDir"
44 rm *.log
45
46 [[ $# -gt 0 ]] && LOG "$1" && exit 1 || exit 0
47}
48
49inspect_hub_rib_exist() {
50 record=$(run_hub_cmd "nfd-status -r" | grep "$1 route")
51 if [[ -z "$record" ]]; then
52 end_test "Fail test $2"
53 fi
54}
55
56inspect_hub_rib_none() {
57 record=$(run_hub_cmd "nfd-status -r" | grep "$1 route")
58 if [[ ! -z "$record" ]]; then
59 end_test "Fail test $2. the matched record: $record"
60 fi
61}
62
63run_test() {
64 faceUri=udp4://$hubIP:6363
65 nfdc create $faceUri >> $testLog
66
67 defer_time=5
68
69 LOG "run test case: 1"
70 run_host_ping_server ndn:/Z/A/G && p1=$! && sleep $defer_time
71 inspect_hub_rib_none /Z/A "1: route of /Z/A exists, but propagation should not be active \
72as the /localhop/nfd prefix has not been registered to the local RIB now."
73
74 LOG "run test case: 2"
75 nfdc register ndn:/localhop/nfd $faceUri >> $testLog && sleep $defer_time
76 inspect_hub_rib_exist /Z/A "2: route of /Z/A does not exist, but it should exist because \
77automatic prefix propagation is active (/localhop/nfd prefix has been registered), Z/A/G is \
78present in local RIB and /Z/A has been configured as an identity in NFD's keychain."
79 inspect_hub_none /Z/A/G "2: route of /Z/A/G exists, but it should not exist because \
80/Z/A is shorter and should be adopted for propagation."
81
82 LOG "run test case: 3"
83 run_host_ping_server ndn:/Z/A/H && p2=$! && sleep $defer_time
84 inspect_hub_rib_exist /Z/A "3: route of /Z/A does not exist, but it should exist because \
85/Z/A has already been propagated."
86 inspect_hub_none /Z/A/H "3: route of /Z/A/H exists, but it should not exist because \
87/Z/A is shorter and should be adopted for propagation."
88
89 LOG "run test case: 4"
90 sudo kill $p1 1>> $testLog 2>&1 && sleep $defer_time
91 inspect_hub_rib_exist /Z/A "4: route of /Z/A was unregistered, it should be kept for \
92local RIB entry /Z/A/H."
93
94 LOG "run test case: 5"
95 sudo kill $p2 1>> $testLog 2>&1 && sleep $defer_time
96 inspect_hub_rib_none /Z/A "5: route of /Z/A still exists, but it should have been \
97automatically unregistered, because all /Z/H/* prefixes have been unregistered locally."
98
99 LOG "run test case: 6"
100 run_host_ping_server ndn:/Z/A/B/C/D && p3=$! && sleep $defer_time
101 inspect_hub_rib_none /Z/A/B/C "6: route of /Z/A/B/C exist, but it should not be \
102propagated because /Z/A is a better choice."
103 inspect_hub_rib_exist /Z/A "6: route of /Z/A does not exist, but it should have \
104been propagated."
105
106 LOG "run test case: 7"
107 sleep 80
108 inspect_hub_rib_exist /Z/A "7: route of /Z/A/ does not exist, it should have been \
109refreshed periodically."
110
111 LOG "run test case: 8"
112 run_host_ping_server ndn:/Z/F/I && sleep $defer_time
113 inspect_hub_rib_none /Z/F "8: route of /Z/F exist, but automatic prefix propagation \
114should not be active becuase there are no configured keys for the covering namespace."
115}
116
117LOG "set environment in the host."
118bash $hostSh -c -p
119
120LOG "set environment in the hub."
121run_hub_cmd "[[ -d $workDir ]] || mkdir -p $workDir"
122run_scp_to_hub $hubSh
123set_hub_trust_anchor ndn:/Z/A
124run_hub_cmd "cd $workDir && bash $hubSh -c -p"
125
126LOG "run test"
127run_test && end_test