blob: 1f3a3138e4e01449d6b309910a3ae9182f050ebc [file] [log] [blame]
Hila Ben Abrahame8c22e92016-10-20 14:30:32 -05001#!/usr/bin/env bash
2source ../multi-host.conf
3workDir=$(pwd)
4logDir=$workDir/logs
5testLogA=$logDir/nack-scenario-A.log
6testLogB=$logDir/nack-scenario-B.log
7testLogC=$logDir/nack-scenario-C.log
8testLogD=$logDir/nack-scenario-D.log
9mkdir -p $workDir/logs
10
11clean_up() {
12
13 dataB=$1
14 dataC=$2
15 echo "killing nfd on B, C and D..."
16 ssh $CTRL_B "sudo killall nfd >> $testLogB 2>&1 &\
17 sudo /sbin/tc qdisc del dev $dataB root"
18 ssh $CTRL_C "sudo killall nfd >> $testLogC 2>&1 &\
19 sudo /sbin/tc qdisc del dev $dataC root"
20 ssh $CTRL_D "sudo killall nfd >> $testLogD 2>&1"
21
22 sudo killall nfd 2>&1
23 sleep 2
24}
25
26echo "Starting nfd on host A" > $testLogA
27
28# start nfd on localhost (A) and set best-route strategy
29nfd-start &> $logDir/nfdA.log
30sleep 2
31nfdc set-strategy / /localhost/nfd/strategy/best-route >> $testLogA
32
33echo "Configure host B..."
34# start nfd on hostB and set best-route-v1
35ssh $CTRL_B "mkdir -p $logDir ; nfd-start &> $logDir/nfdB.log &\
36 sleep 2 ; echo 'Starting nfd on host B' > $testLogB &\
37 nfdc set-strategy / /localhost/nfd/strategy/best-route/%FD%01 >> $testLogB"
38
39echo "Configure host C..."
40# start nfd on hostC and set best-route strategy
41ssh $CTRL_C "mkdir -p $logDir ; nfd-start &> $logDir/nfdC.log &\
42 sleep 2 ; echo 'Starting nfd on host C' > $testLogC &\
43 nfdc set-strategy / /localhost/nfd/strategy/best-route >> $testLogC"
44
45echo "Configure host D..."
46# start nfd on hostD and set best-route strategy
47ssh $CTRL_D "mkdir -p $logDir ; nfd-start &> $logDir/nfdD.log &\
48 sleep 2 ; echo 'Starting nfd on host D' > $testLogD &\
49 nfdc set-strategy / /localhost/nfd/strategy/best-route >> $testLogD"
50
51# A: create a route for prefix ndn:/P toward B and C,
52# where the cost toward B (10) is lower than the cost toward C(20)
53nfdc register -c 10 ndn:/P udp4://$IP4_B1:6363 >> $testLogA
54nfdc register -c 20 ndn:/P udp4://$IP4_C1:6363 >> $testLogA
55
56# D: create a route for prefix ndn:/P toward A
57ssh $CTRL_D "echo 'creating a route for namespace ndn:/P toward A' >> $testLogD &\
58 nfdc register -c 20 ndn:/P udp4://$IP4_A2:6363 >> $testLogD &"
59
60echo "Start test 1..."
61# D: express an Interest for ndn:/P/1, no retransmissions, wait 8000ms
62ssh $CTRL_D "echo 'express an Interest for ndn:/P/1' >> $testLogD &\
63 test-nack-consumer -p ndn:/P/1 -w 8000 > $logDir/test1.log"
64
65scp $CTRL_D:$logDir/test1.log $logDir/test1.log
66
67echo "Analyzing result of test 1..."
68received=$(tail -n 1 $logDir/test1.log | awk '{print $1}')
69if [[ "$received" == "NACK" ]]
70then
71 echo "FAIL: A returned unexpected Nack while Nack is not expected if not all &\
72 upstreams return Nack. The test doesn't retransmit the Interest, and &\
73 therefore A didn't try all possible upstreams to return Nack from all. &\
74 Check test1 log for details."
75 clean_up
76exit 1
77fi
78
79echo "Start test 2..."
80# D: express an Interest for ndn:/P/2, retransmit with new nonce, wait 8000ms
81ssh $CTRL_D "echo 'express an Interest for ndn:/P/2' >> $testLogD &\
82 test-nack-consumer -p ndn:/P/2 -r 2000 -w 8000 > $logDir/test2.log"
83
84scp $CTRL_D:$logDir/test2.log $logDir/test2.log
85
86echo "Analyzing result of test 2..."
87received=$(tail -n 1 $logDir/test2.log | awk '{print $1}')
88if [[ "$received" == "NACK" ]]
89then
90echo "FAIL: A returned unexpected Nack. Nack is not expected when one or &\
91 upstreams time out, even if some upstreams return Nack. &\
92 Check test2 log for details."
93clean_up
94exit 1
95fi
96
97echo "Setup test 3..."
98# get data interface of host B
99dataB=$(ssh $CTRL_B "netstat -ie | grep -B1 $IP4_B1 | head -n1" | awk '{print $1}')
100
101# B: configure best-route strategy and get the set link delay to 500 ms
102ssh $CTRL_B "nfdc set-strategy / /localhost/nfd/strategy/best-route >> $testLogB &\
103 sudo /sbin/tc qdisc add dev $dataB root netem delay 500ms >> $testLogB "
104
105# get data interface of host C
106dataC=$(ssh $CTRL_C "netstat -ie | grep -B1 $IP4_C1 | head -n1" | awk '{print $1}')
107
108# B: configure link delay to 500 ms
109ssh $CTRL_C "sudo /sbin/tc qdisc add dev $dataC root netem delay 500ms >> $testLogC"
110
111echo "Start test 3..."
112# D: express an Interest for ndn:/P/3, retransmit with new nonce after 200ms, wait 3000ms
113ssh $CTRL_D "echo 'express an Interest for ndn:/P/3' >> $testLogD &\
114 test-nack-consumer -p ndn:/P/3 -r 200 -w 3000 > $logDir/test3.log"
115
116scp $CTRL_D:$logDir/test3.log $logDir/test3.log
117
118echo "Analyzing result of test 3..."
119reason=$(grep NACK $logDir/test3.log | awk '{print $NF}')
120NACK_count=$(grep NACK $logDir/test3.log | wc -l)
121
122if [ $NACK_count -ne 1 ] || [[ "$reason" != "NoRoute" ]]
123then
124 echo "FAIL: A should return exactly one Nack after both upstreams have returned Nack. &\
125 Reason should be 'NoRoute'. Test returned $NACK_count Nacks, with reason $reason. &\
126 Check test3 log for more details."
127 clean_up $dataB $dataC
128 exit 1
129fi
130
131echo "Setup test 4..."
132
133# B: configure link delay to 1000 ms
134ssh $CTRL_B "nfdc set-strategy / /localhost/nfd/strategy/best-route >> $testLogB&\
135 sudo /sbin/tc qdisc change dev $dataB root netem delay 1000ms >> $testLogB"
136
137# D: express an Interest for ndn:/P/4, retransmit with new nonce after 200ms, wait 3000ms
138ssh $CTRL_D "echo 'express an Interest for ndn:/P/4' >> $testLogD &\
139 test-nack-consumer -p ndn:/P/4 -r 200 -w 3000 > $logDir/test4.log"
140
141scp $CTRL_D:$logDir/test4.log $logDir/test4.log
142
143echo "Analyzing result of test 4"
144reason=$(grep NACK $logDir/test4.log | awk '{print $NF}')
145NACK_count=$(grep NACK $logDir/test4.log | wc -l)
146nonce2=$(grep "Sending Interest 2:" $logDir/test4.log | awk '{print $NF}')
147NACK_nonce=$(grep NACK $logDir/test4.log | awk '{for(i=1;i<=NF;i++){if($i~/^Nonce/){print $(i+1)}}}'
148)
149
150if [ $NACK_count -ne 1 ] || [[ "$reason" != "NoRoute" ]] || [ "$NACK_nonce" -ne "$nonce2" ]
151then
152 echo "FAIL: A should return exactly one Nack that should carry the latest incoming Nonce \
153 from downstream. Reason should be 'NoRoute'. Test returned $NACK_count Nacks, with nonce &\
154 $NACK_nonce and reason $reason. Check test4 log for test details."
155 clean_up $dataB $dataC
156exit 1
157fi
158
159# cleanup
160clean_up $dataB $dataC
161echo "Test passed successfully"
162exit 0