Skip to content

Commit

Permalink
Add OA switch_shutdown_request notification on syncd exit (sonic-net#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Aug 22, 2016
1 parent 2028daf commit b60a1c1
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 52 deletions.
69 changes: 47 additions & 22 deletions syncd/syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,35 @@ std::map<std::string, std::string> gProfileMap;

bool g_veryFirstRun = false;

void exit_and_notify(int status)
{
SWSS_LOG_ENTER();

try
{
if (notifications != NULL)
{
std::vector<swss::FieldValueTuple> entry;

SWSS_LOG_NOTICE("sending switch_shutdown_request notification to OA");

notifications->send("switch_shutdown_request", "", entry);

SWSS_LOG_NOTICE("notification send successfull");
}
}
catch(const std::exception &e)
{
SWSS_LOG_ERROR("Runtime error: %s", e.what());
}
catch(...)
{
SWSS_LOG_ERROR("Unknown runtime error");
}

exit(status);
}

void sai_diag_shell()
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -87,8 +116,7 @@ sai_object_id_t translate_rid_to_vid(
if (object_type == SAI_OBJECT_TYPE_NULL)
{
SWSS_LOG_ERROR("sai_object_type_query returned NULL type for RID %llx", rid);

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

vid = redis_create_virtual_object_id(object_type);
Expand Down Expand Up @@ -135,8 +163,7 @@ void translate_rid_to_vid_list(
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("unable to find serialization type for object type %x, attribute %x", object_type, attr.id);

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

switch (serialization_type)
Expand Down Expand Up @@ -195,8 +222,7 @@ sai_object_id_t translate_vid_to_rid(
if (prid == NULL)
{
SWSS_LOG_ERROR("unable to get RID for VID: %s", str_vid.c_str());

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

str_rid = *prid;
Expand Down Expand Up @@ -231,8 +257,7 @@ void translate_vid_to_rid_list(
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("unable to find serialization type for object type %x, attribute %x", object_type, attr.id);

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

switch (serialization_type)
Expand Down Expand Up @@ -422,7 +447,7 @@ sai_status_t handle_generic(
if (create == NULL)
{
SWSS_LOG_ERROR("create function is not defined for object type %x", object_type);
exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

sai_object_id_t real_object_id;
Expand Down Expand Up @@ -461,7 +486,7 @@ sai_status_t handle_generic(
if (remove == NULL)
{
SWSS_LOG_ERROR("remove function is not defined for object type %x", object_type);
exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

sai_object_id_t rid = translate_vid_to_rid(object_id);
Expand All @@ -487,7 +512,7 @@ sai_status_t handle_generic(
if (set == NULL)
{
SWSS_LOG_ERROR("set function is not defined for object type %x", object_type);
exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

sai_object_id_t rid = translate_vid_to_rid(object_id);
Expand All @@ -504,7 +529,7 @@ sai_status_t handle_generic(
if (get == NULL)
{
SWSS_LOG_ERROR("get function is not defined for object type %x", object_type);
exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

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

default:
SWSS_LOG_ERROR("generic other apis not implemented");
exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}
}

Expand Down Expand Up @@ -546,7 +571,7 @@ sai_status_t handle_fdb(

default:
SWSS_LOG_ERROR("fdb other apis not implemented");
exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}
}

Expand Down Expand Up @@ -574,7 +599,7 @@ sai_status_t handle_switch(

default:
SWSS_LOG_ERROR("switch other apis not implemented");
exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}
}

Expand Down Expand Up @@ -608,7 +633,7 @@ sai_status_t handle_neighbor(

default:
SWSS_LOG_ERROR("neighbor other apis not implemented");
exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}
}

Expand Down Expand Up @@ -644,7 +669,7 @@ sai_status_t handle_route(

default:
SWSS_LOG_ERROR("route other apis not implemented");
exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}
}

Expand Down Expand Up @@ -676,7 +701,7 @@ sai_status_t handle_vlan(

default:
SWSS_LOG_ERROR("vlan other apis not implemented");
exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}
}

Expand Down Expand Up @@ -704,7 +729,7 @@ sai_status_t handle_trap(

default:
SWSS_LOG_ERROR("trap other apis not implemented");
exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}
}

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

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

return status;
Expand Down Expand Up @@ -1294,7 +1319,7 @@ int main(int argc, char **argv)
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("fail to sai_initialize_switch: %d", status);
exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

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

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

endCountersThread();
Expand Down
2 changes: 2 additions & 0 deletions syncd/syncd.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ extern "C" {
#define SWITCH_SAI_THRIFT_RPC_SERVER_PORT 9092
#endif // SAITHRIFT

extern void exit_and_notify(int status) __attribute__ ((__noreturn__));

extern std::mutex g_mutex;

void onSyncdStart(bool warmStart);
Expand Down
36 changes: 18 additions & 18 deletions syncd/syncd_hard_reinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ sai_object_type_t getObjectTypeFromVid(sai_object_id_t sai_object_id)
{
SWSS_LOG_ERROR("invalid object type: %x on object id: %llx", objectType, sai_object_id);

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

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

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

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

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

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

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

redisSetVidAndRidMap(g_translated);
Expand Down Expand Up @@ -257,7 +257,7 @@ sai_object_id_t processSingleVid(sai_object_id_t vid)
{
SWSS_LOG_ERROR("failed to find VID %llx in VIDTORID map", vid);

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

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

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

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

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

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

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

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

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

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

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}
}
}
Expand All @@ -376,7 +376,7 @@ sai_attr_serialization_type_t getSerializationType(sai_object_type_t objectType,
{
SWSS_LOG_ERROR("unable to find serialization type on object type %x and attr id %x", objectType, attrId);

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}

return serializationType;
Expand Down Expand Up @@ -505,7 +505,7 @@ void processSwitch()
{
SWSS_LOG_ERROR("failed to set_switch_attribute %llx: %d", attr->id, status);

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}
}
}
Expand Down Expand Up @@ -542,7 +542,7 @@ void processVlans()
{
SWSS_LOG_ERROR("failed to create_vlan %d: %d", vlanId, status);

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}
}

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

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}
}
}
Expand Down Expand Up @@ -606,7 +606,7 @@ void processFdbs()
{
SWSS_LOG_ERROR("failed to create_fdb_entry: %d", status);

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}
}
}
Expand Down Expand Up @@ -649,7 +649,7 @@ void processNeighbors()
{
SWSS_LOG_ERROR("failed to create_neighbor_entry: %d", status);

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}
}
}
Expand Down Expand Up @@ -692,7 +692,7 @@ void processRoutes()
{
SWSS_LOG_ERROR("failed to create_route_entry: %d", status);

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}
}
}
Expand Down Expand Up @@ -740,7 +740,7 @@ void processTraps()
{
SWSS_LOG_ERROR("failed to set_trap_attribute %d: %d", trapId, status);

exit(EXIT_FAILURE);
exit_and_notify(EXIT_FAILURE);
}
}
}
Expand Down
Loading

0 comments on commit b60a1c1

Please sign in to comment.