Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[portstat, intfstat] update rates and utilization #817

Closed
wants to merge 9 commits into from
30 changes: 29 additions & 1 deletion config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4518,7 +4518,35 @@ def ecn(profile, rmax, rmin, ymax, ymin, gmax, gmin, rdrop, ydrop, gdrop, verbos


#
# 'pfc' group ('config interface pfc ...')
# 'rate' group ('config rate ...')
#

@config.group()
def rate():
"""Set port rates configuration."""
pass


@rate.command()
@click.argument('interval', metavar='<interval>', type=click.IntRange(min=1, max=1000), required=True)
@click.argument('rates_type', type=click.Choice(['all', 'port', 'rif']), default='all')
def smoothing_interval(interval, rates_type):
"""Set rates smoothing interval """
counters_db = swsssdk.SonicV2Connector()
counters_db.connect('COUNTERS_DB')

alpha = 2.0/(interval + 1)

if rates_type in ['port', 'all']:
counters_db.set('COUNTERS_DB', 'RATES:PORT', 'PORT_SMOOTH_INTERVAL', interval)
counters_db.set('COUNTERS_DB', 'RATES:PORT', 'PORT_ALPHA', alpha)
if rates_type in ['rif', 'all']:
counters_db.set('COUNTERS_DB', 'RATES:RIF', 'RIF_SMOOTH_INTERVAL', interval)
counters_db.set('COUNTERS_DB', 'RATES:RIF', 'RIF_ALPHA', alpha)


#
# 'pfc' group ('config pfc ...')
#

@interface.group(cls=clicommon.AbbreviationGroup)
Expand Down
52 changes: 38 additions & 14 deletions scripts/intfstat
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ except KeyError:
from collections import namedtuple, OrderedDict
from natsort import natsorted
from tabulate import tabulate
from utilities_common.netstat import ns_diff, ns_brate, ns_prate, table_as_json, STATUS_NA
from utilities_common.netstat import ns_diff, ns_brate, ns_prate, table_as_json, STATUS_NA, format_brate, format_prate, format_util
from swsscommon.swsscommon import SonicV2Connector


NStats = namedtuple("NStats", "rx_b_ok, rx_p_ok, tx_b_ok, tx_p_ok,\
rx_b_err, rx_p_err, tx_b_err, tx_p_err,")
nstat_fields = ("rx_b_ok", "rx_p_ok", "tx_b_ok", "tx_p_ok",\
"rx_b_err", "rx_p_err", "tx_b_err", "tx_p_err")
NStats = namedtuple("NStats", nstat_fields)

header = ['IFACE', 'RX_OK', 'RX_BPS', 'RX_PPS', 'RX_ERR',
'TX_OK', 'TX_BPS', 'TX_PPS', 'TX_ERR']
Expand Down Expand Up @@ -76,7 +76,7 @@ class Intfstat(object):
"""
Get the counters from specific table.
"""
fields = [STATUS_NA] * (len(header) - 1)
fields = [STATUS_NA] * len(nstat_fields)
for pos, counter_name in enumerate(counter_names):
full_table_id = COUNTER_TABLE_PREFIX + table_id
counter_data = self.db.get(self.db.COUNTERS_DB, full_table_id, counter_name)
Expand Down Expand Up @@ -127,6 +127,24 @@ class Intfstat(object):
else:
return STATUS_NA

def get_intf_speed(self, port_name):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API is not called anywhere. Why is this API needed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also check why get_intf_state is needed. I don't see it called anywhere

"""
Get the Intf speed
"""
full_table_id = PORT_STATUS_TABLE_PREFIX + port_name
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PORT_STATUS_TABLE_PREFIX doesn't seem to be defined anywhere. Missing code?

admin_state = self.db.get(self.db.APPL_DB, full_table_id, PORT_ADMIN_STATUS_FIELD)
oper_state = self.db.get(self.db.APPL_DB, full_table_id, PORT_OPER_STATUS_FIELD)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PORT_OPER_STATUS_FIELD doesn't seem to be defined anywhere. Missing code?

if admin_state is None or oper_state is None:
return STATUS_NA
elif admin_state.upper() == PORT_STATUS_VALUE_DOWN:
return PORT_STATE_DISABLED
elif admin_state.upper() == PORT_STATUS_VALUE_UP and oper_state.upper() == PORT_STATUS_VALUE_UP:
return PORT_STATE_UP
elif admin_state.upper() == PORT_STATUS_VALUE_UP and oper_state.upper() == PORT_STATUS_VALUE_DOWN:
return PORT_STATE_DOWN
else:
Comment on lines +137 to +145
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check all the variables used there. They don't seem to be defined.

return STATUS_NA

def cnstat_print(self, cnstat_dict, use_json):
"""
Print the cnstat.
Expand Down Expand Up @@ -173,15 +191,21 @@ class Intfstat(object):
ns_prate(cntr.tx_p_ok, old_cntr.tx_p_ok, time_gap),
ns_diff(cntr.tx_p_err, old_cntr.tx_p_err)))
else:
table.append((key,
cntr.rx_p_ok,
STATUS_NA,
STATUS_NA,
cntr.rx_p_err,
cntr.tx_p_ok,
STATUS_NA,
STATUS_NA,
cntr.tx_p_err))
old_cntr = NStats._make([0] * len(nstat_fields))

rates = ratestat_dict.get(key, RateStats._make([STATUS_NA]*len(ratestat_fields)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think ratestat_dict is defined anywhere else in the file. Is there a missing piece of code?


table.append((key,
ns_diff(cntr.rx_p_ok, old_cntr.rx_p_ok),
format_brate(rates.rx_bps),
format_prate(rates.rx_pps),
format_util(rates.rx_bps, speed),
ns_diff(cntr.rx_p_err, old_cntr.rx_p_err),
ns_diff(cntr.tx_p_ok, old_cntr.tx_p_ok),
format_brate(rates.tx_bps),
format_prate(rates.tx_pps),
format_util(rates.tx_bps, speed),
ns_diff(cntr.tx_p_err, old_cntr.tx_p_err)))
if use_json:
print(table_as_json(table, header))
else:
Expand Down
Loading