Beispiel #1
0
def test_fdb(ansible_adhoc, ptfadapter, duthosts, rand_one_dut_hostname,
             ptfhost, pkt_type,
             toggle_all_simulator_ports_to_rand_selected_tor_m,
             record_mux_status, get_dummay_mac_count):

    # Perform FDB clean up before each test and at the end of the final test
    fdb_cleanup(duthosts, rand_one_dut_hostname)
    if pkt_type == "cleanup":
        return
    """
    1. verify fdb forwarding.
    2. verify show mac command on DUT for learned mac.
    """
    duthost = duthosts[rand_one_dut_hostname]
    conf_facts = duthost.config_facts(host=duthost.hostname,
                                      source="persistent")['ansible_facts']

    # reinitialize data plane due to above changes on PTF interfaces
    ptfadapter.reinit()

    router_mac = duthost.facts['router_mac']

    port_index_to_name = {
        v: k
        for k, v in conf_facts['port_index_map'].items()
    }

    configured_dummay_mac_count = get_dummay_mac_count
    # Only take interfaces that are in ptf topology
    ptf_ports_available_in_topo = ptfhost.host.options[
        'variable_manager'].extra_vars.get("ifaces_map")
    available_ports_idx = []
    for idx, name in ptf_ports_available_in_topo.items():
        if idx in port_index_to_name and conf_facts['PORT'][
                port_index_to_name[idx]].get('admin_status', 'down') == 'up':
            available_ports_idx.append(idx)

    vlan_table = {}
    interface_table = defaultdict(set)
    config_portchannels = conf_facts.get('PORTCHANNEL', {})

    for name, vlan in conf_facts['VLAN'].items():
        vlan_id = int(vlan['vlanid'])
        vlan_table[vlan_id] = []

        for ifname in conf_facts['VLAN_MEMBER'][name].keys():
            if 'tagging_mode' not in conf_facts['VLAN_MEMBER'][name][ifname]:
                continue
            tagging_mode = conf_facts['VLAN_MEMBER'][name][ifname][
                'tagging_mode']
            port_index = []
            if ifname in config_portchannels:
                for member in config_portchannels[ifname]['members']:
                    if conf_facts['port_index_map'][
                            member] in available_ports_idx:
                        port_index.append(conf_facts['port_index_map'][member])
                if port_index:
                    interface_table[ifname].add(vlan_id)
            elif conf_facts['port_index_map'][ifname] in available_ports_idx:
                port_index.append(conf_facts['port_index_map'][ifname])
                interface_table[ifname].add(vlan_id)
            if port_index:
                vlan_table[vlan_id].append({
                    'port_index': port_index,
                    'tagging_mode': tagging_mode
                })

    vlan_member_count = sum([len(members) for members in vlan_table.values()])

    fdb = setup_fdb(ptfadapter, vlan_table, router_mac, pkt_type,
                    configured_dummay_mac_count)
    for vlan in vlan_table:
        for src, dst in itertools.combinations(vlan_table[vlan], 2):
            if 'port_index' not in src or 'tagging_mode' not in src:
                continue
            if 'port_index' not in dst or 'tagging_mode' not in dst:
                continue
            src_vlan = vlan if src['tagging_mode'] == 'tagged' else 0
            dst_vlan = vlan if dst['tagging_mode'] == 'tagged' else 0
            src_ports = src['port_index']
            dst_ports = dst['port_index']
            for src_mac, dst_mac in itertools.product(fdb[src_ports[0]],
                                                      fdb[dst_ports[0]]):
                send_recv_eth(duthost, ptfadapter, src_ports, src_mac,
                              dst_ports, dst_mac, src_vlan, dst_vlan)

    # Should we have fdb_facts ansible module for this test?
    fdb_fact = duthost.fdb_facts()['ansible_facts']
    logger.info('fdb facts on DUT:\n{}'.format(pprint.pformat(fdb_fact)))

    dummy_mac_count = 0
    total_mac_count = 0
    for k, v in fdb_fact.items():
        assert v['port'] in interface_table
        assert v['vlan'] in interface_table[ifname]
        assert validate_mac(k) == True
        assert v['type'] in ['Dynamic', 'Static']
        if DUMMY_MAC_PREFIX in k.lower():
            dummy_mac_count += 1
        if "dynamic" in k.lower():
            total_mac_count += 1

    assert vlan_member_count > 0

    # Verify that the number of dummy MAC entries is expected
    assert dummy_mac_count == configured_dummay_mac_count * vlan_member_count
Beispiel #2
0
def test_fdb_mac_move(ptfadapter, duthosts, rand_one_dut_hostname, ptfhost,
                      get_function_conpleteness_level):
    # Perform FDB clean up before each test
    fdb_cleanup(duthosts, rand_one_dut_hostname)

    normalized_level = get_function_conpleteness_level
    if normalized_level is None:
        normalized_level = "basic"
    loop_times = LOOP_TIMES_LEVEL_MAP[normalized_level]

    duthost = duthosts[rand_one_dut_hostname]
    conf_facts = duthost.config_facts(host=duthost.hostname,
                                      source="persistent")['ansible_facts']

    # reinitialize data plane due to above changes on PTF interfaces
    ptfadapter.reinit()

    router_mac = duthost.facts['router_mac']

    port_index_to_name = {
        v: k
        for k, v in conf_facts['port_index_map'].items()
    }

    # Only take interfaces that are in ptf topology
    ptf_ports_available_in_topo = ptfhost.host.options[
        'variable_manager'].extra_vars.get("ifaces_map")
    available_ports_idx = []
    for idx, name in ptf_ports_available_in_topo.items():
        if idx in port_index_to_name and conf_facts['PORT'][
                port_index_to_name[idx]].get('admin_status', 'down') == 'up':
            available_ports_idx.append(idx)

    vlan_table = {}
    interface_table = defaultdict(set)
    config_portchannels = conf_facts.get('PORTCHANNEL', {})

    # if DUT has more than one VLANs, use the first vlan
    name = conf_facts['VLAN'].keys()[0]
    vlan = conf_facts['VLAN'][name]
    vlan_id = int(vlan['vlanid'])
    vlan_table[vlan_id] = []

    for ifname in conf_facts['VLAN_MEMBER'][name].keys():
        if 'tagging_mode' not in conf_facts['VLAN_MEMBER'][name][ifname]:
            continue
        tagging_mode = conf_facts['VLAN_MEMBER'][name][ifname]['tagging_mode']
        port_index = []
        if ifname in config_portchannels:
            for member in config_portchannels[ifname]['members']:
                if conf_facts['port_index_map'][member] in available_ports_idx:
                    port_index.append(conf_facts['port_index_map'][member])
            if port_index:
                interface_table[ifname].add(vlan_id)
        elif conf_facts['port_index_map'][ifname] in available_ports_idx:
            port_index.append(conf_facts['port_index_map'][ifname])
            interface_table[ifname].add(vlan_id)
        if port_index:
            vlan_table[vlan_id].append({
                'port_index': port_index,
                'tagging_mode': tagging_mode
            })

    vlan = vlan_table.keys()[0]
    vlan_member_count = len(vlan_table[vlan])
    total_fdb_entries = min(
        TOTAL_FDB_ENTRIES,
        (get_crm_resources(duthost, "fdb_entry", "available") -
         get_crm_resources(duthost, "fdb_entry", "used")))
    dummay_mac_count = int(math.floor(total_fdb_entries / vlan_member_count))

    fdb = get_fdb_dict(ptfadapter, vlan_table, dummay_mac_count)
    port_list = fdb.keys()
    dummy_mac_list = fdb.values()

    for loop_time in range(0, loop_times):
        port_index_start = (0 + loop_time) % len(port_list)

        for (port, dummy_mac_set) in zip(range(len(port_list)),
                                         dummy_mac_list):
            port_index = (port_index_start + port) % len(port_list)
            for dummy_mac in dummy_mac_set:
                send_arp_request(ptfadapter, port_index, dummy_mac, router_mac,
                                 vlan_id)

        time.sleep(FDB_POPULATE_SLEEP_TIMEOUT)
        pytest_assert(
            wait_until(
                20, 1, 0, lambda: get_fdb_dynamic_mac_count(duthost) >
                vlan_member_count), "FDB Table Add failed")
        # Flush dataplane
        ptfadapter.dataplane.flush()
        fdb_cleanup(duthosts, rand_one_dut_hostname)
        # Wait for 10 seconds before starting next loop
        time.sleep(10)