summaryrefslogtreecommitdiffstats
path: root/src/stateless/cp
diff options
context:
space:
mode:
Diffstat (limited to 'src/stateless/cp')
-rw-r--r--src/stateless/cp/trex_stream.cpp21
-rw-r--r--src/stateless/cp/trex_stream.h72
-rw-r--r--src/stateless/cp/trex_stream_vm.h7
3 files changed, 97 insertions, 3 deletions
diff --git a/src/stateless/cp/trex_stream.cpp b/src/stateless/cp/trex_stream.cpp
index 8ea0c011..ef718529 100644
--- a/src/stateless/cp/trex_stream.cpp
+++ b/src/stateless/cp/trex_stream.cpp
@@ -53,6 +53,22 @@ std::string TrexStream::get_stream_type_str(stream_type_t stream_type){
}
+void TrexStream::post_vm_compile(){
+ /* if VM is enabled */
+ if (is_vm()) {
+ m_vm_dp = m_vm.cloneAsVmDp();
+
+
+ /* calc m_vm_prefix_size which is the size of the writable packet */
+ uint16_t max_pkt_offset = m_vm_dp->get_max_packet_update_offset();
+ uint16_t pkt_size = m_pkt.len;
+
+ /* calculate the mbuf size that we should allocate */
+ m_vm_prefix_size =calc_writable_mbuf_size(max_pkt_offset,pkt_size);
+ }
+}
+
+
void TrexStream::Dump(FILE *fd){
fprintf(fd,"\n");
@@ -113,12 +129,17 @@ TrexStream::TrexStream(uint8_t type,
m_burst_total_pkts=0;
m_num_bursts=1;
m_ibg_usec=0.0;
+ m_vm_dp = NULL;
}
TrexStream::~TrexStream() {
if (m_pkt.binary) {
delete [] m_pkt.binary;
}
+ if ( m_vm_dp ){
+ delete m_vm_dp;
+ m_vm_dp=NULL;
+ }
}
void
diff --git a/src/stateless/cp/trex_stream.h b/src/stateless/cp/trex_stream.h
index 529dcbe4..53b658fc 100644
--- a/src/stateless/cp/trex_stream.h
+++ b/src/stateless/cp/trex_stream.h
@@ -36,6 +36,54 @@ limitations under the License.
class TrexRpcCmdAddStream;
+static inline uint16_t get_log2_size(uint16_t size){
+
+ uint16_t _sizes[]={64,128,256,512,1024,2048};
+ int i;
+ for (i=0; i<sizeof(_sizes)/sizeof(_sizes[0]); i++) {
+ if (size<=_sizes[i]) {
+ return (_sizes[i]);
+ }
+ }
+ assert(0);
+ return (0);
+}
+
+/**
+ * calculate the size of writable mbuf in bytes. maximum size if packet size
+ *
+ * @param max_offset_writable
+ * the last byte that we don't write too. for example when 63 it means that bytes [62] in the array is written (zero base)
+ * @param pkt_size packet size in bytes
+ *
+ * @return the writable size of the first mbuf . the idea is to give at least 64 bytes const mbuf else all packet will be writeable
+ *
+ * examples:
+ * max_offset_writable =63
+ * pkt_size =62
+ * ==>62
+ *
+ */
+static inline uint16_t calc_writable_mbuf_size(uint16_t max_offset_writable,
+ uint16_t pkt_size){
+
+ if ( pkt_size<=64 ){
+ return (pkt_size);
+ }
+ if (pkt_size<=128) {
+ return (pkt_size);
+ }
+
+ //pkt_size> 128
+ uint16_t non_writable = pkt_size - (max_offset_writable -1) ;
+ if ( non_writable<64 ) {
+ return (pkt_size);
+ }
+ return(max_offset_writable-1);
+}
+
+
+
struct CStreamPktData {
uint8_t *binary;
uint16_t len;
@@ -132,9 +180,14 @@ public:
TrexStream * clone_as_dp() const {
TrexStream *dp = new TrexStream(m_type,m_port_id,m_stream_id);
-
-
dp->m_has_vm = m_has_vm;
+ if (m_vm_dp) {
+ /* should have vm */
+ assert(m_has_vm);
+ dp->m_vm_dp = m_vm_dp->clone();
+ }else{
+ dp->m_vm_dp = NULL;
+ }
dp->m_vm_prefix_size = m_vm_prefix_size;
dp->m_isg_usec = m_isg_usec;
@@ -165,11 +218,22 @@ public:
}
void Dump(FILE *fd);
+
+ bool is_vm(){
+ return ( m_has_vm );
+ }
+
+ StreamVmDp * getDpVm(){
+ return ( m_vm_dp);
+ }
+
+ void post_vm_compile();
+
public:
/* basic */
uint8_t m_type;
uint8_t m_port_id;
- uint16_t m_vm_prefix_size;
+ uint16_t m_vm_prefix_size; /* writeable mbuf size */
uint32_t m_stream_id; /* id from RPC can be anything */
@@ -183,6 +247,8 @@ public:
bool m_has_vm; /* do we have instructions to run */
+ StreamVmDp * m_vm_dp; /* compile VM */
+
CStreamPktData m_pkt;
/* pkt */
diff --git a/src/stateless/cp/trex_stream_vm.h b/src/stateless/cp/trex_stream_vm.h
index 2dd4ec19..2bf72829 100644
--- a/src/stateless/cp/trex_stream_vm.h
+++ b/src/stateless/cp/trex_stream_vm.h
@@ -842,6 +842,13 @@ public:
return (lp);
}
+ uint8_t* clone_bss(){
+ assert(m_bss_size>0);
+ uint8_t *p=(uint8_t *)malloc(m_bss_size);
+ assert(p);
+ memcpy(p,m_bss_ptr,m_bss_size);
+ return (p);
+ }
uint16_t get_bss_size(){
return(m_bss_size);