diff options
Diffstat (limited to 'nfvbench/traffic_gen')
-rw-r--r-- | nfvbench/traffic_gen/dummy.py | 2 | ||||
-rw-r--r-- | nfvbench/traffic_gen/traffic_base.py | 2 | ||||
-rw-r--r-- | nfvbench/traffic_gen/trex_gen.py | 33 |
3 files changed, 32 insertions, 5 deletions
diff --git a/nfvbench/traffic_gen/dummy.py b/nfvbench/traffic_gen/dummy.py index 272990a..25664e5 100644 --- a/nfvbench/traffic_gen/dummy.py +++ b/nfvbench/traffic_gen/dummy.py @@ -102,7 +102,7 @@ class DummyTG(AbstractTrafficGenerator): def clear_streamblock(self): pass - def get_stats(self): + def get_stats(self, ifstats): """Get stats from current run. The binary search mainly looks at 2 results to make the decision: diff --git a/nfvbench/traffic_gen/traffic_base.py b/nfvbench/traffic_gen/traffic_base.py index 3bff7da..abf5a22 100644 --- a/nfvbench/traffic_gen/traffic_base.py +++ b/nfvbench/traffic_gen/traffic_base.py @@ -82,7 +82,7 @@ class AbstractTrafficGenerator(object): LOG.info('Modified traffic stream for port %s, new rate=%s.', port, self.rates[port_index]) @abc.abstractmethod - def get_stats(self): + def get_stats(self, ifstats): # Must be implemented by sub classes return None diff --git a/nfvbench/traffic_gen/trex_gen.py b/nfvbench/traffic_gen/trex_gen.py index 7220e4b..b35d13f 100644 --- a/nfvbench/traffic_gen/trex_gen.py +++ b/nfvbench/traffic_gen/trex_gen.py @@ -18,6 +18,7 @@ import os import random import time import traceback +from functools import reduce from itertools import count # pylint: disable=import-error @@ -29,6 +30,8 @@ from nfvbench.utils import cast_integer from nfvbench.utils import timeout from nfvbench.utils import TimeoutError +from hdrh.histogram import HdrHistogram + # pylint: disable=import-error from trex.common.services.trex_service_arp import ServiceARP from trex.stl.api import bind_layers @@ -116,7 +119,7 @@ class TRex(AbstractTrafficGenerator): pg_id = port * TRex.PORT_PG_ID_MASK | chain_id return pg_id, pg_id | TRex.LATENCY_PG_ID_MASK - def extract_stats(self, in_stats): + def extract_stats(self, in_stats, ifstats): """Extract stats from dict returned by Trex API. :param in_stats: dict as returned by TRex api @@ -158,6 +161,30 @@ class TRex(AbstractTrafficGenerator): result['offered_tx_rate_bps'] = total_tx_bps result["flow_stats"] = in_stats["flow_stats"] result["latency"] = in_stats["latency"] + + # Merge HDRHistogram to have an overall value for all chains and ports + try: + hdrh_list = [] + if ifstats: + for chain_id, _ in enumerate(ifstats): + for ph in self.port_handle: + _, lat_pg_id = self.get_pg_id(ph, chain_id) + hdrh_list.append( + HdrHistogram.decode(in_stats['latency'][lat_pg_id]['latency']['hdrh'])) + else: + for pg_id in in_stats['latency']: + if pg_id != 'global': + hdrh_list.append( + HdrHistogram.decode(in_stats['latency'][pg_id]['latency']['hdrh'])) + + def add_hdrh(x, y): + x.add(y) + return x + decoded_hdrh = reduce(add_hdrh, hdrh_list) + result["hdrh"] = HdrHistogram.encode(decoded_hdrh).decode('utf-8') + except KeyError: + pass + return result def get_stream_stats(self, trex_stats, if_stats, latencies, chain_idx): @@ -865,10 +892,10 @@ class TRex(AbstractTrafficGenerator): self.client.reset(self.port_handle) LOG.info('Cleared all existing streams') - def get_stats(self): + def get_stats(self, if_stats=None): """Get stats from Trex.""" stats = self.client.get_stats() - return self.extract_stats(stats) + return self.extract_stats(stats, if_stats) def get_macs(self): """Return the Trex local port MAC addresses. |