integration-tests: remote prefix registration
Change-Id: Ia0e81879ed353307b325c2ed86b35d7b776b9994
refs: #2201
diff --git a/test_remote_register/B.sh b/test_remote_register/B.sh
new file mode 100755
index 0000000..d8b6cf5
--- /dev/null
+++ b/test_remote_register/B.sh
@@ -0,0 +1,149 @@
+#!/usr/bin/env bash
+
+defaultIdentity=
+hubIdentity='/remote-register-test/hub'
+nfdConf='hub.nfd.conf'
+systemNfdConf='/usr/local/etc/ndn/nfd.conf'
+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
+
+ LOG "Deleting the hub identity"
+ delete_identity "$hubIdentity"
+
+ LOG "Reset the default identity"
+ if [[ -n "$defaultIdentity" ]]; then
+ if [[ $(ndnsec-list | grep -c "$defaultIdentity$") -gt 0 ]]; then
+ ndnsec-set-default $defaultIdentity
+ fi
+ else
+ r=$(ndnsec-list)
+ if [[ -n "$r" ]]; then
+ r=`echo "$r" | tr "\n" "-"`
+ r=${r%%-*} && r=${r#*/} && r="/$r"
+ ndnsec-set-default $r
+ fi
+ fi
+}
+
+prepare_for_test() {
+ echo "Start test log on remote hub" >$testLog
+ echo "Start nfd log on remote hub" >$nfdLog
+
+ LOG "Create hub identity as the default identity"
+ defaultIdentity=$(ndnsec-get-default)
+ ndnsec-key-gen $hubIdentity | ndnsec-cert-install - >>$testLog 2>&1
+
+ 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
+
+ # 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.remote_register
+
+ kill_process nfd
+ LOG "start NFD"
+ sudo -b nohup nfd --config $nfdConf >>$nfdLog 2>&1 &
+ sleep 2
+
+ LOG "set autoreg prefix to ndn:/"
+ nfdc set-strategy ndn:/ ndn:/localhost/nfd/strategy/broadcast >>$testLog 2>&1
+ 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