Skip to content

Commit dd37cca

Browse files
[syncd]: run switch->remove_switch() before exiting from syncd (sonic-net#305)
* Add remove_switch to syncd
1 parent 8c3e55c commit dd37cca

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

syncd/syncd.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#include "swss/tokenize.h"
66
#include <limits.h>
77

8+
extern "C" {
9+
#include <sai.h>
10+
}
11+
812
#include <iostream>
913
#include <map>
1014

@@ -65,12 +69,10 @@ std::set<sai_object_id_t> initViewRemovedVidSet;
6569
*/
6670
volatile bool g_asicInitViewMode = false;
6771

68-
#ifdef SAITHRIFT
6972
/*
70-
* SAI switch global needed for RPC server
73+
* SAI switch global needed for RPC server and for remove_switch
7174
*/
7275
sai_object_id_t gSwitchId;
73-
#endif
7476

7577
struct cmdOptions
7678
{
@@ -1234,10 +1236,8 @@ sai_status_t handle_generic(
12341236
if (object_type == SAI_OBJECT_TYPE_SWITCH)
12351237
{
12361238
on_switch_create(switch_id);
1237-
#ifdef SAITHRIFT
12381239
gSwitchId = real_object_id;
12391240
SWSS_LOG_NOTICE("Initialize gSwitchId with ID = 0x%lx", gSwitchId);
1240-
#endif
12411241
}
12421242
}
12431243

@@ -3395,6 +3395,15 @@ int syncd_main(int argc, char **argv)
33953395
}
33963396
}
33973397

3398+
SWSS_LOG_NOTICE("Removing the switch gSwitchId=0x%lx", gSwitchId);
3399+
sai_switch_api_t *sai_switch_api = NULL;
3400+
sai_api_query(SAI_API_SWITCH, (void**)&sai_switch_api);
3401+
status = sai_switch_api->remove_switch(gSwitchId);
3402+
if (status != SAI_STATUS_SUCCESS)
3403+
{
3404+
SWSS_LOG_NOTICE("Can't delete a switch. gSwitchId=0x%lx status=0xx", gSwitchId, status);
3405+
}
3406+
33983407
SWSS_LOG_NOTICE("calling api uninitialize");
33993408

34003409
status = sai_api_uninitialize();

0 commit comments

Comments
 (0)