Skip to content

Commit

Permalink
[chassis][voq[Add "config fabric port ..." commands and tests. (#2730)
Browse files Browse the repository at this point in the history
Added "config fabric port ..." commands and the tests.

This change added following config commands and the test for them.

config fabric port isolate #portId#
config fabric port unisolate #portId#
The above two commands can be used to manually isolate and unisolate a fabric link.

config fabric port monitor error threshold #crcCells# #rxCells#
It sets a fabric link monitoring error threshold

config fabric port monitor poll threshold isolation #pollnumber#
It sets the number of consecutive polls in which the threshold needs to be detected to isolate a link

config fabric port monitor poll threshold recovery #pollnumber#
It sets the number of consecutive polls in which no error is detected to unisolate a link
  • Loading branch information
jfeng-arista authored and root committed Jun 21, 2023
1 parent bf48061 commit 29b26b9
Show file tree
Hide file tree
Showing 5 changed files with 432 additions and 0 deletions.
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})


2 changes: 2 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from . import chassis_modules
from . import console
from . import feature
from . import fabric
from . import flow_counters
from . import kdump
from . import kube
Expand Down Expand Up @@ -1110,6 +1111,7 @@ def config(ctx):
config.add_command(aaa.radius)
config.add_command(chassis_modules.chassis)
config.add_command(console.console)
config.add_command(fabric.fabric)
config.add_command(feature.feature)
config.add_command(flow_counters.flowcnt_route)
config.add_command(kdump.kdump)
Expand Down
67 changes: 67 additions & 0 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
* [ECN](#ecn)
* [ECN show commands](#ecn-show-commands)
* [ECN config commands](#ecn-config-commands)
* [Fabric](#fabric)
* [Fabric config commands](#fabric-config-commands)
* [Feature](#feature)
* [Feature show commands](#feature-show-commands)
* [Feature config commands](#feature-config-commands)
Expand Down Expand Up @@ -3067,6 +3069,71 @@ The list of the WRED profile fields that are configurable is listed in the below
Go Back To [Beginning of the document](#) or [Beginning of this section](#ecn)
## Fabric
This section explains all Fabric commands that are supported in SONiC.
### Fabric config commands
**config fabric port isolate <portId>**
**config fabric port unisolate <portId>**
The above two commands can be used to manually isolate and unisolate a fabric link.
- Usage:
```
config fabric port isolate [OPTIONS] <portid>
config fabric port unisolate [OPTIONS] <portid>
```
- Example:
```
admin@sonic:~$ config fabric port isolate 0 -n asic0
admin@sonic:~$ config fabric port unisolate 0 -n asic0
```
**config fabric port monitor error threshold <crcCells> <rxCells>**
This command sets a fabric link monitoring error threshold
- Usage:
```
config fabric port monitor error threshold [OPTIONS] <crcCells> <rxCells>
```
- Example:
```
admin@sonic:~$ config fabric port monitor error threshold 2 61035156 -n asic0
```
**config fabric port monitor poll threshold isolation <pollnumber>**
This command sets the number of consecutive polls in which the threshold needs to be detected to isolate a link
- Usage:
```
config fabric port monitor poll threshold isolation [OPTIONS] <pollCount>
```
- Example:
```
admin@sonic:~$ config fabric port monitor poll threshold isolation 2 -n asic0
```
**config fabric port monitor poll threshold recovery <pollnumber>**
This command sets the number of consecutive polls in which no error is detected to unisolate a link
- Usage:
```
config fabric port monitor poll threshold recovery [OPTIONS] <pollCount>
```
- Example:
```
admin@sonic:~$ config fabric port monitor poll threshold recovery 5 -n asic0
```
## Feature
SONiC includes a capability in which Feature state can be enabled/disabled
Expand Down
Loading

0 comments on commit 29b26b9

Please sign in to comment.