From 2b5c0e9fc7482584d2259a7f79496ea86bcf4b5a Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Tue, 6 Oct 2015 14:43:39 +0300 Subject: progress in stateless client, added trex_stats --- .../trex_control_plane/common/trex_stats.py | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 scripts/automation/trex_control_plane/common/trex_stats.py (limited to 'scripts/automation/trex_control_plane/common/trex_stats.py') 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..62c3a890 --- /dev/null +++ b/scripts/automation/trex_control_plane/common/trex_stats.py @@ -0,0 +1,45 @@ +#!/router/bin/python +import copy + +class CTRexStatsManager(object): + + def __init__(self): + self._stats = {} + pass + + def update(self, obj_id, stats_obj): + assert isinstance(stats_obj, CTRexStats) + self._stats[obj_id] = stats_obj + + def get_stats(self, obj_id): + return copy.copy(self._stats.pop(obj_id)) + + + + +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 -- cgit From bafc3ec4b2686cdec4ac1c33f69f7607f368d4ce Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Wed, 7 Oct 2015 12:02:13 +0300 Subject: updated stats handling implementation --- .../trex_control_plane/common/trex_stats.py | 38 +++++++++++++++------- 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'scripts/automation/trex_control_plane/common/trex_stats.py') diff --git a/scripts/automation/trex_control_plane/common/trex_stats.py b/scripts/automation/trex_control_plane/common/trex_stats.py index 62c3a890..33015f01 100755 --- a/scripts/automation/trex_control_plane/common/trex_stats.py +++ b/scripts/automation/trex_control_plane/common/trex_stats.py @@ -3,18 +3,32 @@ import copy class CTRexStatsManager(object): - def __init__(self): - self._stats = {} - pass - - def update(self, obj_id, stats_obj): - assert isinstance(stats_obj, CTRexStats) - self._stats[obj_id] = stats_obj - - def get_stats(self, obj_id): - return copy.copy(self._stats.pop(obj_id)) - - + 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): -- cgit From a9f60d36e81c25244dad8f4f4c985f1e8e368c7c Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Mon, 12 Oct 2015 00:27:49 +0300 Subject: Updated handlers of getter methods and stats (Global, port, stream). Also, set return values of RPC commands as namedtuples --- scripts/automation/trex_control_plane/common/trex_stats.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'scripts/automation/trex_control_plane/common/trex_stats.py') diff --git a/scripts/automation/trex_control_plane/common/trex_stats.py b/scripts/automation/trex_control_plane/common/trex_stats.py index 33015f01..b7e768c1 100755 --- a/scripts/automation/trex_control_plane/common/trex_stats.py +++ b/scripts/automation/trex_control_plane/common/trex_stats.py @@ -1,6 +1,7 @@ #!/router/bin/python import copy + class CTRexStatsManager(object): def __init__(self, *args): @@ -9,7 +10,7 @@ class CTRexStatsManager(object): setattr(self, stat_type, CTRexStatsManager.CSingleStatsHandler()) def __getitem__(self, item): - stats_obj = getattr(self,item) + stats_obj = getattr(self, item) if stats_obj: return stats_obj.get_stats() else: -- cgit