From 9fc980b8aa43cf53446eeeb5184f10a86476da28 Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Thu, 7 Jan 2016 13:31:11 +0200 Subject: Working version of streams view in TRex console. TODO: sync when console crashes isn't integrated yet --- .../client/trex_stateless_client.py | 41 +++++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'scripts/automation/trex_control_plane/client/trex_stateless_client.py') diff --git a/scripts/automation/trex_control_plane/client/trex_stateless_client.py b/scripts/automation/trex_control_plane/client/trex_stateless_client.py index 58fa53c9..6139884d 100755 --- a/scripts/automation/trex_control_plane/client/trex_stateless_client.py +++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py @@ -61,7 +61,7 @@ class CTRexStatelessClient(object): self.global_stats = trex_stats.CGlobalStats(self._connection_info, self.server_version, self.ports) - self.stats_generator = trex_stats.CTRexStatsGenerator(self.global_stats, + self.stats_generator = trex_stats.CTRexInfoGenerator(self.global_stats, self.ports) self.events = [] @@ -538,14 +538,14 @@ class CTRexStatelessClient(object): - def add_stream_pack(self, stream_pack_list, port_id_list = None): + def add_stream_pack(self, stream_pack, port_id_list = None): port_id_list = self.__ports(port_id_list) rc = RC() for port_id in port_id_list: - rc.add(self.ports[port_id].add_streams(stream_pack_list)) + rc.add(self.ports[port_id].add_streams(stream_pack)) return rc @@ -821,7 +821,7 @@ class CTRexStatelessClient(object): return rc - rc = self.add_stream_pack(stream_list.compiled, port_id_list) + rc = self.add_stream_pack(stream_list, port_id_list) rc.annotate("Attaching {0} streams to port(s) {1}:".format(len(stream_list.compiled), port_id_list)) if rc.bad(): return rc @@ -861,6 +861,12 @@ class CTRexStatelessClient(object): stats_obj.update(self.stats_generator.generate_single_statistic(port_id_list, stats_type)) return stats_obj + def cmd_streams(self, port_id_list, streams_mask=set()): + + streams_obj = self.stats_generator.generate_streams_info(port_id_list, streams_mask) + + return streams_obj + ############## High Level API With Parser ################ @@ -916,7 +922,7 @@ class CTRexStatelessClient(object): else: # load streams from file - stream_list = None; + stream_list = None try: stream_list = self.streams_db.load_yaml_file(opts.file[0]) except Exception as e: @@ -1050,11 +1056,36 @@ class CTRexStatelessClient(object): for stat_type, stat_data in stats.iteritems(): text_tables.print_table_with_header(stat_data.text_table, stat_type) + return RC_OK() + + def cmd_streams_line(self, line): + '''Fetch streams statistics from TRex server by port\n''' + # define a parser + parser = parsing_opts.gen_parser(self, + "streams", + self.cmd_streams_line.__doc__, + parsing_opts.PORT_LIST_WITH_ALL, + parsing_opts.STREAMS_MASK, + parsing_opts.FULL_OUTPUT) + + opts = parser.parse_args(line.split()) + + if opts is None: + return RC_ERR("bad command line parameters") + + streams = self.cmd_streams(opts.ports, set(opts.streams)) + + # print stats to screen + for stream_hdr, port_streams_data in streams.iteritems(): + text_tables.print_table_with_header(port_streams_data.text_table, + header= stream_hdr.split(":")[0] + ":", + untouched_header= stream_hdr.split(":")[1]) return RC_OK() + @timing def cmd_validate_line (self, line): '''validates port(s) stream configuration\n''' -- cgit 1.2.3-korg