Yi Huang | 2d9ec55 | 2014-04-26 03:41:26 -0700 | [diff] [blame^] | 1 | #!/usr/bin/env bash |
| 2 | clean_up() { |
| 3 | r=$(sudo killall nfd 2>&1) |
| 4 | r=$(mv ~/.ndn/client.conf.bk ~/.ndn/client.conf 2>&1) |
| 5 | } |
| 6 | mkdir -p logs |
| 7 | |
| 8 | # backup client.conf |
| 9 | echo "backup client.conf" |
| 10 | cp ~/.ndn/client.conf ~/.ndn/client.conf.bk |
| 11 | sed -i 's/^protocol=.*$/protocol=nrd-0.1/g' ~/.ndn/client.conf |
| 12 | |
| 13 | # start nfd and nrd |
| 14 | echo "starting nfd and nrd..." |
| 15 | sudo nfd > logs/nfd.log 2>&1 & |
| 16 | sleep 3 |
| 17 | nrd &> logs/nrd.log & |
| 18 | sleep 10 |
| 19 | |
| 20 | # check fib before server starts |
| 21 | echo "checking fib before server starts..." |
| 22 | fib=$(nfd-status -b) |
| 23 | res=$(echo $fib | grep '/test-nrd/A' | wc -l) |
| 24 | if [[ $res -ne 0 ]] |
| 25 | then |
| 26 | echo "the name '/test-nrd/A' already exists" |
| 27 | clean_up |
| 28 | exit 1 |
| 29 | fi |
| 30 | res=$(echo $fib | grep '/test-nrd/B' | wc -l) |
| 31 | if [[ $res -ne 0 ]] |
| 32 | then |
| 33 | echo "the name '/test-nrd/B' already exists" |
| 34 | exit 2 |
| 35 | fi |
| 36 | |
| 37 | # start server |
| 38 | echo "starting server..." |
| 39 | ndn-traffic-server NDNTrafficServer.conf > logs/server.log 2>&1 & |
| 40 | sleep 3 |
| 41 | |
| 42 | # check fib after server starts |
| 43 | echo "checking fib after server starts..." |
| 44 | fib=$(nfd-status -b) |
| 45 | res=$(echo $fib | grep '/test-nrd/A' | wc -l) |
| 46 | if [[ $res -ne 1 ]] |
| 47 | then |
| 48 | echo "the name '/test-nrd/A' does not exists after ndn-traffic-server starts" |
| 49 | clean_up |
| 50 | exit 3 |
| 51 | fi |
| 52 | res=$(echo $fib | grep '/test-nrd/B' | wc -l) |
| 53 | if [[ $res -ne 1 ]] |
| 54 | then |
| 55 | echo "the name '/test-nrd/B' does not exists after ndn-traffic-server starts" |
| 56 | clean_up |
| 57 | exit 4 |
| 58 | fi |
| 59 | |
| 60 | # stop ndn-traffic-server |
| 61 | echo "stopping ndn-traffic-server..." |
| 62 | sudo killall ndn-traffic-server |
| 63 | sleep 3 |
| 64 | |
| 65 | # check fib after server stops |
| 66 | echo "checking fib after server stops..." |
| 67 | fib=$(nfd-status -b) |
| 68 | res=$(echo $fib | grep '/test-nrd/A' | wc -l) |
| 69 | if [[ $res -ne 0 ]] |
| 70 | then |
| 71 | echo "the name '/test-nrd/A' still exists after ndn-traffic-server exit" |
| 72 | clean_up |
| 73 | exit 5 |
| 74 | fi |
| 75 | res=$(echo $fib | grep '/test-nrd/B' | wc -l) |
| 76 | if [[ $res -ne 0 ]] |
| 77 | then |
| 78 | echo "the name '/test-nrd/B' still exists after ndn-traffic-server exit" |
| 79 | clean_up |
| 80 | exit 6 |
| 81 | fi |
| 82 | clean_up |
| 83 | echo "nrd test PASSED" |