diff --git a/syncd/CommandLineOptions.cpp b/syncd/CommandLineOptions.cpp new file mode 100644 index 000000000000..c0639420a0e5 --- /dev/null +++ b/syncd/CommandLineOptions.cpp @@ -0,0 +1,113 @@ +#include "CommandLineOptions.h" + +#include "swss/logger.h" + +#include + +CommandLineOptions::CommandLineOptions() +{ + SWSS_LOG_ENTER(); + + // default values for command line options + + m_enableDiagShell = false; + m_enableTempView = false; + m_disableExitSleep = false; + m_enableUnittests = false; + m_enableConsistencyCheck = false; + m_enableSyncMode = false; + + m_startType = SAI_START_TYPE_COLD_BOOT; + + m_profileMapFile = ""; + +#ifdef SAITHRIFT + + m_runRPCServer = false; + + m_portMapFile = ""; + +#endif // SAITHRIFT + +} + +std::string CommandLineOptions::getCommandLineString() const +{ + SWSS_LOG_ENTER(); + + std::stringstream ss; + + ss << " EnableDiagShell=" << (m_enableDiagShell ? "YES" : "NO"); + ss << " EnableTempView=" << (m_enableTempView ? "YES" : "NO"); + ss << " DisableExitSleep=" << (m_disableExitSleep ? "YES" : "NO"); + ss << " EnableUnittests=" << (m_enableUnittests ? "YES" : "NO"); + ss << " EnableConsistencyCheck=" << (m_enableConsistencyCheck ? "YES" : "NO"); + ss << " EnableSyncMode=" << (m_enableSyncMode ? "YES" : "NO"); + ss << " StartType=" << startTypeToString(m_startType); + ss << " ProfileMapFile=" << m_profileMapFile; + +#ifdef SAITHRIFT + + ss << " RunRPCServer=" << (m_runRPCServer ? "YES" ? "NO"); + ss << " PortMapFile=" << m_portMapFile; + +#endif // SAITHRIFT + + return ss.str(); +} + +sai_start_type_t CommandLineOptions::startTypeStringToStartType( + _In_ const std::string& startType) +{ + SWSS_LOG_ENTER(); + + if (startType == STRING_SAI_START_TYPE_COLD_BOOT) + return SAI_START_TYPE_COLD_BOOT; + + if (startType == STRING_SAI_START_TYPE_WARM_BOOT) + return SAI_START_TYPE_WARM_BOOT; + + if (startType == STRING_SAI_START_TYPE_FAST_BOOT) + return SAI_START_TYPE_FAST_BOOT; + + if (startType == STRING_SAI_START_TYPE_FASTFAST_BOOT) + return SAI_START_TYPE_FASTFAST_BOOT; + + if (startType == STRING_SAI_START_TYPE_UNKNOWN) + return SAI_START_TYPE_UNKNOWN; + + SWSS_LOG_WARN("unknown startType: '%s'", startType.c_str()); + + return SAI_START_TYPE_UNKNOWN; +} + +std::string CommandLineOptions::startTypeToString( + _In_ sai_start_type_t startType) +{ + SWSS_LOG_ENTER(); + + switch (startType) + { + case SAI_START_TYPE_COLD_BOOT: + return STRING_SAI_START_TYPE_COLD_BOOT; + + case SAI_START_TYPE_WARM_BOOT: + return STRING_SAI_START_TYPE_WARM_BOOT; + + case SAI_START_TYPE_FAST_BOOT: + return STRING_SAI_START_TYPE_FAST_BOOT; + + case SAI_START_TYPE_FASTFAST_BOOT: + return STRING_SAI_START_TYPE_FASTFAST_BOOT; + + case SAI_START_TYPE_UNKNOWN: + return STRING_SAI_START_TYPE_UNKNOWN; + + default: + + SWSS_LOG_WARN("unknown startType '%d'", startType); + + return STRING_SAI_START_TYPE_UNKNOWN; + } +} + diff --git a/syncd/CommandLineOptions.h b/syncd/CommandLineOptions.h new file mode 100644 index 000000000000..3787982a5f33 --- /dev/null +++ b/syncd/CommandLineOptions.h @@ -0,0 +1,79 @@ +#pragma once + +#include "swss/sal.h" + +#include + +#define STRING_SAI_START_TYPE_COLD_BOOT "cold" +#define STRING_SAI_START_TYPE_WARM_BOOT "warm" +#define STRING_SAI_START_TYPE_FAST_BOOT "fast" +#define STRING_SAI_START_TYPE_FASTFAST_BOOT "fastfast" +#define STRING_SAI_START_TYPE_UNKNOWN "unknown" + +typedef enum _sai_start_type_t +{ + SAI_START_TYPE_COLD_BOOT = 0, + + SAI_START_TYPE_WARM_BOOT = 1, + + SAI_START_TYPE_FAST_BOOT = 2, + + /** + * A special type of boot used by Mellanox platforms to start in 'fastfast' + * boot mode + */ + SAI_START_TYPE_FASTFAST_BOOT = 3, + + /** + * Set at last, just for error purpose. + */ + SAI_START_TYPE_UNKNOWN + +} sai_start_type_t; + +class CommandLineOptions +{ + public: + + CommandLineOptions(); + + virtual ~CommandLineOptions() = default; + + public: + + virtual std::string getCommandLineString() const; + + public: + + static sai_start_type_t startTypeStringToStartType( + _In_ const std::string& startType); + + static std::string startTypeToString( + _In_ sai_start_type_t startType); + + public: + + bool m_enableDiagShell; + bool m_enableTempView; + bool m_disableExitSleep; + bool m_enableUnittests; + + /** + * When set to true will enable DB vs ASIC consistency check after + * comparison logic. + */ + bool m_enableConsistencyCheck; + + bool m_enableSyncMode; + + sai_start_type_t m_startType; + + std::string m_profileMapFile; + +#ifdef SAITHRIFT + bool m_runRPCServer; + std::string m_portMapFile; +#endif // SAITHRIFT + +}; + diff --git a/syncd/CommandLineOptionsParser.cpp b/syncd/CommandLineOptionsParser.cpp new file mode 100644 index 000000000000..327933293fc4 --- /dev/null +++ b/syncd/CommandLineOptionsParser.cpp @@ -0,0 +1,154 @@ +#include "CommandLineOptionsParser.h" + +#include + +std::shared_ptr CommandLineOptionsParser::parseCommandLine( + _In_ int argc, + _In_ char **argv) +{ + SWSS_LOG_ENTER(); + + auto options = std::make_shared(); + +#ifdef SAITHRIFT + const char* const optstring = "dp:t:uSUCsrm:h"; +#else + const char* const optstring = "dp:t:uSUCsh"; +#endif // SAITHRIFT + + while(true) + { + static struct option long_options[] = + { + { "diag", no_argument, 0, 'd' }, + { "profile", required_argument, 0, 'p' }, + { "startType", required_argument, 0, 't' }, + { "useTempView", no_argument, 0, 'u' }, + { "disableExitSleep", no_argument, 0, 'S' }, + { "enableUnittests", no_argument, 0, 'U' }, + { "enableConsistencyCheck", no_argument, 0, 'C' }, + { "syncMode", no_argument, 0, 's' }, +#ifdef SAITHRIFT + { "rpcserver", no_argument, 0, 'r' }, + { "portmap", required_argument, 0, 'm' }, +#endif // SAITHRIFT + { "help", no_argument, 0, 'h' }, + { 0, 0, 0, 0 } + }; + + int option_index = 0; + + int c = getopt_long(argc, argv, optstring, long_options, &option_index); + + if (c == -1) + { + break; + } + + switch (c) + { + case 'd': + options->m_enableDiagShell = true; + break; + + case 'p': + options->m_profileMapFile = std::string(optarg); + break; + + case 't': + options->m_startType = CommandLineOptions::startTypeStringToStartType(optarg); + + if (options->m_startType == SAI_START_TYPE_UNKNOWN) + { + SWSS_LOG_ERROR("unknown start type '%s'", optarg); + exit(EXIT_FAILURE); + } + break; + + case 'u': + options->m_enableTempView = true; + break; + + case 'S': + options->m_disableExitSleep = true; + break; + + case 'U': + options->m_enableUnittests = true; + break; + + case 'C': + options->m_enableConsistencyCheck = true; + break; + + case 's': + options->m_enableSyncMode = true; + break; + +#ifdef SAITHRIFT + case 'r': + options->m_runRPCServer = true; + break; + case 'm': + options->m_portMapFile = std::string(optarg); + break; +#endif // SAITHRIFT + + case 'h': + printUsage(); + exit(EXIT_SUCCESS); + + case '?': + SWSS_LOG_WARN("unknown option %c", optopt); + printUsage(); + exit(EXIT_FAILURE); + + default: + SWSS_LOG_ERROR("getopt_long failure"); + exit(EXIT_FAILURE); + } + } + + return options; +} + +void CommandLineOptionsParser::printUsage() +{ + SWSS_LOG_ENTER(); + +#ifdef SAITHRIFT + std::cout << "Usage: syncd [-d] [-p profile] [-t type] [-u] [-S] [-U] [-C] [-s] [-r] [-m portmap] [-h]" << std::endl; +#else + std::cout << "Usage: syncd [-d] [-p profile] [-t type] [-u] [-S] [-U] [-C] [-s] [-h]" << std::endl; +#endif // SAITHRIFT + + std::cout << " -d --diag" << std::endl; + std::cout << " Enable diagnostic shell" << std::endl; + std::cout << " -p --profile profile" << std::endl; + std::cout << " Provide profile map file" << std::endl; + std::cout << " -t --startType type" << std::endl; + std::cout << " Specify start type (cold|warm|fast|fastfast) " << std::endl; + std::cout << " -u --useTempView" << std::endl; + std::cout << " Use temporary view between init and apply" << std::endl; + std::cout << " -S --disableExitSleep" << std::endl; + std::cout << " Disable sleep when syncd crashes" << std::endl; + std::cout << " -U --enableUnittests" << std::endl; + std::cout << " Metadata enable unittests" << std::endl; + std::cout << " -C --enableConsistencyCheck" << std::endl; + std::cout << " Enable consisteny check DB vs ASIC after comparison logic" << std::endl; + std::cout << " -s --syncMode" << std::endl; + std::cout << " Enable synchronous mode" << std::endl; + +#ifdef SAITHRIFT + + std::cout << " -r --rpcserver" << std::endl; + std::cout << " Enable rpcserver" << std::endl; + std::cout << " -m --portmap portmap" << std::endl; + std::cout << " Specify port map file" << std::endl; + +#endif // SAITHRIFT + + std::cout << " -h --help" << std::endl; + std::cout << " Print out this message" << std::endl; +} + diff --git a/syncd/CommandLineOptionsParser.h b/syncd/CommandLineOptionsParser.h new file mode 100644 index 000000000000..ba8ca24cbb00 --- /dev/null +++ b/syncd/CommandLineOptionsParser.h @@ -0,0 +1,23 @@ +#pragma once + +#include "syncd.h" +#include "CommandLineOptions.h" + +#include + +class CommandLineOptionsParser +{ + private: + + CommandLineOptionsParser() = delete; + + ~CommandLineOptionsParser() = delete; + + public: + + static std::shared_ptr parseCommandLine( + _In_ int argc, + _In_ char **argv); + + static void printUsage(); +}; diff --git a/syncd/Makefile.am b/syncd/Makefile.am index afb61d6eeeb7..eac7ae2aca4b 100644 --- a/syncd/Makefile.am +++ b/syncd/Makefile.am @@ -23,7 +23,9 @@ syncd_SOURCES = \ syncd_applyview.cpp \ syncd_flex_counter.cpp \ TimerWatchdog.cpp \ - NotificationQueue.cpp + NotificationQueue.cpp \ + CommandLineOptions.cpp \ + CommandLineOptionsParser.cpp syncd_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) $(SAIFLAGS) syncd_LDADD = -lhiredis -lswsscommon $(SAILIB) -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -ldl @@ -50,7 +52,9 @@ tests_SOURCES = \ syncd_applyview.cpp \ syncd_flex_counter.cpp \ TimerWatchdog.cpp \ - NotificationQueue.cpp + NotificationQueue.cpp \ + CommandLineOptions.cpp \ + CommandLineOptionsParser.cpp tests_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) tests_LDADD = -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/lib/src/.libs -lsairedis -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta diff --git a/syncd/syncd.cpp b/syncd/syncd.cpp index fed18336e55b..cc9b8a7fd158 100644 --- a/syncd/syncd.cpp +++ b/syncd/syncd.cpp @@ -11,6 +11,7 @@ #include "swss/redisapi.h" #include "TimerWatchdog.h" +#include "CommandLineOptionsParser.h" extern "C" { #include @@ -76,12 +77,6 @@ std::map> switches; */ std::set initViewRemovedVidSet; -/* - * When set to true will enable DB vs ASIC consistency check after comparison - * logic. - */ -bool g_enableConsistencyCheck = false; - /* * By default we are in APPLY mode. */ @@ -95,36 +90,13 @@ sai_object_id_t gSwitchId; std::string fdbFlushSha; std::string fdbFlushLuaScriptName = "fdb_flush.lua"; -struct cmdOptions -{ - bool diagShell; - bool useTempView; - int startType; - bool disableExitSleep; - bool enableUnittests; - std::string profileMapFile; -#ifdef SAITHRIFT - bool run_rpc_server; - std::string portMapFile; -#endif // SAITHRIFT - bool syncMode; - ~cmdOptions() {} -}; - -cmdOptions options; - -bool enableUnittests() -{ - SWSS_LOG_ENTER(); - - return options.enableUnittests; -} +std::shared_ptr g_commandLineOptions; // TODO move to syncd object bool isInitViewMode() { SWSS_LOG_ENTER(); - return g_asicInitViewMode && options.useTempView; + return g_asicInitViewMode && g_commandLineOptions->m_enableTempView; } bool g_veryFirstRun = false; @@ -1023,7 +995,7 @@ void internal_syncd_api_send_response( * response for sairedis quad API. */ - if (!options.syncMode) + if (!g_commandLineOptions->m_enableSyncMode) return; std::vector entry; @@ -1110,7 +1082,7 @@ void startDiagShell() { SWSS_LOG_ENTER(); - if (options.diagShell) + if (g_commandLineOptions->m_enableDiagShell) { SWSS_LOG_NOTICE("starting diag shell thread"); @@ -1909,7 +1881,7 @@ sai_status_t notifySyncd( { SWSS_LOG_ENTER(); - if (!options.useTempView) + if (!g_commandLineOptions->m_enableTempView) { SWSS_LOG_NOTICE("received %s, ignored since TEMP VIEW is not used, returning success", op.c_str()); @@ -1966,7 +1938,7 @@ sai_status_t notifySyncd( g_asicInitViewMode = false; - if (options.startType == SAI_FASTFAST_BOOT) + if (g_commandLineOptions->m_startType == SAI_START_TYPE_FASTFAST_BOOT) { /* fastfast boot configuration end */ status = onApplyViewInFastFastBoot(); @@ -3569,174 +3541,6 @@ void processFlexCounterEvent( return; } -void printUsage() -{ - SWSS_LOG_ENTER(); - - std::cout << "Usage: syncd [-N] [-U] [-d] [-p profile] [-i interval] [-t [cold|warm|fast|fastfast]] [-h] [-u] [-S] [-s]" << std::endl; - std::cout << " -N --nocounters" << std::endl; - std::cout << " Disable counter thread" << std::endl; - std::cout << " -d --diag" << std::endl; - std::cout << " Enable diagnostic shell" << std::endl; - std::cout << " -p --profile profile" << std::endl; - std::cout << " Provide profile map file" << std::endl; - std::cout << " -i --countersInterval interval" << std::endl; - std::cout << " Provide counter thread interval" << std::endl; - std::cout << " -t --startType type" << std::endl; - std::cout << " Specify cold|warm|fast|fastfast start type" << std::endl; - std::cout << " -u --useTempView:" << std::endl; - std::cout << " Use temporary view between init and apply" << std::endl; - std::cout << " -S --disableExitSleep" << std::endl; - std::cout << " Disable sleep when syncd crashes" << std::endl; - std::cout << " -U --eableUnittests" << std::endl; - std::cout << " Metadata enable unittests" << std::endl; - std::cout << " -C --eableConsistencyCheck" << std::endl; - std::cout << " Enable consisteny check DB vs ASIC after comparison logic" << std::endl; -#ifdef SAITHRIFT - std::cout << " -r --rpcserver" << std::endl; - std::cout << " Enable rpcserver" << std::endl; - std::cout << " -m --portmap" << std::endl; - std::cout << " Specify port map file" << std::endl; -#endif // SAITHRIFT - std::cout << " -s --syncMode" << std::endl; - std::cout << " Enable synchronous mode" << std::endl; - std::cout << " -h --help" << std::endl; - std::cout << " Print out this message" << std::endl; -} - -void handleCmdLine(int argc, char **argv) -{ - SWSS_LOG_ENTER(); - - options.disableExitSleep = false; - options.enableUnittests = false; - options.syncMode = false; - -#ifdef SAITHRIFT - options.run_rpc_server = false; - const char* const optstring = "dNUCt:p:i:rm:huSs"; -#else - const char* const optstring = "dNUCt:p:i:huSs"; -#endif // SAITHRIFT - - while(true) - { - static struct option long_options[] = - { - { "useTempView", no_argument, 0, 'u' }, - { "diag", no_argument, 0, 'd' }, - { "startType", required_argument, 0, 't' }, - { "profile", required_argument, 0, 'p' }, - { "help", no_argument, 0, 'h' }, - { "disableExitSleep", no_argument, 0, 'S' }, - { "enableUnittests", no_argument, 0, 'U' }, - { "enableConsistencyCheck", no_argument, 0, 'C' }, -#ifdef SAITHRIFT - { "rpcserver", no_argument, 0, 'r' }, - { "portmap", required_argument, 0, 'm' }, -#endif // SAITHRIFT - { "syncMode", no_argument, 0, 's' }, - { 0, 0, 0, 0 } - }; - - int option_index = 0; - - int c = getopt_long(argc, argv, optstring, long_options, &option_index); - - if (c == -1) - { - break; - } - - switch (c) - { - case 'U': - SWSS_LOG_NOTICE("enable unittests"); - options.enableUnittests = true; - break; - - case 'C': - SWSS_LOG_NOTICE("enable consistency check"); - g_enableConsistencyCheck = true; - break; - - case 'u': - SWSS_LOG_NOTICE("enable use temp view"); - options.useTempView = true; - break; - - case 'S': - SWSS_LOG_NOTICE("disable crash sleep"); - options.disableExitSleep = true; - break; - - case 'd': - SWSS_LOG_NOTICE("enable diag shell"); - options.diagShell = true; - break; - - case 'p': - SWSS_LOG_NOTICE("profile map file: %s", optarg); - options.profileMapFile = std::string(optarg); - break; - - case 't': - SWSS_LOG_NOTICE("start type: %s", optarg); - if (std::string(optarg) == "cold") - { - options.startType = SAI_COLD_BOOT; - } - else if (std::string(optarg) == "warm") - { - options.startType = SAI_WARM_BOOT; - } - else if (std::string(optarg) == "fast") - { - options.startType = SAI_FAST_BOOT; - } - else if (std::string(optarg) == "fastfast") - { - options.startType = SAI_FASTFAST_BOOT; - } - else - { - SWSS_LOG_ERROR("unknown start type %s", optarg); - exit(EXIT_FAILURE); - } - break; - -#ifdef SAITHRIFT - case 'r': - SWSS_LOG_NOTICE("enable rpc server"); - options.run_rpc_server = true; - break; - case 'm': - SWSS_LOG_NOTICE("port map file: %s", optarg); - options.portMapFile = std::string(optarg); - break; -#endif // SAITHRIFT - - case 's': - SWSS_LOG_NOTICE("enable synchronous mode"); - options.syncMode = true; - break; - - case 'h': - printUsage(); - exit(EXIT_SUCCESS); - - case '?': - SWSS_LOG_WARN("unknown option %c", optopt); - printUsage(); - exit(EXIT_FAILURE); - - default: - SWSS_LOG_ERROR("getopt_long failure"); - exit(EXIT_FAILURE); - } - } -} - void handleProfileMap(const std::string& profileMapFile) { SWSS_LOG_ENTER(); @@ -4129,14 +3933,17 @@ int syncd_main(int argc, char **argv) meta_init_db(); - handleCmdLine(argc, argv); + // TODO move to syncd object + g_commandLineOptions = CommandLineOptionsParser::parseCommandLine(argc, argv); - handleProfileMap(options.profileMapFile); + SWSS_LOG_NOTICE("command line: %s", g_commandLineOptions->getCommandLineString().c_str()); + + handleProfileMap(g_commandLineOptions->m_profileMapFile); #ifdef SAITHRIFT - if (options.portMapFile.size() > 0) + if (g_commandLineOption.portMapFile.size() > 0) { - handlePortMap(options.portMapFile); + handlePortMap(g_commandLineOptions->m_portMapFile); } #endif // SAITHRIFT @@ -4168,12 +3975,12 @@ int syncd_main(int argc, char **argv) g_veryFirstRun = isVeryFirstRun(); /* ignore warm logic here if syncd starts in Mellanox fastfast boot mode */ - if (swss::WarmStart::isWarmStart() && (options.startType != SAI_FASTFAST_BOOT)) + if (swss::WarmStart::isWarmStart() && (g_commandLineOptions->m_startType != SAI_START_TYPE_FASTFAST_BOOT)) { - options.startType = SAI_WARM_BOOT; + g_commandLineOptions->m_startType = SAI_START_TYPE_WARM_BOOT; } - if (options.startType == SAI_WARM_BOOT) + if (g_commandLineOptions->m_startType == SAI_START_TYPE_WARM_BOOT) { const char *warmBootReadFile = profile_get_value(0, SAI_KEY_WARM_BOOT_READ_FILE); @@ -4183,11 +3990,11 @@ int syncd_main(int argc, char **argv) { SWSS_LOG_WARN("user requested warmStart but warmBootReadFile is not specified or not accesible, forcing cold start"); - options.startType = SAI_COLD_BOOT; + g_commandLineOptions->m_startType = SAI_START_TYPE_COLD_BOOT; } } - if (options.startType == SAI_WARM_BOOT && g_veryFirstRun) + if (g_commandLineOptions->m_startType == SAI_START_TYPE_WARM_BOOT && g_veryFirstRun) { SWSS_LOG_WARN("warm start requested, but this is very first syncd start, forcing cold start"); @@ -4198,25 +4005,26 @@ int syncd_main(int argc, char **argv) * repopulate asic view. */ - options.startType = SAI_COLD_BOOT; + g_commandLineOptions->m_startType = SAI_START_TYPE_COLD_BOOT; } - if (options.startType == SAI_FASTFAST_BOOT) + if (g_commandLineOptions->m_startType == SAI_START_TYPE_FASTFAST_BOOT) { /* * Mellanox SAI requires to pass SAI_WARM_BOOT as SAI_BOOT_KEY * to start 'fastfast' */ - gProfileMap[SAI_KEY_BOOT_TYPE] = std::to_string(SAI_WARM_BOOT); + gProfileMap[SAI_KEY_BOOT_TYPE] = std::to_string(SAI_START_TYPE_WARM_BOOT); } else { - gProfileMap[SAI_KEY_BOOT_TYPE] = std::to_string(options.startType); + gProfileMap[SAI_KEY_BOOT_TYPE] = std::to_string(g_commandLineOptions->m_startType); // number value is needed } sai_status_t status = sai_api_initialize(0, (sai_service_method_table_t*)&test_services); if (status != SAI_STATUS_SUCCESS) { - SWSS_LOG_ERROR("fail to sai_api_initialize: %d", status); + SWSS_LOG_ERROR("fail to sai_api_initialize: %s", + sai_serialize_status(status).c_str()); return EXIT_FAILURE; } @@ -4234,7 +4042,7 @@ int syncd_main(int argc, char **argv) */ #ifdef SAITHRIFT - if (options.run_rpc_server) + if (g_commandLineOptions->m_runRPCServer) { start_sai_thrift_rpc_server(SWITCH_SAI_THRIFT_RPC_SERVER_PORT); SWSS_LOG_NOTICE("rpcserver started"); @@ -4255,7 +4063,7 @@ int syncd_main(int argc, char **argv) try { SWSS_LOG_NOTICE("before onSyncdStart"); - onSyncdStart(options.startType == SAI_WARM_BOOT); + onSyncdStart(g_commandLineOptions->m_startType == SAI_START_TYPE_WARM_BOOT); SWSS_LOG_NOTICE("after onSyncdStart"); // create notifications processing thread after we create_switch to @@ -4285,7 +4093,7 @@ int syncd_main(int argc, char **argv) SWSS_LOG_NOTICE("starting main loop, ONLY restart query"); - if (options.disableExitSleep) + if (g_commandLineOptions->m_disableExitSleep) runMainLoop = false; } @@ -4408,11 +4216,11 @@ int syncd_main(int argc, char **argv) s->addSelectable(restartQuery.get()); - if (options.disableExitSleep) + if (g_commandLineOptions->m_disableExitSleep) runMainLoop = false; // make sure that if second exception will arise, then we break the loop - options.disableExitSleep = true; + g_commandLineOptions->m_disableExitSleep = true; twd.setEndTime(); } diff --git a/syncd/syncd.h b/syncd/syncd.h index ca8e7f9b3142..35cc40c3da96 100644 --- a/syncd/syncd.h +++ b/syncd/syncd.h @@ -8,11 +8,11 @@ #include #include #include +#include #include #include #include -#include #ifdef SAITHRIFT #include @@ -52,14 +52,6 @@ extern "C" { #define HIDDEN "HIDDEN" #define COLDVIDS "COLDVIDS" -#define SAI_COLD_BOOT 0 -#define SAI_WARM_BOOT 1 -#define SAI_FAST_BOOT 2 -/** - * A special type of boot used by Mellanox platforms - * to start in 'fastfast' boot mode - */ -#define SAI_FASTFAST_BOOT 3 #ifdef SAITHRIFT #define SWITCH_SAI_THRIFT_RPC_SERVER_PORT 9092 @@ -96,8 +88,6 @@ extern std::shared_ptr g_redisClient; extern std::shared_ptr dbAsic; extern std::string fdbFlushSha; -extern bool g_enableConsistencyCheck; - sai_object_id_t redis_create_virtual_object_id( _In_ sai_object_id_t switch_id, _In_ sai_object_type_t object_type); @@ -143,6 +133,4 @@ void set_sai_api_loglevel(); void set_sai_api_log_min_prio( _In_ const std::string &prio); -bool enableUnittests(); - #endif // __SYNCD_H__ diff --git a/syncd/syncd_applyview.cpp b/syncd/syncd_applyview.cpp index 532f1d14be3b..c7c4096a1b0a 100644 --- a/syncd/syncd_applyview.cpp +++ b/syncd/syncd_applyview.cpp @@ -4,10 +4,14 @@ #include "swss/logger.h" #include "swss/dbconnector.h" +#include "CommandLineOptions.h" + #include #include #include +extern std::shared_ptr g_commandLineOptions; + /* * NOTE: All methods taking current and temporary view could be moved to * transition class etc to just use class members instead of passing those @@ -7513,7 +7517,7 @@ void checkAsicVsDatabaseConsistency( swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_NOTICE); - if (hasErrors && enableUnittests()) + if (hasErrors && g_commandLineOptions->m_enableUnittests) { SWSS_LOG_THROW("ASIC content is differnt than DB content!"); } @@ -7933,7 +7937,7 @@ sai_status_t syncdApplyView() updateRedisDatabase(current, temp); - if (g_enableConsistencyCheck) + if (g_commandLineOptions->m_enableConsistencyCheck) { checkAsicVsDatabaseConsistency(current, temp); } @@ -8470,7 +8474,7 @@ void executeOperationsOnAsic( SWSS_LOG_TIMER("asic apply"); - if (enableUnittests()) + if (g_commandLineOptions->m_enableUnittests) dumpComparisonLogicOutput(currentView); currentView.dumpVidToAsicOperatioId(); diff --git a/tests/Makefile.am b/tests/Makefile.am index d52b397a9f65..5c90cba2cda0 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -19,7 +19,9 @@ vssyncd_SOURCES = \ ../syncd/syncd_applyview.cpp \ ../syncd/syncd_flex_counter.cpp \ ../syncd/TimerWatchdog.cpp \ - ../syncd/NotificationQueue.cpp + ../syncd/NotificationQueue.cpp \ + ../syncd/CommandLineOptions.cpp \ + ../syncd/CommandLineOptionsParser.cpp vssyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON) $(SAIFLAGS) vssyncd_LDADD = -lhiredis -lswsscommon $(SAILIB) -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -ldl