diff options
author | 2016-05-08 14:24:37 +0300 | |
---|---|---|
committer | 2016-05-18 19:20:22 +0300 | |
commit | cb13e66205717a8fcf69185ba350adab3438ffa0 (patch) | |
tree | e11ee60f94005936206daba10fb450ec54eb6f79 /scripts/automation/trex_control_plane/stl/trex_stl_lib | |
parent | 89d643b96d9a86345ef1de8e80c801d1863002e8 (diff) |
Latency stat python API work
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib')
3 files changed, 39 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_async_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_async_client.py index 5c9faf0f..731ddb10 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_async_client.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_async_client.py @@ -293,6 +293,9 @@ class CTRexAsyncClient(): elif name == "flow_stats": self.event_handler.on_async_rx_stats_event(data, baseline) + elif name == "latency_stats": + self.event_handler.on_async_latency_stats_event(data, baseline) + else: pass 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 e7b46aea..88c64e3c 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 @@ -187,6 +187,8 @@ class EventsHandler(object): def on_async_rx_stats_event (self, data, baseline): self.client.flow_stats.update(data, baseline) + def on_async_latency_stats_event (self, data, baseline): + self.client.latency_stats.update(data, baseline) # handles an async stats update from the subscriber def on_async_stats_update(self, dump_data, baseline): @@ -551,6 +553,8 @@ class STLClient(object): self.flow_stats = trex_stl_stats.CRxStats(self.ports) + self.latency_stats = trex_stl_stats.CLatencyStats(self.ports) + self.stats_generator = trex_stl_stats.CTRexInfoGenerator(self.global_stats, self.ports, self.flow_stats) @@ -891,6 +895,7 @@ class STLClient(object): stats['total'] = total stats['flow_stats'] = self.flow_stats.get_stats() + stats['latency'] = self.latency_stats.get_stats() return stats 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 e30da00e..a65ef9e0 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 @@ -831,6 +831,37 @@ class CPortStats(CTRexStats): } +class CLatencyStats(CTRexStats): + def __init__(self, ports): + super(CLatencyStats, self).__init__() + + # for API + def get_stats (self): + return self.latest_stats + + def process_snapshot (self, current): + output = {} + + # we care only about the current active keys + pg_ids = list(filter(is_intable, current.keys())) + + for pg_id in pg_ids: + current_pg = current.get(pg_id) + int_pg_id = int(pg_id) + output[int_pg_id] = {} + for field in ['err_cntrs', 'jitter', 'latency']: + output[int_pg_id][field] = current_pg[field] + return output + + def update (self, snapshot, baseline): + # generate a new snapshot + if (snapshot is not None): + new_snapshot = self.process_snapshot(snapshot) + else: + return + + self.latest_stats = new_snapshot + return True # RX stats objects - COMPLEX :-( |