Skip to content

Commit

Permalink
Merge branch 'master' into reclaim-buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenxs committed Sep 26, 2021
2 parents d66689e + 0d538d3 commit 499bbeb
Show file tree
Hide file tree
Showing 214 changed files with 93,912 additions and 4,526 deletions.
3 changes: 3 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ stages:
jobs:
- job:
displayName: "Python3"
variables:
DIFF_COVER_CHECK_THRESHOLD: 0
DIFF_COVER_ENABLE: 'true'
pool:
vmImage: ubuntu-20.04

Expand Down
30 changes: 28 additions & 2 deletions clear/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import os
import subprocess
import sys

import click
import utilities_common.cli as clicommon
import json

from utilities_common import util_base

from show.plugins.pbh import read_pbh_counters
from . import plugins


Expand Down Expand Up @@ -449,6 +450,31 @@ def translations():
cmd = "natclear -t"
run_command(cmd)

# 'pbh' group ("clear pbh ...")
@cli.group(cls=AliasedGroup)
def pbh():
""" Clear the PBH info """
pass

# 'statistics' subcommand ("clear pbh statistics")
@pbh.command()
@clicommon.pass_db
def statistics(db):
""" Clear PBH counters
clear counters -- write current counters to file in /tmp
"""

pbh_rules = db.cfgdb.get_table("PBH_RULE")
pbh_counters = read_pbh_counters(pbh_rules)

try:
with open('/tmp/.pbh_counters.txt', 'w') as fp:
json.dump(remap_keys(pbh_counters), fp)
except IOError as err:
pass

def remap_keys(dict):
return [{'key': k, 'value': v} for k, v in dict.items()]

# Load plugins and register them
helper = util_base.UtilHelper()
Expand Down
13 changes: 9 additions & 4 deletions config/chassis_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
# 'chassis_modules' group ('config chassis_modules ...')
#
@click.group(cls=clicommon.AliasedGroup)
def chassis_modules():
"""Configure chassis-modules options"""
def chassis():
"""Configure chassis commands group"""
pass

@chassis.group()
def modules():
"""Configure chassis modules"""
pass

#
# 'shutdown' subcommand ('config chassis_modules shutdown ...')
#
@chassis_modules.command('shutdown')
@modules.command('shutdown')
@clicommon.pass_db
@click.argument('chassis_module_name', metavar='<module_name>', required=True)
def shutdown_chassis_module(db, chassis_module_name):
Expand All @@ -34,7 +39,7 @@ def shutdown_chassis_module(db, chassis_module_name):
#
# 'startup' subcommand ('config chassis_modules startup ...')
#
@chassis_modules.command('startup')
@modules.command('startup')
@clicommon.pass_db
@click.argument('chassis_module_name', metavar='<module_name>', required=True)
def startup_chassis_module(db, chassis_module_name):
Expand Down
51 changes: 41 additions & 10 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,16 +686,21 @@ def _stop_services():
pass

click.echo("Stopping SONiC target ...")
clicommon.run_command("sudo systemctl stop sonic.target")
clicommon.run_command("sudo systemctl stop sonic.target --job-mode replace-irreversibly")


def _get_sonic_services():
out = clicommon.run_command("systemctl list-dependencies --plain sonic.target | sed '1d'", return_cmd=True)
return [unit.strip() for unit in out.splitlines()]
return (unit.strip() for unit in out.splitlines())


def _get_delayed_sonic_services():
out = clicommon.run_command("systemctl list-dependencies --plain sonic-delayed.target | sed '1d'", return_cmd=True)
return (unit.strip().rstrip('.timer') for unit in out.splitlines())


def _reset_failed_services():
for service in _get_sonic_services():
for service in itertools.chain(_get_sonic_services(), _get_delayed_sonic_services()):
clicommon.run_command("systemctl reset-failed {}".format(service))


Expand Down Expand Up @@ -981,7 +986,7 @@ def config(ctx):
config.add_command(aaa.aaa)
config.add_command(aaa.tacacs)
config.add_command(aaa.radius)
config.add_command(chassis_modules.chassis_modules)
config.add_command(chassis_modules.chassis)
config.add_command(console.console)
config.add_command(feature.feature)
config.add_command(kdump.kdump)
Expand Down Expand Up @@ -3781,8 +3786,7 @@ def update_pg(ctx, interface_name, pg_map, override_profile, add = True):
ctx.fail("Profile {} doesn't exist".format(override_profile))
if not 'xoff' in profile_dict.keys() and 'size' in profile_dict.keys():
ctx.fail("Profile {} doesn't exist or isn't a lossless profile".format(override_profile))
profile_full_name = "[BUFFER_PROFILE|{}]".format(override_profile)
config_db.set_entry("BUFFER_PG", (interface_name, pg_map), {"profile": profile_full_name})
config_db.set_entry("BUFFER_PG", (interface_name, pg_map), {"profile": override_profile})
else:
config_db.set_entry("BUFFER_PG", (interface_name, pg_map), {"profile": "NULL"})
adjust_pfc_enable(ctx, interface_name, pg_map, True)
Expand All @@ -3804,7 +3808,7 @@ def remove_pg_on_port(ctx, interface_name, pg_map):
if port == interface_name and (not pg_map or pg_map == existing_pg):
need_to_remove = False
referenced_profile = v.get('profile')
if referenced_profile and referenced_profile == '[BUFFER_PROFILE|ingress_lossy_profile]':
if referenced_profile and referenced_profile == 'ingress_lossy_profile':
if pg_map:
ctx.fail("Lossy PG {} can't be removed".format(pg_map))
else:
Expand Down Expand Up @@ -4958,7 +4962,7 @@ def update_profile(ctx, config_db, profile_name, xon, xoff, size, dynamic_th, po

if not pool:
pool = 'ingress_lossless_pool'
params['pool'] = '[BUFFER_POOL|' + pool + ']'
params['pool'] = pool
if not config_db.get_entry('BUFFER_POOL', pool):
ctx.fail("Pool {} doesn't exist".format(pool))

Expand Down Expand Up @@ -5031,12 +5035,11 @@ def remove_profile(db, profile):
config_db = db.cfgdb
ctx = click.get_current_context()

full_profile_name = '[BUFFER_PROFILE|{}]'.format(profile)
existing_pgs = config_db.get_table("BUFFER_PG")
for k, v in existing_pgs.items():
port, pg = k
referenced_profile = v.get('profile')
if referenced_profile and referenced_profile == full_profile_name:
if referenced_profile and referenced_profile == profile:
ctx.fail("Profile {} is referenced by {}|{} and can't be removed".format(profile, port, pg))

entry = config_db.get_entry("BUFFER_PROFILE", profile)
Expand Down Expand Up @@ -5810,6 +5813,34 @@ def disable_link_local(ctx):
set_ipv6_link_local_only_on_interface(config_db, table_dict, table_type, key, mode)


#
# '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)


# Load plugins and register them
helper = util_base.UtilHelper()
for plugin in helper.load_plugins(plugins):
Expand Down
Loading

0 comments on commit 499bbeb

Please sign in to comment.