From 05379d5890c006b143d921eae2dd10fb71111745 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 21 Jul 2020 13:23:58 -0700 Subject: [PATCH 01/21] Add a test to check ipv6 routes over ipv4 bgp session --- ansible/roles/test/files/ptftests/fib.py | 7 + ansible/roles/test/files/ptftests/fib_test.py | 5 +- ansible/roles/test/files/ptftests/lpm.py | 3 + tests/bgp/test_bgp_speaker.py | 197 +++++++++++++++++- 4 files changed, 202 insertions(+), 10 deletions(-) diff --git a/ansible/roles/test/files/ptftests/fib.py b/ansible/roles/test/files/ptftests/fib.py index c600aa2d921..5686bf516c0 100644 --- a/ansible/roles/test/files/ptftests/fib.py +++ b/ansible/roles/test/files/ptftests/fib.py @@ -72,6 +72,13 @@ def __getitem__(self, ip): elif ip.version is 6: return self._ipv6_lpm_dict[str(ip)] + def __contains__(self, ip): + ip_obj = ip_address(unicode(ip)) + if ip_obj.version == 4: + return self._ipv4_lpm_dict.contains(ip) + elif ip_obj.version == 6: + return self._ipv6_lpm_dict.contains(ip) + def ipv4_ranges(self): return self._ipv4_lpm_dict.ranges() diff --git a/ansible/roles/test/files/ptftests/fib_test.py b/ansible/roles/test/files/ptftests/fib_test.py index a51c0c5cfe3..1ed3ba477a4 100644 --- a/ansible/roles/test/files/ptftests/fib_test.py +++ b/ansible/roles/test/files/ptftests/fib_test.py @@ -149,8 +149,9 @@ def check_ip_ranges(self, ipv4=True): ip_ranges = self.fib.ipv6_ranges() for ip_range in ip_ranges: - next_hop = self.fib[ip_range.get_first_ip()] - self.check_ip_range(ip_range, next_hop, ipv4) + if ip_range.get_first_ip() in self.fib: + next_hop = self.fib[ip_range.get_first_ip()] + self.check_ip_range(ip_range, next_hop, ipv4) def check_ip_range(self, ip_range, next_hop, ipv4=True): # Get the expected list of ports that would receive the packets diff --git a/ansible/roles/test/files/ptftests/lpm.py b/ansible/roles/test/files/ptftests/lpm.py index f30fdcef4e9..609613d4eea 100644 --- a/ansible/roles/test/files/ptftests/lpm.py +++ b/ansible/roles/test/files/ptftests/lpm.py @@ -103,3 +103,6 @@ def ranges(self): interval = self.IpInterval(sorted_boundaries[index], ip_address(u'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff')) ranges.append(interval) return ranges + + def contains(self, key): + return key in self._subnet_tree diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index 7556cd0fb9f..ae66fa061d8 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -21,17 +21,15 @@ def generate_ips(num, prefix, exclude_ips): prefix = IPNetwork(prefix) exclude_ips.append(prefix.broadcast) exclude_ips.append(prefix.network) - available_ips = list(prefix) - - if len(available_ips) - len(exclude_ips)< num: - raise Exception("Not enough available IPs") generated_ips = [] - for available_ip in available_ips: + for available_ip in prefix: if available_ip not in exclude_ips: generated_ips.append(IPNetwork(str(available_ip) + '/' + str(prefix.prefixlen))) if len(generated_ips) == num: break + else: + raise Exception("Not enough available IPs") return generated_ips @@ -56,7 +54,11 @@ def common_setup_teardown(duthost, ptfhost, localhost): mg_facts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] interface_facts = duthost.interface_facts()['ansible_facts'] - res = duthost.shell("sonic-cfggen -m -d -y /etc/sonic/constants.yml -v \"constants.deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']]\"") + check = duthost.shell("test -e /etc/sonic/constants.yml || echo 'not present'") + if check['stdout'] == 'not present': + res = duthost.shell("sonic-cfggen -m -d -y /etc/sonic/deployment_id_asn_map.yml -v \"deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']]\"") + else: + res = duthost.shell("sonic-cfggen -m -d -y /etc/sonic/constants.yml -v \"constants.deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']]\"") bgp_speaker_asn = res['stdout'] vlan_ips = generate_ips(3, "%s/%s" % (mg_facts['minigraph_vlan_interfaces'][0]['addr'], @@ -78,6 +80,7 @@ def common_setup_teardown(duthost, ptfhost, localhost): lo_addr_prefixlen = int(mg_facts['minigraph_lo_interfaces'][0]['prefixlen']) vlan_addr = mg_facts['minigraph_vlan_interfaces'][0]['addr'] + logging.info("Vlan addr = %s" % vlan_addr) vlan_ports = [] for i in range(0, 3): @@ -93,7 +96,8 @@ def common_setup_teardown(duthost, ptfhost, localhost): ptfhost.shell("ifconfig eth%d %s" % (vlan_ports[2], vlan_ips[2])) ptfhost.shell("ip route flush %s/%d" % (lo_addr, lo_addr_prefixlen)) - ptfhost.shell("ip route add %s/%d via %s" % (lo_addr, lo_addr_prefixlen, vlan_addr)) + logging.info("Vlan addr = %s" % vlan_addr) +# ptfhost.shell("ip route add %s/%d via %s" % (lo_addr, lo_addr_prefixlen, vlan_addr)) logging.info("Start exabgp on ptf") for i in range(0, 3): @@ -144,7 +148,6 @@ def test_bgp_speaker_bgp_sessions(common_setup_teardown, duthost, ptfhost, colle "Not all bgp sessions are established" assert str(speaker_ips[2].ip) in bgp_facts["bgp_neighbors"], "No bgp session with PTF" - @pytest.mark.parametrize("ipv4, ipv6, mtu", [pytest.param(True, False, 1514)]) def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, ptfhost, ipv4, ipv6, mtu, collect_techsupport): """Setup bgp speaker on T0 topology and verify routes advertised by bgp speaker is received by T0 TOR @@ -202,3 +205,181 @@ def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, pt "testbed_mtu": mtu }, log_file="/tmp/bgp_speaker_test.FibTest.log", socket_recv_size=16384) + + +@pytest.fixture(scope="module") +def common_setup_teardown_v6(duthost, ptfhost, localhost): + + logging.info("########### Setup for bgp speaker testing ###########") + + ptfhost.script("./scripts/remove_ip.sh") + + ptfip = ptfhost.host.options['inventory_manager'].get_host(ptfhost.hostname).vars['ansible_host'] + logging.info("ptfip=%s" % ptfip) + + mg_facts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] + interface_facts = duthost.interface_facts()['ansible_facts'] + # Generate ipv6 nexthops + vlan_ipv6_entry = mg_facts['minigraph_vlan_interfaces'][1] + vlan_ipv6_prefix = "%s/%s" % (vlan_ipv6_entry["addr"], vlan_ipv6_entry["prefixlen"]) + vlan_ipv6_address = vlan_ipv6_entry["addr"] + vlan_if_name = vlan_ipv6_entry['attachto'] + nexthops_ipv6 = generate_ips(3, vlan_ipv6_prefix, [IPAddress(vlan_ipv6_address)]) + logging.info("Generated nexthops_ipv6: %s" % str(nexthops_ipv6)) + + # Set ipv6 nexthop addresses on the ptf interfaces + for nh in nexthops_ipv6: + duthost.command("ip -6 route flush %s/64" % nh.ip) + duthost.command("ip -6 route add %s/64 dev %s" % (nh.ip, vlan_if_name)) + + # Generate ips for bgp dynamic peers + speaker_ips = generate_ips(3, mg_facts['minigraph_bgp_peers_with_range'][0]['ip_range'][0], []) + logging.info("speaker_ips: %s" % str(speaker_ips)) + + lo_addr = mg_facts['minigraph_lo_interfaces'][0]['addr'] + lo_addr_prefixlen = int(mg_facts['minigraph_lo_interfaces'][0]['prefixlen']) + + vlan_ipv4_addr = mg_facts['minigraph_vlan_interfaces'][0]['addr'] + + vlan_ports = [] + for i in [0, 1, 2]: + vlan_ports.append(mg_facts['minigraph_port_indices'][mg_facts['minigraph_vlans'][mg_facts['minigraph_vlan_interfaces'][0]['attachto']]['members'][i]]) + logging.info("vlan_ports: %s" % str(vlan_ports)) + + logging.info("setup ip/routes in ptf") + for i in [0, 1, 2]: + ptfhost.shell("ip -6 addr add %s dev eth%d:%d" % (nexthops_ipv6[i], vlan_ports[0], i)) + ptfhost.shell("ip addr add %s dev eth%d:%d" % (speaker_ips[i], vlan_ports[0], i)) + + vlan_ipv4_addrs = generate_ips(3, mg_facts['minigraph_bgp_peers_with_range'][0]['ip_range'][0], []) + + # Generate ipv4 vlan ips + vlan_ipv4_entry = mg_facts['minigraph_vlan_interfaces'][0] + vlan_ipv4_prefix = "%s/%s" % (vlan_ipv4_entry["addr"], vlan_ipv4_entry["prefixlen"]) + vlan_ipv4_address = vlan_ipv4_entry["addr"] + vlan_ipv4s = generate_ips(3, vlan_ipv4_prefix, [IPAddress(vlan_ipv4_address)]) + logging.info("Generated vlan_ipv4: %s" % str(vlan_ipv4s)) + + ptfhost.shell("ip addr add %s dev eth%d:%d" % (vlan_ipv4s[0], vlan_ports[1], 0)) + ptfhost.shell("ip route flush %s/%d" % (lo_addr, lo_addr_prefixlen)) + ptfhost.shell("ip route add %s/%d via %s" % (lo_addr, lo_addr_prefixlen, vlan_ipv4_addr)) + + for i in [0, 1, 2]: + duthost.shell('ip route flush %s/32' % speaker_ips[i].ip) + duthost.shell("ip route add %s/32 via %s" % (speaker_ips[i].ip, vlan_ipv4s[0].ip)) + + port_num = [7000, 8000, 9000] + + check = duthost.shell("test -e /etc/sonic/constants.yml || echo 'not present'") + if check['stdout'] == 'not present': + res = duthost.shell("sonic-cfggen -m -d -y /etc/sonic/deployment_id_asn_map.yml -v \"deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']]\"") + else: + res = duthost.shell("sonic-cfggen -m -d -y /etc/sonic/constants.yml -v \"constants.deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']]\"") + bgp_speaker_asn = res['stdout'] + + logging.info("Start exabgp on ptf") + for i in [0, 1, 2]: + local_ip = str(speaker_ips[i].ip) + logging.info("local_ip=%s" % local_ip) + logging.info("router_id=%s" % local_ip) + logging.info("peer_ip=%s" % lo_addr) + logging.info("local_asn=%s" % bgp_speaker_asn) + logging.info("peer_asn=%s" % mg_facts['minigraph_bgp_asn']) + logging.info("port=%s" % str(port_num[i])) + logging.info("------------") + ptfhost.exabgp(name="bgps%d" % i, + state="started", + local_ip=local_ip, + router_id=local_ip, + peer_ip=lo_addr, + local_asn=bgp_speaker_asn, + peer_asn=mg_facts['minigraph_bgp_asn'], + port=str(port_num[i])) + + # check exabgp http_api port is ready + http_ready = True + for i in [0, 1, 2]: + http_ready = wait_tcp_connection(localhost, ptfip, port_num[i]) + if not http_ready: + break + + # ping + ptfhost.shell("ping -c 3 -S %s %s" % (speaker_ips[0].ip, lo_addr)) + + logging.info("########### Done setup for bgp speaker testing ###########") + + yield ptfip, mg_facts, interface_facts, lo_addr, vlan_if_name, nexthops_ipv6, speaker_ips, port_num, http_ready + + logging.info("########### Teardown for bgp speaker testing ###########") + + for i in [0, 1, 2]: + ptfhost.exabgp(name="bgps%d" % i, state="absent") + + logging.info("exabgp stopped") + + for nh in nexthops_ipv6: + duthost.command("ip -6 route flush %s/64" % nh.ip) + + logging.info("Flushed ipv6 nexthop routes from dut") + + for i in [0, 1, 2]: + duthost.shell("ip route del %s/32 via %s" % (speaker_ips[i].ip, vlan_ipv4s[0].ip)) + + logging.info("Removed ipv4 speaker routes from dut") + + ptfhost.script("./scripts/remove_ip.sh") + + logging.info("########### Done teardown for bgp speaker testing ###########") + + +@pytest.mark.parametrize("ipv4, ipv6, mtu", [pytest.param(False, True, 1514)]) +def test_bgp_speaker_announce_routes_ipv6(common_setup_teardown_v6, testbed, duthost, ptfhost, ipv4, ipv6, mtu, collect_techsupport): + """Setup bgp speaker on T0 topology and verify routes advertised by bgp speaker is received by T0 TOR + + """ + ptfip, mg_facts, interface_facts, lo_addr, vlan_if_name, nexthops_ipv6, speaker_ips, port_num, http_ready = common_setup_teardown_v6 + assert http_ready + + logging.info("Announce ipv6 prefixes over ipv4 bgp sessions") + for i, nexthop in enumerate(nexthops_ipv6): + prefix = 'fc00:1%d::/64' % i + logging.info("announce route: prefix: %s nexthops: %s" % (prefix, str(nexthop.ip))) + announce_route(ptfip, lo_addr, prefix, nexthop.ip, port_num[i]) + + logging.info("Wait some time to make sure routes announced to dynamic bgp neighbors") + time.sleep(30) + + logging.info("Verify nexthops and nexthop interfaces for accepted prefixes of the dynamic neighbors") + for i, nexthop in enumerate(nexthops_ipv6): + prefix = 'fc00:1%d::/64' % i + cmd = "ip -6 route get %s" % prefix + output = duthost.shell(cmd) + res = output["stdout"].split("\n") + assert " via %s dev %s " % (nexthop.ip, vlan_if_name) in res[0] + + logging.info("Generate route-port map information") + extra_vars = {'announce_prefix': 'fc00:10::/64', + 'minigraph_portchannels': mg_facts['minigraph_portchannels'], + 'minigraph_vlans': mg_facts['minigraph_vlans'], + 'minigraph_port_indices': mg_facts['minigraph_port_indices']} + ptfhost.host.options['variable_manager'].extra_vars.update(extra_vars) + logging.info("extra_vars: %s" % str(ptfhost.host.options['variable_manager'].extra_vars)) + + ptfhost.template(src="bgp_speaker/bgp_speaker_route.j2", dest="/root/bgp_speaker_route.txt") + + logging.info("run ptf test") + + ptf_runner(ptfhost, + "ptftests", + "fib_test.FibTest", + platform_dir="ptftests", + params={"testbed_type": testbed['topo']['name'], + "router_mac": interface_facts['ansible_interface_facts']['Ethernet0']['macaddress'], + "fib_info": "/root/bgp_speaker_route.txt", + "ipv4": ipv4, + "ipv6": ipv6, + "testbed_mtu": mtu }, + log_file="/tmp/bgp_speaker_test.FibTest.log", + socket_recv_size=16384) + + logging.info("Nexthop tests are done") From 7fe4f01de51a55c3433524f0b74b0ba0b15a2b50 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 21 Jul 2020 13:28:17 -0700 Subject: [PATCH 02/21] Remove debug code --- tests/bgp/test_bgp_speaker.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index ae66fa061d8..477364eba59 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -80,7 +80,6 @@ def common_setup_teardown(duthost, ptfhost, localhost): lo_addr_prefixlen = int(mg_facts['minigraph_lo_interfaces'][0]['prefixlen']) vlan_addr = mg_facts['minigraph_vlan_interfaces'][0]['addr'] - logging.info("Vlan addr = %s" % vlan_addr) vlan_ports = [] for i in range(0, 3): @@ -96,8 +95,6 @@ def common_setup_teardown(duthost, ptfhost, localhost): ptfhost.shell("ifconfig eth%d %s" % (vlan_ports[2], vlan_ips[2])) ptfhost.shell("ip route flush %s/%d" % (lo_addr, lo_addr_prefixlen)) - logging.info("Vlan addr = %s" % vlan_addr) -# ptfhost.shell("ip route add %s/%d via %s" % (lo_addr, lo_addr_prefixlen, vlan_addr)) logging.info("Start exabgp on ptf") for i in range(0, 3): From 8b9830c41b629bcf5dd7575b722741cfce932db5 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 21 Jul 2020 13:34:14 -0700 Subject: [PATCH 03/21] Restore old code --- tests/bgp/test_bgp_speaker.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index 477364eba59..589b834ab49 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -95,6 +95,7 @@ def common_setup_teardown(duthost, ptfhost, localhost): ptfhost.shell("ifconfig eth%d %s" % (vlan_ports[2], vlan_ips[2])) ptfhost.shell("ip route flush %s/%d" % (lo_addr, lo_addr_prefixlen)) + ptfhost.shell("ip route add %s/%d via %s" % (lo_addr, lo_addr_prefixlen, vlan_addr)) logging.info("Start exabgp on ptf") for i in range(0, 3): From 487b272cef781558de7048a8273effa253c25a5b Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 21 Jul 2020 14:22:41 -0700 Subject: [PATCH 04/21] Fix a bug in exabgp module --- ansible/library/exabgp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible/library/exabgp.py b/ansible/library/exabgp.py index e051d6f0259..1c8f938237d 100644 --- a/ansible/library/exabgp.py +++ b/ansible/library/exabgp.py @@ -187,7 +187,7 @@ def setup_exabgp_conf(name, router_id, local_ip, peer_ip, local_asn, peer_asn, p def remove_exabgp_conf(name): try: os.remove("/etc/exabgp/%s.conf" % name) - except e: + except Exception: pass @@ -200,7 +200,7 @@ def setup_exabgp_supervisord_conf(name): def remove_exabgp_supervisord_conf(name): try: os.remove("/etc/supervisor/conf.d/exabgp-%s.conf" % name) - except e: + except Exception: pass def setup_exabgp_processor(): From 63cb226450944af8a28bcf587d5dbf0b0273a475 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 21 Jul 2020 14:55:36 -0700 Subject: [PATCH 05/21] Fix issues from lgtm --- tests/bgp/test_bgp_speaker.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index 589b834ab49..cc8c4a400b3 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -146,6 +146,7 @@ def test_bgp_speaker_bgp_sessions(common_setup_teardown, duthost, ptfhost, colle "Not all bgp sessions are established" assert str(speaker_ips[2].ip) in bgp_facts["bgp_neighbors"], "No bgp session with PTF" + @pytest.mark.parametrize("ipv4, ipv6, mtu", [pytest.param(True, False, 1514)]) def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, ptfhost, ipv4, ipv6, mtu, collect_techsupport): """Setup bgp speaker on T0 topology and verify routes advertised by bgp speaker is received by T0 TOR @@ -249,8 +250,6 @@ def common_setup_teardown_v6(duthost, ptfhost, localhost): ptfhost.shell("ip -6 addr add %s dev eth%d:%d" % (nexthops_ipv6[i], vlan_ports[0], i)) ptfhost.shell("ip addr add %s dev eth%d:%d" % (speaker_ips[i], vlan_ports[0], i)) - vlan_ipv4_addrs = generate_ips(3, mg_facts['minigraph_bgp_peers_with_range'][0]['ip_range'][0], []) - # Generate ipv4 vlan ips vlan_ipv4_entry = mg_facts['minigraph_vlan_interfaces'][0] vlan_ipv4_prefix = "%s/%s" % (vlan_ipv4_entry["addr"], vlan_ipv4_entry["prefixlen"]) From 7d7be28e6b802af06591bbb28540bee8de985722 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Fri, 24 Jul 2020 17:44:15 -0700 Subject: [PATCH 06/21] Add ipv6 prefixes to vlans --- ansible/templates/minigraph_dpg.j2 | 9 +++++++++ ansible/vars/topo_t0-116.yml | 3 +++ ansible/vars/topo_t0-16.yml | 3 +++ ansible/vars/topo_t0-52.yml | 3 +++ ansible/vars/topo_t0-56.yml | 3 +++ ansible/vars/topo_t0-64-32.yml | 3 +++ ansible/vars/topo_t0-64.yml | 3 +++ ansible/vars/topo_t0.yml | 3 +++ 8 files changed, 30 insertions(+) diff --git a/ansible/templates/minigraph_dpg.j2 b/ansible/templates/minigraph_dpg.j2 index 801abcfef42..3ccf2709932 100644 --- a/ansible/templates/minigraph_dpg.j2 +++ b/ansible/templates/minigraph_dpg.j2 @@ -102,6 +102,15 @@ {{ vlan_param['prefix'] }} {% endfor %} +{% for vlan, vlan_param in vlan_configs.items() %} +{% if 'prefix_v6' in vlan_param %} + + + {{ vlan }} + {{ vlan_param['prefix_v6'] }} + +{% endif %} +{% endfor %} {% endif %} diff --git a/ansible/vars/topo_t0-116.yml b/ansible/vars/topo_t0-116.yml index ff0f7aaa289..60d6e0abf33 100644 --- a/ansible/vars/topo_t0-116.yml +++ b/ansible/vars/topo_t0-116.yml @@ -141,17 +141,20 @@ topology: id: 1000 intfs: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119] prefix: 192.168.0.1/21 + prefix_v6: fc02:1000::1/64 tag: 1000 two_vlan_a: Vlan100: id: 100 intfs: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] prefix: 192.168.100.1/21 + prefix_v6: fc02:100::1/64 tag: 100 Vlan200: id: 200 intfs: [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119] prefix: 192.168.200.1/21 + prefix_v6: fc02:200::1/64 tag: 200 configuration_properties: diff --git a/ansible/vars/topo_t0-16.yml b/ansible/vars/topo_t0-16.yml index ea71d34d35d..c267b29a14e 100644 --- a/ansible/vars/topo_t0-16.yml +++ b/ansible/vars/topo_t0-16.yml @@ -114,17 +114,20 @@ topology: id: 1000 intfs: [32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47] prefix: 192.168.0.1/21 + prefix_v6: fc02:1000::1/64 tag: 1000 two_vlan_a: Vlan100: id: 100 intfs: [32, 33, 34, 35, 36, 37, 38, 39] prefix: 192.168.100.1/21 + prefix_v6: fc02:100::1/64 tag: 100 Vlan200: id: 200 intfs: [40, 41, 42, 43, 44, 45, 46, 47] prefix: 192.168.200.1/21 + prefix_v6: fc02:200::1/64 tag: 200 configuration_properties: diff --git a/ansible/vars/topo_t0-52.yml b/ansible/vars/topo_t0-52.yml index a214905db0c..623b4376618 100644 --- a/ansible/vars/topo_t0-52.yml +++ b/ansible/vars/topo_t0-52.yml @@ -73,17 +73,20 @@ topology: id: 1000 intfs: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47] prefix: 192.168.0.1/21 + prefix_v6: fc02:1000::1/64 tag: 1000 two_vlan_a: Vlan100: id: 100 intfs: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23] prefix: 192.168.100.1/21 + prefix_v6: fc02:100::1/64 tag: 100 Vlan200: id: 200 intfs: [24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47] prefix: 192.168.200.1/21 + prefix_v6: fc02:200::1/64 tag: 200 configuration_properties: diff --git a/ansible/vars/topo_t0-56.yml b/ansible/vars/topo_t0-56.yml index 24b0ca38d13..2db3902baaf 100644 --- a/ansible/vars/topo_t0-56.yml +++ b/ansible/vars/topo_t0-56.yml @@ -114,17 +114,20 @@ topology: id: 1000 intfs: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55] prefix: 192.168.0.1/21 + prefix_v6: fc02:1000::1/64 tag: 1000 two_vlan_a: Vlan100: id: 100 intfs: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26] prefix: 192.168.100.1/21 + prefix_v6: fc02:100::1/64 tag: 100 Vlan200: id: 200 intfs: [27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55] prefix: 192.168.200.1/21 + prefix_v6: fc02:200::1/64 tag: 200 configuration_properties: diff --git a/ansible/vars/topo_t0-64-32.yml b/ansible/vars/topo_t0-64-32.yml index 5ca9cf51bca..6b42438c53b 100644 --- a/ansible/vars/topo_t0-64-32.yml +++ b/ansible/vars/topo_t0-64-32.yml @@ -53,17 +53,20 @@ topology: id: 1000 intfs: [2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31] prefix: 192.168.0.1/21 + prefix_v6: fc02:1000::1/64 tag: 1000 two_vlan_a: Vlan100: id: 100 intfs: [2, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] prefix: 192.168.100.1/21 + prefix_v6: fc02:100::1/64 tag: 100 Vlan200: id: 200 intfs: [18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31] prefix: 192.168.200.1/21 + prefix_v6: fc02:200::1/64 tag: 200 configuration_properties: diff --git a/ansible/vars/topo_t0-64.yml b/ansible/vars/topo_t0-64.yml index 99c9aa53fbe..b130fa27b11 100644 --- a/ansible/vars/topo_t0-64.yml +++ b/ansible/vars/topo_t0-64.yml @@ -106,17 +106,20 @@ topology: id: 1000 intfs: [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 36, 37, 38, 39, 40, 41, 42, 48, 52, 53, 54, 55, 56, 57, 58] prefix: 192.168.0.1/21 + prefix_v6: fc02:1000::1/64 tag: 1000 two_vlan_a: Vlan100: id: 100 intfs: [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 22, 23, 24, 25, 26, 27, 28, 29] prefix: 192.168.100.1/21 + prefix_v6: fc02:100::1/64 tag: 100 Vlan200: id: 200 intfs: [30, 31, 32, 36, 37, 38, 39, 40, 41, 42, 48, 52, 53, 54, 55, 56, 57, 58] prefix: 192.168.200.1/21 + prefix_v6: fc02:200::1/64 tag: 200 configuration_properties: diff --git a/ansible/vars/topo_t0.yml b/ansible/vars/topo_t0.yml index 441b1d7e59c..3f5a1d74cea 100644 --- a/ansible/vars/topo_t0.yml +++ b/ansible/vars/topo_t0.yml @@ -58,17 +58,20 @@ topology: id: 1000 intfs: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] prefix: 192.168.0.1/21 + prefix_v6: fc02:1000::1/64 tag: 1000 two_vlan_a: Vlan100: id: 100 intfs: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] prefix: 192.168.100.1/21 + prefix_v6: fc02:100::1/64 tag: 100 Vlan200: id: 200 intfs: [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] prefix: 192.168.200.1/21 + prefix_v6: fc02:200::1/64 tag: 200 configuration_properties: From 6d1edcf40d886870507fdb806408d70b9a982135 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Fri, 24 Jul 2020 18:13:07 -0700 Subject: [PATCH 07/21] Use ansible module to check existence of the file --- tests/bgp/test_bgp_speaker.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index cc8c4a400b3..72ee89b001e 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -54,11 +54,11 @@ def common_setup_teardown(duthost, ptfhost, localhost): mg_facts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] interface_facts = duthost.interface_facts()['ansible_facts'] - check = duthost.shell("test -e /etc/sonic/constants.yml || echo 'not present'") - if check['stdout'] == 'not present': - res = duthost.shell("sonic-cfggen -m -d -y /etc/sonic/deployment_id_asn_map.yml -v \"deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']]\"") - else: + constants_stat = duthost.stat(path="/etc/sonic/constants.yml") + if constants_stat["stat"]["exists"]: res = duthost.shell("sonic-cfggen -m -d -y /etc/sonic/constants.yml -v \"constants.deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']]\"") + else: + res = duthost.shell("sonic-cfggen -m -d -y /etc/sonic/deployment_id_asn_map.yml -v \"deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']]\"") bgp_speaker_asn = res['stdout'] vlan_ips = generate_ips(3, "%s/%s" % (mg_facts['minigraph_vlan_interfaces'][0]['addr'], @@ -267,11 +267,11 @@ def common_setup_teardown_v6(duthost, ptfhost, localhost): port_num = [7000, 8000, 9000] - check = duthost.shell("test -e /etc/sonic/constants.yml || echo 'not present'") - if check['stdout'] == 'not present': - res = duthost.shell("sonic-cfggen -m -d -y /etc/sonic/deployment_id_asn_map.yml -v \"deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']]\"") - else: + constants_stat = duthost.stat(path="/etc/sonic/constants.yml") + if constants_stat["stat"]["exists"]: res = duthost.shell("sonic-cfggen -m -d -y /etc/sonic/constants.yml -v \"constants.deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']]\"") + else: + res = duthost.shell("sonic-cfggen -m -d -y /etc/sonic/deployment_id_asn_map.yml -v \"deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']]\"") bgp_speaker_asn = res['stdout'] logging.info("Start exabgp on ptf") From dd636958063b8df87f5f393001d807f6bf700bbe Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Mon, 3 Aug 2020 14:11:17 -0700 Subject: [PATCH 08/21] Check added nexthop routes using get_ip_route_info --- tests/bgp/test_bgp_speaker.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index 72ee89b001e..f4e75986eda 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -349,10 +349,11 @@ def test_bgp_speaker_announce_routes_ipv6(common_setup_teardown_v6, testbed, dut logging.info("Verify nexthops and nexthop interfaces for accepted prefixes of the dynamic neighbors") for i, nexthop in enumerate(nexthops_ipv6): prefix = 'fc00:1%d::/64' % i - cmd = "ip -6 route get %s" % prefix - output = duthost.shell(cmd) - res = output["stdout"].split("\n") - assert " via %s dev %s " % (nexthop.ip, vlan_if_name) in res[0] + rtinfo = duthost.get_ip_route_info(ipaddress.ip_network(unicode(prefix))) + logging.debug("prefix='%s' rtinfo=%s" % (prefix, rtinfo)) + assert len(rtinfo["nexthops"]) > 0 + assert rtinfo["nexthops"][0][0] == ipaddress.ip_address(unicode(nexthop.ip)) + assert rtinfo["nexthops"][0][1] == unicode(vlan_if_name) logging.info("Generate route-port map information") extra_vars = {'announce_prefix': 'fc00:10::/64', From c41154a1bb2fc71afb1aee0bd8b8f35973433e42 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Mon, 3 Aug 2020 14:15:34 -0700 Subject: [PATCH 09/21] Fix imports --- tests/bgp/test_bgp_speaker.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index f4e75986eda..3621392eee9 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -3,12 +3,15 @@ import time import logging import requests +import ipaddress + from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import] from tests.common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import] from tests.ptf_runner import ptf_runner from tests.common.utilities import wait_tcp_connection + pytestmark = [ pytest.mark.topology('t0'), pytest.mark.device_type('vs') From 06d2f22b1bce9db7a59759e9b4a38a77784fa818 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Mon, 3 Aug 2020 22:48:16 -0700 Subject: [PATCH 10/21] Working for me --- tests/bgp/test_bgp_speaker.py | 190 +++++++++------------------------- 1 file changed, 49 insertions(+), 141 deletions(-) diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index 3621392eee9..ff2b27c55d8 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -89,6 +89,19 @@ def common_setup_teardown(duthost, ptfhost, localhost): vlan_ports.append(mg_facts['minigraph_port_indices'][mg_facts['minigraph_vlans'][mg_facts['minigraph_vlan_interfaces'][0]['attachto']]['members'][i]]) logging.info("vlan_ports: %s" % str(vlan_ports)) + # Generate ipv6 nexthops + vlan_ipv6_entry = mg_facts['minigraph_vlan_interfaces'][1] + vlan_ipv6_prefix = "%s/%s" % (vlan_ipv6_entry["addr"], vlan_ipv6_entry["prefixlen"]) + vlan_ipv6_address = vlan_ipv6_entry["addr"] + vlan_if_name = vlan_ipv6_entry['attachto'] + nexthops_ipv6 = generate_ips(3, vlan_ipv6_prefix, [IPAddress(vlan_ipv6_address)]) + logging.info("Generated nexthops_ipv6: %s" % str(nexthops_ipv6)) + + # Set ipv6 nexthop addresses on the ptf interfaces + for nh in nexthops_ipv6: + duthost.command("ip -6 route flush %s/64" % nh.ip) + duthost.command("ip -6 route add %s/64 dev %s" % (nh.ip, vlan_if_name)) + logging.info("setup ip/routes in ptf") ptfhost.shell("ifconfig eth%d %s" % (vlan_ports[0], vlan_ips[0])) ptfhost.shell("ifconfig eth%d:0 %s" % (vlan_ports[0], speaker_ips[0])) @@ -100,6 +113,10 @@ def common_setup_teardown(duthost, ptfhost, localhost): ptfhost.shell("ip route flush %s/%d" % (lo_addr, lo_addr_prefixlen)) ptfhost.shell("ip route add %s/%d via %s" % (lo_addr, lo_addr_prefixlen, vlan_addr)) + logging.info("setup ip/routes in ptf") + for i in [0, 1, 2]: + ptfhost.shell("ip -6 addr add %s dev eth%d:%d" % (nexthops_ipv6[i], vlan_ports[0], i)) + logging.info("Start exabgp on ptf") for i in range(0, 3): local_ip = str(speaker_ips[i].ip) @@ -121,12 +138,17 @@ def common_setup_teardown(duthost, ptfhost, localhost): logging.info("########### Done setup for bgp speaker testing ###########") - yield ptfip, mg_facts, interface_facts, vlan_ips, speaker_ips, port_num, http_ready + yield ptfip, mg_facts, interface_facts, vlan_ips, vlan_if_name, nexthops_ipv6, speaker_ips, port_num, http_ready logging.info("########### Teardown for bgp speaker testing ###########") for i in range(0, 3): ptfhost.exabgp(name="bgps%d" % i, state="absent") + logging.info("exabgp stopped") + + for nh in nexthops_ipv6: + duthost.command("ip -6 route flush %s/64" % nh.ip) + logging.info("Flushed ipv6 nexthop routes from dut") for ip in vlan_ips: duthost.command("ip route flush %s/32" % ip.ip, module_ignore_errors=True) @@ -135,7 +157,6 @@ def common_setup_teardown(duthost, ptfhost, localhost): logging.info("########### Done teardown for bgp speaker testing ###########") - def test_bgp_speaker_bgp_sessions(common_setup_teardown, duthost, ptfhost, collect_techsupport): """Setup bgp speaker on T0 topology and verify bgp sessions are established """ @@ -149,13 +170,12 @@ def test_bgp_speaker_bgp_sessions(common_setup_teardown, duthost, ptfhost, colle "Not all bgp sessions are established" assert str(speaker_ips[2].ip) in bgp_facts["bgp_neighbors"], "No bgp session with PTF" - @pytest.mark.parametrize("ipv4, ipv6, mtu", [pytest.param(True, False, 1514)]) def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, ptfhost, ipv4, ipv6, mtu, collect_techsupport): """Setup bgp speaker on T0 topology and verify routes advertised by bgp speaker is received by T0 TOR """ - ptfip, mg_facts, interface_facts, vlan_ips, speaker_ips, port_num, http_ready = common_setup_teardown + ptfip, mg_facts, interface_facts, vlan_ips, vlan_if_name, nexthops_ipv6, speaker_ips, port_num, http_ready = common_setup_teardown assert http_ready logging.info("announce route") @@ -209,154 +229,42 @@ def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, pt socket_recv_size=16384) -@pytest.fixture(scope="module") -def common_setup_teardown_v6(duthost, ptfhost, localhost): - - logging.info("########### Setup for bgp speaker testing ###########") - - ptfhost.script("./scripts/remove_ip.sh") - - ptfip = ptfhost.host.options['inventory_manager'].get_host(ptfhost.hostname).vars['ansible_host'] - logging.info("ptfip=%s" % ptfip) - - mg_facts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] - interface_facts = duthost.interface_facts()['ansible_facts'] - # Generate ipv6 nexthops - vlan_ipv6_entry = mg_facts['minigraph_vlan_interfaces'][1] - vlan_ipv6_prefix = "%s/%s" % (vlan_ipv6_entry["addr"], vlan_ipv6_entry["prefixlen"]) - vlan_ipv6_address = vlan_ipv6_entry["addr"] - vlan_if_name = vlan_ipv6_entry['attachto'] - nexthops_ipv6 = generate_ips(3, vlan_ipv6_prefix, [IPAddress(vlan_ipv6_address)]) - logging.info("Generated nexthops_ipv6: %s" % str(nexthops_ipv6)) - - # Set ipv6 nexthop addresses on the ptf interfaces - for nh in nexthops_ipv6: - duthost.command("ip -6 route flush %s/64" % nh.ip) - duthost.command("ip -6 route add %s/64 dev %s" % (nh.ip, vlan_if_name)) - - # Generate ips for bgp dynamic peers - speaker_ips = generate_ips(3, mg_facts['minigraph_bgp_peers_with_range'][0]['ip_range'][0], []) - logging.info("speaker_ips: %s" % str(speaker_ips)) - - lo_addr = mg_facts['minigraph_lo_interfaces'][0]['addr'] - lo_addr_prefixlen = int(mg_facts['minigraph_lo_interfaces'][0]['prefixlen']) - - vlan_ipv4_addr = mg_facts['minigraph_vlan_interfaces'][0]['addr'] - - vlan_ports = [] - for i in [0, 1, 2]: - vlan_ports.append(mg_facts['minigraph_port_indices'][mg_facts['minigraph_vlans'][mg_facts['minigraph_vlan_interfaces'][0]['attachto']]['members'][i]]) - logging.info("vlan_ports: %s" % str(vlan_ports)) - - logging.info("setup ip/routes in ptf") - for i in [0, 1, 2]: - ptfhost.shell("ip -6 addr add %s dev eth%d:%d" % (nexthops_ipv6[i], vlan_ports[0], i)) - ptfhost.shell("ip addr add %s dev eth%d:%d" % (speaker_ips[i], vlan_ports[0], i)) - - # Generate ipv4 vlan ips - vlan_ipv4_entry = mg_facts['minigraph_vlan_interfaces'][0] - vlan_ipv4_prefix = "%s/%s" % (vlan_ipv4_entry["addr"], vlan_ipv4_entry["prefixlen"]) - vlan_ipv4_address = vlan_ipv4_entry["addr"] - vlan_ipv4s = generate_ips(3, vlan_ipv4_prefix, [IPAddress(vlan_ipv4_address)]) - logging.info("Generated vlan_ipv4: %s" % str(vlan_ipv4s)) - - ptfhost.shell("ip addr add %s dev eth%d:%d" % (vlan_ipv4s[0], vlan_ports[1], 0)) - ptfhost.shell("ip route flush %s/%d" % (lo_addr, lo_addr_prefixlen)) - ptfhost.shell("ip route add %s/%d via %s" % (lo_addr, lo_addr_prefixlen, vlan_ipv4_addr)) - - for i in [0, 1, 2]: - duthost.shell('ip route flush %s/32' % speaker_ips[i].ip) - duthost.shell("ip route add %s/32 via %s" % (speaker_ips[i].ip, vlan_ipv4s[0].ip)) - - port_num = [7000, 8000, 9000] - - constants_stat = duthost.stat(path="/etc/sonic/constants.yml") - if constants_stat["stat"]["exists"]: - res = duthost.shell("sonic-cfggen -m -d -y /etc/sonic/constants.yml -v \"constants.deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']]\"") - else: - res = duthost.shell("sonic-cfggen -m -d -y /etc/sonic/deployment_id_asn_map.yml -v \"deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']]\"") - bgp_speaker_asn = res['stdout'] - - logging.info("Start exabgp on ptf") - for i in [0, 1, 2]: - local_ip = str(speaker_ips[i].ip) - logging.info("local_ip=%s" % local_ip) - logging.info("router_id=%s" % local_ip) - logging.info("peer_ip=%s" % lo_addr) - logging.info("local_asn=%s" % bgp_speaker_asn) - logging.info("peer_asn=%s" % mg_facts['minigraph_bgp_asn']) - logging.info("port=%s" % str(port_num[i])) - logging.info("------------") - ptfhost.exabgp(name="bgps%d" % i, - state="started", - local_ip=local_ip, - router_id=local_ip, - peer_ip=lo_addr, - local_asn=bgp_speaker_asn, - peer_asn=mg_facts['minigraph_bgp_asn'], - port=str(port_num[i])) - - # check exabgp http_api port is ready - http_ready = True - for i in [0, 1, 2]: - http_ready = wait_tcp_connection(localhost, ptfip, port_num[i]) - if not http_ready: - break - - # ping - ptfhost.shell("ping -c 3 -S %s %s" % (speaker_ips[0].ip, lo_addr)) - - logging.info("########### Done setup for bgp speaker testing ###########") - - yield ptfip, mg_facts, interface_facts, lo_addr, vlan_if_name, nexthops_ipv6, speaker_ips, port_num, http_ready - - logging.info("########### Teardown for bgp speaker testing ###########") - - for i in [0, 1, 2]: - ptfhost.exabgp(name="bgps%d" % i, state="absent") - - logging.info("exabgp stopped") - - for nh in nexthops_ipv6: - duthost.command("ip -6 route flush %s/64" % nh.ip) - - logging.info("Flushed ipv6 nexthop routes from dut") - - for i in [0, 1, 2]: - duthost.shell("ip route del %s/32 via %s" % (speaker_ips[i].ip, vlan_ipv4s[0].ip)) - - logging.info("Removed ipv4 speaker routes from dut") - - ptfhost.script("./scripts/remove_ip.sh") - - logging.info("########### Done teardown for bgp speaker testing ###########") - - @pytest.mark.parametrize("ipv4, ipv6, mtu", [pytest.param(False, True, 1514)]) -def test_bgp_speaker_announce_routes_ipv6(common_setup_teardown_v6, testbed, duthost, ptfhost, ipv4, ipv6, mtu, collect_techsupport): +def test_bgp_speaker_announce_routes_v6(common_setup_teardown, testbed, duthost, ptfhost, ipv4, ipv6, mtu, collect_techsupport): """Setup bgp speaker on T0 topology and verify routes advertised by bgp speaker is received by T0 TOR """ - ptfip, mg_facts, interface_facts, lo_addr, vlan_if_name, nexthops_ipv6, speaker_ips, port_num, http_ready = common_setup_teardown_v6 + ptfip, mg_facts, interface_facts, vlan_ips, vlan_if_name, nexthops_ipv6, speaker_ips, port_num, http_ready = common_setup_teardown assert http_ready + logging.info("announce route") + peer_range = mg_facts['minigraph_bgp_peers_with_range'][0]['ip_range'][0] + lo_addr = mg_facts['minigraph_lo_interfaces'][0]['addr'] + lo_addr_prefixlen = int(mg_facts['minigraph_lo_interfaces'][0]['prefixlen']) + logging.info("Announce ipv6 prefixes over ipv4 bgp sessions") - for i, nexthop in enumerate(nexthops_ipv6): - prefix = 'fc00:1%d::/64' % i - logging.info("announce route: prefix: %s nexthops: %s" % (prefix, str(nexthop.ip))) - announce_route(ptfip, lo_addr, prefix, nexthop.ip, port_num[i]) + prefix = 'fc00:10::/64' + announce_route(ptfip, lo_addr, prefix, nexthops_ipv6[1].ip, port_num[0]) + announce_route(ptfip, lo_addr, prefix, nexthops_ipv6[2].ip, port_num[1]) + announce_route(ptfip, lo_addr, peer_range, vlan_ips[0].ip, port_num[2]) logging.info("Wait some time to make sure routes announced to dynamic bgp neighbors") time.sleep(30) + # The ping here is workaround for known issue: + # https://github.com/Azure/SONiC/issues/387 Pre-ARP support for static route config + # When there is no arp entry for next hop, routes learnt from exabgp will not be set down to ASIC + # Traffic to prefix 10.10.10.0 will be routed to vEOS VMs via default gateway. + duthost.shell("ping %s -c 3" % vlan_ips[1].ip) + duthost.shell("ping %s -c 3" % vlan_ips[2].ip) + time.sleep(5) + logging.info("Verify nexthops and nexthop interfaces for accepted prefixes of the dynamic neighbors") - for i, nexthop in enumerate(nexthops_ipv6): - prefix = 'fc00:1%d::/64' % i - rtinfo = duthost.get_ip_route_info(ipaddress.ip_network(unicode(prefix))) - logging.debug("prefix='%s' rtinfo=%s" % (prefix, rtinfo)) - assert len(rtinfo["nexthops"]) > 0 - assert rtinfo["nexthops"][0][0] == ipaddress.ip_address(unicode(nexthop.ip)) - assert rtinfo["nexthops"][0][1] == unicode(vlan_if_name) + rtinfo = duthost.get_ip_route_info(ipaddress.ip_network(unicode(prefix))) + assert len(rtinfo["nexthops"]) == 2 + for i in [0,1]: + assert str(rtinfo["nexthops"][i][0]) == str(nexthops_ipv6[i+1].ip) + assert rtinfo["nexthops"][i][1] == unicode(vlan_if_name) logging.info("Generate route-port map information") extra_vars = {'announce_prefix': 'fc00:10::/64', @@ -383,4 +291,4 @@ def test_bgp_speaker_announce_routes_ipv6(common_setup_teardown_v6, testbed, dut log_file="/tmp/bgp_speaker_test.FibTest.log", socket_recv_size=16384) - logging.info("Nexthop tests are done") + logging.info("Nexthop tests are done") \ No newline at end of file From 91878db1bcde0e7f53d15c57b4e713a43b6af4c6 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 4 Aug 2020 11:40:35 -0700 Subject: [PATCH 11/21] nexthop_ipv6 order could be rearranged --- tests/bgp/test_bgp_speaker.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index ff2b27c55d8..1b855ac3571 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -261,9 +261,10 @@ def test_bgp_speaker_announce_routes_v6(common_setup_teardown, testbed, duthost, logging.info("Verify nexthops and nexthop interfaces for accepted prefixes of the dynamic neighbors") rtinfo = duthost.get_ip_route_info(ipaddress.ip_network(unicode(prefix))) + nexthops_ipv6_set = { str(nexthop.ip) for nexthop in nexthops_ipv6 } assert len(rtinfo["nexthops"]) == 2 for i in [0,1]: - assert str(rtinfo["nexthops"][i][0]) == str(nexthops_ipv6[i+1].ip) + assert str(rtinfo["nexthops"][i][0]) in nexthops_ipv6_set assert rtinfo["nexthops"][i][1] == unicode(vlan_if_name) logging.info("Generate route-port map information") From 2fb3a2169413d9095c1f631bc380910fdea96589 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 4 Aug 2020 12:07:35 -0700 Subject: [PATCH 12/21] Use correct number of arguments --- tests/bgp/test_bgp_speaker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index 1b855ac3571..5c8e2b655d5 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -160,7 +160,7 @@ def common_setup_teardown(duthost, ptfhost, localhost): def test_bgp_speaker_bgp_sessions(common_setup_teardown, duthost, ptfhost, collect_techsupport): """Setup bgp speaker on T0 topology and verify bgp sessions are established """ - ptfip, mg_facts, interface_facts, vlan_ips, speaker_ips, port_num, http_ready = common_setup_teardown + ptfip, mg_facts, interface_facts, vlan_ips, _, __, speaker_ips, port_num, http_ready = common_setup_teardown assert http_ready logging.info("Wait some time to verify that bgp sessions are established") @@ -175,7 +175,7 @@ def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, pt """Setup bgp speaker on T0 topology and verify routes advertised by bgp speaker is received by T0 TOR """ - ptfip, mg_facts, interface_facts, vlan_ips, vlan_if_name, nexthops_ipv6, speaker_ips, port_num, http_ready = common_setup_teardown + ptfip, mg_facts, interface_facts, vlan_ips, _, __, speaker_ips, port_num, http_ready = common_setup_teardown assert http_ready logging.info("announce route") From b65f811528c639cca4f60fa87d3102709577a20d Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 4 Aug 2020 12:43:23 -0700 Subject: [PATCH 13/21] Fix lgtm warnings --- tests/bgp/test_bgp_speaker.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index 5c8e2b655d5..23fc5ac1b76 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -181,7 +181,7 @@ def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, pt logging.info("announce route") peer_range = mg_facts['minigraph_bgp_peers_with_range'][0]['ip_range'][0] lo_addr = mg_facts['minigraph_lo_interfaces'][0]['addr'] - lo_addr_prefixlen = int(mg_facts['minigraph_lo_interfaces'][0]['prefixlen']) + prefix = '10.10.10.0/26' announce_route(ptfip, lo_addr, prefix, vlan_ips[1].ip, port_num[0]) announce_route(ptfip, lo_addr, prefix, vlan_ips[2].ip, port_num[1]) @@ -240,7 +240,6 @@ def test_bgp_speaker_announce_routes_v6(common_setup_teardown, testbed, duthost, logging.info("announce route") peer_range = mg_facts['minigraph_bgp_peers_with_range'][0]['ip_range'][0] lo_addr = mg_facts['minigraph_lo_interfaces'][0]['addr'] - lo_addr_prefixlen = int(mg_facts['minigraph_lo_interfaces'][0]['prefixlen']) logging.info("Announce ipv6 prefixes over ipv4 bgp sessions") prefix = 'fc00:10::/64' From 97d24b83413aa191d869fc39a143f6d56f84551b Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Tue, 4 Aug 2020 23:16:35 -0700 Subject: [PATCH 14/21] Temporary. For debug --- tests/bgp/test_bgp_speaker.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index 23fc5ac1b76..4efbc04ee09 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -90,10 +90,15 @@ def common_setup_teardown(duthost, ptfhost, localhost): logging.info("vlan_ports: %s" % str(vlan_ports)) # Generate ipv6 nexthops - vlan_ipv6_entry = mg_facts['minigraph_vlan_interfaces'][1] - vlan_ipv6_prefix = "%s/%s" % (vlan_ipv6_entry["addr"], vlan_ipv6_entry["prefixlen"]) - vlan_ipv6_address = vlan_ipv6_entry["addr"] - vlan_if_name = vlan_ipv6_entry['attachto'] + if len(mg_facts['minigraph_vlan_interfaces']) > 1: + vlan_ipv6_entry = mg_facts['minigraph_vlan_interfaces'][1] + vlan_ipv6_prefix = "%s/%s" % (vlan_ipv6_entry["addr"], vlan_ipv6_entry["prefixlen"]) + vlan_ipv6_address = vlan_ipv6_entry["addr"] + vlan_if_name = vlan_ipv6_entry['attachto'] + else: + vlan_ipv6_prefix = "fc02:1000::1/64" + vlan_ipv6_address = "fc02:1000::1" + vlan_if_name = mg_facts['minigraph_vlan_interfaces'][0]['attachto'] nexthops_ipv6 = generate_ips(3, vlan_ipv6_prefix, [IPAddress(vlan_ipv6_address)]) logging.info("Generated nexthops_ipv6: %s" % str(nexthops_ipv6)) From a0a58afa334f1139d5cb1572db58136f245fa46d Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Thu, 6 Aug 2020 13:54:38 -0700 Subject: [PATCH 15/21] Revert "Temporary. For debug" This reverts commit 97d24b83413aa191d869fc39a143f6d56f84551b. --- tests/bgp/test_bgp_speaker.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index 4efbc04ee09..23fc5ac1b76 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -90,15 +90,10 @@ def common_setup_teardown(duthost, ptfhost, localhost): logging.info("vlan_ports: %s" % str(vlan_ports)) # Generate ipv6 nexthops - if len(mg_facts['minigraph_vlan_interfaces']) > 1: - vlan_ipv6_entry = mg_facts['minigraph_vlan_interfaces'][1] - vlan_ipv6_prefix = "%s/%s" % (vlan_ipv6_entry["addr"], vlan_ipv6_entry["prefixlen"]) - vlan_ipv6_address = vlan_ipv6_entry["addr"] - vlan_if_name = vlan_ipv6_entry['attachto'] - else: - vlan_ipv6_prefix = "fc02:1000::1/64" - vlan_ipv6_address = "fc02:1000::1" - vlan_if_name = mg_facts['minigraph_vlan_interfaces'][0]['attachto'] + vlan_ipv6_entry = mg_facts['minigraph_vlan_interfaces'][1] + vlan_ipv6_prefix = "%s/%s" % (vlan_ipv6_entry["addr"], vlan_ipv6_entry["prefixlen"]) + vlan_ipv6_address = vlan_ipv6_entry["addr"] + vlan_if_name = vlan_ipv6_entry['attachto'] nexthops_ipv6 = generate_ips(3, vlan_ipv6_prefix, [IPAddress(vlan_ipv6_address)]) logging.info("Generated nexthops_ipv6: %s" % str(nexthops_ipv6)) From e36828a4590da08baf6dd8e1ca23244809b2f76a Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Fri, 7 Aug 2020 10:24:11 -0700 Subject: [PATCH 16/21] Rename double _ to _ --- tests/bgp/test_bgp_speaker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index 4863a050722..a206f82806d 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -157,7 +157,7 @@ def common_setup_teardown(duthost, ptfhost, localhost): def test_bgp_speaker_bgp_sessions(common_setup_teardown, duthost, ptfhost, collect_techsupport): """Setup bgp speaker on T0 topology and verify bgp sessions are established """ - ptfip, mg_facts, interface_facts, vlan_ips, _, __, speaker_ips, port_num, http_ready = common_setup_teardown + ptfip, mg_facts, interface_facts, vlan_ips, _, _, speaker_ips, port_num, http_ready = common_setup_teardown assert http_ready logging.info("Wait some time to verify that bgp sessions are established") @@ -172,7 +172,7 @@ def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, pt """Setup bgp speaker on T0 topology and verify routes advertised by bgp speaker is received by T0 TOR """ - ptfip, mg_facts, interface_facts, vlan_ips, _, __, speaker_ips, port_num, http_ready = common_setup_teardown + ptfip, mg_facts, interface_facts, vlan_ips, _, _, speaker_ips, port_num, http_ready = common_setup_teardown assert http_ready logging.info("announce route") From a37834b8e505b0da584058cd9bd5a3f9c2ac66d0 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Fri, 7 Aug 2020 10:25:56 -0700 Subject: [PATCH 17/21] Rename /root/bgp_speaker_route.txt to /root/bgp_speaker_v6route.txt for the ipv6 test --- tests/bgp/test_bgp_speaker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index a206f82806d..56d159ddec4 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -208,7 +208,7 @@ def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, pt ptfhost.host.options['variable_manager'].extra_vars.update(extra_vars) logging.info("extra_vars: %s" % str(ptfhost.host.options['variable_manager'].extra_vars)) - ptfhost.template(src="bgp_speaker/bgp_speaker_route.j2", dest="/root/bgp_speaker_route.txt") + ptfhost.template(src="bgp_speaker/bgp_speaker_route.j2", dest="/root/bgp_speaker_v6route.txt") logging.info("run ptf test") @@ -218,7 +218,7 @@ def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, pt platform_dir="ptftests", params={"testbed_type": testbed['topo']['name'], "router_mac": interface_facts['ansible_interface_facts']['Ethernet0']['macaddress'], - "fib_info": "/root/bgp_speaker_route.txt", + "fib_info": "/root/bgp_speaker_v6route.txt", "ipv4": ipv4, "ipv6": ipv6, "testbed_mtu": mtu }, From 6b6eaebe012d2167b2ada385a177b1b1a165a2b2 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Fri, 7 Aug 2020 14:41:10 -0700 Subject: [PATCH 18/21] Add nexthop check into test_bgp_speaker_announce_routes() --- tests/bgp/test_bgp_speaker.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index 56d159ddec4..341ef971e6c 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -172,7 +172,7 @@ def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, pt """Setup bgp speaker on T0 topology and verify routes advertised by bgp speaker is received by T0 TOR """ - ptfip, mg_facts, interface_facts, vlan_ips, _, _, speaker_ips, port_num, http_ready = common_setup_teardown + ptfip, mg_facts, interface_facts, vlan_ips, vlan_if_name, _, speaker_ips, port_num, http_ready = common_setup_teardown assert http_ready logging.info("announce route") @@ -200,6 +200,14 @@ def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, pt for ip in speaker_ips: assert bgp_facts['bgp_neighbors'][str(ip.ip)]['accepted prefixes'] == 1 + logging.info("Verify nexthops and nexthop interfaces for accepted prefixes of the dynamic neighbors") + rtinfo = duthost.get_ip_route_info(ipaddress.ip_network(unicode(prefix))) + nexthops_ip_set = { str(nexthop.ip) for nexthop in vlan_ips } + assert len(rtinfo["nexthops"]) == 2 + for i in [0,1]: + assert str(rtinfo["nexthops"][i][0]) in nexthops_ip_set + assert rtinfo["nexthops"][i][1] == unicode(vlan_if_name) + logging.info("Generate route-port map information") extra_vars = {'announce_prefix': '10.10.10.0/26', 'minigraph_portchannels': mg_facts['minigraph_portchannels'], From 38f08c912deca0d5dbdf5cd5859d5e00f984689d Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Fri, 7 Aug 2020 17:34:41 -0700 Subject: [PATCH 19/21] Check number of received routes --- tests/bgp/test_bgp_speaker.py | 38 +++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index 341ef971e6c..47157a6952b 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -37,14 +37,18 @@ def generate_ips(num, prefix, exclude_ips): return generated_ips - def announce_route(ptfip, neighbor, route, nexthop, port): + change_route("announce", ptfip, neighbor, route, nexthop, port) + +def withdraw_route(ptfip, neighbor, route, nexthop, port): + change_route("withdraw", ptfip, neighbor, route, nexthop, port) + +def change_route(operation, ptfip, neighbor, route, nexthop, port): url = "http://%s:%d" % (ptfip, port) - data = {"command": "neighbor %s announce route %s next-hop %s" % (neighbor, route, nexthop)} + data = {"command": "neighbor %s %s route %s next-hop %s" % (neighbor, operation, route, nexthop)} r = requests.post(url, data=data) assert r.status_code == 200 - @pytest.fixture(scope="module") def common_setup_teardown(duthost, ptfhost, localhost): @@ -154,6 +158,7 @@ def common_setup_teardown(duthost, ptfhost, localhost): logging.info("########### Done teardown for bgp speaker testing ###########") + def test_bgp_speaker_bgp_sessions(common_setup_teardown, duthost, ptfhost, collect_techsupport): """Setup bgp speaker on T0 topology and verify bgp sessions are established """ @@ -167,6 +172,7 @@ def test_bgp_speaker_bgp_sessions(common_setup_teardown, duthost, ptfhost, colle "Not all bgp sessions are established" assert str(speaker_ips[2].ip) in bgp_facts["bgp_neighbors"], "No bgp session with PTF" + @pytest.mark.parametrize("ipv4, ipv6, mtu", [pytest.param(True, False, 1514)]) def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, ptfhost, ipv4, ipv6, mtu, collect_techsupport): """Setup bgp speaker on T0 topology and verify routes advertised by bgp speaker is received by T0 TOR @@ -216,7 +222,7 @@ def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, pt ptfhost.host.options['variable_manager'].extra_vars.update(extra_vars) logging.info("extra_vars: %s" % str(ptfhost.host.options['variable_manager'].extra_vars)) - ptfhost.template(src="bgp_speaker/bgp_speaker_route.j2", dest="/root/bgp_speaker_v6route.txt") + ptfhost.template(src="bgp_speaker/bgp_speaker_route.j2", dest="/root/bgp_speaker_route.txt") logging.info("run ptf test") @@ -226,13 +232,20 @@ def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, pt platform_dir="ptftests", params={"testbed_type": testbed['topo']['name'], "router_mac": interface_facts['ansible_interface_facts']['Ethernet0']['macaddress'], - "fib_info": "/root/bgp_speaker_v6route.txt", + "fib_info": "/root/bgp_speaker_route.txt", "ipv4": ipv4, "ipv6": ipv6, "testbed_mtu": mtu }, log_file="/tmp/bgp_speaker_test.FibTest.log", socket_recv_size=16384) + logging.info("Withdraw routes") + withdraw_route(ptfip, lo_addr, prefix, vlan_ips[1].ip, port_num[0]) + withdraw_route(ptfip, lo_addr, prefix, vlan_ips[2].ip, port_num[1]) + withdraw_route(ptfip, lo_addr, peer_range, vlan_ips[0].ip, port_num[2]) + + logging.info("Nexthop ipv4 tests are done") + @pytest.mark.parametrize("ipv4, ipv6, mtu", [pytest.param(False, True, 1514)]) def test_bgp_speaker_announce_routes_v6(common_setup_teardown, testbed, duthost, ptfhost, ipv4, ipv6, mtu, collect_techsupport): @@ -263,6 +276,11 @@ def test_bgp_speaker_announce_routes_v6(common_setup_teardown, testbed, duthost, duthost.shell("ping %s -c 3" % vlan_ips[2].ip) time.sleep(5) + logging.info("Verify accepted prefixes of the dynamic neighbors are correct") + bgp_facts = duthost.bgp_facts()['ansible_facts'] + for ip in speaker_ips: + assert bgp_facts['bgp_neighbors'][str(ip.ip)]['accepted prefixes'] == 1 + logging.info("Verify nexthops and nexthop interfaces for accepted prefixes of the dynamic neighbors") rtinfo = duthost.get_ip_route_info(ipaddress.ip_network(unicode(prefix))) nexthops_ipv6_set = { str(nexthop.ip) for nexthop in nexthops_ipv6 } @@ -279,7 +297,7 @@ def test_bgp_speaker_announce_routes_v6(common_setup_teardown, testbed, duthost, ptfhost.host.options['variable_manager'].extra_vars.update(extra_vars) logging.info("extra_vars: %s" % str(ptfhost.host.options['variable_manager'].extra_vars)) - ptfhost.template(src="bgp_speaker/bgp_speaker_route.j2", dest="/root/bgp_speaker_route.txt") + ptfhost.template(src="bgp_speaker/bgp_speaker_route.j2", dest="/root/bgp_speaker_v6route.txt") logging.info("run ptf test") @@ -289,11 +307,15 @@ def test_bgp_speaker_announce_routes_v6(common_setup_teardown, testbed, duthost, platform_dir="ptftests", params={"testbed_type": testbed['topo']['name'], "router_mac": interface_facts['ansible_interface_facts']['Ethernet0']['macaddress'], - "fib_info": "/root/bgp_speaker_route.txt", + "fib_info": "/root/bgp_speaker_v6route.txt", "ipv4": ipv4, "ipv6": ipv6, "testbed_mtu": mtu }, log_file="/tmp/bgp_speaker_test.FibTest.log", socket_recv_size=16384) - logging.info("Nexthop tests are done") \ No newline at end of file + withdraw_route(ptfip, lo_addr, prefix, nexthops_ipv6[1].ip, port_num[0]) + withdraw_route(ptfip, lo_addr, prefix, nexthops_ipv6[2].ip, port_num[1]) + withdraw_route(ptfip, lo_addr, peer_range, vlan_ips[0].ip, port_num[2]) + + logging.info("Nexthop ipv6 tests are done") From 2a8741def3b0f62ef58e5ced86f918b99c8d9994 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Sat, 8 Aug 2020 23:09:03 -0700 Subject: [PATCH 20/21] Change order in yield --- tests/bgp/test_bgp_speaker.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index 47157a6952b..21e69851753 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -141,7 +141,7 @@ def common_setup_teardown(duthost, ptfhost, localhost): logging.info("########### Done setup for bgp speaker testing ###########") - yield ptfip, mg_facts, interface_facts, vlan_ips, vlan_if_name, nexthops_ipv6, speaker_ips, port_num, http_ready + yield ptfip, mg_facts, interface_facts, vlan_ips, nexthops_ipv6, vlan_if_name, speaker_ips, port_num, http_ready logging.info("########### Teardown for bgp speaker testing ###########") @@ -178,7 +178,7 @@ def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, pt """Setup bgp speaker on T0 topology and verify routes advertised by bgp speaker is received by T0 TOR """ - ptfip, mg_facts, interface_facts, vlan_ips, vlan_if_name, _, speaker_ips, port_num, http_ready = common_setup_teardown + ptfip, mg_facts, interface_facts, vlan_ips, _, vlan_if_name, speaker_ips, port_num, http_ready = common_setup_teardown assert http_ready logging.info("announce route") @@ -252,7 +252,7 @@ def test_bgp_speaker_announce_routes_v6(common_setup_teardown, testbed, duthost, """Setup bgp speaker on T0 topology and verify routes advertised by bgp speaker is received by T0 TOR """ - ptfip, mg_facts, interface_facts, vlan_ips, vlan_if_name, nexthops_ipv6, speaker_ips, port_num, http_ready = common_setup_teardown + ptfip, mg_facts, interface_facts, vlan_ips, nexthops_ipv6, vlan_if_name, speaker_ips, port_num, http_ready = common_setup_teardown assert http_ready logging.info("announce route") From 34bbeecd0485f46211455c22e554c4bdaf6e5044 Mon Sep 17 00:00:00 2001 From: Pavel Shirshov Date: Mon, 10 Aug 2020 14:28:29 -0700 Subject: [PATCH 21/21] Extract common test body --- tests/bgp/test_bgp_speaker.py | 99 ++++++++--------------------------- 1 file changed, 21 insertions(+), 78 deletions(-) diff --git a/tests/bgp/test_bgp_speaker.py b/tests/bgp/test_bgp_speaker.py index 21e69851753..ffdcf9a2a1e 100644 --- a/tests/bgp/test_bgp_speaker.py +++ b/tests/bgp/test_bgp_speaker.py @@ -173,8 +173,7 @@ def test_bgp_speaker_bgp_sessions(common_setup_teardown, duthost, ptfhost, colle assert str(speaker_ips[2].ip) in bgp_facts["bgp_neighbors"], "No bgp session with PTF" -@pytest.mark.parametrize("ipv4, ipv6, mtu", [pytest.param(True, False, 1514)]) -def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, ptfhost, ipv4, ipv6, mtu, collect_techsupport): +def bgp_speaker_announce_routes_common(common_setup_teardown, testbed, duthost, ptfhost, ipv4, ipv6, mtu, family, prefix, nexthop_ips): """Setup bgp speaker on T0 topology and verify routes advertised by bgp speaker is received by T0 TOR """ @@ -185,9 +184,9 @@ def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, pt peer_range = mg_facts['minigraph_bgp_peers_with_range'][0]['ip_range'][0] lo_addr = mg_facts['minigraph_lo_interfaces'][0]['addr'] - prefix = '10.10.10.0/26' - announce_route(ptfip, lo_addr, prefix, vlan_ips[1].ip, port_num[0]) - announce_route(ptfip, lo_addr, prefix, vlan_ips[2].ip, port_num[1]) + logging.info("Announce ip%s prefixes over ipv4 bgp sessions" % family) + announce_route(ptfip, lo_addr, prefix, nexthop_ips[1].ip, port_num[0]) + announce_route(ptfip, lo_addr, prefix, nexthop_ips[2].ip, port_num[1]) announce_route(ptfip, lo_addr, peer_range, vlan_ips[0].ip, port_num[2]) logging.info("Wait some time to make sure routes announced to dynamic bgp neighbors") @@ -208,21 +207,21 @@ def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, pt logging.info("Verify nexthops and nexthop interfaces for accepted prefixes of the dynamic neighbors") rtinfo = duthost.get_ip_route_info(ipaddress.ip_network(unicode(prefix))) - nexthops_ip_set = { str(nexthop.ip) for nexthop in vlan_ips } + nexthops_ip_set = { str(nexthop.ip) for nexthop in nexthop_ips } assert len(rtinfo["nexthops"]) == 2 for i in [0,1]: assert str(rtinfo["nexthops"][i][0]) in nexthops_ip_set assert rtinfo["nexthops"][i][1] == unicode(vlan_if_name) logging.info("Generate route-port map information") - extra_vars = {'announce_prefix': '10.10.10.0/26', + extra_vars = {'announce_prefix': prefix, 'minigraph_portchannels': mg_facts['minigraph_portchannels'], 'minigraph_vlans': mg_facts['minigraph_vlans'], 'minigraph_port_indices': mg_facts['minigraph_port_indices']} ptfhost.host.options['variable_manager'].extra_vars.update(extra_vars) logging.info("extra_vars: %s" % str(ptfhost.host.options['variable_manager'].extra_vars)) - ptfhost.template(src="bgp_speaker/bgp_speaker_route.j2", dest="/root/bgp_speaker_route.txt") + ptfhost.template(src="bgp_speaker/bgp_speaker_route.j2", dest="/root/bgp_speaker_route_%s.txt" % family) logging.info("run ptf test") @@ -232,7 +231,7 @@ def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, pt platform_dir="ptftests", params={"testbed_type": testbed['topo']['name'], "router_mac": interface_facts['ansible_interface_facts']['Ethernet0']['macaddress'], - "fib_info": "/root/bgp_speaker_route.txt", + "fib_info": "/root/bgp_speaker_route_%s.txt" % family, "ipv4": ipv4, "ipv6": ipv6, "testbed_mtu": mtu }, @@ -240,82 +239,26 @@ def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, pt socket_recv_size=16384) logging.info("Withdraw routes") - withdraw_route(ptfip, lo_addr, prefix, vlan_ips[1].ip, port_num[0]) - withdraw_route(ptfip, lo_addr, prefix, vlan_ips[2].ip, port_num[1]) + withdraw_route(ptfip, lo_addr, prefix, nexthop_ips[1].ip, port_num[0]) + withdraw_route(ptfip, lo_addr, prefix, nexthop_ips[2].ip, port_num[1]) withdraw_route(ptfip, lo_addr, peer_range, vlan_ips[0].ip, port_num[2]) - logging.info("Nexthop ipv4 tests are done") + logging.info("Nexthop ip%s tests are done" % family) -@pytest.mark.parametrize("ipv4, ipv6, mtu", [pytest.param(False, True, 1514)]) -def test_bgp_speaker_announce_routes_v6(common_setup_teardown, testbed, duthost, ptfhost, ipv4, ipv6, mtu, collect_techsupport): +@pytest.mark.parametrize("ipv4, ipv6, mtu", [pytest.param(True, False, 1514)]) +def test_bgp_speaker_announce_routes(common_setup_teardown, testbed, duthost, ptfhost, ipv4, ipv6, mtu, collect_techsupport): """Setup bgp speaker on T0 topology and verify routes advertised by bgp speaker is received by T0 TOR """ - ptfip, mg_facts, interface_facts, vlan_ips, nexthops_ipv6, vlan_if_name, speaker_ips, port_num, http_ready = common_setup_teardown - assert http_ready - - logging.info("announce route") - peer_range = mg_facts['minigraph_bgp_peers_with_range'][0]['ip_range'][0] - lo_addr = mg_facts['minigraph_lo_interfaces'][0]['addr'] - - logging.info("Announce ipv6 prefixes over ipv4 bgp sessions") - prefix = 'fc00:10::/64' - announce_route(ptfip, lo_addr, prefix, nexthops_ipv6[1].ip, port_num[0]) - announce_route(ptfip, lo_addr, prefix, nexthops_ipv6[2].ip, port_num[1]) - announce_route(ptfip, lo_addr, peer_range, vlan_ips[0].ip, port_num[2]) + nexthops = common_setup_teardown[3] + bgp_speaker_announce_routes_common(common_setup_teardown, testbed, duthost, ptfhost, ipv4, ipv6, mtu, "v4", "10.10.10.0/26", nexthops) - logging.info("Wait some time to make sure routes announced to dynamic bgp neighbors") - time.sleep(30) - # The ping here is workaround for known issue: - # https://github.com/Azure/SONiC/issues/387 Pre-ARP support for static route config - # When there is no arp entry for next hop, routes learnt from exabgp will not be set down to ASIC - # Traffic to prefix 10.10.10.0 will be routed to vEOS VMs via default gateway. - duthost.shell("ping %s -c 3" % vlan_ips[1].ip) - duthost.shell("ping %s -c 3" % vlan_ips[2].ip) - time.sleep(5) - - logging.info("Verify accepted prefixes of the dynamic neighbors are correct") - bgp_facts = duthost.bgp_facts()['ansible_facts'] - for ip in speaker_ips: - assert bgp_facts['bgp_neighbors'][str(ip.ip)]['accepted prefixes'] == 1 - - logging.info("Verify nexthops and nexthop interfaces for accepted prefixes of the dynamic neighbors") - rtinfo = duthost.get_ip_route_info(ipaddress.ip_network(unicode(prefix))) - nexthops_ipv6_set = { str(nexthop.ip) for nexthop in nexthops_ipv6 } - assert len(rtinfo["nexthops"]) == 2 - for i in [0,1]: - assert str(rtinfo["nexthops"][i][0]) in nexthops_ipv6_set - assert rtinfo["nexthops"][i][1] == unicode(vlan_if_name) - - logging.info("Generate route-port map information") - extra_vars = {'announce_prefix': 'fc00:10::/64', - 'minigraph_portchannels': mg_facts['minigraph_portchannels'], - 'minigraph_vlans': mg_facts['minigraph_vlans'], - 'minigraph_port_indices': mg_facts['minigraph_port_indices']} - ptfhost.host.options['variable_manager'].extra_vars.update(extra_vars) - logging.info("extra_vars: %s" % str(ptfhost.host.options['variable_manager'].extra_vars)) - - ptfhost.template(src="bgp_speaker/bgp_speaker_route.j2", dest="/root/bgp_speaker_v6route.txt") - - logging.info("run ptf test") - - ptf_runner(ptfhost, - "ptftests", - "fib_test.FibTest", - platform_dir="ptftests", - params={"testbed_type": testbed['topo']['name'], - "router_mac": interface_facts['ansible_interface_facts']['Ethernet0']['macaddress'], - "fib_info": "/root/bgp_speaker_v6route.txt", - "ipv4": ipv4, - "ipv6": ipv6, - "testbed_mtu": mtu }, - log_file="/tmp/bgp_speaker_test.FibTest.log", - socket_recv_size=16384) - - withdraw_route(ptfip, lo_addr, prefix, nexthops_ipv6[1].ip, port_num[0]) - withdraw_route(ptfip, lo_addr, prefix, nexthops_ipv6[2].ip, port_num[1]) - withdraw_route(ptfip, lo_addr, peer_range, vlan_ips[0].ip, port_num[2]) +@pytest.mark.parametrize("ipv4, ipv6, mtu", [pytest.param(False, True, 1514)]) +def test_bgp_speaker_announce_routes_v6(common_setup_teardown, testbed, duthost, ptfhost, ipv4, ipv6, mtu, collect_techsupport): + """Setup bgp speaker on T0 topology and verify routes advertised by bgp speaker is received by T0 TOR - logging.info("Nexthop ipv6 tests are done") + """ + nexthops = common_setup_teardown[4] + bgp_speaker_announce_routes_common(common_setup_teardown, testbed, duthost, ptfhost, ipv4, ipv6, mtu, "v6", "fc00:10::/64", nexthops)