blob: d8b6cf50670496e0faca52ff72125dba119595fd [file] [log] [blame]
Yanbiao Lie00f7f02015-05-20 20:20:10 -07001#!/usr/bin/env bash
2
3defaultIdentity=
4hubIdentity='/remote-register-test/hub'
5nfdConf='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
74 # insert a rule section to validate Interest
75 cat <<EOF | infoedit -f $nfdConf -a rib.localhop_security.rule
76id "NRD Prefix Registration Command Rule"
77for interest
78filter
79{
80 type name
81 regex ^[<localhop><localhost>]<nfd><rib>[<register><unregister>]<>$
82}
83checker
84{
85 type customized
86 sig-type rsa-sha256
87 key-locator
88 {
89 type name
90 regex ^[^<KEY>]*<KEY><>*[<ksk-.*>]<ID-CERT>$
91 }
92}
93EOF
94
95 #insert a rule section to validate Data
96 cat <<EOF | infoedit -f $nfdConf -a rib.localhop_security.rule
97id "NDN Testbed Hierarchy Rule"
98for data
99filter
100{
101 type name
102 regex ^[^<KEY>]*<KEY><>*[<ksk-.*>]<ID-CERT><>*$
103}
104checker
105{
106 type customized
107 sig-type rsa-sha256
108 key-locator
109 {
110 type name
111 regex ^[^<KEY>]*<KEY><>*[<ksk-.*>]<ID-CERT>$
112 }
113}
114EOF
115
116 #insert a trust-anchor section
117 cat <<EOF | infoedit -f $nfdConf -a rib.localhop_security.trust-anchor
118type file
119file-name anchor.cert
120EOF
121
122 #delete remote_register section
123 infoedit -f $nfdConf -d rib.remote_register
124
125 kill_process nfd
126 LOG "start NFD"
127 sudo -b nohup nfd --config $nfdConf >>$nfdLog 2>&1 &
128 sleep 2
129
130 LOG "set autoreg prefix to ndn:/"
131 nfdc set-strategy ndn:/ ndn:/localhost/nfd/strategy/broadcast >>$testLog 2>&1
132 nfd-autoreg --prefix=/Z >> $testLog 2>&1 &
133}
134
135while getopts "a:cp" arg
136 do
137 case $arg in
138 c)
139 clean_up
140 ;;
141 p)
142 prepare_for_test
143 ;;
144 ?)
145 echo "unknown argument"
146 exit 1
147 ;;
148 esac
149done