blob: 6f627825940745ca2fa8eceadc426b4fd48453c6 [file] [log] [blame]
#!/usr/bin/env bash
source ../multi-host.conf
workDir=$(pwd)
logDir=$workDir/logs
hubIP=$CTRL_B
testLog=$logDir/auto-prefix-propagate.log
hostSh=A.sh
hubSh=B.sh
[[ -d $logDir ]] || mkdir -p $logDir
echo "TEST AUTOMATIC PREFIX PROPAGATE START" > $testLog
LOG () {
echo $1; echo $1 >>$testLog
}
run_hub_cmd () {
ssh $hubIP "$1" 2>&1
}
run_scp_to_hub () {
scp $1 $hubIP:$workDir/$1 2>&1
}
set_hub_trust_anchor () {
LOG "set the trust anchor to $1 on the hub."
certFile=$(sh $hostSh -a $1)
run_scp_to_hub $certFile
}
run_host_ping_server() {
ndnpingserver $1 >>$testLog 2>&1 &
}
end_test() {
scp $hubIP:$workDir/hub.nfd.log hub.nfd.log 2>&1
scp $hubIP:$workDir/hub.test.log hub.test.log 2>&1
cat host.nfd.log hub.nfd.log > nfd.log
cat host.test.log hub.test.log > test.log
cat nfd.log test.log >> $testLog
bash $hostSh -c && run_hub_cmd "cd $workDir && bash $hubSh -c"
rm *.log
[[ $# -gt 0 ]] && LOG "$1" && exit 1 || exit 0
}
inspect_hub_rib_exist() {
record=$(run_hub_cmd "nfd-status -r" | grep "$1 route")
if [[ -z "$record" ]]; then
end_test "Fail test $2"
fi
}
inspect_hub_rib_none() {
record=$(run_hub_cmd "nfd-status -r" | grep "$1 route")
if [[ ! -z "$record" ]]; then
end_test "Fail test $2. the matched record: $record"
fi
}
run_test() {
faceUri=udp4://$hubIP:6363
nfdc create $faceUri >> $testLog
defer_time=5
LOG "run test case: 1"
run_host_ping_server ndn:/Z/A/G && p1=$! && sleep $defer_time
inspect_hub_rib_none /Z/A "1: route of /Z/A exists, but propagation should not be active \
as the /localhop/nfd prefix has not been registered to the local RIB now."
LOG "run test case: 2"
nfdc register ndn:/localhop/nfd $faceUri >> $testLog && sleep $defer_time
inspect_hub_rib_exist /Z/A "2: route of /Z/A does not exist, but it should exist because \
automatic prefix propagation is active (/localhop/nfd prefix has been registered), Z/A/G is \
present in local RIB and /Z/A has been configured as an identity in NFD's keychain."
inspect_hub_rib_none /Z/A/G "2: route of /Z/A/G exists, but it should not exist because \
/Z/A is shorter and should be adopted for propagation."
LOG "run test case: 3"
run_host_ping_server ndn:/Z/A/H && p2=$! && sleep $defer_time
inspect_hub_rib_exist /Z/A "3: route of /Z/A does not exist, but it should exist because \
/Z/A has already been propagated."
inspect_hub_rib_none /Z/A/H "3: route of /Z/A/H exists, but it should not exist because \
/Z/A is shorter and should be adopted for propagation."
LOG "run test case: 4"
sudo kill $p1 1>> $testLog 2>&1 && sleep $defer_time
inspect_hub_rib_exist /Z/A "4: route of /Z/A was unregistered, it should be kept for \
local RIB entry /Z/A/H."
LOG "run test case: 5"
sudo kill $p2 1>> $testLog 2>&1 && sleep $defer_time
inspect_hub_rib_none /Z/A "5: route of /Z/A still exists, but it should have been \
automatically unregistered, because all /Z/H/* prefixes have been unregistered locally."
LOG "run test case: 6"
run_host_ping_server ndn:/Z/A/B/C/D && p3=$! && sleep $defer_time
inspect_hub_rib_none /Z/A/B/C "6: route of /Z/A/B/C exist, but it should not be \
propagated because /Z/A is a better choice."
inspect_hub_rib_exist /Z/A "6: route of /Z/A does not exist, but it should have \
been propagated."
LOG "run test case: 7"
sleep 80
inspect_hub_rib_exist /Z/A "7: route of /Z/A/ does not exist, it should have been \
refreshed periodically."
LOG "run test case: 8"
run_host_ping_server ndn:/Z/F/I && sleep $defer_time
inspect_hub_rib_none /Z/F "8: route of /Z/F exist, but automatic prefix propagation \
should not be active becuase there are no configured keys for the covering namespace."
}
LOG "set environment in the host."
bash $hostSh -c -p
LOG "set environment in the hub."
run_hub_cmd "[[ -d $workDir ]] || mkdir -p $workDir"
run_scp_to_hub $hubSh
set_hub_trust_anchor ndn:/Z/A
run_hub_cmd "cd $workDir && bash $hubSh -c -p"
LOG "run test"
run_test && end_test