Add nfdc and nfd-status integration test

refs: #1388

Change-Id: Ic9b181dfb333a9543b1d319e03713325d70c933e
diff --git a/test_nfdc/include.sh b/test_nfdc/include.sh
new file mode 100755
index 0000000..5f1c491
--- /dev/null
+++ b/test_nfdc/include.sh
@@ -0,0 +1,120 @@
+#!/usr/bin/env bash
+NUM_OF_PINGS=10
+
+# clean up - kill nfd
+clean_up() {
+  r=$(ssh $CTRL_B "sudo killall nfd" 2>&1)
+  r=$(sudo killall nfd 2>&1)
+
+  if [[ $testCase == 'C' ]]; then
+    r=$(sudo killall nrd 2>&1)
+  fi
+}
+
+start_nfd() {
+  # start nfd on localhost
+  sudo nfd &> $workdir/logs/nfd.log &
+
+  # start nfd on hostB
+  ssh $CTRL_B "mkdir -p $workdir/logs ; sudo nfd &> $workdir/logs/nfd.log &\
+    sleep 2"
+  sleep 2
+}
+
+start_nrd() {
+  # start nfd on localhost
+  sudo nrd &> $workdir/logs/nrd.log &
+
+  sleep 2
+}
+
+
+check_nfd_status_counters() {
+  faceId=$1
+  faceUri=$2
+  counterType=$3
+  threshold=$4
+
+  outCounter=$(nfd-status | grep -iF 'faceid='$faceId' remote='$faceUri | grep -Po $counterType={[0-9]+ | sed 's/'$counterType'={//')
+
+
+  if [[ $outCounter -lt $threshold ]]; then
+    if [[ "out" = $counterType ]]; then
+      echo "nfd-status: out counter of face=$faceId is less than $threshold " >> $testLog
+      echo "nfd-status is:" >> $testLog
+      nfd-status >> $testLog
+      clean_up
+    fi
+    exit 2
+
+  fi
+
+}
+
+# check for the existence of the face
+# param list: $1 - face Id
+#             $2 - face Uri
+check_nfd_status_face_existence() {
+  faceId=$1
+  faceUri=$2
+
+  # check for the existence of the face
+  # First, get the face line
+  # Second, extract the face id attached to the fetched line
+  face=$(nfd-status | grep -iF remote=$faceUri | grep -Po faceid=\[0-9\]+ | sed 's/faceid=//')
+
+  if [[ "none" != $faceId ]]; then
+    if [[ $face != $faceId ]]; then
+      echo "nfd-status: Failed to find face $faceId of $faceUri" >> $testLog
+      echo "nfd-status is:" >> $testLog
+      nfd-status >> $testLog
+      echo "-1"
+    else
+      echo $face
+    fi
+  else
+    echo $face
+  fi
+
+}
+
+
+# This function checks for the existence of a face and a fib entry
+# including nexthop records
+# param list: $1 - face Id
+#             $2 - face Uri
+#             $3 - prefix
+#             $4 - cost
+check_nfd_status_correctness() {
+  faceId=$1
+  faceUri=$2
+  prefix=$3
+  cost=$4
+
+  face=$(check_nfd_status_face_existence $faceId $faceUri)
+  if [[ "-1" = $face ]]; then
+    clean_up
+    exit 2
+  fi
+
+  # check the existence of prefix FIB entry
+  fibEntry=$(nfd-status | grep $prefix)
+  if [[ -z "$fibEntry" ]]; then
+    echo "nfd-status: Failed to find $prefix in FIB table" >> $testLog
+    echo "nfd-status is:" >> $testLog
+    nfd-status >> $testLog
+    clean_up
+    exit 2
+  fi
+
+  # check the correctness of cost on nexthop records
+  fibEntryCost=$(echo $fibEntry | grep -Po 'faceid='$faceId'.\(cost=[0-9]+\)' | sed 's/faceid='$faceId' //' | sed 's/(cost=//' | sed 's/)//')
+
+  if [[ $cost != $fibEntryCost ]]; then
+    echo "nfd-status: nexthop records are incorrect, expected cost is $cost, cost in records $fibEntryCost" >> $testLog
+    echo "nfd-status is:" >> $testLog
+    nfd-status >> $testLog
+    clean_up
+    exit 2
+  fi
+}
\ No newline at end of file