summaryrefslogtreecommitdiffstats
path: root/src/stateless/dp/trex_stateless_dp_core.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/stateless/dp/trex_stateless_dp_core.cpp')
-rw-r--r--src/stateless/dp/trex_stateless_dp_core.cpp171
1 files changed, 157 insertions, 14 deletions
diff --git a/src/stateless/dp/trex_stateless_dp_core.cpp b/src/stateless/dp/trex_stateless_dp_core.cpp
index 6648e2f3..c5963625 100644
--- a/src/stateless/dp/trex_stateless_dp_core.cpp
+++ b/src/stateless/dp/trex_stateless_dp_core.cpp
@@ -25,6 +25,88 @@ limitations under the License.
#include "trex_stream.h"
#include "trex_stream_node.h"
#include "trex_streams_compiler.h"
+#include "mbuf.h"
+
+
+
+
+void CGenNodeStateless::cache_mbuf_array_init(){
+ m_cache_size=0;
+ m_cache_array_cnt=0;
+}
+
+
+
+void CGenNodeStateless::cache_mbuf_array_copy(CGenNodeCacheMbuf *obj,
+ uint16_t size){
+
+ int i;
+ cache_mbuf_array_alloc(size);
+ for (i=0; i<size; i++) {
+ cache_mbuf_array_set(i,obj->m_array[i]);
+ }
+ cache_mbuf_array_set_const_mbuf(obj->m_mbuf_const);
+}
+
+
+rte_mbuf_t ** CGenNodeStateless::cache_mbuf_array_alloc(uint16_t size){
+
+ uint32_t buf_size = CGenNodeCacheMbuf::get_object_size(size);
+ /* TBD replace with align, zero API */
+ m_cache_mbuf = (void *)malloc(buf_size);
+ assert(m_cache_mbuf);
+ memset(m_cache_mbuf,0,buf_size);
+
+ m_flags |= SL_NODE_CONST_MBUF_CACHE_ARRAY;
+ m_cache_size=size;
+ m_cache_array_cnt=0;
+ return ((rte_mbuf_t **)m_cache_mbuf);
+}
+
+void CGenNodeStateless::cache_mbuf_array_free(){
+
+ assert(m_cache_mbuf);
+ int i;
+ for (i=0; i<(int)m_cache_size; i++) {
+ rte_mbuf_t * m=cache_mbuf_array_get((uint16_t)i);
+ assert(m);
+ rte_pktmbuf_free(m);
+ }
+
+ /* free the const */
+ rte_mbuf_t * m=cache_mbuf_array_get_const_mbuf() ;
+ if (m) {
+ rte_pktmbuf_free(m);
+ }
+
+ free(m_cache_mbuf);
+ m_cache_mbuf=0;
+}
+
+
+rte_mbuf_t * CGenNodeStateless::cache_mbuf_array_get(uint16_t index){
+
+ CGenNodeCacheMbuf *p =(CGenNodeCacheMbuf *) m_cache_mbuf;
+ return (p->m_array[index]);
+}
+
+void CGenNodeStateless::cache_mbuf_array_set_const_mbuf(rte_mbuf_t * m){
+ CGenNodeCacheMbuf *p =(CGenNodeCacheMbuf *) m_cache_mbuf;
+ p->m_mbuf_const=m;
+}
+
+rte_mbuf_t * CGenNodeStateless::cache_mbuf_array_get_const_mbuf(){
+ CGenNodeCacheMbuf *p =(CGenNodeCacheMbuf *) m_cache_mbuf;
+ return (p->m_mbuf_const);
+}
+
+
+void CGenNodeStateless::cache_mbuf_array_set(uint16_t index,
+ rte_mbuf_t * m){
+ CGenNodeCacheMbuf *p =(CGenNodeCacheMbuf *) m_cache_mbuf;
+ p->m_array[index]=m;
+}
+
void CDpOneStream::Delete(CFlowGenListPerThread * core){
assert(m_node->get_state() == CGenNodeStateless::ss_INACTIVE);
@@ -186,26 +268,40 @@ rte_mbuf_t * CGenNodeStateless::alloc_node_with_vm(){
return (m);
}
-
-void CGenNodeStateless::free_stl_node(){
- /* if we have cache mbuf free it */
- rte_mbuf_t * m=get_cache_mbuf();
- if (m) {
- rte_pktmbuf_free(m);
- m_cache_mbuf=0;
- }else{
- /* non cache - must have an header */
+void CGenNodeStateless::free_stl_vm_buf(){
+ rte_mbuf_t * m ;
m=get_const_mbuf();
if (m) {
rte_pktmbuf_free(m); /* reduce the ref counter */
+ /* clear the const marker */
+ clear_const_mbuf();
}
+
free_prefix_header();
+
+ if (m_vm_flow_var) {
+ /* free flow var */
+ free(m_vm_flow_var);
+ m_vm_flow_var=0;
+ }
+}
+
+
+
+void CGenNodeStateless::free_stl_node(){
+
+ if ( is_cache_mbuf_array() ){
+ /* do we have cache of mbuf pre allocated */
+ cache_mbuf_array_free();
+ }else{
+ /* if we have cache mbuf free it */
+ rte_mbuf_t * m=get_cache_mbuf();
+ if (m) {
+ rte_pktmbuf_free(m);
+ m_cache_mbuf=0;
+ }
}
- if (m_vm_flow_var) {
- /* free flow var */
- free(m_vm_flow_var);
- m_vm_flow_var=0;
- }
+ free_stl_vm_buf();
}
@@ -633,6 +729,40 @@ void TrexStatelessDpCore::update_mac_addr(TrexStream * stream,
}
+void TrexStatelessDpCore::replay_vm_into_cache(TrexStream * stream,
+ CGenNodeStateless *node){
+
+ uint16_t cache_size = stream->m_cache_size;
+ assert(cache_size>0);
+ rte_mbuf_t * m=0;
+
+ uint32_t buf_size = CGenNodeCacheMbuf::get_object_size(cache_size);
+ CGenNodeCacheMbuf * p = (CGenNodeCacheMbuf *)malloc(buf_size);
+ assert(p);
+ memset(p,0,buf_size);
+
+ int i;
+ for (i=0; i<cache_size; i++) {
+ p->m_array[i] = node->alloc_node_with_vm();
+ }
+ /* save const */
+ m=node->get_const_mbuf();
+ if (m) {
+ p->m_mbuf_const=m;
+ rte_pktmbuf_refcnt_update(m,1);
+ }
+
+ /* free all VM and const mbuf */
+ node->free_stl_vm_buf();
+
+ /* copy to local node meory */
+ node->cache_mbuf_array_copy(p,cache_size);
+
+ /* free the memory */
+ free(p);
+}
+
+
void
TrexStatelessDpCore::add_stream(TrexStatelessDpPerPort * lp_port,
TrexStream * stream,
@@ -640,6 +770,9 @@ TrexStatelessDpCore::add_stream(TrexStatelessDpPerPort * lp_port,
CGenNodeStateless *node = m_core->create_node_sl();
+ node->cache_mbuf_array_init();
+ node->m_batch_size=0;
+
/* add periodic */
node->m_cache_mbuf=0;
node->m_type = CGenNode::STATELESS_PKT;
@@ -799,6 +932,11 @@ TrexStatelessDpCore::add_stream(TrexStatelessDpPerPort * lp_port,
memcpy(p,stream_pkt , header_size);
update_mac_addr(stream,node,dir,(char *)p);
+
+ if (stream->m_cache_size > 0 ) {
+ /* we need to create cache of objects */
+ replay_vm_into_cache(stream, node);
+ }
}
@@ -825,6 +963,11 @@ TrexStatelessDpCore::start_traffic(TrexStreamsCompiledObj *obj,
lp_port->m_active_streams = 0;
lp_port->set_event_id(event_id);
+ /* update cur time */
+ if ( CGlobalInfo::is_realtime() ){
+ m_core->m_cur_time_sec = now_sec() + SCHD_OFFSET_DTIME ;
+ }
+
/* no nodes in the list */
assert(lp_port->m_active_nodes.size()==0);