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