Yanbiao Li | 7112c89 | 2016-01-24 15:48:10 -0800 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | source ../multi-host.conf |
| 3 | workDir=$(pwd) |
| 4 | logDir=$workDir/logs |
| 5 | hubIP=$CTRL_B |
| 6 | testLog=$logDir/auto-prefix-propagate.log |
| 7 | hostSh=A.sh |
| 8 | hubSh=B.sh |
| 9 | |
Yanbiao Li | 526b564 | 2016-11-17 01:42:27 +0800 | [diff] [blame] | 10 | [[ -d $logDir ]] || mkdir -p $logDir |
Yanbiao Li | 7112c89 | 2016-01-24 15:48:10 -0800 | [diff] [blame] | 11 | echo "TEST AUTOMATIC PREFIX PROPAGATE START" > $testLog |
| 12 | |
| 13 | LOG () { |
| 14 | echo $1; echo $1 >>$testLog |
| 15 | } |
| 16 | |
| 17 | run_hub_cmd () { |
| 18 | ssh $hubIP "$1" 2>&1 |
| 19 | } |
| 20 | |
| 21 | run_scp_to_hub () { |
| 22 | scp $1 $hubIP:$workDir/$1 2>&1 |
| 23 | } |
| 24 | |
| 25 | set_hub_trust_anchor () { |
| 26 | LOG "set the trust anchor to $1 on the hub." |
Yanbiao Li | 526b564 | 2016-11-17 01:42:27 +0800 | [diff] [blame] | 27 | certFile=$(sh $hostSh -a $1) |
| 28 | run_scp_to_hub $certFile |
Yanbiao Li | 7112c89 | 2016-01-24 15:48:10 -0800 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | run_host_ping_server() { |
| 32 | ndnpingserver $1 >>$testLog 2>&1 & |
| 33 | } |
| 34 | |
| 35 | end_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 Li | 7112c89 | 2016-01-24 15:48:10 -0800 | [diff] [blame] | 43 | rm *.log |
| 44 | |
| 45 | [[ $# -gt 0 ]] && LOG "$1" && exit 1 || exit 0 |
| 46 | } |
| 47 | |
| 48 | inspect_hub_rib_exist() { |
Eric Newberry | 7745c1a | 2017-04-20 00:23:05 -0700 | [diff] [blame] | 49 | record=$(run_hub_cmd "nfdc route list" | grep "prefix=$1 ") |
Yanbiao Li | 7112c89 | 2016-01-24 15:48:10 -0800 | [diff] [blame] | 50 | if [[ -z "$record" ]]; then |
| 51 | end_test "Fail test $2" |
| 52 | fi |
| 53 | } |
| 54 | |
| 55 | inspect_hub_rib_none() { |
Eric Newberry | 7745c1a | 2017-04-20 00:23:05 -0700 | [diff] [blame] | 56 | record=$(run_hub_cmd "nfdc route list" | grep "prefix=$1 ") |
Yanbiao Li | 7112c89 | 2016-01-24 15:48:10 -0800 | [diff] [blame] | 57 | if [[ ! -z "$record" ]]; then |
| 58 | end_test "Fail test $2. the matched record: $record" |
| 59 | fi |
| 60 | } |
| 61 | |
| 62 | run_test() { |
| 63 | faceUri=udp4://$hubIP:6363 |
Eric Newberry | 7745c1a | 2017-04-20 00:23:05 -0700 | [diff] [blame] | 64 | nfdc face create $faceUri >> $testLog |
Yanbiao Li | 7112c89 | 2016-01-24 15:48:10 -0800 | [diff] [blame] | 65 | |
| 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 \ |
| 71 | as the /localhop/nfd prefix has not been registered to the local RIB now." |
| 72 | |
| 73 | LOG "run test case: 2" |
Eric Newberry | 7745c1a | 2017-04-20 00:23:05 -0700 | [diff] [blame] | 74 | nfdc route add /localhop/nfd $faceUri >> $testLog && sleep $defer_time |
Yanbiao Li | 7112c89 | 2016-01-24 15:48:10 -0800 | [diff] [blame] | 75 | inspect_hub_rib_exist /Z/A "2: route of /Z/A does not exist, but it should exist because \ |
| 76 | automatic prefix propagation is active (/localhop/nfd prefix has been registered), Z/A/G is \ |
| 77 | present in local RIB and /Z/A has been configured as an identity in NFD's keychain." |
Yanbiao Li | 526b564 | 2016-11-17 01:42:27 +0800 | [diff] [blame] | 78 | inspect_hub_rib_none /Z/A/G "2: route of /Z/A/G exists, but it should not exist because \ |
Yanbiao Li | 7112c89 | 2016-01-24 15:48:10 -0800 | [diff] [blame] | 79 | /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 Li | 526b564 | 2016-11-17 01:42:27 +0800 | [diff] [blame] | 85 | inspect_hub_rib_none /Z/A/H "3: route of /Z/A/H exists, but it should not exist because \ |
Yanbiao Li | 7112c89 | 2016-01-24 15:48:10 -0800 | [diff] [blame] | 86 | /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 \ |
| 91 | local 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 \ |
| 96 | automatically 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 \ |
| 101 | propagated 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 \ |
| 103 | been 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 \ |
| 108 | refreshed 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 \ |
| 113 | should not be active becuase there are no configured keys for the covering namespace." |
| 114 | } |
| 115 | |
| 116 | LOG "set environment in the host." |
| 117 | bash $hostSh -c -p |
| 118 | |
| 119 | LOG "set environment in the hub." |
| 120 | run_hub_cmd "[[ -d $workDir ]] || mkdir -p $workDir" |
| 121 | run_scp_to_hub $hubSh |
| 122 | set_hub_trust_anchor ndn:/Z/A |
| 123 | run_hub_cmd "cd $workDir && bash $hubSh -c -p" |
| 124 | |
| 125 | LOG "run test" |
| 126 | run_test && end_test |