本文整理汇总了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 ¶ms, 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);
}
示例2: if
/***************************
* start traffic on port
*
**************************/
trex_rpc_cmd_rc_e
TrexRpcCmdStartTraffic::_run(const Json::Value ¶ms, 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);
}
示例3: switch
/***************************
* start traffic on port
*
**************************/
trex_rpc_cmd_rc_e
TrexRpcCmdStartTraffic::_run(const Json::Value ¶ms, 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);
}