Yanbiao Li | e00f7f0 | 2015-05-20 20:20:10 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
Yanbiao Li | e00f7f0 | 2015-05-20 20:20:10 -0700 | [diff] [blame] | 3 | nfdConf='hub.nfd.conf' |
Yanbiao Li | 526b564 | 2016-11-17 01:42:27 +0800 | [diff] [blame] | 4 | systemNfdConf='/usr/local/etc/ndn/nfd.conf.sample' |
Yanbiao Li | e00f7f0 | 2015-05-20 20:20:10 -0700 | [diff] [blame] | 5 | testLog='hub.test.log' |
| 6 | nfdLog='hub.nfd.log' |
| 7 | |
| 8 | LOG() { |
| 9 | echo "[B] $1" |
| 10 | echo "[B] $1" >>$testLog |
| 11 | } |
| 12 | |
| 13 | kill_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 | |
| 25 | delete_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 | |
| 35 | clean_up() { |
| 36 | LOG "Killing NFD process!" |
| 37 | kill_process nfd |
| 38 | kill_process ndn-autoconfig-server |
Yanbiao Li | e00f7f0 | 2015-05-20 20:20:10 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | prepare_for_test() { |
| 42 | echo "Start test log on remote hub" >$testLog |
| 43 | echo "Start nfd log on remote hub" >$nfdLog |
| 44 | |
Yanbiao Li | e00f7f0 | 2015-05-20 20:20:10 -0700 | [diff] [blame] | 45 | 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 Li | 7112c89 | 2016-01-24 15:48:10 -0800 | [diff] [blame] | 51 | # set UDP face timeout to 35 seconds |
| 52 | infoedit -f $nfdConf -s face_system.udp.idle_timeout -v 35 |
| 53 | |
Yanbiao Li | e00f7f0 | 2015-05-20 20:20:10 -0700 | [diff] [blame] | 54 | # insert a rule section to validate Interest |
| 55 | cat <<EOF | infoedit -f $nfdConf -a rib.localhop_security.rule |
| 56 | id "NRD Prefix Registration Command Rule" |
| 57 | for interest |
| 58 | filter |
| 59 | { |
| 60 | type name |
| 61 | regex ^[<localhop><localhost>]<nfd><rib>[<register><unregister>]<>$ |
| 62 | } |
| 63 | checker |
| 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 | } |
| 73 | EOF |
| 74 | |
| 75 | #insert a rule section to validate Data |
| 76 | cat <<EOF | infoedit -f $nfdConf -a rib.localhop_security.rule |
| 77 | id "NDN Testbed Hierarchy Rule" |
| 78 | for data |
| 79 | filter |
| 80 | { |
| 81 | type name |
| 82 | regex ^[^<KEY>]*<KEY><>*[<ksk-.*>]<ID-CERT><>*$ |
| 83 | } |
| 84 | checker |
| 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 | } |
| 94 | EOF |
| 95 | |
| 96 | #insert a trust-anchor section |
| 97 | cat <<EOF | infoedit -f $nfdConf -a rib.localhop_security.trust-anchor |
| 98 | type file |
| 99 | file-name anchor.cert |
| 100 | EOF |
| 101 | |
| 102 | #delete remote_register section |
Yanbiao Li | 7112c89 | 2016-01-24 15:48:10 -0800 | [diff] [blame] | 103 | infoedit -f $nfdConf -d rib.auto_prefix_propagate |
Yanbiao Li | e00f7f0 | 2015-05-20 20:20:10 -0700 | [diff] [blame] | 104 | |
| 105 | kill_process nfd |
| 106 | LOG "start NFD" |
| 107 | sudo -b nohup nfd --config $nfdConf >>$nfdLog 2>&1 & |
| 108 | sleep 2 |
| 109 | |
Yanbiao Li | 7112c89 | 2016-01-24 15:48:10 -0800 | [diff] [blame] | 110 | LOG "set multicast strategy for ndn:/" |
Eric Newberry | 7745c1a | 2017-04-20 00:23:05 -0700 | [diff] [blame^] | 111 | nfdc strategy set / /localhost/nfd/strategy/multicast >>$testLog 2>&1 |
Yanbiao Li | 7112c89 | 2016-01-24 15:48:10 -0800 | [diff] [blame] | 112 | LOG "set autoreg prefix to /Z" |
Yanbiao Li | e00f7f0 | 2015-05-20 20:20:10 -0700 | [diff] [blame] | 113 | nfd-autoreg --prefix=/Z >> $testLog 2>&1 & |
| 114 | } |
| 115 | |
| 116 | while 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 |
| 130 | done |