NFVBENCH-28 Set result values for NDR/PDR if they cannot be found within the given...
[nfvbench.git] / nfvbench / traffic_client.py
index 319dc0b..4337ad3 100644 (file)
@@ -537,9 +537,9 @@ class TrafficClient(object):
                     retDict[port]['rx'][key] = int(stats[port]['rx'][key])
                 except ValueError:
                     retDict[port]['rx'][key] = 0
-            retDict[port]['rx']['avg_delay_usec'] = float(stats[port]['rx']['avg_delay_usec'])
-            retDict[port]['rx']['min_delay_usec'] = float(stats[port]['rx']['min_delay_usec'])
-            retDict[port]['rx']['max_delay_usec'] = float(stats[port]['rx']['max_delay_usec'])
+            retDict[port]['rx']['avg_delay_usec'] = int(stats[port]['rx']['avg_delay_usec'])
+            retDict[port]['rx']['min_delay_usec'] = int(stats[port]['rx']['min_delay_usec'])
+            retDict[port]['rx']['max_delay_usec'] = int(stats[port]['rx']['max_delay_usec'])
             retDict[port]['drop_rate_percent'] = self.__get_dropped_rate(retDict[port])
 
         ports = sorted(retDict.keys())
@@ -609,7 +609,8 @@ class TrafficClient(object):
                 indicating the rate to send on each interface
         right   the right side of the range to search as a % of line rate
                 indicating the rate to send on each interface
-        targets a dict of drop rates to search (0.1 = 0.1%), indexed by the DR name or "tag" ('ndr', 'pdr')
+        targets a dict of drop rates to search (0.1 = 0.1%), indexed by the DR name or "tag"
+                ('ndr', 'pdr')
         results a dict to store results
         '''
         if len(targets) == 0:
@@ -639,6 +640,21 @@ class TrafficClient(object):
                 })
                 right_targets[tag] = target
             else:
+                # initialize to 0 all fields of result for
+                # the worst case scenario of the binary search (if ndr/pdr is not found)
+                if tag not in results:
+                    results[tag] = dict.fromkeys(rates, 0)
+                    empty_stats = self.__format_output_stats(dict(stats))
+                    for key in empty_stats:
+                        if isinstance(empty_stats[key], dict):
+                            empty_stats[key] = dict.fromkeys(empty_stats[key], 0)
+                        else:
+                            empty_stats[key] = 0
+                    results[tag].update({
+                        'load_percent_per_direction': 0,
+                        'stats': empty_stats,
+                        'timestamp_sec': None
+                    })
                 left_targets[tag] = target
 
         # search lower half