modify param parsing in createNetCfg.sh and checkNetInit.sh to enable flexible configuration for ODTN network

Change-Id: I8e3902870a1bd952c39051dfd299981af31c834e
diff --git a/tools/test/scenarios/odtn/README.md b/tools/test/scenarios/odtn/README.md
index 8a6eae6..e0df1ca 100644
--- a/tools/test/scenarios/odtn/README.md
+++ b/tools/test/scenarios/odtn/README.md
@@ -1,7 +1,7 @@
 ## Description
 
 This directory contains several Shell scripts for ODTN project testing in STC environment.
-The normal steps of ODTN testing are listed:
+The normal steps of ODTN testing are listed (or see the wiki page: https://wiki.onosproject.org/display/ODTN/Cassini+with+STC):
 
 #### 1. `stc net-odtn-presmoke`
 This command completes preparation for testing, including latest onos image build, and onos/atomix cluster containers startup. Also, because of dynamic IP Address for containers, some related environment variables are stored in /tmp/odtn/OCvar.sh. All subsequent stc command should source this file as default environment. An example of this file is:
diff --git a/tools/test/scenarios/odtn/checkNetInit.sh b/tools/test/scenarios/odtn/checkNetInit.sh
index 792a8d7..25524bb 100755
--- a/tools/test/scenarios/odtn/checkNetInit.sh
+++ b/tools/test/scenarios/odtn/checkNetInit.sh
@@ -1,15 +1,22 @@
 #!/bin/bash
 
-# Two input parameters:
+# Three input parameters:
 # $1 - one of {device, port, link}, specify what needs to be checked.
 # $2 - IP address of ONOS instance.
+# $3 - Optional. absolute path of net summary json file. The default path is "/tmp/odtn/net-summary.json".
 
-line_num=`cat ~/emulator/net-summary.json | wc -l`
+summary="/tmp/odtn/net-summary.json"
+if [[ $# == 3 ]];then
+    summary=$3
+fi
+
+line_num=`cat $summary | wc -l`
 if [[ "$line_num" != "1" ]]; then
     echo "JSON file should have only 1 line."
     exit 1
 fi
-
+content=`cat $summary`
+echo -e "The content of the json file is :\n $content"
 # Extract specific value from returned json string under onos command "odtn-show-tapi-context"
 function get_json_value()
 {
@@ -22,7 +29,7 @@
     local num=$3
     fi
 
-    local value=$(echo "${json}" | awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'${key}'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p)
+    eval value=$(echo "${json}" | awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'${key}'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p)
 
     return ${value}
 }
@@ -30,7 +37,7 @@
 tried=0
 case "$1" in
     "device" )
-        get_json_value $( cat ~/emulator/net-summary.json) device_num
+        eval get_json_value '$content' device_num
         device_num=$?
         num_in_topo=`onos $2 devices | wc -l`
         num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<node>" | wc -l`
@@ -47,9 +54,9 @@
         done
         ;;
     "port" )
-        get_json_value $( cat ~/emulator/net-summary.json) port_num
+        eval get_json_value '$content' port_num
         port_num=$?
-        get_json_value $( cat ~/emulator/net-summary.json) device_num
+        eval get_json_value '$content' device_num
         device_num=$?
         num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<owned-node-edge-point>" | wc -l`
         num_in_topo=`onos $2 ports | wc -l`
@@ -68,7 +75,7 @@
             done
             ;;
     "link" )
-        get_json_value $( cat ~/emulator/net-summary.json) link_num
+        eval get_json_value '$content' link_num
         link_num=$?
         num_in_topo=`onos $2 links | wc -l`
         num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<link>" | wc -l`
diff --git a/tools/test/scenarios/odtn/createNetCfg.sh b/tools/test/scenarios/odtn/createNetCfg.sh
index 9bbd456..9bfbb28 100755
--- a/tools/test/scenarios/odtn/createNetCfg.sh
+++ b/tools/test/scenarios/odtn/createNetCfg.sh
@@ -1,9 +1,23 @@
 #!/bin/bash
 
-# Get first IPv4 Address on local machine, even the machine has lots of NICs.
-localIP=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:" | head -n1`
-mkdir /tmp/odtn
-# Replace IP address in openconfig json files with real ones.
-cat ${ONOS_ROOT}/apps/odtn/api/src/test/resources/openconfig-devices.json | sed "s/127.0.0.1/${localIP}/g" > /tmp/odtn/openconfig-devices.json
-cat ${ONOS_ROOT}/apps/odtn/api/src/test/resources/openconfig-device-link.json | sed "s/127.0.0.1/${localIP}/g" > /tmp/odtn/openconfig-device-link.json
-sleep 30
+if [[ "$1" == "-h" ]];then
+    echo "Usage for script $0:"
+    echo " - $0. The command without parameter means that config jsons are generated by modifying testing configuration of odtn app"
+    echo " - $0 {dev-abs-path} {link-abs-path} {net-summary}. The command means use specified device config and link config directly."
+fi
+
+if [[ $# == 0 ]];then
+    # Get first IPv4 Address on local machine, even the machine has lots of NICs.
+    localIP=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:" | head -n1`
+    mkdir /tmp/odtn
+    # Replace IP address in openconfig json files with real ones.
+    cat ${ONOS_ROOT}/apps/odtn/api/src/test/resources/openconfig-devices.json | sed "s/127.0.0.1/${localIP}/g" > /tmp/odtn/openconfig-devices.json
+    cat ${ONOS_ROOT}/apps/odtn/api/src/test/resources/openconfig-device-link.json | sed "s/127.0.0.1/${localIP}/g" > /tmp/odtn/openconfig-device-link.json
+    cp ${HOME}/emulator/net-summary.json /tmp/odtn/net-summary.json
+    sleep 30
+elif [[ $# == 3 ]];then
+    mkdir /tmp/odtn
+    cp $1 /tmp/odtn/openconfig-devices.json
+    cp $2 /tmp/odtn/openconfig-device-link.json
+    cp $3 /tmp/odtn/net-summary.json
+fi