blob: 9d9914b2c02cc8fecbebb26a877a9beef4389036 [file] [log] [blame]
Boyuan Yan1c27bc72019-02-15 19:22:19 +00001#!/bin/bash
2
Boyuan Yan36231d22019-04-09 18:38:23 +00003# Three input parameters:
Boyuan Yan1c27bc72019-02-15 19:22:19 +00004# $1 - one of {device, port, link}, specify what needs to be checked.
5# $2 - IP address of ONOS instance.
Boyuan Yan36231d22019-04-09 18:38:23 +00006# $3 - Optional. absolute path of net summary json file. The default path is "/tmp/odtn/net-summary.json".
Boyuan Yan1c27bc72019-02-15 19:22:19 +00007
Boyuan Yan36231d22019-04-09 18:38:23 +00008summary="/tmp/odtn/net-summary.json"
9if [[ $# == 3 ]];then
10 summary=$3
11fi
Boyuan Yanc684db32019-04-21 15:48:23 -070012# The 'sed'command behind 'wc -l' is uset to strip leading spaces.
13# Because in some scenarios, 'wc -l' always outputs leading spaces (https://lists.gnu.org/archive/html/bug-coreutils/2005-01/msg00029.html).
14line_num=`cat $summary | wc -l | sed -e 's/^[ ]*//g'`
Boyuan Yan1c27bc72019-02-15 19:22:19 +000015if [[ "$line_num" != "1" ]]; then
16 echo "JSON file should have only 1 line."
17 exit 1
18fi
Boyuan Yan36231d22019-04-09 18:38:23 +000019content=`cat $summary`
20echo -e "The content of the json file is :\n $content"
Boyuan Yan1c27bc72019-02-15 19:22:19 +000021# Extract specific value from returned json string under onos command "odtn-show-tapi-context"
22function get_json_value()
23{
24 local json=$1
25 local key=$2
26
27 if [[ -z "$3" ]]; then
28 local num=1
29 else
30 local num=$3
31 fi
32
Boyuan Yan36231d22019-04-09 18:38:23 +000033 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)
Boyuan Yan1c27bc72019-02-15 19:22:19 +000034
35 return ${value}
36}
37
38tried=0
39case "$1" in
40 "device" )
Boyuan Yan36231d22019-04-09 18:38:23 +000041 eval get_json_value '$content' device_num
Boyuan Yan1c27bc72019-02-15 19:22:19 +000042 device_num=$?
Boyuan Yanc684db32019-04-21 15:48:23 -070043 num_in_topo=`onos $2 devices | wc -l | sed -e 's/^[ ]*//g'`
44 num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<node>" | wc -l | sed -e 's/^[ ]*//g'`
Boyuan Yan1c27bc72019-02-15 19:22:19 +000045 while [[ "$num_in_topo" != "$device_num" || "$num_in_tapi" != "$device_num" ]]
46 do
47 echo "On ONOS $2, current device num in topo:$num_in_topo, num in tapi:$num_in_tapi, expected $device_num. Waiting..."
48 sleep 10
Boyuan Yanc684db32019-04-21 15:48:23 -070049 num_in_topo=`onos $2 devices | wc -l | sed -e 's/^[ ]*//g'`
50 num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<node>" | wc -l | sed -e 's/^[ ]*//g'`
Boyuan Yan1c27bc72019-02-15 19:22:19 +000051 let "tried=tried+1"
52 if [[ "$tried" == "10" ]]; then
53 exit 99
54 fi
55 done
56 ;;
57 "port" )
Boyuan Yan36231d22019-04-09 18:38:23 +000058 eval get_json_value '$content' port_num
Boyuan Yan1c27bc72019-02-15 19:22:19 +000059 port_num=$?
Boyuan Yan36231d22019-04-09 18:38:23 +000060 eval get_json_value '$content' device_num
Boyuan Yan1c27bc72019-02-15 19:22:19 +000061 device_num=$?
Boyuan Yanc684db32019-04-21 15:48:23 -070062 num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<owned-node-edge-point>" | wc -l | sed -e 's/^[ ]*//g'`
63 num_in_topo=`onos $2 ports | wc -l | sed -e 's/^[ ]*//g'`
Boyuan Yan1c27bc72019-02-15 19:22:19 +000064 num_in_topo=$[num_in_topo-device_num]
65 while [[ "$num_in_topo" != "$port_num" || "$num_in_tapi" != "$port_num" ]]
66 do
67 echo "On ONOS $2, current port num in topo: $num_in_topo, num in tapi: $num_in_tapi, expected $port_num. Waiting..."
68 sleep 10
Boyuan Yanc684db32019-04-21 15:48:23 -070069 num_in_topo=`onos $2 ports | wc -l | sed -e 's/^[ ]*//g'`
Boyuan Yan1c27bc72019-02-15 19:22:19 +000070 num_in_topo=$[num_in_topo-device_num]
Boyuan Yanc684db32019-04-21 15:48:23 -070071 num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<owned-node-edge-point>" | wc -l | sed -e 's/^[ ]*//g'`
Boyuan Yan1c27bc72019-02-15 19:22:19 +000072 let "tried=tried+1"
73 if [[ "$tried" == "10" ]]; then
74 exit 99
75 fi
76 done
77 ;;
78 "link" )
Boyuan Yan36231d22019-04-09 18:38:23 +000079 eval get_json_value '$content' link_num
Boyuan Yan1c27bc72019-02-15 19:22:19 +000080 link_num=$?
Boyuan Yanc684db32019-04-21 15:48:23 -070081 num_in_topo=`onos $2 links | wc -l | sed -e 's/^[ ]*//g'`
82 num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<link>" | wc -l | sed -e 's/^[ ]*//g'`
Boyuan Yan1c27bc72019-02-15 19:22:19 +000083 while [[ "$num_in_topo" != "$link_num" || "$num_in_tapi" != "$link_num" ]]
84 do
85 echo "On ONOS $2, current link num: $num_in_topo, expected $link_num. Waiting..."
86 sleep 10
Boyuan Yanc684db32019-04-21 15:48:23 -070087 num_in_topo=`onos $2 links | wc -l | sed -e 's/^[ ]*//g'`
88 num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<link>" | wc -l | sed -e 's/^[ ]*//g'`
Boyuan Yan1c27bc72019-02-15 19:22:19 +000089 let "tried=tried+1"
90 if [[ "$tried" == "10" ]]; then
91 exit 99
92 fi
93 done
94esac