diff --git a/cfgmgr/buffermgrd.cpp b/cfgmgr/buffermgrd.cpp index 05740eea1c..bdaec8553f 100644 --- a/cfgmgr/buffermgrd.cpp +++ b/cfgmgr/buffermgrd.cpp @@ -1,17 +1,17 @@ -#include "buffermgr.h" -#include "buffermgrdyn.h" +#include +#include +#include +#include #include "dbconnector.h" +#include "select.h" #include "exec.h" -#include "json.h" -#include "json.hpp" #include "schema.h" -#include "select.h" +#include "buffermgr.h" +#include "buffermgrdyn.h" #include -#include #include -#include -#include -#include +#include "json.h" +#include "json.hpp" using namespace std; using namespace swss; @@ -56,7 +56,7 @@ void dump_db_item(KeyOpFieldsValuesTuple &db_item) SWSS_LOG_DEBUG("\toperation: %s", kfvOp(db_item).c_str()); SWSS_LOG_DEBUG("\thash: %s", kfvKey(db_item).c_str()); SWSS_LOG_DEBUG("\tfields: ["); - for (auto fv : kfvFieldsValues(db_item)) + for (auto fv: kfvFieldsValues(db_item)) SWSS_LOG_DEBUG("\t\tfield: %s value: %s", fvField(fv).c_str(), fvValue(fv).c_str()); SWSS_LOG_DEBUG("\t]"); SWSS_LOG_DEBUG("]"); @@ -119,7 +119,7 @@ int main(int argc, char **argv) SWSS_LOG_NOTICE("--- Starting buffermgrd ---"); - while ((opt = getopt(argc, argv, "l:a:p:h")) != -1) + while ((opt = getopt(argc, argv, "l:a:p:h")) != -1 ) { switch (opt) { @@ -162,7 +162,7 @@ int main(int argc, char **argv) if (!peripherial_table_file.empty()) { - // Load the json file containing the PERIPHERIAL_TABLE + //Load the json file containing the PERIPHERIAL_TABLE db_items_ptr = load_json(peripherial_table_file); if (nullptr != db_items_ptr) write_to_state_db(db_items_ptr); @@ -240,7 +240,7 @@ int main(int argc, char **argv) c->execute(); } } - catch (const std::exception &e) + catch(const std::exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); } diff --git a/cfgmgr/coppmgrd.cpp b/cfgmgr/coppmgrd.cpp index 1e330d8c97..60b0a2442a 100644 --- a/cfgmgr/coppmgrd.cpp +++ b/cfgmgr/coppmgrd.cpp @@ -4,8 +4,8 @@ #include #include -#include "coppmgr.h" #include "exec.h" +#include "coppmgr.h" #include "schema.h" #include "select.h" #include "warm_restart.h" diff --git a/cfgmgr/intfmgrd.cpp b/cfgmgr/intfmgrd.cpp index 69195cb760..9ed3653333 100644 --- a/cfgmgr/intfmgrd.cpp +++ b/cfgmgr/intfmgrd.cpp @@ -1,14 +1,14 @@ +#include +#include +#include #include "dbconnector.h" +#include "select.h" #include "exec.h" -#include "intfmgr.h" #include "schema.h" -#include "select.h" -#include "warm_restart.h" +#include "intfmgr.h" #include #include -#include -#include -#include +#include "warm_restart.h" using namespace std; using namespace swss; @@ -94,7 +94,7 @@ int main(int argc, char **argv) c->execute(); } } - catch (const std::exception &e) + catch(const std::exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); } diff --git a/cfgmgr/macsecmgrd.cpp b/cfgmgr/macsecmgrd.cpp index 3f8bfd6545..913c0ac4ee 100644 --- a/cfgmgr/macsecmgrd.cpp +++ b/cfgmgr/macsecmgrd.cpp @@ -1,19 +1,19 @@ -#include +#include +#include +#include #include #include #include -#include -#include -#include +#include -#include #include -#include #include -#include -#include +#include +#include #include +#include #include +#include #include "macsecmgr.h" @@ -45,6 +45,7 @@ string gResponsePublisherRecordFile; /* Global database mutex */ mutex gDbMutex; + int main(int argc, char **argv) { @@ -93,7 +94,7 @@ int main(int argc, char **argv) c->execute(); } } - catch (const std::exception &e) + catch(const std::exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); } diff --git a/cfgmgr/natmgrd.cpp b/cfgmgr/natmgrd.cpp index 4e4f8ea302..c2baf7eb87 100644 --- a/cfgmgr/natmgrd.cpp +++ b/cfgmgr/natmgrd.cpp @@ -14,24 +14,24 @@ * limitations under the License. */ +#include +#include +#include +#include +#include +#include +#include +#include #include "dbconnector.h" +#include "select.h" #include "exec.h" +#include "schema.h" #include "macaddress.h" -#include "natmgr.h" -#include "notificationproducer.h" #include "producerstatetable.h" -#include "schema.h" -#include "select.h" +#include "notificationproducer.h" +#include "natmgr.h" #include "shellcmd.h" #include "warm_restart.h" -#include -#include -#include -#include -#include -#include -#include -#include using namespace std; using namespace swss; @@ -47,20 +47,20 @@ using namespace swss; * Once Orch class refactoring is done, these global variables * should be removed from here. */ -int gBatchSize = 0; -bool gSwssRecord = false; -bool gLogRotate = false; -ofstream gRecordOfs; -string gRecordFile; -bool gResponsePublisherRecord = false; -bool gResponsePublisherLogRotate = false; -ofstream gResponsePublisherRecordOfs; -string gResponsePublisherRecordFile; -mutex gDbMutex; -NatMgr *natmgr = NULL; - -NotificationConsumer *timeoutNotificationsConsumer = NULL; -NotificationConsumer *flushNotificationsConsumer = NULL; +int gBatchSize = 0; +bool gSwssRecord = false; +bool gLogRotate = false; +ofstream gRecordOfs; +string gRecordFile; +bool gResponsePublisherRecord = false; +bool gResponsePublisherLogRotate = false; +ofstream gResponsePublisherRecordOfs; +string gResponsePublisherRecordFile; +mutex gDbMutex; +NatMgr *natmgr = NULL; + +NotificationConsumer *timeoutNotificationsConsumer = NULL; +NotificationConsumer *flushNotificationsConsumer = NULL; std::shared_ptr cleanupNotifier; @@ -68,7 +68,7 @@ void sigterm_handler(int signo) { int ret = 0; std::string res; - const std::string conntrackFlush = "conntrack -F"; + const std::string conntrackFlush = "conntrack -F"; SWSS_LOG_NOTICE("Got SIGTERM"); @@ -88,7 +88,7 @@ void sigterm_handler(int signo) cleanupNotifier->send("nat_cleanup", "all", entry); } - + if (natmgr) { natmgr->removeStaticNatIptables(); @@ -138,7 +138,7 @@ int main(int argc, char **argv) natmgr = new NatMgr(&cfgDb, &appDb, &stateDb, cfg_tables); natmgr->isPortInitDone(&appDb); - + std::vector cfgOrchList = {natmgr}; swss::Select s; @@ -168,24 +168,24 @@ int main(int argc, char **argv) if (sel == timeoutNotificationsConsumer) { - std::string op; - std::string data; - std::vector values; + std::string op; + std::string data; + std::vector values; - timeoutNotificationsConsumer->pop(op, data, values); - natmgr->timeoutNotifications(op, data); - continue; + timeoutNotificationsConsumer->pop(op, data, values); + natmgr->timeoutNotifications(op, data); + continue; } if (sel == flushNotificationsConsumer) { - std::string op; - std::string data; - std::vector values; + std::string op; + std::string data; + std::vector values; - flushNotificationsConsumer->pop(op, data, values); - natmgr->flushNotifications(op, data); - continue; + flushNotificationsConsumer->pop(op, data, values); + natmgr->flushNotifications(op, data); + continue; } if (ret == Select::TIMEOUT) @@ -198,7 +198,7 @@ int main(int argc, char **argv) c->execute(); } } - catch (const std::exception &e) + catch(const std::exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); } diff --git a/cfgmgr/nbrmgrd.cpp b/cfgmgr/nbrmgrd.cpp index 203490c0ca..338d8d9d0d 100644 --- a/cfgmgr/nbrmgrd.cpp +++ b/cfgmgr/nbrmgrd.cpp @@ -1,14 +1,14 @@ -#include -#include -#include -#include #include #include +#include +#include +#include +#include +#include "select.h" #include "exec.h" -#include "nbrmgr.h" #include "schema.h" -#include "select.h" +#include "nbrmgr.h" #include "warm_restart.h" using namespace std; @@ -67,8 +67,8 @@ int main(int argc, char **argv) chrono::steady_clock::time_point starttime = chrono::steady_clock::now(); while (!nbrmgr.isNeighRestoreDone()) { - chrono::duration time_span = - chrono::duration_cast>(chrono::steady_clock::now() - starttime); + chrono::duration time_span = chrono::duration_cast> + (chrono::steady_clock::now() - starttime); int pasttime = int(time_span.count()); SWSS_LOG_INFO("Kernel neighbor table restoration waited for %d seconds", pasttime); if (pasttime > RESTORE_NEIGH_WAIT_TIME_OUT) @@ -110,7 +110,7 @@ int main(int argc, char **argv) c->execute(); } } - catch (const std::exception &e) + catch(const std::exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); } diff --git a/cfgmgr/sflowmgrd.cpp b/cfgmgr/sflowmgrd.cpp index 30118aadfc..7de5f15a2d 100644 --- a/cfgmgr/sflowmgrd.cpp +++ b/cfgmgr/sflowmgrd.cpp @@ -5,9 +5,9 @@ #include #include "exec.h" +#include "sflowmgr.h" #include "schema.h" #include "select.h" -#include "sflowmgr.h" using namespace std; using namespace swss; diff --git a/cfgmgr/teammgrd.cpp b/cfgmgr/teammgrd.cpp index 871f17476f..66bfa4b6d2 100644 --- a/cfgmgr/teammgrd.cpp +++ b/cfgmgr/teammgrd.cpp @@ -1,9 +1,9 @@ #include +#include "teammgr.h" #include "netdispatcher.h" #include "netlink.h" #include "select.h" -#include "teammgr.h" #include "warm_restart.h" #include @@ -64,7 +64,7 @@ int main(int argc, char **argv) vector cfgOrchList = {&teammgr}; Select s; - for (Orch *o : cfgOrchList) + for (Orch *o: cfgOrchList) { s.addSelectables(o->getSelectables()); } diff --git a/cfgmgr/tunnelmgrd.cpp b/cfgmgr/tunnelmgrd.cpp index 2147784ff3..0165eb94b5 100644 --- a/cfgmgr/tunnelmgrd.cpp +++ b/cfgmgr/tunnelmgrd.cpp @@ -1,15 +1,15 @@ -#include +#include +#include +#include #include #include #include -#include -#include -#include +#include #include "dbconnector.h" +#include "select.h" #include "exec.h" #include "schema.h" -#include "select.h" #include "tunnelmgr.h" using namespace std; @@ -86,7 +86,7 @@ int main(int argc, char **argv) c->execute(); } } - catch (const std::exception &e) + catch(const std::exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); } diff --git a/cfgmgr/vlanmgrd.cpp b/cfgmgr/vlanmgrd.cpp index de737ed4ee..b69dc78122 100644 --- a/cfgmgr/vlanmgrd.cpp +++ b/cfgmgr/vlanmgrd.cpp @@ -1,19 +1,19 @@ +#include +#include +#include +#include +#include +#include +#include #include "dbconnector.h" +#include "select.h" #include "exec.h" +#include "schema.h" #include "macaddress.h" #include "producerstatetable.h" -#include "schema.h" -#include "select.h" -#include "shellcmd.h" #include "vlanmgr.h" +#include "shellcmd.h" #include "warm_restart.h" -#include -#include -#include -#include -#include -#include -#include using namespace std; using namespace swss; @@ -72,10 +72,8 @@ int main(int argc, char **argv) Table table(&cfgDb, "DEVICE_METADATA"); std::vector ovalues; table.get("localhost", ovalues); - auto it = - std::find_if(ovalues.begin(), ovalues.end(), [](const FieldValueTuple &t) { return t.first == "mac"; }); - if (it == ovalues.end()) - { + auto it = std::find_if( ovalues.begin(), ovalues.end(), [](const FieldValueTuple& t){ return t.first == "mac";} ); + if ( it == ovalues.end() ) { throw runtime_error("couldn't find MAC address of the device from config DB"); } gMacAddress = MacAddress(it->second); @@ -112,7 +110,7 @@ int main(int argc, char **argv) c->execute(); } } - catch (const std::exception &e) + catch(const std::exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); } diff --git a/cfgmgr/vrfmgrd.cpp b/cfgmgr/vrfmgrd.cpp index 3c19921d83..735e59191d 100644 --- a/cfgmgr/vrfmgrd.cpp +++ b/cfgmgr/vrfmgrd.cpp @@ -1,14 +1,14 @@ +#include +#include +#include #include "dbconnector.h" +#include "select.h" #include "exec.h" #include "schema.h" -#include "select.h" #include "vrfmgr.h" -#include "warm_restart.h" #include #include -#include -#include -#include +#include "warm_restart.h" using namespace std; using namespace swss; @@ -104,7 +104,7 @@ int main(int argc, char **argv) c->execute(); } } - catch (const std::exception &e) + catch(const std::exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); } diff --git a/cfgmgr/vxlanmgrd.cpp b/cfgmgr/vxlanmgrd.cpp index 58a1048a4a..d47893a614 100644 --- a/cfgmgr/vxlanmgrd.cpp +++ b/cfgmgr/vxlanmgrd.cpp @@ -1,19 +1,19 @@ +#include +#include +#include +#include +#include +#include +#include #include "dbconnector.h" +#include "select.h" #include "exec.h" +#include "schema.h" #include "macaddress.h" #include "producerstatetable.h" -#include "schema.h" -#include "select.h" -#include "shellcmd.h" #include "vxlanmgr.h" +#include "shellcmd.h" #include "warm_restart.h" -#include -#include -#include -#include -#include -#include -#include using namespace std; using namespace swss; @@ -87,10 +87,8 @@ int main(int argc, char **argv) Table table(&cfgDb, "DEVICE_METADATA"); std::vector ovalues; table.get("localhost", ovalues); - auto it = - std::find_if(ovalues.begin(), ovalues.end(), [](const FieldValueTuple &t) { return t.first == "mac"; }); - if (it == ovalues.end()) - { + auto it = std::find_if( ovalues.begin(), ovalues.end(), [](const FieldValueTuple& t){ return t.first == "mac";} ); + if ( it == ovalues.end() ) { throw runtime_error("couldn't find MAC address of the device from config DB"); } gMacAddress = MacAddress(it->second); @@ -136,7 +134,7 @@ int main(int argc, char **argv) c->execute(); } } - catch (const std::exception &e) + catch(const std::exception &e) { SWSS_LOG_ERROR("Runtime error: %s", e.what()); } diff --git a/orchagent/main.cpp b/orchagent/main.cpp index 5a761a850c..68fdcdfa87 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -1,37 +1,36 @@ -extern "C" -{ +extern "C" { #include "sai.h" #include "saistatus.h" } -#include #include -#include -#include #include +#include #include #include +#include +#include +#include +#include +#include #include #include #include #include -#include -#include -#include -#include "timestamp.h" #include +#include "timestamp.h" -#include #include +#include -#include "gearboxutils.h" -#include "notifications.h" #include "orchdaemon.h" #include "sai_serialize.h" #include "saihelper.h" -#include "warm_restart.h" +#include "notifications.h" #include +#include "warm_restart.h" +#include "gearboxutils.h" using namespace std; using namespace swss; @@ -39,7 +38,7 @@ using namespace swss; extern sai_switch_api_t *sai_switch_api; extern sai_router_interface_api_t *sai_router_intfs_api; -#define UNREFERENCED_PARAMETER(P) (P) +#define UNREFERENCED_PARAMETER(P) (P) #define UNDERLAY_RIF_DEFAULT_MTU 9100 @@ -52,7 +51,7 @@ MacAddress gVxlanMacAddress; extern size_t gMaxBulkSize; -#define DEFAULT_BATCH_SIZE 128 +#define DEFAULT_BATCH_SIZE 128 int gBatchSize = DEFAULT_BATCH_SIZE; bool gSairedisRecord = true; @@ -85,9 +84,7 @@ string gMyAsicName = ""; void usage() { - cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-f swss_rec_filename] [-j " - "sairedis_rec_filename] [-b batch_size] [-m MAC] [-i INST_ID] [-s] [-z mode] [-k bulk_size]" - << endl; + cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-f swss_rec_filename] [-j sairedis_rec_filename] [-b batch_size] [-m MAC] [-i INST_ID] [-s] [-z mode] [-k bulk_size]" << endl; cout << " -h: display this message" << endl; cout << " -r record_type: record orchagent logs with type (default 7)" << endl; cout << " Bit 0: sairedis.rec, Bit 1: swss.rec, Bit 2: responsepublisher.rec. For example:" << endl; @@ -139,10 +136,10 @@ void syncd_apply_view() * Create and initialize the external Gearbox PHYs. Upon success, store the * new PHY OID in the database to be used later when creating the Gearbox * ports. - */ +*/ void init_gearbox_phys(DBConnector *applDb) { - Table *tmpGearboxTable = new Table(applDb, "_GEARBOX_TABLE"); + Table* tmpGearboxTable = new Table(applDb, "_GEARBOX_TABLE"); map gearboxPhyMap; GearboxUtils gearbox; @@ -358,7 +355,7 @@ int main(int argc, char **argv) // If longer, truncate into a string gAsicInstance.assign(optarg, len); } - break; + break; case 'm': gMacAddress = MacAddress(optarg); break; @@ -416,7 +413,7 @@ int main(int argc, char **argv) SWSS_LOG_ERROR("Invalid input for maximum bulk size in bulk mode: %d. Ignoring.", limit); } } - break; + break; default: /* '?' */ exit(EXIT_FAILURE); } @@ -438,9 +435,12 @@ int main(int argc, char **argv) attrs.push_back(attr); // Initialize recording parameters. - gSairedisRecord = (record_type & SAIREDIS_RECORD_ENABLE) == SAIREDIS_RECORD_ENABLE; + gSairedisRecord = + (record_type & SAIREDIS_RECORD_ENABLE) == SAIREDIS_RECORD_ENABLE; gSwssRecord = (record_type & SWSS_RECORD_ENABLE) == SWSS_RECORD_ENABLE; - gResponsePublisherRecord = (record_type & RESPONSE_PUBLISHER_RECORD_ENABLE) == RESPONSE_PUBLISHER_RECORD_ENABLE; + gResponsePublisherRecord = + (record_type & RESPONSE_PUBLISHER_RECORD_ENABLE) == + RESPONSE_PUBLISHER_RECORD_ENABLE; /* Disable/enable SwSS recording */ if (gSwssRecord) @@ -521,7 +521,8 @@ int main(int argc, char **argv) // Get info required for VOQ system and connect to CHASSISS_APP_DB shared_ptr chassis_app_db; vector sysportconfiglist; - if ((gMySwitchType == "voq") && (getSystemPortConfigList(&config_db, &appl_db, sysportconfiglist))) + if ((gMySwitchType == "voq") && + (getSystemPortConfigList(&config_db, &appl_db, sysportconfiglist))) { attr.id = SAI_SWITCH_ATTR_TYPE; attr.value.u32 = SAI_SWITCH_TYPE_VOQ; @@ -574,6 +575,7 @@ int main(int argc, char **argv) } SWSS_LOG_NOTICE("Create a switch, id:%" PRIu64, gSwitchId); + if (gMySwitchType != "fabric") { /* Get switch source MAC address if not provided */ @@ -637,8 +639,7 @@ int main(int argc, char **argv) underlay_intf_attr.value.u32 = UNDERLAY_RIF_DEFAULT_MTU; underlay_intf_attrs.push_back(underlay_intf_attr); - status = sai_router_intfs_api->create_router_interface( - &gUnderlayIfId, gSwitchId, (uint32_t)underlay_intf_attrs.size(), underlay_intf_attrs.data()); + status = sai_router_intfs_api->create_router_interface(&gUnderlayIfId, gSwitchId, (uint32_t)underlay_intf_attrs.size(), underlay_intf_attrs.data()); if (status != SAI_STATUS_SUCCESS) { SWSS_LOG_ERROR("Failed to create underlay router interface %d", status); @@ -673,9 +674,9 @@ int main(int argc, char **argv) } /* - * In syncd view comparison solution, apply view has been sent - * immediately after restore is done - */ + * In syncd view comparison solution, apply view has been sent + * immediately after restore is done + */ if (!WarmStart::isWarmStart()) { syncd_apply_view(); diff --git a/orchagent/orch.cpp b/orchagent/orch.cpp index 5ba97e7b81..d043542d91 100644 --- a/orchagent/orch.cpp +++ b/orchagent/orch.cpp @@ -1,19 +1,19 @@ -#include "orch.h" -#include "timestamp.h" #include -#include #include +#include #include #include #include +#include "timestamp.h" +#include "orch.h" -#include "consumerstatetable.h" +#include "subscriberstatetable.h" #include "converter.h" -#include "logger.h" #include "portsorch.h" -#include "sai_serialize.h" -#include "subscriberstatetable.h" #include "tokenize.h" +#include "logger.h" +#include "consumerstatetable.h" +#include "sai_serialize.h" using namespace swss; @@ -75,6 +75,7 @@ void Consumer::addToSync(const KeyOpFieldsValuesTuple &entry) { SWSS_LOG_ENTER(); + string key = kfvKey(entry); string op = kfvOp(entry); @@ -85,10 +86,10 @@ void Consumer::addToSync(const KeyOpFieldsValuesTuple &entry) } /* - * m_toSync is a multimap which will allow one key with multiple values, - * Also, the order of the key-value pairs whose keys compare equivalent - * is the order of insertion and does not change. (since C++11) - */ + * m_toSync is a multimap which will allow one key with multiple values, + * Also, the order of the key-value pairs whose keys compare equivalent + * is the order of insertion and does not change. (since C++11) + */ /* If a new task comes we directly put it into getConsumerTable().m_toSync map */ if (m_toSync.find(key) == m_toSync.end()) @@ -105,16 +106,16 @@ void Consumer::addToSync(const KeyOpFieldsValuesTuple &entry) else { /* - * Now we are trying to add the key-value with SET. - * We maintain maximum two values per key. - * In case there is one key-value, it should be DEL or SET - * In case there are two key-value pairs, it should be DEL then SET - * The code logic is following: - * We iterate the values with the key, we skip the value with DEL and then - * check if that was the only one (I,E, the iter pointer now points to end or next key), - * in such case, we insert the key-value with SET. - * If there was a SET already (I,E, the pointer still points to the same key), we combine the kfv. - */ + * Now we are trying to add the key-value with SET. + * We maintain maximum two values per key. + * In case there is one key-value, it should be DEL or SET + * In case there are two key-value pairs, it should be DEL then SET + * The code logic is following: + * We iterate the values with the key, we skip the value with DEL and then + * check if that was the only one (I,E, the iter pointer now points to end or next key), + * in such case, we insert the key-value with SET. + * If there was a SET already (I,E, the pointer still points to the same key), we combine the kfv. + */ auto ret = m_toSync.equal_range(key); auto iter = ret.first; for (; iter != ret.second; ++iter) @@ -134,6 +135,7 @@ void Consumer::addToSync(const KeyOpFieldsValuesTuple &entry) auto new_values = kfvFieldsValues(entry); auto existing_values = kfvFieldsValues(existing_data); + for (auto it : new_values) { string field = fvField(it); @@ -153,6 +155,7 @@ void Consumer::addToSync(const KeyOpFieldsValuesTuple &entry) iter->second = KeyOpFieldsValuesTuple(key, op, existing_values); } } + } size_t Consumer::addToSync(const std::deque &entries) @@ -509,7 +512,7 @@ void Orch::dumpPendingTasks(vector &ts) { for (auto &it : m_consumerMap) { - Consumer *consumer = dynamic_cast(it.second.get()); + Consumer* consumer = dynamic_cast(it.second.get()); if (consumer == NULL) { SWSS_LOG_DEBUG("Executor is not a Consumer"); @@ -696,53 +699,53 @@ task_process_status Orch::handleSaiCreateStatus(sai_api_t api, sai_status_t stat */ switch (api) { - case SAI_API_FDB: - switch (status) - { - case SAI_STATUS_SUCCESS: - SWSS_LOG_WARN("SAI_STATUS_SUCCESS is not expected in handleSaiCreateStatus"); - return task_success; - case SAI_STATUS_ITEM_ALREADY_EXISTS: - /* - * In FDB creation, there are scenarios where the hardware learns an FDB entry before orchagent. - * In such cases, the FDB SAI creation would report the status of SAI_STATUS_ITEM_ALREADY_EXISTS, - * and orchagent should ignore the error and treat it as entry was explicitly created. - */ - return task_success; - default: - SWSS_LOG_ERROR("Encountered failure in create operation, exiting orchagent, SAI API: %s, status: %s", - sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); - exit(EXIT_FAILURE); - } - break; - case SAI_API_HOSTIF: - switch (status) - { - case SAI_STATUS_SUCCESS: - return task_success; - case SAI_STATUS_FAILURE: - /* - * Host interface maybe failed due to lane not available. - * In some scenarios, like SONiC virtual machine, the invalid lane may be not enabled by VM configuration, - * So just ignore the failure and report an error log. - */ - return task_ignore; - default: - SWSS_LOG_ERROR("Encountered failure in create operation, exiting orchagent, SAI API: %s, status: %s", - sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); - exit(EXIT_FAILURE); - } - default: - switch (status) - { - case SAI_STATUS_SUCCESS: - SWSS_LOG_WARN("SAI_STATUS_SUCCESS is not expected in handleSaiCreateStatus"); - return task_success; + case SAI_API_FDB: + switch (status) + { + case SAI_STATUS_SUCCESS: + SWSS_LOG_WARN("SAI_STATUS_SUCCESS is not expected in handleSaiCreateStatus"); + return task_success; + case SAI_STATUS_ITEM_ALREADY_EXISTS: + /* + * In FDB creation, there are scenarios where the hardware learns an FDB entry before orchagent. + * In such cases, the FDB SAI creation would report the status of SAI_STATUS_ITEM_ALREADY_EXISTS, + * and orchagent should ignore the error and treat it as entry was explicitly created. + */ + return task_success; + default: + SWSS_LOG_ERROR("Encountered failure in create operation, exiting orchagent, SAI API: %s, status: %s", + sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); + exit(EXIT_FAILURE); + } + break; + case SAI_API_HOSTIF: + switch (status) + { + case SAI_STATUS_SUCCESS: + return task_success; + case SAI_STATUS_FAILURE: + /* + * Host interface maybe failed due to lane not available. + * In some scenarios, like SONiC virtual machine, the invalid lane may be not enabled by VM configuration, + * So just ignore the failure and report an error log. + */ + return task_ignore; + default: + SWSS_LOG_ERROR("Encountered failure in create operation, exiting orchagent, SAI API: %s, status: %s", + sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); + exit(EXIT_FAILURE); + } default: - SWSS_LOG_ERROR("Encountered failure in create operation, exiting orchagent, SAI API: %s, status: %s", - sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); - exit(EXIT_FAILURE); - } + switch (status) + { + case SAI_STATUS_SUCCESS: + SWSS_LOG_WARN("SAI_STATUS_SUCCESS is not expected in handleSaiCreateStatus"); + return task_success; + default: + SWSS_LOG_ERROR("Encountered failure in create operation, exiting orchagent, SAI API: %s, status: %s", + sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); + exit(EXIT_FAILURE); + } } return task_need_retry; } @@ -768,26 +771,26 @@ task_process_status Orch::handleSaiSetStatus(sai_api_t api, sai_status_t status, switch (api) { - case SAI_API_PORT: - switch (status) - { - case SAI_STATUS_INVALID_ATTR_VALUE_0: - /* - * If user gives an invalid attribute value, no need to retry or exit orchagent, just fail the current task - * and let user correct the configuration. - */ - SWSS_LOG_ERROR("Encountered SAI_STATUS_INVALID_ATTR_VALUE_0 in set operation, task failed, SAI API: %s, status: %s", - sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); - return task_failed; + case SAI_API_PORT: + switch (status) + { + case SAI_STATUS_INVALID_ATTR_VALUE_0: + /* + * If user gives an invalid attribute value, no need to retry or exit orchagent, just fail the current task + * and let user correct the configuration. + */ + SWSS_LOG_ERROR("Encountered SAI_STATUS_INVALID_ATTR_VALUE_0 in set operation, task failed, SAI API: %s, status: %s", + sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); + return task_failed; + default: + SWSS_LOG_ERROR("Encountered failure in set operation, exiting orchagent, SAI API: %s, status: %s", + sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); + exit(EXIT_FAILURE); + } default: SWSS_LOG_ERROR("Encountered failure in set operation, exiting orchagent, SAI API: %s, status: %s", - sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); + sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); exit(EXIT_FAILURE); - } - default: - SWSS_LOG_ERROR("Encountered failure in set operation, exiting orchagent, SAI API: %s, status: %s", - sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); - exit(EXIT_FAILURE); } return task_need_retry; @@ -809,13 +812,13 @@ task_process_status Orch::handleSaiRemoveStatus(sai_api_t api, sai_status_t stat */ switch (status) { - case SAI_STATUS_SUCCESS: - SWSS_LOG_WARN("SAI_STATUS_SUCCESS is not expected in handleSaiRemoveStatus"); - return task_success; - default: - SWSS_LOG_ERROR("Encountered failure in remove operation, exiting orchagent, SAI API: %s, status: %s", - sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); - exit(EXIT_FAILURE); + case SAI_STATUS_SUCCESS: + SWSS_LOG_WARN("SAI_STATUS_SUCCESS is not expected in handleSaiRemoveStatus"); + return task_success; + default: + SWSS_LOG_ERROR("Encountered failure in remove operation, exiting orchagent, SAI API: %s, status: %s", + sai_serialize_api(api).c_str(), sai_serialize_status(status).c_str()); + exit(EXIT_FAILURE); } return task_need_retry; } @@ -858,12 +861,12 @@ bool Orch::parseHandleSaiStatusFailure(task_process_status status) */ switch (status) { - case task_need_retry: - return false; - case task_failed: - return true; - default: - SWSS_LOG_WARN("task_process_status %d is not expected in parseHandleSaiStatusFailure", status); + case task_need_retry: + return false; + case task_failed: + return true; + default: + SWSS_LOG_WARN("task_process_status %d is not expected in parseHandleSaiStatusFailure", status); } return true; } diff --git a/orchagent/orch.h b/orchagent/orch.h index 383e61da18..806935158a 100644 --- a/orchagent/orch.h +++ b/orchagent/orch.h @@ -1,27 +1,26 @@ #ifndef SWSS_ORCH_H #define SWSS_ORCH_H -#include -#include -#include #include #include +#include +#include +#include #include -extern "C" -{ +extern "C" { #include "sai.h" #include "saistatus.h" } -#include "consumerstatetable.h" -#include "consumertable.h" #include "dbconnector.h" -#include "macaddress.h" +#include "table.h" +#include "consumertable.h" +#include "consumerstatetable.h" #include "notificationconsumer.h" -#include "response_publisher.h" #include "selectabletimer.h" -#include "table.h" +#include "macaddress.h" +#include "response_publisher.h" const char delimiter = ':'; const char list_item_delimiter = ','; @@ -89,7 +88,7 @@ class Orch; // 3. Executor will hold an pointer to new-ed selectable, and delete it during dtor class Executor : public swss::Selectable { - public: +public: Executor(swss::Selectable *selectable, Orch *orch, const std::string &name) : m_selectable(selectable) , m_orch(orch) @@ -119,7 +118,7 @@ class Executor : public swss::Selectable return m_name; } - protected: +protected: swss::Selectable *m_selectable; Orch *m_orch; @@ -192,7 +191,7 @@ typedef std::pair> TablesConnector class Orch { - public: +public: Orch(swss::DBConnector *db, const std::string tableName, int pri = default_orch_pri); Orch(swss::DBConnector *db, const std::vector &tableNames); Orch(swss::DBConnector *db, const std::vector &tableNameWithPri); @@ -221,8 +220,7 @@ class Orch static void recordTuple(Consumer &consumer, const swss::KeyOpFieldsValuesTuple &tuple); void dumpPendingTasks(std::vector &ts); - - protected: +protected: ConsumerMap m_consumerMap; static void logfileReopen(); @@ -248,8 +246,7 @@ class Orch bool parseHandleSaiStatusFailure(task_process_status status); ResponsePublisher m_publisher; - - private: +private: void removeMeFromObjsReferencedByMe(type_map &type_maps, const std::string &table, const std::string &obj_name, const std::string &field, const std::string &old_referenced_obj_name); void addConsumer(swss::DBConnector *db, std::string tableName, int pri = default_orch_pri); };