blob: 9ad43b5319d132b483a4e61fb548313228a41fdf [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)
8
9 if [[ $testCase == 'C' ]]; then
10 r=$(sudo killall nrd 2>&1)
11 fi
12}
13
14start_nfd() {
15 # start nfd on localhost
16 sudo nfd &> $workdir/logs/nfd.log &
17
18 # start nfd on hostB
19 ssh $CTRL_B "mkdir -p $workdir/logs ; sudo nfd &> $workdir/logs/nfd.log &\
20 sleep 2"
21 sleep 2
22}
23
24start_nrd() {
25 # start nfd on localhost
26 sudo nrd &> $workdir/logs/nrd.log &
27
28 sleep 2
29}
30
31
32check_nfd_status_counters() {
33 faceId=$1
34 faceUri=$2
35 counterType=$3
36 threshold=$4
37
Hila Ben Abraham799f78f2015-03-01 22:06:33 -060038 # wait for the refreshed output of nfd-status
39 sleep 2
40
Hila Ben Abraham47583d12014-05-22 04:39:31 -050041 outCounter=$(nfd-status | grep -iF 'faceid='$faceId' remote='$faceUri | grep -Po $counterType={[0-9]+ | sed 's/'$counterType'={//')
42
43
44 if [[ $outCounter -lt $threshold ]]; then
45 if [[ "out" = $counterType ]]; then
46 echo "nfd-status: out counter of face=$faceId is less than $threshold " >> $testLog
47 echo "nfd-status is:" >> $testLog
48 nfd-status >> $testLog
49 clean_up
50 fi
51 exit 2
52
53 fi
54
55}
56
57# check for the existence of the face
58# param list: $1 - face Id
59# $2 - face Uri
60check_nfd_status_face_existence() {
61 faceId=$1
62 faceUri=$2
63
Hila Ben Abraham799f78f2015-03-01 22:06:33 -060064 # wait for the refreshed output of nfd-status
65 sleep 2
66
Hila Ben Abraham47583d12014-05-22 04:39:31 -050067 # check for the existence of the face
68 # First, get the face line
69 # Second, extract the face id attached to the fetched line
70 face=$(nfd-status | grep -iF remote=$faceUri | grep -Po faceid=\[0-9\]+ | sed 's/faceid=//')
71
72 if [[ "none" != $faceId ]]; then
73 if [[ $face != $faceId ]]; then
74 echo "nfd-status: Failed to find face $faceId of $faceUri" >> $testLog
75 echo "nfd-status is:" >> $testLog
76 nfd-status >> $testLog
77 echo "-1"
78 else
79 echo $face
80 fi
81 else
82 echo $face
83 fi
84
85}
86
87
88# This function checks for the existence of a face and a fib entry
89# including nexthop records
90# param list: $1 - face Id
91# $2 - face Uri
92# $3 - prefix
93# $4 - cost
94check_nfd_status_correctness() {
95 faceId=$1
96 faceUri=$2
97 prefix=$3
98 cost=$4
99
100 face=$(check_nfd_status_face_existence $faceId $faceUri)
101 if [[ "-1" = $face ]]; then
102 clean_up
103 exit 2
104 fi
105
Hila Ben Abraham799f78f2015-03-01 22:06:33 -0600106 # wait for the refreshed output of nfd-status
107 sleep 2
108
Hila Ben Abraham47583d12014-05-22 04:39:31 -0500109 # check the existence of prefix FIB entry
110 fibEntry=$(nfd-status | grep $prefix)
111 if [[ -z "$fibEntry" ]]; then
112 echo "nfd-status: Failed to find $prefix in FIB table" >> $testLog
113 echo "nfd-status is:" >> $testLog
114 nfd-status >> $testLog
115 clean_up
116 exit 2
117 fi
118
119 # check the correctness of cost on nexthop records
120 fibEntryCost=$(echo $fibEntry | grep -Po 'faceid='$faceId'.\(cost=[0-9]+\)' | sed 's/faceid='$faceId' //' | sed 's/(cost=//' | sed 's/)//')
121
122 if [[ $cost != $fibEntryCost ]]; then
123 echo "nfd-status: nexthop records are incorrect, expected cost is $cost, cost in records $fibEntryCost" >> $testLog
124 echo "nfd-status is:" >> $testLog
125 nfd-status >> $testLog
126 clean_up
127 exit 2
128 fi
Hila Ben Abraham799f78f2015-03-01 22:06:33 -0600129}