diff --git a/orchagent/Makefile.am b/orchagent/Makefile.am index f94e6d3bfa..abb7a27336 100644 --- a/orchagent/Makefile.am +++ b/orchagent/Makefile.am @@ -107,6 +107,7 @@ orchagent_SOURCES = \ response_publisher.cpp \ nvgreorch.cpp \ zmqorch.cpp \ + dbggendumporch.cpp\ dash/dashorch.cpp \ dash/dashrouteorch.cpp \ dash/dashvnetorch.cpp \ diff --git a/orchagent/dbggendumporch.cpp b/orchagent/dbggendumporch.cpp new file mode 100644 index 0000000000..7a380b69a4 --- /dev/null +++ b/orchagent/dbggendumporch.cpp @@ -0,0 +1,55 @@ +#include "dbggendumporch.h" +#include "schema.h" + +using namespace std; +using namespace swss; + +DbgGenDumpOrch::DbgGenDumpOrch(TableConnector dbConnector, const std::string statusTableName): + Orch(dbConnector.first, dbConnector.second), + m_dbDumpTable(dbConnector.first, statusTableName) +{ + SWSS_LOG_ENTER(); +} + +DbgGenDumpOrch::~DbgGenDumpOrch() +{ + SWSS_LOG_ENTER(); +} + +void DbgGenDumpOrch::doTask(Consumer &consumer) +{ + SWSS_LOG_ENTER(); + auto it = consumer.m_toSync.begin(); + while (it != consumer.m_toSync.end()) + { + if (consumer.getTableName() == APP_DBG_GEN_DUMP_TABLE_NAME) + { + KeyOpFieldsValuesTuple t = it->second; + string op = kfvOp(t); + if (op == SET_COMMAND) + { + auto& fieldValues = kfvFieldsValues(t); + auto value = fvValue(fieldValues[0]); + const char* value_cstr = value.c_str(); + SWSS_LOG_INFO("call sai_dbg_generate_dump with file %s\n", value_cstr); + sai_status_t ret = sai_dbg_generate_dump(value_cstr); + if (ret != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("Failed to generate dbg dump file %s\n", value_cstr); + } + else + { + SWSS_LOG_DEBUG("generate dbg dump file %s successfully\n", value_cstr); + } + + //write to state DB the return status to inform the caller + string ret_str = std::to_string(ret); + string key = kfvKey(t); + std::vector fvTuples; + fvTuples.push_back(swss::FieldValueTuple("status", ret_str)); + m_dbDumpTable.set(key, fvTuples); + } + } + consumer.m_toSync.erase(it++); + } +} diff --git a/orchagent/dbggendumporch.h b/orchagent/dbggendumporch.h new file mode 100644 index 0000000000..e3cab1d06d --- /dev/null +++ b/orchagent/dbggendumporch.h @@ -0,0 +1,30 @@ +#ifndef SWSS_DBG_GEN_DUMP_H +#define SWSS_DBG_GEN_DUMP_H + +#include "orch.h" +#include "dbconnector.h" +#include "table.h" +#include + +using namespace std; +using namespace swss; + +extern "C" { +#include "sai.h" +} + +class DbgGenDumpOrch : public Orch +{ +public: + DbgGenDumpOrch(TableConnector dbConnector, const std::string statusTableName); + + ~DbgGenDumpOrch(); + + void doTask(Consumer& consumer); + +private: + Table m_dbDumpTable; + +}; + +#endif /* SWSS_DBG_GEN_DUMP_H */ diff --git a/orchagent/orchdaemon.cpp b/orchagent/orchdaemon.cpp index 13ef89c487..8d5837bd15 100644 --- a/orchagent/orchdaemon.cpp +++ b/orchagent/orchdaemon.cpp @@ -781,6 +781,10 @@ bool OrchDaemon::init() TwampOrch *twamp_orch = new TwampOrch(confDbTwampTable, stateDbTwampTable, gSwitchOrch, gPortsOrch, vrf_orch); m_orchList.push_back(twamp_orch); + TableConnector applDbDgbGenDumpTable(m_applDb, APP_DBG_GEN_DUMP_TABLE_NAME); + auto* gDbgGenDumpOrch = new DbgGenDumpOrch(applDbDgbGenDumpTable, APP_DBG_GEN_DUMP_STATUS_TABLE_NAME); + m_orchList.push_back(gDbgGenDumpOrch); + if (WarmStart::isWarmStart()) { bool suc = warmRestoreAndSyncUp(); diff --git a/orchagent/orchdaemon.h b/orchagent/orchdaemon.h index 6a1c0b999a..da6efe76f5 100644 --- a/orchagent/orchdaemon.h +++ b/orchagent/orchdaemon.h @@ -53,6 +53,7 @@ #include "dash/dashrouteorch.h" #include "dash/dashvnetorch.h" #include +#include using namespace swss; diff --git a/tests/mock_tests/Makefile.am b/tests/mock_tests/Makefile.am index 72f0fdf6ee..6ea9f18288 100644 --- a/tests/mock_tests/Makefile.am +++ b/tests/mock_tests/Makefile.am @@ -113,6 +113,7 @@ tests_SOURCES = aclorch_ut.cpp \ $(top_srcdir)/orchagent/vxlanorch.cpp \ $(top_srcdir)/orchagent/vnetorch.cpp \ $(top_srcdir)/orchagent/dtelorch.cpp \ + $(top_srcdir)/orchagent/dbggendumporch.cpp \ $(top_srcdir)/orchagent/flexcounterorch.cpp \ $(top_srcdir)/orchagent/watermarkorch.cpp \ $(top_srcdir)/orchagent/chassisorch.cpp \