Esempio n. 1
0
def build_encapsulated_packet(rand_selected_interface, ptfadapter, rand_selected_dut, tunnel_traffic_monitor):
    """Build the encapsulated packet sent from T1 to ToR."""
    tor = rand_selected_dut
    _, server_ips = rand_selected_interface
    server_ipv4 = server_ips["server_ipv4"].split("/")[0]
    config_facts = tor.get_running_config_facts()
    try:
        peer_ipv4_address = [_["address_ipv4"] for _ in config_facts["PEER_SWITCH"].values()][0]
    except IndexError:
        raise ValueError("Failed to get peer ToR address from CONFIG_DB")

    tor_ipv4_address = [_ for _ in config_facts["LOOPBACK_INTERFACE"]["Loopback0"]
                        if is_ipv4_address(_.split("/")[0])][0]
    tor_ipv4_address = tor_ipv4_address.split("/")[0]

    inner_dscp = random.choice(range(0, 33))
    inner_ttl = random.choice(range(3, 65))
    inner_packet = testutils.simple_ip_packet(
        ip_src="1.1.1.1",
        ip_dst=server_ipv4,
        ip_dscp=inner_dscp,
        ip_ttl=inner_ttl
    )[IP]
    packet = testutils.simple_ipv4ip_packet(
        eth_dst=tor.facts["router_mac"],
        eth_src=ptfadapter.dataplane.get_mac(0, 0),
        ip_src=peer_ipv4_address,
        ip_dst=tor_ipv4_address,
        ip_dscp=inner_dscp,
        ip_ttl=255,
        inner_frame=inner_packet
    )
    logging.info("the encapsulated packet to send:\n%s", tunnel_traffic_monitor._dump_show_str(packet))
    return packet
Esempio n. 2
0
def add_default_route_to_dut(duts_running_config_facts, duthosts, tbinfo):
    """
    Add a default route to the device for storage backend testbed.
    This is to ensure the packet sent in test_sip_link_local and test_dip_link_local
    are routable on the device.
    """
    if "backend" in tbinfo["topo"]["name"]:
        logging.info("Add default route on the DUT.")
        try:
            for duthost in duthosts:
                cfg_facts = duts_running_config_facts[duthost.hostname]
                for asic_index, asic_cfg_facts in enumerate(cfg_facts):
                    asic = duthost.asic_instance(asic_index)
                    bgp_neighbors = asic_cfg_facts["BGP_NEIGHBOR"]
                    ipv4_cmd_parts = ["ip route add default"]
                    for neighbor in bgp_neighbors.keys():
                        if is_ipv4_address(neighbor):
                            ipv4_cmd_parts.append("nexthop via %s" % neighbor)
                    ipv4_cmd_parts.sort()
                    ipv4_cmd = " ".join(ipv4_cmd_parts)
                    asic.shell(ipv4_cmd)
            yield
        finally:
            logging.info("Remove default route on the DUT.")
            for duthost in duthosts:
                for asic in duthost.asics:
                    if asic.is_it_backend():
                        continue
                    asic.shell("ip route del default",
                               module_ignore_errors=True)
    else:
        yield
Esempio n. 3
0
 def _get_prefix_counters(duthost, bgp_neighbor, namespace):
     """Get Rib route counters for neighbor."""
     if is_ipv4_address(unicode(bgp_neighbor)):
         cmd = "vtysh -c 'show bgp ipv4 neighbor %s prefix-counts json'" % bgp_neighbor
     else:
         cmd = "vtysh -c 'show bgp ipv6 neighbor %s prefix-counts json'" % bgp_neighbor
     cmd = duthost.get_vtysh_cmd_for_namespace(cmd, namespace)
     cmd_result = json.loads(duthost.shell(cmd, verbose=False)["stdout"])
     return cmd_result
Esempio n. 4
0
 def _get_learned_bgp_routes_from_neighbor(duthost, bgp_neighbor):
     """Get all learned routes from the BGP neighbor."""
     routes = {}
     if is_ipv4_address(unicode(bgp_neighbor)):
         cmd = "vtysh -c 'show bgp ipv4 neighbor %s routes json'" % bgp_neighbor
     else:
         cmd = "vtysh -c 'show bgp ipv6 neighbor %s routes json'" % bgp_neighbor
     for namespace in duthost.get_frontend_asic_namespace_list():
         cmd = duthost.get_vtysh_cmd_for_namespace(cmd, namespace)
         routes.update(json.loads(duthost.shell(cmd, verbose=False)["stdout"])["routes"])
     return routes
Esempio n. 5
0
def testbed_params(duthosts, rand_one_dut_hostname, tbinfo):
    duthost = duthosts[rand_one_dut_hostname]
    skip_version(duthost, ["201811", "201911"])
    mg_facts = duthost.get_extended_minigraph_facts(tbinfo)

    vlan_intf_name = mg_facts["minigraph_vlans"].keys()[0]
    vlan_member_ports = mg_facts["minigraph_vlans"][vlan_intf_name]["members"]
    vlan_member_ports_to_ptf_ports = {
        _: mg_facts["minigraph_ptf_indices"][_]
        for _ in vlan_member_ports
    }
    vlan_intf = [
        _ for _ in mg_facts["minigraph_vlan_interfaces"]
        if _["attachto"] == vlan_intf_name and is_ipv4_address(_["addr"])
    ][0]
    return vlan_intf, vlan_member_ports_to_ptf_ports
Esempio n. 6
0
def build_non_encapsulated_ip_packet(rand_selected_interface, ptfadapter,
                                     rand_selected_dut,
                                     tunnel_traffic_monitor):
    """
    Build the regular (non encapsulated) packet to be sent from T1 to ToR.
    """
    tor = rand_selected_dut
    _, server_ips = rand_selected_interface
    server_ipv4 = server_ips["server_ipv4"].split("/")[0]
    config_facts = tor.get_running_config_facts()
    try:
        peer_ipv4_address = [
            dut_name["address_ipv4"]
            for dut_name in config_facts["PEER_SWITCH"].values()
        ][0]
    except IndexError:
        raise ValueError("Failed to get peer ToR address from CONFIG_DB")

    tor_ipv4_address = [
        addr for addr in config_facts["LOOPBACK_INTERFACE"]["Loopback0"]
        if is_ipv4_address(addr.split("/")[0])
    ][0]
    tor_ipv4_address = tor_ipv4_address.split("/")[0]

    dscp = random.choice(range(0, 33))
    ttl = random.choice(range(3, 65))
    ecn = random.choice(range(0, 3))

    packet = testutils.simple_ip_packet(eth_dst=tor.facts["router_mac"],
                                        eth_src=ptfadapter.dataplane.get_mac(
                                            0, 0),
                                        ip_src="1.1.1.1",
                                        ip_dst=server_ipv4,
                                        ip_dscp=dscp,
                                        ip_ecn=ecn,
                                        ip_ttl=ttl)
    logging.info("the regular IP packet to send:\n%s",
                 dump_scapy_packet_show_output(packet))

    return packet
Esempio n. 7
0
def add_default_route_to_dut(config_facts, duthosts, tbinfo):
    """
    Add a default route to the device for storage backend testbed.
    This is to ensure the IO packets could be successfully directed.
    """
    if "backend" in tbinfo["topo"]["name"]:
        logging.info("Add default route on the DUT.")
        try:
            for duthost in duthosts:
                cfg_facts = config_facts[duthost.hostname]
                for asic_index, asic_cfg_facts in enumerate(cfg_facts):
                    asic = duthost.asic_instance(asic_index)
                    bgp_neighbors = asic_cfg_facts["BGP_NEIGHBOR"]
                    ipv4_cmd_parts = ["ip route add default"]
                    ipv6_cmd_parts = ["ip -6 route add default"]
                    for neighbor in bgp_neighbors.keys():
                        if is_ipv4_address(neighbor):
                            ipv4_cmd_parts.append("nexthop via %s" % neighbor)
                        else:
                            ipv6_cmd_parts.append("nexthop via %s" % neighbor)
                    ipv4_cmd_parts.sort()
                    ipv6_cmd_parts.sort()
                    # limit to 4 nexthop entries
                    ipv4_cmd = " ".join(ipv4_cmd_parts[:5])
                    ipv6_cmd = " ".join(ipv6_cmd_parts[:5])
                    asic.shell(ipv4_cmd)
                    asic.shell(ipv6_cmd)
            yield
        finally:
            logging.info("Remove default route on the DUT.")
            for duthost in duthosts:
                for asic in duthost.asics:
                    if asic.is_it_backend():
                        continue
                    asic.shell("ip route del default", module_ignore_errors=True)
                    asic.shell("ip -6 route del default", module_ignore_errors=True)
    else:
        yield
Esempio n. 8
0
 def _find_ipv4_vlan(mg_facts):
     for vlan_intf in mg_facts["minigraph_vlan_interfaces"]:
         if is_ipv4_address(vlan_intf["addr"]):
             return vlan_intf