Boyuan Yan | 1c27bc7 | 2019-02-15 19:22:19 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Boyuan Yan | 36231d2 | 2019-04-09 18:38:23 +0000 | [diff] [blame] | 3 | # Three input parameters: |
Boyuan Yan | 1c27bc7 | 2019-02-15 19:22:19 +0000 | [diff] [blame] | 4 | # $1 - one of {device, port, link}, specify what needs to be checked. |
| 5 | # $2 - IP address of ONOS instance. |
Boyuan Yan | 36231d2 | 2019-04-09 18:38:23 +0000 | [diff] [blame] | 6 | # $3 - Optional. absolute path of net summary json file. The default path is "/tmp/odtn/net-summary.json". |
Boyuan Yan | 1c27bc7 | 2019-02-15 19:22:19 +0000 | [diff] [blame] | 7 | |
Boyuan Yan | 36231d2 | 2019-04-09 18:38:23 +0000 | [diff] [blame] | 8 | summary="/tmp/odtn/net-summary.json" |
| 9 | if [[ $# == 3 ]];then |
| 10 | summary=$3 |
| 11 | fi |
| 12 | |
| 13 | line_num=`cat $summary | wc -l` |
Boyuan Yan | 1c27bc7 | 2019-02-15 19:22:19 +0000 | [diff] [blame] | 14 | if [[ "$line_num" != "1" ]]; then |
| 15 | echo "JSON file should have only 1 line." |
| 16 | exit 1 |
| 17 | fi |
Boyuan Yan | 36231d2 | 2019-04-09 18:38:23 +0000 | [diff] [blame] | 18 | content=`cat $summary` |
| 19 | echo -e "The content of the json file is :\n $content" |
Boyuan Yan | 1c27bc7 | 2019-02-15 19:22:19 +0000 | [diff] [blame] | 20 | # Extract specific value from returned json string under onos command "odtn-show-tapi-context" |
| 21 | function 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 Yan | 36231d2 | 2019-04-09 18:38:23 +0000 | [diff] [blame] | 32 | 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 Yan | 1c27bc7 | 2019-02-15 19:22:19 +0000 | [diff] [blame] | 33 | |
| 34 | return ${value} |
| 35 | } |
| 36 | |
| 37 | tried=0 |
| 38 | case "$1" in |
| 39 | "device" ) |
Boyuan Yan | 36231d2 | 2019-04-09 18:38:23 +0000 | [diff] [blame] | 40 | eval get_json_value '$content' device_num |
Boyuan Yan | 1c27bc7 | 2019-02-15 19:22:19 +0000 | [diff] [blame] | 41 | 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 Yan | 36231d2 | 2019-04-09 18:38:23 +0000 | [diff] [blame] | 57 | eval get_json_value '$content' port_num |
Boyuan Yan | 1c27bc7 | 2019-02-15 19:22:19 +0000 | [diff] [blame] | 58 | port_num=$? |
Boyuan Yan | 36231d2 | 2019-04-09 18:38:23 +0000 | [diff] [blame] | 59 | eval get_json_value '$content' device_num |
Boyuan Yan | 1c27bc7 | 2019-02-15 19:22:19 +0000 | [diff] [blame] | 60 | 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 Yan | 36231d2 | 2019-04-09 18:38:23 +0000 | [diff] [blame] | 78 | eval get_json_value '$content' link_num |
Boyuan Yan | 1c27bc7 | 2019-02-15 19:22:19 +0000 | [diff] [blame] | 79 | 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 |
| 93 | esac |