Exemple #1
0
def test_telemetry_ouput(duthost, ptfhost, localhost):
    """Run pyclient from ptfdocker and show gnmi server outputself.
    """
    docker_present = verify_telemetry_dockerimage(duthost)
    if not docker_present:
        pytest.skip("docker-sonic-telemetry is not part of the image")

    logger.info('start telemetry output testing')
    setup_telemetry_forpyclient(duthost)

    # wait till telemetry is restarted
    pytest_assert(
        wait_until(100, 10, duthost.is_service_fully_started, "telemetry"),
        "TELEMETRY not started")
    logger.info('telemetry process restarted. Now run pyclient on ptfdocker')

    # Wait until the TCP port is open
    dut_ip = duthost.mgmt_ip
    wait_tcp_connection(localhost, dut_ip, TELEMETRY_PORT, timeout_s=60)

    # pyclient should be available on ptfhost. If not fail pytest.
    file_exists = ptfhost.stat(path="/gnxi/gnmi_cli_py/py_gnmicli.py")
    pytest_assert(file_exists["stat"]["exists"] is True)
    cmd = 'python /gnxi/gnmi_cli_py/py_gnmicli.py -g -t {0} -p {1} -m get -x COUNTERS/Ethernet0 -xt COUNTERS_DB \
           -o "ndastreamingservertest"'.format(dut_ip, TELEMETRY_PORT)
    show_gnmi_out = ptfhost.shell(cmd)['stdout']
    logger.info("GNMI Server output")
    logger.info(show_gnmi_out)
    result = str(show_gnmi_out)
    inerrors_match = re.search("SAI_PORT_STAT_IF_IN_ERRORS", result)
    pytest_assert(inerrors_match is not None,
                  "SAI_PORT_STAT_IF_IN_ERRORS not found in gnmi_output")
def setup_streaming_telemetry(duthosts, rand_one_dut_hostname, localhost,  ptfhost):
    """
    @summary: Post setting up the streaming telemetry before running the test.
    """
    duthost = duthosts[rand_one_dut_hostname]
    setup_telemetry_forpyclient(duthost)

    # Wait until telemetry was restarted
    pytest_assert(wait_until(100, 10, duthost.is_service_fully_started, "telemetry"), "TELEMETRY not started.")
    logger.info("telemetry process restarted. Now run pyclient on ptfdocker")

    # Wait until the TCP port was opened
    dut_ip = duthost.mgmt_ip
    wait_tcp_connection(localhost, dut_ip, TELEMETRY_PORT, timeout_s=60)

    # pyclient should be available on ptfhost. If it was not available, then fail pytest.
    file_exists = ptfhost.stat(path="/gnxi/gnmi_cli_py/py_gnmicli.py")
    pytest_assert(file_exists["stat"]["exists"] is True)
Exemple #3
0
def bgpmon_setup_teardown(ptfhost, duthost, localhost, setup_interfaces):
    connection = setup_interfaces[0]
    dut_lo_addr = connection["loopback_ip"].split("/")[0]
    peer_addr = connection['neighbor_addr'].split("/")[0]
    mg_facts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts']
    asn = mg_facts['minigraph_bgp_asn']
    # TODO: Add a common method to load BGPMON config for test_bgpmon and test_traffic_shift
    logger.info("Configuring bgp monitor session on DUT")
    bgpmon_args = {
        'db_table_name': 'BGP_MONITORS',
        'peer_addr': peer_addr,
        'asn': asn,
        'local_addr': dut_lo_addr,
        'peer_name': BGP_MONITOR_NAME
    }
    bgpmon_template = Template(open(BGPMON_TEMPLATE_FILE).read())
    duthost.copy(content=bgpmon_template.render(**bgpmon_args),
                 dest=BGPMON_CONFIG_FILE)
    # Start bgpmon on DUT
    logger.info("Starting bgpmon on DUT")
    duthost.command("sonic-cfggen -j {} -w".format(BGPMON_CONFIG_FILE))

    logger.info("Starting bgp monitor session on PTF")
    ptfhost.file(path=DUMP_FILE, state="absent")
    ptfhost.copy(src=CUSTOM_DUMP_SCRIPT, dest=CUSTOM_DUMP_SCRIPT_DEST)
    ptfhost.exabgp(name=BGP_MONITOR_NAME,
                   state="started",
                   local_ip=peer_addr,
                   router_id=peer_addr,
                   peer_ip=dut_lo_addr,
                   local_asn=asn,
                   peer_asn=asn,
                   port=BGP_MONITOR_PORT,
                   dump_script=CUSTOM_DUMP_SCRIPT_DEST)
    # Add the route to DUT loopback IP  and the interface router mac
    ptfhost.shell("ip neigh add %s lladdr %s dev %s" %
                  (dut_lo_addr, duthost.facts["router_mac"],
                   connection["neighbor_intf"]))
    ptfhost.shell("ip route add %s dev %s" %
                  (dut_lo_addr + "/32", connection["neighbor_intf"]))

    pt_assert(
        wait_tcp_connection(localhost, ptfhost.mgmt_ip, BGP_MONITOR_PORT),
        "Failed to start bgp monitor session on PTF")
    yield
    # Cleanup bgp monitor
    duthost.shell("redis-cli -n 4 -c DEL 'BGP_MONITORS|{}'".format(peer_addr))
    ptfhost.exabgp(name=BGP_MONITOR_NAME, state="absent")
    ptfhost.file(path=CUSTOM_DUMP_SCRIPT_DEST, state="absent")
    ptfhost.file(path=DUMP_FILE, state="absent")
    # Remove the route to DUT loopback IP  and the interface router mac
    ptfhost.shell("ip route del %s dev %s" %
                  (dut_lo_addr + "/32", connection["neighbor_intf"]))
    ptfhost.shell("ip neigh del %s lladdr %s dev %s" %
                  (dut_lo_addr, duthost.facts["router_mac"],
                   connection["neighbor_intf"]))
    def start_session(self):
        """Start the BGP session."""
        logging.debug("start bgp session %s", self.name)
        self.ptfhost.shell("ifconfig %s %s/32" % (self.iface, self.ip))
        self.ptfhost.exabgp(
            name=self.name,
            state="started",
            local_ip=self.ip,
            router_id=self.ip,
            peer_ip=self.peer_ip,
            local_asn=self.asn,
            peer_asn=self.peer_asn,
            port=self.port
        )
        if not wait_tcp_connection(self.ptfhost, self.ptfip, self.port):
            raise RuntimeError("Failed to start BGP neighbor %s" % self.name)

        _write_variable_from_j2_to_configdb(
            self.duthost,
            "bgp/templates/neighbor_metadata_template.j2",
            save_dest_path=NEIGHBOR_SAVE_DEST_TMPL % self.name,
            neighbor_name=self.name,
            neighbor_lo_addr=self.ip,
            neighbor_mgmt_addr=self.ip,
            neighbor_hwsku=None,
            neighbor_type="ToRRouter"
        )

        _write_variable_from_j2_to_configdb(
            self.duthost,
            "bgp/templates/bgp_template.j2",
            save_dest_path=BGP_SAVE_DEST_TMPL % self.name,
            db_table_name="BGP_NEIGHBOR",
            peer_addr=self.ip,
            asn=self.asn,
            local_addr=self.peer_ip,
            peer_name=self.name
        )

        if self.is_quagga:
            allow_ebgp_multihop_cmd = (
                "vtysh "
                "-c 'configure terminal' "
                "-c 'router bgp %s' "
                "-c 'neighbor %s ebgp-multihop'"
            )
            allow_ebgp_multihop_cmd %= (self.peer_asn, self.ip)
            self.duthost.shell(allow_ebgp_multihop_cmd)

        # populate DUT arp table
        self.duthost.shell("ping -c 3 %s" % (self.ip))
def common_setup_teardown(ptfhost, duthost, localhost):
    mg_facts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts']
    dut_lo_addr = mg_facts['minigraph_lo_interfaces'][0]['addr']
    dut_mgmt_ip = mg_facts['minigraph_mgmt_interface']['addr']
    asn = mg_facts['minigraph_bgp_asn']
    peer_addr = ptfhost.mgmt_ip
    # TODO: Add a common method to load BGPMON config for test_bgpmon and test_traffic_shift
    logger.info("Configuring bgp monitor session on DUT")
    bgpmon_args = {
        'db_table_name': 'BGP_MONITORS',
        'peer_addr': peer_addr,
        'asn': asn,
        'local_addr': dut_lo_addr,
        'peer_name': BGP_MONITOR_NAME
    }
    bgpmon_template = Template(open(BGPMON_TEMPLATE_FILE).read())
    duthost.copy(content=bgpmon_template.render(**bgpmon_args),
                 dest=BGPMON_CONFIG_FILE)

    # Add a static route via mgmt interface on ptf
    ptfhost.shell('ip route add {}/32 via {} dev mgmt'.format(
        dut_lo_addr, dut_mgmt_ip))
    logger.info("Starting bgp monitor session on PTF")
    ptfhost.file(path=DUMP_FILE, state="absent")
    ptfhost.copy(src=CUSTOM_DUMP_SCRIPT, dest=CUSTOM_DUMP_SCRIPT_DEST)
    ptfhost.exabgp(name=BGP_MONITOR_NAME,
                   state="started",
                   local_ip=peer_addr,
                   router_id=peer_addr,
                   peer_ip=dut_lo_addr,
                   local_asn=asn,
                   peer_asn=asn,
                   port=BGP_MONITOR_PORT,
                   dump_script=CUSTOM_DUMP_SCRIPT_DEST)
    pytest_assert(
        wait_tcp_connection(localhost, ptfhost.mgmt_ip, BGP_MONITOR_PORT),
        "Failed to start bgp monitor session on PTF")
    yield
    # Cleanup bgp monitor
    duthost.shell("redis-cli -n 4 -c DEL 'BGP_MONITORS|{}'".format(peer_addr))
    ptfhost.exabgp(name=BGP_MONITOR_NAME, state="absent")
    ptfhost.file(path=CUSTOM_DUMP_SCRIPT_DEST, state="absent")
    ptfhost.file(path=DUMP_FILE, state="absent")
    ptfhost.shell('ip route flush {}/32'.format(dut_lo_addr))
Exemple #6
0
def common_setup_teardown(duthost, ptfhost, localhost):

    logging.info("########### Setup for bgp speaker testing ###########")

    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']

    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'],
                      mg_facts['minigraph_vlan_interfaces'][0]['prefixlen']),
        [IPAddress(mg_facts['minigraph_vlan_interfaces'][0]['addr'])])
    logging.info("Generated vlan_ips: %s" % str(vlan_ips))

    speaker_ips = generate_ips(
        2, mg_facts['minigraph_bgp_peers_with_range'][0]['ip_range'][0], [])
    speaker_ips.append(vlan_ips[0])
    logging.info("speaker_ips: %s" % str(speaker_ips))

    port_num = [7000, 8000, 9000]

    lo_addr = mg_facts['minigraph_lo_interfaces'][0]['addr']
    lo_addr_prefixlen = int(
        mg_facts['minigraph_lo_interfaces'][0]['prefixlen'])

    vlan_addr = mg_facts['minigraph_vlan_interfaces'][0]['addr']

    vlan_ports = []
    for i in range(0, 3):
        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]))
    ptfhost.shell("ifconfig eth%d:1 %s" % (vlan_ports[0], speaker_ips[1]))

    ptfhost.shell("ifconfig eth%d %s" % (vlan_ports[1], vlan_ips[1]))
    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("clear ARP cache on DUT")
    duthost.command("sonic-clear arp")
    for ip in vlan_ips:
        duthost.command("ip route flush %s/32" % ip.ip)
        # 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
        # Also because of issue https://github.com/Azure/sonic-buildimage/issues/5185 ping is done before route addition.
        duthost.shell("ping %s -c 3" % ip.ip)
        time.sleep(2)
        duthost.command(
            "ip route add %s/32 dev %s" %
            (ip.ip, mg_facts['minigraph_vlan_interfaces'][0]['attachto']))

    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)
        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 range(0, 3):
        http_ready = wait_tcp_connection(localhost, ptfip, port_num[i])
        if not http_ready:
            break

    logging.info("########### Done setup for bgp speaker testing ###########")

    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 ###########")

    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)

    logging.info(
        "########### Done teardown for bgp speaker testing ###########")
Exemple #7
0
def fib_t0(ptfhost, testbed, localhost, topology=None):
    logger.info("use fib_t0 to setup routes for topo {}".format(testbed['topo']['name']))

    podset_number = 200
    tor_number = 16
    tor_subnet_number = 2
    max_tor_subnet_number = 16
    tor_subnet_size = 128

    # TODO: spine_asn, leaf_asn_start and tor_asn_start should come from the topology file
    spine_asn = 65534
    if topology == 't0-116':
        leaf_asn_start = 4200064600
        tor_asn_start = 4200065500
    else:
        leaf_asn_start = 64600
        tor_asn_start = 65500

    topo = testbed['topo']['properties']
    ptf_hostname = testbed['ptf']
    ptfip = ptfhost.host.options['inventory_manager'].get_host(ptf_hostname).vars['ansible_host']

    local_ip = ipaddress.IPAddress("10.10.246.254")
    local_ipv6 = ipaddress.IPAddress("fc0a::ff")
    for k, v in testbed['topo']['properties']['configuration'].items():
        vm_offset = testbed['topo']['properties']['topology']['VMs'][k]['vm_offset']
        peer_ip = ipaddress.IPNetwork(v['bp_interface']['ipv4'])
        peer_ipv6 = ipaddress.IPNetwork(v['bp_interface']['ipv6'])
        asn = int(v['bgp']['asn'])
        port = 5000 + vm_offset
        port6 = 6000 + vm_offset

        ptfhost.exabgp(name=k,
                       state="started", \
                       router_id = str(local_ip), \
                       local_ip  = str(local_ip), \
                       peer_ip   = str(peer_ip.ip), \
                       local_asn = asn, \
                       peer_asn  = asn, \
                       port = port)

        ptfhost.exabgp(name="%s-v6" % k,
                       state="started", \
                       router_id = str(local_ip), \
                       local_ip  = str(local_ipv6), \
                       peer_ip   = str(peer_ipv6.ip), \
                       local_asn = asn, \
                       peer_asn  = asn, \
                       port = port6)
    # check if bgp http_api is ready
    for k, v in testbed['topo']['properties']['configuration'].items():
        vm_offset = testbed['topo']['properties']['topology']['VMs'][k]['vm_offset']

        port = 5000 + vm_offset
        assert wait_tcp_connection(localhost, ptfip, port)

        port6 = 6000 + vm_offset
        assert wait_tcp_connection(localhost, ptfip, port6)

    for k, v in testbed['topo']['properties']['configuration'].items():
        vm_offset = testbed['topo']['properties']['topology']['VMs'][k]['vm_offset']
        port = 5000 + vm_offset
        port6 = 6000 + vm_offset

        routes_v4 = generate_routes("v4", podset_number, tor_number, tor_subnet_number,
                                    spine_asn, leaf_asn_start, tor_asn_start,
                                    local_ip, local_ipv6)
        routes_v6 = generate_routes("v6", podset_number, tor_number, tor_subnet_number,
                                    spine_asn, leaf_asn_start, tor_asn_start,
                                    local_ip, local_ipv6)

        announce_routes(ptfip, port, routes_v4)
        announce_routes(ptfip, port6, routes_v6)
Exemple #8
0
def fib_t1_lag(ptfhost, testbed, localhost):
    logger.info("use fib_t1_lag to setup routes for topo {}".format(testbed['topo']['name']))

    podset_number = 200
    tor_number = 16
    tor_subnet_number = 2
    max_tor_subnet_number = 16
    tor_subnet_size = 128

    leaf_asn_start  = 64600
    tor_asn_start   = 65500

    topo = testbed['topo']['properties']
    ptf_hostname = testbed['ptf']
    ptfip = ptfhost.host.options['inventory_manager'].get_host(ptf_hostname).vars['ansible_host']

    local_ip = ipaddress.IPAddress("10.10.246.254")
    local_ipv6 = ipaddress.IPAddress("fc0a::ff")

    for k, v in testbed['topo']['properties']['configuration'].items():
        vm_offset = testbed['topo']['properties']['topology']['VMs'][k]['vm_offset']
        peer_ip = ipaddress.IPNetwork(v['bp_interface']['ipv4'])
        peer_ipv6 = ipaddress.IPNetwork(v['bp_interface']['ipv6'])
        asn = int(v['bgp']['asn'])
        port = 5000 + vm_offset
        port6 = 6000 + vm_offset

        ptfhost.exabgp(name=k,
                       state="started", \
                       router_id = str(local_ip), \
                       local_ip  = str(local_ip), \
                       peer_ip   = str(peer_ip.ip), \
                       local_asn = asn, \
                       peer_asn  = asn, \
                       port = port)

        ptfhost.exabgp(name="%s-v6" % k,
                       state="started", \
                       router_id = str(local_ip), \
                       local_ip  = str(local_ipv6), \
                       peer_ip   = str(peer_ipv6.ip), \
                       local_asn = asn, \
                       peer_asn  = asn, \
                       port = port6)
    # Check if bgp http_api port is ready
    for k, v in testbed['topo']['properties']['configuration'].items():
        vm_offset = testbed['topo']['properties']['topology']['VMs'][k]['vm_offset']

        port = 5000 + vm_offset
        assert wait_tcp_connection(localhost, ptfip, port)

        port6 = 6000 + vm_offset
        assert wait_tcp_connection(localhost, ptfip, port6)

    for k, v in testbed['topo']['properties']['configuration'].items():

        vm_offset = testbed['topo']['properties']['topology']['VMs'][k]['vm_offset']
        port = 5000 + vm_offset
        port6 = 6000 + vm_offset

        router_type = None
        if 'spine' in v['properties']:
            router_type = 'spine'
        elif 'tor' in v['properties']:
            router_type = 'tor'
        if router_type:
            routes_v4 = generate_routes("v4", podset_number, tor_number, tor_subnet_number,
                                        None, leaf_asn_start, tor_asn_start,
                                        local_ip, local_ipv6, router_type=router_type)
            routes_v6 = generate_routes("v6", podset_number, tor_number, tor_subnet_number,
                                        None, leaf_asn_start, tor_asn_start,
                                        local_ip, local_ipv6, router_type=router_type)
            announce_routes(ptfip, port, routes_v4)
            announce_routes(ptfip, port6, routes_v6)

        if 'vips' in v:
            routes_vips = []
            for prefix in v["vips"]["ipv4"]["prefixes"]:
                routes_vips.append((prefix, local_ip, v["vips"]["ipv4"]["asn"]))
            announce_routes(ptfip, port, routes_vips)
Exemple #9
0
def test_bgpmon(duthost, localhost, common_setup_teardown, ptfadapter,
                ptfhost):
    """
    Add a bgp monitor on ptf and verify that DUT is attempting to establish connection to it
    """
    def bgpmon_peer_connected(duthost, bgpmon_peer):
        try:
            bgp_summary = json.loads(
                duthost.shell('vtysh -c "show bgp summary json"')['stdout'])
            return bgp_summary['ipv4Unicast']['peers'][bgpmon_peer][
                "state"] == "Established"
        except Exception as e:
            logger.info('Unable to get bgp status')
            return False

    local_addr, peer_addr, peer_ports, asn = common_setup_teardown
    exp_packet = build_syn_pkt(local_addr, peer_addr)
    # Flush dataplane
    ptfadapter.dataplane.flush()
    # Load bgp monitor config
    logger.info(
        "Configured bgpmon and verifying packet on {}".format(peer_ports))
    duthost.command("sonic-cfggen -j {} -w".format(BGPMON_CONFIG_FILE))
    # Verify syn packet on ptf
    (rcvd_port_index,
     rcvd_pkt) = testutils.verify_packet_any_port(test=ptfadapter,
                                                  pkt=exp_packet,
                                                  ports=peer_ports,
                                                  timeout=BGP_CONNECT_TIMEOUT)
    #To establish the connection we set the PTF port that receive syn packet following properties
    # ip as BGMPMON IP , mac as the neighbor mac(mac for default nexthop that was used for sending syn packet) ,
    # add the neighbor entry and the default route for dut loopback
    ptf_interface = "eth" + str(peer_ports[rcvd_port_index])
    res = ptfhost.shell('cat /sys/class/net/{}/address'.format(ptf_interface))
    original_mac = res['stdout']
    ptfhost.shell("ifconfig %s hw ether %s" %
                  (ptf_interface, Ether(rcvd_pkt).dst))
    ptfhost.shell("ip add add %s dev %s" % (peer_addr + "/24", ptf_interface))
    ptfhost.exabgp(name=BGP_MONITOR_NAME,
                   state="started",
                   local_ip=peer_addr,
                   router_id=peer_addr,
                   peer_ip=local_addr,
                   local_asn=asn,
                   peer_asn=asn,
                   port=BGP_MONITOR_PORT,
                   passive=True)
    ptfhost.shell("ip neigh add %s lladdr %s dev %s" %
                  (local_addr, duthost.facts["router_mac"], ptf_interface))
    ptfhost.shell("ip route add %s dev %s" %
                  (local_addr + "/32", ptf_interface))
    try:
        pytest_assert(
            wait_tcp_connection(localhost, ptfhost.mgmt_ip, BGP_MONITOR_PORT),
            "Failed to start bgp monitor session on PTF")
        pytest_assert(
            wait_until(30, 5, bgpmon_peer_connected, duthost, peer_addr),
            "BGPMon Peer connection not established")
    finally:
        ptfhost.exabgp(name=BGP_MONITOR_NAME, state="absent")
        ptfhost.shell("ip route del %s dev %s" %
                      (local_addr + "/32", ptf_interface))
        ptfhost.shell("ip neigh del %s lladdr %s dev %s" %
                      (local_addr, duthost.facts["router_mac"], ptf_interface))
        ptfhost.shell("ip add del %s dev %s" %
                      (peer_addr + "/24", ptf_interface))
        ptfhost.shell("ifconfig %s hw ether %s" %
                      (ptf_interface, original_mac))
Exemple #10
0
def fib_t0(ptfhost, tbinfo, localhost, topology=None):
    logger.info("use fib_t0 to setup routes for topo {}".format(tbinfo['topo']['name']))

    common_config_topo = tbinfo['topo']['properties']['configuration_properties']['common']
    podset_number = common_config_topo.get("podset_number", 200)
    tor_number = common_config_topo.get("tor_number", 16)
    tor_subnet_number = common_config_topo.get("tor_subnet_number", 2)
    max_tor_subnet_number = common_config_topo.get("max_tor_subnet_number", 16)
    tor_subnet_size = common_config_topo.get("tor_subnet_size", 128)
    nhipv4 = common_config_topo.get("nhipv4", "10.10.246.254")
    nhipv6 = common_config_topo.get("nhipv6", "fc0a::ff")
    spine_asn = common_config_topo.get("spine_asn", 65534)
    leaf_asn_start = common_config_topo.get("leaf_asn_start", 64600)
    tor_asn_start = common_config_topo.get("tor_asn_start", 65500)

    ptf_hostname = tbinfo['ptf']
    ptfip = ptfhost.host.options['inventory_manager'].get_host(ptf_hostname).vars['ansible_host']

    local_ip = ipaddress.IPAddress(nhipv4)
    local_ipv6 = ipaddress.IPAddress(nhipv6)
    for k, v in tbinfo['topo']['properties']['configuration'].items():
        vm_offset = tbinfo['topo']['properties']['topology']['VMs'][k]['vm_offset']
        peer_ip = ipaddress.IPNetwork(v['bp_interface']['ipv4'])
        peer_ipv6 = ipaddress.IPNetwork(v['bp_interface']['ipv6'])
        asn = int(v['bgp']['asn'])
        port = 5000 + vm_offset
        port6 = 6000 + vm_offset

        ptfhost.exabgp(name=k,
                       state="started", \
                       router_id = str(local_ip), \
                       local_ip  = str(local_ip), \
                       peer_ip   = str(peer_ip.ip), \
                       local_asn = asn, \
                       peer_asn  = asn, \
                       port = port)

        ptfhost.exabgp(name="%s-v6" % k,
                       state="started", \
                       router_id = str(local_ip), \
                       local_ip  = str(local_ipv6), \
                       peer_ip   = str(peer_ipv6.ip), \
                       local_asn = asn, \
                       peer_asn  = asn, \
                       port = port6)
    # check if bgp http_api is ready
    for k, v in tbinfo['topo']['properties']['configuration'].items():
        vm_offset = tbinfo['topo']['properties']['topology']['VMs'][k]['vm_offset']

        port = 5000 + vm_offset
        assert wait_tcp_connection(localhost, ptfip, port)

        port6 = 6000 + vm_offset
        assert wait_tcp_connection(localhost, ptfip, port6)

    for k, v in tbinfo['topo']['properties']['configuration'].items():
        vm_offset = tbinfo['topo']['properties']['topology']['VMs'][k]['vm_offset']
        port = 5000 + vm_offset
        port6 = 6000 + vm_offset

        routes_v4 = generate_routes("v4", podset_number, tor_number, tor_subnet_number,
                                    spine_asn, leaf_asn_start, tor_asn_start,
                                    local_ip, local_ipv6, tor_subnet_size, max_tor_subnet_number)
        routes_v6 = generate_routes("v6", podset_number, tor_number, tor_subnet_number,
                                    spine_asn, leaf_asn_start, tor_asn_start,
                                    local_ip, local_ipv6, tor_subnet_size, max_tor_subnet_number)

        announce_routes(ptfip, port, routes_v4)
        announce_routes(ptfip, port6, routes_v6)
Exemple #11
0
def common_setup_teardown(duthost, ptfhost, localhost):

    logging.info("########### Setup for bgp speaker testing ###########")

    ptfip = ptfhost.host.options['inventory_manager'].get_host(
        ptfhost.hostname).vars['ansible_host']
    logging.info("ptfip=%s" % ptfip)

    ptfhost.script("./scripts/remove_ip.sh")

    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']]\""
    )
    bgp_speaker_asn = res['stdout']

    vlan_ips = generate_ips(
        3, "%s/%s" % (mg_facts['minigraph_vlan_interfaces'][0]['addr'],
                      mg_facts['minigraph_vlan_interfaces'][0]['prefixlen']),
        [IPAddress(mg_facts['minigraph_vlan_interfaces'][0]['addr'])])
    logging.info("Generated vlan_ips: %s" % str(vlan_ips))

    speaker_ips = generate_ips(
        2, mg_facts['minigraph_bgp_peers_with_range'][0]['ip_range'][0], [])
    speaker_ips.append(vlan_ips[0])
    logging.info("speaker_ips: %s" % str(speaker_ips))

    for ip in vlan_ips:
        duthost.command("ip route flush %s/32" % ip.ip)
        duthost.command(
            "ip route add %s/32 dev %s" %
            (ip.ip, mg_facts['minigraph_vlan_interfaces'][0]['attachto']))

    port_num = [7000, 8000, 9000]

    lo_addr = mg_facts['minigraph_lo_interfaces'][0]['addr']
    lo_addr_prefixlen = int(
        mg_facts['minigraph_lo_interfaces'][0]['prefixlen'])

    vlan_addr = mg_facts['minigraph_vlan_interfaces'][0]['addr']

    vlan_ports = []
    for i in range(0, 3):
        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")
    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]))
    ptfhost.shell("ifconfig eth%d:1 %s" % (vlan_ports[0], speaker_ips[1]))

    ptfhost.shell("ifconfig eth%d %s" % (vlan_ports[1], vlan_ips[1]))
    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):
        local_ip = str(speaker_ips[i].ip)
        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 range(0, 3):
        http_ready = wait_tcp_connection(localhost, ptfip, port_num[i])
        if not http_ready:
            break

    logging.info("########### Done setup for bgp speaker testing ###########")

    yield ptfip, mg_facts, interface_facts, vlan_ips, 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")

    for ip in vlan_ips:
        duthost.command("ip route flush %s/32" % ip.ip,
                        module_ignore_errors=True)

    ptfhost.script("./scripts/remove_ip.sh")

    logging.info(
        "########### Done teardown for bgp speaker testing ###########")