@@ -161,35 +161,14 @@ int main(int argc, char **argv)
161161
162162 initSaiApi ();
163163
164- SWSS_LOG_NOTICE (" sai_switch_api: create a switch" );
165-
166- vector<sai_attribute_t > switch_attrs;
167-
168- sai_attribute_t switch_attr;
169- switch_attr.id = SAI_SWITCH_ATTR_INIT_SWITCH;
170- switch_attr.value .booldata = true ;
171- switch_attrs.push_back (switch_attr);
172-
173- switch_attr.id = SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY;
174- switch_attr.value .ptr = (void *)on_fdb_event;
175- switch_attrs.push_back (switch_attr);
176-
177- switch_attr.id = SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY;
178- switch_attr.value .ptr = (void *)on_port_state_change;
179- switch_attrs.push_back (switch_attr);
180-
181- switch_attr.id = SAI_SWITCH_ATTR_SHUTDOWN_REQUEST_NOTIFY;
182- switch_attr.value .ptr = (void *)on_switch_shutdown_request;
183- switch_attrs.push_back (switch_attr);
184-
185- sai_attribute_t attr;
186-
187164 /*
188165 * NOTE: Notice that all redis attributes here are using SAI_NULL_OBJECT_ID
189166 * as switch id, because thsoe operations don't require actual switch to be
190167 * performed, and they should be executed before creating switch.
191168 */
192169
170+ sai_attribute_t attr;
171+
193172 /* Disable/enable SAI Redis recording */
194173 if (gSairedisRecord )
195174 {
@@ -227,61 +206,76 @@ int main(int argc, char **argv)
227206 }
228207 }
229208
230- SWSS_LOG_NOTICE (" Notify syncd INIT_VIEW" );
231-
232209 attr.id = SAI_REDIS_SWITCH_ATTR_NOTIFY_SYNCD;
233210 attr.value .s32 = SAI_REDIS_NOTIFY_SYNCD_INIT_VIEW;
234211 status = sai_switch_api->set_switch_attribute (gSwitchId , &attr);
235212
236213 if (status != SAI_STATUS_SUCCESS)
237214 {
238- SWSS_LOG_ERROR (" Failed to notify syncd INIT_VIEW %d" , status);
215+ SWSS_LOG_ERROR (" Failed to notify syncd INIT_VIEW, rv: %d" , status);
239216 exit (EXIT_FAILURE);
240217 }
241-
242- SWSS_LOG_NOTICE (" Enable redis pipeline" );
218+ SWSS_LOG_NOTICE (" Notify syncd INIT_VIEW" );
243219
244220 attr.id = SAI_REDIS_SWITCH_ATTR_USE_PIPELINE;
245221 attr.value .booldata = true ;
246222
247223 status = sai_switch_api->set_switch_attribute (gSwitchId , &attr);
248224 if (status != SAI_STATUS_SUCCESS)
249225 {
250- SWSS_LOG_ERROR (" Failed to enable redis pipeline %d" , status);
226+ SWSS_LOG_ERROR (" Failed to enable redis pipeline, rv: %d" , status);
251227 exit (EXIT_FAILURE);
252228 }
229+ SWSS_LOG_NOTICE (" Enable redis pipeline" );
230+
231+ vector<sai_attribute_t > attrs;
232+
233+ attr.id = SAI_SWITCH_ATTR_INIT_SWITCH;
234+ attr.value .booldata = true ;
235+ attrs.push_back (attr);
236+
237+ attr.id = SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY;
238+ attr.value .ptr = (void *)on_fdb_event;
239+ attrs.push_back (attr);
240+
241+ attr.id = SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY;
242+ attr.value .ptr = (void *)on_port_state_change;
243+ attrs.push_back (attr);
244+
245+ attr.id = SAI_SWITCH_ATTR_SHUTDOWN_REQUEST_NOTIFY;
246+ attr.value .ptr = (void *)on_switch_shutdown_request;
247+ attrs.push_back (attr);
248+
249+ if (gMacAddress )
250+ {
251+ attr.id = SAI_SWITCH_ATTR_SRC_MAC_ADDRESS;
252+ memcpy (attr.value .mac , gMacAddress .getMac (), 6 );
253+ attrs.push_back (attr);
254+ }
253255
254- status = sai_switch_api->create_switch (&gSwitchId , switch_attrs .size (), switch_attrs .data ());
256+ status = sai_switch_api->create_switch (&gSwitchId , attrs .size (), attrs .data ());
255257 if (status != SAI_STATUS_SUCCESS)
256258 {
257- SWSS_LOG_ERROR (" Failed to create a switch %d" , status);
259+ SWSS_LOG_ERROR (" Failed to create a switch, rv: %d" , status);
258260 exit (EXIT_FAILURE);
259261 }
262+ SWSS_LOG_NOTICE (" Create a switch" );
260263
261- attr. id = SAI_SWITCH_ATTR_SRC_MAC_ADDRESS;
264+ /* Get switch source MAC address if not provided */
262265 if (!gMacAddress )
263266 {
267+ attr.id = SAI_SWITCH_ATTR_SRC_MAC_ADDRESS;
264268 status = sai_switch_api->get_switch_attribute (gSwitchId , 1 , &attr);
265269 if (status != SAI_STATUS_SUCCESS)
266270 {
267- SWSS_LOG_ERROR (" Failed to get MAC address from switch %d" , status);
271+ SWSS_LOG_ERROR (" Failed to get MAC address from switch, rv: %d" , status);
268272 exit (EXIT_FAILURE);
269273 }
270274 else
271275 {
272276 gMacAddress = attr.value .mac ;
273277 }
274278 }
275- else
276- {
277- memcpy (attr.value .mac , gMacAddress .getMac (), 6 );
278- status = sai_switch_api->set_switch_attribute (gSwitchId , &attr);
279- if (status != SAI_STATUS_SUCCESS)
280- {
281- SWSS_LOG_ERROR (" Failed to set MAC address to switch %d" , status);
282- exit (EXIT_FAILURE);
283- }
284- }
285279
286280 /* Get the default virtual router ID */
287281 attr.id = SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID;
0 commit comments