Skip to content

Commit 24b3dc7

Browse files
authored
Manual cherry-pick of PR: Adjusting test_stress_arp is it can handle cases of ipv6-only topologies . sonic-net#20932 (sonic-net#923)
Manual cherry-pick of PR sonic-net#20932 Adjusting test_stress_arp is it can handle cases of ipv6-only topologies .
1 parent 3e10ed4 commit 24b3dc7

2 files changed

Lines changed: 36 additions & 16 deletions

File tree

tests/arp/arp_utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
BASE_MAC_PREFIX = "00:00:01"
1111

1212

13-
def clear_dut_arp_cache(duthost, ns_option=None):
13+
def clear_dut_arp_cache(duthost, ns_option=None, is_ipv6=False):
1414
logger.info("Clearing {} neighbor table".format(duthost.hostname))
15-
arp_flush_cmd = "ip -stats neigh flush all"
15+
ipv6_cmd = '-6' if is_ipv6 else ''
16+
arp_flush_cmd = "ip {} -stats neigh flush all".format(ipv6_cmd)
1617
if ns_option:
17-
arp_flush_cmd = "ip -stats {} neigh flush all".format(ns_option)
18+
arp_flush_cmd = "ip {} -stats {} neigh flush all".format(ipv6_cmd, ns_option)
1819
duthost.shell(arp_flush_cmd)
1920

2021

tests/arp/test_stress_arp.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from scapy.all import Ether, IPv6, ICMPv6ND_NS, ICMPv6NDOptSrcLLAddr, in6_getnsmac, \
1010
in6_getnsma, inet_pton, inet_ntop, socket
1111
from ipaddress import ip_address, ip_network
12-
from tests.common.utilities import wait_until, increment_ipv6_addr
12+
from tests.common.utilities import wait_until, increment_ipv6_addr, is_ipv6_only_topology
1313
from tests.common.errors import RunAnsibleModuleFail
1414

1515

@@ -22,7 +22,8 @@
2222
logger = logging.getLogger(__name__)
2323

2424
pytestmark = [
25-
pytest.mark.topology('t0')
25+
pytest.mark.topology('t0'),
26+
pytest.mark.dualtor_active_standby_toggle_to_enum_tor
2627
]
2728

2829
LOOP_TIMES_LEVEL_MAP = {
@@ -35,9 +36,11 @@
3536

3637

3738
@pytest.fixture(autouse=True)
38-
def arp_cache_fdb_cleanup(duthost):
39+
def arp_cache_fdb_cleanup(duthosts, rand_one_dut_hostname, tbinfo):
40+
is_ipv6_only = is_ipv6_only_topology(tbinfo)
41+
duthost = duthosts[rand_one_dut_hostname]
3942
try:
40-
clear_dut_arp_cache(duthost)
43+
clear_dut_arp_cache(duthost, is_ipv6=is_ipv6_only)
4144
fdb_cleanup(duthost)
4245
except RunAnsibleModuleFail as e:
4346
if 'Failed to send flush request: No such file or directory' in str(e):
@@ -51,8 +54,10 @@ def arp_cache_fdb_cleanup(duthost):
5154

5255
# Ensure clean test environment even after failing
5356
try:
54-
clear_dut_arp_cache(duthost)
55-
fdb_cleanup(duthost)
57+
dut_list = duthosts if "dualtor-aa" in tbinfo["topo"]["name"] else [duthost]
58+
for dut in dut_list:
59+
clear_dut_arp_cache(dut, is_ipv6=is_ipv6_only)
60+
fdb_cleanup(dut)
5661
except RunAnsibleModuleFail as e:
5762
if 'Failed to send flush request: No such file or directory' in str(e):
5863
logger.warning("Failed to clear arp cache or cleanup fdb table, file may not exist yet")
@@ -90,13 +95,15 @@ def genrate_ipv4_ip():
9095
return list(ptf_intf_ipv4_hosts)
9196

9297

93-
def test_ipv4_arp(duthost, garp_enabled, ip_and_intf_info, intfs_for_test,
98+
def test_ipv4_arp(duthosts, enum_rand_one_per_hwsku_frontend_hostname,
99+
garp_enabled, ip_and_intf_info, intfs_for_test,
94100
ptfadapter, get_function_completeness_level):
95101
"""
96102
Send gratuitous ARP (GARP) packet sfrom the PTF to the DUT
97103
98104
The DUT should learn the (previously unseen) ARP info from the packet
99105
"""
106+
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
100107
normalized_level = get_function_completeness_level
101108
if normalized_level is None:
102109
normalized_level = "debug"
@@ -106,6 +113,11 @@ def test_ipv4_arp(duthost, garp_enabled, ip_and_intf_info, intfs_for_test,
106113
pytest_assert(ipv4_available > 0 and fdb_available > 0, "Entries have been filled")
107114

108115
arp_available = min(min(ipv4_available, fdb_available), ENTRIES_NUMBERS)
116+
# Limit ARP scale based on available NH entries
117+
asic_type = duthost.facts["asic_type"]
118+
if 'cisco-8000' in asic_type:
119+
ipv4_nh_available = get_crm_resources(duthost, "ipv4_nexthop", "available")
120+
arp_available = min(arp_available, ipv4_nh_available)
109121

110122
pytest_require(garp_enabled, 'Gratuitous ARP not enabled for this device')
111123
ptf_intf_ipv4_hosts = genrate_ipv4_ip()
@@ -181,8 +193,11 @@ def add_nd(ptfadapter, ip_and_intf_info, ptf_intf_index, nd_available):
181193
logger.info("Sending {} ipv6 neighbor entries".format(nd_available))
182194

183195

184-
def test_ipv6_nd(duthost, ptfhost, config_facts, tbinfo, ip_and_intf_info,
196+
def test_ipv6_nd(duthosts, enum_rand_one_per_hwsku_frontend_hostname,
197+
ptfhost, config_facts, tbinfo, ip_and_intf_info,
185198
ptfadapter, get_function_completeness_level, proxy_arp_enabled):
199+
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
200+
is_ipv6_only = is_ipv6_only_topology(tbinfo)
186201
_, _, ptf_intf_ipv6_addr, _, ptf_intf_index = ip_and_intf_info
187202
ptf_intf_ipv6_addr = increment_ipv6_addr(ptf_intf_ipv6_addr)
188203
pytest_require(proxy_arp_enabled, 'Proxy ARP not enabled for all VLANs')
@@ -198,7 +213,10 @@ def test_ipv6_nd(duthost, ptfhost, config_facts, tbinfo, ip_and_intf_info,
198213
pytest_assert(ipv6_available > 0 and fdb_available > 0, "Entries have been filled")
199214

200215
nd_available = min(min(ipv6_available, fdb_available), ENTRIES_NUMBERS)
201-
216+
asic_type = duthost.facts["asic_type"]
217+
if 'cisco-8000' in asic_type:
218+
ipv6_nh_available = get_crm_resources(duthost, "ipv6_nexthop", "available")
219+
nd_available = min(nd_available, ipv6_nh_available)
202220
while loop_times > 0:
203221
loop_times -= 1
204222
try:
@@ -213,7 +231,7 @@ def test_ipv6_nd(duthost, ptfhost, config_facts, tbinfo, ip_and_intf_info,
213231
"Neighbor Table Add failed")
214232
finally:
215233
try:
216-
clear_dut_arp_cache(duthost)
234+
clear_dut_arp_cache(duthost, is_ipv6=is_ipv6_only)
217235
fdb_cleanup(duthost)
218236
except RunAnsibleModuleFail as e:
219237
if 'Failed to send flush request: No such file or directory' in str(e):
@@ -246,6 +264,7 @@ def test_ipv6_nd_incomplete(duthost, ptfhost, config_facts, tbinfo, ip_and_intf_
246264
ptfadapter, get_function_completeness_level, proxy_arp_enabled):
247265
_, _, ptf_intf_ipv6_addr, _, ptf_intf_index = ip_and_intf_info
248266
ptf_intf_ipv6_addr = increment_ipv6_addr(ptf_intf_ipv6_addr)
267+
is_ipv6_only = is_ipv6_only_topology(tbinfo)
249268
pytest_require(proxy_arp_enabled, 'Proxy ARP not enabled for all VLANs')
250269
pytest_require(ptf_intf_ipv6_addr is not None, 'No IPv6 VLAN address configured on device')
251270

@@ -272,7 +291,7 @@ def test_ipv6_nd_incomplete(duthost, ptfhost, config_facts, tbinfo, ip_and_intf_
272291
logger.info("original nf_conntrack_icmpv6_timeout: {}".format(orig_conntrack_icmpv6_timeout))
273292

274293
try:
275-
clear_dut_arp_cache(duthost)
294+
clear_dut_arp_cache(duthost, is_ipv6=is_ipv6_only)
276295

277296
duthost.command("conntrack -F")
278297

@@ -286,7 +305,7 @@ def test_ipv6_nd_incomplete(duthost, ptfhost, config_facts, tbinfo, ip_and_intf_
286305
conntrack_cnt_post = int(duthost.command("cat /proc/sys/net/netfilter/nf_conntrack_count")["stdout"])
287306
logger.info("nf_conntrack_count post test: {}".format(conntrack_cnt_post))
288307

289-
pytest_assert((conntrack_cnt_post - conntrack_cnt_pre) < tgt_conntrack_cnt * 0.1,
308+
pytest_assert((conntrack_cnt_post - conntrack_cnt_pre) < tgt_conntrack_cnt,
290309
"{} echo requests cause large increase in conntrack entries".format(tgt_conntrack_cnt))
291310

292311
pytest_assert("[UNREPLIED]" not in duthost.command("conntrack -f ipv6 -L dying")["stdout"],
@@ -302,4 +321,4 @@ def test_ipv6_nd_incomplete(duthost, ptfhost, config_facts, tbinfo, ip_and_intf_
302321

303322
duthost.command("conntrack -F")
304323

305-
clear_dut_arp_cache(duthost)
324+
clear_dut_arp_cache(duthost, is_ipv6=is_ipv6_only)

0 commit comments

Comments
 (0)