From 85a7f31e2122b52a913a36a8af66f393e99e9bf0 Mon Sep 17 00:00:00 2001 From: Yaroslav Brustinov Date: Sat, 10 Dec 2016 12:11:19 +0200 Subject: Limit ZMQ RPC requests to 999999 bytes at CPP side. TODO: split requests at Python to smaller chunks. Change-Id: Ieaf477d2ed8264e30a8275a75d597fdc8858da79 Signed-off-by: Yaroslav Brustinov --- .../stl/trex_stl_lib/trex_stl_jsonrpc_client.py | 4 ++-- .../trex_control_plane/stl/trex_stl_lib/utils/zipmsg.py | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib') diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py index 93a930e4..ce430e2b 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py @@ -130,13 +130,13 @@ class JsonRpcClient(object): if self.zipper.check_threshold(buffer): response = self.send_raw_msg(self.zipper.compress(buffer)) - if response: - response = self.zipper.decompress(response) else: response = self.send_raw_msg(buffer) if not response: return response + elif self.zipper.is_compressed(response): + response = self.zipper.decompress(response) # return to string response = response.decode() diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/zipmsg.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/zipmsg.py index 397ada16..a2a47927 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/zipmsg.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/zipmsg.py @@ -6,7 +6,7 @@ class ZippedMsg: MSG_COMPRESS_THRESHOLD = 256 MSG_COMPRESS_HEADER_MAGIC = 0xABE85CEA - def check_threshold (self, msg): + def check_threshold(self, msg): return len(msg) >= self.MSG_COMPRESS_THRESHOLD def compress (self, msg): @@ -16,7 +16,7 @@ class ZippedMsg: return new_msg - def decompress (self, msg): + def decompress(self, msg): if len(msg) < 8: return None @@ -30,3 +30,15 @@ class ZippedMsg: return x + + def is_compressed(self, msg): + if len(msg) < 8: + return False + + t = struct.unpack(">II", msg[:8]) + if (t[0] != self.MSG_COMPRESS_HEADER_MAGIC): + return False + + return True + + -- cgit From 392ca5baf8c50c90e656981bde1571feaebc7a5a Mon Sep 17 00:00:00 2001 From: Yaroslav Brustinov Date: Sat, 10 Dec 2016 22:23:31 +0200 Subject: Stateless API: send batches by chunks Change-Id: If551b474c4b6be58dfc3ed19e5c14a4ccd387afd Signed-off-by: Yaroslav Brustinov --- .../stl/trex_stl_lib/trex_stl_jsonrpc_client.py | 31 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib') diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py index ce430e2b..fbad9f7f 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py @@ -32,13 +32,36 @@ class BatchMessage(object): id, msg = self.rpc_client.create_jsonrpc_v2(method_name, params, api_class, encode = False) self.batch_list.append(msg) - def invoke(self, block = False): + def invoke(self, block = False, chunk_size = 500000): if not self.rpc_client.connected: return RC_ERR("Not connected to server") - msg = json.dumps(self.batch_list) - - return self.rpc_client.send_msg(msg) + if chunk_size: + response_batch = RC() + size = 0 + new_batch = [] + for msg in self.batch_list: + if size < chunk_size: + size += len(json.dumps(msg)) + new_batch.append(msg) + else: + batch_json = json.dumps(new_batch) + response = self.rpc_client.send_msg(batch_json) + if not response: + return response + response_batch.add(response) + size = 0 + new_batch = [] + if new_batch: + batch_json = json.dumps(new_batch) + response = self.rpc_client.send_msg(batch_json) + if not response: + return response + response_batch.add(response) + return response_batch + else: + batch_json = json.dumps(self.batch_list) + return self.rpc_client.send_msg(batch_json) # JSON RPC v2.0 client -- cgit From 266ac2d8209e9f63170e3ff32eefb331fca53300 Mon Sep 17 00:00:00 2001 From: Yaroslav Brustinov Date: Sun, 11 Dec 2016 10:30:22 +0200 Subject: STL API: fix split batch to chunks - one packet not being sent Change-Id: Id2e96f2fe6a6c1bb0438198675a61f3c73d53072 Signed-off-by: Yaroslav Brustinov --- .../trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib') diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py index fbad9f7f..51e93f5a 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py @@ -41,10 +41,9 @@ class BatchMessage(object): size = 0 new_batch = [] for msg in self.batch_list: - if size < chunk_size: - size += len(json.dumps(msg)) - new_batch.append(msg) - else: + size += len(json.dumps(msg)) + new_batch.append(msg) + if size > chunk_size: batch_json = json.dumps(new_batch) response = self.rpc_client.send_msg(batch_json) if not response: -- cgit