Skip to content

Commit

Permalink
Merge branch 'sonic-net:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
651477787 authored Jun 2, 2023
2 parents 1b8cb30 + b316fc2 commit fa063ba
Show file tree
Hide file tree
Showing 132 changed files with 6,801 additions and 2,026 deletions.
16 changes: 8 additions & 8 deletions clear/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,10 @@ def flowcnt_route(ctx, namespace):
"""Clear all route flow counters"""
exit_if_route_flow_counter_not_support()
if ctx.invoked_subcommand is None:
command = "flow_counters_stat -c -t route"
command = ['flow_counters_stat', '-c', '-t', 'route']
# None namespace means default namespace
if namespace is not None:
command += " -n {}".format(namespace)
command += ['-n', str(namespace)]
clicommon.run_command(command)


Expand All @@ -506,12 +506,12 @@ def flowcnt_route(ctx, namespace):
@click.argument('prefix-pattern', required=True)
def pattern(prefix_pattern, vrf, namespace):
"""Clear route flow counters by pattern"""
command = "flow_counters_stat -c -t route --prefix_pattern {}".format(prefix_pattern)
command = ['flow_counters_stat', '-c', '-t', 'route', '--prefix_pattern', str(prefix_pattern)]
if vrf:
command += ' --vrf {}'.format(vrf)
command += ['--vrf', str(vrf)]
# None namespace means default namespace
if namespace is not None:
command += " -n {}".format(namespace)
command += ['-n', str(namespace)]
clicommon.run_command(command)


Expand All @@ -522,12 +522,12 @@ def pattern(prefix_pattern, vrf, namespace):
@click.argument('prefix', required=True)
def route(prefix, vrf, namespace):
"""Clear route flow counters by prefix"""
command = "flow_counters_stat -c -t route --prefix {}".format(prefix)
command = ['flow_counters_stat', '-c', '-t', 'route', '--prefix', str(prefix)]
if vrf:
command += ' --vrf {}'.format(vrf)
command += ['--vrf', str(vrf)]
# None namespace means default namespace
if namespace is not None:
command += " -n {}".format(namespace)
command += ['-n', str(namespace)]
clicommon.run_command(command)


Expand Down
18 changes: 11 additions & 7 deletions config/config_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ def __init__(self, source="configDB", debug=False, allowTablesWithoutYang=True,
self.source = source
self.allowTablesWithoutYang = allowTablesWithoutYang
self.sonicYangOptions = sonicYangOptions
if configdb is None:
self.configdb = ConfigDBConnector()
self.configdb.connect()
else:
self.configdb = configdb
self.configdb = configdb

# logging vars
self.SYSLOG_IDENTIFIER = "ConfigMgmt"
Expand Down Expand Up @@ -201,7 +197,11 @@ def readConfigDB(self):
self.sysLog(doPrint=True, msg='Reading data from Redis configDb')
# Read from config DB on sonic switch
data = dict()
configdb = self.configdb
if self.configdb is None:
configdb = ConfigDBConnector()
configdb.connect()
else:
configdb = self.configdb
sonic_cfggen.deep_update(data, sonic_cfggen.FormatConverter.db_to_output(configdb.get_config()))
self.configdbJsonIn = sonic_cfggen.FormatConverter.to_serialized(data)
self.sysLog(syslog.LOG_DEBUG, 'Reading Input from ConfigDB {}'.\
Expand All @@ -221,7 +221,11 @@ def writeConfigDB(self, jDiff):
'''
self.sysLog(doPrint=True, msg='Writing in Config DB')
data = dict()
configdb = self.configdb
if self.configdb is None:
configdb = ConfigDBConnector()
configdb.connect(False)
else:
configdb = self.configdb
sonic_cfggen.deep_update(data, sonic_cfggen.FormatConverter.to_deserialized(jDiff))
self.sysLog(msg="Write in DB: {}".format(data))
configdb.mod_config(sonic_cfggen.FormatConverter.output_to_db(data))
Expand Down
247 changes: 247 additions & 0 deletions config/fabric.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
import click
import utilities_common.cli as clicommon
import utilities_common.multi_asic as multi_asic_util
from sonic_py_common import multi_asic
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector

#
# 'config fabric ...'
#
@click.group(cls=clicommon.AbbreviationGroup)
def fabric():
"""FABRIC-related configuration tasks"""
pass

#
# 'config fabric port ...'
#
@fabric.group(cls=clicommon.AbbreviationGroup)
def port():
"""FABRIC PORT configuration tasks"""
pass

#
# 'config fabric port isolate <portid> [ -n <asic> ]'
#
@port.command()
@click.argument('portid', metavar='<portid>', required=True)
@multi_asic_util.multi_asic_click_option_namespace
def isolate(portid, namespace):
"""FABRIC PORT isolate <portid>"""

ctx = click.get_current_context()

if not portid.isdigit():
ctx.fail("Invalid portid")

n_asics = multi_asic.get_num_asics()
if n_asics > 1 and namespace is None:
ctx.fail('Must specify asic')

# Connect to config database
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()

# Connect to state database
state_db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
state_db.connect(state_db.STATE_DB, False)

# check if the port is actually in use
portName = f'PORT{portid}'
portStateData = state_db.get_all(state_db.STATE_DB, "FABRIC_PORT_TABLE|" + portName)
if "REMOTE_PORT" not in portStateData:
ctx.fail(f"Port {portid} is not in use")

# Make sure configuration data exists
portName = f'Fabric{portid}'
portConfigData = config_db.get_all(config_db.CONFIG_DB, "FABRIC_PORT|" + portName)
if not bool(portConfigData):
ctx.fail("Fabric monitor configuration data not present")

# Update entry
config_db.mod_entry("FABRIC_PORT", portName, {'isolateStatus': True})

#
# 'config fabric port unisolate <portid> [ -n <asic> ]'
#
@port.command()
@click.argument('portid', metavar='<portid>', required=True)
@multi_asic_util.multi_asic_click_option_namespace
def unisolate(portid, namespace):
"""FABRIC PORT unisolate <portid>"""

ctx = click.get_current_context()

if not portid.isdigit():
ctx.fail("Invalid portid")

n_asics = multi_asic.get_num_asics()
if n_asics > 1 and namespace is None:
ctx.fail('Must specify asic')

# Connect to config database
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()

# Connect to state database
state_db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
state_db.connect(state_db.STATE_DB, False)

# check if the port is actually in use
portName = f'PORT{portid}'
portStateData = state_db.get_all(state_db.STATE_DB, "FABRIC_PORT_TABLE|" + portName)
if "REMOTE_PORT" not in portStateData:
ctx.fail(f"Port {portid} is not in use")

# Make sure configuration data exists
portName = f'Fabric{portid}'
portConfigData = config_db.get_all(config_db.CONFIG_DB, "FABRIC_PORT|" + portName)
if not bool(portConfigData):
ctx.fail("Fabric monitor configuration data not present")

# Update entry
config_db.mod_entry("FABRIC_PORT", portName, {'isolateStatus': False})

#
# 'config fabric port monitor ...'
#
@port.group(cls=clicommon.AbbreviationGroup)
def monitor():
"""FABRIC PORT MONITOR configuration tasks"""
pass

#
# 'config fabric port monitor error ...'
#
@monitor.group(cls=clicommon.AbbreviationGroup)
def error():
"""FABRIC PORT MONITOR ERROR configuration tasks"""
pass

#
# 'config fabric port monitor error threshold <crcCells> <rxCells>'
#
@error.command('threshold')
@click.argument('crcCells', metavar='<crcCells>', required=True, type=int)
@click.argument('rxcells', metavar='<rxCells>', required=True, type=int)
@multi_asic_util.multi_asic_click_option_namespace
def error_threshold(crccells, rxcells, namespace):
"""FABRIC PORT MONITOR ERROR THRESHOLD configuration tasks"""

ctx = click.get_current_context()

n_asics = multi_asic.get_num_asics()
if n_asics > 1 and namespace is None:
ctx.fail('Must specify asic')

# Check the values
if crccells < 1 or crccells > 1000:
ctx.fail("crcCells must be in range 1...1000")
if rxcells < 10000 or rxcells > 100000000:
ctx.fail("rxCells must be in range 10000...100000000")

# Connect to config database
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()

# Connect to state database
state_db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
state_db.connect(state_db.STATE_DB, False)

# Make sure configuration data exists
monitorData = config_db.get_all(config_db.CONFIG_DB, "FABRIC_MONITOR|FABRIC_MONITOR_DATA")
if not bool(monitorData):
ctx.fail("Fabric monitor configuration data not present")

# Update entry
config_db.mod_entry("FABRIC_MONITOR", "FABRIC_MONITOR_DATA",
{'monErrThreshCrcCells': crccells, 'monErrThreshRxCells': rxcells})

#
# 'config fabric port monitor poll ...'
#
@monitor.group(cls=clicommon.AbbreviationGroup)
def poll():
"""FABRIC PORT MONITOR POLL configuration tasks"""
pass

#
# 'config fabric port monitor poll threshold ...'
#
@poll.group(cls=clicommon.AbbreviationGroup, name='threshold')
def poll_threshold():
"""FABRIC PORT MONITOR POLL THRESHOLD configuration tasks"""
pass

#
# 'config fabric port monitor poll threshold isolation <pollCount>'
#
@poll_threshold.command()
@click.argument('pollcount', metavar='<pollCount>', required=True, type=int)
@multi_asic_util.multi_asic_click_option_namespace
def isolation(pollcount, namespace):
"""FABRIC PORT MONITOR POLL THRESHOLD configuration tasks"""

ctx = click.get_current_context()

n_asics = multi_asic.get_num_asics()
if n_asics > 1 and namespace is None:
ctx.fail('Must specify asic')

if pollcount < 1 or pollcount > 10:
ctx.fail("pollCount must be in range 1...10")

# Connect to config database
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()

# Connect to state database
state_db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
state_db.connect(state_db.STATE_DB, False)

# Make sure configuration data exists
monitorData = config_db.get_all(config_db.CONFIG_DB, "FABRIC_MONITOR|FABRIC_MONITOR_DATA")
if not bool(monitorData):
ctx.fail("Fabric monitor configuration data not present")

# Update entry
config_db.mod_entry("FABRIC_MONITOR", "FABRIC_MONITOR_DATA",
{"monPollThreshIsolation": pollcount})


#
# 'config fabric port monitor poll threshold recovery <pollCount>'
#
@poll_threshold.command()
@click.argument('pollcount', metavar='<pollCount>', required=True, type=int)
@multi_asic_util.multi_asic_click_option_namespace
def recovery(pollcount, namespace):
"""FABRIC PORT MONITOR POLL THRESHOLD configuration tasks"""

ctx = click.get_current_context()

n_asics = multi_asic.get_num_asics()
if n_asics > 1 and namespace is None:
ctx.fail('Must specify asic')

if pollcount < 1 or pollcount > 10:
ctx.fail("pollCount must be in range 1...10")

# Connect to config database
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()

# Connect to state database
state_db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
state_db.connect(state_db.STATE_DB, False)

# Make sure configuration data exists
monitorData = config_db.get_all(config_db.CONFIG_DB, "FABRIC_MONITOR|FABRIC_MONITOR_DATA")
if not bool(monitorData):
ctx.fail("Fabric monitor configuration data not present")

# Update entry
config_db.mod_entry("FABRIC_MONITOR", "FABRIC_MONITOR_DATA",
{"monPollThreshRecovery": pollcount})


Loading

0 comments on commit fa063ba

Please sign in to comment.