Yanbiao Li | e00f7f0 | 2015-05-20 20:20:10 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | defaultIdentity= |
Yanbiao Li | 7112c89 | 2016-01-24 15:48:10 -0800 | [diff] [blame^] | 4 | hubIdentity='/auto-prefix-propagate/hub' |
Yanbiao Li | e00f7f0 | 2015-05-20 20:20:10 -0700 | [diff] [blame] | 5 | nfdConf='hub.nfd.conf' |
| 6 | systemNfdConf='/usr/local/etc/ndn/nfd.conf' |
| 7 | testLog='hub.test.log' |
| 8 | nfdLog='hub.nfd.log' |
| 9 | |
| 10 | LOG() { |
| 11 | echo "[B] $1" |
| 12 | echo "[B] $1" >>$testLog |
| 13 | } |
| 14 | |
| 15 | kill_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 | |
| 27 | delete_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 | |
| 37 | clean_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 | |
| 60 | prepare_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 Li | 7112c89 | 2016-01-24 15:48:10 -0800 | [diff] [blame^] | 74 | # set UDP face timeout to 35 seconds |
| 75 | infoedit -f $nfdConf -s face_system.udp.idle_timeout -v 35 |
| 76 | |
Yanbiao Li | e00f7f0 | 2015-05-20 20:20:10 -0700 | [diff] [blame] | 77 | # insert a rule section to validate Interest |
| 78 | cat <<EOF | infoedit -f $nfdConf -a rib.localhop_security.rule |
| 79 | id "NRD Prefix Registration Command Rule" |
| 80 | for interest |
| 81 | filter |
| 82 | { |
| 83 | type name |
| 84 | regex ^[<localhop><localhost>]<nfd><rib>[<register><unregister>]<>$ |
| 85 | } |
| 86 | checker |
| 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 | } |
| 96 | EOF |
| 97 | |
| 98 | #insert a rule section to validate Data |
| 99 | cat <<EOF | infoedit -f $nfdConf -a rib.localhop_security.rule |
| 100 | id "NDN Testbed Hierarchy Rule" |
| 101 | for data |
| 102 | filter |
| 103 | { |
| 104 | type name |
| 105 | regex ^[^<KEY>]*<KEY><>*[<ksk-.*>]<ID-CERT><>*$ |
| 106 | } |
| 107 | checker |
| 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 | } |
| 117 | EOF |
| 118 | |
| 119 | #insert a trust-anchor section |
| 120 | cat <<EOF | infoedit -f $nfdConf -a rib.localhop_security.trust-anchor |
| 121 | type file |
| 122 | file-name anchor.cert |
| 123 | EOF |
| 124 | |
| 125 | #delete remote_register section |
Yanbiao Li | 7112c89 | 2016-01-24 15:48:10 -0800 | [diff] [blame^] | 126 | infoedit -f $nfdConf -d rib.auto_prefix_propagate |
Yanbiao Li | e00f7f0 | 2015-05-20 20:20:10 -0700 | [diff] [blame] | 127 | |
| 128 | kill_process nfd |
| 129 | LOG "start NFD" |
| 130 | sudo -b nohup nfd --config $nfdConf >>$nfdLog 2>&1 & |
| 131 | sleep 2 |
| 132 | |
Yanbiao Li | 7112c89 | 2016-01-24 15:48:10 -0800 | [diff] [blame^] | 133 | 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 Li | e00f7f0 | 2015-05-20 20:20:10 -0700 | [diff] [blame] | 136 | nfd-autoreg --prefix=/Z >> $testLog 2>&1 & |
| 137 | } |
| 138 | |
| 139 | while 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 |
| 153 | done |