Skip to content
18 changes: 3 additions & 15 deletions ansible/roles/test/files/ptftests/hash_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def setUp(self):
self.dataplane = ptf.dataplane_instance
self.fib = fib.Fib(self.test_params['fib_info'])
self.router_mac = self.test_params['router_mac']
self.in_ports = self.test_params['in_ports']

self.src_ip_range = [unicode(x) for x in self.test_params['src_ip_range'].split(',')]
self.dst_ip_range = [unicode(x) for x in self.test_params['dst_ip_range'].split(',')]
Expand All @@ -58,19 +59,6 @@ def setUp(self):

self.balancing_range = self.test_params.get('balancing_range', self.DEFAULT_BALANCING_RANGE)

# Provide the list of all UP interfaces with index in sequence order starting from 0
if self.test_params['testbed_type'] == 't1' or self.test_params['testbed_type'] == 't1-lag':
self.src_ports = range(0, 32)
if self.test_params['testbed_type'] == 't1-64-lag' or self.test_params['testbed_type'] == 't1-64-lag-clet':
self.src_ports = [0, 1, 4, 5, 16, 17, 20, 21, 34, 36, 37, 38, 39, 42, 44, 45, 46, 47, 50, 52, 53, 54, 55, 58, 60, 61, 62, 63]
if self.test_params['testbed_type'] == 't0':
self.src_ports = range(1, 25) + range(28, 32)
if self.test_params['testbed_type'] == 't0-56':
self.src_ports = [0, 1, 4, 5, 8, 9] + range(12, 18) + [20, 21, 24, 25, 28, 29, 32, 33, 36, 37] + range(40, 46) + [48, 49, 52, 53]
if self.test_params['testbed_type'] == 't0-64':
self.src_ports = range(0, 2) + range(4, 18) + range(20, 33) + range(36, 43) + range(48, 49) + range(52, 59)
if self.test_params['testbed_type'] == 't0-116':
self.src_ports = range(0, 120)
#---------------------------------------------------------------------

def check_hash(self, hash_key):
Expand All @@ -81,11 +69,11 @@ def check_hash(self, hash_key):
if exp_port_list <= 1:
logging.warning("{} has only {} nexthop".format(dst_ip, exp_port_list))
assert False
in_port = random.choice([port for port in self.src_ports if port not in exp_port_list])
in_port = random.choice([port for port in self.in_ports if port not in exp_port_list])

hit_count_map = {}
if hash_key == 'ingress-port': # The sample is too little for hash_key ingress-port, check it loose(just verify if the asic actually used the hash field as a load-balancing factor)
for in_port in [port for port in self.src_ports if port not in exp_port_list]:
for in_port in [port for port in self.in_ports if port not in exp_port_list]:
logging.info("in_port: {}".format(in_port))
(matched_index, _) = self.check_ip_route(hash_key, in_port, dst_ip, exp_port_list)
hit_count_map[matched_index] = hit_count_map.get(matched_index, 0) + 1
Expand Down
32 changes: 31 additions & 1 deletion tests/fib/test_fib.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,31 @@ def build_fib(duthost, config_facts, fibfile, t):
else:
ofp.write("{} []\n".format(prefix))

def get_router_interface_ports(config_facts, testbed):
"""
get all physical ports associated with router interface (physical router interface, port channel router interface and vlan router interface)
"""

ports = config_facts.get('INTERFACE', {}).keys()
portchannels_member_ports = []
vlan_untag_ports = []
portchannels_name = config_facts.get('PORTCHANNEL_INTERFACE', {}).keys()
if portchannels_name:
for po_name in portchannels_name:
for port_name in config_facts.get('PORTCHANNEL', {})[po_name]['members']:
portchannels_member_ports.append(port_name)
if 't0' in testbed['topo']['name']:
vlans = config_facts.get('VLAN_INTERFACE', {}).keys()
for vlan in vlans:
vlan_member_info = config_facts.get('VLAN_MEMBER', {}).get(vlan, {})
if vlan_member_info:
for port_name, tag_mode in vlan_member_info.items():
if tag_mode['tagging_mode'] == 'untagged':
vlan_untag_ports.append(port_name)

router_interface_ports = ports + portchannels_member_ports + vlan_untag_ports

return router_interface_ports

@pytest.mark.parametrize("ipv4, ipv6, mtu", [pytest.param(True, True, 1514)])
def test_fib(testbed, duthost, ptfhost, ipv4, ipv6, mtu):
Expand Down Expand Up @@ -129,7 +154,10 @@ def setup_hash(self, testbed, duthost, ptfhost):

g_vars['testbed_type'] = testbed['topo']['name']
g_vars['router_mac'] = duthost.shell('sonic-cfggen -d -v \'DEVICE_METADATA.localhost.mac\'')["stdout_lines"][0].decode("utf-8")


in_ports_name = get_router_interface_ports(config_facts, testbed)
g_vars['in_ports'] = [config_facts.get('port_index_map', {})[p] for p in in_ports_name]

def test_hash_ipv4(self, ptfhost):
log_file = "/tmp/hash_test.HashTest.ipv4.{}.log".format(self.t)
logging.info("PTF log file: %s" % log_file)
Expand All @@ -145,6 +173,7 @@ def test_hash_ipv4(self, ptfhost):
"fib_info": "/root/fib_info.txt",
"src_ip_range": ",".join(src_ip_range),
"dst_ip_range": ",".join(dst_ip_range),
"in_ports": g_vars['in_ports'],
"hash_keys": self.hash_keys },
log_file=log_file,
socket_recv_size=16384)
Expand All @@ -164,6 +193,7 @@ def test_hash_ipv6(self, ptfhost):
"fib_info": "/root/fib_info.txt",
"src_ip_range": ",".join(src_ip_range),
"dst_ip_range": ",".join(dst_ip_range),
"in_ports": g_vars['in_ports'],
"hash_keys": self.hash_keys },
log_file=log_file,
socket_recv_size=16384)