- bidrectional vnet link creation
- optionally specify expected number of intents in "onos-check-intent"

Change-Id: I523a7fd9e1aaa72b441d2428fb9ebb692b07bdd0

-  bidrectional vnet link creation (when using ssh)
- optionally specify expected number of intents in "onos-check-intent"

Change-Id: I5c6fe1f269eddeaa70dfec819853d42af59fbd8e
diff --git a/tools/test/bin/onos b/tools/test/bin/onos
index 780a90d..222ab99 100755
--- a/tools/test/bin/onos
+++ b/tools/test/bin/onos
@@ -6,10 +6,11 @@
 function _usage () {
 cat << _EOF_
 usage:
- $(basename $0) [-w] [node]
+ $(basename $0) [-w] [-f] [node]
 
 flags:
 - -w : Waits for ONOS instance to reach run-level 100, i.e. to be fully started.
+- -f : (Affects non-secure client only) - use bash's IFS expansion of positional parameters
 
 options:
 - [node] : the node to attach to
@@ -29,13 +30,18 @@
 . $ONOS_ROOT/tools/test/bin/find-node.sh
 
 [ "$1" = "-w" ] && shift && onos-wait-for-start $1
+[ "$1" = "-f" ] && shift && flat=1
 
 [ -n "$1" ] && OCI=$(find_node $1) && shift
 
 if which client 1>/dev/null 2>&1 && [ -z "$ONOS_USE_SSH" ]; then
     # Use Karaf client only if we can and are allowed to
     unset KARAF_HOME
-    client -h $OCI -u karaf "$@" 2>/dev/null
+    if [ -z "$flat" ]; then
+        client -h $OCI -u karaf "$@" 2>/dev/null
+    else
+        client -h $OCI -u karaf "$*" 2>/dev/null
+    fi
 else
     # Otherwise use raw ssh; strict checking is off for dev environments only
     ssh -p 8101 -o StrictHostKeyChecking=no $OCI "$@"
diff --git a/tools/test/bin/onos-check-intent b/tools/test/bin/onos-check-intent
index 760afaf..37558cc 100755
--- a/tools/test/bin/onos-check-intent
+++ b/tools/test/bin/onos-check-intent
@@ -13,9 +13,29 @@
 echo onos-check-intent: $*
 
 set -x
+
+# $1: target host
+# $2: intent key
+# $3: intent state
+# $4: number of expected intents
+re='^[0-9]+$'
+[[ $4 =~ $re ]] && numIntentsExpected=$4 # silently ignore if not positive
+
 for i in {1..15}; do
+    echo "Attempt #$i"
     onos $target "onos:intents" | tee $aux
-    ( cat $aux | grep "key=$2" | grep "state=$3" ) && cat $aux && exit 0
+    if  [ -z "$numIntentsExpected" ]; then
+        ( cat $aux | grep "key=$2" | grep "state=$3" ) && cat $aux && exit 0
+    else 
+        # exit 0 only if expected number of intents (with required key)
+        # are present and all intents match state (if expected no. of intents > 0)
+        numIntents=`grep "key=$2" $aux | wc -l`
+        numIntentsOfState=0
+        [ $numIntentsExpected -gt 0 ] && numIntentsOfState=`grep "key=$2" $aux | grep "state=$3" | wc -l`
+        [ $numIntents -eq $numIntentsOfState ] \
+            && [ $numIntents -eq $numIntentsExpected ] \
+            && cat $aux && exit 0
+    fi 
     sleep 1
 done
 
diff --git a/tools/test/scenarios/net-setup-vnets.xml b/tools/test/scenarios/net-setup-vnets.xml
index 66e5697..55207cc 100644
--- a/tools/test/scenarios/net-setup-vnets.xml
+++ b/tools/test/scenarios/net-setup-vnets.xml
@@ -46,19 +46,14 @@
         <step name="Create-Port-2" requires="^"
               exec="onos ${OCI} vnet-create-port ${networkId} device2 2 of:0000000000000009 1"/>
 
-        <step name="Create-Link-1" requires="^"
-              exec="onos ${OCI} vnet-create-link ${networkId} device1 1 device2 2"/>
+        <step name="Create-Bidirectional-Link" requires="^"
+              exec="onos -f ${OCI} vnet-create-link --bidirectional ${networkId} device2 2 device1 1"/>
 
-        <step name="Create-Link-2" requires="^"
-              exec="onos ${OCI} vnet-create-link ${networkId} device2 2 device1 1"/>
+        <step name="Check-intents-installed" requires="^"
+              exec="onos-check-intent ${OCI} networkId=${networkId} INSTALLED 2"/>
 
-        <step name="Check-intents-installed" requires="^" env="~"
-              exec="onos-check-intent ${OCI} networkId=${networkId} INSTALLED"/>
-              <!-- TODO: ignore return code once intent is working -->
-
-        <step name="Ping-hosts-1" requires="^" env="~"
+        <step name="Ping-hosts-1" requires="^"
               exec="onos-mininet sendAndExpect h4 ping -c1 h9 --expect \ 0% packet loss"/>
-              <!-- TODO: ignore return code once intent is working -->
 
     </group>
 </scenario>
diff --git a/tools/test/scenarios/net-teardown-vnets.xml b/tools/test/scenarios/net-teardown-vnets.xml
index c030e73..69b7c5c 100644
--- a/tools/test/scenarios/net-teardown-vnets.xml
+++ b/tools/test/scenarios/net-teardown-vnets.xml
@@ -22,11 +22,11 @@
         <step name="Check-Vnet-Link" requires="^"
               exec="onos ${OCI} vnet-links ${networkId}"/>
 
-        <step name="Remove-Link-1" requires="^"
-              exec="onos ${OCI} vnet-remove-link ${networkId} device1 1 device2 2"/>
+        <step name="Remove-Bidirectional-Link" requires="^"
+              exec="onos -f ${OCI} vnet-remove-link --bidirectional ${networkId} device2 2 device1 1"/>
 
-        <step name="Remove-Link-2" requires="^"
-              exec="onos ${OCI} vnet-remove-link ${networkId} device2 2 device1 1"/>
+        <step name="Check-intents-removed" requires="^"
+              exec="onos-check-intent ${OCI} networkId=${networkId} IGNORE_STATE 0"/>
 
         <step name="Ping-hosts-2" requires="^"
               exec="onos-mininet sendAndExpect h4 ping -c1 h9 --expect \ 100% packet loss"/>