blob: 4319e9fe883fc9284c7eee99e52176de3a432a7e [file] [log] [blame]
Hila Ben Abraham47583d12014-05-22 04:39:31 -05001#!/usr/bin/env bash
2NUM_OF_PINGS=10
3
4# clean up - kill nfd
5clean_up() {
6 r=$(ssh $CTRL_B "sudo killall nfd" 2>&1)
7 r=$(sudo killall nfd 2>&1)
Hila Ben Abraham47583d12014-05-22 04:39:31 -05008}
9
10start_nfd() {
11 # start nfd on localhost
Eric Newberry6fc88222015-06-19 10:43:24 -070012 sudo nfd &> $workdir/logs/$1/nfd.log &
Hila Ben Abraham47583d12014-05-22 04:39:31 -050013
14 # start nfd on hostB
Eric Newberry6fc88222015-06-19 10:43:24 -070015 ssh $CTRL_B "mkdir -p $workdir/logs/$1 ; sudo nfd &> $workdir/logs/$1/nfd.log &\
Hila Ben Abraham47583d12014-05-22 04:39:31 -050016 sleep 2"
17 sleep 2
18}
19
Hila Ben Abraham47583d12014-05-22 04:39:31 -050020
21check_nfd_status_counters() {
22 faceId=$1
23 faceUri=$2
24 counterType=$3
25 threshold=$4
26
Hila Ben Abraham799f78f2015-03-01 22:06:33 -060027 # wait for the refreshed output of nfd-status
28 sleep 2
29
Hila Ben Abraham47583d12014-05-22 04:39:31 -050030 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
49check_nfd_status_face_existence() {
50 faceId=$1
51 faceUri=$2
52
Hila Ben Abraham799f78f2015-03-01 22:06:33 -060053 # wait for the refreshed output of nfd-status
54 sleep 2
55
Hila Ben Abraham47583d12014-05-22 04:39:31 -050056 # 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
83check_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 Abraham799f78f2015-03-01 22:06:33 -060095 # wait for the refreshed output of nfd-status
96 sleep 2
97
Hila Ben Abraham47583d12014-05-22 04:39:31 -050098 # 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 Abraham799f78f2015-03-01 22:06:33 -0600118}