Skip to content

Commit

Permalink
[TPID CONFIG] Added TPID configuration CLI support (sonic-net#1618)
Browse files Browse the repository at this point in the history
* [TPID CONFIG] Added TPID configuration CLI support

Signed-off-by: Gen-Hwa Chiang <gechiang@microsoft.com>

* Added command-reference update for the new config TPID and show TPID related commands

* Fixed Reference-command spacing issue that caused the show interfaces tpid output incorrectly
  • Loading branch information
gechiang authored May 26, 2021
1 parent 01eb4b1 commit b616cd9
Show file tree
Hide file tree
Showing 9 changed files with 535 additions and 7 deletions.
39 changes: 39 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@

PORT_MTU = "mtu"
PORT_SPEED = "speed"
PORT_TPID = "tpid"
DEFAULT_TPID = "0x8100"

asic_type = None

Expand Down Expand Up @@ -1583,6 +1585,15 @@ def add_portchannel_member(ctx, portchannel_name, port_name):
ctx.fail("Port MTU of {} is different than the {} MTU size"
.format(port_name, portchannel_name))

# Dont allow a port to be member of port channel if its TPID is not at default 0x8100
# If TPID is supported at LAG level, when member is added, the LAG's TPID is applied to the
# new member by SAI.
port_entry = db.get_entry('PORT', port_name)
if port_entry and port_entry.get(PORT_TPID) is not None:
port_tpid = port_entry.get(PORT_TPID)
if port_tpid != DEFAULT_TPID:
ctx.fail("Port TPID of {}: {} is not at default 0x8100".format(port_name, port_tpid))

db.set_entry('PORTCHANNEL_MEMBER', (portchannel_name, port_name),
{'NULL': 'NULL'})

Expand Down Expand Up @@ -3367,6 +3378,34 @@ def mtu(ctx, interface_name, interface_mtu, verbose):
command += " -vv"
clicommon.run_command(command, display_cmd=verbose)

#
# 'tpid' subcommand
#

@interface.command()
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
@click.argument('interface_tpid', metavar='<interface_tpid>', required=True)
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def tpid(ctx, interface_name, interface_tpid, verbose):
"""Set interface tpid"""
# 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!")

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

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


@interface.command()
@click.pass_context
@click.argument('interface_name', metavar='<interface_name>', required=True)
Expand Down
60 changes: 60 additions & 0 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ The same syntax applies to all subgroups of `show` which themselves contain subc
neighbor Show neighbor related information
portchannel Show PortChannel information
status Show Interface status information
tpid Show Interface tpid information
transceiver Show SFP Transceiver information
```

Expand Down Expand Up @@ -3076,6 +3077,7 @@ Subsequent pages explain each of these commands in detail.
neighbor Show neighbor related information
portchannel Show PortChannel information
status Show Interface status information
tpid Show Interface tpid information
transceiver Show SFP Transceiver information
```

Expand Down Expand Up @@ -3310,6 +3312,48 @@ This command displays the key fields of the interfaces such as Operational Statu
Ethernet4 down up hundredGigE1/2 T0-2:hundredGigE1/30
```

**show interfaces tpid**

This command displays the key fields of the interfaces such as Operational Status, Administrative Status, Alias and TPID.

- Usage:
```
show interfaces tpid [<interface_name>]
```

- Example:
```
admin@sonic:~$ show interfaces tpid
Interface Alias Oper Admin TPID
--------------- --------------- ------ ------- ------
Ethernet0 fortyGigE1/1/1 up up 0x8100
Ethernet1 fortyGigE1/1/2 up up 0x8100
Ethernet2 fortyGigE1/1/3 down down 0x8100
Ethernet3 fortyGigE1/1/4 down down 0x8100
Ethernet4 fortyGigE1/1/5 up up 0x8100
Ethernet5 fortyGigE1/1/6 up up 0x8100
Ethernet6 fortyGigE1/1/7 up up 0x9200
Ethernet7 fortyGigE1/1/8 up up 0x88A8
Ethernet8 fortyGigE1/1/9 up up 0x8100
...
Ethernet63 fortyGigE1/4/16 down down 0x8100
PortChannel0001 N/A up up 0x8100
PortChannel0002 N/A up up 0x8100
PortChannel0003 N/A up up 0x8100
PortChannel0004 N/A up up 0x8100
admin@sonic:~$
```

- Example (to only display the TPID for interface Ethernet6):

```
admin@sonic:~$ show interfaces tpid Ethernet6
Interface Alias Oper Admin TPID
----------- -------------- ------ ------- ------
Ethernet6 fortyGigE1/1/7 up up 0x9200
admin@sonic:~$
```

**show interfaces naming_mode**

Refer sub-section [Interface-Naming-Mode](#Interface-Naming-Mode)
Expand Down Expand Up @@ -3715,6 +3759,22 @@ This command is used to configure the mtu for the Physical interface. Use the va
admin@sonic:~$ sudo config interface mtu Ethernet64 1500
```

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

This command is used to configure the TPID for the Physical/PortChannel interface. default is 0x8100. Other allowed values if supported by HW SKU (0x9100, 0x9200, 0x88A8).

- Usage:

*Versions >= 202106*
```
config interface tpid <interface_name> <tpid_value>
```

- Example (Versions >= 202106):
```
admin@sonic:~$ sudo config interface tpid Ethernet64 0x9200
```

**config interface breakout**

This command is used to set breakout mode available for user-specified interface.
Expand Down
96 changes: 95 additions & 1 deletion scripts/intfutil
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ PORT_AUTONEG = 'autoneg'
PORT_ADV_SPEEDS = 'adv_speeds'
PORT_INTERFACE_TYPE = 'interface_type'
PORT_ADV_INTERFACE_TYPES = 'adv_interface_types'
PORT_TPID = "tpid"

VLAN_SUB_INTERFACE_SEPARATOR = "."
VLAN_SUB_INTERFACE_TYPE = "802.1q-encapsulation"
Expand Down Expand Up @@ -298,6 +299,11 @@ def appl_db_portchannel_status_get(appl_db, config_db, po_name, status_type, por
if status_type == "mtu":
status = config_db.get(config_db.CONFIG_DB, po_table_id, status_type)
return status
if status_type == "tpid":
status = config_db.get(config_db.CONFIG_DB, po_table_id, status_type)
if status is None:
return "0x8100"
return status
status = appl_db.get(appl_db.APPL_DB, full_table_id, status_type)
#print(status)
if status is None:
Expand Down Expand Up @@ -583,10 +589,95 @@ class IntfAutoNegStatus(object):
self.table += self.generate_autoneg_status()


# ========================== interface-tpid logic ==========================

header_tpid = ['Interface', 'Alias', 'Oper', 'Admin', 'TPID']

class IntfTpid(object):

def __init__(self, intf_name, namespace_option, display_option):
"""
Class constructor method
:param self:
:param intf_name: string of interface
:return:
"""
self.db = None
self.config_db = None
self.intf_name = intf_name
self.table = []
self.multi_asic = multi_asic_util.MultiAsic(
display_option, namespace_option)

if intf_name is not None and intf_name == SUB_PORT:
self.intf_name = None

def display_intf_tpid(self):
self.get_intf_tpid()

# Sorting and tabulating the result table.
sorted_table = natsorted(self.table)
print(tabulate(sorted_table, header_tpid, tablefmt="simple", stralign='right'))

def generate_intf_tpid(self):
"""
Generate interface-tpid output
"""

i = {}
table = []
key = []

intf_fs = parse_interface_in_filter(self.intf_name)
#
# Iterate through all the keys and append port's associated state to
# the result table.
#
for i in self.appl_db_keys:
key = re.split(':', i, maxsplit=1)[-1].strip()
if key in self.front_panel_ports_list:
if self.multi_asic.skip_display(constants.PORT_OBJ, key):
continue

if self.intf_name is None or key in intf_fs:
table.append((key,
appl_db_port_status_get(self.db, key, PORT_ALIAS),
appl_db_port_status_get(self.db, key, PORT_OPER_STATUS),
appl_db_port_status_get(self.db, key, PORT_ADMIN_STATUS),
appl_db_port_status_get(self.db, key, PORT_TPID)))

for po, value in self.po_speed_dict.items():
if po:
if self.multi_asic.skip_display(constants.PORT_CHANNEL_OBJ, po):
continue
if self.intf_name is None or po in intf_fs:
table.append((po,
appl_db_portchannel_status_get(self.db, self.config_db, po, PORT_ALIAS, self.po_speed_dict),
appl_db_portchannel_status_get(self.db, self.config_db, po, PORT_OPER_STATUS, self.po_speed_dict),
appl_db_portchannel_status_get(self.db, self.config_db, po, PORT_ADMIN_STATUS, self.po_speed_dict),
appl_db_portchannel_status_get(self.db, self.config_db, po, PORT_TPID, self.po_speed_dict)))
return table

@multi_asic_util.run_on_multi_asic
def get_intf_tpid(self):
self.front_panel_ports_list = get_frontpanel_port_list(self.config_db)
self.appl_db_keys = appl_db_keys_get(self.db, self.front_panel_ports_list, None)
self.get_raw_po_int_configdb_info = get_raw_portchannel_info(self.config_db)
self.portchannel_list = get_portchannel_list(self.get_raw_po_int_configdb_info)
self.po_int_tuple_list = create_po_int_tuple_list(self.get_raw_po_int_configdb_info)
self.po_int_dict = create_po_int_dict(self.po_int_tuple_list)
self.int_po_dict = create_int_to_portchannel_dict(self.po_int_tuple_list)
self.po_speed_dict = po_speed_dict(self.po_int_dict, self.db)
self.portchannel_keys = self.po_speed_dict.keys()

if self.appl_db_keys:
self.table += self.generate_intf_tpid()


def main():
parser = argparse.ArgumentParser(description='Display Interface information',
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('-c', '--command', type=str, help='get interface status or description or auto negotiation status', default=None)
parser.add_argument('-c', '--command', type=str, help='get interface status or description or auto negotiation status or tpid', default=None)
parser.add_argument('-i', '--interface', type=str, help='interface information for specific port: Ethernet0', default=None)
parser = multi_asic_util.multi_asic_args(parser)
args = parser.parse_args()
Expand All @@ -600,6 +691,9 @@ def main():
elif args.command == "autoneg":
interface_autoneg_status = IntfAutoNegStatus(args.interface, args.namespace, args.display)
interface_autoneg_status.display_autoneg_status()
elif args.command == "tpid":
interface_tpid = IntfTpid(args.interface, args.namespace, args.display)
interface_tpid.display_intf_tpid()

sys.exit(0)

Expand Down
Loading

0 comments on commit b616cd9

Please sign in to comment.