summaryrefslogtreecommitdiffstats
path: root/src/stateless
diff options
context:
space:
mode:
Diffstat (limited to 'src/stateless')
-rw-r--r--src/stateless/cp/trex_stateless_port.cpp38
-rw-r--r--src/stateless/cp/trex_stream.h4
-rw-r--r--src/stateless/dp/trex_stateless_dp_core.cpp137
-rw-r--r--src/stateless/dp/trex_stateless_dp_core.h120
-rw-r--r--src/stateless/messaging/trex_stateless_messaging.cpp60
-rw-r--r--src/stateless/messaging/trex_stateless_messaging.h88
6 files changed, 446 insertions, 1 deletions
diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp
index 6b77b107..92d0a7f8 100644
--- a/src/stateless/cp/trex_stateless_port.cpp
+++ b/src/stateless/cp/trex_stateless_port.cpp
@@ -18,8 +18,11 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
+
#include <trex_stateless.h>
#include <trex_stateless_port.h>
+#include <trex_stateless_messaging.h>
+
#include <string>
#ifndef TREX_RPC_MOCK_SERVER
@@ -61,7 +64,32 @@ TrexStatelessPort::start_traffic(void) {
m_port_state = PORT_STATE_TRANSMITTING;
- /* real code goes here */
+
+ /* ************* A HACK FOR NOW *************/
+ /* we support only one stream continious */
+ if (get_stream_table()->size() != 1) {
+ return (RC_ERR_FAILED_TO_COMPILE_STREAMS);
+ }
+
+ TrexStream *stream;
+ for (auto it = get_stream_table()->begin(); it != get_stream_table()->end(); it++ ) {
+ stream = (*it).second;
+ }
+
+ /* support only cont streams */
+ TrexStreamContinuous *cont_stream = dynamic_cast<TrexStreamContinuous *>(stream);
+ if (!cont_stream) {
+ return (RC_ERR_FAILED_TO_COMPILE_STREAMS);
+ }
+
+ /* generate a message to all the relevant DP cores to start transmitting */
+ TrexStatelessCpToDpMsgBase *start_msg = new TrexStatelessDpStart(cont_stream->m_pkt.binary, cont_stream->m_pkt.len, cont_stream->get_pps());
+
+ // FIXME (add the right core list)
+ CNodeRing *ring = CMsgIns::Ins()->getCpDp()->getRingCpToDp(0);
+
+ ring->Enqueue((CGenNode *)start_msg);
+
return (RC_OK);
}
@@ -72,6 +100,14 @@ TrexStatelessPort::stop_traffic(void) {
if (m_port_state == PORT_STATE_TRANSMITTING) {
m_port_state = PORT_STATE_UP_IDLE;
}
+
+ /* generate a message to all the relevant DP cores to start transmitting */
+ TrexStatelessCpToDpMsgBase *stop_msg = new TrexStatelessDpStop();
+
+ // FIXME (add the right core list)
+ CNodeRing *ring = CMsgIns::Ins()->getCpDp()->getRingCpToDp(0);
+
+ ring->Enqueue((CGenNode *)stop_msg);
}
/**
diff --git a/src/stateless/cp/trex_stream.h b/src/stateless/cp/trex_stream.h
index f5bc96ef..91e64d23 100644
--- a/src/stateless/cp/trex_stream.h
+++ b/src/stateless/cp/trex_stream.h
@@ -41,6 +41,7 @@ class TrexStream {
friend class TrexRpcCmdAddStream;
friend class TrexRpcCmdGetStream;
friend class TrexStreamTable;
+ friend class TrexStatelessPort;
public:
TrexStream(uint8_t port_id, uint32_t stream_id);
@@ -197,6 +198,9 @@ public:
*/
int size();
+ std::unordered_map<int, TrexStream *>::iterator begin() {return m_stream_table.begin();}
+ std::unordered_map<int, TrexStream *>::iterator end() {return m_stream_table.end();}
+
private:
/**
* holds all the stream in a hash table by stream id
diff --git a/src/stateless/dp/trex_stateless_dp_core.cpp b/src/stateless/dp/trex_stateless_dp_core.cpp
new file mode 100644
index 00000000..20eadfc5
--- /dev/null
+++ b/src/stateless/dp/trex_stateless_dp_core.cpp
@@ -0,0 +1,137 @@
+/*
+ Itay Marom
+ Cisco Systems, Inc.
+*/
+
+/*
+Copyright (c) 2015-2015 Cisco Systems, Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+#include <trex_stateless_dp_core.h>
+#include <trex_stateless_messaging.h>
+
+#include <bp_sim.h>
+
+typedef struct dp_node_extended_info_ {
+ double next_time_offset;
+} dp_node_extended_info_st;
+
+TrexStatelessDpCore::TrexStatelessDpCore(uint8_t thread_id, CFlowGenListPerThread *core) {
+ m_thread_id = thread_id;
+ m_core = core;
+
+ m_state = STATE_IDLE;
+
+ CMessagingManager * cp_dp = CMsgIns::Ins()->getCpDp();
+
+ m_ring_from_cp = cp_dp->getRingCpToDp(thread_id);
+ m_ring_to_cp = cp_dp->getRingDpToCp(thread_id);
+}
+
+void
+TrexStatelessDpCore::start() {
+
+ /* creates a maintenace job using the scheduler */
+ CGenNode * node_sync = m_core->create_node() ;
+ node_sync->m_type = CGenNode::FLOW_SYNC;
+ node_sync->m_time = m_core->m_cur_time_sec + SYNC_TIME_OUT;
+ m_core->m_node_gen.add_node(node_sync);
+
+ double old_offset = 0.0;
+ m_core->m_node_gen.flush_file(100000000, 0.0, false, m_core, old_offset);
+
+}
+
+void
+TrexStatelessDpCore::handle_pkt_event(CGenNode *node) {
+
+ /* if port has stopped - no transmition */
+ if (m_state == STATE_IDLE) {
+ return;
+ }
+
+ m_core->m_node_gen.m_v_if->send_node(node);
+
+ CGenNodeStateless *node_sl = (CGenNodeStateless *)node;
+
+ /* in case of continues */
+ dp_node_extended_info_st *opaque = (dp_node_extended_info_st *)node_sl->get_opaque_storage();
+ node->m_time += opaque->next_time_offset;
+
+ /* insert a new event */
+ m_core->m_node_gen.m_p_queue.push(node);
+}
+
+void
+TrexStatelessDpCore::start_const_traffic(const uint8_t *pkt,
+ uint16_t pkt_len,
+ double pps) {
+
+ CGenNodeStateless *node = m_core->create_node_sl();
+
+ /* add periodic */
+ node->m_type = CGenNode::STATELESS_PKT;
+ node->m_time = m_core->m_cur_time_sec + 0.0 /* STREAM ISG */;
+ node->m_flags = 0;
+
+ /* set socket id */
+ node->set_socket_id(m_core->m_node_gen.m_socket_id);
+
+ /* build a mbuf from a packet */
+ uint16_t pkt_size = pkt_len;
+ const uint8_t *stream_pkt = pkt;
+
+ dp_node_extended_info_st *opaque = (dp_node_extended_info_st *)node->get_opaque_storage();
+ opaque->next_time_offset = 1.0 / pps;
+
+ /* allocate const mbuf */
+ rte_mbuf_t *m = CGlobalInfo::pktmbuf_alloc(node->get_socket_id(), pkt_size);
+ assert(m);
+
+ char *p = rte_pktmbuf_append(m, pkt_size);
+ assert(p);
+ /* copy the packet */
+ memcpy(p,stream_pkt,pkt_size);
+
+ /* set dir 0 or 1 client or server */
+ pkt_dir_t dir = 0;
+ node->set_mbuf_cache_dir(dir);
+
+ /* TBD repace the mac if req we should add flag */
+ m_core->m_node_gen.m_v_if->update_mac_addr_from_global_cfg(dir, m);
+
+ /* set the packet as a readonly */
+ node->set_cache_mbuf(m);
+
+ m_state = TrexStatelessDpCore::STATE_TRANSMITTING;
+
+ m_core->m_node_gen.add_node((CGenNode *)node);
+
+}
+
+void
+TrexStatelessDpCore::stop_traffic() {
+ m_state = STATE_IDLE;
+}
+
+/**
+ * handle a message from CP to DP
+ *
+ */
+void
+TrexStatelessDpCore::handle_cp_msg(TrexStatelessCpToDpMsgBase *msg) {
+ msg->handle(this);
+ delete msg;
+}
+
diff --git a/src/stateless/dp/trex_stateless_dp_core.h b/src/stateless/dp/trex_stateless_dp_core.h
new file mode 100644
index 00000000..65d894d2
--- /dev/null
+++ b/src/stateless/dp/trex_stateless_dp_core.h
@@ -0,0 +1,120 @@
+/*
+ Itay Marom
+ Cisco Systems, Inc.
+*/
+
+/*
+Copyright (c) 2015-2015 Cisco Systems, Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+#ifndef __TREX_STATELESS_DP_CORE_H__
+#define __TREX_STATELESS_DP_CORE_H__
+
+#include <msg_manager.h>
+#include <pal_utl.h>
+
+class TrexStatelessCpToDpMsgBase;
+class TrexStatelessDpStart;
+class CFlowGenListPerThread;
+class CGenNode;
+
+class TrexStatelessDpCore {
+
+public:
+
+ /* states */
+ enum state_e {
+ STATE_IDLE,
+ STATE_TRANSMITTING
+ };
+
+ TrexStatelessDpCore(uint8_t thread_id, CFlowGenListPerThread *core);
+
+ /**
+ * launch the stateless DP core code
+ *
+ */
+ void start();
+
+ /**
+ * handle pkt event
+ *
+ * @author imarom (27-Oct-15)
+ */
+ void handle_pkt_event(CGenNode *node);
+
+ /**
+ * dummy traffic creator
+ *
+ * @author imarom (27-Oct-15)
+ *
+ * @param pkt
+ * @param pkt_len
+ */
+ void start_const_traffic(const uint8_t *pkt, uint16_t pkt_len, double pps);
+
+ /**
+ * stop all traffic for this core
+ *
+ */
+ void stop_traffic();
+
+ /**
+ * check for and handle messages from CP
+ *
+ * @author imarom (27-Oct-15)
+ */
+ void periodic_check_for_cp_messages() {
+ // doing this inline for performance reasons
+
+ /* fast path */
+ if ( likely ( m_ring_from_cp->isEmpty() ) ) {
+ return;
+ }
+
+ while ( true ) {
+ CGenNode * node;
+ if (m_ring_from_cp->Dequeue(node) != 0) {
+ break;
+ }
+
+ assert(node);
+
+ TrexStatelessCpToDpMsgBase * msg = (TrexStatelessCpToDpMsgBase *)node;
+ handle_cp_msg(msg);
+ }
+
+ }
+
+private:
+ /**
+ * handles a CP to DP message
+ *
+ * @author imarom (27-Oct-15)
+ *
+ * @param msg
+ */
+ void handle_cp_msg(TrexStatelessCpToDpMsgBase *msg);
+
+ uint8_t m_thread_id;
+ state_e m_state;
+ CNodeRing *m_ring_from_cp;
+ CNodeRing *m_ring_to_cp;
+
+ /* pointer to the main object */
+ CFlowGenListPerThread *m_core;
+};
+
+#endif /* __TREX_STATELESS_DP_CORE_H__ */
+
diff --git a/src/stateless/messaging/trex_stateless_messaging.cpp b/src/stateless/messaging/trex_stateless_messaging.cpp
new file mode 100644
index 00000000..4cd5b416
--- /dev/null
+++ b/src/stateless/messaging/trex_stateless_messaging.cpp
@@ -0,0 +1,60 @@
+/*
+ Itay Marom
+ Cisco Systems, Inc.
+*/
+
+/*
+Copyright (c) 2015-2015 Cisco Systems, Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+#include <trex_stateless_messaging.h>
+#include <trex_stateless_dp_core.h>
+#include <string.h>
+
+/*************************
+ start traffic message
+ ************************/
+TrexStatelessDpStart::TrexStatelessDpStart(const uint8_t *pkt, uint16_t pkt_len, double pps) {
+ assert(pkt);
+ assert(pkt_len > 0);
+
+ m_pkt = new uint8_t[pkt_len];
+ memcpy(m_pkt, pkt, pkt_len);
+ m_pkt_len = pkt_len;
+
+ m_pps = pps;
+}
+
+TrexStatelessDpStart::~TrexStatelessDpStart() {
+ if (m_pkt) {
+ delete m_pkt;
+ }
+}
+
+bool
+TrexStatelessDpStart::handle(TrexStatelessDpCore *dp_core) {
+
+ dp_core->start_const_traffic(m_pkt, m_pkt_len, m_pps);
+ return true;
+}
+
+/*************************
+ stop traffic message
+ ************************/
+bool
+TrexStatelessDpStop::handle(TrexStatelessDpCore *dp_core) {
+ dp_core->stop_traffic();
+ return true;
+}
+
diff --git a/src/stateless/messaging/trex_stateless_messaging.h b/src/stateless/messaging/trex_stateless_messaging.h
new file mode 100644
index 00000000..af05aa4c
--- /dev/null
+++ b/src/stateless/messaging/trex_stateless_messaging.h
@@ -0,0 +1,88 @@
+/*
+ Itay Marom
+ Cisco Systems, Inc.
+*/
+
+/*
+Copyright (c) 2015-2015 Cisco Systems, Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+#ifndef __TREX_STATELESS_MESSAGING_H__
+#define __TREX_STATELESS_MESSAGING_H__
+
+#include <msg_manager.h>
+
+class TrexStatelessDpCore;
+
+/**
+ * defines the base class for CP to DP messages
+ *
+ * @author imarom (27-Oct-15)
+ */
+class TrexStatelessCpToDpMsgBase {
+public:
+
+ TrexStatelessCpToDpMsgBase() {
+ }
+
+ virtual ~TrexStatelessCpToDpMsgBase() {
+ }
+
+ /**
+ * virtual function to handle a message
+ *
+ */
+ virtual bool handle(TrexStatelessDpCore *dp_core) = 0;
+};
+
+/**
+ * a message to start traffic
+ *
+ * @author imarom (27-Oct-15)
+ */
+class TrexStatelessDpStart : public TrexStatelessCpToDpMsgBase {
+public:
+
+ TrexStatelessDpStart(const uint8_t *pkt, uint16_t pkt_len, double pps);
+
+ ~TrexStatelessDpStart();
+
+ const uint8_t * get_pkt() {
+ return m_pkt;
+ }
+
+ uint16_t get_pkt_len() {
+ return m_pkt_len;
+ }
+
+ virtual bool handle(TrexStatelessDpCore *dp_core);
+
+private:
+ uint8_t *m_pkt;
+ uint16_t m_pkt_len;
+ double m_pps;
+};
+
+/**
+ * a message to stop traffic
+ *
+ * @author imarom (27-Oct-15)
+ */
+class TrexStatelessDpStop : public TrexStatelessCpToDpMsgBase {
+public:
+ virtual bool handle(TrexStatelessDpCore *dp_core);
+};
+
+
+#endif /* __TREX_STATELESS_MESSAGING_H__ */