blob: 585f2dce3ea4a542777813d08f871ce7a60ba4d9 [file] [log] [blame]
Yanbiao Lie00f7f02015-05-20 20:20:10 -07001#!/usr/bin/env bash
2
Yanbiao Lie00f7f02015-05-20 20:20:10 -07003nfdConf='hub.nfd.conf'
Yanbiao Li526b5642016-11-17 01:42:27 +08004systemNfdConf='/usr/local/etc/ndn/nfd.conf.sample'
Yanbiao Lie00f7f02015-05-20 20:20:10 -07005testLog='hub.test.log'
6nfdLog='hub.nfd.log'
7
8LOG() {
9 echo "[B] $1"
10 echo "[B] $1" >>$testLog
11}
12
13kill_process() {
14 # $1: name of process
15 if [[ $# -lt 1 ]]; then
16 echo "require process name"
17 exit 1
18 fi
19
20 if pgrep -x $1 > /dev/null; then
21 sudo -b killall -w "$1" >>$testLog 2>&1
22 fi
23}
24
25delete_identity() {
26 # $1: name of identity
27 if [[ $(ndnsec-list | grep -c "$1$") -gt 0 ]]; then
28 LOG " deleting identity $1!"
29 ndnsec-delete $1 >>$testLog 2>&1
30 else
31 LOG " identity $1 does not exist"
32 fi
33}
34
35clean_up() {
36 LOG "Killing NFD process!"
37 kill_process nfd
38 kill_process ndn-autoconfig-server
Yanbiao Lie00f7f02015-05-20 20:20:10 -070039}
40
41prepare_for_test() {
42 echo "Start test log on remote hub" >$testLog
43 echo "Start nfd log on remote hub" >$nfdLog
44
Yanbiao Lie00f7f02015-05-20 20:20:10 -070045 LOG "create nfd conf file with localhop_security section specified for test"
46 [[ ! -f $systemNfdConf ]] && LOG "can not find nfd config file" && exit 1
47
48 # copy the config file to the working directory
49 cp $systemNfdConf $nfdConf
50
Yanbiao Li7112c892016-01-24 15:48:10 -080051 # set UDP face timeout to 35 seconds
52 infoedit -f $nfdConf -s face_system.udp.idle_timeout -v 35
53
Yanbiao Lie00f7f02015-05-20 20:20:10 -070054 # insert a rule section to validate Interest
55 cat <<EOF | infoedit -f $nfdConf -a rib.localhop_security.rule
56id "NRD Prefix Registration Command Rule"
57for interest
58filter
59{
60 type name
61 regex ^[<localhop><localhost>]<nfd><rib>[<register><unregister>]<>$
62}
63checker
64{
65 type customized
66 sig-type rsa-sha256
67 key-locator
68 {
69 type name
70 regex ^[^<KEY>]*<KEY><>*[<ksk-.*>]<ID-CERT>$
71 }
72}
73EOF
74
75 #insert a rule section to validate Data
76 cat <<EOF | infoedit -f $nfdConf -a rib.localhop_security.rule
77id "NDN Testbed Hierarchy Rule"
78for data
79filter
80{
81 type name
82 regex ^[^<KEY>]*<KEY><>*[<ksk-.*>]<ID-CERT><>*$
83}
84checker
85{
86 type customized
87 sig-type rsa-sha256
88 key-locator
89 {
90 type name
91 regex ^[^<KEY>]*<KEY><>*[<ksk-.*>]<ID-CERT>$
92 }
93}
94EOF
95
96 #insert a trust-anchor section
97 cat <<EOF | infoedit -f $nfdConf -a rib.localhop_security.trust-anchor
98type file
99file-name anchor.cert
100EOF
101
102 #delete remote_register section
Yanbiao Li7112c892016-01-24 15:48:10 -0800103 infoedit -f $nfdConf -d rib.auto_prefix_propagate
Yanbiao Lie00f7f02015-05-20 20:20:10 -0700104
105 kill_process nfd
106 LOG "start NFD"
107 sudo -b nohup nfd --config $nfdConf >>$nfdLog 2>&1 &
108 sleep 2
109
Yanbiao Li7112c892016-01-24 15:48:10 -0800110 LOG "set multicast strategy for ndn:/"
Eric Newberry7745c1a2017-04-20 00:23:05 -0700111 nfdc strategy set / /localhost/nfd/strategy/multicast >>$testLog 2>&1
Yanbiao Li7112c892016-01-24 15:48:10 -0800112 LOG "set autoreg prefix to /Z"
Yanbiao Lie00f7f02015-05-20 20:20:10 -0700113 nfd-autoreg --prefix=/Z >> $testLog 2>&1 &
114}
115
116while getopts "a:cp" arg
117 do
118 case $arg in
119 c)
120 clean_up
121 ;;
122 p)
123 prepare_for_test
124 ;;
125 ?)
126 echo "unknown argument"
127 exit 1
128 ;;
129 esac
130done