Hila Ben Abraham | e8c22e9 | 2016-10-20 14:30:32 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | source ../multi-host.conf |
| 3 | workDir=$(pwd) |
| 4 | logDir=$workDir/logs |
| 5 | testLogA=$logDir/nack-scenario-A.log |
| 6 | testLogB=$logDir/nack-scenario-B.log |
| 7 | testLogC=$logDir/nack-scenario-C.log |
| 8 | testLogD=$logDir/nack-scenario-D.log |
| 9 | mkdir -p $workDir/logs |
| 10 | |
| 11 | clean_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 | |
| 26 | echo "Starting nfd on host A" > $testLogA |
| 27 | |
| 28 | # start nfd on localhost (A) and set best-route strategy |
| 29 | nfd-start &> $logDir/nfdA.log |
| 30 | sleep 2 |
| 31 | nfdc set-strategy / /localhost/nfd/strategy/best-route >> $testLogA |
| 32 | |
| 33 | echo "Configure host B..." |
| 34 | # start nfd on hostB and set best-route-v1 |
| 35 | ssh $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 | |
| 39 | echo "Configure host C..." |
| 40 | # start nfd on hostC and set best-route strategy |
| 41 | ssh $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 | |
| 45 | echo "Configure host D..." |
| 46 | # start nfd on hostD and set best-route strategy |
| 47 | ssh $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) |
| 53 | nfdc register -c 10 ndn:/P udp4://$IP4_B1:6363 >> $testLogA |
| 54 | nfdc register -c 20 ndn:/P udp4://$IP4_C1:6363 >> $testLogA |
| 55 | |
| 56 | # D: create a route for prefix ndn:/P toward A |
| 57 | ssh $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 | |
| 60 | echo "Start test 1..." |
| 61 | # D: express an Interest for ndn:/P/1, no retransmissions, wait 8000ms |
| 62 | ssh $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 | |
| 65 | scp $CTRL_D:$logDir/test1.log $logDir/test1.log |
| 66 | |
| 67 | echo "Analyzing result of test 1..." |
| 68 | received=$(tail -n 1 $logDir/test1.log | awk '{print $1}') |
| 69 | if [[ "$received" == "NACK" ]] |
| 70 | then |
| 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 |
| 76 | exit 1 |
| 77 | fi |
| 78 | |
| 79 | echo "Start test 2..." |
| 80 | # D: express an Interest for ndn:/P/2, retransmit with new nonce, wait 8000ms |
| 81 | ssh $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 | |
| 84 | scp $CTRL_D:$logDir/test2.log $logDir/test2.log |
| 85 | |
| 86 | echo "Analyzing result of test 2..." |
| 87 | received=$(tail -n 1 $logDir/test2.log | awk '{print $1}') |
| 88 | if [[ "$received" == "NACK" ]] |
| 89 | then |
| 90 | echo "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." |
| 93 | clean_up |
| 94 | exit 1 |
| 95 | fi |
| 96 | |
| 97 | echo "Setup test 3..." |
| 98 | # get data interface of host B |
| 99 | dataB=$(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 |
| 102 | ssh $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 |
| 106 | dataC=$(ssh $CTRL_C "netstat -ie | grep -B1 $IP4_C1 | head -n1" | awk '{print $1}') |
| 107 | |
| 108 | # B: configure link delay to 500 ms |
| 109 | ssh $CTRL_C "sudo /sbin/tc qdisc add dev $dataC root netem delay 500ms >> $testLogC" |
| 110 | |
| 111 | echo "Start test 3..." |
| 112 | # D: express an Interest for ndn:/P/3, retransmit with new nonce after 200ms, wait 3000ms |
| 113 | ssh $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 | |
| 116 | scp $CTRL_D:$logDir/test3.log $logDir/test3.log |
| 117 | |
| 118 | echo "Analyzing result of test 3..." |
| 119 | reason=$(grep NACK $logDir/test3.log | awk '{print $NF}') |
| 120 | NACK_count=$(grep NACK $logDir/test3.log | wc -l) |
| 121 | |
| 122 | if [ $NACK_count -ne 1 ] || [[ "$reason" != "NoRoute" ]] |
| 123 | then |
| 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 |
| 129 | fi |
| 130 | |
| 131 | echo "Setup test 4..." |
| 132 | |
| 133 | # B: configure link delay to 1000 ms |
| 134 | ssh $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 |
| 138 | ssh $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 | |
| 141 | scp $CTRL_D:$logDir/test4.log $logDir/test4.log |
| 142 | |
| 143 | echo "Analyzing result of test 4" |
| 144 | reason=$(grep NACK $logDir/test4.log | awk '{print $NF}') |
| 145 | NACK_count=$(grep NACK $logDir/test4.log | wc -l) |
| 146 | nonce2=$(grep "Sending Interest 2:" $logDir/test4.log | awk '{print $NF}') |
| 147 | NACK_nonce=$(grep NACK $logDir/test4.log | awk '{for(i=1;i<=NF;i++){if($i~/^Nonce/){print $(i+1)}}}' |
| 148 | ) |
| 149 | |
| 150 | if [ $NACK_count -ne 1 ] || [[ "$reason" != "NoRoute" ]] || [ "$NACK_nonce" -ne "$nonce2" ] |
| 151 | then |
| 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 |
| 156 | exit 1 |
| 157 | fi |
| 158 | |
| 159 | # cleanup |
| 160 | clean_up $dataB $dataC |
| 161 | echo "Test passed successfully" |
| 162 | exit 0 |