From db8c150240173ddce75e8c42b6b8d3dc5faf3af3 Mon Sep 17 00:00:00 2001 From: Perumal Venkatesh Date: Mon, 30 Oct 2023 22:15:53 -0700 Subject: [PATCH] Select only ports belonging to same asic - chassis-packet (#10365) In case of chassis-packet switch type, when src port of the traffic is on the same DUT and same asic as destination port, it sends out traffic only on the ports that belong to the same asic. Currently both fib_test and hash_test was set to send out on ports that belonged to different asic causing the balancing test to fail. THis change pertains only to chassis-packet switch type --- ansible/roles/test/files/ptftests/fib_test.py | 36 ++++++++++++++++- .../test/files/ptftests/py3/hash_test.py | 39 +++++++++++++++++-- 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/ansible/roles/test/files/ptftests/fib_test.py b/ansible/roles/test/files/ptftests/fib_test.py index d70cd64f1bc..e4e48c61524 100644 --- a/ansible/roles/test/files/ptftests/fib_test.py +++ b/ansible/roles/test/files/ptftests/fib_test.py @@ -213,6 +213,8 @@ def get_src_and_exp_ports(self, dst_ip): # Because the MACsec is session based channel but the injected ports are stateless ports if src_port in macsec.MACSEC_INFOS.keys(): continue + if self.switch_type == "chassis-packet": + exp_port_lists = self.check_same_asic(src_port, exp_port_lists) logging.info('src_port={}, exp_port_lists={}, active_dut_indexes={}'.format( src_port, exp_port_lists, active_dut_indexes)) break @@ -284,7 +286,7 @@ def check_balancing(self, ip_ranges, dut_index, ipv4=True): for next_hop in next_hops: # only check balance on a DUT self.check_hit_count_map( - next_hop.get_next_hop(), hit_count_map) + next_hop.get_next_hop(), hit_count_map, src_port) self.balancing_test_count += 1 if self.balancing_test_count >= self.balancing_test_number: break @@ -508,7 +510,34 @@ def check_within_expected_range(self, actual, expected): percentage = (actual - expected) / float(expected) return (percentage, abs(percentage) <= self.balancing_range) - def check_hit_count_map(self, dest_port_list, port_hit_cnt): + def check_same_asic(self, src_port, exp_port_list): + updated_exp_port_list = list() + for port in exp_port_list: + if type(port) == list: + per_port_list = list() + for per_port in port: + if self.ptf_test_port_map[str(per_port)]['target_dut'] \ + != self.ptf_test_port_map[str(src_port)]['target_dut']: + return exp_port_list + else: + if self.ptf_test_port_map[str(per_port)]['asic_idx'] \ + == self.ptf_test_port_map[str(src_port)]['asic_idx']: + per_port_list.append(per_port) + if per_port_list: + updated_exp_port_list.append(per_port_list) + else: + if self.ptf_test_port_map[str(port)]['target_dut'] \ + != self.ptf_test_port_map[str(src_port)]['target_dut']: + return exp_port_list + else: + if self.ptf_test_port_map[str(port)]['asic_idx'] \ + == self.ptf_test_port_map[str(src_port)]['asic_idx']: + updated_exp_port_list.append(port) + if updated_exp_port_list: + exp_port_list = updated_exp_port_list + return exp_port_list + + def check_hit_count_map(self, dest_port_list, port_hit_cnt, src_port): ''' @summary: Check if the traffic is balanced across the ECMP groups and the LAG members @param dest_port_list : a list of ECMP entries and in each ECMP entry a list of ports @@ -519,6 +548,9 @@ def check_hit_count_map(self, dest_port_list, port_hit_cnt): ("type", "port(s)", "exp_cnt", "act_cnt", "diff(%)")) result = True + if self.switch_type == "chassis-packet": + dest_port_list = self.check_same_asic(src_port, dest_port_list) + asic_list = defaultdict(list) if self.switch_type == "voq": asic_list['voq'] = dest_port_list diff --git a/ansible/roles/test/files/ptftests/py3/hash_test.py b/ansible/roles/test/files/ptftests/py3/hash_test.py index 556fc87c4bb..a4a80f6a629 100644 --- a/ansible/roles/test/files/ptftests/py3/hash_test.py +++ b/ansible/roles/test/files/ptftests/py3/hash_test.py @@ -162,6 +162,8 @@ def check_hash(self, hash_key): dst_ip = self.dst_ip_interval.get_random_ip() src_port, exp_port_lists, next_hops = self.get_src_and_exp_ports( dst_ip) + if self.switch_type == "chassis-packet": + exp_port_lists = self.check_same_asic(src_port, exp_port_lists) logging.info("dst_ip={}, src_port={}, exp_port_lists={}".format( dst_ip, src_port, exp_port_lists)) for exp_port_list in exp_port_lists: @@ -201,7 +203,7 @@ def check_hash(self, hash_key): hash_key, hit_count_map)) for next_hop in next_hops: - self.check_balancing(next_hop.get_next_hop(), hit_count_map) + self.check_balancing(next_hop.get_next_hop(), hit_count_map, src_port) def check_ip_route(self, hash_key, src_port, dst_ip, dst_port_lists): if ip_network(six.text_type(dst_ip)).version == 4: @@ -443,7 +445,34 @@ def check_within_expected_range(self, actual, expected): percentage = (actual - expected) / float(expected) return (percentage, abs(percentage) <= self.balancing_range) - def check_balancing(self, dest_port_list, port_hit_cnt): + def check_same_asic(self, src_port, exp_port_list): + updated_exp_port_list = list() + for port in exp_port_list: + if type(port) == list: + per_port_list = list() + for per_port in port: + if self.ptf_test_port_map[str(per_port)]['target_dut'] \ + != self.ptf_test_port_map[str(src_port)]['target_dut']: + return exp_port_list + else: + if self.ptf_test_port_map[str(per_port)]['asic_idx'] \ + == self.ptf_test_port_map[str(src_port)]['asic_idx']: + per_port_list.append(per_port) + if per_port_list: + updated_exp_port_list.append(per_port_list) + else: + if self.ptf_test_port_map[str(port)]['target_dut'] \ + != self.ptf_test_port_map[str(src_port)]['target_dut']: + return exp_port_list + else: + if self.ptf_test_port_map[str(port)]['asic_idx'] \ + == self.ptf_test_port_map[str(src_port)]['asic_idx']: + updated_exp_port_list.append(port) + if updated_exp_port_list: + exp_port_list = updated_exp_port_list + return exp_port_list + + def check_balancing(self, dest_port_list, port_hit_cnt, src_port): ''' @summary: Check if the traffic is balanced across the ECMP groups and the LAG members @param dest_port_list : a list of ECMP entries and in each ECMP entry a list of ports @@ -454,6 +483,8 @@ def check_balancing(self, dest_port_list, port_hit_cnt): logging.info("%-10s \t %-10s \t %10s \t %10s \t %10s" % ("type", "port(s)", "exp_cnt", "act_cnt", "diff(%)")) result = True + if self.switch_type == "chassis-packet": + dest_port_list = self.check_same_asic(src_port, dest_port_list) asic_list = defaultdict(list) if self.switch_type == "voq": @@ -743,6 +774,8 @@ def check_hash(self, hash_key): outer_dst_ip = '80.1.0.32' src_port, exp_port_lists, next_hops = self.get_src_and_exp_ports( outer_dst_ip) + if self.switch_type == "chassis-packet": + exp_port_lists = self.check_same_asic(src_port, exp_port_lists) logging.info("outer_src_ip={}, outer_dst_ip={}, src_port={}, exp_port_lists={}".format( outer_src_ip, outer_dst_ip, src_port, exp_port_lists)) @@ -791,7 +824,7 @@ def check_hash(self, hash_key): hash_key, hit_count_map)) for next_hop in next_hops: - self.check_balancing(next_hop.get_next_hop(), hit_count_map) + self.check_balancing(next_hop.get_next_hop(), hit_count_map, src_port) def runTest(self): """