88class PortChangeEvent :
99 PORT_ADD = 0
1010 PORT_REMOVE = 1
11+ PORT_SET = 2
12+ PORT_DEL = 3
13+
1114 def __init__ (self , port_name , port_index , asic_id , event_type , port_dict = None ):
1215 # Logical port name, e.g. Ethernet0
1316 self .port_name = port_name
@@ -99,7 +102,7 @@ def subscribe_port_config_change():
99102 return sel , asic_context
100103
101104
102- def handle_port_config_change (sel , asic_context , stop_event , port_mapping , logger , port_change_event_handler , is_cmis = False ):
105+ def handle_port_config_change (sel , asic_context , stop_event , port_mapping , logger , port_change_event_handler ):
103106 """Select CONFIG_DB PORT table changes, once there is a port configuration add/remove, notify observers
104107 """
105108 if not stop_event .is_set ():
@@ -110,50 +113,65 @@ def handle_port_config_change(sel, asic_context, stop_event, port_mapping, logge
110113 logger .log_warning ('sel.select() did not return swsscommon.Select.OBJECT' )
111114 return
112115
113- read_port_config_change (asic_context , port_mapping , logger , port_change_event_handler , is_cmis )
116+ read_port_config_change (asic_context , port_mapping , logger , port_change_event_handler )
114117
115- def read_port_config_change (asic_context , port_mapping , logger , port_change_event_handler , is_cmis = False ):
118+ def read_port_config_change (asic_context , port_mapping , logger , port_change_event_handler ):
116119 for port_tbl in asic_context .keys ():
117120 while True :
118121 (key , op , fvp ) = port_tbl .pop ()
119122 if not key :
120123 break
124+ fvp = dict (fvp ) if fvp is not None else {}
121125 if op == swsscommon .SET_COMMAND :
122- fvp = dict (fvp )
123126 if 'index' not in fvp :
124127 continue
125128
126129 new_physical_index = int (fvp ['index' ])
127- if is_cmis :
128- fvp [ 'name' ] = key
129- port_change_event = PortChangeEvent ( key , new_physical_index , asic_context [ port_tbl ], PortChangeEvent . PORT_ADD , fvp )
130- port_change_event_handler ( port_change_event )
131- elif not port_mapping .is_logical_port (key ):
130+
131+ port_change_event = PortChangeEvent ( key , new_physical_index , asic_context [ port_tbl ], PortChangeEvent . PORT_SET , fvp )
132+ port_change_event_handler ( port_change_event )
133+
134+ if not port_mapping .is_logical_port (key ):
132135 # New logical port created
133- port_change_event = PortChangeEvent (key , new_physical_index , asic_context [port_tbl ], PortChangeEvent .PORT_ADD )
136+ port_change_event = PortChangeEvent (key , new_physical_index , asic_context [port_tbl ], PortChangeEvent .PORT_ADD , fvp )
134137 port_change_event_handler (port_change_event )
135138 else :
136139 current_physical_index = port_mapping .get_logical_to_physical (key )[0 ]
137140 if current_physical_index != new_physical_index :
138- port_change_event = PortChangeEvent (key ,
139- current_physical_index ,
140- asic_context [port_tbl ],
141- PortChangeEvent .PORT_REMOVE )
141+ port_change_event = PortChangeEvent (key ,
142+ current_physical_index ,
143+ asic_context [port_tbl ],
144+ PortChangeEvent .PORT_REMOVE ,
145+ fvp )
142146 port_change_event_handler (port_change_event )
143147
144- port_change_event = PortChangeEvent (key , new_physical_index , asic_context [port_tbl ], PortChangeEvent .PORT_ADD )
148+ port_change_event = PortChangeEvent (key , new_physical_index , asic_context [port_tbl ], PortChangeEvent .PORT_ADD , fvp )
145149 port_change_event_handler (port_change_event )
146150 elif op == swsscommon .DEL_COMMAND :
151+ if 'index' in fvp :
152+ physical_index = int (fvp ['index' ])
153+ elif port_mapping .is_logical_port (key ):
154+ physical_index = port_mapping .get_logical_to_physical (key )[0 ]
155+ else :
156+ physical_index = 0
157+
158+ port_change_event = PortChangeEvent (key ,
159+ physical_index ,
160+ asic_context [port_tbl ],
161+ PortChangeEvent .PORT_DEL ,
162+ fvp )
163+ port_change_event_handler (port_change_event )
164+
147165 if port_mapping .is_logical_port (key ):
148- port_change_event = PortChangeEvent (key ,
149- port_mapping .get_logical_to_physical (key )[0 ],
150- asic_context [port_tbl ],
151- PortChangeEvent .PORT_REMOVE )
166+ port_change_event = PortChangeEvent (key ,
167+ physical_index ,
168+ asic_context [port_tbl ],
169+ PortChangeEvent .PORT_REMOVE ,
170+ fvp )
152171 port_change_event_handler (port_change_event )
153172 else :
154173 logger .log_warning ('Invalid DB operation: {}' .format (op ))
155174
156-
157175def get_port_mapping ():
158176 """Get port mapping from CONFIG_DB
159177 """
0 commit comments