Skip to content

Commit b616cd9

Browse files
authored
[TPID CONFIG] Added TPID configuration CLI support (#1618)
* [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
1 parent 01eb4b1 commit b616cd9

File tree

9 files changed

+535
-7
lines changed

9 files changed

+535
-7
lines changed

config/main.py

+39
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484

8585
PORT_MTU = "mtu"
8686
PORT_SPEED = "speed"
87+
PORT_TPID = "tpid"
88+
DEFAULT_TPID = "0x8100"
8789

8890
asic_type = None
8991

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

1588+
# Dont allow a port to be member of port channel if its TPID is not at default 0x8100
1589+
# If TPID is supported at LAG level, when member is added, the LAG's TPID is applied to the
1590+
# new member by SAI.
1591+
port_entry = db.get_entry('PORT', port_name)
1592+
if port_entry and port_entry.get(PORT_TPID) is not None:
1593+
port_tpid = port_entry.get(PORT_TPID)
1594+
if port_tpid != DEFAULT_TPID:
1595+
ctx.fail("Port TPID of {}: {} is not at default 0x8100".format(port_name, port_tpid))
1596+
15861597
db.set_entry('PORTCHANNEL_MEMBER', (portchannel_name, port_name),
15871598
{'NULL': 'NULL'})
15881599

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

3381+
#
3382+
# 'tpid' subcommand
3383+
#
3384+
3385+
@interface.command()
3386+
@click.pass_context
3387+
@click.argument('interface_name', metavar='<interface_name>', required=True)
3388+
@click.argument('interface_tpid', metavar='<interface_tpid>', required=True)
3389+
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
3390+
def tpid(ctx, interface_name, interface_tpid, verbose):
3391+
"""Set interface tpid"""
3392+
# Get the config_db connector
3393+
config_db = ctx.obj['config_db']
3394+
if clicommon.get_interface_naming_mode() == "alias":
3395+
interface_name = interface_alias_to_name(config_db, interface_name)
3396+
if interface_name is None:
3397+
ctx.fail("'interface_name' is None!")
3398+
3399+
if ctx.obj['namespace'] is DEFAULT_NAMESPACE:
3400+
command = "portconfig -p {} -tp {}".format(interface_name, interface_tpid)
3401+
else:
3402+
command = "portconfig -p {} -tp {} -n {}".format(interface_name, interface_tpid, ctx.obj['namespace'])
3403+
3404+
if verbose:
3405+
command += " -vv"
3406+
clicommon.run_command(command, display_cmd=verbose)
3407+
3408+
33703409
@interface.command()
33713410
@click.pass_context
33723411
@click.argument('interface_name', metavar='<interface_name>', required=True)

doc/Command-Reference.md

+60
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ The same syntax applies to all subgroups of `show` which themselves contain subc
406406
neighbor Show neighbor related information
407407
portchannel Show PortChannel information
408408
status Show Interface status information
409+
tpid Show Interface tpid information
409410
transceiver Show SFP Transceiver information
410411
```
411412

@@ -3076,6 +3077,7 @@ Subsequent pages explain each of these commands in detail.
30763077
neighbor Show neighbor related information
30773078
portchannel Show PortChannel information
30783079
status Show Interface status information
3080+
tpid Show Interface tpid information
30793081
transceiver Show SFP Transceiver information
30803082
```
30813083
@@ -3310,6 +3312,48 @@ This command displays the key fields of the interfaces such as Operational Statu
33103312
Ethernet4 down up hundredGigE1/2 T0-2:hundredGigE1/30
33113313
```
33123314
3315+
**show interfaces tpid**
3316+
3317+
This command displays the key fields of the interfaces such as Operational Status, Administrative Status, Alias and TPID.
3318+
3319+
- Usage:
3320+
```
3321+
show interfaces tpid [<interface_name>]
3322+
```
3323+
3324+
- Example:
3325+
```
3326+
admin@sonic:~$ show interfaces tpid
3327+
Interface Alias Oper Admin TPID
3328+
--------------- --------------- ------ ------- ------
3329+
Ethernet0 fortyGigE1/1/1 up up 0x8100
3330+
Ethernet1 fortyGigE1/1/2 up up 0x8100
3331+
Ethernet2 fortyGigE1/1/3 down down 0x8100
3332+
Ethernet3 fortyGigE1/1/4 down down 0x8100
3333+
Ethernet4 fortyGigE1/1/5 up up 0x8100
3334+
Ethernet5 fortyGigE1/1/6 up up 0x8100
3335+
Ethernet6 fortyGigE1/1/7 up up 0x9200
3336+
Ethernet7 fortyGigE1/1/8 up up 0x88A8
3337+
Ethernet8 fortyGigE1/1/9 up up 0x8100
3338+
...
3339+
Ethernet63 fortyGigE1/4/16 down down 0x8100
3340+
PortChannel0001 N/A up up 0x8100
3341+
PortChannel0002 N/A up up 0x8100
3342+
PortChannel0003 N/A up up 0x8100
3343+
PortChannel0004 N/A up up 0x8100
3344+
admin@sonic:~$
3345+
```
3346+
3347+
- Example (to only display the TPID for interface Ethernet6):
3348+
3349+
```
3350+
admin@sonic:~$ show interfaces tpid Ethernet6
3351+
Interface Alias Oper Admin TPID
3352+
----------- -------------- ------ ------- ------
3353+
Ethernet6 fortyGigE1/1/7 up up 0x9200
3354+
admin@sonic:~$
3355+
```
3356+
33133357
**show interfaces naming_mode**
33143358
33153359
Refer sub-section [Interface-Naming-Mode](#Interface-Naming-Mode)
@@ -3715,6 +3759,22 @@ This command is used to configure the mtu for the Physical interface. Use the va
37153759
admin@sonic:~$ sudo config interface mtu Ethernet64 1500
37163760
```
37173761
3762+
**config interface tpid <interface_name> (Versions >= 202106)**
3763+
3764+
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).
3765+
3766+
- Usage:
3767+
3768+
*Versions >= 202106*
3769+
```
3770+
config interface tpid <interface_name> <tpid_value>
3771+
```
3772+
3773+
- Example (Versions >= 202106):
3774+
```
3775+
admin@sonic:~$ sudo config interface tpid Ethernet64 0x9200
3776+
```
3777+
37183778
**config interface breakout**
37193779
37203780
This command is used to set breakout mode available for user-specified interface.

scripts/intfutil

+95-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ PORT_AUTONEG = 'autoneg'
4545
PORT_ADV_SPEEDS = 'adv_speeds'
4646
PORT_INTERFACE_TYPE = 'interface_type'
4747
PORT_ADV_INTERFACE_TYPES = 'adv_interface_types'
48+
PORT_TPID = "tpid"
4849

4950
VLAN_SUB_INTERFACE_SEPARATOR = "."
5051
VLAN_SUB_INTERFACE_TYPE = "802.1q-encapsulation"
@@ -298,6 +299,11 @@ def appl_db_portchannel_status_get(appl_db, config_db, po_name, status_type, por
298299
if status_type == "mtu":
299300
status = config_db.get(config_db.CONFIG_DB, po_table_id, status_type)
300301
return status
302+
if status_type == "tpid":
303+
status = config_db.get(config_db.CONFIG_DB, po_table_id, status_type)
304+
if status is None:
305+
return "0x8100"
306+
return status
301307
status = appl_db.get(appl_db.APPL_DB, full_table_id, status_type)
302308
#print(status)
303309
if status is None:
@@ -583,10 +589,95 @@ class IntfAutoNegStatus(object):
583589
self.table += self.generate_autoneg_status()
584590

585591

592+
# ========================== interface-tpid logic ==========================
593+
594+
header_tpid = ['Interface', 'Alias', 'Oper', 'Admin', 'TPID']
595+
596+
class IntfTpid(object):
597+
598+
def __init__(self, intf_name, namespace_option, display_option):
599+
"""
600+
Class constructor method
601+
:param self:
602+
:param intf_name: string of interface
603+
:return:
604+
"""
605+
self.db = None
606+
self.config_db = None
607+
self.intf_name = intf_name
608+
self.table = []
609+
self.multi_asic = multi_asic_util.MultiAsic(
610+
display_option, namespace_option)
611+
612+
if intf_name is not None and intf_name == SUB_PORT:
613+
self.intf_name = None
614+
615+
def display_intf_tpid(self):
616+
self.get_intf_tpid()
617+
618+
# Sorting and tabulating the result table.
619+
sorted_table = natsorted(self.table)
620+
print(tabulate(sorted_table, header_tpid, tablefmt="simple", stralign='right'))
621+
622+
def generate_intf_tpid(self):
623+
"""
624+
Generate interface-tpid output
625+
"""
626+
627+
i = {}
628+
table = []
629+
key = []
630+
631+
intf_fs = parse_interface_in_filter(self.intf_name)
632+
#
633+
# Iterate through all the keys and append port's associated state to
634+
# the result table.
635+
#
636+
for i in self.appl_db_keys:
637+
key = re.split(':', i, maxsplit=1)[-1].strip()
638+
if key in self.front_panel_ports_list:
639+
if self.multi_asic.skip_display(constants.PORT_OBJ, key):
640+
continue
641+
642+
if self.intf_name is None or key in intf_fs:
643+
table.append((key,
644+
appl_db_port_status_get(self.db, key, PORT_ALIAS),
645+
appl_db_port_status_get(self.db, key, PORT_OPER_STATUS),
646+
appl_db_port_status_get(self.db, key, PORT_ADMIN_STATUS),
647+
appl_db_port_status_get(self.db, key, PORT_TPID)))
648+
649+
for po, value in self.po_speed_dict.items():
650+
if po:
651+
if self.multi_asic.skip_display(constants.PORT_CHANNEL_OBJ, po):
652+
continue
653+
if self.intf_name is None or po in intf_fs:
654+
table.append((po,
655+
appl_db_portchannel_status_get(self.db, self.config_db, po, PORT_ALIAS, self.po_speed_dict),
656+
appl_db_portchannel_status_get(self.db, self.config_db, po, PORT_OPER_STATUS, self.po_speed_dict),
657+
appl_db_portchannel_status_get(self.db, self.config_db, po, PORT_ADMIN_STATUS, self.po_speed_dict),
658+
appl_db_portchannel_status_get(self.db, self.config_db, po, PORT_TPID, self.po_speed_dict)))
659+
return table
660+
661+
@multi_asic_util.run_on_multi_asic
662+
def get_intf_tpid(self):
663+
self.front_panel_ports_list = get_frontpanel_port_list(self.config_db)
664+
self.appl_db_keys = appl_db_keys_get(self.db, self.front_panel_ports_list, None)
665+
self.get_raw_po_int_configdb_info = get_raw_portchannel_info(self.config_db)
666+
self.portchannel_list = get_portchannel_list(self.get_raw_po_int_configdb_info)
667+
self.po_int_tuple_list = create_po_int_tuple_list(self.get_raw_po_int_configdb_info)
668+
self.po_int_dict = create_po_int_dict(self.po_int_tuple_list)
669+
self.int_po_dict = create_int_to_portchannel_dict(self.po_int_tuple_list)
670+
self.po_speed_dict = po_speed_dict(self.po_int_dict, self.db)
671+
self.portchannel_keys = self.po_speed_dict.keys()
672+
673+
if self.appl_db_keys:
674+
self.table += self.generate_intf_tpid()
675+
676+
586677
def main():
587678
parser = argparse.ArgumentParser(description='Display Interface information',
588679
formatter_class=argparse.RawTextHelpFormatter)
589-
parser.add_argument('-c', '--command', type=str, help='get interface status or description or auto negotiation status', default=None)
680+
parser.add_argument('-c', '--command', type=str, help='get interface status or description or auto negotiation status or tpid', default=None)
590681
parser.add_argument('-i', '--interface', type=str, help='interface information for specific port: Ethernet0', default=None)
591682
parser = multi_asic_util.multi_asic_args(parser)
592683
args = parser.parse_args()
@@ -600,6 +691,9 @@ def main():
600691
elif args.command == "autoneg":
601692
interface_autoneg_status = IntfAutoNegStatus(args.interface, args.namespace, args.display)
602693
interface_autoneg_status.display_autoneg_status()
694+
elif args.command == "tpid":
695+
interface_tpid = IntfTpid(args.interface, args.namespace, args.display)
696+
interface_tpid.display_intf_tpid()
603697

604698
sys.exit(0)
605699

0 commit comments

Comments
 (0)