blob: 13614e1c26ddccbc3b70d4c7fc9eed5b8b24aaf5 [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
Yanbiao Li526b5642016-11-17 01:42:27 +080010[[ -d $logDir ]] || mkdir -p $logDir
Yanbiao Li7112c892016-01-24 15:48:10 -080011echo "TEST AUTOMATIC PREFIX PROPAGATE START" > $testLog
12
13LOG () {
14 echo $1; echo $1 >>$testLog
15}
16
17run_hub_cmd () {
18 ssh $hubIP "$1" 2>&1
19}
20
21run_scp_to_hub () {
22 scp $1 $hubIP:$workDir/$1 2>&1
23}
24
25set_hub_trust_anchor () {
26 LOG "set the trust anchor to $1 on the hub."
Yanbiao Li526b5642016-11-17 01:42:27 +080027 certFile=$(sh $hostSh -a $1)
28 run_scp_to_hub $certFile
Yanbiao Li7112c892016-01-24 15:48:10 -080029}
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"
Yanbiao Li7112c892016-01-24 15:48:10 -080043 rm *.log
44
45 [[ $# -gt 0 ]] && LOG "$1" && exit 1 || exit 0
46}
47
48inspect_hub_rib_exist() {
Eric Newberry7745c1a2017-04-20 00:23:05 -070049 record=$(run_hub_cmd "nfdc route list" | grep "prefix=$1 ")
Yanbiao Li7112c892016-01-24 15:48:10 -080050 if [[ -z "$record" ]]; then
51 end_test "Fail test $2"
52 fi
53}
54
55inspect_hub_rib_none() {
Eric Newberry7745c1a2017-04-20 00:23:05 -070056 record=$(run_hub_cmd "nfdc route list" | grep "prefix=$1 ")
Yanbiao Li7112c892016-01-24 15:48:10 -080057 if [[ ! -z "$record" ]]; then
58 end_test "Fail test $2. the matched record: $record"
59 fi
60}
61
62run_test() {
63 faceUri=udp4://$hubIP:6363
Eric Newberry7745c1a2017-04-20 00:23:05 -070064 nfdc face create $faceUri >> $testLog
Yanbiao Li7112c892016-01-24 15:48:10 -080065
66 defer_time=5
67
68 LOG "run test case: 1"
69 run_host_ping_server ndn:/Z/A/G && p1=$! && sleep $defer_time
70 inspect_hub_rib_none /Z/A "1: route of /Z/A exists, but propagation should not be active \
71as the /localhop/nfd prefix has not been registered to the local RIB now."
72
73 LOG "run test case: 2"
Eric Newberry7745c1a2017-04-20 00:23:05 -070074 nfdc route add /localhop/nfd $faceUri >> $testLog && sleep $defer_time
Yanbiao Li7112c892016-01-24 15:48:10 -080075 inspect_hub_rib_exist /Z/A "2: route of /Z/A does not exist, but it should exist because \
76automatic prefix propagation is active (/localhop/nfd prefix has been registered), Z/A/G is \
77present in local RIB and /Z/A has been configured as an identity in NFD's keychain."
Yanbiao Li526b5642016-11-17 01:42:27 +080078 inspect_hub_rib_none /Z/A/G "2: route of /Z/A/G exists, but it should not exist because \
Yanbiao Li7112c892016-01-24 15:48:10 -080079/Z/A is shorter and should be adopted for propagation."
80
81 LOG "run test case: 3"
82 run_host_ping_server ndn:/Z/A/H && p2=$! && sleep $defer_time
83 inspect_hub_rib_exist /Z/A "3: route of /Z/A does not exist, but it should exist because \
84/Z/A has already been propagated."
Yanbiao Li526b5642016-11-17 01:42:27 +080085 inspect_hub_rib_none /Z/A/H "3: route of /Z/A/H exists, but it should not exist because \
Yanbiao Li7112c892016-01-24 15:48:10 -080086/Z/A is shorter and should be adopted for propagation."
87
88 LOG "run test case: 4"
89 sudo kill $p1 1>> $testLog 2>&1 && sleep $defer_time
90 inspect_hub_rib_exist /Z/A "4: route of /Z/A was unregistered, it should be kept for \
91local RIB entry /Z/A/H."
92
93 LOG "run test case: 5"
94 sudo kill $p2 1>> $testLog 2>&1 && sleep $defer_time
95 inspect_hub_rib_none /Z/A "5: route of /Z/A still exists, but it should have been \
96automatically unregistered, because all /Z/H/* prefixes have been unregistered locally."
97
98 LOG "run test case: 6"
99 run_host_ping_server ndn:/Z/A/B/C/D && p3=$! && sleep $defer_time
100 inspect_hub_rib_none /Z/A/B/C "6: route of /Z/A/B/C exist, but it should not be \
101propagated because /Z/A is a better choice."
102 inspect_hub_rib_exist /Z/A "6: route of /Z/A does not exist, but it should have \
103been propagated."
104
105 LOG "run test case: 7"
106 sleep 80
107 inspect_hub_rib_exist /Z/A "7: route of /Z/A/ does not exist, it should have been \
108refreshed periodically."
109
110 LOG "run test case: 8"
111 run_host_ping_server ndn:/Z/F/I && sleep $defer_time
112 inspect_hub_rib_none /Z/F "8: route of /Z/F exist, but automatic prefix propagation \
113should not be active becuase there are no configured keys for the covering namespace."
114}
115
116LOG "set environment in the host."
117bash $hostSh -c -p
118
119LOG "set environment in the hub."
120run_hub_cmd "[[ -d $workDir ]] || mkdir -p $workDir"
121run_scp_to_hub $hubSh
122set_hub_trust_anchor ndn:/Z/A
123run_hub_cmd "cd $workDir && bash $hubSh -c -p"
124
125LOG "run test"
126run_test && end_test