Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Eric Newberry | bef4947 | 2017-05-08 22:49:05 -0700 | [diff] [blame^] | 2 | NUM_OF_PINGS=100 |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 3 | |
| 4 | # clean up - kill nfd |
| 5 | clean_up() { |
| 6 | r=$(ssh $CTRL_B "sudo killall nfd" 2>&1) |
| 7 | r=$(sudo killall nfd 2>&1) |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 8 | } |
| 9 | |
| 10 | start_nfd() { |
| 11 | # start nfd on localhost |
Eric Newberry | bef4947 | 2017-05-08 22:49:05 -0700 | [diff] [blame^] | 12 | sudo nfd &> $workdir/logs/nfd.log & |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 13 | |
| 14 | # start nfd on hostB |
Eric Newberry | bef4947 | 2017-05-08 22:49:05 -0700 | [diff] [blame^] | 15 | ssh $CTRL_B "mkdir -p $workdir/logs ; sudo nfd &> $workdir/logs/nfd.log & sleep 2" |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 16 | sleep 2 |
| 17 | } |
| 18 | |
Eric Newberry | bef4947 | 2017-05-08 22:49:05 -0700 | [diff] [blame^] | 19 | # check whether a given face with the specified FaceId and URI has had at least a given number of |
| 20 | # incoming/outgoing Interests |
| 21 | # param list: $1 - face ID |
| 22 | # $2 - face URI |
| 23 | # $3 - counter type (in/out) |
| 24 | # $4 - minimum successful value of the counter |
| 25 | check_nfdc_face_counters() { |
| 26 | local faceId=$1 |
| 27 | local faceUri=$2 |
| 28 | local counterType=$3 |
| 29 | local threshold=$4 |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 30 | |
Hila Ben Abraham | 799f78f | 2015-03-01 22:06:33 -0600 | [diff] [blame] | 31 | # wait for the refreshed output of nfd-status |
| 32 | sleep 2 |
| 33 | |
Eric Newberry | bef4947 | 2017-05-08 22:49:05 -0700 | [diff] [blame^] | 34 | local counter=$(nfdc face list | grep -iF "faceid=$faceId remote=$faceUri" | sed -E "s/.*${counterType}=\{([0-9]+)i.*/\1/") |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 35 | |
Eric Newberry | bef4947 | 2017-05-08 22:49:05 -0700 | [diff] [blame^] | 36 | if [[ $counter -lt $threshold ]]; then |
| 37 | echo "nfdc: $counterType counter of face=$faceId is less than $threshold " >> $testLog |
| 38 | echo "'nfdc face list' is:" >> $testLog |
| 39 | nfdc face list >> $testLog |
| 40 | clean_up |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 41 | exit 2 |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 42 | fi |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 43 | } |
| 44 | |
Eric Newberry | bef4947 | 2017-05-08 22:49:05 -0700 | [diff] [blame^] | 45 | # check for the existence of a face with the specified FaceId and URI |
| 46 | # param list: $1 - face ID |
| 47 | # $2 - face URI |
| 48 | check_nfdc_face_existence() { |
| 49 | local faceId=$1 |
| 50 | local faceUri=$2 |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 51 | |
Eric Newberry | bef4947 | 2017-05-08 22:49:05 -0700 | [diff] [blame^] | 52 | # wait for the refreshed output of nfdc |
Hila Ben Abraham | 799f78f | 2015-03-01 22:06:33 -0600 | [diff] [blame] | 53 | sleep 2 |
| 54 | |
Eric Newberry | bef4947 | 2017-05-08 22:49:05 -0700 | [diff] [blame^] | 55 | # check for the existence of the specified face |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 56 | # First, get the face line |
| 57 | # Second, extract the face id attached to the fetched line |
Eric Newberry | bef4947 | 2017-05-08 22:49:05 -0700 | [diff] [blame^] | 58 | local face=$(nfdc face list | grep -iF "remote=$faceUri" | sed -E "s/.*faceid=([0-9]+).*/\1/") |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 59 | |
Eric Newberry | bef4947 | 2017-05-08 22:49:05 -0700 | [diff] [blame^] | 60 | if [[ $faceId != "none" && $face != $faceId ]]; then |
| 61 | echo "nfdc: Failed to find face $faceId to $faceUri" >> $testLog |
| 62 | echo "'nfdc face list' is:" >> $testLog |
| 63 | nfdc face list >> $testLog |
| 64 | echo "-1" |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 65 | else |
| 66 | echo $face |
| 67 | fi |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 68 | } |
| 69 | |
Eric Newberry | bef4947 | 2017-05-08 22:49:05 -0700 | [diff] [blame^] | 70 | # check for the existence of a face with the specified FaceId and URI using `nfdc face show` |
| 71 | # param list: $1 - face ID |
| 72 | # $2 - face URI |
| 73 | check_nfdc_face_existence_show() { |
| 74 | local faceId=$1 |
| 75 | local faceUri=$2 |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 76 | |
Eric Newberry | bef4947 | 2017-05-08 22:49:05 -0700 | [diff] [blame^] | 77 | # wait for the refreshed output of nfdc |
Hila Ben Abraham | 799f78f | 2015-03-01 22:06:33 -0600 | [diff] [blame] | 78 | sleep 2 |
| 79 | |
Eric Newberry | bef4947 | 2017-05-08 22:49:05 -0700 | [diff] [blame^] | 80 | # check for the existence of the specified face |
| 81 | # Extract the remote URI |
| 82 | local actualUri=$(nfdc face show id $faceId | grep -iFo "remote=$faceUri" | sed 's/remote=//') |
| 83 | |
| 84 | if [[ "$actualUri" != "$faceUri" ]]; then |
| 85 | echo "nfdc: Failed to find face $faceId to $faceUri" >> $testLog |
| 86 | echo "'nfdc face show id $faceId' is:" >> $testLog |
| 87 | nfdc face show id $faceId >> $testLog |
| 88 | echo "-1" |
| 89 | else |
| 90 | echo $face |
| 91 | fi |
| 92 | } |
| 93 | |
| 94 | # check for the existence of a face with the specified FaceId and URI using `nfdc face list`, filtered |
| 95 | # for remote URI |
| 96 | # param list: $1 - face ID |
| 97 | # $2 - face URI |
| 98 | check_nfdc_face_existence_remote_uri() { |
| 99 | local faceId=$1 |
| 100 | local faceUri=$2 |
| 101 | |
| 102 | # wait for the refreshed output of nfdc |
| 103 | sleep 2 |
| 104 | |
| 105 | # check for the existence of the specified face |
| 106 | # First, get the face line |
| 107 | # Second, extract the face id attached to the fetched line |
| 108 | local face=$(nfdc face list remote $faceUri | grep -iF "remote=$faceUri" | grep -Po "faceid=[0-9]+" | sed 's/faceid=//') |
| 109 | |
| 110 | if [[ "none" != $faceId && $face != $faceId ]]; then |
| 111 | echo "nfdc: Failed to find face $faceId to $faceUri" >> $testLog |
| 112 | echo "'nfdc face list remote $faceUri' is:" >> $testLog |
| 113 | nfdc face list >> $testLog |
| 114 | echo "-1" |
| 115 | else |
| 116 | echo $face |
| 117 | fi |
| 118 | } |
| 119 | |
| 120 | # check for the existence of a route for a given prefix with nexthop face ID and cost |
| 121 | # param list: $1 - route prefix |
| 122 | # $2 - nexthop face ID |
| 123 | # $3 - route cost |
| 124 | # $4 - if set, check if route does not exist (optional) |
| 125 | check_nfdc_route_existence() { |
| 126 | local prefix=$1 |
| 127 | local nexthop=$2 |
| 128 | local cost=$3 |
| 129 | local noexist=false |
| 130 | if [[ $# -gt 3 ]]; then |
| 131 | noexist=true |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 132 | fi |
| 133 | |
Eric Newberry | bef4947 | 2017-05-08 22:49:05 -0700 | [diff] [blame^] | 134 | local routeInfo=$(nfdc route list | grep "^prefix=$prefix nexthop=$nexthop origin=[a-zA-Z0-9]* cost=$cost flags=") |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 135 | |
Eric Newberry | bef4947 | 2017-05-08 22:49:05 -0700 | [diff] [blame^] | 136 | if [[ $noexist == false ]]; then |
| 137 | if [[ -z $routeInfo ]]; then |
| 138 | echo "nfdc: Failed to find route to $prefix with nexthop $nexthop and cost $cost" >> $testLog |
| 139 | echo "'nfdc route list' is:" >> $testLog |
| 140 | nfdc route list >> $testLog |
| 141 | clean_up |
| 142 | exit 2 |
| 143 | fi |
| 144 | else |
| 145 | if [[ -n $routeInfo ]]; then |
| 146 | echo "nfdc: Failed to remove route to $prefix with nexthop" >> $testLog |
| 147 | echo "'nfdc route list' is:" >> $testLog |
| 148 | nfdc route list >> $testLog |
| 149 | clean_up |
| 150 | exit 2 |
| 151 | fi |
| 152 | fi |
| 153 | } |
| 154 | |
| 155 | # check for the existence of a route for a given prefix with nexthop face ID and cost using |
| 156 | # `nfdc route show` |
| 157 | # param list: $1 - route prefix |
| 158 | # $2 - nexthop face ID |
| 159 | # $3 - route cost |
| 160 | # $4 - if set, check if route does not exist (optional) |
| 161 | check_nfdc_route_existence_show() { |
| 162 | local prefix=$1 |
| 163 | local nexthop=$2 |
| 164 | local cost=$3 |
| 165 | local noexist=false |
| 166 | if [[ $# -gt 3 ]]; then |
| 167 | noexist=true |
| 168 | fi |
| 169 | |
| 170 | local routeInfo=$(nfdc route show $prefix | grep "^prefix=$prefix nexthop=$nexthop origin=[a-zA-Z0-9]* cost=$cost flags=") |
| 171 | |
| 172 | if [[ $noexist == false ]]; then |
| 173 | if [[ -z $routeInfo ]]; then |
| 174 | echo "nfdc: Failed to find route to $prefix with nexthop $nexthop and cost $cost" >> $testLog |
| 175 | echo "'nfdc route list' is:" >> $testLog |
| 176 | nfdc route list >> $testLog |
| 177 | clean_up |
| 178 | exit 2 |
| 179 | fi |
| 180 | else |
| 181 | if [[ -n $routeInfo ]]; then |
| 182 | echo "nfdc: Failed to remove route to $prefix with nexthop" >> $testLog |
| 183 | echo "'nfdc route list' is:" >> $testLog |
| 184 | nfdc route list >> $testLog |
| 185 | clean_up |
| 186 | exit 2 |
| 187 | fi |
| 188 | fi |
| 189 | } |
| 190 | |
| 191 | # check for the existence of a given route for a given nexthop |
| 192 | # param list: $1 - route prefix |
| 193 | # $2 - nexthop face ID |
| 194 | # $3 - route cost |
| 195 | # $4 - if set, check if route does not exist (optional) |
| 196 | check_nfdc_nexthop_existence() { |
| 197 | local prefix=$1 |
| 198 | local faceId=$2 |
| 199 | local cost=$3 |
| 200 | local noexist=false |
| 201 | if [[ $# -gt 3 ]]; then |
| 202 | noexist=true |
| 203 | fi |
| 204 | |
| 205 | local nexthopInfo=$(nfdc fib list | grep "^ $prefix" | grep "faceid=$faceId (cost=$cost)") |
| 206 | |
| 207 | if [[ $noexist == false ]]; then |
| 208 | if [[ -z $nexthopInfo ]]; then |
| 209 | echo "nfdc: Failed to find route to $prefix via $faceId with cost $cost in FIB" >> $testLog |
| 210 | echo "'nfdc fib list' is:" >> $testLog |
| 211 | nfdc fib list >> $testLog |
| 212 | clean_up |
| 213 | exit 2 |
| 214 | fi |
| 215 | else |
| 216 | if [[ -n $nexthopInfo ]]; then |
| 217 | echo "nfdc: Failed to remove route to $prefix via $faceId with from FIB" >> $testLog |
| 218 | echo "'nfdc fib list' is:" >> $testLog |
| 219 | nfdc fib list >> $testLog |
| 220 | clean_up |
| 221 | exit 2 |
| 222 | fi |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 223 | fi |
Hila Ben Abraham | 799f78f | 2015-03-01 22:06:33 -0600 | [diff] [blame] | 224 | } |