blob: b767926cbbf7848491044b8815f922809f3f8943 [file] [log] [blame]
#!/usr/bin/env bash
source ../multi-host.conf
start_nfd() {
sudo nfd &> $workdir/logs/nfd.log &
ssh $CTRL_B "sudo nfd &"
sleep 2
}
set_up() {
workdir=$(pwd)
mkdir -p $workdir/logs
start_nfd
}
clean_up() {
nfd-stop
exit 0
}
create_face() {
nextHop=$1
result=$(nfdc face create udp4://$nextHop)
echo $result
}
register() {
name=$1
expirationPeriod=$2
nextHop=$3
result=$(nfdc route add $name udp4://$nextHop expires $(($expirationPeriod * 1000)) | grep -o 'nexthop=[0-9]*' | sed s/'nexthop='//)
echo $result
}
is_expiration_period_correct() {
name=$1
nextHop=$2
lowerBound=$3
upperBound=$4
expirationPeriod=$(nfdc route list | grep -iF ''$name'' | grep 'nexthop='$nextHop'' |\
grep -o 'expires=[0-9]*' | sed 's/'expires='//')
if [[ "$expirationPeriod" -lt $lowerBound || "$expirationPeriod" -gt $upperBound ]]; then
echo $name "has an expiration period of $expirationPeriod seconds which is not between the expected $lowerBound-$upperBound seconds"
exit 1
else
echo $name "has a correct expiration period between $lowerBound and $upperBound seconds"
fi
}
expect_entry_does_not_exist() {
name=$1
count=$(nfdc route list | grep -c '$name ')
if [[ $count -gt 0 ]]; then
echo $name "exists past its expected expiration period."
exit 2
else
echo $name "has expired successfully"
fi
}
expect_route_does_not_exist() {
name=$1
nexthop=$2
count=$(nfdc route list | grep -iF ''$name'' | grep -c 'nexthop='$nexthop'')
if [[ $count -gt 0 ]]; then
echo "Route for $name with nexthop=$nexthop exists past its expected expiration period."
exit 2
else
echo "Route for $name with nexthop=$nexthop has expired successfully"
fi
}
sleep_for_seconds() {
echo -e "Sleeping for $1 seconds...\n"
sleep $1
}