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

[sonic-utilities] CLI support for port auto negotiation #1568

Merged
merged 22 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
79a7f8e
Add CLIs to support port auto negotiation
Junchao-Mellanox Jan 11, 2021
960ebeb
Adjust CLI for port auto negotiation
Junchao-Mellanox Jan 22, 2021
d328d87
Fix unit test issue
Junchao-Mellanox Feb 1, 2021
6deb7df
Fix unit test issues
Junchao-Mellanox Feb 22, 2021
408a166
Merge commit '42cab68' into port-auto-neg
Junchao-Mellanox Feb 22, 2021
3a6f711
Change autoneg value range from 0|1 to on|off
Junchao-Mellanox Mar 5, 2021
3bc1518
Merge commit '6ced42c' into port-auto-neg
Junchao-Mellanox Mar 12, 2021
e11e288
Fix unit test issue
Junchao-Mellanox Mar 15, 2021
5e2f34e
Fixes issue: db_migrator change cause db_migrator test case failure
Junchao-Mellanox Mar 15, 2021
b7369b8
Fix issues found in manual test
Junchao-Mellanox Mar 17, 2021
81f1da8
Fix issue: db migrator not working for port auto negotiation attributes
Junchao-Mellanox Mar 19, 2021
0f10f46
Add unit test for DB migrator
Junchao-Mellanox Mar 23, 2021
ce6dded
Merge branch 'master' into port-auto-neg
Junchao-Mellanox Mar 25, 2021
2892c4f
Merge commit '9a2872d' into port-auto-neg
Junchao-Mellanox Apr 2, 2021
4ecc4b8
Fix review comments
Junchao-Mellanox Apr 2, 2021
d19e369
Fix review comments
Junchao-Mellanox Apr 2, 2021
0399b08
Fix review comment
Junchao-Mellanox Apr 2, 2021
edc5f51
Merge commit '5976399' into port-auto-neg
Junchao-Mellanox Apr 16, 2021
87d9861
Merge branch 'master' into port-auto-neg
Junchao-Mellanox Apr 28, 2021
8eaf2e8
Merge branch 'master' into port-auto-neg
Junchao-Mellanox May 6, 2021
7c5273a
Update command reference
Junchao-Mellanox May 7, 2021
4adca3e
Merge branch 'port-auto-neg' of github.com:Junchao-Mellanox/sonic-uti…
Junchao-Mellanox May 7, 2021
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
120 changes: 120 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3014,6 +3014,126 @@ def speed(ctx, interface_name, interface_speed, verbose):
command += " -vv"
clicommon.run_command(command, display_cmd=verbose)

#
# 'autoneg' subcommand
#

@interface.command()
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('mode', metavar='<mode>', required=True, type=click.Choice(["enabled", "disabled"]))
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def autoneg(ctx, interface_name, mode, verbose):
"""Set interface auto negotiation mode"""
# Get the config_db connector
config_db = ctx.obj['config_db']

if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")

log.log_info("'interface autoneg {} {}' executing...".format(interface_name, mode))

if ctx.obj['namespace'] is DEFAULT_NAMESPACE:
command = "portconfig -p {} -an {}".format(interface_name, mode)
else:
command = "portconfig -p {} -an {} -n {}".format(interface_name, mode, ctx.obj['namespace'])

if verbose:
command += " -vv"
clicommon.run_command(command, display_cmd=verbose)

#
# 'adv-speeds' subcommand
#

@interface.command()
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('speed_list', metavar='<speed_list>', required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def advertised_speeds(ctx, interface_name, speed_list, verbose):
"""Set interface advertised speeds"""
# Get the config_db connector
config_db = ctx.obj['config_db']

if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")

log.log_info("'interface advertised_speeds {} {}' executing...".format(interface_name, speed_list))

if ctx.obj['namespace'] is DEFAULT_NAMESPACE:
command = "portconfig -p {} -S {}".format(interface_name, speed_list)
else:
command = "portconfig -p {} -S {} -n {}".format(interface_name, speed_list, ctx.obj['namespace'])

if verbose:
command += " -vv"
clicommon.run_command(command, display_cmd=verbose)

#
# 'interface-type' subcommand
#

@interface.command(name='type')
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('interface_type_value', metavar='<interface_type_value>', required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def interface_type(ctx, interface_name, interface_type_value, verbose):
"""Set interface type"""
# Get the config_db connector
config_db = ctx.obj['config_db']

if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")

log.log_info("'interface interface_type {} {}' executing...".format(interface_name, interface_type_value))

if ctx.obj['namespace'] is DEFAULT_NAMESPACE:
command = "portconfig -p {} -t {}".format(interface_name, interface_type_value)
else:
command = "portconfig -p {} -t {} -n {}".format(interface_name, interface_type_value, ctx.obj['namespace'])

if verbose:
command += " -vv"
clicommon.run_command(command, display_cmd=verbose)

#
# 'advertised-interface-types' subcommand
#

@interface.command()
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('interface_type_list', metavar='<interface_type_list>', required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def advertised_types(ctx, interface_name, interface_type_list, verbose):
"""Set interface advertised types"""
# Get the config_db connector
config_db = ctx.obj['config_db']

if clicommon.get_interface_naming_mode() == "alias":
interface_name = interface_alias_to_name(config_db, interface_name)
if interface_name is None:
ctx.fail("'interface_name' is None!")

log.log_info("'interface advertised_interface_types {} {}' executing...".format(interface_name, interface_type_list))

if ctx.obj['namespace'] is DEFAULT_NAMESPACE:
command = "portconfig -p {} -T {}".format(interface_name, interface_type_list)
else:
command = "portconfig -p {} -T {} -n {}".format(interface_name, interface_type_list, ctx.obj['namespace'])

if verbose:
command += " -vv"
clicommon.run_command(command, display_cmd=verbose)

#
# 'breakout' subcommand
#
Expand Down
127 changes: 127 additions & 0 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3064,6 +3064,7 @@ Subsequent pages explain each of these commands in detail.
-?, -h, --help Show this message and exit.

Commands:
autoneg Show interface autoneg information
breakout Show Breakout Mode information by interfaces
counters Show interface counters
description Show interface status, protocol and...
Expand All @@ -3074,6 +3075,30 @@ Subsequent pages explain each of these commands in detail.
transceiver Show SFP Transceiver information
```

**show interfaces autoneg**

This show command displays the port auto negotiation status for all interfaces i.e. interface name, auto negotiation mode, speed, advertised speeds, interface type, advertised interface types, operational status, admin status. For a single interface, provide the interface name with the sub-command.

- Usage:
```
show interfaces autoneg status
show interfaces autoneg status <interface_name>
```

- Example:
```
admin@sonic:~$ show interfaces autoneg status
Interface Auto-Neg Mode Speed Adv Speeds Type Adv Types Oper Admin
----------- --------------- ------- ------------ ------ ----------- ------ -------
Ethernet0 enabled 25G 10G,25G CR CR,CR4 up up
Ethernet4 disabled 100G all CR4 all up up

admin@sonic:~$ show interfaces autoneg status Ethernet8
Interface Auto-Neg Mode Speed Adv Speeds Type Adv Types Oper Admin
----------- --------------- ------- ------------ ------ ----------- ------ -------
Ethernet8 disabled 100G N/A CR4 N/A up up
```

**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.
Expand Down Expand Up @@ -3380,6 +3405,10 @@ This sub-section explains the following list of configuration on the interfaces.
4) speed - to set the interface speed
5) startup - to bring up the administratively shutdown interface
6) breakout - to set interface breakout mode
7) autoneg - to set interface auto negotiation mode
8) advertised-speeds - to set interface advertised speeds
9) advertised-types - to set interface advertised types
10) type - to set interface type

From 201904 release onwards, the “config interface” command syntax is changed and the format is as follows:

Expand Down Expand Up @@ -3714,6 +3743,104 @@ kindly use, double tab i.e. <tab><tab> to see the available breakout option cust

Go Back To [Beginning of the document](#) or [Beginning of this section](#interfaces)

**config interface autoneg <interface_name> (Versions >= 202106)**

This command is used to set port auto negotiation mode.

- Usage:
```
sudo config interface autoneg --help
Usage: config interface autoneg [OPTIONS] <interface_name> <mode>

Set interface auto negotiation mode

Options:
-v, --verbose Enable verbose output
-h, -?, --help Show this message and exit.
```

- Example:
```
admin@sonic:~$ sudo config interface autoneg Ethernet0 enabled

admin@sonic:~$ sudo config interface autoneg Ethernet0 disabled
```

Go Back To [Beginning of the document](#) or [Beginning of this section](#interfaces)

**config interface advertised-speeds <interface_name> (Versions >= 202106)**

This command is used to set port advertised speed.

- Usage:
```
sudo config interface advertised-speeds --help
Usage: config interface advertised-speeds [OPTIONS] <interface_name> <speed_list>

Set interface advertised speeds

Options:
-v, --verbose Enable verbose output
-h, -?, --help Show this message and exit.
```

- Example:
```
admin@sonic:~$ sudo config interface advertised-speeds Ethernet0 all

admin@sonic:~$ sudo config interface advertised-speeds Ethernet0 50000,100000
```

Go Back To [Beginning of the document](#) or [Beginning of this section](#interfaces)

**config interface advertised-types <interface_name> (Versions >= 202106)**

This command is used to set port advertised interface types.

- Usage:
```
sudo config interface advertised-types --help
Usage: config interface advertised-types [OPTIONS] <interface_name> <interface_type_list>

Set interface advertised types

Options:
-v, --verbose Enable verbose output
-h, -?, --help Show this message and exit.
```

- Example:
```
admin@sonic:~$ sudo config interface advertised-types Ethernet0 all

admin@sonic:~$ sudo config interface advertised-types Ethernet0 CR,CR4
```

Go Back To [Beginning of the document](#) or [Beginning of this section](#interfaces)

**config interface type <interface_name> (Versions >= 202106)**

This command is used to set port interface type.

- Usage:
```
sudo config interface type --help
Usage: config interface type [OPTIONS] <interface_name> <interface_type_value>

Set interface type

Options:
-v, --verbose Enable verbose output
-h, -?, --help Show this message and exit.
```

- Example:
```
admin@sonic:~$ sudo config interface type Ethernet0 CR4
```

Go Back To [Beginning of the document](#) or [Beginning of this section](#interfaces)

**config interface cable_length (Versions >= 202006)**

This command is used to configure the length of the cable connected to a port. The cable_length is in unit of meters and must be suffixed with "m".
Expand Down
22 changes: 21 additions & 1 deletion scripts/db_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,18 @@ def prepare_dynamic_buffer_for_warm_reboot(self, buffer_pools=None, buffer_profi

return True

def migrate_config_db_port_table_for_auto_neg(self):
table_name = 'PORT'
port_table = self.configDB.get_table(table_name)
for key, value in port_table.items():
if 'autoneg' in value:
if value['autoneg'] == '1':
self.configDB.set(self.configDB.CONFIG_DB, '{}|{}'.format(table_name, key), 'autoneg', 'on')
if 'speed' in value and 'adv_speeds' not in value:
self.configDB.set(self.configDB.CONFIG_DB, '{}|{}'.format(table_name, key), 'adv_speeds', value['speed'])
elif value['autoneg'] == '0':
self.configDB.set(self.configDB.CONFIG_DB, '{}|{}'.format(table_name, key), 'autoneg', 'off')

def version_unknown(self):
"""
version_unknown tracks all SONiC versions that doesn't have a version
Expand Down Expand Up @@ -470,10 +482,18 @@ def version_1_0_5(self):

def version_2_0_0(self):
"""
Current latest version. Nothing to do here.
Version 2_0_0.
"""
log.log_info('Handling version_2_0_0')
self.migrate_config_db_port_table_for_auto_neg()
self.set_version('version_2_0_1')
return 'version_2_0_1'

def version_2_0_1(self):
"""
Current latest version. Nothing to do here.
"""
log.log_info('Handling version_2_0_1')
return None

def get_version(self):
Expand Down
Loading