Skip to content

Commit 34f9a64

Browse files
authored
[DHCP_RELAY] Updated wait_for_intf.sh to wait for ipv6 global and link local addr (#12273)
- Why I did it Fixes #11431 - How I did it dhcp6relay binds to ipv6 addresses configured on these vlan interfaces Thus check if they are ready before launching dhcp6relay - How to verify it Unit Tests Tested on a live device Signed-off-by: Vivek Reddy Karri <[email protected]>
1 parent 257cc96 commit 34f9a64

File tree

5 files changed

+77
-1
lines changed

5 files changed

+77
-1
lines changed

dockers/docker-dhcp-relay/wait_for_intf.sh.j2

+26
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,28 @@ function wait_until_iface_ready
2121
echo "Interface ${IFACE_NAME} is ready!"
2222
}
2323

24+
function check_for_ipv6_link_local
25+
{
26+
IFACE_NAME=$1
27+
echo "Waiting until interface ${IFACE_NAME} has a link-local ipv6 address configured...."
28+
29+
# Status of link local address is not populated in STATE_DB
30+
while true; do
31+
HAS_LL=$(ip -6 addr show ${IFACE_NAME} scope link 2> /dev/null)
32+
RC=$?
33+
if [[ ${RC} == "0" ]] && [[ ! -z ${HAS_LL} ]]; then
34+
break
35+
fi
36+
37+
sleep 1
38+
done
39+
40+
echo "Link-Local address is configured on ${IFACE_NAME}"
41+
}
2442

2543
# Wait for all interfaces with IPv4 addresses to be up and ready
44+
# dhcp6relay binds to ipv6 addresses configured on these vlan ifaces
45+
# Thus check if they are ready before launching dhcp6relay
2646
{% for (name, prefix) in INTERFACE|pfx_filter %}
2747
{% if prefix | ipv4 %}
2848
wait_until_iface_ready {{ name }} {{ prefix }}
@@ -32,6 +52,12 @@ wait_until_iface_ready {{ name }} {{ prefix }}
3252
{% if prefix | ipv4 %}
3353
wait_until_iface_ready {{ name }} {{ prefix }}
3454
{% endif %}
55+
{% if prefix | ipv6 %}
56+
{% if DHCP_RELAY and name in DHCP_RELAY %}
57+
wait_until_iface_ready {{ name }} {{ prefix }}
58+
check_for_ipv6_link_local {{ name }}
59+
{% endif %}
60+
{% endif %}
3561
{% endfor %}
3662
{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %}
3763
{% if prefix | ipv4 %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"VLAN_INTERFACE": {
3+
"Vlan1000|fc02:2000::2/24": {}
4+
}
5+
}

src/sonic-config-engine/tests/sample_output/py2/wait_for_intf.sh

+22
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,32 @@ function wait_until_iface_ready
2121
echo "Interface ${IFACE_NAME} is ready!"
2222
}
2323

24+
function check_for_ipv6_link_local
25+
{
26+
IFACE_NAME=$1
27+
echo "Waiting until interface ${IFACE_NAME} has a link-local ipv6 address configured...."
28+
29+
# Status of link local address is not populated in STATE_DB
30+
while true; do
31+
HAS_LL=$(ip -6 addr show ${IFACE_NAME} scope link 2> /dev/null)
32+
RC=$?
33+
if [[ ${RC} == "0" ]] && [[ ! -z ${HAS_LL} ]]; then
34+
break
35+
fi
36+
37+
sleep 1
38+
done
39+
40+
echo "Link-Local address is configured on ${IFACE_NAME}"
41+
}
2442

2543
# Wait for all interfaces with IPv4 addresses to be up and ready
44+
# dhcp6relay binds to ipv6 addresses configured on these vlan ifaces
45+
# Thus check if they are ready before launching dhcp6relay
2646
wait_until_iface_ready Vlan2000 192.168.200.1/27
2747
wait_until_iface_ready Vlan1000 192.168.0.1/27
48+
wait_until_iface_ready Vlan1000 fc02:2000::2/24
49+
check_for_ipv6_link_local Vlan1000
2850
wait_until_iface_ready PortChannel02 10.0.0.58/31
2951
wait_until_iface_ready PortChannel03 10.0.0.60/31
3052
wait_until_iface_ready PortChannel04 10.0.0.62/31

src/sonic-config-engine/tests/sample_output/py3/wait_for_intf.sh

+22
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,30 @@ function wait_until_iface_ready
2121
echo "Interface ${IFACE_NAME} is ready!"
2222
}
2323

24+
function check_for_ipv6_link_local
25+
{
26+
IFACE_NAME=$1
27+
echo "Waiting until interface ${IFACE_NAME} has a link-local ipv6 address configured...."
28+
29+
# Status of link local address is not populated in STATE_DB
30+
while true; do
31+
HAS_LL=$(ip -6 addr show ${IFACE_NAME} scope link 2> /dev/null)
32+
RC=$?
33+
if [[ ${RC} == "0" ]] && [[ ! -z ${HAS_LL} ]]; then
34+
break
35+
fi
36+
37+
sleep 1
38+
done
39+
40+
echo "Link-Local address is configured on ${IFACE_NAME}"
41+
}
2442

2543
# Wait for all interfaces with IPv4 addresses to be up and ready
44+
# dhcp6relay binds to ipv6 addresses configured on these vlan ifaces
45+
# Thus check if they are ready before launching dhcp6relay
46+
wait_until_iface_ready Vlan1000 fc02:2000::2/24
47+
check_for_ipv6_link_local Vlan1000
2648
wait_until_iface_ready Vlan1000 192.168.0.1/27
2749
wait_until_iface_ready Vlan2000 192.168.200.1/27
2850
wait_until_iface_ready PortChannel01 10.0.0.56/31

src/sonic-config-engine/tests/test_j2files.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ def test_ports_json(self):
142142

143143
def test_dhcp_relay(self):
144144
# Test generation of wait_for_intf.sh
145+
dhc_sample_data = os.path.join(self.test_dir, "dhcp-relay-sample.json")
145146
template_path = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-dhcp-relay', 'wait_for_intf.sh.j2')
146-
argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -t ' + template_path + ' > ' + self.output_file
147+
argument = '-m ' + self.t0_minigraph + ' -j ' + dhc_sample_data + ' -p ' + self.t0_port_config + ' -t ' + template_path + ' > ' + self.output_file
147148
self.run_script(argument)
148149
self.assertTrue(utils.cmp(os.path.join(self.test_dir, 'sample_output', utils.PYvX_DIR, 'wait_for_intf.sh'), self.output_file))
149150

0 commit comments

Comments
 (0)