| #!/usr/bin/env bash |
| NUM_OF_PINGS=100 |
| |
| # clean up - kill nfd |
| clean_up() { |
| r=$(ssh $CTRL_B "sudo killall nfd" 2>&1) |
| r=$(sudo killall nfd 2>&1) |
| } |
| |
| start_nfd() { |
| # start nfd on localhost |
| sudo nfd &> $workdir/logs/nfd.log & |
| |
| # start nfd on hostB |
| ssh $CTRL_B "mkdir -p $workdir/logs ; sudo nfd &> $workdir/logs/nfd.log & sleep 2" |
| sleep 2 |
| } |
| |
| # check whether a given face with the specified FaceId and URI has had at least a given number of |
| # incoming/outgoing Interests |
| # param list: $1 - face ID |
| # $2 - face URI |
| # $3 - counter type (in/out) |
| # $4 - minimum successful value of the counter |
| check_nfdc_face_counters() { |
| local faceId=$1 |
| local faceUri=$2 |
| local counterType=$3 |
| local threshold=$4 |
| |
| # wait for the refreshed output of nfd-status |
| sleep 2 |
| |
| local counter=$(nfdc face list | grep -iF "faceid=$faceId remote=$faceUri" | sed -E "s/.*${counterType}=\{([0-9]+)i.*/\1/") |
| |
| if [[ $counter -lt $threshold ]]; then |
| echo "nfdc: $counterType counter of face=$faceId is less than $threshold " >> $testLog |
| echo "'nfdc face list' is:" >> $testLog |
| nfdc face list >> $testLog |
| clean_up |
| exit 2 |
| fi |
| } |
| |
| # check for the existence of a face with the specified FaceId and URI |
| # param list: $1 - face ID |
| # $2 - face URI |
| check_nfdc_face_existence() { |
| local faceId=$1 |
| local faceUri=$2 |
| |
| # wait for the refreshed output of nfdc |
| sleep 2 |
| |
| # check for the existence of the specified face |
| # First, get the face line |
| # Second, extract the face id attached to the fetched line |
| local face=$(nfdc face list | grep -iF "remote=$faceUri" | sed -E "s/.*faceid=([0-9]+).*/\1/") |
| |
| if [[ $faceId != "none" && $face != $faceId ]]; then |
| echo "nfdc: Failed to find face $faceId to $faceUri" >> $testLog |
| echo "'nfdc face list' is:" >> $testLog |
| nfdc face list >> $testLog |
| echo "-1" |
| else |
| echo $face |
| fi |
| } |
| |
| # check for the existence of a face with the specified FaceId and URI using `nfdc face show` |
| # param list: $1 - face ID |
| # $2 - face URI |
| check_nfdc_face_existence_show() { |
| local faceId=$1 |
| local faceUri=$2 |
| |
| # wait for the refreshed output of nfdc |
| sleep 2 |
| |
| # check for the existence of the specified face |
| # Extract the remote URI |
| local actualUri=$(nfdc face show id $faceId | grep -iFo "remote=$faceUri" | sed 's/remote=//') |
| |
| if [[ "$actualUri" != "$faceUri" ]]; then |
| echo "nfdc: Failed to find face $faceId to $faceUri" >> $testLog |
| echo "'nfdc face show id $faceId' is:" >> $testLog |
| nfdc face show id $faceId >> $testLog |
| echo "-1" |
| else |
| echo $face |
| fi |
| } |
| |
| # check for the existence of a face with the specified FaceId and URI using `nfdc face list`, filtered |
| # for remote URI |
| # param list: $1 - face ID |
| # $2 - face URI |
| check_nfdc_face_existence_remote_uri() { |
| local faceId=$1 |
| local faceUri=$2 |
| |
| # wait for the refreshed output of nfdc |
| sleep 2 |
| |
| # check for the existence of the specified face |
| # First, get the face line |
| # Second, extract the face id attached to the fetched line |
| local face=$(nfdc face list remote $faceUri | grep -iF "remote=$faceUri" | grep -Po "faceid=[0-9]+" | sed 's/faceid=//') |
| |
| if [[ "none" != $faceId && $face != $faceId ]]; then |
| echo "nfdc: Failed to find face $faceId to $faceUri" >> $testLog |
| echo "'nfdc face list remote $faceUri' is:" >> $testLog |
| nfdc face list >> $testLog |
| echo "-1" |
| else |
| echo $face |
| fi |
| } |
| |
| # check for the existence of a route for a given prefix with nexthop face ID and cost |
| # param list: $1 - route prefix |
| # $2 - nexthop face ID |
| # $3 - route cost |
| # $4 - if set, check if route does not exist (optional) |
| check_nfdc_route_existence() { |
| local prefix=$1 |
| local nexthop=$2 |
| local cost=$3 |
| local noexist=false |
| if [[ $# -gt 3 ]]; then |
| noexist=true |
| fi |
| |
| local routeInfo=$(nfdc route list | grep "^prefix=$prefix nexthop=$nexthop origin=[a-zA-Z0-9]* cost=$cost flags=") |
| |
| if [[ $noexist == false ]]; then |
| if [[ -z $routeInfo ]]; then |
| echo "nfdc: Failed to find route to $prefix with nexthop $nexthop and cost $cost" >> $testLog |
| echo "'nfdc route list' is:" >> $testLog |
| nfdc route list >> $testLog |
| clean_up |
| exit 2 |
| fi |
| else |
| if [[ -n $routeInfo ]]; then |
| echo "nfdc: Failed to remove route to $prefix with nexthop" >> $testLog |
| echo "'nfdc route list' is:" >> $testLog |
| nfdc route list >> $testLog |
| clean_up |
| exit 2 |
| fi |
| fi |
| } |
| |
| # check for the existence of a route for a given prefix with nexthop face ID and cost using |
| # `nfdc route show` |
| # param list: $1 - route prefix |
| # $2 - nexthop face ID |
| # $3 - route cost |
| # $4 - if set, check if route does not exist (optional) |
| check_nfdc_route_existence_show() { |
| local prefix=$1 |
| local nexthop=$2 |
| local cost=$3 |
| local noexist=false |
| if [[ $# -gt 3 ]]; then |
| noexist=true |
| fi |
| |
| local routeInfo=$(nfdc route show $prefix | grep "^prefix=$prefix nexthop=$nexthop origin=[a-zA-Z0-9]* cost=$cost flags=") |
| |
| if [[ $noexist == false ]]; then |
| if [[ -z $routeInfo ]]; then |
| echo "nfdc: Failed to find route to $prefix with nexthop $nexthop and cost $cost" >> $testLog |
| echo "'nfdc route list' is:" >> $testLog |
| nfdc route list >> $testLog |
| clean_up |
| exit 2 |
| fi |
| else |
| if [[ -n $routeInfo ]]; then |
| echo "nfdc: Failed to remove route to $prefix with nexthop" >> $testLog |
| echo "'nfdc route list' is:" >> $testLog |
| nfdc route list >> $testLog |
| clean_up |
| exit 2 |
| fi |
| fi |
| } |
| |
| # check for the existence of a given route for a given nexthop |
| # param list: $1 - route prefix |
| # $2 - nexthop face ID |
| # $3 - route cost |
| # $4 - if set, check if route does not exist (optional) |
| check_nfdc_nexthop_existence() { |
| local prefix=$1 |
| local faceId=$2 |
| local cost=$3 |
| local noexist=false |
| if [[ $# -gt 3 ]]; then |
| noexist=true |
| fi |
| |
| local nexthopInfo=$(nfdc fib list | grep "^ $prefix" | grep "faceid=$faceId (cost=$cost)") |
| |
| if [[ $noexist == false ]]; then |
| if [[ -z $nexthopInfo ]]; then |
| echo "nfdc: Failed to find route to $prefix via $faceId with cost $cost in FIB" >> $testLog |
| echo "'nfdc fib list' is:" >> $testLog |
| nfdc fib list >> $testLog |
| clean_up |
| exit 2 |
| fi |
| else |
| if [[ -n $nexthopInfo ]]; then |
| echo "nfdc: Failed to remove route to $prefix via $faceId with from FIB" >> $testLog |
| echo "'nfdc fib list' is:" >> $testLog |
| nfdc fib list >> $testLog |
| clean_up |
| exit 2 |
| fi |
| fi |
| } |