当前位置: 首页>>代码示例>>Python>>正文


Python TestLib.custom方法代码示例

本文整理汇总了Python中TestLib.TestLib.custom方法的典型用法代码示例。如果您正苦于以下问题:Python TestLib.custom方法的具体用法?Python TestLib.custom怎么用?Python TestLib.custom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestLib.TestLib的用法示例。


在下文中一共展示了TestLib.custom方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: do_task

# 需要导入模块: from TestLib import TestLib [as 别名]
# 或者: from TestLib.TestLib import custom [as 别名]
def do_task(ctl, hosts, ifaces, aliases):
    """
    This test deffines MAX_ROUTES number of routes on the switch with different
    32bit prefixes in the range 192.168.[10..].[1..254] and redirects them to a
    nexthop on machine2. The test than checks that:
     - All routes has the offloaded flag
     - Traffic destined to each of the route prefixes did end up on machine2, as
       the route specifies
    """
    m1, sw, m2 = hosts
    m1_if1, sw_if1, sw_if2, m2_if1 = ifaces

    m1_if1.reset(ip=test_ip(1, 1))
    sw_if1.reset(ip=test_ip(1, 2))

    sw_if2.reset(ip=test_ip(2, 2))
    m2_if1.reset(ip=test_ip(2, 3))

    for route_index in range(ROUTES_COUNT):
        route_major = get_route_major(route_index)
        route_minor = get_route_minor(route_index)
        sw_if1.add_nhs_route(ipv4(test_ip(route_major, route_minor, [])),
                             [ipv4(test_ip(2, 3, []))])

    sleep(30)
    tl = TestLib(ctl, aliases)

    # check that there are ROUTES_COUNT offloaded routes
    dc_routes, nh_routes = sw.get_routes()
    offloaded_routes_num = 0
    for nh_route in nh_routes:
        if "offload" in nh_route["nexthops"][0]["flags"]:
            offloaded_routes_num += 1

    if offloaded_routes_num < ROUTES_COUNT:
        tl.custom(sw, "route", "Only %d out of %d routes offloaded" %
                  (offloaded_routes_num, ROUTES_COUNT))

    # run traffic, and validate that each route will be hit
    sleep(2)
    before_stats = m2_if1.link_stats()["rx_packets"]

    total_sent = 0
    for major in get_all_route_majors():
        total_sent += traffic_route_major(tl, major, m1_if1, m2_if1, sw_if1)

    sleep(2)
    after_stats = m2_if1.link_stats()["rx_packets"]
    recieved = after_stats - before_stats

    # validate that all traffic went according to the routes
    thresh = total_sent * 0.95
    if recieved < thresh:
        tl.custom(sw, "route", "Recieved %d out of %d packets" %
                  (recieved, thresh))
开发者ID:jpirko,项目名称:lnst,代码行数:57,代码来源:l3-008-routes_stress.py

示例2: do_task

# 需要导入模块: from TestLib import TestLib [as 别名]
# 或者: from TestLib.TestLib import custom [as 别名]
def do_task(ctl, hosts, ifaces, aliases):
    m1, m2, sw = hosts
    m1_if1, m2_if1, sw_if1, sw_if2 = ifaces

    vrf_None = None
    tl = TestLib(ctl, aliases)

    # Test that offloaded routes do have "offload" flag.
    with dummy(sw, vrf_None, ip=["1.2.3.4/32"]) as d:
        with gre(sw, None, vrf_None,
                 tos="inherit",
                 local_ip="1.2.3.4",
                 remote_ip="1.2.3.5") as g, \
             encap_route(sw, vrf_None, 2, g, ip=ipv4), \
             encap_route(sw, vrf_None, 2, g, ip=ipv6):
            sleep(15)

            ulip = test_ip(2, 0, [24, 64])
            (r4,), _ = sw.get_routes("table 0 %s" % ipv4(ulip))
            if "offload" not in r4["flags"]:
                tl.custom(sw, "ipip", "IPv4 encap route not offloaded")

            (r6,), _ = sw.get_routes("table 0 %s" % ipv6(ulip))
            if "offload" not in r6["flags"]:
                tl.custom(sw, "ipip", "IPv6 encap route not offloaded")

            (dcr4,), _ = sw.get_routes("table local 1.2.3.4")
            if "offload" not in dcr4["flags"]:
                tl.custom(sw, "ipip", "IPv4 decap route not offloaded")

        sleep(5)
        (dcr4,), _ = sw.get_routes("table local 1.2.3.4")
        if "offload" in dcr4["flags"]:
            tl.custom(sw, "ipip", "IPv4 decap still flagged offloaded")
开发者ID:jpirko,项目名称:lnst,代码行数:36,代码来源:ipip-005-offload-flag.py

示例3: do_task

# 需要导入模块: from TestLib import TestLib [as 别名]
# 或者: from TestLib.TestLib import custom [as 别名]
def do_task(ctl, hosts, ifaces, aliases):
    m1, m2, sw = hosts
    m1_if1, m2_if1, sw_if1, sw_if2 = ifaces

    m1_if1.add_nhs_route(ipv4(test_ip(2, 0)), [ipv4(test_ip(1, 1, []))])
    m2_if1.add_nhs_route("1.2.3.4/32", [ipv4(test_ip(99, 1, []))])

    vrf_None = None
    tl = TestLib(ctl, aliases)

    # Test that non-IPIP traffic gets to slow path.
    with dummy(sw, vrf_None, ip=["1.2.3.4/32"]) as d, \
         gre(sw, None, vrf_None,
             tos="inherit",
             local_ip="1.2.3.4",
             remote_ip="1.2.3.5") as g, \
         encap_route(sw, vrf_None, 2, g, ip=ipv4):
        sleep(15)
        ping_test(tl, m2, sw, "1.2.3.4", m2_if1, g, count=20)

    # Configure the wrong interface on M2 to test that the traffic gets trapped
    # to CPU.
    with encap_route(m2, vrf_None, 1, "gre3"):

        add_forward_route(sw, vrf_None, "1.2.3.5")

        with dummy(sw, vrf_None, ip=["1.2.3.4/32"]) as d, \
             gre(sw, None, vrf_None,
                 local_ip="1.2.3.4",
                 remote_ip="1.2.3.5") as g:
            sleep(15)

            before_stats = sw_if2.link_stats()["rx_packets"]
            ping_test(tl, m2, sw, ipv4(test_ip(1, 33, [])), m2_if1, g,
                      count=20, fail_expected=True)
            after_stats = sw_if2.link_stats()["rx_packets"]
            delta = after_stats - before_stats
            if delta < 15:
                tl.custom(sw, "ipip",
                        "Too few packets (%d) observed in slow path" % delta)
开发者ID:jpirko,项目名称:lnst,代码行数:42,代码来源:ipip-004-gre-traps.py

示例4: do_task

# 需要导入模块: from TestLib import TestLib [as 别名]
# 或者: from TestLib.TestLib import custom [as 别名]

#.........这里部分代码省略.........
    # egress port, so change ports' speeds accordingly.
    sw_if1.set_speed(int(aliases["speed_hi"]))
    sw_if2.set_speed(int(aliases["speed_lo"]))

    sleep(30)

    sw.create_bridge(slaves=[sw_if1, sw_if2], options={"vlan_filtering": 1})
    sw_if1.add_br_vlan(10)
    sw_if2.add_br_vlan(10)

    tl = TestLib(ctl, aliases)

    # Hosts should be set to default values.
    m1.enable_service("lldpad")
    m1_if1.enable_lldp()
    tl.lldp_ets_default_set(m1_if1)
    tl.lldp_pfc_set(m1_if1, prio=[])

    m2.enable_service("lldpad")
    m2_if1.enable_lldp()
    tl.lldp_ets_default_set(m2_if1)
    tl.lldp_pfc_set(m2_if1, prio=[])

    # Get two different random priorities that will represent both
    # competing flows.
    p1 = randint(1, 7)
    p2 = 7 - p1

    # And two random weights for the ETS algorithm.
    bw1 = randint(0, 100)
    bw2 = 100 - bw1

    sw.enable_service("lldpad")
    # Configure the egress port using chosen values.
    sw_if2.enable_lldp()
    tl.lldp_ets_default_set(sw_if2, willing=False)
    tl.lldp_ets_up2tc_set(sw_if2, [(p1, p1), (p2, p2)])
    tl.lldp_ets_tsa_set(sw_if2, [(p1, "ets"), (p2, "ets")],
                        [(p1, bw1), (p2, bw2)])
    tl.lldp_pfc_set(sw_if1, prio=[], willing=False)

    # Make sure the flows are also separated at ingress.
    sw_if1.enable_lldp()
    tl.lldp_ets_default_set(sw_if1, willing=False)
    tl.lldp_ets_up2tc_set(sw_if1, [(p1, p1), (p2, p2)])
    tl.lldp_pfc_set(sw_if1, prio=[], willing=False)

    # ETS won't work if there aren't enough packets in the shared buffer
    # awaiting transmission. Therefore, let each port take up to ~98% of
    # free buffer in the pool and each PG/TC up to 50%. We assume pools
    # 0 and 4 are configured with non-zero sizes.
    tl.devlink_pool_thtype_set(sw, sw_if1.get_devlink_name(), 0, False)
    tl.devlink_port_tc_quota_set(sw_if1, p1, True, 0, 10)
    tl.devlink_port_tc_quota_set(sw_if1, p2, True, 0, 10)
    tl.devlink_port_quota_set(sw_if1, 0, 16)
    tl.devlink_pool_thtype_set(sw, sw_if1.get_devlink_name(), 4, False)
    tl.devlink_port_tc_quota_set(sw_if2, p1, False, 4, 10)
    tl.devlink_port_tc_quota_set(sw_if2, p2, False, 4, 10)
    tl.devlink_port_quota_set(sw_if2, 4, 16)

    tl.ping_simple(m1_if1, m2_if1)

    # Record the stats before the test for comparison.
    tx_stats_p1_t0 = tl.get_tx_prio_stats(sw_if2, p1)
    tx_stats_p2_t0 = tl.get_tx_prio_stats(sw_if2, p2)

    # Transmit each flow using as many threads as possible, thereby
    # making sure the egress port is congested. Otherwise, ETS won't
    # take effect.
    num_cpus = m1.get_num_cpus()
    packet_count = 10 * 10 ** 6
    thread_option = ["vlan_p {}".format(p1)] * (num_cpus / 2)
    thread_option += ["vlan_p {}".format(p2)] * (num_cpus / 2)
    tl.pktgen(m1_if1, m2_if1, m1_if1.get_mtu(), thread_option=thread_option,
              vlan_id=10, count=packet_count, flag="QUEUE_MAP_CPU")

    # Record the stats after the test and check if ETS worked as
    # expected.
    tx_stats_p1_t1 = tl.get_tx_prio_stats(sw_if2, p1)
    tx_stats_p2_t1 = tl.get_tx_prio_stats(sw_if2, p2)
    p1_count = tx_stats_p1_t1 - tx_stats_p1_t0
    p2_count = tx_stats_p2_t1 - tx_stats_p2_t0

    total = p1_count + p2_count
    bw1_oper = p1_count / float(total) * 100
    bw2_oper = p2_count / float(total) * 100

    # Log useful information.
    logging.info("p1_count={} p2_count={}".format(p1_count, p2_count))
    bw_str = "bw1_oper={:.2f}% ({}%) bw2_oper={:.2f}% ({}%)".format(bw1_oper,
                                                                    bw1,
                                                                    bw2_oper,
                                                                    bw2)
    logging.info(bw_str)
    # The 802.1Qaz standard states a deviation of no more than 10%.
    if abs(bw1_oper - bw1) < 10 and abs(bw2_oper - bw2) < 10:
        err_msg = ""
    else:
        err_msg = "bandwidth deviation exceeded 10%"
    tl.custom(sw, "ets test", err_msg)
开发者ID:jpirko,项目名称:lnst,代码行数:104,代码来源:qos-005-ets.py


注:本文中的TestLib.TestLib.custom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。