Ejemplo n.º 1
0
/**
 * starts the traffic on the port
 * 
 */
TrexStatelessPort::rc_e
TrexStatelessPort::start_traffic(double mul) {

    if (m_port_state != PORT_STATE_UP_IDLE) {
        return (RC_ERR_BAD_STATE_FOR_OP);
    }

    if (get_stream_table()->size() == 0) {
        return (RC_ERR_NO_STREAMS);
    }

    /* fetch all the streams from the table */
    vector<TrexStream *> streams;
    get_stream_table()->get_object_list(streams);

    /* compiler it */
    TrexStreamsCompiler compiler;
    TrexStreamsCompiledObj *compiled_obj = new TrexStreamsCompiledObj(m_port_id, mul);

    bool rc = compiler.compile(streams, *compiled_obj);
    if (!rc) {
        return (RC_ERR_FAILED_TO_COMPILE_STREAMS);
    }

    /* generate a message to all the relevant DP cores to start transmitting */
    TrexStatelessCpToDpMsgBase *start_msg = new TrexStatelessDpStart(compiled_obj);

    send_message_to_dp(start_msg);

    /* move the state to transmiting */
    m_port_state = PORT_STATE_TRANSMITTING;

    return (RC_OK);
}
const TrexStreamsGraphObj *
TrexStatelessPort::validate(void) {

    /* first compile the graph */

    vector<TrexStream *> streams;
    get_object_list(streams);

    if (streams.size() == 0) {
        throw TrexException("no streams attached to port");
    }

    TrexStreamsCompiler compiler;
    std::vector<TrexStreamsCompiledObj *> compiled_objs;

    std::string fail_msg;
    bool rc = compiler.compile(m_port_id,
                               streams,
                               compiled_objs,
                               get_dp_core_count(),
                               1.0,
                               &fail_msg);
    if (!rc) {
        throw TrexException(fail_msg);
    }

    for (auto obj : compiled_objs) {
        delete obj;
    }

    /* now create a stream graph */
    if (!m_graph_obj) {
        generate_streams_graph();
    }

    return m_graph_obj;
}
/**
 * starts the traffic on the port
 * 
 */
void
TrexStatelessPort::start_traffic(const TrexPortMultiplier &mul, double duration) {

    /* command allowed only on state stream */
    verify_state(PORT_STATE_STREAMS);

    /* just making sure no leftovers... */
    delete_streams_graph();

    /* on start - we can only provide absolute values */
    assert(mul.m_op == TrexPortMultiplier::OP_ABS);

    double factor = calculate_effective_factor(mul);

    /* fetch all the streams from the table */
    vector<TrexStream *> streams;
    get_object_list(streams);


    /* compiler it */
    std::vector<TrexStreamsCompiledObj *> compiled_objs;
    std::string fail_msg;

    TrexStreamsCompiler compiler;
    bool rc = compiler.compile(m_port_id,
                               streams,
                               compiled_objs,
                               get_dp_core_count(),
                               factor,
                               &fail_msg);
    if (!rc) {
        throw TrexRpcException(fail_msg);
    }

    /* generate a message to all the relevant DP cores to start transmitting */
    int event_id = m_dp_events.generate_event_id();

    /* mark that DP event of stoppped is possible */
    m_dp_events.wait_for_event(TrexDpPortEvent::EVENT_STOP, event_id);


    /* update object status */
    m_factor = factor;
    m_last_all_streams_continues = compiled_objs[0]->get_all_streams_continues();
    m_last_duration = duration;
    change_state(PORT_STATE_TX);


    /* update the DP - messages will be freed by the DP */
    int index = 0;
    for (auto core_id : m_cores_id_list) {

        TrexStatelessCpToDpMsgBase *start_msg = new TrexStatelessDpStart(m_port_id, event_id, compiled_objs[index], duration);
        send_message_to_dp(core_id, start_msg);

        index++;
    }
    
    /* update subscribers */    
    Json::Value data;
    data["port_id"] = m_port_id;
    get_stateless_obj()->get_publisher()->publish_event(TrexPublisher::EVENT_PORT_STARTED, data);
    
}