def run_encap_combination_test(self, outer_pkt_type, inner_pkt_type): """ @summary: Send double and triple encapsulated packets for each IP range and expect the packet to be received from one of the expected ports """ for dut_index, fib in enumerate(self.fibs): if inner_pkt_type == 'ipv4': ip_ranges = fib.ipv4_ranges() elif inner_pkt_type == 'ipv6': ip_ranges = fib.ipv6_ranges() else: raise Exception('ERROR: Invalid inner packet type passed: ', inner_pkt_type) ip_ranges_length = len(ip_ranges) if ip_ranges_length > 150: # This is to limit the test execution time. Because the IP ranges in the head and tail of the list are # kind of special. We need to always cover them. The IP ranges in the middle are not fundamentally # different. We can just sample some IP ranges in the middle. Using this method, test coverage is not # compromized. Test execution time can be reduced from over 5000 seconds to around 300 seconds. last_ten_index = ip_ranges_length - 10 covered_ip_ranges = ip_ranges[:100] + \ random.sample(ip_ranges[100:last_ten_index], 40) + \ ip_ranges[last_ten_index:] else: covered_ip_ranges = ip_ranges[:] for ip_range in covered_ip_ranges: self.check_range(ip_range, outer_pkt_type, inner_pkt_type, dut_index)
def check_ip_ranges(self, ipv4=True): for dut_index, fib in enumerate(self.fibs): if ipv4: ip_ranges = fib.ipv4_ranges() else: ip_ranges = fib.ipv6_ranges() if len(ip_ranges) > 150: covered_ip_ranges = ip_ranges[:100] + random.sample(ip_ranges[100:], 50) # Limit test execution time else: covered_ip_ranges = ip_ranges[:] for ip_range in covered_ip_ranges: if ip_range.get_first_ip() in fib: self.check_ip_range(ip_range, dut_index, ipv4) random.shuffle(covered_ip_ranges) self.check_balancing(covered_ip_ranges, dut_index, ipv4)