blob: 25524bb03a1bc4cb7fa8db8d47b0b52a88be67b3 [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
12
13line_num=`cat $summary | wc -l`
Boyuan Yan1c27bc72019-02-15 19:22:19 +000014if [[ "$line_num" != "1" ]]; then
15 echo "JSON file should have only 1 line."
16 exit 1
17fi
Boyuan Yan36231d22019-04-09 18:38:23 +000018content=`cat $summary`
19echo -e "The content of the json file is :\n $content"
Boyuan Yan1c27bc72019-02-15 19:22:19 +000020# Extract specific value from returned json string under onos command "odtn-show-tapi-context"
21function get_json_value()
22{
23 local json=$1
24 local key=$2
25
26 if [[ -z "$3" ]]; then
27 local num=1
28 else
29 local num=$3
30 fi
31
Boyuan Yan36231d22019-04-09 18:38:23 +000032 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 +000033
34 return ${value}
35}
36
37tried=0
38case "$1" in
39 "device" )
Boyuan Yan36231d22019-04-09 18:38:23 +000040 eval get_json_value '$content' device_num
Boyuan Yan1c27bc72019-02-15 19:22:19 +000041 device_num=$?
42 num_in_topo=`onos $2 devices | wc -l`
43 num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<node>" | wc -l`
44 while [[ "$num_in_topo" != "$device_num" || "$num_in_tapi" != "$device_num" ]]
45 do
46 echo "On ONOS $2, current device num in topo:$num_in_topo, num in tapi:$num_in_tapi, expected $device_num. Waiting..."
47 sleep 10
48 num_in_topo=`onos $2 devices | wc -l`
49 num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<node>" | wc -l`
50 let "tried=tried+1"
51 if [[ "$tried" == "10" ]]; then
52 exit 99
53 fi
54 done
55 ;;
56 "port" )
Boyuan Yan36231d22019-04-09 18:38:23 +000057 eval get_json_value '$content' port_num
Boyuan Yan1c27bc72019-02-15 19:22:19 +000058 port_num=$?
Boyuan Yan36231d22019-04-09 18:38:23 +000059 eval get_json_value '$content' device_num
Boyuan Yan1c27bc72019-02-15 19:22:19 +000060 device_num=$?
61 num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<owned-node-edge-point>" | wc -l`
62 num_in_topo=`onos $2 ports | wc -l`
63 num_in_topo=$[num_in_topo-device_num]
64 while [[ "$num_in_topo" != "$port_num" || "$num_in_tapi" != "$port_num" ]]
65 do
66 echo "On ONOS $2, current port num in topo: $num_in_topo, num in tapi: $num_in_tapi, expected $port_num. Waiting..."
67 sleep 10
68 num_in_topo=`onos $2 ports | wc -l`
69 num_in_topo=$[num_in_topo-device_num]
70 num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<owned-node-edge-point>" | wc -l`
71 let "tried=tried+1"
72 if [[ "$tried" == "10" ]]; then
73 exit 99
74 fi
75 done
76 ;;
77 "link" )
Boyuan Yan36231d22019-04-09 18:38:23 +000078 eval get_json_value '$content' link_num
Boyuan Yan1c27bc72019-02-15 19:22:19 +000079 link_num=$?
80 num_in_topo=`onos $2 links | wc -l`
81 num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<link>" | wc -l`
82 while [[ "$num_in_topo" != "$link_num" || "$num_in_tapi" != "$link_num" ]]
83 do
84 echo "On ONOS $2, current link num: $num_in_topo, expected $link_num. Waiting..."
85 sleep 10
86 num_in_topo=`onos $2 links | wc -l`
87 num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<link>" | wc -l`
88 let "tried=tried+1"
89 if [[ "$tried" == "10" ]]; then
90 exit 99
91 fi
92 done
93esac