示例#1
0
    def to_table(self, with_zeroes=False):
        data = self._get_stats_values()
        sec_count = len(self.sections)

        # init table
        stats_table = text_tables.TRexTextTable('Traffic stats')
        stats_table.set_cols_align(["r"] * (1 + sec_count) + ["l"])
        stats_table.set_cols_width([self._max_desc_name_len] +
                                   [17] * sec_count +
                                   [self._max_desc_name_len])
        stats_table.set_cols_dtype(['t'] * (2 + sec_count))
        header = [''] + self.sections + ['']
        stats_table.header(header)

        for desc in self._desc:
            if desc['real']:
                vals = [data[section][desc['id']] for section in self.sections]
                if not (with_zeroes or desc['zero'] or any(vals)):
                    continue
                if desc['info'] == 'error':
                    vals = [red(v) if v else green(v) for v in vals]
                if desc['units']:
                    vals = [format_num(v, suffix=desc['units']) for v in vals]

                stats_table.add_row([desc['name']] + vals + [desc['help']])
            else:
                stats_table.add_row([desc['name']] + [''] * (1 + sec_count))

        return stats_table
示例#2
0
    def to_table(self,
                 with_zeroes=False,
                 tgid=0,
                 pid_input=DEFAULT_PROFILE_ID,
                 is_sum=False):
        self._get_tg_names(pid_input)
        num_of_tgids = len(self.tg_names_dict[pid_input]['tg_names'])
        title = ""
        data = {}
        if tgid == 0:
            data = self._get_stats_values(pid_input=pid_input, is_sum=is_sum)
            if is_sum:
                title = 'Traffic stats summary.'
            else:
                title = 'Traffic stats of Profile ID : ' + pid_input + '. Number of template groups = ' + str(
                    num_of_tgids)
        else:
            if not 1 <= tgid <= num_of_tgids:
                raise ASTFErrorBadTG('Invalid tgid in to_table')
            else:
                name = self.tg_names_dict[pid_input]['tg_names'][tgid - 1]
                title = 'Profile ID : ' + pid_input + '. Template Group Name: ' + name + '. Number of template groups = ' + str(
                    num_of_tgids)
                data = self.get_traffic_tg_stats(tg_names=name,
                                                 for_table=True,
                                                 pid_input=pid_input)
        sec_count = len(self.sections)

        # init table
        stats_table = text_tables.TRexTextTable(title)
        stats_table.set_cols_align(["r"] * (1 + sec_count) + ["l"])
        stats_table.set_cols_width([self._max_desc_name_len] +
                                   [17] * sec_count +
                                   [self._max_desc_name_len])
        stats_table.set_cols_dtype(['t'] * (2 + sec_count))
        header = [''] + self.sections + ['']
        stats_table.header(header)

        for desc in self._desc:
            if desc['real']:
                vals = [data[section][desc['id']] for section in self.sections]
                if not (with_zeroes or desc['zero'] or any(vals)):
                    continue
                if desc['info'] == 'error':
                    vals = [red(v) if v else green(v) for v in vals]
                if desc['units']:
                    vals = [format_num(v, suffix=desc['units']) for v in vals]

                stats_table.add_row([desc['name']] + vals + [desc['help']])
            else:
                stats_table.add_row([desc['name']] + [''] * (1 + sec_count))

        return stats_table
示例#3
0
    def to_table_main(self):
        data = self.get_stats()
        ports = sorted(data.keys())[:5]
        port_count = len(ports)
        rows = []

        def add_counter(name, *path):
            rows.append([name])
            for port_id in ports:
                sub = data[port_id]
                for key in path:
                    sub = sub[key]
                rows[-1].append(int(sub))

        def add_section(name):
            rows.append([name] + [''] * port_count)

        add_counter('TX pkts', 'stats', 'm_tx_pkt_ok')
        add_counter('RX pkts', 'stats', 'm_pkt_ok')
        add_counter('Max latency', 'hist', 'max_usec')
        add_counter('Avg latency', 'hist', 's_avg')
        add_section('-- Window --')

        for index in range(self.latency_window_size):
            if index == 0:
                rows.append(['Last max'])
            else:
                rows.append(['Last-%d' % index])
            if index < len(self.history_of_max):
                rows[-1] += [(val if val else '')
                             for val in self.history_of_max[index][:5]]
            else:
                rows[-1] += [''] * port_count

        add_section('---')
        add_counter('Jitter', 'stats', 'm_jitter')
        add_section('----')

        error_counters = [
            'm_unsup_prot', 'm_no_magic', 'm_no_id', 'm_seq_error',
            'm_length_error', 'm_no_ipv4_option', 'm_tx_pkt_err',
            'm_l3_cs_err', 'm_l4_cs_err'
        ]

        rows.append(['Errors'])
        for port_id in ports:
            errors = 0
            for error_counter in error_counters:
                errors += data[port_id]['stats'][error_counter]
            rows[-1].append(red(errors) if errors else green(errors))

        for row in rows:
            self.longest_key = max(self.longest_key, len(row[0]))

        # init table
        stats_table = text_tables.TRexTextTable('Latency Statistics')
        stats_table.set_cols_align(['l'] + ['r'] * port_count)
        stats_table.set_cols_width([self.longest_key] + [15] * port_count)
        stats_table.set_cols_dtype(['t'] * (1 + port_count))
        header = ['Port ID:'] + ports
        stats_table.header(header)

        self._fit_to_panel(rows)
        for row in rows:
            stats_table.add_row(row)

        return stats_table