From fc58f9c3d87874fc604105234c5d5a5d8ef98e2d Mon Sep 17 00:00:00 2001 From: falodiya Date: Fri, 29 Jan 2021 19:01:44 -0500 Subject: [PATCH] Modified FIB testcases to support T2 topology on multi-dut --- ansible/roles/test/files/ptftests/fib.py | 1 + ansible/roles/test/files/ptftests/fib_test.py | 13 ++++++- .../roles/test/files/ptftests/hash_test.py | 9 ++++- tests/common/plugins/fib.py | 13 +++++-- tests/fib/test_fib.py | 39 +++++++++++++------ 5 files changed, 57 insertions(+), 18 deletions(-) diff --git a/ansible/roles/test/files/ptftests/fib.py b/ansible/roles/test/files/ptftests/fib.py index 5686bf516c..de5905b1e7 100644 --- a/ansible/roles/test/files/ptftests/fib.py +++ b/ansible/roles/test/files/ptftests/fib.py @@ -19,6 +19,7 @@ EXCLUDE_IPV6_PREFIXES = [ '::/128', # Unspecified RFC 4291 '::1/128', # Loopback RFC 4291 + 'fc00::/8', # Interface local address that can interfere in testing T2 topology (learnt via fabric) 'fe80::/10', # Link local RFC 4291 'ff00::/8' # Multicast RFC 4291 ] diff --git a/ansible/roles/test/files/ptftests/fib_test.py b/ansible/roles/test/files/ptftests/fib_test.py index 7133064e23..9e60d4d455 100644 --- a/ansible/roles/test/files/ptftests/fib_test.py +++ b/ansible/roles/test/files/ptftests/fib_test.py @@ -103,6 +103,7 @@ def setUp(self): fib_info = self.test_params.get('fib_info', None) self.fib = fib.Fib(self.test_params['fib_info']) if fib_info is not None else None self.router_mac = self.test_params.get('router_mac', None) + self.exp_router_mac = self.test_params.get('exp_router_mac', None) self.pktlen = self.test_params.get('testbed_mtu', 1500) self.test_ipv4 = self.test_params.get('ipv4', True) @@ -124,6 +125,8 @@ def setUp(self): # 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' or self.test_params['testbed_type'] == 't0-64-32': self.src_ports = range(0, 32) + if self.test_params['testbed_type'] == 't2': + self.src_ports = range(32, 63) 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': @@ -236,9 +239,12 @@ def check_ipv4_route(self, src_port, dst_ip_addr, dst_port_list): ip_options=self.ip_options, dl_vlan_enable=self.src_vid is not None, vlan_vid=self.src_vid or 0) + + exp_router_mac = self.exp_router_mac if self.exp_router_mac else self.router_mac + exp_pkt = simple_tcp_packet( self.pktlen, - eth_src=self.router_mac, + eth_src=exp_router_mac, ip_src=ip_src, ip_dst=ip_dst, tcp_sport=sport, @@ -284,9 +290,12 @@ def check_ipv6_route(self, src_port, dst_ip_addr, dst_port_list): ipv6_hlim=self.ttl, dl_vlan_enable=self.src_vid is not None, vlan_vid=self.src_vid or 0) + + exp_router_mac = self.exp_router_mac if self.exp_router_mac else self.router_mac + exp_pkt = simple_tcpv6_packet( pktlen=self.pktlen, - eth_src=self.router_mac, + eth_src=exp_router_mac, ipv6_dst=ip_dst, ipv6_src=ip_src, tcp_sport=sport, diff --git a/ansible/roles/test/files/ptftests/hash_test.py b/ansible/roles/test/files/ptftests/hash_test.py index eeb7e70099..e0106be4ed 100644 --- a/ansible/roles/test/files/ptftests/hash_test.py +++ b/ansible/roles/test/files/ptftests/hash_test.py @@ -54,6 +54,7 @@ def setUp(self): self.vlan_ids = self.test_params.get('vlan_ids', []) self.hash_keys = self.test_params.get('hash_keys', ['src-ip', 'dst-ip', 'src-port', 'dst-port']) self.dst_macs = self.test_params.get('dst_macs', []) # TODO + self.in_port_router_mac = self.test_params.get('in_port_router_mac', None) self.balancing_range = self.test_params.get('balancing_range', self.DEFAULT_BALANCING_RANGE) @@ -130,8 +131,10 @@ def check_ipv4_route(self, hash_key, in_port, dst_port_list): vlan_id = random.choice(self.vlan_ids) if hash_key == 'vlan-id' else 0 ip_proto = self._get_ip_proto() if hash_key == 'ip-proto' else None + in_port_router_mac = self.in_port_router_mac if self.in_port_router_mac else dst_mac + pkt = simple_tcp_packet(pktlen=100 if vlan_id == 0 else 104, - eth_dst=dst_mac, + eth_dst=in_port_router_mac, eth_src=src_mac, dl_vlan_enable=False if vlan_id == 0 else True, vlan_vid=vlan_id, @@ -179,8 +182,10 @@ def check_ipv6_route(self, hash_key, in_port, dst_port_list): vlan_id = random.choice(self.vlan_ids) if hash_key == 'vlan-id' else 0 ip_proto = self._get_ip_proto(ipv6=True) if hash_key == "ip-proto" else None + in_port_router_mac = self.in_port_router_mac if self.in_port_router_mac else dst_mac + pkt = simple_tcpv6_packet(pktlen=100 if vlan_id == 0 else 104, - eth_dst=dst_mac, + eth_dst=in_port_router_mac, eth_src=src_mac, dl_vlan_enable=False if vlan_id == 0 else True, vlan_vid=vlan_id, diff --git a/tests/common/plugins/fib.py b/tests/common/plugins/fib.py index ecefdfb55e..6915d91c88 100644 --- a/tests/common/plugins/fib.py +++ b/tests/common/plugins/fib.py @@ -48,8 +48,8 @@ def generate_routes(family, podset_number, tor_number, tor_subnet_number, for podset in range(0, podset_number): for tor in range(0, tor_number): for subnet in range(0, tor_subnet_number): - if router_type == "spine": - # Skip podset 0 for T2 + if router_type == "spine" or router_type == "core": + # Skip podset 0 for T2/T3 if podset == 0: continue elif router_type == "leaf": @@ -80,7 +80,7 @@ def generate_routes(family, podset_number, tor_number, tor_subnet_number, tor_asn = tor_asn_start + tor aspath = None - if router_type == "spine": + if router_type == "spine" or router_type == "core": aspath = "{} {}".format(leaf_asn, tor_asn) elif router_type == "leaf": if podset == 0: @@ -231,6 +231,8 @@ def fib_t1_lag(ptfhost, tbinfo, localhost): router_type = None if 'spine' in v['properties']: router_type = 'spine' + if 'core' in v['properties']: + router_type = 'core' elif 'tor' in v['properties']: router_type = 'tor' tornum = v.get('tornum', None) @@ -253,6 +255,9 @@ def fib_t1_lag(ptfhost, tbinfo, localhost): routes_vips.append((prefix, local_ip, v["vips"]["ipv4"]["asn"])) announce_routes(ptfip, port, routes_vips) +def fib_t2_lag(ptfhost, tbinfo, localhost): + logger.info("use fib_t2__lag to setup routes for topo {}".format(tbinfo['topo']['name'])) + fib_t1_lag(ptfhost, tbinfo, localhost) @pytest.fixture(scope='module') def fib(ptfhost, tbinfo, localhost): @@ -262,5 +267,7 @@ def fib(ptfhost, tbinfo, localhost): fib_t0(ptfhost, tbinfo, localhost, topology) elif tbinfo['topo']['type'] == "t1": fib_t1_lag(ptfhost, tbinfo, localhost) + elif tbinfo['topo']['type'] == "t2": + fib_t2_lag(ptfhost, tbinfo, localhost) else: logger.error("unknown topology {}".format(tbinfo['topo']['name'])) diff --git a/tests/fib/test_fib.py b/tests/fib/test_fib.py index 569e968db3..b90a79f830 100644 --- a/tests/fib/test_fib.py +++ b/tests/fib/test_fib.py @@ -27,14 +27,14 @@ @pytest.fixture(scope="module") -def config_facts(duthosts, rand_one_dut_hostname): - duthost = duthosts[rand_one_dut_hostname] +def config_facts(duthosts): + duthost = duthosts[0] return duthost.config_facts(host=duthost.hostname, source="running")['ansible_facts'] @pytest.fixture(scope='module') -def build_fib(duthosts, rand_one_dut_hostname, ptfhost, config_facts, tbinfo): - duthost = duthosts[rand_one_dut_hostname] +def build_fib(duthosts, ptfhost, config_facts, tbinfo): + duthost = duthosts[0] timestamp = datetime.now().strftime('%Y-%m-%d-%H:%M:%S') @@ -60,7 +60,7 @@ def build_fib(duthosts, rand_one_dut_hostname, ptfhost, config_facts, tbinfo): if po.has_key(ifname): oports.append([str(mg_facts['minigraph_ptf_indices'][x]) for x in po[ifname]['members']]) else: - if ports.has_key(ifname): + if ports.has_key(ifname) and mg_facts['minigraph_ptf_indices'].get(ifname): oports.append([str(mg_facts['minigraph_ptf_indices'][ifname])]) else: logger.info("Route point to non front panel port {}:{}".format(k, v)) @@ -119,9 +119,8 @@ def get_router_interface_ports(config_facts, tbinfo): @pytest.mark.parametrize("ipv4, ipv6, mtu", [pytest.param(True, True, 1514)]) -def test_basic_fib(tbinfo, duthosts, rand_one_dut_hostname, ptfhost, ipv4, ipv6, mtu, config_facts, build_fib): - duthost = duthosts[rand_one_dut_hostname] - +def test_basic_fib(tbinfo, duthosts, ptfhost, ipv4, ipv6, mtu, config_facts, build_fib): + duthost = duthosts[0] timestamp = datetime.now().strftime('%Y-%m-%d-%H:%M:%S') # do not test load balancing for vs platform as kernel 4.9 @@ -133,7 +132,16 @@ def test_basic_fib(tbinfo, duthosts, rand_one_dut_hostname, ptfhost, ipv4, ipv6, logging.info("run ptf test") testbed_type = tbinfo['topo']['name'] - router_mac = duthost.shell('sonic-cfggen -d -v \'DEVICE_METADATA.localhost.mac\'')["stdout_lines"][0].decode("utf-8") + + exp_router_mac = None + # In case of T2 topology traffic is flowing from T1 to other T3, so exp_router mac is going to be different + if tbinfo['topo']['name'] == 't2': + t1_duthost = duthosts[1] + router_mac = t1_duthost.shell('sonic-cfggen -d -v \'DEVICE_METADATA.localhost.mac\'')["stdout_lines"][0].decode("utf-8") + exp_router_mac = duthost.shell('sonic-cfggen -d -v \'DEVICE_METADATA.localhost.mac\'')["stdout_lines"][0].decode("utf-8") + else: + router_mac = duthost.shell('sonic-cfggen -d -v \'DEVICE_METADATA.localhost.mac\'')["stdout_lines"][0].decode("utf-8") + log_file = "/tmp/fib_test.FibTest.ipv4.{}.ipv6.{}.{}.log".format(ipv4, ipv6, timestamp) logging.info("PTF log file: %s" % log_file) ptf_runner(ptfhost, @@ -142,6 +150,7 @@ def test_basic_fib(tbinfo, duthosts, rand_one_dut_hostname, ptfhost, ipv4, ipv6, platform_dir="ptftests", params={"testbed_type": testbed_type, "router_mac": router_mac, + "exp_router_mac": exp_router_mac, "fib_info": "/root/fib_info.txt", "ipv4": ipv4, "ipv6": ipv6, @@ -153,8 +162,8 @@ def test_basic_fib(tbinfo, duthosts, rand_one_dut_hostname, ptfhost, ipv4, ipv6, @pytest.fixture(scope="module") -def setup_hash(tbinfo, duthosts, rand_one_dut_hostname, config_facts): - duthost = duthosts[rand_one_dut_hostname] +def setup_hash(tbinfo, duthosts, config_facts): + duthost = duthosts[0] timestamp = datetime.now().strftime('%Y-%m-%d-%H:%M:%S') setup_info = {} @@ -195,6 +204,13 @@ def setup_hash(tbinfo, duthosts, rand_one_dut_hostname, config_facts): duthost.shell('config interface ip add Vlan{} '.format(vlan) + VLANIP.format(vlan%256)) time.sleep(5) + setup_info['in_port_router_mac'] = None + # In case of T2 toplogy traffic is flowing from one linecard to other linecard so in port mac is going to be different + if setup_info['testbed_type'] == 't2': + t1_duthost = duthosts[1] + setup_info['in_ports'] = range(32, 63) + setup_info['in_port_router_mac'] = t1_duthost.shell('sonic-cfggen -d -v \'DEVICE_METADATA.localhost.mac\'')["stdout_lines"][0].decode("utf-8") + yield setup_info # remove added vlan @@ -229,6 +245,7 @@ def test_hash(setup_hash, ptfhost, build_fib, ipver): platform_dir="ptftests", params={"testbed_type": setup_hash['testbed_type'], "router_mac": setup_hash['router_mac'], + "in_port_router_mac": setup_hash['in_port_router_mac'], "fib_info": "/root/fib_info.txt", "src_ip_range": ",".join(src_ip_range), "dst_ip_range": ",".join(dst_ip_range),