Skip to content

Commit

Permalink
Add support for fast reload (sonic-net#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Apr 6, 2018
1 parent c860472 commit c3bed54
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 15 deletions.
59 changes: 49 additions & 10 deletions syncd/syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2265,7 +2265,6 @@ sai_status_t processFdbFlush(
SWSS_LOG_ENTER();

const std::string &key = kfvKey(kco);
const std::string &str_object_type = key.substr(0, key.find(":"));
const std::string &str_object_id = key.substr(key.find(":") + 1);

sai_object_id_t switch_vid;
Expand Down Expand Up @@ -2917,7 +2916,17 @@ void handlePortMap(const std::string& portMapFile)
}
#endif // SAITHRIFT

bool handleRestartQuery(swss::NotificationConsumer &restartQuery)
typedef enum _syncd_restart_type_t
{
SYNCD_RESTART_TYPE_COLD,

SYNCD_RESTART_TYPE_WARM,

SYNCD_RESTART_TYPE_FAST,

} syncd_restart_type_t;

syncd_restart_type_t handleRestartQuery(swss::NotificationConsumer &restartQuery)
{
SWSS_LOG_ENTER();

Expand All @@ -2932,17 +2941,23 @@ bool handleRestartQuery(swss::NotificationConsumer &restartQuery)
if (op == "COLD")
{
SWSS_LOG_NOTICE("received COLD switch shutdown event");
return false;
return SYNCD_RESTART_TYPE_COLD;
}

if (op == "WARM")
{
SWSS_LOG_NOTICE("received WARM switch shutdown event");
return true;
return SYNCD_RESTART_TYPE_WARM;
}

if (op == "FAST")
{
SWSS_LOG_NOTICE("received FAST switch shutdown event");
return SYNCD_RESTART_TYPE_FAST;
}

SWSS_LOG_WARN("received '%s' unknown switch shutdown event, assuming COLD", op.c_str());
return false;
return SYNCD_RESTART_TYPE_COLD;
}

bool isVeryFirstRun()
Expand Down Expand Up @@ -3318,7 +3333,7 @@ int syncd_main(int argc, char **argv)

SWSS_LOG_NOTICE("syncd started");

bool warmRestartHint = false;
syncd_restart_type_t restartType = SYNCD_RESTART_TYPE_COLD;

try
{
Expand Down Expand Up @@ -3357,7 +3372,7 @@ int syncd_main(int argc, char **argv)
* lead to unable to find some objects.
*/

warmRestartHint = handleRestartQuery(*restartQuery);
restartType = handleRestartQuery(*restartQuery);
break;
}
else if (sel == flexCounter.get())
Expand All @@ -3381,7 +3396,7 @@ int syncd_main(int argc, char **argv)
exit_and_notify(EXIT_FAILURE);
}

if (warmRestartHint)
if (restartType == SYNCD_RESTART_TYPE_WARM)
{
const char *warmBootWriteFile = profile_get_value(0, SAI_KEY_WARM_BOOT_WRITE_FILE);

Expand All @@ -3391,17 +3406,41 @@ int syncd_main(int argc, char **argv)
{
SWSS_LOG_WARN("user requested warm shutdown but warmBootWriteFile is not specified, forcing cold shutdown");

warmRestartHint = false;
restartType = SYNCD_RESTART_TYPE_COLD;
}
}

SWSS_LOG_NOTICE("Removing the switch gSwitchId=0x%lx", gSwitchId);
sai_switch_api_t *sai_switch_api = NULL;
sai_api_query(SAI_API_SWITCH, (void**)&sai_switch_api);

#ifdef SAI_SWITCH_ATTR_UNINIT_DATA_PLANE_ON_REMOVAL

if (restartType == SYNCD_RESTART_TYPE_FAST)
{
SWSS_LOG_NOTICE("Fast Reboot requested, keeping data plane running");

sai_attribute_t attr;

attr.id = SAI_SWITCH_ATTR_UNINIT_DATA_PLANE_ON_REMOVAL;
attr.value.booldata = false;

status = sai_switch_api->set_switch_attribute(gSwitchId, &attr);

if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set SAI_SWITCH_ATTR_UNINIT_DATA_PLANE_ON_REMOVAL=false: %s",
sai_serialize_status(status).c_str());
}
}

#endif

status = sai_switch_api->remove_switch(gSwitchId);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_NOTICE("Can't delete a switch. gSwitchId=0x%lx status=0xx", gSwitchId, status);
SWSS_LOG_NOTICE("Can't delete a switch. gSwitchId=0x%lx status=%s", gSwitchId,
sai_serialize_status(status).c_str());
}

SWSS_LOG_NOTICE("calling api uninitialize");
Expand Down
14 changes: 9 additions & 5 deletions syncd/syncd_request_shutdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ int main(int argc, char **argv)
{ "warm", no_argument, 0, 'w' }
};

bool warmRestartHint = false;
std::string op;
bool optionSpecified = false;

while(true)
Expand All @@ -34,12 +34,17 @@ int main(int argc, char **argv)
switch (c)
{
case 'c':
warmRestartHint = false;
op = "COLD";
optionSpecified = true;
break;

case 'w':
warmRestartHint = true;
op = "WARM";
optionSpecified = true;
break;

case 'f':
op = "FAST";
optionSpecified = true;
break;

Expand All @@ -57,6 +62,7 @@ int main(int argc, char **argv)
std::cerr << "---------------------------------" << std::endl;
std::cerr << " --warm -w for warm restart" << std::endl;
std::cerr << " --cold -c for cold restart" << std::endl;
std::cerr << " --fast -f for fast restart" << std::endl;

exit(EXIT_FAILURE);
}
Expand All @@ -66,8 +72,6 @@ int main(int argc, char **argv)

std::vector<swss::FieldValueTuple> values;

std::string op = warmRestartHint ? "WARM" : "COLD";

SWSS_LOG_NOTICE("requested %s shutdown", op.c_str());

std::cerr << "requested " << op << " shutdown" << std::endl;
Expand Down

0 comments on commit c3bed54

Please sign in to comment.