trex_stateless_messaging.cpp revision 537f5831
1/*
2 Itay Marom
3 Hanoch Haim
4 Cisco Systems, Inc.
5*/
6
7/*
8Copyright (c) 2015-2016 Cisco Systems, Inc.
9
10Licensed under the Apache License, Version 2.0 (the "License");
11you may not use this file except in compliance with the License.
12You may obtain a copy of the License at
13
14    http://www.apache.org/licenses/LICENSE-2.0
15
16Unless required by applicable law or agreed to in writing, software
17distributed under the License is distributed on an "AS IS" BASIS,
18WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19See the License for the specific language governing permissions and
20limitations under the License.
21*/
22#include <string.h>
23
24#include "trex_stateless_messaging.h"
25#include "trex_stateless_dp_core.h"
26#include "trex_stateless_rx_core.h"
27#include "trex_streams_compiler.h"
28#include "trex_stateless.h"
29#include "bp_sim.h"
30
31/*************************
32  start traffic message
33 ************************/
34TrexStatelessDpStart::TrexStatelessDpStart(uint8_t port_id, int event_id, TrexStreamsCompiledObj *obj, double duration) {
35    m_port_id = port_id;
36    m_event_id = event_id;
37    m_obj = obj;
38    m_duration = duration;
39}
40
41
42/**
43 * clone for DP start message
44 *
45 */
46TrexStatelessCpToDpMsgBase *
47TrexStatelessDpStart::clone() {
48
49    TrexStreamsCompiledObj *new_obj = m_obj->clone();
50
51    TrexStatelessCpToDpMsgBase *new_msg = new TrexStatelessDpStart(m_port_id, m_event_id, new_obj, m_duration);
52
53    return new_msg;
54}
55
56TrexStatelessDpStart::~TrexStatelessDpStart() {
57    if (m_obj) {
58        delete m_obj;
59    }
60}
61
62bool
63TrexStatelessDpStart::handle(TrexStatelessDpCore *dp_core) {
64
65    /* staet traffic */
66    dp_core->start_traffic(m_obj, m_duration,m_event_id);
67
68    return true;
69}
70
71/*************************
72  stop traffic message
73 ************************/
74bool
75TrexStatelessDpStop::handle(TrexStatelessDpCore *dp_core) {
76
77
78    dp_core->stop_traffic(m_port_id,m_stop_only_for_event_id,m_event_id);
79    return true;
80}
81
82
83void TrexStatelessDpStop::on_node_remove(){
84    if ( m_core ) {
85        assert(m_core->m_non_active_nodes>0);
86        m_core->m_non_active_nodes--;
87    }
88}
89
90
91TrexStatelessCpToDpMsgBase * TrexStatelessDpPause::clone(){
92
93    TrexStatelessDpPause *new_msg = new TrexStatelessDpPause(m_port_id);
94    return new_msg;
95}
96
97
98bool TrexStatelessDpPause::handle(TrexStatelessDpCore *dp_core){
99    dp_core->pause_traffic(m_port_id);
100    return (true);
101}
102
103
104
105TrexStatelessCpToDpMsgBase * TrexStatelessDpResume::clone(){
106    TrexStatelessDpResume *new_msg = new TrexStatelessDpResume(m_port_id);
107    return new_msg;
108}
109
110bool TrexStatelessDpResume::handle(TrexStatelessDpCore *dp_core){
111    dp_core->resume_traffic(m_port_id);
112    return (true);
113}
114
115
116/**
117 * clone for DP stop message
118 *
119 */
120TrexStatelessCpToDpMsgBase *
121TrexStatelessDpStop::clone() {
122    TrexStatelessDpStop *new_msg = new TrexStatelessDpStop(m_port_id);
123
124    new_msg->set_event_id(m_event_id);
125    new_msg->set_wait_for_event_id(m_stop_only_for_event_id);
126    /* set back pointer to master */
127    new_msg->set_core_ptr(m_core);
128
129    return new_msg;
130}
131
132
133
134TrexStatelessCpToDpMsgBase *
135TrexStatelessDpQuit::clone(){
136
137    TrexStatelessCpToDpMsgBase *new_msg = new TrexStatelessDpQuit();
138
139    return new_msg;
140}
141
142
143bool TrexStatelessDpQuit::handle(TrexStatelessDpCore *dp_core){
144
145    /* quit  */
146    dp_core->quit_main_loop();
147    return (true);
148}
149
150bool TrexStatelessDpCanQuit::handle(TrexStatelessDpCore *dp_core){
151
152    if ( dp_core->are_all_ports_idle() ){
153        /* if all ports are idle quit now */
154        set_quit(true);
155    }
156    return (true);
157}
158
159TrexStatelessCpToDpMsgBase *
160TrexStatelessDpCanQuit::clone(){
161
162    TrexStatelessCpToDpMsgBase *new_msg = new TrexStatelessDpCanQuit();
163
164    return new_msg;
165}
166
167/*************************
168  update traffic message
169 ************************/
170bool
171TrexStatelessDpUpdate::handle(TrexStatelessDpCore *dp_core) {
172    dp_core->update_traffic(m_port_id, m_factor);
173
174    return true;
175}
176
177TrexStatelessCpToDpMsgBase *
178TrexStatelessDpUpdate::clone() {
179    TrexStatelessCpToDpMsgBase *new_msg = new TrexStatelessDpUpdate(m_port_id, m_factor);
180
181    return new_msg;
182}
183
184
185/*************************
186  push PCAP message
187 ************************/
188bool
189TrexStatelessDpPushPCAP::handle(TrexStatelessDpCore *dp_core) {
190    dp_core->push_pcap(m_port_id,
191                       m_event_id,
192                       m_pcap_filename,
193                       m_ipg_usec,
194                       m_speedup,
195                       m_count,
196                       m_duration,
197                       m_is_dual);
198    return true;
199}
200
201TrexStatelessCpToDpMsgBase *
202TrexStatelessDpPushPCAP::clone() {
203    TrexStatelessCpToDpMsgBase *new_msg = new TrexStatelessDpPushPCAP(m_port_id,
204                                                                      m_event_id,
205                                                                      m_pcap_filename,
206                                                                      m_ipg_usec,
207                                                                      m_speedup,
208                                                                      m_count,
209                                                                      m_duration,
210                                                                      m_is_dual);
211
212    return new_msg;
213}
214
215
216/*************************
217  barrier message
218 ************************/
219
220bool
221TrexStatelessDpBarrier::handle(TrexStatelessDpCore *dp_core) {
222    dp_core->barrier(m_port_id, m_event_id);
223    return true;
224}
225
226TrexStatelessCpToDpMsgBase *
227TrexStatelessDpBarrier::clone() {
228
229    TrexStatelessCpToDpMsgBase *new_msg = new TrexStatelessDpBarrier(m_port_id, m_event_id);
230
231    return new_msg;
232}
233
234/************************* messages from DP to CP **********************/
235bool
236TrexDpPortEventMsg::handle() {
237    TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(m_port_id);
238    port->get_dp_events().on_core_reporting_in(m_event_id, m_thread_id, get_status());
239
240    return (true);
241}
242
243/************************* messages from CP to RX **********************/
244bool TrexStatelessRxEnableLatency::handle (CRxCoreStateless *rx_core) {
245    rx_core->enable_latency();
246    return true;
247}
248
249bool TrexStatelessRxDisableLatency::handle (CRxCoreStateless *rx_core) {
250    rx_core->disable_latency();
251    return true;
252}
253
254bool TrexStatelessRxQuit::handle (CRxCoreStateless *rx_core) {
255    rx_core->quit();
256    return true;
257}
258
259
260bool
261TrexStatelessRxStartCapture::handle(CRxCoreStateless *rx_core) {
262    rx_core->start_recorder(m_port_id, m_pcap_filename, m_limit, m_shared_counter);
263
264    set_reply(true);
265
266    return true;
267}
268
269bool
270TrexStatelessRxStopCapture::handle(CRxCoreStateless *rx_core) {
271    rx_core->stop_recorder(m_port_id);
272
273    return true;
274}
275
276bool
277TrexStatelessRxStartQueue::handle(CRxCoreStateless *rx_core) {
278    rx_core->start_queue(m_port_id, m_size, m_shared_counter);
279
280    /* mark as done */
281    set_reply(true);
282
283    return true;
284}
285
286bool
287TrexStatelessRxStopQueue::handle(CRxCoreStateless *rx_core) {
288    rx_core->stop_queue(m_port_id);
289
290    return true;
291}
292
293
294
295bool TrexStatelessRxQueueGetPkts::handle(CRxCoreStateless *rx_core) {
296    RXPacketBuffer *pkt_buffer = rx_core->get_rx_queue_pkts(m_port_id);
297    assert(pkt_buffer);
298
299    /* set the reply */
300    set_reply(pkt_buffer);
301
302    return true;
303}
304