blob: fcfceacf0bd6506e3418721af51fa47b608494d1 [file] [log] [blame]
Hila Ben Abraham47583d12014-05-22 04:39:31 -05001#!/usr/bin/env bash
Eric Newberrybef49472017-05-08 22:49:05 -07002NUM_OF_PINGS=100
Hila Ben Abraham47583d12014-05-22 04:39:31 -05003
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 Newberrybef49472017-05-08 22:49:05 -070012 sudo nfd &> $workdir/logs/nfd.log &
Hila Ben Abraham47583d12014-05-22 04:39:31 -050013
14 # start nfd on hostB
Eric Newberrybef49472017-05-08 22:49:05 -070015 ssh $CTRL_B "mkdir -p $workdir/logs ; sudo nfd &> $workdir/logs/nfd.log & sleep 2"
Hila Ben Abraham47583d12014-05-22 04:39:31 -050016 sleep 2
17}
18
Eric Newberrybef49472017-05-08 22:49:05 -070019# 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
25check_nfdc_face_counters() {
26 local faceId=$1
27 local faceUri=$2
28 local counterType=$3
29 local threshold=$4
Hila Ben Abraham47583d12014-05-22 04:39:31 -050030
Hila Ben Abraham799f78f2015-03-01 22:06:33 -060031 # wait for the refreshed output of nfd-status
32 sleep 2
33
Eric Newberrybef49472017-05-08 22:49:05 -070034 local counter=$(nfdc face list | grep -iF "faceid=$faceId remote=$faceUri" | sed -E "s/.*${counterType}=\{([0-9]+)i.*/\1/")
Hila Ben Abraham47583d12014-05-22 04:39:31 -050035
Eric Newberrybef49472017-05-08 22:49:05 -070036 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 Abraham47583d12014-05-22 04:39:31 -050041 exit 2
Hila Ben Abraham47583d12014-05-22 04:39:31 -050042 fi
Hila Ben Abraham47583d12014-05-22 04:39:31 -050043}
44
Eric Newberrybef49472017-05-08 22:49:05 -070045# check for the existence of a face with the specified FaceId and URI
46# param list: $1 - face ID
47# $2 - face URI
48check_nfdc_face_existence() {
49 local faceId=$1
50 local faceUri=$2
Hila Ben Abraham47583d12014-05-22 04:39:31 -050051
Eric Newberrybef49472017-05-08 22:49:05 -070052 # wait for the refreshed output of nfdc
Hila Ben Abraham799f78f2015-03-01 22:06:33 -060053 sleep 2
54
Eric Newberrybef49472017-05-08 22:49:05 -070055 # check for the existence of the specified face
Hila Ben Abraham47583d12014-05-22 04:39:31 -050056 # First, get the face line
57 # Second, extract the face id attached to the fetched line
Eric Newberrybef49472017-05-08 22:49:05 -070058 local face=$(nfdc face list | grep -iF "remote=$faceUri" | sed -E "s/.*faceid=([0-9]+).*/\1/")
Hila Ben Abraham47583d12014-05-22 04:39:31 -050059
Eric Newberrybef49472017-05-08 22:49:05 -070060 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 Abraham47583d12014-05-22 04:39:31 -050065 else
66 echo $face
67 fi
Hila Ben Abraham47583d12014-05-22 04:39:31 -050068}
69
Eric Newberrybef49472017-05-08 22:49:05 -070070# 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
73check_nfdc_face_existence_show() {
74 local faceId=$1
75 local faceUri=$2
Hila Ben Abraham47583d12014-05-22 04:39:31 -050076
Eric Newberrybef49472017-05-08 22:49:05 -070077 # wait for the refreshed output of nfdc
Hila Ben Abraham799f78f2015-03-01 22:06:33 -060078 sleep 2
79
Eric Newberrybef49472017-05-08 22:49:05 -070080 # 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
98check_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)
125check_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 Abraham47583d12014-05-22 04:39:31 -0500132 fi
133
Eric Newberrybef49472017-05-08 22:49:05 -0700134 local routeInfo=$(nfdc route list | grep "^prefix=$prefix nexthop=$nexthop origin=[a-zA-Z0-9]* cost=$cost flags=")
Hila Ben Abraham47583d12014-05-22 04:39:31 -0500135
Eric Newberrybef49472017-05-08 22:49:05 -0700136 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)
161check_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)
196check_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 Abraham47583d12014-05-22 04:39:31 -0500223 fi
Hila Ben Abraham799f78f2015-03-01 22:06:33 -0600224}