Example #1
0
def add_ipaddr(ptfadapter,
               ptfhost,
               nexthop_addrs,
               prefix_len,
               nexthop_interfaces,
               ipv6=False):
    if ipv6:
        for idx in range(len(nexthop_addrs)):
            ptfhost.shell("ip -6 addr add {}/{} dev eth{}".format(
                nexthop_addrs[idx], prefix_len, nexthop_interfaces[idx]),
                          module_ignore_errors=True)
    else:
        vlan_host_map = defaultdict(dict)
        for idx in range(len(nexthop_addrs)):
            mac = ptfadapter.dataplane.get_mac(
                0, int(get_intf_by_sub_intf(nexthop_interfaces[idx]))).replace(
                    ":", "")
            vlan_host_map[nexthop_interfaces[idx]][nexthop_addrs[idx]] = mac

        arp_responder_conf = {}
        for port in vlan_host_map:
            arp_responder_conf['eth{}'.format(port)] = vlan_host_map[port]

        with open("/tmp/from_t1.json", "w") as ar_config:
            json.dump(arp_responder_conf, ar_config)
        ptfhost.copy(src="/tmp/from_t1.json", dest="/tmp/from_t1.json")
        ptfhost.host.options["variable_manager"].extra_vars.update(
            {"arp_responder_args": "-e"})
        ptfhost.template(src="templates/arp_responder.conf.j2",
                         dest="/etc/supervisor/conf.d/arp_responder.conf")

        ptfhost.shell('supervisorctl reread && supervisorctl update')
        ptfhost.shell('supervisorctl restart arp_responder')
Example #2
0
 def _constructPacket(self):
     """
     Build list of packets to be sent and expected
     """
     for idx, intf in enumerate(self.ptf_ports):
         udp_sport = random.randint(0, 65535)
         udp_dport = random.randint(0, 65535)
         src_port = self.ptf_ports[intf][0]
         src_ip = self.ptf_ports[intf][2]
         vlan_id = self.ptf_ports[intf][3]
         pkt = testutils.simple_udp_packet(eth_dst=self.dut_mac,
                                           eth_src=self.ptfadapter.dataplane.get_mac(0, src_port),
                                           ip_dst=self.dst_ip,
                                           ip_src=src_ip,
                                           ip_tos=self.dscp << 2,
                                           udp_sport=udp_sport,
                                           udp_dport=udp_dport,
                                           ip_ttl=64
                                           )
         self.pkts.append(pkt)
         tmp_pkt = testutils.simple_udp_packet(eth_dst=self.arp_entry[self.dst_ip],
                                               eth_src=self.dut_mac,
                                               ip_dst=self.dst_ip,
                                               ip_src=src_ip,
                                               ip_tos=self.dscp << 2,
                                               udp_sport=udp_sport,
                                               udp_dport=udp_dport,
                                               ip_ttl=63
                                               )
         tmp_pkt = mask.Mask(tmp_pkt)
         tmp_pkt.set_do_not_care_scapy(packet.IP, "chksum")
         self.exp_pkts.append(tmp_pkt)
         # if inft is a sub interface, tuple be like ("Eth0.10", "Eth0")
         # if inft is a general interface, tuple be like ("Eth0", "Eth0")
         self.pkt_map[pkt] = (intf, get_intf_by_sub_intf(intf, vlan_id))
def get_t1_ptf_ports_for_backend_topo(mg_facts):
    """
    In backend topology, there isn't any port channel between T0 and T1,
    we use sub interface instead.
    Args:
        mg_facts (dict): mg_facts
    Returns:
        list: ptf t1 ports, e.g. ['eth10', 'eth11']
    """
    ptf_portmap = mg_facts['minigraph_ptf_indices']

    ports = set()
    for vlan_sub_interface in mg_facts['minigraph_vlan_sub_interfaces']:
        sub_intf_name = vlan_sub_interface['attachto']
        vlan_id = vlan_sub_interface['vlan']
        intf_name = get_intf_by_sub_intf(sub_intf_name, vlan_id)

        ptf_port_index = ptf_portmap[intf_name]
        ports.add("eth{}".format(ptf_port_index))

    return list(ports)
Example #4
0
def unknownMacSetup(duthosts, rand_one_dut_hostname, tbinfo):
    """
    Fixture to populate all the parameters needed for the test

    Args:
        duthosts(AnsibleHost) : multi dut instance
        rand_one_dut_hostname(string) : one of the dut instances from the multi dut
        tbinfo(TestbedInfo) : testbed info

    Yields:
        setup(dict): dict of vlan, ptf, portchannel intf mappings

    """
    duthost = duthosts[rand_one_dut_hostname]
    # The behavior on Mellanox for unknown MAC is flooding rather than DROP,
    # so we need to skip this test on Mellanox platform
    asic_type = duthost.facts["asic_type"]
    pytest_require(asic_type != "mellanox", "Skip on Mellanox platform")

    mg_facts = duthost.get_extended_minigraph_facts(tbinfo)
    is_backend_topology = mg_facts.get(constants.IS_BACKEND_TOPOLOGY_KEY, False)
    server_ips = []
    if 'dualtor' in tbinfo['topo']['name']:
        servers = mux_cable_server_ip(duthost)
        for ips in servers.values():
            server_ips.append(ips['server_ipv4'].split('/')[0])

    # populate vlan info
    vlan = dict()
    vlan['addr'] = mg_facts['minigraph_vlan_interfaces'][0]['addr']
    vlan['pfx'] = mg_facts['minigraph_vlan_interfaces'][0]['prefixlen']
    vlan['ips'] = duthost.get_ip_in_range(num=1, prefix="{}/{}".format(vlan['addr'], vlan['pfx']),
                                          exclude_ips=[vlan['addr']] + server_ips)['ansible_facts']['generated_ips']
    vlan['hostip'] = vlan['ips'][0].split('/')[0]
    vlan['ports'] = mg_facts["minigraph_vlans"].values()[0]["members"]
    # populate dst intf and ptf id
    ptf_portmap = mg_facts['minigraph_ptf_indices']
    dst_port = random.choice(vlan['ports'])
    if is_backend_topology:
        ptf_dst_port = str(ptf_portmap[dst_port]) + constants.VLAN_SUB_INTERFACE_SEPARATOR + \
                       mg_facts["minigraph_vlans"].values()[0]["vlanid"]
    else:
        ptf_dst_port = ptf_portmap[dst_port]
    ptf_vlan_ports = [ptf_portmap[ifname] for ifname in vlan['ports']]
    # populate portchannel intf, peer address and ptf ids
    pc = dict()
    intfs = list()
    ptf_ports = dict()
    sub_intfs = set()
    if is_backend_topology:
        for vlan_sub_interface in mg_facts['minigraph_vlan_sub_interfaces']:
            sub_intf_name = vlan_sub_interface['attachto']
            if sub_intf_name in intfs:
                continue
            vlan_id = vlan_sub_interface['vlan']
            intf_name = get_intf_by_sub_intf(sub_intf_name, vlan_id)
            sub_intfs.add(sub_intf_name)
            ptf_ports[sub_intf_name] = (ptf_portmap[intf_name], sub_intf_name,
                                           vlan_sub_interface['peer_addr'],
                                           vlan_id)
            intfs = list(sub_intfs)
    else:
        for key in mg_facts['minigraph_portchannels']:
            value = mg_facts['minigraph_portchannels'][key]
            for item in value['members']:
                intfs.append(item)
                ptf_ports[item] = (ptf_portmap[item], item, None, None)
                pc.setdefault(key, []).append(item)

            for element in mg_facts['minigraph_portchannel_interfaces']:
                if key in element['attachto']:
                    for member in pc[key]:
                        tmp_list = list(ptf_ports[member])
                        tmp_list[2] = element['peer_addr']
                        ptf_ports[member] = tuple(tmp_list)
                    break

    setup = {'vlan': vlan,
             'dst_port': dst_port,
             'ptf_dst_port': ptf_dst_port,
             'ptf_vlan_ports': ptf_vlan_ports,
             'intfs': intfs,
             'ptf_ports': ptf_ports
             }
    yield setup