Skip to content

Commit 8644b31

Browse files
committed
Switchport mode update for 'show interfaces status'
RCA: According to present design port was conisdered as "trunk" if its part of a VLAN, there was no handling to fetch the acutal mode from Redis DB regarding the configured switchport mode. Solution: Configured "switchport mode" is fetched from DB for all front panel ports and PortChannel interfaces. "Vlan" column in "show interface status" is displayed based on below considerations: 1. If interface is part of PortChannel - display PortChannel interface name [present behavior] 2. If "switchport mode" is configured on interface [Ethernet/PortChannel] - display configured mode [new behavior] 3. If "switchport mode" is NOT configured on interface but part of a VLAN [Ethernet/PortChannel] - display as "trunk" [present behavior]
1 parent d5051cd commit 8644b31

1 file changed

Lines changed: 59 additions & 27 deletions

File tree

scripts/intfutil

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -80,33 +80,40 @@ def get_sub_port_intf_list(config_db):
8080
return sub_intf_list
8181

8282

83-
def get_interface_vlan_dict(config_db):
83+
def get_interface_sw_mode_dict(config_db, front_panel_ports_list):
8484
"""
85-
Get info from REDIS ConfigDB and create interface to vlan mapping
85+
Get info from REDIS ConfigDB and create interface to swithport mode mapping
8686
"""
87-
get_int_vlan_configdb_info = config_db.get_table('VLAN_MEMBER')
88-
int_list = []
89-
vlan_list = []
90-
for line in get_int_vlan_configdb_info:
91-
vlan_number = line[0]
92-
interface = line[1]
93-
int_list.append(interface)
94-
vlan_list.append(vlan_number)
95-
int_to_vlan_dict = dict(zip(int_list, vlan_list))
96-
return int_to_vlan_dict
87+
vlan_member_table = config_db.get_table('VLAN_MEMBER')
9788

89+
vlan_member_keys = []
90+
for _, key in vlan_member_table:
91+
vlan_member_keys.append(key)
9892

99-
def config_db_vlan_port_keys_get(int_to_vlan_dict, front_panel_ports_list, intf_name):
93+
intf_to_sw_mode_dict = {}
94+
for intf_name in front_panel_ports_list:
95+
port = config_db.get_entry('PORT', intf_name)
96+
if "mode" in port:
97+
mode = port['mode']
98+
elif intf_name in vlan_member_keys:
99+
mode = 'trunk'
100+
else:
101+
mode = 'routed'
102+
intf_to_sw_mode_dict[intf_name] = mode
103+
104+
return intf_to_sw_mode_dict
105+
106+
107+
def config_db_vlan_port_keys_get(intf_to_sw_mode_dict, intf_to_po_dict, intf_name):
100108
"""
101109
Get interface vlan value and return it.
102110
"""
103-
vlan = "routed"
104-
if intf_name in front_panel_ports_list:
105-
if intf_name in int_to_vlan_dict.keys():
106-
vlan = int_to_vlan_dict[intf_name]
107-
if "Vlan" in vlan:
108-
vlan = "trunk"
109-
return vlan
111+
mode = "routed"
112+
if intf_name in intf_to_po_dict.keys():
113+
mode = intf_to_po_dict[intf_name]
114+
elif intf_name in intf_to_sw_mode_dict.keys():
115+
mode = intf_to_sw_mode_dict[intf_name]
116+
return mode
110117

111118

112119
def appl_db_keys_get(appl_db, front_panel_ports_list, intf_name):
@@ -307,6 +314,31 @@ def create_po_int_dict(po_int_tuple_list):
307314
po_int_dict = tuple_to_dict(po_int_tuple_list, temp_dict)
308315
return po_int_dict
309316

317+
def create_po_to_sw_mode_dict(config_db, po_int_tuple_list):
318+
"""
319+
This function takes the portchannel to interface tuple
320+
and converts that into an interface to portchannel dictionary
321+
with the portchannels as the key and the mode as the values.
322+
"""
323+
vlan_member_table = config_db.get_table('VLAN_MEMBER')
324+
325+
vlan_member_keys = []
326+
for _, key in vlan_member_table:
327+
vlan_member_keys.append(key)
328+
329+
po_to_sw_mode_dict = {}
330+
for po, intf in po_int_tuple_list:
331+
portchannel = config_db.get_entry('PORTCHANNEL', po)
332+
if "mode" in portchannel:
333+
mode = portchannel['mode']
334+
elif po in vlan_member_keys:
335+
mode = 'trunk'
336+
else:
337+
mode = 'routed'
338+
339+
po_to_sw_mode_dict[po] = mode
340+
return po_to_sw_mode_dict
341+
310342
def create_int_to_portchannel_dict(po_int_tuple_list):
311343
"""
312344
This function takes the portchannel to interface tuple
@@ -354,7 +386,7 @@ def po_speed_dict(po_int_dict, appl_db):
354386
po_speed_dict = {}
355387
return po_speed_dict
356388

357-
def appl_db_portchannel_status_get(appl_db, config_db, po_name, status_type, portchannel_speed_dict, combined_int_to_vlan_po_dict=None):
389+
def appl_db_portchannel_status_get(appl_db, config_db, po_name, status_type, portchannel_speed_dict, po_to_sw_mode_dict=None):
358390
"""
359391
Get the port status
360392
"""
@@ -367,8 +399,8 @@ def appl_db_portchannel_status_get(appl_db, config_db, po_name, status_type, por
367399
return "N/A"
368400
return status
369401
if status_type == "vlan":
370-
if combined_int_to_vlan_po_dict and po_name in combined_int_to_vlan_po_dict.keys():
371-
status = "trunk"
402+
if po_to_sw_mode_dict and po_name in po_to_sw_mode_dict.keys():
403+
status = po_to_sw_mode_dict[po_name]
372404
else:
373405
status = "routed"
374406
return status
@@ -484,7 +516,7 @@ class IntfStatus(object):
484516
appl_db_port_status_get(self.db, key, PORT_MTU_STATUS),
485517
appl_db_port_status_get(self.db, key, PORT_FEC),
486518
appl_db_port_status_get(self.db, key, PORT_ALIAS),
487-
config_db_vlan_port_keys_get(self.combined_int_to_vlan_po_dict, self.front_panel_ports_list, key),
519+
config_db_vlan_port_keys_get(self.intf_to_sw_mode_dict, self.int_po_dict, key),
488520
appl_db_port_status_get(self.db, key, PORT_OPER_STATUS),
489521
appl_db_port_status_get(self.db, key, PORT_ADMIN_STATUS),
490522
port_optics_get(self.db, key, PORT_OPTICS_TYPE),
@@ -501,7 +533,7 @@ class IntfStatus(object):
501533
appl_db_portchannel_status_get(self.db, self.config_db, po, PORT_MTU_STATUS, self.portchannel_speed_dict),
502534
appl_db_portchannel_status_get(self.db, self.config_db, po, PORT_FEC, self.portchannel_speed_dict),
503535
appl_db_portchannel_status_get(self.db, self.config_db, po, PORT_ALIAS, self.portchannel_speed_dict),
504-
appl_db_portchannel_status_get(self.db, self.config_db, po, "vlan", self.portchannel_speed_dict, self.combined_int_to_vlan_po_dict),
536+
appl_db_portchannel_status_get(self.db, self.config_db, po, "vlan", self.portchannel_speed_dict, self.po_to_sw_mode_dict),
505537
appl_db_portchannel_status_get(self.db, self.config_db, po, PORT_OPER_STATUS, self.portchannel_speed_dict),
506538
appl_db_portchannel_status_get(self.db, self.config_db, po, PORT_ADMIN_STATUS, self.portchannel_speed_dict),
507539
appl_db_portchannel_status_get(self.db, self.config_db, po, PORT_OPTICS_TYPE, self.portchannel_speed_dict),
@@ -523,13 +555,13 @@ class IntfStatus(object):
523555
def get_intf_status(self):
524556
self.front_panel_ports_list = get_frontpanel_port_list(self.config_db)
525557
self.appl_db_keys = appl_db_keys_get(self.db, self.front_panel_ports_list, None)
526-
self.int_to_vlan_dict = get_interface_vlan_dict(self.config_db)
558+
self.intf_to_sw_mode_dict = get_interface_sw_mode_dict(self.config_db, self.front_panel_ports_list)
527559
self.get_raw_po_int_configdb_info = get_raw_portchannel_info(self.config_db)
528560
self.portchannel_list = get_portchannel_list(self.get_raw_po_int_configdb_info)
529561
self.po_int_tuple_list = create_po_int_tuple_list(self.get_raw_po_int_configdb_info)
530562
self.po_int_dict = create_po_int_dict(self.po_int_tuple_list)
531563
self.int_po_dict = create_int_to_portchannel_dict(self.po_int_tuple_list)
532-
self.combined_int_to_vlan_po_dict = merge_dicts(self.int_to_vlan_dict, self.int_po_dict)
564+
self.po_to_sw_mode_dict = create_po_to_sw_mode_dict(self.config_db, self.po_int_tuple_list)
533565
self.portchannel_speed_dict = po_speed_dict(self.po_int_dict, self.db)
534566
self.portchannel_keys = self.portchannel_speed_dict.keys()
535567

0 commit comments

Comments
 (0)