@@ -45,6 +45,7 @@ PORT_AUTONEG = 'autoneg'
45
45
PORT_ADV_SPEEDS = 'adv_speeds'
46
46
PORT_INTERFACE_TYPE = 'interface_type'
47
47
PORT_ADV_INTERFACE_TYPES = 'adv_interface_types'
48
+ PORT_TPID = "tpid"
48
49
49
50
VLAN_SUB_INTERFACE_SEPARATOR = "."
50
51
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
298
299
if status_type == "mtu" :
299
300
status = config_db .get (config_db .CONFIG_DB , po_table_id , status_type )
300
301
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
301
307
status = appl_db .get (appl_db .APPL_DB , full_table_id , status_type )
302
308
#print(status)
303
309
if status is None :
@@ -583,10 +589,95 @@ class IntfAutoNegStatus(object):
583
589
self .table += self .generate_autoneg_status ()
584
590
585
591
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
+
586
677
def main ():
587
678
parser = argparse .ArgumentParser (description = 'Display Interface information' ,
588
679
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 )
590
681
parser .add_argument ('-i' , '--interface' , type = str , help = 'interface information for specific port: Ethernet0' , default = None )
591
682
parser = multi_asic_util .multi_asic_args (parser )
592
683
args = parser .parse_args ()
@@ -600,6 +691,9 @@ def main():
600
691
elif args .command == "autoneg" :
601
692
interface_autoneg_status = IntfAutoNegStatus (args .interface , args .namespace , args .display )
602
693
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 ()
603
697
604
698
sys .exit (0 )
605
699
0 commit comments