Merge "Extend TRex RFC2544 test case collected stats"
[yardstick.git] / yardstick / network_services / vnf_generic / vnf / tg_trex.py
index 93ba855..0cb66a7 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2016-2017 Intel Corporation
+# Copyright (c) 2016-2019 Intel Corporation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-""" Trex acts as traffic generation and vnf definitions based on IETS Spec """
-
-from __future__ import absolute_import
-from __future__ import print_function
 
+import datetime
 import logging
 import os
 
@@ -27,6 +24,7 @@ from yardstick.network_services.vnf_generic.vnf.sample_vnf import SampleVNFTraff
 from yardstick.network_services.vnf_generic.vnf.sample_vnf import ClientResourceHelper
 from yardstick.network_services.vnf_generic.vnf.sample_vnf import DpdkVnfSetupEnvHelper
 
+
 LOG = logging.getLogger(__name__)
 
 
@@ -128,6 +126,11 @@ class TrexResourceHelper(ClientResourceHelper):
         self.ssh_helper.execute(self.MAKE_INSTALL.format(ko_src))
 
     def start(self, ports=None, *args, **kwargs):
+        # pylint: disable=keyword-arg-before-vararg
+        # NOTE(ralonsoh): defining keyworded arguments before variable
+        # positional arguments is a bug. This function definition doesn't work
+        # in Python 2, although it works in Python 3. Reference:
+        # https://www.python.org/dev/peps/pep-3102/
         cmd = "sudo fuser -n tcp {0.SYNC_PORT} {0.ASYNC_PORT} -k > /dev/null 2>&1"
         self.ssh_helper.execute(cmd.format(self))
 
@@ -162,6 +165,34 @@ class TrexResourceHelper(ClientResourceHelper):
         cmd = "sudo fuser -n tcp %s %s -k > /dev/null 2>&1"
         self.ssh_helper.execute(cmd % (self.SYNC_PORT, self.ASYNC_PORT))
 
+    def _get_samples(self, ports, port_pg_id=None):
+        stats = self.get_stats(ports)
+        timestamp = datetime.datetime.now()
+        samples = {}
+        for pname in (intf['name'] for intf in self.vnfd_helper.interfaces):
+            port_num = self.vnfd_helper.port_num(pname)
+            port_stats = stats.get(port_num, {})
+            samples[pname] = {
+                'rx_throughput_fps': float(port_stats.get('rx_pps', 0.0)),
+                'tx_throughput_fps': float(port_stats.get('tx_pps', 0.0)),
+                'rx_throughput_bps': float(port_stats.get('rx_bps', 0.0)),
+                'tx_throughput_bps': float(port_stats.get('tx_bps', 0.0)),
+                'in_packets': int(port_stats.get('ipackets', 0)),
+                'out_packets': int(port_stats.get('opackets', 0)),
+                'in_bytes': int(port_stats.get('ibytes', 0)),
+                'out_bytes': int(port_stats.get('obytes', 0)),
+                'timestamp': timestamp
+            }
+
+            pg_id_list = port_pg_id.get_pg_ids(port_num)
+            samples[pname]['latency'] = {}
+            for pg_id in pg_id_list:
+                latency_global = stats.get('latency', {})
+                pg_latency = latency_global.get(pg_id, {}).get('latency')
+                samples[pname]['latency'][pg_id] = pg_latency
+
+        return samples
+
 
 class TrexTrafficGen(SampleVNFTrafficGen):
     """
@@ -188,11 +219,8 @@ class TrexTrafficGen(SampleVNFTrafficGen):
         super(TrexTrafficGen, self)._start_server()
         self.resource_helper.start()
 
-    def scale(self, flavor=""):
-        pass
-
-    def listen_traffic(self, traffic_profile):
-        pass
-
     def terminate(self):
         self.resource_helper.terminate()
+
+    def wait_for_instantiate(self):
+        return self._wait_for_process()