NSB sync: clean-up draft IPC implementation (part 1)
[yardstick.git] / yardstick / network_services / vnf_generic / vnf / prox_vnf.py
index 839f309..0d1360d 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2017 Intel Corporation
+# Copyright (c) 2018 Intel Corporation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
 import errno
 import logging
 import datetime
+import time
 
 from yardstick.common.process import check_if_process_failed
 from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxDpdkVnfSetupEnvHelper
@@ -34,8 +35,7 @@ class ProxApproxVnf(SampleVNF):
     VNF_PROMPT = "PROX started"
     LUA_PARAMETER_NAME = "sut"
 
-    def __init__(self, name, vnfd, task_id, setup_env_helper_type=None,
-                 resource_helper_type=None):
+    def __init__(self, name, vnfd, setup_env_helper_type=None, resource_helper_type=None):
         if setup_env_helper_type is None:
             setup_env_helper_type = ProxDpdkVnfSetupEnvHelper
 
@@ -46,8 +46,8 @@ class ProxApproxVnf(SampleVNF):
         self.prev_packets_sent = 0
         self.prev_tsc = 0
         self.tsc_hz = 0
-        super(ProxApproxVnf, self).__init__(
-            name, vnfd, task_id, setup_env_helper_type, resource_helper_type)
+        super(ProxApproxVnf, self).__init__(name, vnfd, setup_env_helper_type,
+                                            resource_helper_type)
 
     def _vnf_up_post(self):
         self.resource_helper.up_post()
@@ -81,6 +81,8 @@ class ProxApproxVnf(SampleVNF):
                 "packets_in": 0,
                 "packets_dropped": 0,
                 "packets_fwd": 0,
+                "curr_packets_in": 0,
+                "curr_packets_fwd": 0,
                 "collect_stats": {"core": {}},
             })
             return result
@@ -97,15 +99,26 @@ class ProxApproxVnf(SampleVNF):
             raise RuntimeError("Failed ..Invalid no of ports .. "
                                "1, 2 or 4 ports only supported at this time")
 
-        all_port_stats = self.vnf_execute('multi_port_stats', range(port_count))
-        rx_total = tx_total = tsc = 0
-        try:
-            for single_port_stats in all_port_stats:
-                rx_total = rx_total + single_port_stats[1]
-                tx_total = tx_total + single_port_stats[2]
-                tsc = tsc + single_port_stats[5]
-        except (TypeError, IndexError):
-            LOG.error("Invalid data ...")
+        tmpPorts = [self.vnfd_helper.port_num(port_name)
+                    for port_name in self.vnfd_helper.port_pairs.all_ports]
+        ok = False
+        timeout = time.time() + constants.RETRY_TIMEOUT
+        while not ok:
+            ok, all_port_stats = self.vnf_execute('multi_port_stats', tmpPorts)
+            if time.time() > timeout:
+                break
+
+        if ok:
+            rx_total = tx_total = tsc = 0
+            try:
+                for single_port_stats in all_port_stats:
+                    rx_total = rx_total + single_port_stats[1]
+                    tx_total = tx_total + single_port_stats[2]
+                    tsc = tsc + single_port_stats[5]
+            except (TypeError, IndexError):
+                LOG.error("Invalid data ...")
+                return {}
+        else:
             return {}
 
         tsc = tsc / port_count