From dbd2b47ce0683051288d3fa225285956fab5ab3f Mon Sep 17 00:00:00 2001 From: Yaroslav Brustinov Date: Mon, 21 Dec 2015 11:27:58 +0200 Subject: latency.cpp: update ports stats at CLatencyManager::update, instead of CCPortLatency::DumpShort Python API added: * is_idle(): determine if TRex is in idle state * sample_x_seconds(): sample TRex for given number of seconds, useful for changing device (router etc.) config afterwards. --- .../trex_control_plane/client/trex_client.py | 63 ++++++++++++++++++++++ src/latency.cpp | 6 ++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/scripts/automation/trex_control_plane/client/trex_client.py b/scripts/automation/trex_control_plane/client/trex_client.py index 5709b7a5..40a8a45d 100755 --- a/scripts/automation/trex_control_plane/client/trex_client.py +++ b/scripts/automation/trex_control_plane/client/trex_client.py @@ -294,6 +294,34 @@ class CTRexClient(object): finally: self.prompt_verbose_data() + def is_idle (self): + """ + Poll for TRex running status, check if TRex is in Idle state. + + :parameters: + None + + :return: + + **True** if TRex is idle. + + **False** if TRex is starting or running. + + :raises: + + :exc:`trex_exceptions.TRexIncompleteRunError`, in case one of failed TRex run (unexpected termination). + + :exc:`TypeError`, in case JSON stream decoding error. + + ProtocolError, in case of error in JSON-RPC protocol. + + """ + try: + if self.get_running_status()['state'] == TRexStatus.Idle: + return True + return False + except TRexException: + raise + except ProtocolError as err: + raise + finally: + self.prompt_verbose_data() + def get_trex_files_path (self): """ Fetches the local path in which files are stored when pushed to TRex server from client. @@ -455,6 +483,41 @@ class CTRexClient(object): results = self.get_result_obj() return results + def sample_x_seconds (self, sample_time, time_between_samples = 5): + """ + Automatically sets ongoing sampling of TRex data for sample_time seconds, with sampling rate described by time_between_samples. + Does not stop the TRex afterwards! + + .. tip:: Useful for changing the device (Router, ASA etc.) configuration after given time. + + :parameters: + sample_time : int + sample the TRex this number of seconds + + time_between_samples : int + determines the time between each sample of the server + + default value : **5** + + :return: + the first result object (see :class:`CTRexResult` for further details) of the TRex run after given sample_time. + + :raises: + + :exc:`UserWarning`, in case the TRex run ended before sample_time duration + + :exc:`trex_exceptions.TRexIncompleteRunError`, in case one of failed TRex run (unexpected termination). + + :exc:`TypeError`, in case JSON stream decoding error. + + ProtocolError, in case of error in JSON-RPC protocol. + + """ + # make sure TRex is running. raise exceptions here if any + self.wait_until_kickoff_finish() + elapsed_time = 0 + while self.is_running(): + if elapsed_time >= sample_time: + return self.get_result_obj() + time.sleep(time_between_samples) + elapsed_time += time_between_samples + raise UserWarning("TRex has stopped at %s seconds (before expected %s seconds)\nTry increasing test duration or decreasing sample_time" % (elapsed_time, sample_time)) def get_result_obj (self, copy_obj = True): """ diff --git a/src/latency.cpp b/src/latency.cpp index 02b54f75..3969c357 100644 --- a/src/latency.cpp +++ b/src/latency.cpp @@ -268,7 +268,7 @@ void CCPortLatency::dump_json(std::string & json ){ void CCPortLatency::DumpShort(FILE *fd){ - m_hist.update(); +// m_hist.update(); <- moved to CLatencyManager::update() fprintf(fd,"%8lu,%8lu,%10lu,%4lu,", m_tx_pkt_ok, m_pkt_ok, @@ -907,6 +907,10 @@ void CLatencyManager::rx_check_dump_json(std::string & json){ void CLatencyManager::update(){ m_cpu_cp_u.Update() ; + for (int i=0; im_port.m_hist.update(); + } } void CLatencyManager::DumpShort(FILE *fd){ -- cgit 1.2.3-korg