| #!/usr/bin/env bash |
| |
| nfdConf='hub.nfd.conf' |
| systemNfdConf='/usr/local/etc/ndn/nfd.conf.sample' |
| testLog='hub.test.log' |
| nfdLog='hub.nfd.log' |
| |
| LOG() { |
| echo "[B] $1" |
| echo "[B] $1" >>$testLog |
| } |
| |
| kill_process() { |
| # $1: name of process |
| if [[ $# -lt 1 ]]; then |
| echo "require process name" |
| exit 1 |
| fi |
| |
| if pgrep -x $1 > /dev/null; then |
| sudo -b killall -w "$1" >>$testLog 2>&1 |
| fi |
| } |
| |
| delete_identity() { |
| # $1: name of identity |
| if [[ $(ndnsec-list | grep -c "$1$") -gt 0 ]]; then |
| LOG " deleting identity $1!" |
| ndnsec-delete $1 >>$testLog 2>&1 |
| else |
| LOG " identity $1 does not exist" |
| fi |
| } |
| |
| clean_up() { |
| LOG "Killing NFD process!" |
| kill_process nfd |
| kill_process ndn-autoconfig-server |
| } |
| |
| prepare_for_test() { |
| echo "Start test log on remote hub" >$testLog |
| echo "Start nfd log on remote hub" >$nfdLog |
| |
| LOG "create nfd conf file with localhop_security section specified for test" |
| [[ ! -f $systemNfdConf ]] && LOG "can not find nfd config file" && exit 1 |
| |
| # copy the config file to the working directory |
| cp $systemNfdConf $nfdConf |
| |
| # set UDP face timeout to 35 seconds |
| infoedit -f $nfdConf -s face_system.udp.idle_timeout -v 35 |
| |
| # insert a rule section to validate Interest |
| cat <<EOF | infoedit -f $nfdConf -a rib.localhop_security.rule |
| id "NRD Prefix Registration Command Rule" |
| for interest |
| filter |
| { |
| type name |
| regex ^[<localhop><localhost>]<nfd><rib>[<register><unregister>]<>$ |
| } |
| checker |
| { |
| type customized |
| sig-type rsa-sha256 |
| key-locator |
| { |
| type name |
| regex ^[^<KEY>]*<KEY><>*[<ksk-.*>]<ID-CERT>$ |
| } |
| } |
| EOF |
| |
| #insert a rule section to validate Data |
| cat <<EOF | infoedit -f $nfdConf -a rib.localhop_security.rule |
| id "NDN Testbed Hierarchy Rule" |
| for data |
| filter |
| { |
| type name |
| regex ^[^<KEY>]*<KEY><>*[<ksk-.*>]<ID-CERT><>*$ |
| } |
| checker |
| { |
| type customized |
| sig-type rsa-sha256 |
| key-locator |
| { |
| type name |
| regex ^[^<KEY>]*<KEY><>*[<ksk-.*>]<ID-CERT>$ |
| } |
| } |
| EOF |
| |
| #insert a trust-anchor section |
| cat <<EOF | infoedit -f $nfdConf -a rib.localhop_security.trust-anchor |
| type file |
| file-name anchor.cert |
| EOF |
| |
| #delete remote_register section |
| infoedit -f $nfdConf -d rib.auto_prefix_propagate |
| |
| kill_process nfd |
| LOG "start NFD" |
| sudo -b nohup nfd --config $nfdConf >>$nfdLog 2>&1 & |
| sleep 2 |
| |
| LOG "set multicast strategy for ndn:/" |
| nfdc strategy set / /localhost/nfd/strategy/multicast >>$testLog 2>&1 |
| LOG "set autoreg prefix to /Z" |
| nfd-autoreg --prefix=/Z >> $testLog 2>&1 & |
| } |
| |
| while getopts "a:cp" arg |
| do |
| case $arg in |
| c) |
| clean_up |
| ;; |
| p) |
| prepare_for_test |
| ;; |
| ?) |
| echo "unknown argument" |
| exit 1 |
| ;; |
| esac |
| done |