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


C++ TrexStatelessPort::start_traffic方法代码示例

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


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

示例1: mul

/***************************
 * start traffic on port
 * 
 **************************/
trex_rpc_cmd_rc_e
TrexRpcCmdStartTraffic::_run(const Json::Value &params, Json::Value &result) {

    uint8_t port_id = parse_port(params, result);
    TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);

    double duration  = parse_double(params, "duration", result);

    /* multiplier */
    const Json::Value &mul_obj  = parse_object(params, "mul", result);

    std::string type   = parse_choice(mul_obj, "type", TrexPortMultiplier::g_types, result);
    std::string op     = parse_string(mul_obj, "op", result);
    double      value  = parse_double(mul_obj, "value", result);

    if (op != "abs") {
        generate_parse_err(result, "start message can only specify absolute speed rate");
    }

    TrexPortMultiplier mul(type, op, value);

    try {
        port->start_traffic(mul, duration);

    } catch (const TrexRpcException &ex) {
        generate_execute_err(result, ex.what());
    }

    result["result"]["multiplier"] = port->get_multiplier();

    return (TREX_RPC_CMD_OK);
}
开发者ID:dfried-vasona,项目名称:trex,代码行数:36,代码来源:trex_rpc_cmd_stream.cpp

示例2: if

/***************************
 * start traffic on port
 * 
 **************************/
trex_rpc_cmd_rc_e
TrexRpcCmdStartTraffic::_run(const Json::Value &params, Json::Value &result) {

    uint8_t port_id  = parse_byte(params, "port_id", result);
    double duration  = parse_double(params, "duration", result);

    if (port_id >= get_stateless_obj()->get_port_count()) {
        std::stringstream ss;
        ss << "invalid port id - should be between 0 and " << (int)get_stateless_obj()->get_port_count() - 1;
        generate_execute_err(result, ss.str());
    }

    TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);


    const Json::Value &mul = parse_object(params, "mul", result);
    std::string mul_type = parse_string(mul, "type", result);

    /* dispatch according to type of multiplier  */

    try {
        if (mul_type == "raw") {

            double m = parse_double(mul, "factor", result);
            port->start_traffic(m, duration);

        } else if (mul_type == "max_bps") {

            double max_bps = parse_double(mul, "max", result);
            port->start_traffic_max_bps(max_bps, duration);

        } else if (mul_type == "max_pps") {

            double max_pps = parse_double(mul, "max", result);
            port->start_traffic_max_pps(max_pps, duration);
        }

    } catch (const TrexRpcException &ex) {
        generate_execute_err(result, ex.what());
    }

    result["result"] = "ACK";

    return (TREX_RPC_CMD_OK);
}
开发者ID:MaTriXy,项目名称:trex-core,代码行数:49,代码来源:trex_rpc_cmd_stream.cpp

示例3: switch

/***************************
 * start traffic on port
 * 
 **************************/
trex_rpc_cmd_rc_e
TrexRpcCmdStartTraffic::_run(const Json::Value &params, Json::Value &result) {

    uint8_t port_id = parse_byte(params, "port_id", result);
    double mul = parse_double(params, "mul", result);

    if (port_id >= get_stateless_obj()->get_port_count()) {
        std::stringstream ss;
        ss << "invalid port id - should be between 0 and " << (int)get_stateless_obj()->get_port_count() - 1;
        generate_execute_err(result, ss.str());
    }

    TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);

    TrexStatelessPort::rc_e rc = port->start_traffic(mul);

    if (rc == TrexStatelessPort::RC_OK) {
        result["result"] = "ACK";
    } else {
        std::stringstream ss;
        switch (rc) {
        case TrexStatelessPort::RC_ERR_BAD_STATE_FOR_OP:
            ss << "bad state for operations: port is either transmitting traffic or down";
            break;
        case TrexStatelessPort::RC_ERR_NO_STREAMS:
            ss << "no active streams on that port";
            break;
        default:
            ss << "failed to start traffic";
            break;
        }

        generate_execute_err(result, ss.str());
    }

   return (TREX_RPC_CMD_OK);
}
开发者ID:git-root,项目名称:trex-core,代码行数:41,代码来源:trex_rpc_cmd_stream.cpp


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