diff options
author | 2015-10-12 08:45:06 +0300 | |
---|---|---|
committer | 2015-10-12 08:45:06 +0300 | |
commit | fba9663980d600d9c54c90f5ebd4afc346a007db (patch) | |
tree | 2b83fedde188e442ebc8e54eac00e4d33decafe5 /scripts/automation/trex_control_plane/common/trex_stats.py | |
parent | ca479ac9bb1e4d1a5953e9d121ab39a29f7b8b8e (diff) | |
parent | e6bf849809c1ff84eb887973576611f2457774eb (diff) |
Merge branch 'dan_stateless' into dan_latest
Diffstat (limited to 'scripts/automation/trex_control_plane/common/trex_stats.py')
-rwxr-xr-x | scripts/automation/trex_control_plane/common/trex_stats.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/common/trex_stats.py b/scripts/automation/trex_control_plane/common/trex_stats.py new file mode 100755 index 00000000..b7e768c1 --- /dev/null +++ b/scripts/automation/trex_control_plane/common/trex_stats.py @@ -0,0 +1,60 @@ +#!/router/bin/python +import copy + + +class CTRexStatsManager(object): + + def __init__(self, *args): + for stat_type in args: + # register stat handler for each stats type + setattr(self, stat_type, CTRexStatsManager.CSingleStatsHandler()) + + def __getitem__(self, item): + stats_obj = getattr(self, item) + if stats_obj: + return stats_obj.get_stats() + else: + return None + + class CSingleStatsHandler(object): + + def __init__(self): + self._stats = {} + + def update(self, obj_id, stats_obj): + assert isinstance(stats_obj, CTRexStats) + self._stats[obj_id] = stats_obj + + def get_stats(self, obj_id=None): + if obj_id: + return copy.copy(self._stats.pop(obj_id)) + else: + return copy.copy(self._stats) + + +class CTRexStats(object): + def __init__(self, **kwargs): + for k, v in kwargs.items(): + setattr(self, k, v) + + +class CGlobalStats(CTRexStats): + def __init__(self, **kwargs): + super(CGlobalStats, self).__init__(kwargs) + pass + + +class CPortStats(CTRexStats): + def __init__(self, **kwargs): + super(CPortStats, self).__init__(kwargs) + pass + + +class CStreamStats(CTRexStats): + def __init__(self, **kwargs): + super(CStreamStats, self).__init__(kwargs) + pass + + +if __name__ == "__main__": + pass |