blob: b767926cbbf7848491044b8815f922809f3f8943 [file] [log] [blame]
Vince Lehman797207e2014-07-28 16:30:51 -05001#!/usr/bin/env bash
2
3source ../multi-host.conf
4
5start_nfd() {
6 sudo nfd &> $workdir/logs/nfd.log &
7 ssh $CTRL_B "sudo nfd &"
8 sleep 2
9}
10
Vince Lehman797207e2014-07-28 16:30:51 -050011set_up() {
12 workdir=$(pwd)
13 mkdir -p $workdir/logs
14
15 start_nfd
Vince Lehman797207e2014-07-28 16:30:51 -050016}
17
18clean_up() {
19 nfd-stop
20 exit 0
21}
22
Eric Newberry7745c1a2017-04-20 00:23:05 -070023create_face() {
24 nextHop=$1
25
26 result=$(nfdc face create udp4://$nextHop)
27 echo $result
28}
29
Vince Lehman797207e2014-07-28 16:30:51 -050030register() {
31 name=$1
32 expirationPeriod=$2
33 nextHop=$3
34
Eric Newberry7745c1a2017-04-20 00:23:05 -070035 result=$(nfdc route add $name udp4://$nextHop expires $(($expirationPeriod * 1000)) | grep -o 'nexthop=[0-9]*' | sed s/'nexthop='//)
Vince Lehman797207e2014-07-28 16:30:51 -050036 echo $result
37}
38
39is_expiration_period_correct() {
40 name=$1
41 nextHop=$2
42 lowerBound=$3
43 upperBound=$4
44
Eric Newberry7745c1a2017-04-20 00:23:05 -070045 expirationPeriod=$(nfdc route list | grep -iF ''$name'' | grep 'nexthop='$nextHop'' |\
Vince Lehman797207e2014-07-28 16:30:51 -050046 grep -o 'expires=[0-9]*' | sed 's/'expires='//')
47
48 if [[ "$expirationPeriod" -lt $lowerBound || "$expirationPeriod" -gt $upperBound ]]; then
49 echo $name "has an expiration period of $expirationPeriod seconds which is not between the expected $lowerBound-$upperBound seconds"
50 exit 1
51 else
52 echo $name "has a correct expiration period between $lowerBound and $upperBound seconds"
53 fi
54}
55
56expect_entry_does_not_exist() {
57 name=$1
58
Eric Newberry7745c1a2017-04-20 00:23:05 -070059 count=$(nfdc route list | grep -c '$name ')
Vince Lehman797207e2014-07-28 16:30:51 -050060
61 if [[ $count -gt 0 ]]; then
62 echo $name "exists past its expected expiration period."
63 exit 2
64 else
65 echo $name "has expired successfully"
66 fi
67}
68
69expect_route_does_not_exist() {
70 name=$1
Eric Newberry7745c1a2017-04-20 00:23:05 -070071 nexthop=$2
Vince Lehman797207e2014-07-28 16:30:51 -050072
Eric Newberry7745c1a2017-04-20 00:23:05 -070073 count=$(nfdc route list | grep -iF ''$name'' | grep -c 'nexthop='$nexthop'')
Vince Lehman797207e2014-07-28 16:30:51 -050074
75 if [[ $count -gt 0 ]]; then
Eric Newberry7745c1a2017-04-20 00:23:05 -070076 echo "Route for $name with nexthop=$nexthop exists past its expected expiration period."
Vince Lehman797207e2014-07-28 16:30:51 -050077 exit 2
78 else
Eric Newberry7745c1a2017-04-20 00:23:05 -070079 echo "Route for $name with nexthop=$nexthop has expired successfully"
Vince Lehman797207e2014-07-28 16:30:51 -050080 fi
81}
82
83sleep_for_seconds() {
84 echo -e "Sleeping for $1 seconds...\n"
85 sleep $1
Eric Newberry7745c1a2017-04-20 00:23:05 -070086}