blob: 5f1c4917433348d5bdf57bf62e0133bdb9f2c844 [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
38 outCounter=$(nfd-status | grep -iF 'faceid='$faceId' remote='$faceUri | grep -Po $counterType={[0-9]+ | sed 's/'$counterType'={//')
39
40
41 if [[ $outCounter -lt $threshold ]]; then
42 if [[ "out" = $counterType ]]; then
43 echo "nfd-status: out counter of face=$faceId is less than $threshold " >> $testLog
44 echo "nfd-status is:" >> $testLog
45 nfd-status >> $testLog
46 clean_up
47 fi
48 exit 2
49
50 fi
51
52}
53
54# check for the existence of the face
55# param list: $1 - face Id
56# $2 - face Uri
57check_nfd_status_face_existence() {
58 faceId=$1
59 faceUri=$2
60
61 # check for the existence of the face
62 # First, get the face line
63 # Second, extract the face id attached to the fetched line
64 face=$(nfd-status | grep -iF remote=$faceUri | grep -Po faceid=\[0-9\]+ | sed 's/faceid=//')
65
66 if [[ "none" != $faceId ]]; then
67 if [[ $face != $faceId ]]; then
68 echo "nfd-status: Failed to find face $faceId of $faceUri" >> $testLog
69 echo "nfd-status is:" >> $testLog
70 nfd-status >> $testLog
71 echo "-1"
72 else
73 echo $face
74 fi
75 else
76 echo $face
77 fi
78
79}
80
81
82# This function checks for the existence of a face and a fib entry
83# including nexthop records
84# param list: $1 - face Id
85# $2 - face Uri
86# $3 - prefix
87# $4 - cost
88check_nfd_status_correctness() {
89 faceId=$1
90 faceUri=$2
91 prefix=$3
92 cost=$4
93
94 face=$(check_nfd_status_face_existence $faceId $faceUri)
95 if [[ "-1" = $face ]]; then
96 clean_up
97 exit 2
98 fi
99
100 # check the existence of prefix FIB entry
101 fibEntry=$(nfd-status | grep $prefix)
102 if [[ -z "$fibEntry" ]]; then
103 echo "nfd-status: Failed to find $prefix in FIB table" >> $testLog
104 echo "nfd-status is:" >> $testLog
105 nfd-status >> $testLog
106 clean_up
107 exit 2
108 fi
109
110 # check the correctness of cost on nexthop records
111 fibEntryCost=$(echo $fibEntry | grep -Po 'faceid='$faceId'.\(cost=[0-9]+\)' | sed 's/faceid='$faceId' //' | sed 's/(cost=//' | sed 's/)//')
112
113 if [[ $cost != $fibEntryCost ]]; then
114 echo "nfd-status: nexthop records are incorrect, expected cost is $cost, cost in records $fibEntryCost" >> $testLog
115 echo "nfd-status is:" >> $testLog
116 nfd-status >> $testLog
117 clean_up
118 exit 2
119 fi
120}