forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqsfp_monitor.sh
executable file
·104 lines (95 loc) · 3.03 KB
/
qsfp_monitor.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
# Copyright (C) 2017 Ingrasys, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
INTERVAL=3
I2C_UTILS="/usr/sbin/i2c_utils.sh"
QSFP_SI_SCRIPT="/usr/sbin/qsfp_si_cfg.sh"
QSFP_ARRAY=(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
#QSFP SI monitor
function _qsfp_si_monitor {
local i
local status
for i in {0..31};
do
status=`${I2C_UTILS} i2c_qsfp_status_get $(expr $i + 1) | egrep '^status=.*$' | sed -e 's/status=//g'`
if [ "${status}" == "1" ]; then
_qsfp_type_check $i
fi
done
}
#QSFP type
function _qsfp_type_check {
local port=$1
local qsfp_type=`${I2C_UTILS} i2c_qsfp_type_get $(expr $port + 1)`
local identifier=`echo "$qsfp_type" | grep '^identifier=.*$' | sed -e 's/identifier=//g'`
if [ "${identifier}" == "11" ]; then
connector=`echo "$qsfp_type" | grep '^connector=.*$' | sed -e 's/connector=//g'`
case ${connector} in
21|23)
#DAC
if [ "${QSFP_ARRAY[$port]}" != "${connector}" ]; then
echo "Change Port $(expr $port + 1) to DAC"
QSFP_ARRAY[$port]=${connector}
${QSFP_SI_SCRIPT} dac $port >/dev/null
fi
;;
*)
#Optical
if [ "${QSFP_ARRAY[$port]}" != "${connector}" ]; then
echo "Change Port $(expr $port + 1) to Optical"
QSFP_ARRAY[$port]=${connector}
${QSFP_SI_SCRIPT} optical $port >/dev/null
fi
;;
esac
fi
}
#Docker exist check
function _docker_swss_check {
while true
do
# Check if syncd starts
result=`docker exec -i swss bash -c "echo -en \"SELECT 1\\nHLEN HIDDEN\" | redis-cli -p 6380 | sed -n 2p"` #TBD FIX ME
if [ "$result" == "3" ]; then
return
fi
sleep $INTERVAL
done
}
#Docker exist check
function _qsfp_si_cfg_script_check {
if [ -f ${QSFP_SI_SCRIPT} ] && [ -x ${QSFP_SI_SCRIPT} ]; then
echo "SI Script exists. Start monitor."
return
else
echo "SI Script not exist. Exit monitor."
exit
fi
}
# main function
function _main {
#Check SI Script
_qsfp_si_cfg_script_check
#Check docker swss is running
_docker_swss_check
while true
do
_qsfp_si_monitor
# Sleep while still handling signals
sleep $INTERVAL &
wait $!
done
}
_main