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 | |
| 23 | register() { |
| 24 | name=$1 |
| 25 | expirationPeriod=$2 |
| 26 | nextHop=$3 |
| 27 | |
| 28 | result=$(nfdc register -e $(($expirationPeriod * 1000)) $name udp4://$nextHop | grep -o 'FaceId: [0-9]*' | sed s/'FaceId: '//) |
| 29 | echo $result |
| 30 | } |
| 31 | |
| 32 | is_expiration_period_correct() { |
| 33 | name=$1 |
| 34 | nextHop=$2 |
| 35 | lowerBound=$3 |
| 36 | upperBound=$4 |
| 37 | |
| 38 | expirationPeriod=$(nfd-status -r | grep -iF ''$name'' | grep -o 'faceid='$nextHop' ([a-zA-Z0-9 =]*)' |\ |
| 39 | grep -o 'expires=[0-9]*' | sed 's/'expires='//') |
| 40 | |
| 41 | if [[ "$expirationPeriod" -lt $lowerBound || "$expirationPeriod" -gt $upperBound ]]; then |
| 42 | echo $name "has an expiration period of $expirationPeriod seconds which is not between the expected $lowerBound-$upperBound seconds" |
| 43 | exit 1 |
| 44 | else |
| 45 | echo $name "has a correct expiration period between $lowerBound and $upperBound seconds" |
| 46 | fi |
| 47 | } |
| 48 | |
| 49 | expect_entry_does_not_exist() { |
| 50 | name=$1 |
| 51 | |
| 52 | count=$(nfd-status -r | grep -c ' $name ') |
| 53 | |
| 54 | if [[ $count -gt 0 ]]; then |
| 55 | echo $name "exists past its expected expiration period." |
| 56 | exit 2 |
| 57 | else |
| 58 | echo $name "has expired successfully" |
| 59 | fi |
| 60 | } |
| 61 | |
| 62 | expect_route_does_not_exist() { |
| 63 | name=$1 |
| 64 | faceId=$2 |
| 65 | |
| 66 | count=$(nfd-status -r | grep -iF ''$name'' | grep -c 'faceid='$faceId'') |
| 67 | |
| 68 | if [[ $count -gt 0 ]]; then |
| 69 | echo "Route for $name with FaceId: $faceId exists past its expected expiration period." |
| 70 | exit 2 |
| 71 | else |
| 72 | echo "Route for $name with FaceId: $faceId has expired successfully" |
| 73 | fi |
| 74 | } |
| 75 | |
| 76 | sleep_for_seconds() { |
| 77 | echo -e "Sleeping for $1 seconds...\n" |
| 78 | sleep $1 |
| 79 | } |