blob: 792a8d70afd80d634f3348c671dd466afafdcc62 [file] [log] [blame]
Boyuan Yan1c27bc72019-02-15 19:22:19 +00001#!/bin/bash
2
3# Two input parameters:
4# $1 - one of {device, port, link}, specify what needs to be checked.
5# $2 - IP address of ONOS instance.
6
7line_num=`cat ~/emulator/net-summary.json | wc -l`
8if [[ "$line_num" != "1" ]]; then
9 echo "JSON file should have only 1 line."
10 exit 1
11fi
12
13# Extract specific value from returned json string under onos command "odtn-show-tapi-context"
14function get_json_value()
15{
16 local json=$1
17 local key=$2
18
19 if [[ -z "$3" ]]; then
20 local num=1
21 else
22 local num=$3
23 fi
24
25 local value=$(echo "${json}" | awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'${key}'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p)
26
27 return ${value}
28}
29
30tried=0
31case "$1" in
32 "device" )
33 get_json_value $( cat ~/emulator/net-summary.json) device_num
34 device_num=$?
35 num_in_topo=`onos $2 devices | wc -l`
36 num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<node>" | wc -l`
37 while [[ "$num_in_topo" != "$device_num" || "$num_in_tapi" != "$device_num" ]]
38 do
39 echo "On ONOS $2, current device num in topo:$num_in_topo, num in tapi:$num_in_tapi, expected $device_num. Waiting..."
40 sleep 10
41 num_in_topo=`onos $2 devices | wc -l`
42 num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<node>" | wc -l`
43 let "tried=tried+1"
44 if [[ "$tried" == "10" ]]; then
45 exit 99
46 fi
47 done
48 ;;
49 "port" )
50 get_json_value $( cat ~/emulator/net-summary.json) port_num
51 port_num=$?
52 get_json_value $( cat ~/emulator/net-summary.json) device_num
53 device_num=$?
54 num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<owned-node-edge-point>" | wc -l`
55 num_in_topo=`onos $2 ports | wc -l`
56 num_in_topo=$[num_in_topo-device_num]
57 while [[ "$num_in_topo" != "$port_num" || "$num_in_tapi" != "$port_num" ]]
58 do
59 echo "On ONOS $2, current port num in topo: $num_in_topo, num in tapi: $num_in_tapi, expected $port_num. Waiting..."
60 sleep 10
61 num_in_topo=`onos $2 ports | wc -l`
62 num_in_topo=$[num_in_topo-device_num]
63 num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<owned-node-edge-point>" | wc -l`
64 let "tried=tried+1"
65 if [[ "$tried" == "10" ]]; then
66 exit 99
67 fi
68 done
69 ;;
70 "link" )
71 get_json_value $( cat ~/emulator/net-summary.json) link_num
72 link_num=$?
73 num_in_topo=`onos $2 links | wc -l`
74 num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<link>" | wc -l`
75 while [[ "$num_in_topo" != "$link_num" || "$num_in_tapi" != "$link_num" ]]
76 do
77 echo "On ONOS $2, current link num: $num_in_topo, expected $link_num. Waiting..."
78 sleep 10
79 num_in_topo=`onos $2 links | wc -l`
80 num_in_tapi=`onos $2 odtn-show-tapi-context | grep "<link>" | wc -l`
81 let "tried=tried+1"
82 if [[ "$tried" == "10" ]]; then
83 exit 99
84 fi
85 done
86esac