Skip to content

Commit 5b33a16

Browse files
authored
Enhance vxlan decap test to support non-portchannel testcases (sonic-net#17105)
What is the motivation for this PR? The vxlan-decap testcases cannot be supported in some testbeds without port-channel How did you do it? Adapting the test parameters on both portchannel and non-portchannel scenarioes. How did you verify/test it? Run it on non-portchannel platform: Signed-off-by: Ze Gan <ganze718@gmail.com>
1 parent 1c3162c commit 5b33a16

File tree

2 files changed

+45
-23
lines changed

2 files changed

+45
-23
lines changed

ansible/roles/test/files/ptftests/py3/vxlan-decap.py

+44-23
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
"""
88
# The test checks vxlan decapsulation for the dataplane.
99
# The test runs three tests for each vlan on the DUT:
10-
# 1. 'Vxlan' : Sends encapsulated packets to PortChannel interfaces and expects to see
10+
# 1. 'Vxlan' : Sends encapsulated packets to DUT interfaces and expects to see
1111
# the decapsulated inner packets on the corresponding vlan interface.
12-
# 2. 'RegularLAGtoVLAN' : Sends regular packets to PortChannel interfaces and expects to see
12+
# 2. 'RegularDUTtoVLAN' : Sends regular packets to DUT interfaces and expects to see
1313
# the packets on the corresponding vlan interface.
14-
# 3. 'RegularVLANtoLAG' : Sends regular packets to Vlan member interfaces and expects to see
15-
# the packets on the one of PortChannel interfaces.
14+
# 3. 'RegularVLANtoDUT' : Sends regular packets to Vlan member interfaces and expects to see
15+
# the packets on the one of DUT interfaces.
1616
#
1717
# The test has 6 parameters:
1818
# 1. 'config_file' is a filename of a file which contains all necessary information to run the test.
@@ -37,6 +37,7 @@
3737
import socket
3838
import struct
3939
import re
40+
import ipaddress
4041

4142
import ptf
4243
import ptf.packet as scapy
@@ -48,6 +49,14 @@
4849
from device_connection import DeviceConnection
4950

5051

52+
def is_valid_ipv4(ip_str):
53+
try:
54+
ipaddress.IPv4Address(ip_str)
55+
return True
56+
except ipaddress.AddressValueError:
57+
return False
58+
59+
5160
def count_matched_packets_helper(test, exp_packet, exp_packet_number, port=None, device_number=0, timeout=1):
5261
"""
5362
Add exp_packet_number to original ptf interface in order to
@@ -217,9 +226,10 @@ def setUp(self):
217226
with open(config) as fp:
218227
graph = json.load(fp)
219228

220-
self.pc_info = []
229+
self.intf_info = []
221230
self.net_ports = []
222231
self.all_active_net_ports = []
232+
# To portchannels interfaces
223233
for name, val in graph['minigraph_portchannels'].items():
224234
members = [graph['minigraph_port_indices'][member]
225235
for member in val['members']]
@@ -239,7 +249,18 @@ def setUp(self):
239249
raise Exception(
240250
"Portchannel '%s' ip address is not found" % name)
241251

242-
self.pc_info.append((ip, members))
252+
self.intf_info.append((ip, members))
253+
254+
# To non portchannels interfaces
255+
for d in graph['minigraph_interfaces']:
256+
intf = d['attachto']
257+
if (intf in graph['minigraph_portchannels'] or
258+
intf not in graph['minigraph_port_indices'] or
259+
'peer_addr' not in d or
260+
not is_valid_ipv4(d['peer_addr'])):
261+
continue
262+
self.intf_info.append((d['peer_addr'], [graph['minigraph_port_indices'][intf]]))
263+
self.net_ports.append(graph['minigraph_port_indices'][intf])
243264

244265
self.tests = []
245266
vni_base = 336
@@ -248,7 +269,7 @@ def setUp(self):
248269
test['name'] = name
249270
test['intf_alias'] = data['members']
250271
test['acc_ports'] = [graph['minigraph_port_indices'][member]
251-
for member in data['members']]
272+
for member in data['members'] if member in graph['minigraph_port_indices']]
252273
vlan_id = int(name.replace('Vlan', ''))
253274
test['vni'] = vni_base + vlan_id
254275
test['src_ip'] = "8.8.8.8"
@@ -344,10 +365,10 @@ def warmup(self):
344365
err = ''
345366
trace = ''
346367
ret = 0
347-
TIMEOUT = 60
368+
TIMEOUT = 300
348369
try:
349370
for test in self.tests:
350-
self.RegularLAGtoVLAN(test, True)
371+
self.RegularDUTtoVLAN(test, True)
351372
# wait sometime for DUT to build FDB and ARP table
352373
res = self.wait_dut(test, TIMEOUT)
353374
self.log_dut_status()
@@ -390,19 +411,19 @@ def work_test(self):
390411
for test in self.tests:
391412
self.log(test['name'])
392413

393-
res_f, out_f = self.RegularLAGtoVLAN(test)
394-
self.log("RegularLAGtoVLAN = {} {}".format(res_f, out_f))
414+
res_f, out_f = self.RegularDUTtoVLAN(test)
415+
self.log("RegularDUTtoVLAN = {} {}".format(res_f, out_f))
395416
if not res_f:
396417
self.log_dut_status()
397418
self.assertTrue(
398-
res_f, "RegularLAGtoVLAN test failed:\n %s\n" % (out_f))
419+
res_f, "RegularDUTtoVLAN test failed:\n %s\n" % (out_f))
399420

400-
res_t, out_t = self.RegularVLANtoLAG(test)
401-
self.log("RegularVLANtoLAG = {} {}".format(res_t, out_t))
421+
res_t, out_t = self.RegularVLANtoDUT(test)
422+
self.log("RegularVLANtoDUT = {} {}".format(res_t, out_t))
402423
if not res_t:
403424
self.log_dut_status()
404425
self.assertTrue(
405-
res_t, "RegularVLANtoLAG test failed:\n %s\n" % (out_t))
426+
res_t, "RegularVLANtoDUT test failed:\n %s\n" % (out_t))
406427

407428
res_v, out_v = self.Vxlan(test)
408429
self.log("Vxlan = {} {}".format(res_v, out_v))
@@ -453,10 +474,10 @@ def Vxlan(self, test):
453474
return False, out + " | net_port_rel=%d acc_port_rel=%d" % (i, j)
454475
return True, ""
455476

456-
def RegularLAGtoVLAN(self, test, wu=False):
477+
def RegularDUTtoVLAN(self, test, wu=False):
457478
for i, n in enumerate(self.net_ports):
458479
for j, a in enumerate(test['acc_ports']):
459-
res, out = self.checkRegularRegularLAGtoVLAN(a, n, test, wu)
480+
res, out = self.checkRegularRegularDUTtoVLAN(a, n, test, wu)
460481
if wu:
461482
# Wait a short time for building FDB and ARP table
462483
time.sleep(0.5)
@@ -467,16 +488,16 @@ def RegularLAGtoVLAN(self, test, wu=False):
467488
break
468489
return True, ""
469490

470-
def RegularVLANtoLAG(self, test):
471-
for i, (dst, ports) in enumerate(self.pc_info):
491+
def RegularVLANtoDUT(self, test):
492+
for i, (dst, ports) in enumerate(self.intf_info):
472493
for j, a in enumerate(test['acc_ports']):
473-
res, out = self.checkRegularRegularVLANtoLAG(
494+
res, out = self.checkRegularRegularVLANtoDUT(
474495
a, ports, dst, test)
475496
if not res:
476-
return False, out + " | pc_info_rel=%d acc_port_rel=%d" % (i, j)
497+
return False, out + " | intf_info_rel=%d acc_port_rel=%d" % (i, j)
477498
return True, ""
478499

479-
def checkRegularRegularVLANtoLAG(self, acc_port, pc_ports, dst_ip, test):
500+
def checkRegularRegularVLANtoDUT(self, acc_port, pc_ports, dst_ip, test):
480501
src_mac = self.ptf_mac_addrs['eth%d' % acc_port]
481502
dst_mac = self.vlan_mac
482503
src_ip = test['vlan_ip_prefixes'][acc_port]
@@ -522,7 +543,7 @@ def checkRegularRegularVLANtoLAG(self, acc_port, pc_ports, dst_ip, test):
522543
out = "sent = %d rcvd = %d | src_port=%s dst_ports=%s | src_mac=%s dst_mac=%s src_ip=%s dst_ip=%s" % arg
523544
return rv, out
524545

525-
def checkRegularRegularLAGtoVLAN(self, acc_port, net_port, test, wu):
546+
def checkRegularRegularDUTtoVLAN(self, acc_port, net_port, test, wu):
526547
src_mac = self.random_mac
527548
dst_mac = self.dut_mac
528549
src_ip = test['src_ip']

tests/vxlan/test_vxlan_decap.py

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def prepare_ptf(ptfhost, mg_facts, duthost, unslctd_mg_facts=None):
6161
"minigraph_lo_interfaces": mg_facts["minigraph_lo_interfaces"],
6262
"minigraph_vlans": mg_facts["minigraph_vlans"],
6363
"minigraph_vlan_interfaces": mg_facts["minigraph_vlan_interfaces"],
64+
"minigraph_interfaces": mg_facts["minigraph_interfaces"],
6465
"dut_mac": duthost.facts["router_mac"],
6566
"vlan_mac": vlan_mac
6667
}

0 commit comments

Comments
 (0)