Skip to content

Commit b60a1c1

Browse files
authored
Add OA switch_shutdown_request notification on syncd exit (sonic-net#62)
1 parent 2028daf commit b60a1c1

File tree

4 files changed

+79
-52
lines changed

4 files changed

+79
-52
lines changed

syncd/syncd.cpp

+47-22
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,35 @@ std::map<std::string, std::string> gProfileMap;
1111

1212
bool g_veryFirstRun = false;
1313

14+
void exit_and_notify(int status)
15+
{
16+
SWSS_LOG_ENTER();
17+
18+
try
19+
{
20+
if (notifications != NULL)
21+
{
22+
std::vector<swss::FieldValueTuple> entry;
23+
24+
SWSS_LOG_NOTICE("sending switch_shutdown_request notification to OA");
25+
26+
notifications->send("switch_shutdown_request", "", entry);
27+
28+
SWSS_LOG_NOTICE("notification send successfull");
29+
}
30+
}
31+
catch(const std::exception &e)
32+
{
33+
SWSS_LOG_ERROR("Runtime error: %s", e.what());
34+
}
35+
catch(...)
36+
{
37+
SWSS_LOG_ERROR("Unknown runtime error");
38+
}
39+
40+
exit(status);
41+
}
42+
1443
void sai_diag_shell()
1544
{
1645
SWSS_LOG_ENTER();
@@ -87,8 +116,7 @@ sai_object_id_t translate_rid_to_vid(
87116
if (object_type == SAI_OBJECT_TYPE_NULL)
88117
{
89118
SWSS_LOG_ERROR("sai_object_type_query returned NULL type for RID %llx", rid);
90-
91-
exit(EXIT_FAILURE);
119+
exit_and_notify(EXIT_FAILURE);
92120
}
93121

94122
vid = redis_create_virtual_object_id(object_type);
@@ -135,8 +163,7 @@ void translate_rid_to_vid_list(
135163
if (status != SAI_STATUS_SUCCESS)
136164
{
137165
SWSS_LOG_ERROR("unable to find serialization type for object type %x, attribute %x", object_type, attr.id);
138-
139-
exit(EXIT_FAILURE);
166+
exit_and_notify(EXIT_FAILURE);
140167
}
141168

142169
switch (serialization_type)
@@ -195,8 +222,7 @@ sai_object_id_t translate_vid_to_rid(
195222
if (prid == NULL)
196223
{
197224
SWSS_LOG_ERROR("unable to get RID for VID: %s", str_vid.c_str());
198-
199-
exit(EXIT_FAILURE);
225+
exit_and_notify(EXIT_FAILURE);
200226
}
201227

202228
str_rid = *prid;
@@ -231,8 +257,7 @@ void translate_vid_to_rid_list(
231257
if (status != SAI_STATUS_SUCCESS)
232258
{
233259
SWSS_LOG_ERROR("unable to find serialization type for object type %x, attribute %x", object_type, attr.id);
234-
235-
exit(EXIT_FAILURE);
260+
exit_and_notify(EXIT_FAILURE);
236261
}
237262

238263
switch (serialization_type)
@@ -422,7 +447,7 @@ sai_status_t handle_generic(
422447
if (create == NULL)
423448
{
424449
SWSS_LOG_ERROR("create function is not defined for object type %x", object_type);
425-
exit(EXIT_FAILURE);
450+
exit_and_notify(EXIT_FAILURE);
426451
}
427452

428453
sai_object_id_t real_object_id;
@@ -461,7 +486,7 @@ sai_status_t handle_generic(
461486
if (remove == NULL)
462487
{
463488
SWSS_LOG_ERROR("remove function is not defined for object type %x", object_type);
464-
exit(EXIT_FAILURE);
489+
exit_and_notify(EXIT_FAILURE);
465490
}
466491

467492
sai_object_id_t rid = translate_vid_to_rid(object_id);
@@ -487,7 +512,7 @@ sai_status_t handle_generic(
487512
if (set == NULL)
488513
{
489514
SWSS_LOG_ERROR("set function is not defined for object type %x", object_type);
490-
exit(EXIT_FAILURE);
515+
exit_and_notify(EXIT_FAILURE);
491516
}
492517

493518
sai_object_id_t rid = translate_vid_to_rid(object_id);
@@ -504,7 +529,7 @@ sai_status_t handle_generic(
504529
if (get == NULL)
505530
{
506531
SWSS_LOG_ERROR("get function is not defined for object type %x", object_type);
507-
exit(EXIT_FAILURE);
532+
exit_and_notify(EXIT_FAILURE);
508533
}
509534

510535
sai_object_id_t rid = translate_vid_to_rid(object_id);
@@ -514,7 +539,7 @@ sai_status_t handle_generic(
514539

515540
default:
516541
SWSS_LOG_ERROR("generic other apis not implemented");
517-
exit(EXIT_FAILURE);
542+
exit_and_notify(EXIT_FAILURE);
518543
}
519544
}
520545

@@ -546,7 +571,7 @@ sai_status_t handle_fdb(
546571

547572
default:
548573
SWSS_LOG_ERROR("fdb other apis not implemented");
549-
exit(EXIT_FAILURE);
574+
exit_and_notify(EXIT_FAILURE);
550575
}
551576
}
552577

@@ -574,7 +599,7 @@ sai_status_t handle_switch(
574599

575600
default:
576601
SWSS_LOG_ERROR("switch other apis not implemented");
577-
exit(EXIT_FAILURE);
602+
exit_and_notify(EXIT_FAILURE);
578603
}
579604
}
580605

@@ -608,7 +633,7 @@ sai_status_t handle_neighbor(
608633

609634
default:
610635
SWSS_LOG_ERROR("neighbor other apis not implemented");
611-
exit(EXIT_FAILURE);
636+
exit_and_notify(EXIT_FAILURE);
612637
}
613638
}
614639

@@ -644,7 +669,7 @@ sai_status_t handle_route(
644669

645670
default:
646671
SWSS_LOG_ERROR("route other apis not implemented");
647-
exit(EXIT_FAILURE);
672+
exit_and_notify(EXIT_FAILURE);
648673
}
649674
}
650675

@@ -676,7 +701,7 @@ sai_status_t handle_vlan(
676701

677702
default:
678703
SWSS_LOG_ERROR("vlan other apis not implemented");
679-
exit(EXIT_FAILURE);
704+
exit_and_notify(EXIT_FAILURE);
680705
}
681706
}
682707

@@ -704,7 +729,7 @@ sai_status_t handle_trap(
704729

705730
default:
706731
SWSS_LOG_ERROR("trap other apis not implemented");
707-
exit(EXIT_FAILURE);
732+
exit_and_notify(EXIT_FAILURE);
708733
}
709734
}
710735

@@ -805,7 +830,7 @@ sai_status_t processEvent(swss::ConsumerTable &consumer)
805830
{
806831
SWSS_LOG_ERROR("failed to execute api: %s: %d", op.c_str(), status);
807832

808-
exit(EXIT_FAILURE);
833+
exit_and_notify(EXIT_FAILURE);
809834
}
810835

811836
return status;
@@ -1294,7 +1319,7 @@ int main(int argc, char **argv)
12941319
if (status != SAI_STATUS_SUCCESS)
12951320
{
12961321
SWSS_LOG_ERROR("fail to sai_initialize_switch: %d", status);
1297-
exit(EXIT_FAILURE);
1322+
exit_and_notify(EXIT_FAILURE);
12981323
}
12991324

13001325
#ifdef BRCMSAI
@@ -1371,7 +1396,7 @@ int main(int argc, char **argv)
13711396
{
13721397
SWSS_LOG_ERROR("Runtime error: %s", e.what());
13731398

1374-
exit(EXIT_FAILURE);
1399+
exit_and_notify(EXIT_FAILURE);
13751400
}
13761401

13771402
endCountersThread();

syncd/syncd.h

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ extern "C" {
5959
#define SWITCH_SAI_THRIFT_RPC_SERVER_PORT 9092
6060
#endif // SAITHRIFT
6161

62+
extern void exit_and_notify(int status) __attribute__ ((__noreturn__));
63+
6264
extern std::mutex g_mutex;
6365

6466
void onSyncdStart(bool warmStart);

syncd/syncd_hard_reinit.cpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ sai_object_type_t getObjectTypeFromVid(sai_object_id_t sai_object_id)
4444
{
4545
SWSS_LOG_ERROR("invalid object type: %x on object id: %llx", objectType, sai_object_id);
4646

47-
exit(EXIT_FAILURE);
47+
exit_and_notify(EXIT_FAILURE);
4848
}
4949

5050
return objectType;
@@ -89,7 +89,7 @@ sai_object_type_t getObjectTypeFromAsicKey(const std::string &key)
8989
{
9090
SWSS_LOG_ERROR("invalid object type: %x on asic key: %s", objectType, key.c_str());
9191

92-
exit(EXIT_FAILURE);
92+
exit_and_notify(EXIT_FAILURE);
9393
}
9494

9595
return objectType;
@@ -134,7 +134,7 @@ void checkAllIds()
134134
{
135135
SWSS_LOG_ERROR("failed to find vid %llx in previous map", kv.first);
136136

137-
exit(EXIT_FAILURE);
137+
exit_and_notify(EXIT_FAILURE);
138138
}
139139

140140
g_vidToRidMap.erase(it);
@@ -151,7 +151,7 @@ void checkAllIds()
151151
SWSS_LOG_ERROR("vid not translated: %llx, object type: %llx", kv.first, objectType);
152152
}
153153

154-
exit(EXIT_FAILURE);
154+
exit_and_notify(EXIT_FAILURE);
155155
}
156156

157157
redisSetVidAndRidMap(g_translated);
@@ -257,7 +257,7 @@ sai_object_id_t processSingleVid(sai_object_id_t vid)
257257
{
258258
SWSS_LOG_ERROR("failed to find VID %llx in VIDTORID map", vid);
259259

260-
exit(EXIT_FAILURE);
260+
exit_and_notify(EXIT_FAILURE);
261261
}
262262

263263
sai_object_id_t virtualRouterRid = it->second;
@@ -288,7 +288,7 @@ sai_object_id_t processSingleVid(sai_object_id_t vid)
288288
{
289289
SWSS_LOG_ERROR("failed to find VID %llx in VIDTORID map", vid);
290290

291-
exit(EXIT_FAILURE);
291+
exit_and_notify(EXIT_FAILURE);
292292
}
293293

294294
rid = it->second;
@@ -304,7 +304,7 @@ sai_object_id_t processSingleVid(sai_object_id_t vid)
304304
{
305305
SWSS_LOG_ERROR("failed to find VID %s in OIDs map", strVid.c_str());
306306

307-
exit(EXIT_FAILURE);
307+
exit_and_notify(EXIT_FAILURE);
308308
}
309309

310310
std::string asicKey = oit->second;;
@@ -325,7 +325,7 @@ sai_object_id_t processSingleVid(sai_object_id_t vid)
325325
{
326326
SWSS_LOG_ERROR("create function is not defined for object type %llx", objectType);
327327

328-
exit(EXIT_FAILURE);
328+
exit_and_notify(EXIT_FAILURE);
329329
}
330330

331331
sai_status_t status = create(&rid, attrCount, attrList);
@@ -334,7 +334,7 @@ sai_object_id_t processSingleVid(sai_object_id_t vid)
334334
{
335335
SWSS_LOG_ERROR("failed to create object %llx: %d", objectType, status);
336336

337-
exit(EXIT_FAILURE);
337+
exit_and_notify(EXIT_FAILURE);
338338
}
339339

340340
SWSS_LOG_DEBUG("created object of type %x, processed VID %llx to RID %llx", objectType, vid, rid);
@@ -355,7 +355,7 @@ sai_object_id_t processSingleVid(sai_object_id_t vid)
355355
{
356356
SWSS_LOG_ERROR("failed to set attribute for object type %llx attr id %llx: %d", objectType, attr->id, status);
357357

358-
exit(EXIT_FAILURE);
358+
exit_and_notify(EXIT_FAILURE);
359359
}
360360
}
361361
}
@@ -376,7 +376,7 @@ sai_attr_serialization_type_t getSerializationType(sai_object_type_t objectType,
376376
{
377377
SWSS_LOG_ERROR("unable to find serialization type on object type %x and attr id %x", objectType, attrId);
378378

379-
exit(EXIT_FAILURE);
379+
exit_and_notify(EXIT_FAILURE);
380380
}
381381

382382
return serializationType;
@@ -505,7 +505,7 @@ void processSwitch()
505505
{
506506
SWSS_LOG_ERROR("failed to set_switch_attribute %llx: %d", attr->id, status);
507507

508-
exit(EXIT_FAILURE);
508+
exit_and_notify(EXIT_FAILURE);
509509
}
510510
}
511511
}
@@ -542,7 +542,7 @@ void processVlans()
542542
{
543543
SWSS_LOG_ERROR("failed to create_vlan %d: %d", vlanId, status);
544544

545-
exit(EXIT_FAILURE);
545+
exit_and_notify(EXIT_FAILURE);
546546
}
547547
}
548548

@@ -564,7 +564,7 @@ void processVlans()
564564
{
565565
SWSS_LOG_ERROR("failed to set_vlan_attribute %llx: %d", attr->id, status);
566566

567-
exit(EXIT_FAILURE);
567+
exit_and_notify(EXIT_FAILURE);
568568
}
569569
}
570570
}
@@ -606,7 +606,7 @@ void processFdbs()
606606
{
607607
SWSS_LOG_ERROR("failed to create_fdb_entry: %d", status);
608608

609-
exit(EXIT_FAILURE);
609+
exit_and_notify(EXIT_FAILURE);
610610
}
611611
}
612612
}
@@ -649,7 +649,7 @@ void processNeighbors()
649649
{
650650
SWSS_LOG_ERROR("failed to create_neighbor_entry: %d", status);
651651

652-
exit(EXIT_FAILURE);
652+
exit_and_notify(EXIT_FAILURE);
653653
}
654654
}
655655
}
@@ -692,7 +692,7 @@ void processRoutes()
692692
{
693693
SWSS_LOG_ERROR("failed to create_route_entry: %d", status);
694694

695-
exit(EXIT_FAILURE);
695+
exit_and_notify(EXIT_FAILURE);
696696
}
697697
}
698698
}
@@ -740,7 +740,7 @@ void processTraps()
740740
{
741741
SWSS_LOG_ERROR("failed to set_trap_attribute %d: %d", trapId, status);
742742

743-
exit(EXIT_FAILURE);
743+
exit_and_notify(EXIT_FAILURE);
744744
}
745745
}
746746
}

0 commit comments

Comments
 (0)