summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gtest/trex_stateless_gtest.cpp9
-rw-r--r--src/stateless/cp/trex_stream_vm.h117
2 files changed, 122 insertions, 4 deletions
diff --git a/src/gtest/trex_stateless_gtest.cpp b/src/gtest/trex_stateless_gtest.cpp
index b80067b4..20e13602 100644
--- a/src/gtest/trex_stateless_gtest.cpp
+++ b/src/gtest/trex_stateless_gtest.cpp
@@ -770,7 +770,7 @@ TEST_F(basic_vm, vm9) {
StreamVm vm;
- vm.add_instruction( new StreamVmInstructionFlowClient( "cl1",
+ vm.add_instruction( new StreamVmInstructionFlowClient( "tuple_gen",
0x10000001,
0x10000006,
1025,
@@ -779,13 +779,13 @@ TEST_F(basic_vm, vm9) {
0) );
/* src ip */
- vm.add_instruction( new StreamVmInstructionWriteToPkt( "cl1.ip",26, 0,true)
+ vm.add_instruction( new StreamVmInstructionWriteToPkt( "tuple_gen.ip",26, 0,true)
);
vm.add_instruction( new StreamVmInstructionFixChecksumIpv4(14) );
/* src port */
- vm.add_instruction( new StreamVmInstructionWriteToPkt( "cl1.port",34, 0,true)
+ vm.add_instruction( new StreamVmInstructionWriteToPkt( "tuple_gen.port",34, 0,true)
);
@@ -793,6 +793,9 @@ TEST_F(basic_vm, vm9) {
vm.compile_next();
+ printf(" max packet update %lu \n",(ulong)vm.get_max_packet_update_offset());
+
+ EXPECT_EQ(36,vm.get_max_packet_update_offset());
uint32_t program_size=vm.get_dp_instruction_buffer()->get_program_size();
diff --git a/src/stateless/cp/trex_stream_vm.h b/src/stateless/cp/trex_stream_vm.h
index 08a8621a..2dd4ec19 100644
--- a/src/stateless/cp/trex_stream_vm.h
+++ b/src/stateless/cp/trex_stream_vm.h
@@ -702,7 +702,8 @@ public:
}
bool is_unlimited_flows(){
- return ( (m_flags & StreamVmInstructionFlowClient::CLIENT_F_UNLIMITED_FLOWS ) ==StreamVmInstructionFlowClient::CLIENT_F_UNLIMITED_FLOWS);
+ return ( (m_flags & StreamVmInstructionFlowClient::CLIENT_F_UNLIMITED_FLOWS ) ==
+ StreamVmInstructionFlowClient::CLIENT_F_UNLIMITED_FLOWS );
}
public:
@@ -771,11 +772,113 @@ public:
bool m_is_big_endian;
};
+
+/**
+ * describes a VM program for DP
+ *
+ */
+
+class StreamVmDp {
+public:
+ StreamVmDp(){
+ m_bss_ptr=NULL;
+ m_program_ptr =NULL ;
+ m_bss_size=0;
+ m_program_size=0;
+ m_max_pkt_offset_change=0;
+ }
+
+ StreamVmDp( uint8_t * bss,
+ uint16_t bss_size,
+ uint8_t * prog,
+ uint16_t prog_size,
+ uint16_t max_pkt_offset
+ ){
+
+ if (bss) {
+ assert(bss_size);
+ m_bss_ptr=(uint8_t*)malloc(bss_size);
+ assert(m_bss_ptr);
+ memcpy(m_bss_ptr,bss,bss_size);
+ m_bss_size=bss_size;
+ }else{
+ m_bss_ptr=NULL;
+ m_bss_size=0;
+ }
+
+ if (prog) {
+ assert(prog_size);
+ m_program_ptr=(uint8_t*)malloc(prog_size);
+ memcpy(m_program_ptr,prog,prog_size);
+ m_program_size = prog_size;
+ }else{
+ m_program_ptr = NULL;
+ m_program_size=0;
+ }
+ m_max_pkt_offset_change =max_pkt_offset;
+ }
+
+ ~StreamVmDp(){
+ if (m_bss_ptr) {
+ free(m_bss_ptr);
+ m_bss_ptr=0;
+ m_bss_size=0;
+ }
+ if (m_program_ptr) {
+ free(m_program_ptr);
+ m_program_size=0;
+ m_program_ptr=0;
+ }
+ }
+
+ StreamVmDp * clone() const {
+ StreamVmDp * lp= new StreamVmDp(m_bss_ptr,
+ m_bss_size,
+ m_program_ptr,
+ m_program_size,
+ m_max_pkt_offset_change
+ );
+ assert(lp);
+ return (lp);
+ }
+
+
+ uint16_t get_bss_size(){
+ return(m_bss_size);
+ }
+
+ uint8_t* get_bss(){
+ return (m_bss_ptr);
+ }
+
+ uint8_t* get_program(){
+ return (m_program_ptr);
+ }
+
+ uint16_t get_program_size(){
+ return (m_program_size);
+ }
+
+ uint16_t get_max_packet_update_offset(){
+ return (m_max_pkt_offset_change);
+ }
+
+private:
+ uint8_t * m_bss_ptr; /* pointer to the data section */
+ uint8_t * m_program_ptr; /* pointer to the program */
+ uint16_t m_bss_size;
+ uint16_t m_program_size; /* program size*/
+ uint16_t m_max_pkt_offset_change;
+
+};
+
+
/**
* describes a VM program
*
*/
class StreamVm {
+
public:
enum STREAM_VM {
svMAX_FLOW_VAR = 64, /* maximum flow varible */
@@ -801,6 +904,18 @@ public:
}
+ StreamVmDp * cloneAsVmDp(){
+
+ StreamVmDp * lp= new StreamVmDp(get_bss_ptr(),
+ get_bss_size(),
+ get_dp_instruction_buffer()->get_program(),
+ get_dp_instruction_buffer()->get_program_size(),
+ get_max_packet_update_offset()
+ );
+ assert(lp);
+ return (lp);
+
+ }
/**
* add new instruction to the VM