Skip to content

Commit 63034b2

Browse files
committed
Improve test logging and other misc improvements
1 parent b0987ff commit 63034b2

1 file changed

Lines changed: 96 additions & 44 deletions

File tree

tests/ecmp/test_fgnhg.py

Lines changed: 96 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -153,30 +153,42 @@ def setup_test_config(ptfadapter, duthost, ptfhost, cfg_facts, router_mac, net_p
153153
return port_list, ip_to_port, bank_0_port, bank_1_port
154154

155155

156+
def configure_dut(duthost, cmd):
157+
logger.info("Configuring dut with " + cmd)
158+
duthost.shell(cmd)
159+
160+
156161
def fg_ecmp(ptfhost, duthost, router_mac, net_ports, port_list, ip_to_port, bank_0_port, bank_1_port, prefix):
157162

163+
# Init base test params
158164
if isinstance(ipaddress.ip_network(prefix), ipaddress.IPv4Network):
159165
ipcmd = "ip route"
160166
else:
161167
ipcmd = "ipv6 route"
162168

169+
vtysh_base_cmd = "vtysh -c 'configure terminal'"
170+
171+
test_time = str(datetime.now().strftime('%Y-%m-%d-%H:%M:%S'))
172+
173+
163174
### Start test in state where 1 link is down, when nexthop addition occurs for link which is down, the nexthop
164175
### should not go to active
165176
shutdown_link = bank_0_port[0]
166177
dut_if_shutdown = ptf_to_dut_port_map[shutdown_link]
167-
duthost.shell("config interface shutdown " + dut_if_shutdown)
178+
logger.info("Initialize test by creating flows and checking basic ecmp, "
179+
"we start in a state where link " + dut_if_shutdown + " is down")
180+
181+
configure_dut(duthost, "config interface shutdown " + dut_if_shutdown)
168182
time.sleep(30)
169183

170184
# Now add the route and nhs
185+
cmd = vtysh_base_cmd
171186
for nexthop in ip_to_port:
172-
duthost.shell("vtysh -c 'configure terminal' -c '{} {} {}'".format(ipcmd, prefix, nexthop))
187+
cmd = cmd + " -c '{} {} {}'".format(ipcmd, prefix, nexthop)
188+
configure_dut(duthost, cmd)
173189
time.sleep(3)
174190

175-
test_time = str(datetime.now().strftime('%Y-%m-%d-%H:%M:%S'))
176-
177-
178-
### Sned flows with 1 link down, and check the hash distribution
179-
log_file = "/tmp/fg_ecmp_test.FgEcmpTest.{}.create_flows_with_1_link_down.log".format(test_time)
191+
# Calculate expected flow counts per port to verify in ptf host
180192
exp_flow_count = {}
181193
flows_per_nh = NUM_FLOWS/len(port_list)
182194
for port in port_list:
@@ -188,6 +200,9 @@ def fg_ecmp(ptfhost, duthost, router_mac, net_ports, port_list, ip_to_port, bank
188200
exp_flow_count[port] = exp_flow_count[port] + flows_to_redist/(len(bank_0_port) - 1)
189201
del exp_flow_count[shutdown_link]
190202

203+
log_file = "/tmp/fg_ecmp_test.FgEcmpTest.{}.create_flows_with_1_link_down.log".format(test_time)
204+
205+
# Send the packets
191206
ptf_runner(ptfhost,
192207
"ptftests",
193208
"fg_ecmp_test.FgEcmpTest",
@@ -199,7 +214,11 @@ def fg_ecmp(ptfhost, duthost, router_mac, net_ports, port_list, ip_to_port, bank
199214
log_file=log_file)
200215

201216

202-
### Hashing verification: Send the same flows again, and verify packets end up on the same ports for a given flow
217+
### Hashing verification: Send the same flows again,
218+
### and verify packets end up on the same ports for a given flow
219+
logger.info("Hashing verification: Send the same flows again, "
220+
"and verify packets end up on the same ports for a given flow")
221+
203222
log_file = "/tmp/fg_ecmp_test.FgEcmpTest.{}.initial_hash_check.log".format(test_time)
204223

205224
ptf_runner(ptfhost,
@@ -215,14 +234,18 @@ def fg_ecmp(ptfhost, duthost, router_mac, net_ports, port_list, ip_to_port, bank
215234

216235
### Send the same flows again, but unshut the port which was shutdown at the beginning of test
217236
### Check if hash buckets rebalanced as expected
218-
log_file = "/tmp/fg_ecmp_test.FgEcmpTest.{}.first_link_up.log".format(test_time)
219-
duthost.shell("config interface startup " + dut_if_shutdown)
237+
logger.info("Send the same flows again, but unshut " + dut_if_shutdown + " and check "
238+
"if flows reblanced as expected and are seen on now brought up link")
239+
240+
configure_dut(duthost, "config interface startup " + dut_if_shutdown)
220241
time.sleep(30)
221242

222243
flows_per_nh = NUM_FLOWS/len(port_list)
223244
for port in port_list:
224245
exp_flow_count[port] = flows_per_nh
225246

247+
log_file = "/tmp/fg_ecmp_test.FgEcmpTest.{}.first_link_up.log".format(test_time)
248+
226249
ptf_runner(ptfhost,
227250
"ptftests",
228251
"fg_ecmp_test.FgEcmpTest",
@@ -237,20 +260,24 @@ def fg_ecmp(ptfhost, duthost, router_mac, net_ports, port_list, ip_to_port, bank
237260

238261
### Send the same flows again, but withdraw one next-hop before sending the flows, check if hash bucket
239262
### rebalanced as expected, and the number of flows received on a link is as expected
240-
flows_for_withdrawn_nh_bank = (NUM_FLOWS/2)/(len(bank_0_port) - 1)
263+
logger.info("Send the same flows again, but withdraw one next-hop before sending the flows, check if hash bucket "
264+
"rebalanced as expected, and the number of flows received on a link is as expected")
265+
241266
withdraw_nh_port = bank_0_port[1]
267+
cmd = vtysh_base_cmd
268+
for nexthop, port in ip_to_port.items():
269+
if port == withdraw_nh_port:
270+
cmd = cmd + " -c 'no {} {} {}'".format(ipcmd, prefix, nexthop)
271+
configure_dut(duthost, cmd)
272+
time.sleep(3)
273+
274+
flows_for_withdrawn_nh_bank = (NUM_FLOWS/2)/(len(bank_0_port) - 1)
242275
for port in bank_0_port:
243276
if port != withdraw_nh_port:
244277
exp_flow_count[port] = flows_for_withdrawn_nh_bank
245278
del exp_flow_count[withdraw_nh_port]
246279

247-
for nexthop, port in ip_to_port.items():
248-
if port == withdraw_nh_port:
249-
duthost.shell("vtysh -c 'configure terminal' -c 'no {} {} {}'".format(ipcmd, prefix, nexthop))
250-
251-
252280
log_file = "/tmp/fg_ecmp_test.FgEcmpTest.{}.withdraw_nh.log".format(test_time)
253-
time.sleep(3)
254281

255282
ptf_runner(ptfhost,
256283
"ptftests",
@@ -264,19 +291,23 @@ def fg_ecmp(ptfhost, duthost, router_mac, net_ports, port_list, ip_to_port, bank
264291
log_file=log_file)
265292

266293

267-
### Send the same flows again, but disable one of the links associated to validate flow redistribution
294+
### Send the same flows again, but disable one of the links,
295+
### and check flow hash redistribution
268296
shutdown_link = bank_0_port[2]
297+
dut_if_shutdown = ptf_to_dut_port_map[shutdown_link]
298+
logger.info("Send the same flows again, but shutdown " + dut_if_shutdown + " and check "
299+
"the flow hash redistribution")
300+
301+
configure_dut(duthost, "config interface shutdown " + dut_if_shutdown)
302+
time.sleep(30)
303+
269304
flows_for_shutdown_links_bank = (NUM_FLOWS/2)/(len(bank_0_port) - 2)
270305
for port in bank_0_port:
271306
if port != withdraw_nh_port and port != shutdown_link:
272307
exp_flow_count[port] = flows_for_shutdown_links_bank
273308
del exp_flow_count[shutdown_link]
274309

275-
dut_if_shutdown = ptf_to_dut_port_map[shutdown_link]
276-
duthost.shell("config interface shutdown " + dut_if_shutdown)
277-
278310
log_file = "/tmp/fg_ecmp_test.FgEcmpTest.{}.link_down.log".format(test_time)
279-
time.sleep(30)
280311

281312
ptf_runner(ptfhost,
282313
"ptftests",
@@ -291,6 +322,13 @@ def fg_ecmp(ptfhost, duthost, router_mac, net_ports, port_list, ip_to_port, bank
291322

292323

293324
### Send the same flows again, but enable the link we disabled the last time
325+
### and check flow hash redistribution
326+
logger.info("Send the same flows again, but startup " + dut_if_shutdown + " and check "
327+
"the flow hash redistribution")
328+
329+
configure_dut(duthost, "config interface startup " + dut_if_shutdown)
330+
time.sleep(30)
331+
294332
exp_flow_count = {}
295333
flows_for_withdrawn_nh_bank = (NUM_FLOWS/2)/(len(bank_0_port) - 1)
296334
for port in bank_1_port:
@@ -299,10 +337,7 @@ def fg_ecmp(ptfhost, duthost, router_mac, net_ports, port_list, ip_to_port, bank
299337
if port != withdraw_nh_port:
300338
exp_flow_count[port] = flows_for_withdrawn_nh_bank
301339

302-
duthost.shell("config interface startup " + dut_if_shutdown)
303-
304340
log_file = "/tmp/fg_ecmp_test.FgEcmpTest.{}.second_link_up.log".format(test_time)
305-
time.sleep(30)
306341

307342
ptf_runner(ptfhost,
308343
"ptftests",
@@ -317,20 +352,24 @@ def fg_ecmp(ptfhost, duthost, router_mac, net_ports, port_list, ip_to_port, bank
317352

318353

319354
### Send the same flows again, but enable the next-hop which was down previously
320-
exp_flow_count = {}
321-
flows_per_nh = NUM_FLOWS/len(port_list)
322-
for port in port_list:
323-
exp_flow_count[port] = flows_per_nh
355+
### and check flow hash redistribution
356+
logger.info("Send the same flows again, but enable the next-hop which was down previously "
357+
" and check flow hash redistribution")
324358

359+
cmd = vtysh_base_cmd
325360
for nexthop, port in ip_to_port.items():
326361
if port == withdraw_nh_port:
327-
duthost.shell("vtysh -c 'configure terminal' -c '{} {} {}'".format(ipcmd, prefix, nexthop))
362+
cmd = cmd + " -c '{} {} {}'".format(ipcmd, prefix, nexthop)
363+
configure_dut(duthost, cmd)
364+
time.sleep(3)
328365

366+
exp_flow_count = {}
367+
flows_per_nh = NUM_FLOWS/len(port_list)
368+
for port in port_list:
369+
exp_flow_count[port] = flows_per_nh
329370

330371
log_file = "/tmp/fg_ecmp_test.FgEcmpTest.{}.add_nh.log".format(test_time)
331372

332-
time.sleep(3)
333-
334373
ptf_runner(ptfhost,
335374
"ptftests",
336375
"fg_ecmp_test.FgEcmpTest",
@@ -343,22 +382,27 @@ def fg_ecmp(ptfhost, duthost, router_mac, net_ports, port_list, ip_to_port, bank
343382
log_file=log_file)
344383

345384

346-
### Send the same flows again, but disable all next-hops in a bank to test flow redistribution to the other bank
385+
### Send the same flows again, but disable all next-hops in a bank
386+
### to test flow redistribution to the other bank
387+
logger.info("Send the same flows again, but disable all next-hops in a bank "
388+
"to test flow redistribution to the other bank")
389+
347390
withdraw_nh_bank = bank_0_port
391+
392+
cmd = vtysh_base_cmd
348393
for nexthop, port in ip_to_port.items():
349394
if port in withdraw_nh_bank:
350-
duthost.shell("vtysh -c 'configure terminal' -c 'no {} {} {}'".format(ipcmd, prefix, nexthop))
351-
352-
353-
log_file = "/tmp/fg_ecmp_test.FgEcmpTest.{}.withdraw_bank.log".format(test_time)
354-
395+
cmd = cmd + " -c 'no {} {} {}'".format(ipcmd, prefix, nexthop)
396+
configure_dut(duthost, cmd)
355397
time.sleep(3)
356398

357399
exp_flow_count = {}
358400
flows_per_nh = NUM_FLOWS/len(bank_1_port)
359401
for port in bank_1_port:
360402
exp_flow_count[port] = flows_per_nh
361403

404+
log_file = "/tmp/fg_ecmp_test.FgEcmpTest.{}.withdraw_bank.log".format(test_time)
405+
362406
ptf_runner(ptfhost,
363407
"ptftests",
364408
"fg_ecmp_test.FgEcmpTest",
@@ -371,23 +415,28 @@ def fg_ecmp(ptfhost, duthost, router_mac, net_ports, port_list, ip_to_port, bank
371415
log_file=log_file)
372416

373417

374-
### Send the same flows again, but enable 1 next-hop in a previously down bank to check if flows redistribute back to previously down bank
418+
### Send the same flows again, but enable 1 next-hop in a previously down bank to check
419+
### if flows redistribute back to previously down bank
420+
logger.info("Send the same flows again, but enable 1 next-hop in a previously down bank to check "
421+
"if flows redistribute back to previously down bank")
422+
375423
first_nh = bank_0_port[3]
424+
425+
cmd = vtysh_base_cmd
376426
for nexthop, port in ip_to_port.items():
377427
if port == first_nh:
378-
duthost.shell("vtysh -c 'configure terminal' -c '{} {} {}'".format(ipcmd, prefix, nexthop))
379-
380-
log_file = "/tmp/fg_ecmp_test.FgEcmpTest.{}.add_first_nh.log".format(test_time)
381-
428+
cmd = cmd + " -c '{} {} {}'".format(ipcmd, prefix, nexthop)
429+
configure_dut(duthost, cmd)
382430
time.sleep(3)
383431

384432
exp_flow_count = {}
385433
flows_per_nh = (NUM_FLOWS/2)/(len(bank_1_port))
386434
for port in bank_1_port:
387435
exp_flow_count[port] = flows_per_nh
388-
389436
exp_flow_count[first_nh] = NUM_FLOWS/2
390437

438+
log_file = "/tmp/fg_ecmp_test.FgEcmpTest.{}.add_first_nh.log".format(test_time)
439+
391440
ptf_runner(ptfhost,
392441
"ptftests",
393442
"fg_ecmp_test.FgEcmpTest",
@@ -399,8 +448,11 @@ def fg_ecmp(ptfhost, duthost, router_mac, net_ports, port_list, ip_to_port, bank
399448
qlen=1000,
400449
log_file=log_file)
401450

451+
logger.info("Completed ...")
452+
402453

403454
def cleanup(duthost):
455+
logger.info("Start cleanup")
404456
config_reload(duthost)
405457

406458

0 commit comments

Comments
 (0)