diff options
author | imarom <imarom@cisco.com> | 2016-04-03 18:19:20 +0300 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2016-04-04 09:49:54 +0300 |
commit | 4eacb570cf24927de536d23671f50609f1a9ffa5 (patch) | |
tree | 83b8dcd86994c7668a054413d0ba0449a1cf2816 /scripts/automation | |
parent | 0eb15b2e851b5f50669633678143c5a1d3a7d95b (diff) |
API classes (versions)
Diffstat (limited to 'scripts/automation')
7 files changed, 55 insertions, 38 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py index 7fbd2808..bddc4ad0 100755 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py @@ -320,11 +320,11 @@ class AsyncEventHandler(object): class CCommLink(object): """Describes the connectivity of the stateless client method""" - def __init__(self, server="localhost", port=5050, virtual=False, prn_func = None): + def __init__(self, server="localhost", port=5050, virtual=False, client = None): self.virtual = virtual self.server = server self.port = port - self.rpc_link = JsonRpcClient(self.server, self.port, prn_func) + self.rpc_link = JsonRpcClient(self.server, self.port, client) @property def is_connected(self): @@ -347,25 +347,25 @@ class CCommLink(object): if not self.virtual: return self.rpc_link.disconnect() - def transmit(self, method_name, params={}): + def transmit(self, method_name, params = None, api_class = 'core'): if self.virtual: self._prompt_virtual_tx_msg() - _, msg = self.rpc_link.create_jsonrpc_v2(method_name, params) + _, msg = self.rpc_link.create_jsonrpc_v2(method_name, params, api_class) print(msg) return else: - return self.rpc_link.invoke_rpc_method(method_name, params) + return self.rpc_link.invoke_rpc_method(method_name, params, api_class) def transmit_batch(self, batch_list): if self.virtual: self._prompt_virtual_tx_msg() print([msg - for _, msg in [self.rpc_link.create_jsonrpc_v2(command.method, command.params) + for _, msg in [self.rpc_link.create_jsonrpc_v2(command.method, command.params, command.api_class) for command in batch_list]]) else: batch = self.rpc_link.create_batch() for command in batch_list: - batch.add(command.method, command.params) + batch.add(command.method, command.params, command.api_class) # invoke the batch return batch.invoke() @@ -449,7 +449,7 @@ class STLClient(object): self.comm_link = CCommLink(server, sync_port, virtual, - self.logger) + self) # async event handler manager self.event_handler = AsyncEventHandler(self) @@ -481,7 +481,11 @@ class STLClient(object): self.flow_stats) - + # API classes + self.api_vers = [ {'type': 'core', 'major': 1, 'minor':0 } + ] + self.api_h = {'core': None} + ############# private functions - used by the class itself ########### # some preprocessing for port argument @@ -668,6 +672,7 @@ class STLClient(object): return rc + # connect to server def __connect(self): @@ -686,12 +691,22 @@ class STLClient(object): if not rc: return rc + + # API sync + rc = self._transmit("api_sync", params = {'api_vers': self.api_vers}, api_class = None) + if not rc: + return rc + + # decode + for api in rc.data()['api_vers']: + self.api_h[ api['type'] ] = api['api_h'] + + # version rc = self._transmit("get_version") if not rc: return rc - self.server_version = rc.data() self.global_stats.server_version = rc.data() @@ -817,8 +832,8 @@ class STLClient(object): # transmit request on the RPC link - def _transmit(self, method_name, params={}): - return self.comm_link.transmit(method_name, params) + def _transmit(self, method_name, params = None, api_class = 'core'): + return self.comm_link.transmit(method_name, params, api_class) # transmit batch request on the RPC link def _transmit_batch(self, batch_list): @@ -1304,7 +1319,7 @@ class STLClient(object): self.logger.pre_cmd( "Pinging the server on '{0}' port '{1}': ".format(self.connection_info['server'], self.connection_info['sync_port'])) - rc = self._transmit("ping") + rc = self._transmit("ping", api_class = None) self.logger.post_cmd(rc) 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 166fd64e..bd5ba8e7 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 @@ -26,9 +26,9 @@ class BatchMessage(object): self.rpc_client = rpc_client self.batch_list = [] - def add (self, method_name, params={}): + def add (self, method_name, params = None, api_class = 'core'): - id, msg = self.rpc_client.create_jsonrpc_v2(method_name, params, encode = False) + 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): @@ -46,8 +46,9 @@ class JsonRpcClient(object): MSG_COMPRESS_THRESHOLD = 4096 MSG_COMPRESS_HEADER_MAGIC = 0xABE85CEA - def __init__ (self, default_server, default_port, logger): - self.logger = logger + def __init__ (self, default_server, default_port, client): + self.client = client + self.logger = client.logger self.connected = False # default values @@ -93,14 +94,18 @@ class JsonRpcClient(object): def create_batch (self): return BatchMessage(self) - def create_jsonrpc_v2 (self, method_name, params = {}, encode = True): + def create_jsonrpc_v2 (self, method_name, params = None, api_class = 'core', encode = True): msg = {} msg["jsonrpc"] = "2.0" msg["method"] = method_name + msg["id"] = next(self.id_gen) - msg["params"] = params + msg["params"] = params if params is not None else {} - msg["id"] = next(self.id_gen) + # if this RPC has an API class - add it's handler + if api_class: + msg["params"]["api_h"] = self.client.api_h[api_class] + if encode: return id, json.dumps(msg) @@ -108,11 +113,11 @@ class JsonRpcClient(object): return id, msg - def invoke_rpc_method (self, method_name, params = {}): + def invoke_rpc_method (self, method_name, params = None, api_class = 'core'): if not self.connected: return RC_ERR("Not connected to server") - id, msg = self.create_jsonrpc_v2(method_name, params) + id, msg = self.create_jsonrpc_v2(method_name, params, api_class) return self.send_msg(msg) @@ -273,7 +278,7 @@ class JsonRpcClient(object): self.connected = True - rc = self.invoke_rpc_method('ping') + rc = self.invoke_rpc_method('ping', api_class = None) if not rc: self.connected = False return rc diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py index 049929ae..89ad2663 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py @@ -81,8 +81,7 @@ class Port(object): "session_id": self.session_id, "force": force} - command = RpcCmdData("acquire", params) - rc = self.transmit(command.method, command.params) + rc = self.transmit("acquire", params) if rc.good(): self.handler = rc.data() return self.ok() @@ -94,8 +93,7 @@ class Port(object): params = {"port_id": self.port_id, "handler": self.handler} - command = RpcCmdData("release", params) - rc = self.transmit(command.method, command.params) + rc = self.transmit("release", params) self.handler = None if rc.good(): @@ -119,8 +117,7 @@ class Port(object): def sync(self): params = {"port_id": self.port_id} - command = RpcCmdData("get_port_status", params) - rc = self.transmit(command.method, command.params) + rc = self.transmit("get_port_status", params) if rc.bad(): return self.err(rc.err()) @@ -149,8 +146,7 @@ class Port(object): # sync the streams params = {"port_id": self.port_id} - command = RpcCmdData("get_all_streams", params) - rc = self.transmit(command.method, command.params) + rc = self.transmit("get_all_streams", params) if rc.bad(): return self.err(rc.err()) @@ -224,7 +220,7 @@ class Port(object): "stream_id": stream_id, "stream": stream_json} - cmd = RpcCmdData('add_stream', params) + cmd = RpcCmdData('add_stream', params, 'core') batch.append(cmd) @@ -276,7 +272,7 @@ class Port(object): "port_id": self.port_id, "stream_id": stream_id} - cmd = RpcCmdData('remove_stream', params) + cmd = RpcCmdData('remove_stream', params, 'core') batch.append(cmd) diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py index 18678e3e..1d89a599 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py @@ -39,7 +39,7 @@ class BpSimException(Exception): # stateless simulation class STLSim(object): - def __init__ (self, bp_sim_path = None, handler = 0, port_id = 0): + def __init__ (self, bp_sim_path = None, handler = 0, port_id = 0, api_h = "dummy"): if not bp_sim_path: # auto find scripts @@ -54,6 +54,7 @@ class STLSim(object): # dummies self.handler = handler + self.api_h = api_h self.port_id = port_id @@ -62,6 +63,7 @@ class STLSim(object): "jsonrpc": "2.0", "method": "start_traffic", "params": {"handler": self.handler, + "api_h" : self.api_h, "force": force, "port_id": self.port_id, "mul": parsing_opts.decode_multiplier(mult), @@ -168,6 +170,7 @@ class STLSim(object): "jsonrpc": "2.0", "method": "add_stream", "params": {"handler": self.handler, + "api_h": self.api_h, "port_id": self.port_id, "stream_id": stream_id, "stream": stream_json} diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py index a1ccf4e6..a4bb64db 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py @@ -3,8 +3,6 @@ from .utils import text_tables from .utils.text_opts import format_text, format_threshold, format_num -from .trex_stl_async_client import CTRexAsyncStats - from collections import namedtuple, OrderedDict, deque import sys import copy diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py index aeeddc49..3ce876ad 100755 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py @@ -833,7 +833,7 @@ class STLProfile(object): return '\n'.join([str(stream) for stream in self.streams]) def is_pauseable (self): - return all([x.get_mode() == "Continuous" for x in (self.get_streams())]) + return all([x.get_mode() == "Continuous" for x in self.get_streams()]) def has_flow_stats (self): return any([x.has_flow_stats() for x in self.get_streams()]) diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py index e5305c78..cd15b831 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py @@ -4,7 +4,7 @@ from .utils.text_opts import * from .trex_stl_exceptions import * import types -RpcCmdData = namedtuple('RpcCmdData', ['method', 'params']) +RpcCmdData = namedtuple('RpcCmdData', ['method', 'params', 'api_class']) TupleRC = namedtuple('RCT', ['rc', 'data', 'is_warn']) class RpcResponseStatus(namedtuple('RpcResponseStatus', ['success', 'id', 'msg'])): |