int main(int argc, char* argv[]) { int rv = 0; auto options = handleCmdLine(argc, argv); handleProfileMap(options.profileMapFile); handlePortMap(options.portMapFile); sai_api_initialize(0, &test_services); sai_api_query(SAI_API_SWITCH, (void**)&sai_switch_api); constexpr std::uint32_t attrSz = 6; sai_attribute_t attr[attrSz]; std::memset(attr, '\0', sizeof(attr)); attr[0].id = SAI_SWITCH_ATTR_INIT_SWITCH; attr[0].value.booldata = true; attr[1].id = SAI_SWITCH_ATTR_SWITCH_STATE_CHANGE_NOTIFY; attr[1].value.ptr = reinterpret_cast<sai_pointer_t>(&on_switch_state_change); attr[2].id = SAI_SWITCH_ATTR_SHUTDOWN_REQUEST_NOTIFY; attr[2].value.ptr = reinterpret_cast<sai_pointer_t>(&on_shutdown_request); attr[3].id = SAI_SWITCH_ATTR_FDB_EVENT_NOTIFY; attr[3].value.ptr = reinterpret_cast<sai_pointer_t>(&on_fdb_event); attr[4].id = SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY; attr[4].value.ptr = reinterpret_cast<sai_pointer_t>(&on_port_state_change); attr[5].id = SAI_SWITCH_ATTR_PACKET_EVENT_NOTIFY; attr[5].value.ptr = reinterpret_cast<sai_pointer_t>(&on_packet_event); sai_status_t status = sai_switch_api->create_switch(&gSwitchId, attrSz, attr); if (status != SAI_STATUS_SUCCESS) { exit(EXIT_FAILURE); } handleInitScript(options.initScript); #ifdef BRCMSAI std::thread bcm_diag_shell_thread = std::thread(sai_diag_shell); bcm_diag_shell_thread.detach(); #endif start_sai_thrift_rpc_server(SWITCH_SAI_THRIFT_RPC_SERVER_PORT); sai_log_set(SAI_API_SWITCH, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_BRIDGE, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_FDB, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_PORT, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_VLAN, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_ROUTE, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_VIRTUAL_ROUTER, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_ROUTER_INTERFACE, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_NEXT_HOP, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_NEXT_HOP_GROUP, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_NEIGHBOR, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_ACL, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_MIRROR, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_LAG, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_BUFFER, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_POLICER, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_WRED, SAI_LOG_LEVEL_NOTICE); sai_log_set(SAI_API_QOS_MAP, SAI_LOG_LEVEL_NOTICE); while (1) pause(); return rv; }
int main(int argc, char **argv) { swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG); SWSS_LOG_ENTER(); swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_NOTICE); handleCmdLine(argc, argv); #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wsuggest-attribute=format" sai_metadata_log = &sai_meta_log_syncd; #pragma GCC diagnostic pop EXIT_ON_ERROR(sai_api_initialize(0, (const service_method_table_t *)&test_services)); sai_metadata_apis_query(sai_api_query); sai_attribute_t attr; attr.id = SAI_REDIS_SWITCH_ATTR_USE_TEMP_VIEW; attr.value.booldata = g_useTempView; /* * Notice that we use null object id as switch id, which is fine since * those attributes don't need switch. */ sai_object_id_t switch_id = SAI_NULL_OBJECT_ID; EXIT_ON_ERROR(sai_metadata_sai_switch_api->set_switch_attribute(switch_id, &attr)); int exitcode = replay(argc, argv); sai_api_uninitialize(); return exitcode; }
void Config::parse(int argc, char **argv) { // parse command line try { po::store(po::parse_command_line(argc, argv, optdesc_), opts_); po::notify(opts_); } catch (std::exception &e) { error_ = e.what(); return; } // fill in internal variables with values received from command line handleCmdLine(); // parse configuration file only if command line is correct if (ok_) { parseConfig(); } }
int main(int argc, char **argv) { swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG); SWSS_LOG_ENTER(); auto options = handleCmdLine(argc, argv); handleProfileMap(options.profileMapFile); swss::DBConnector *db = new swss::DBConnector(ASIC_DB, "localhost", 6379, 0); swss::DBConnector *dbNtf = new swss::DBConnector(ASIC_DB, "localhost", 6379, 0); g_redisClient = new swss::RedisClient(db); updateLogLevel(); swss::ConsumerTable *asicState = new swss::ConsumerTable(db, "ASIC_STATE"); swss::NotificationConsumer *notifySyncdQuery = new swss::NotificationConsumer(db, "NOTIFYSYNCDREQUERY"); swss::NotificationConsumer *restartQuery = new swss::NotificationConsumer(db, "RESTARTQUERY"); // at the end we cant use producer consumer concept since // if one proces will restart there may be something in the queue // also "remove" from response queue will also trigger another "response" getRequest = new swss::ConsumerTable(db, "GETREQUEST"); getResponse = new swss::ProducerTable(db, "GETRESPONSE"); notifications = new swss::NotificationProducer(dbNtf, "NOTIFICATIONS"); notifySyncdResponse = new swss::NotificationProducer(db, "NOTIFYSYNCDRESPONSE"); #ifdef MLNXSAI /* This file is included in Mellanox SAI package. */ std::string mlnx_config_file = "/usr/share/sai_2700.xml"; gProfileMap[SAI_KEY_INIT_CONFIG_FILE] = mlnx_config_file; #endif /* MLNX_SAI */ g_veryFirstRun = isVeryFirstRun(); if (options.warmStart) { const char *warmBootReadFile = profile_get_value(0, SAI_KEY_WARM_BOOT_READ_FILE); SWSS_LOG_NOTICE("using warmBootReadFile: '%s'", warmBootReadFile); if (warmBootReadFile == NULL || access(warmBootReadFile, F_OK) == -1) { SWSS_LOG_WARN("user requested warmStart but warmBootReadFile is not specified or not accesible, forcing cold start"); options.warmStart = false; } } if (options.warmStart && g_veryFirstRun) { SWSS_LOG_WARN("warm start requested, but this is very first syncd start, forcing cold start"); // we force cold start since if it's first run then redis db is not complete // so redis asic view will not reflect warm boot asic state, if this happen // then orch agent needs to be restarted as well to repopulate asic view options.warmStart = false; } // gProfileMap[SAI_KEY_WARM_BOOT] = options.warmStart ? "1" : "0"; sai_api_initialize(0, (service_method_table_t*)&test_services); populate_sai_apis(); initialize_common_api_pointers(); sai_status_t status = sai_switch_api->initialize_switch(0, "0xb850", "", &switch_notifications); if (status != SAI_STATUS_SUCCESS) { SWSS_LOG_ERROR("fail to sai_initialize_switch: %d", status); exit(EXIT_FAILURE); } #ifdef BRCMSAI if (options.diagShell) { SWSS_LOG_NOTICE("starting bcm diag shell thread"); std::thread bcm_diag_shell_thread = std::thread(sai_diag_shell); bcm_diag_shell_thread.detach(); } #endif /* BRCMSAI */ SWSS_LOG_NOTICE("syncd started"); bool warmRestartHint = false; try { onSyncdStart(options.warmStart); if (options.disableCountersThread == false) { SWSS_LOG_NOTICE("starting counters thread"); startCountersThread(options.countersThreadIntervalInSeconds); } SWSS_LOG_NOTICE("syncd listening for events"); swss::Select s; s.addSelectable(getRequest); s.addSelectable(asicState); s.addSelectable(notifySyncdQuery); s.addSelectable(restartQuery); while(true) { swss::Selectable *sel; int fd; int result = s.select(&sel, &fd); if (sel == restartQuery) { warmRestartHint = handleRestartQuery(*restartQuery); break; } if (sel == notifySyncdQuery) { notifySyncd(*notifySyncdQuery); continue; } if (result == swss::Select::OBJECT) { processEvent(*(swss::ConsumerTable*)sel); } } } catch(const std::exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); exit(EXIT_FAILURE); } endCountersThread(); if (warmRestartHint) { const char *warmBootWriteFile = profile_get_value(0, SAI_KEY_WARM_BOOT_WRITE_FILE); SWSS_LOG_NOTICE("using warmBootWriteFile: '%s'", warmBootWriteFile); if (warmBootWriteFile == NULL) { SWSS_LOG_WARN("user requested warm shutdown but warmBootWriteFile is not specified, forcing cold shutdown"); warmRestartHint = false; } } sai_switch_api->shutdown_switch(warmRestartHint); SWSS_LOG_NOTICE("calling api uninitialize"); sai_api_uninitialize(); SWSS_LOG_NOTICE("uninitialize finished"); return EXIT_SUCCESS; }