summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/publisher/trex_publisher.cpp26
-rw-r--r--src/publisher/trex_publisher.h7
-rw-r--r--src/stateless/cp/trex_stateless.cpp2
3 files changed, 30 insertions, 5 deletions
diff --git a/src/publisher/trex_publisher.cpp b/src/publisher/trex_publisher.cpp
index f56d56df..850b5955 100644
--- a/src/publisher/trex_publisher.cpp
+++ b/src/publisher/trex_publisher.cpp
@@ -20,6 +20,7 @@ limitations under the License.
*/
#include "trex_publisher.h"
+#include "trex_rpc_zip.h"
#include <zmq.h>
#include <assert.h>
#include <sstream>
@@ -73,13 +74,32 @@ TrexPublisher::Delete(){
void
-TrexPublisher::publish_json(const std::string &s){
+TrexPublisher::publish_json(const std::string &s, uint32_t zip_threshold){
+
if (m_publisher) {
- int size = zmq_send (m_publisher, s.c_str(), s.length(), 0);
- assert(size == s.length());
+ if ( (zip_threshold > 0) && (s.size() > zip_threshold) ) {
+ publish_zipped_json(s);
+ } else {
+ publish_raw_json(s);
+ }
}
}
+void
+TrexPublisher::publish_zipped_json(const std::string &s) {
+ std::string compressed_msg;
+
+ TrexRpcZip::compress(s, compressed_msg);
+ int size = zmq_send (m_publisher, compressed_msg.c_str(), compressed_msg.length(), 0);
+ assert(size == compressed_msg.length());
+}
+
+void
+TrexPublisher::publish_raw_json(const std::string &s) {
+ int size = zmq_send (m_publisher, s.c_str(), s.length(), 0);
+ assert(size == s.length());
+}
+
void
TrexPublisher::publish_event(event_type_e type, const Json::Value &data) {
Json::FastWriter writer;
diff --git a/src/publisher/trex_publisher.h b/src/publisher/trex_publisher.h
index 1d283478..fb7226c4 100644
--- a/src/publisher/trex_publisher.h
+++ b/src/publisher/trex_publisher.h
@@ -38,7 +38,7 @@ public:
virtual bool Create(uint16_t port, bool disable);
virtual void Delete();
- virtual void publish_json(const std::string &s);
+ virtual void publish_json(const std::string &s, uint32_t zip_threshold = MSG_COMPRESS_THRESHOLD);
enum event_type_e {
EVENT_PORT_STARTED = 0,
@@ -71,9 +71,14 @@ public:
private:
void show_zmq_last_error(const std::string &err);
+ void publish_zipped_json(const std::string &s);
+ void publish_raw_json(const std::string &s);
+
private:
void * m_context;
void * m_publisher;
+
+ static const int MSG_COMPRESS_THRESHOLD = 256;
};
#endif /* __TREX_PUBLISHER_H__ */
diff --git a/src/stateless/cp/trex_stateless.cpp b/src/stateless/cp/trex_stateless.cpp
index 6d80539c..22389d6a 100644
--- a/src/stateless/cp/trex_stateless.cpp
+++ b/src/stateless/cp/trex_stateless.cpp
@@ -54,7 +54,7 @@ TrexStateless::TrexStateless(const TrexStatelessCfg &cfg) {
m_publisher = cfg.m_publisher;
/* API core version */
- const int API_VER_MAJOR = 1;
+ const int API_VER_MAJOR = 2;
const int API_VER_MINOR = 3;
m_api_classes[APIClass::API_CLASS_TYPE_CORE].init(APIClass::API_CLASS_TYPE_CORE,
API_VER_MAJOR,