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

[Show | Command Reference] Add Port breakout Show Command #859

Merged
merged 5 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2205,6 +2205,7 @@ Subsequent pages explain each of these commands in detail.
-?, -h, --help Show this message and exit.

Commands:
breakout Show interface breakout
counters Show interface counters
description Show interface status, protocol and...
naming_mode Show interface naming_mode status
Expand All @@ -2214,6 +2215,54 @@ Subsequent pages explain each of these commands in detail.
transceiver Show SFP Transceiver information
```

**show interfaces breakout**

This show command displays the port capability for all interfaces i.e. index, lanes, default_brkout_mode, breakout_modes(i.e. all the available breakout modes) and brkout_mode (i.e. current breakout mode). To display current breakout mode, "current-mode" subcommand can be used.For a single interface, provide the interface name with the sub-command.

- Usage:
```
show interfaces breakout
show interfaces breakout cuurent-mode
show interfaces breakout cuurent-mode <interface_name>
```

- Example:
```
admin@lnos-x1-a-fab01:~$ show interfaces breakout
{
"Ethernet0": {
"index": "1,1,1,1",
"default_brkout_mode": "4x25G[10G]",
"lanes": "65,66,67,68",
"brkout_mode": "4x25G[10G]",
"breakout_modes": "1x100G[40G],2x50G,4x25G[10G]",
"alias_at_lanes": "Eth1/1, Eth1/2, Eth1/3, Eth1/4"
},... continue
}

The "current-mode" subcommand is used to display current breakout mode for all interfaces.

admin@lnos-x1-a-fab01:~$ show interfaces breakout current-mode
+-------------+-------------------------+
| Interface | Current Breakout Mode |
+=============+=========================+
| Ethernet0 | 4x25G[10G] |
+-------------+-------------------------+
| Ethernet4 | 4x25G[10G] |
+-------------+-------------------------+
| Ethernet8 | 4x25G[10G] |
+-------------+-------------------------+
| Ethernet12 | 4x25G[10G] |
+-------------+-------------------------+

admin@lnos-x1-a-fab01:~$ show interfaces breakout current-mode Ethernet0
+-------------+-------------------------+
| Interface | Current Breakout Mode |
+=============+=========================+
| Ethernet0 | 4x25G[10G] |
+-------------+-------------------------+
```

**show interfaces counters**

This show command displays packet counters for all interfaces since the last time the counters were cleared. To display l3 counters "rif" subcommand can be used. There is no facility to display counters for one specific l2 interface. For l3 interfaces a single interface output mode is present. Optional argument "-a" provides two additional columns - RX-PPS and TX_PPS.
Expand Down
112 changes: 112 additions & 0 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@
from swsssdk import SonicV2Connector

import mlnx
from collections import OrderedDict
samaity marked this conversation as resolved.
Show resolved Hide resolved
from portconfig import get_child_ports
samaity marked this conversation as resolved.
Show resolved Hide resolved

# Global Variable
PLATFORM_ROOT_PATH = "/usr/share/sonic/device"
PLATFORM_JSON = 'platform.json'
HWSKU_JSON = 'hwsku.json'
SONIC_CFGGEN_PATH = '/usr/local/bin/sonic-cfggen'
PORT_STR = "Ethernet"

VLAN_SUB_INTERFACE_SEPARATOR = '.'

Expand Down Expand Up @@ -189,6 +196,15 @@ def get_routing_stack():
# Global Routing-Stack variable
routing_stack = get_routing_stack()

# Read given JSON file
def readJsonFile(fileName):
try:
with open(fileName) as f:
result = json.load(f)
except Exception as e:
click.echo(str(e))
raise click.Abort()
return result

def run_command(command, display_cmd=False, return_cmd=False):
if display_cmd:
Expand Down Expand Up @@ -797,6 +813,102 @@ def alias(interfacename):

click.echo(tabulate(body, header))


#
# 'breakout' group ###
#
@interfaces.group(invoke_without_command=True)
@click.pass_context
def breakout(ctx):
"""Show interface breakout"""
samaity marked this conversation as resolved.
Show resolved Hide resolved

# Reading data from Redis configDb
config_db = ConfigDBConnector()
config_db.connect()
ctx.obj = {'db': config_db}

try:
curBrkout_tbl = config_db.get_table('BREAKOUT_CFG')
except Exception as e:
click.echo("Breakout table is not present in Config DB")
raise click.Abort()

if ctx.invoked_subcommand is None:

# Get HWSKU and Platform information
hw_info_dict = get_hw_info_dict()
platform = hw_info_dict['platform']
hwsku = hw_info_dict['hwsku']

# Get port capability from platform and hwsku related files
platformFile = "{}/{}/{}".format(PLATFORM_ROOT_PATH, platform, PLATFORM_JSON)
platformDict = readJsonFile(platformFile)['interfaces']
hwskuDict = readJsonFile("{}/{}/{}/{}".format(PLATFORM_ROOT_PATH, platform, hwsku, HWSKU_JSON))['interfaces']

if not platformDict or not hwskuDict:
click.echo("Can not load port config from {} or {} file".format(PLATFORM_JSON, HWSKU_JSON))
raise click.Abort()

for port_name in platformDict.keys():
curBrkout_mode = curBrkout_tbl[port_name]["brkout_mode"]

# Update deafult breakout mode and current breakout mode to platformDict
platformDict[port_name].update(hwskuDict[port_name])
platformDict[port_name]["Current Breakout Mode"] = curBrkout_mode

# List all the child ports if present
child_portDict = get_child_ports(port_name,curBrkout_mode, platformFile)
samaity marked this conversation as resolved.
Show resolved Hide resolved
if not child_portDict:
click.echo("Can not find ports from {} file ".format(PLATFORM_JSON))
samaity marked this conversation as resolved.
Show resolved Hide resolved
raise click.Abort()

child_ports = natsorted(child_portDict.keys())

children, speeds = [], []
# Update portname and speed of child ports if present
for port in child_ports:
speed = config_db.get_entry('PORT', port).get('speed')
if speed is not None:
speeds.append(str(int(speed)/1000)+'G')
children.append(port)

platformDict[port_name]["child ports"] = ",".join(children)
platformDict[port_name]["child port speeds"] = ",".join(speeds)

# Sorted keys by name in natural sort Order for human readability
parsed = OrderedDict((k, platformDict[k]) for k in natsorted(platformDict.keys()))
click.echo(json.dumps(parsed, indent=4))

# 'breakout current-mode' subcommand ("show interfaces breakout current-mode")
@breakout.command('current-mode')
@click.argument('interface', metavar='<interface_name>', required=False, type=str)
@click.pass_context
def currrent_mode(ctx, interface):
"""Show interface breakout current-mode"""

config_db = ctx.obj['db']

header = ['Interface', 'Current Breakout Mode']
body = []

try:
curBrkout_tbl = config_db.get_table('BREAKOUT_CFG')
except Exception as e:
click.echo("Breakout table is not present in Config DB")
raise click.Abort()

# Show current Breakout Mode of user prompted interface
if interface is not None:
body.append([interface, str(curBrkout_tbl[interface]['brkout_mode'])])
click.echo(tabulate(body, header, tablefmt="grid"))
return

# Show current Breakout Mode for all interfaces
for name in natsorted(curBrkout_tbl.keys()):
body.append([name, str(curBrkout_tbl[name]['brkout_mode'])])
click.echo(tabulate(body, header, tablefmt="grid"))


#
# 'neighbor' group ###
#
Expand Down