forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check internface status before start bgp (sonic-net#19189)
Why I did it With the following PR, make bgp start after swss. sonic-net#12381 bgp started after the swss but still ahead of the interface init. Jun 12 04:53:59.768546 bjw-can-7050qx-1 NOTICE root: Starting swss service... ... Jun 12 04:54:12.725418 bjw-can-7050qx-1 NOTICE admin: Starting bgp service... ... Jun 12 04:54:43.036682 bjw-can-7050qx-1 NOTICE swss#orchagent: :- updatePortOperStatus: Port Ethernet0 oper state set from down to up Jun 12 04:54:43.191143 bjw-can-7050qx-1 NOTICE swss#orchagent: :- updatePortOperStatus: Port Ethernet4 oper state set from down to up Jun 12 04:54:43.207343 bjw-can-7050qx-1 NOTICE swss#orchagent: :- updatePortOperStatus: Port Ethernet12 oper state set from down to up Work item tracking Microsoft ADO (number only): 26557087 How I did it Check the interface status before start bgp. waiting timeout is about 60s, will output a warning message if interface still down. How to verify it build debug image, boot the image, check the syslog. and bgp process. syslog:1098:Jun 3 03:10:30.338071 str-a7060cx-acs-10 INFO bgp#root: [bgpd] It took 0.498398 seconds for interface to become ready
- Loading branch information
Showing
4 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Define global timeout in seconds | ||
GLOBAL_TIMEOUT=60 | ||
GLOBAL_TIMEOUT_REACHED="false" | ||
|
||
function wait_iface_ready | ||
{ | ||
IFACE_NAME=$1 | ||
IFACE_CIDR=$2 | ||
START_TIME=$3 | ||
|
||
# First phase: wait for all interfaces until the global timeout is reached | ||
while [ "$GLOBAL_TIMEOUT_REACHED" == "false" ]; do | ||
CURRENT_TIME=$(date +%s.%N) | ||
ELAPSED_TIME=$(awk -v current_time=$CURRENT_TIME -v start_time=$START_TIME 'BEGIN {print current_time - start_time}') | ||
|
||
# Check if global timeout is reached | ||
if (( $(awk -v elapsed_time=$ELAPSED_TIME -v global_timeout=$GLOBAL_TIMEOUT 'BEGIN {print (elapsed_time >= global_timeout)}') )); then | ||
GLOBAL_TIMEOUT_REACHED="true" | ||
break | ||
fi | ||
|
||
RESULT=$(sonic-db-cli STATE_DB HGET "INTERFACE_TABLE|${IFACE_NAME}|${IFACE_CIDR}" "state" 2> /dev/null) | ||
if [ x"$RESULT" == x"ok" ]; then | ||
return 0 | ||
fi | ||
sleep 0.5 | ||
done | ||
|
||
# Second phase: apply per-interface timeout | ||
# Counter to track the number of iterations | ||
ITERATION=0 | ||
while [ $ITERATION -lt 3 ]; do | ||
RESULT=$(sonic-db-cli STATE_DB HGET "INTERFACE_TABLE|${IFACE_NAME}|${IFACE_CIDR}" "state" 2> /dev/null) | ||
if [ x"$RESULT" == x"ok" ]; then | ||
return 0 | ||
fi | ||
|
||
sleep 0.5 | ||
((ITERATION++)) | ||
done | ||
|
||
logger -p warning "[bgpd] warning: Interface ${IFACE_NAME} not ready." | ||
return 1 | ||
} | ||
|
||
start=$(date +%s.%N) | ||
|
||
{% for (name, prefix) in INTERFACE|pfx_filter %} | ||
{% if prefix | ipv4 %} | ||
wait_iface_ready {{ name }} {{ prefix }} $start | ||
{% endif %} | ||
{% endfor %} | ||
|
||
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %} | ||
{% if prefix | ipv4 %} | ||
wait_iface_ready {{ name }} {{ prefix }} $start | ||
{% endif %} | ||
{% endfor %} | ||
|
||
{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %} | ||
{% if prefix | ipv4 %} | ||
wait_iface_ready {{ name }} {{ prefix }} $start | ||
{% endif %} | ||
{% endfor %} | ||
|
||
end=$(date +%s.%N) | ||
timespan=$(awk -v start=$start -v end=$end 'BEGIN {print end - start}') | ||
logger -p info "[bgpd] It took ${timespan} seconds for interfaces to become ready" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters