Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | NUM_OF_PINGS=10 |
| 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 | 6fc8822 | 2015-06-19 10:43:24 -0700 | [diff] [blame^] | 12 | sudo nfd &> $workdir/logs/$1/nfd.log & |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 13 | |
| 14 | # start nfd on hostB |
Eric Newberry | 6fc8822 | 2015-06-19 10:43:24 -0700 | [diff] [blame^] | 15 | ssh $CTRL_B "mkdir -p $workdir/logs/$1 ; sudo nfd &> $workdir/logs/$1/nfd.log &\ |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 16 | sleep 2" |
| 17 | sleep 2 |
| 18 | } |
| 19 | |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 20 | |
| 21 | check_nfd_status_counters() { |
| 22 | faceId=$1 |
| 23 | faceUri=$2 |
| 24 | counterType=$3 |
| 25 | threshold=$4 |
| 26 | |
Hila Ben Abraham | 799f78f | 2015-03-01 22:06:33 -0600 | [diff] [blame] | 27 | # wait for the refreshed output of nfd-status |
| 28 | sleep 2 |
| 29 | |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 30 | outCounter=$(nfd-status | grep -iF 'faceid='$faceId' remote='$faceUri | grep -Po $counterType={[0-9]+ | sed 's/'$counterType'={//') |
| 31 | |
| 32 | |
| 33 | if [[ $outCounter -lt $threshold ]]; then |
| 34 | if [[ "out" = $counterType ]]; then |
| 35 | echo "nfd-status: out counter of face=$faceId is less than $threshold " >> $testLog |
| 36 | echo "nfd-status is:" >> $testLog |
| 37 | nfd-status >> $testLog |
| 38 | clean_up |
| 39 | fi |
| 40 | exit 2 |
| 41 | |
| 42 | fi |
| 43 | |
| 44 | } |
| 45 | |
| 46 | # check for the existence of the face |
| 47 | # param list: $1 - face Id |
| 48 | # $2 - face Uri |
| 49 | check_nfd_status_face_existence() { |
| 50 | faceId=$1 |
| 51 | faceUri=$2 |
| 52 | |
Hila Ben Abraham | 799f78f | 2015-03-01 22:06:33 -0600 | [diff] [blame] | 53 | # wait for the refreshed output of nfd-status |
| 54 | sleep 2 |
| 55 | |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 56 | # check for the existence of the face |
| 57 | # First, get the face line |
| 58 | # Second, extract the face id attached to the fetched line |
| 59 | face=$(nfd-status | grep -iF remote=$faceUri | grep -Po faceid=\[0-9\]+ | sed 's/faceid=//') |
| 60 | |
| 61 | if [[ "none" != $faceId ]]; then |
| 62 | if [[ $face != $faceId ]]; then |
| 63 | echo "nfd-status: Failed to find face $faceId of $faceUri" >> $testLog |
| 64 | echo "nfd-status is:" >> $testLog |
| 65 | nfd-status >> $testLog |
| 66 | echo "-1" |
| 67 | else |
| 68 | echo $face |
| 69 | fi |
| 70 | else |
| 71 | echo $face |
| 72 | fi |
| 73 | |
| 74 | } |
| 75 | |
| 76 | |
| 77 | # This function checks for the existence of a face and a fib entry |
| 78 | # including nexthop records |
| 79 | # param list: $1 - face Id |
| 80 | # $2 - face Uri |
| 81 | # $3 - prefix |
| 82 | # $4 - cost |
| 83 | check_nfd_status_correctness() { |
| 84 | faceId=$1 |
| 85 | faceUri=$2 |
| 86 | prefix=$3 |
| 87 | cost=$4 |
| 88 | |
| 89 | face=$(check_nfd_status_face_existence $faceId $faceUri) |
| 90 | if [[ "-1" = $face ]]; then |
| 91 | clean_up |
| 92 | exit 2 |
| 93 | fi |
| 94 | |
Hila Ben Abraham | 799f78f | 2015-03-01 22:06:33 -0600 | [diff] [blame] | 95 | # wait for the refreshed output of nfd-status |
| 96 | sleep 2 |
| 97 | |
Hila Ben Abraham | 47583d1 | 2014-05-22 04:39:31 -0500 | [diff] [blame] | 98 | # check the existence of prefix FIB entry |
| 99 | fibEntry=$(nfd-status | grep $prefix) |
| 100 | if [[ -z "$fibEntry" ]]; then |
| 101 | echo "nfd-status: Failed to find $prefix in FIB table" >> $testLog |
| 102 | echo "nfd-status is:" >> $testLog |
| 103 | nfd-status >> $testLog |
| 104 | clean_up |
| 105 | exit 2 |
| 106 | fi |
| 107 | |
| 108 | # check the correctness of cost on nexthop records |
| 109 | fibEntryCost=$(echo $fibEntry | grep -Po 'faceid='$faceId'.\(cost=[0-9]+\)' | sed 's/faceid='$faceId' //' | sed 's/(cost=//' | sed 's/)//') |
| 110 | |
| 111 | if [[ $cost != $fibEntryCost ]]; then |
| 112 | echo "nfd-status: nexthop records are incorrect, expected cost is $cost, cost in records $fibEntryCost" >> $testLog |
| 113 | echo "nfd-status is:" >> $testLog |
| 114 | nfd-status >> $testLog |
| 115 | clean_up |
| 116 | exit 2 |
| 117 | fi |
Hila Ben Abraham | 799f78f | 2015-03-01 22:06:33 -0600 | [diff] [blame] | 118 | } |