blob: 4784a31068240f023cc00e0a79c65c3d01ff1080 [file] [log] [blame]
Yanbiao Lie00f7f02015-05-20 20:20:10 -07001#!/usr/bin/env bash
2
3defaultIdentity=
Yanbiao Li7112c892016-01-24 15:48:10 -08004hubIdentity='/auto-prefix-propagate/hub'
Yanbiao Lie00f7f02015-05-20 20:20:10 -07005nfdConf='hub.nfd.conf'
6systemNfdConf='/usr/local/etc/ndn/nfd.conf'
7testLog='hub.test.log'
8nfdLog='hub.nfd.log'
9
10LOG() {
11 echo "[B] $1"
12 echo "[B] $1" >>$testLog
13}
14
15kill_process() {
16 # $1: name of process
17 if [[ $# -lt 1 ]]; then
18 echo "require process name"
19 exit 1
20 fi
21
22 if pgrep -x $1 > /dev/null; then
23 sudo -b killall -w "$1" >>$testLog 2>&1
24 fi
25}
26
27delete_identity() {
28 # $1: name of identity
29 if [[ $(ndnsec-list | grep -c "$1$") -gt 0 ]]; then
30 LOG " deleting identity $1!"
31 ndnsec-delete $1 >>$testLog 2>&1
32 else
33 LOG " identity $1 does not exist"
34 fi
35}
36
37clean_up() {
38 LOG "Killing NFD process!"
39 kill_process nfd
40 kill_process ndn-autoconfig-server
41
42 LOG "Deleting the hub identity"
43 delete_identity "$hubIdentity"
44
45 LOG "Reset the default identity"
46 if [[ -n "$defaultIdentity" ]]; then
47 if [[ $(ndnsec-list | grep -c "$defaultIdentity$") -gt 0 ]]; then
48 ndnsec-set-default $defaultIdentity
49 fi
50 else
51 r=$(ndnsec-list)
52 if [[ -n "$r" ]]; then
53 r=`echo "$r" | tr "\n" "-"`
54 r=${r%%-*} && r=${r#*/} && r="/$r"
55 ndnsec-set-default $r
56 fi
57 fi
58}
59
60prepare_for_test() {
61 echo "Start test log on remote hub" >$testLog
62 echo "Start nfd log on remote hub" >$nfdLog
63
64 LOG "Create hub identity as the default identity"
65 defaultIdentity=$(ndnsec-get-default)
66 ndnsec-key-gen $hubIdentity | ndnsec-cert-install - >>$testLog 2>&1
67
68 LOG "create nfd conf file with localhop_security section specified for test"
69 [[ ! -f $systemNfdConf ]] && LOG "can not find nfd config file" && exit 1
70
71 # copy the config file to the working directory
72 cp $systemNfdConf $nfdConf
73
Yanbiao Li7112c892016-01-24 15:48:10 -080074 # set UDP face timeout to 35 seconds
75 infoedit -f $nfdConf -s face_system.udp.idle_timeout -v 35
76
Yanbiao Lie00f7f02015-05-20 20:20:10 -070077 # insert a rule section to validate Interest
78 cat <<EOF | infoedit -f $nfdConf -a rib.localhop_security.rule
79id "NRD Prefix Registration Command Rule"
80for interest
81filter
82{
83 type name
84 regex ^[<localhop><localhost>]<nfd><rib>[<register><unregister>]<>$
85}
86checker
87{
88 type customized
89 sig-type rsa-sha256
90 key-locator
91 {
92 type name
93 regex ^[^<KEY>]*<KEY><>*[<ksk-.*>]<ID-CERT>$
94 }
95}
96EOF
97
98 #insert a rule section to validate Data
99 cat <<EOF | infoedit -f $nfdConf -a rib.localhop_security.rule
100id "NDN Testbed Hierarchy Rule"
101for data
102filter
103{
104 type name
105 regex ^[^<KEY>]*<KEY><>*[<ksk-.*>]<ID-CERT><>*$
106}
107checker
108{
109 type customized
110 sig-type rsa-sha256
111 key-locator
112 {
113 type name
114 regex ^[^<KEY>]*<KEY><>*[<ksk-.*>]<ID-CERT>$
115 }
116}
117EOF
118
119 #insert a trust-anchor section
120 cat <<EOF | infoedit -f $nfdConf -a rib.localhop_security.trust-anchor
121type file
122file-name anchor.cert
123EOF
124
125 #delete remote_register section
Yanbiao Li7112c892016-01-24 15:48:10 -0800126 infoedit -f $nfdConf -d rib.auto_prefix_propagate
Yanbiao Lie00f7f02015-05-20 20:20:10 -0700127
128 kill_process nfd
129 LOG "start NFD"
130 sudo -b nohup nfd --config $nfdConf >>$nfdLog 2>&1 &
131 sleep 2
132
Yanbiao Li7112c892016-01-24 15:48:10 -0800133 LOG "set multicast strategy for ndn:/"
134 nfdc set-strategy ndn:/ ndn:/localhost/nfd/strategy/multicast >>$testLog 2>&1
135 LOG "set autoreg prefix to /Z"
Yanbiao Lie00f7f02015-05-20 20:20:10 -0700136 nfd-autoreg --prefix=/Z >> $testLog 2>&1 &
137}
138
139while getopts "a:cp" arg
140 do
141 case $arg in
142 c)
143 clean_up
144 ;;
145 p)
146 prepare_for_test
147 ;;
148 ?)
149 echo "unknown argument"
150 exit 1
151 ;;
152 esac
153done