Vince Lehman | 797207e | 2014-07-28 16:30:51 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | source ../multi-host.conf |
| 4 | |
| 5 | start_nfd() { |
| 6 | sudo nfd &> $workdir/logs/nfd.log & |
| 7 | ssh $CTRL_B "sudo nfd &" |
| 8 | sleep 2 |
| 9 | } |
| 10 | |
Vince Lehman | 797207e | 2014-07-28 16:30:51 -0500 | [diff] [blame] | 11 | set_up() { |
| 12 | workdir=$(pwd) |
| 13 | mkdir -p $workdir/logs |
| 14 | |
| 15 | start_nfd |
Vince Lehman | 797207e | 2014-07-28 16:30:51 -0500 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | clean_up() { |
| 19 | nfd-stop |
| 20 | exit 0 |
| 21 | } |
| 22 | |
Eric Newberry | 7745c1a | 2017-04-20 00:23:05 -0700 | [diff] [blame] | 23 | create_face() { |
| 24 | nextHop=$1 |
| 25 | |
| 26 | result=$(nfdc face create udp4://$nextHop) |
| 27 | echo $result |
| 28 | } |
| 29 | |
Vince Lehman | 797207e | 2014-07-28 16:30:51 -0500 | [diff] [blame] | 30 | register() { |
| 31 | name=$1 |
| 32 | expirationPeriod=$2 |
| 33 | nextHop=$3 |
| 34 | |
Eric Newberry | 7745c1a | 2017-04-20 00:23:05 -0700 | [diff] [blame] | 35 | result=$(nfdc route add $name udp4://$nextHop expires $(($expirationPeriod * 1000)) | grep -o 'nexthop=[0-9]*' | sed s/'nexthop='//) |
Vince Lehman | 797207e | 2014-07-28 16:30:51 -0500 | [diff] [blame] | 36 | echo $result |
| 37 | } |
| 38 | |
| 39 | is_expiration_period_correct() { |
| 40 | name=$1 |
| 41 | nextHop=$2 |
| 42 | lowerBound=$3 |
| 43 | upperBound=$4 |
| 44 | |
Eric Newberry | 7745c1a | 2017-04-20 00:23:05 -0700 | [diff] [blame] | 45 | expirationPeriod=$(nfdc route list | grep -iF ''$name'' | grep 'nexthop='$nextHop'' |\ |
Vince Lehman | 797207e | 2014-07-28 16:30:51 -0500 | [diff] [blame] | 46 | 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 | |
| 56 | expect_entry_does_not_exist() { |
| 57 | name=$1 |
| 58 | |
Eric Newberry | 7745c1a | 2017-04-20 00:23:05 -0700 | [diff] [blame] | 59 | count=$(nfdc route list | grep -c '$name ') |
Vince Lehman | 797207e | 2014-07-28 16:30:51 -0500 | [diff] [blame] | 60 | |
| 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 | |
| 69 | expect_route_does_not_exist() { |
| 70 | name=$1 |
Eric Newberry | 7745c1a | 2017-04-20 00:23:05 -0700 | [diff] [blame] | 71 | nexthop=$2 |
Vince Lehman | 797207e | 2014-07-28 16:30:51 -0500 | [diff] [blame] | 72 | |
Eric Newberry | 7745c1a | 2017-04-20 00:23:05 -0700 | [diff] [blame] | 73 | count=$(nfdc route list | grep -iF ''$name'' | grep -c 'nexthop='$nexthop'') |
Vince Lehman | 797207e | 2014-07-28 16:30:51 -0500 | [diff] [blame] | 74 | |
| 75 | if [[ $count -gt 0 ]]; then |
Eric Newberry | 7745c1a | 2017-04-20 00:23:05 -0700 | [diff] [blame] | 76 | echo "Route for $name with nexthop=$nexthop exists past its expected expiration period." |
Vince Lehman | 797207e | 2014-07-28 16:30:51 -0500 | [diff] [blame] | 77 | exit 2 |
| 78 | else |
Eric Newberry | 7745c1a | 2017-04-20 00:23:05 -0700 | [diff] [blame] | 79 | echo "Route for $name with nexthop=$nexthop has expired successfully" |
Vince Lehman | 797207e | 2014-07-28 16:30:51 -0500 | [diff] [blame] | 80 | fi |
| 81 | } |
| 82 | |
| 83 | sleep_for_seconds() { |
| 84 | echo -e "Sleeping for $1 seconds...\n" |
| 85 | sleep $1 |
Eric Newberry | 7745c1a | 2017-04-20 00:23:05 -0700 | [diff] [blame] | 86 | } |