def run_test(ansible_adhoc, testbed, conn_graph_facts, leaf_fanouts, is_pfc=True, pause_time=65535): """ @Summary: Run test for Ethernet flow control (FC) or priority-based flow control (PFC) @param ansible_adhoc: Fixture provided by the pytest-ansible package. Source of the various device objects. It is mandatory argument for the class constructors. @param testbed: Testbed information @param conn_graph_facts: Testbed topology connectivity information @param leaf_fanouts: Leaf fanout switches @param is_pfc: If this test is for PFC? @param pause_time: Pause time quanta (0-65535) in the frame. 0 means unpause. """ setup_testbed(ansible_adhoc, testbed, leaf_fanouts) conn_facts = conn_graph_facts['device_conn'] dut_hostname = testbed['dut'] dut_ans = AnsibleHost(ansible_adhoc, dut_hostname) int_status = dut_ans.show_interface( command="status")['ansible_facts']['int_status'] """ We only test active physical interfaces """ active_phy_intfs = [intf for intf in int_status if \ intf.startswith('Ethernet') and \ int_status[intf]['admin_state'] == 'up' and \ int_status[intf]['oper_state'] == 'up'] """ Generate PFC or FC packets for active physical interfaces """ for intf in active_phy_intfs: peer_device = conn_facts[intf]['peerdevice'] peer_port = conn_facts[intf]['peerport'] peer_port_name = eos_to_linux_intf(peer_port) peerdev_ans = AnsibleHost(ansible_adhoc, peer_device) if is_pfc: for priority in range(PRIO_COUNT): cmd = "sudo python %s -i %s -p %d -t %d -n %d" % ( PFC_GEN_FILE_DEST, peer_port_name, 2** priority, pause_time, PKT_COUNT) peerdev_ans.command(cmd) else: cmd = "sudo python %s -i %s -g -t %d -n %d" % ( PFC_GEN_FILE_DEST, peer_port_name, pause_time, PKT_COUNT) peerdev_ans.command(cmd) """ SONiC takes some time to update counters in database """ time.sleep(5) """ Check results """ counter_facts = dut_ans.sonic_pfc_counters(method="get")['ansible_facts'] for intf in active_phy_intfs: if is_pfc: assert counter_facts[intf]['Rx'] == [str(PKT_COUNT)] * PRIO_COUNT else: assert counter_facts[intf]['Rx'] == ['0'] * PRIO_COUNT
def run_test(fanouthosts, duthost, conn_graph_facts, leaf_fanouts, is_pfc=True, pause_time=65535, check_continous_pfc=False): """ @Summary: Run test for Ethernet flow control (FC) or priority-based flow control (PFC) @param duthost: The object for interacting with DUT through ansible @param conn_graph_facts: Testbed topology connectivity information @param leaf_fanouts: Leaf fanout switches @param is_pfc: If this test is for PFC? @param pause_time: Pause time quanta (0-65535) in the frame. 0 means unpause. """ setup_testbed(fanouthosts, duthost, leaf_fanouts) conn_facts = conn_graph_facts['device_conn'][duthost.hostname] int_status = duthost.show_interface(command = "status")['ansible_facts']['int_status'] """ We only test active physical interfaces """ active_phy_intfs = [intf for intf in int_status if \ intf.startswith('Ethernet') and \ int_status[intf]['admin_state'] == 'up' and \ int_status[intf]['oper_state'] == 'up'] if not check_continous_pfc: """ Generate PFC or FC packets for active physical interfaces """ for intf in active_phy_intfs: peer_device = conn_facts[intf]['peerdevice'] peer_port = conn_facts[intf]['peerport'] peer_port_name = eos_to_linux_intf(peer_port) peerdev_ans = fanouthosts[peer_device] if is_pfc: for priority in range(PRIO_COUNT): cmd = "sudo python %s -i %s -p %d -t %d -n %d" % (PFC_GEN_FILE_DEST, peer_port_name, 2 ** priority, pause_time, PKT_COUNT) peerdev_ans.host.command(cmd) else: cmd = "sudo python %s -i %s -g -t %d -n %d" % (PFC_GEN_FILE_DEST, peer_port_name, pause_time, PKT_COUNT) peerdev_ans.host.command(cmd) """ SONiC takes some time to update counters in database """ time.sleep(5) """ Check results """ counter_facts = duthost.sonic_pfc_counters(method = "get")['ansible_facts'] for intf in active_phy_intfs: if is_pfc: assert counter_facts[intf]['Rx'] == [str(PKT_COUNT)] * PRIO_COUNT else: assert counter_facts[intf]['Rx'] == ['0'] * PRIO_COUNT else: for intf in active_phy_intfs: """only check priority 3 and 4: lossless priorities""" for priority in range(3, 5): """ Clear PFC counters """ duthost.sonic_pfc_counters(method = "clear") peer_device = conn_facts[intf]['peerdevice'] peer_port = conn_facts[intf]['peerport'] peer_port_name = eos_to_linux_intf(peer_port) peerdev_ans = fanouthosts[peer_device] cmd = "sudo python %s -i %s -p %d -t %d -n %d" % (PFC_GEN_FILE_DEST, peer_port_name, 2 ** priority, pause_time, PKT_COUNT) peerdev_ans.host.command(cmd) time.sleep(5) pfc_rx = duthost.sonic_pfc_counters(method = "get")['ansible_facts'] """check pfc Rx frame count on particular priority are increased""" assert pfc_rx[intf]['Rx'][priority] == str(PKT_COUNT) """check LHS priorities are 0 count""" for i in range(priority): assert pfc_rx[intf]['Rx'][i] == '0' """check RHS priorities are 0 count""" for i in range(priority+1, PRIO_COUNT): assert pfc_rx[intf]['Rx'][i] == '0'
def run_test_t0(fanouthosts, duthost, ptfhost, conn_graph_facts, leaf_fanouts, dscp, dscp_bg, queue_paused, send_pause, pfc_pause, pause_prio, pause_time=65535, max_test_intfs_count=128): """ @Summary: Run a series of tests on a T0 topology. For the T0 topology, we only test Vlan (server-faced) interfaces. @param conn_graph_facts: Testbed topology @param leaf_fanouts: Leaf fanout switches @param dscp: DSCP value of test data packets @param dscp_bg: DSCP value of background data packets @param queue_paused: if the queue is expected to be paused @param send_pause: send pause frames or not @param pfc_pause: send PFC pause frames or not @param pause_prio: priority of PFC franme @param pause_time: pause time quanta. It is 65535 (maximum pause time quanta) by default. @param max_test_intfs_count: maximum count of interfaces to test. By default, it is a very large value to cover all the interfaces. return: Return # of iterations and # of passed iterations for each tested interface. """ """ Clear DUT's PFC counters """ duthost.sonic_pfc_counters(method="clear") """ Disable DUT's PFC wd """ duthost.shell('sudo pfcwd stop') """ Generate a T0 testbed configuration """ dut_intfs, ptf_intfs, ptf_ip_addrs, ptf_mac_addrs = gen_testbed_t0(duthost) results = dict() for i in range(min(max_test_intfs_count, len(ptf_intfs))): src_index = i dst_index = (i + 1) % len(ptf_intfs) src_intf = ptf_intfs[src_index] dst_intf = ptf_intfs[dst_index] src_ip = ptf_ip_addrs[src_index] dst_ip = ptf_ip_addrs[dst_index] src_mac = ptf_mac_addrs[src_index] dst_mac = ptf_mac_addrs[dst_index] """ DUT interface to pause """ dut_intf_paused = dut_intfs[dst_index] """ Clear MAC table in DUT """ duthost.shell('sonic-clear fdb all') time.sleep(2) if send_pause: peer_device = conn_graph_facts['device_conn'][dut_intf_paused]['peerdevice'] peer_port = conn_graph_facts['device_conn'][dut_intf_paused]['peerport'] peer_port_name = eos_to_linux_intf(peer_port) peerdev_ans = fanouthosts[peer_device] if not pfc_pause: pause_prio = None start_pause(host_ans=peerdev_ans, pkt_gen_path=PFC_GEN_REMOTE_PATH, intf=peer_port_name, pkt_count=PFC_PKT_COUNT, pause_duration=pause_time, pause_priority=pause_prio) """ Wait for PFC pause frame generation """ time.sleep(1) """ Run PTF test """ intf_info = '--interface %d@%s --interface %d@%s' % (src_index, src_intf, dst_index, dst_intf) test_params = ("mac_src=\'%s\';" % src_mac + "mac_dst=\'%s\';" % dst_mac + "ip_src=\'%s\';" % src_ip + "ip_dst=\'%s\';" % dst_ip + "dscp=%d;" % dscp + "dscp_bg=%d;" % dscp_bg + "pkt_count=%d;" % PTF_PKT_COUNT + "pkt_intvl=%f;" % PTF_PKT_INTVL_SEC + "port_src=%d;" % src_index + "port_dst=%d;" % dst_index + "queue_paused=%s;" % queue_paused + "dut_has_mac=False") cmd = 'ptf --test-dir %s %s --test-params="%s"' % (os.path.dirname(PTF_FILE_REMOTE_PATH), intf_info, test_params) print cmd stdout = ansible_stdout_to_str(ptfhost.shell(cmd)['stdout']) words = stdout.split() """ Expected format: "Passes: a / b" where a is # of passed iterations and b is total # of iterations """ if len(words) != 4: print 'Unknown PTF test result format' results[dut_intf_paused] = [0, 0] else: results[dut_intf_paused] = [int(words[1]), int(words[3])] time.sleep(1) if send_pause: """ Stop PFC / FC storm """ stop_pause(peerdev_ans, PFC_GEN_FILE) time.sleep(1) return results