Redesign nfdc test case to use new nfdc syntax
refs #4058
Change-Id: If48027509c3c8865334b776a30f420c5fafa02ec
diff --git a/test_nfdc/nfdc-test.sh b/test_nfdc/nfdc-test.sh
index fcaecc0..f52105b 100755
--- a/test_nfdc/nfdc-test.sh
+++ b/test_nfdc/nfdc-test.sh
@@ -2,180 +2,195 @@
source ../multi-host.conf
source include.sh
workdir=$(pwd)
-mkdir -p $workdir/logs/$1
-testCase=$1
-testLog=$workdir/logs/$testCase/nfdc_test.log
+mkdir -p $workdir/logs
+testLog=$workdir/logs/nfdc_test.log
echo "TEST START" > $testLog
-start_nfd $testCase
+start_nfd
-# run test case A: test nfdc create / add-nexthop / destroy test case
-if [[ $testCase == 'A' ]]; then
+# 1: Check for the existence of mcast address udp4://224.0.23.170
+udp4Mcast=$(nfdc face list | grep "udp4://224.0.23.170")
+udp6Mcast=$(nfdc face list | grep -iF "udp6://[ff00")
+ethv4=$(nfdc face list | grep -iF "ether://[01:00:5E:")
+ethv6=$(nfdc face list | grep -iF "ether://[33:33:")
- # Check for the existence of mcast address udp4://224.0.23.170
- udp4Mcast=$(nfd-status | grep udp4://224.0.23.170)
- udp6Mcast=$(nfd-status | grep -iF udp6://[ff00)
- ethv4=$(nfd-status | grep -iF ether://[01:00:5E:)
- ethv6=$(nfd-status | grep -iF ether://[33:33:)
-
- if [[ -z "$udp4Mcast" ]] && [[ -z "$udp6Mcast" ]] && [[ -z "$ethv4" ]] && [[ -z "$ethv6" ]]; then
- echo "nfd-status: Failed to find udp4/udp6/ether multicast faces" >> $testLog
- echo "nfd-status is:" >> $testLog
- nfd-status >> $testLog
- clean_up
- exit 2
- fi
-
- # Invoke nfdc create tcp://$IP4_B1.
- faceIdTcp4=$(nfdc create tcp4://$IP4_B1 | grep -Po 'FaceId: .*?,' | sed 's/FaceId: //' | sed 's/,//')
- sleep 2
- face=$(check_nfd_status_face_existence $faceIdTcp4 tcp4://$IP4_B1)
- if [ "-1" = $face ]; then
- clean_up
- exit 2
- fi
-
- #compress IPv6
- IP6_B1=$(python -c "import sys; import socket; result = socket.getaddrinfo('$IP6_B1', None); family, socktype, proto, canonname,(address, port, flow_info, scope_id) = result[0]; print address")
-
- # Invoke nfdc create tcp://$IP6_B1.
- faceIdTcp6=$(nfdc create tcp6://[$IP6_B1] | grep -Po 'FaceId: .*?,' | sed 's/FaceId: //' | sed 's/,//')
- sleep 2
- face=$(check_nfd_status_face_existence $faceIdTcp6 tcp6://[$IP6_B1])
- if [ "-1" = $face ]; then
- clean_up
- exit 2
- fi
-
- # Invoke nfdc create udp://$IP4_B1.
- faceIdUdp4=$(nfdc create udp4://$IP4_B1 | grep -Po 'FaceId: .*?,' | sed 's/FaceId: //' | sed 's/,//')
- sleep 2
-
- face=$(check_nfd_status_face_existence $faceIdUdp4 udp4://$IP4_B1)
- if [ "-1" = $face ]; then
- clean_up
- exit 2
- fi
-
-
- # Invoke nfdc create udp://$IP6_B1.
- faceIdUdp6=$(nfdc create udp6://[$IP6_B1] | grep -Po 'FaceId: .*?,' | sed 's/FaceId: //' | sed 's/,//')
- sleep 2
- face=$(check_nfd_status_face_existence $faceIdUdp6 udp6://[$IP6_B1])
- if [ "-1" = $face ]; then
- clean_up
- exit 2
- fi
-
- # Invoke nfdc to add next hops
- nfdc add-nexthop -c 24 ndn:/test-nfdc $faceIdTcp4
- nfdc add-nexthop -c 26 ndn:/test-nfdc $faceIdTcp6
- nfdc add-nexthop -c 14 ndn:/test-nfdc $faceIdUdp4
- nfdc add-nexthop -c 16 ndn:/test-nfdc $faceIdUdp6
-
- # check correctness of add-nexthop -c 24 ndn:/test-nfdc $faceIdTcp4
- check_nfd_status_correctness $faceIdTcp4 tcp4://$IP4_B1 /test-nfdc 24
-
- # check correctness of add-nexthop -c 26 ndn:/test-nfdc $faceIdTcp6
- check_nfd_status_correctness $faceIdTcp6 tcp6://[$IP6_B1] /test-nfdc 26
-
- # check correctness of add-nexthop -c 14 ndn:/test-nfdc $faceIdUdp4
- check_nfd_status_correctness $faceIdUdp4 udp4://$IP4_B1 /test-nfdc 14
-
- # check correctness of add-nexthop -c 16 ndn:/test-nfdc $faceIdUdp6
- check_nfd_status_correctness $faceIdUdp6 udp6://[$IP6_B1] /test-nfdc 16
-
- # Invoke nfdc to choose MulticastStrategy for ndn:/ namespace.
- nfdc set-strategy ndn:/ ndn:/localhost/nfd/strategy/multicast
-
- ndnping -c $NUM_OF_PINGS ndn:/test-nfdc
-
- check_nfd_status_counters $faceIdTcp4 tcp4://$IP4_B1 out $NUM_OF_PINGS
- check_nfd_status_counters $faceIdTcp6 tcp6://[$IP6_B1] out $NUM_OF_PINGS
- check_nfd_status_counters $faceIdUdp4 udp4://$IP4_B1 out $NUM_OF_PINGS
- check_nfd_status_counters $faceIdUdp6 udp6://[$IP6_B1] out $NUM_OF_PINGS
-
- ssh $CTRL_B "$workdir/test-B.sh $workdir"
- if [[ $? -ne 0 ]]; then
- echo "Failed to verify correctness on node B" >> $testLog
- clean_up
- exit 3
- fi
-
- nfdc destroy $faceIdTcp4
- echo "after nfdc destroy $faceIdTcp4" >> $testLog
- face=$(check_nfd_status_face_existence $faceIdTcp4 tcp4://$IP4_B1)
- if [ "-1" != $face ]; then
- echo "face $faceIdTcp4 still exists after nfdc destory" >> $testLog
- clean_up
- exit 2
- fi
-
- nfdc destroy $faceIdTcp6
- echo "after nfdc destroy $faceIdTcp6" >> $testLog
- face=$(check_nfd_status_face_existence $faceIdTcp6 tcp6://[$IP6_B1])
- if [ "-1" != $face ]; then
- clean_up
- exit 2
- fi
-
+if [[ -z "$udp4Mcast" ]] && [[ -z "$udp6Mcast" ]] && [[ -z "$ethv4" ]] && [[ -z "$ethv6" ]]; then
+ echo "nfdc: Failed to find udp4/udp6/ether multicast faces" >> $testLog
+ echo "'nfdc face list' output is:" >> $testLog
+ nfdc face list >> $testLog
clean_up
+ exit 2
+fi
-# run test case B: nfdc add-nexthop / remove-nexthop test case
-elif [[ $testCase == 'B' ]]; then
-
- # Invoke nfdc to add next hop
- faceId=$(nfdc add-nexthop -c 44 ndn:/test-nfdc udp4://$IP4_B1 | grep -Po 'FaceId: .*?,' | sed 's/FaceId: //' | sed 's/,//')
- if [[ "ERROR" == $faceId* ]]
- then
- echo "nfdc: Failed to add nexthop for $IP4_B1" >> $testLog
- clean_up
- exit 1
- fi
-
- check_nfd_status_correctness $faceId udp4://$IP4_B1 /test-nfdc 44
-
- # invoke nfdc to remove the nexthop for created FaceId
- removeNextHop=$(nfdc remove-nexthop ndn:/test-nfdc $faceId)
-
- #wait for the refreshed output of nfd-status
- sleep 2
-
- # check the existence of ndn:/test-nfdc FIB entry
- fibEntry=$(nfd-status | grep /test-nfdc)
- if [ ! -z "$fibEntry" ]; then
- echo "nfd-status: Failed to delete ndn:/test-nfdc FIB entry" >> $testLog
- clean_up
- exit 2
- fi
+# 2 and 3: Create face tcp4://$IP4_B1 and check for its existence
+faceIdTcp4=$(nfdc face create tcp4://$IP4_B1 | grep -Po 'id=[0-9]+' | sed 's/id=//' | sed 's/ //')
+sleep 2
+face=$(check_nfdc_face_existence $faceIdTcp4 tcp4://$IP4_B1)
+if [ "-1" == $face ]; then
+ echo "Could not create face tcp4://$IP4_B1"
clean_up
+ exit 2
+fi
-# run test case C: test nfdc register / unregister test case
-elif [[ $testCase == 'C' ]]; then
+#compress IPv6
+IP6_B1=$(python -c "import sys; import socket; result = socket.getaddrinfo('$IP6_B1', None); family, socktype, proto, canonname,(address, port, flow_info, scope_id) = result[0]; print address")
- # Invoke nfdc register a new prefix
- faceId=$(nfdc register -c 55 ndn:/test-nfdc udp4://$IP4_B1 | grep -Po 'FaceId: .*?,' | sed 's/FaceId: //' | sed 's/,//')
- if [[ "ERROR" == $faceId* ]]; then
- echo "nfdc: Failed to register ndn:/test-nfdc for $IP4_B1" >> $testLog
- clean_up
- exit 1
- fi
- check_nfd_status_correctness $faceId udp4://$IP4_B1 /test-nfdc 55
-
- # Invoke nfdc to unregister the prefix
- unregisterPrefix=$(nfdc unregister ndn:/test-nfdc $faceId)
- sleep 2
- # check the existence of ndn:/test-nfdc FIB entry
- fibEntry=$(nfd-status | grep /test-nfdc)
- if [ ! -z "$fibEntry" ]; then
- echo "nfd-status: Failed to unregister prefix" >> $testLog
- clean_up
- exit 2
- fi
+# 4 and 5: Create face tcp6://[$IP6_B1] and check for its existence
+faceIdTcp6=$(nfdc face create tcp6://[$IP6_B1] | grep -Po 'id=[0-9]+' | sed 's/id=//' | sed 's/ //')
+sleep 2
+face=$(check_nfdc_face_existence_show $faceIdTcp6 tcp6://[$IP6_B1])
+if [ "-1" == $face ]; then
+ echo "Could not create face tcp6://[$IP6_B1]"
clean_up
+ exit 2
+fi
+
+# 6 and 7: Create face udp4://$IP4_B1 and check for its existence
+faceIdUdp4=$(nfdc face create udp4://$IP4_B1 | grep -Po 'id=[0-9]+' | sed 's/id=//' | sed 's/ //')
+sleep 2
+face=$(check_nfdc_face_existence_remote_uri $faceIdUdp4 udp4://$IP4_B1)
+if [ "-1" == $face ]; then
+ echo "Could not create face udp4://$IP4_B1"
+ clean_up
+ exit 2
+fi
+
+
+# 8 and 9: Create face udp6://[$IP4_B1] and check for its existence
+faceIdUdp6=$(nfdc face create udp6://[$IP6_B1] | grep -Po 'id=[0-9]+' | sed 's/id=//' | sed 's/ //')
+sleep 2
+face=$(check_nfdc_face_existence $faceIdUdp6 udp6://[$IP6_B1])
+if [ "-1" == $face ]; then
+ echo "Could not create face udp6://[$IP6_B1]"
+ clean_up
+ exit 2
+fi
+
+# 10, 11, 12, and 13: Add routes for /test-nfdc
+nfdc route add /test-nfdc tcp4://$IP4_B1 cost 24
+nfdc route add /test-nfdc tcp6://[$IP6_B1] cost 26
+nfdc route add /test-nfdc udp4://$IP4_B1 cost 14
+nfdc route add /test-nfdc udp6://[$IP6_B1] cost 16
+
+# 14: Check for the existence of the created routes
+check_nfdc_route_existence "/test-nfdc" $faceIdTcp4 24
+check_nfdc_route_existence "/test-nfdc" $faceIdTcp6 26
+check_nfdc_route_existence_show "/test-nfdc" $faceIdUdp4 14
+check_nfdc_route_existence_show "/test-nfdc" $faceIdUdp6 16
+
+# 15: Check whether the `/test-nfdc` FIB entry contains all routes with the correct nexthops, in the correct order
+check_nfdc_nexthop_existence "/test-nfdc" $faceIdTcp4 24
+check_nfdc_nexthop_existence "/test-nfdc" $faceIdTcp6 26
+check_nfdc_nexthop_existence "/test-nfdc" $faceIdUdp4 14
+check_nfdc_nexthop_existence "/test-nfdc" $faceIdUdp6 16
+
+# Check if nexthops in correct order
+nexthopInfo=$(nfdc fib list | grep "/test-nfdc" | \
+ grep "nexthops={faceid=$faceIdUdp4 (cost=14), faceid=$faceIdUdp6 (cost=16), faceid=$faceIdTcp4 (cost=24), faceid=$faceIdTcp6 (cost=26)}")
+
+if [[ -z "$nexthopInfo" ]]; then
+ echo "nfdc: Nexthops to /test-nfdc not in correct order (by cost)" >> $testLog
+ echo "'nfdc fib list' is:" >> $testLog
+ nfdc fib list >> $testLog
+ clean_up
+ exit 2
+fi
+
+# 16: Use MulticastStrategy for the /test-nfdc prefix
+nfdc strategy set /test-nfdc /localhost/nfd/strategy/multicast
+
+# 17: Verify that /test-nfdc prefix uses MulticastStrategy
+strategyInfo=$(nfdc strategy show /test-nfdc | grep "^strategy=/localhost/nfd/strategy/multicast/%FD%[0-9][0-9]$")
+
+if [[ -z "$strategyInfo" ]]; then
+ echo "nfdc: prefix /test-nfdc does not use MulticastStrategy" >> $testLog
+ echo "'nfdc strategy show /test-nfdc' is:" >> $testLog
+ nfdc strategy show /test-nfdc >> $testLog
+ clean_up
+ exit 2
+fi
+
+# 18: Send 100 Interests to /test-nfdc w/ 50ms interval
+ndnping -c $NUM_OF_PINGS -i 50 /test-nfdc
+
+# 19: Verify that each face we created has had at least 100 outgoing Interests
+check_nfdc_face_counters $faceIdTcp4 tcp4://$IP4_B1 out $NUM_OF_PINGS
+check_nfdc_face_counters $faceIdTcp6 tcp6://[$IP6_B1] out $NUM_OF_PINGS
+check_nfdc_face_counters $faceIdUdp4 udp4://$IP4_B1 out $NUM_OF_PINGS
+check_nfdc_face_counters $faceIdUdp6 udp6://[$IP6_B1] out $NUM_OF_PINGS
+
+# 20: Verify that corresponding faces on host B have had at least 100 incoming Interests
+ssh $CTRL_B "$workdir/test-B.sh $workdir"
+if [[ $? -ne 0 ]]; then
+ echo "Failed to verify correctness on node B" >> $testLog
+ clean_up
+ exit 3
+fi
+
+# 21: Destroy faces tcp4://$IP4_B1 and tcp6://[$IP6_B1]
+nfdc face destroy $faceIdTcp4
+echo "after nfdc face destroy $faceIdTcp4" >> $testLog
+face=$(check_nfdc_face_existence $faceIdTcp4 tcp4://$IP4_B1)
+if [ "-1" != $face ]; then
+ echo "face $faceIdTcp4 still exists after nfdc face destroy" >> $testLog
+ clean_up
+ exit 2
+fi
+
+nfdc face destroy $faceIdTcp6
+echo "after nfdc face destroy $faceIdTcp6" >> $testLog
+face=$(check_nfdc_face_existence $faceIdTcp6 tcp6://[$IP6_B1])
+if [ "-1" != $face ]; then
+ clean_up
+ exit 2
+fi
+
+# 22: Unset MulticastStrategy for prefix /test-nfdc
+nfdc strategy unset /test-nfdc
+
+# 23: Verify that /test-nfdc prefix no longer uses MulticastStrategy
+strategyInfo=$(nfdc strategy show /test-nfdc | grep "^strategy=/localhost/nfd/strategy/multicast/%FD%[0-9][0-9]$")
+
+if [[ -n "$strategyInfo" ]]; then
+ echo "nfdc: prefix /test-nfdc still uses MulticastStrategy after 'nfdc strategy unset /test-nfdc''" >> $testLog
+ echo "'nfdc strategy show /test-nfdc' is:" >> $testLog
+ nfdc strategy show /test-nfdc >> $testLog
+ clean_up
+ exit 2
+fi
+
+# 24: Remove route to /test-nfdc via nexthop udp4://$IP4_B1
+nfdc route remove /test-nfdc udp4://$IP4_B1
+
+# 25: Ensure that route to /test-nfdc w/ nexthop udp4://$IP4_B1 has been removed
+check_nfdc_route_existence "/test-nfdc" $faceIdTcp4 24 noexist
+check_nfdc_route_existence "/test-nfdc" $faceIdTcp6 26 noexist
+check_nfdc_route_existence "/test-nfdc" $faceIdUdp4 14 noexist
+check_nfdc_route_existence "/test-nfdc" $faceIdUdp6 16
+
+# 26: Ensure that /test-nfdc FIB entry no longer contains nexthop to udp4://$IP4_B1
+check_nfdc_nexthop_existence "/test-nfdc" $faceIdTcp4 24 noexist
+check_nfdc_nexthop_existence "/test-nfdc" $faceIdTcp6 26 noexist
+check_nfdc_nexthop_existence "/test-nfdc" $faceIdUdp4 14 noexist
+check_nfdc_nexthop_existence "/test-nfdc" $faceIdUdp6 16
+
+# 27: Remove route to /test-nfdc via nexthop udp6://[$IP6_B1]
+nfdc route remove /test-nfdc udp6://[$IP6_B1]
+
+sleep 1
+
+# 28: Ensure that FIB entry for /test-nfdc has been removed, given that all routes to it have been removed
+check_nfdc_nexthop_existence "/test-nfdc" $faceIdUdp6 16 noexist
+
+nexthopInfo=$(nfdc fib list | grep "/test-nfdc")
+if [[ -n $nexthopInfo ]]; then
+ echo "nfdc: FIB entry for /test-nfdc should not exist" >> $testLog
+ echo "'nfdc fib list' is:" >> $testLog
+ nfdc fib list >> $testLog
+ clean_up
+ exit 2
fi
clean_up
exit 0
-