From 76d7d9f3db6549331b1c1762d67f0e7ffb5be4fd Mon Sep 17 00:00:00 2001 From: liting Date: Wed, 3 Aug 2016 23:28:50 -0400 Subject: Xena: Modify aggregate_stats one port no stats when bi-direction Xena exception when no stats collected on receive on one port during bi-directional traffic. Modify aggregate_stats in the XenaDriver.py, add judge whether the two port both has stats, if one port has no stats, the result use the port's value which has stats. JIRA: VSPERF-327 Change-Id: I18c349d609a2834907f0383dbfbebd5cd281f541 Signed-off-by: liting --- tools/pkt_gen/xena/XenaDriver.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/pkt_gen/xena/XenaDriver.py b/tools/pkt_gen/xena/XenaDriver.py index aa8443c9..d3862312 100644 --- a/tools/pkt_gen/xena/XenaDriver.py +++ b/tools/pkt_gen/xena/XenaDriver.py @@ -1001,8 +1001,20 @@ class XenaTXStats(object): mydict = statdict return mydict - def aggregate_stats(stat1, stat2): + """ + Judge whether stat1 and stat2 both have same key, if both have same key, + call the aggregate fuction, else use the stat1's value + """ + newstat = dict() + for keys in stat1.keys(): + if keys in stat2 and isinstance(stat1[keys], dict): + newstat[keys] = aggregate(stat1[keys], stat2[keys]) + else: + newstat[keys] = stat1[keys] + return newstat + +def aggregate(stat1, stat2): """ Recursive function to aggregate two sets of statistics. This is used when bi directional traffic is done and statistics need to be calculated based @@ -1014,7 +1026,7 @@ def aggregate_stats(stat1, stat2): newstat = dict() for (keys1, keys2) in zip(stat1.keys(), stat2.keys()): if isinstance(stat1[keys1], dict): - newstat[keys1] = aggregate_stats(stat1[keys1], stat2[keys2]) + newstat[keys1] = aggregate(stat1[keys1], stat2[keys2]) else: if not isinstance(stat1[keys1], int) and not isinstance( [keys1], float): -- cgit 1.2.3-korg