diff --git a/cfgmgr/Makefile.am b/cfgmgr/Makefile.am index 69cefc8052..685ab04407 100644 --- a/cfgmgr/Makefile.am +++ b/cfgmgr/Makefile.am @@ -26,67 +26,72 @@ else DBGFLAGS = -g endif -vlanmgrd_SOURCES = vlanmgrd.cpp vlanmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h +COMMON_ORCH_SOURCE = $(top_srcdir)/orchagent/orch.cpp \ + $(top_srcdir)/orchagent/request_parser.cpp \ + $(top_srcdir)/orchagent/response_publisher.cpp \ + $(top_srcdir)/lib/recorder.cpp + +vlanmgrd_SOURCES = vlanmgrd.cpp vlanmgr.cpp $(COMMON_ORCH_SOURCE) shellcmd.h vlanmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) vlanmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) vlanmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) -teammgrd_SOURCES = teammgrd.cpp teammgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h +teammgrd_SOURCES = teammgrd.cpp teammgr.cpp $(COMMON_ORCH_SOURCE) shellcmd.h teammgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) teammgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) teammgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) -portmgrd_SOURCES = portmgrd.cpp portmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h +portmgrd_SOURCES = portmgrd.cpp portmgr.cpp $(COMMON_ORCH_SOURCE) shellcmd.h portmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) portmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) portmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) -intfmgrd_SOURCES = intfmgrd.cpp intfmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/lib/subintf.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h +intfmgrd_SOURCES = intfmgrd.cpp intfmgr.cpp $(top_srcdir)/lib/subintf.cpp $(COMMON_ORCH_SOURCE) shellcmd.h intfmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) intfmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) intfmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) -buffermgrd_SOURCES = buffermgrd.cpp buffermgr.cpp buffermgrdyn.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h +buffermgrd_SOURCES = buffermgrd.cpp buffermgr.cpp buffermgrdyn.cpp $(COMMON_ORCH_SOURCE) shellcmd.h buffermgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) buffermgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) buffermgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) -vrfmgrd_SOURCES = vrfmgrd.cpp vrfmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h +vrfmgrd_SOURCES = vrfmgrd.cpp vrfmgr.cpp $(COMMON_ORCH_SOURCE) shellcmd.h vrfmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) vrfmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) vrfmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) -nbrmgrd_SOURCES = nbrmgrd.cpp nbrmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h +nbrmgrd_SOURCES = nbrmgrd.cpp nbrmgr.cpp $(COMMON_ORCH_SOURCE) shellcmd.h nbrmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(LIBNL_CFLAGS) $(CFLAGS_ASAN) nbrmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(LIBNL_CPPFLAGS) $(CFLAGS_ASAN) nbrmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) $(LIBNL_LIBS) -vxlanmgrd_SOURCES = vxlanmgrd.cpp vxlanmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h +vxlanmgrd_SOURCES = vxlanmgrd.cpp vxlanmgr.cpp $(COMMON_ORCH_SOURCE) shellcmd.h vxlanmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) vxlanmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) vxlanmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) -sflowmgrd_SOURCES = sflowmgrd.cpp sflowmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h +sflowmgrd_SOURCES = sflowmgrd.cpp sflowmgr.cpp $(COMMON_ORCH_SOURCE) shellcmd.h sflowmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) sflowmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) sflowmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) -natmgrd_SOURCES = natmgrd.cpp natmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h +natmgrd_SOURCES = natmgrd.cpp natmgr.cpp $(COMMON_ORCH_SOURCE) shellcmd.h natmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) natmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) natmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) -coppmgrd_SOURCES = coppmgrd.cpp coppmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h +coppmgrd_SOURCES = coppmgrd.cpp coppmgr.cpp $(COMMON_ORCH_SOURCE) shellcmd.h coppmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) coppmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) coppmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) -tunnelmgrd_SOURCES = tunnelmgrd.cpp tunnelmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h +tunnelmgrd_SOURCES = tunnelmgrd.cpp tunnelmgr.cpp $(COMMON_ORCH_SOURCE) shellcmd.h tunnelmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) tunnelmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) tunnelmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) -macsecmgrd_SOURCES = macsecmgrd.cpp macsecmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp $(top_srcdir)/orchagent/response_publisher.cpp shellcmd.h +macsecmgrd_SOURCES = macsecmgrd.cpp macsecmgr.cpp $(COMMON_ORCH_SOURCE) shellcmd.h macsecmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) macsecmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN) macsecmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS) diff --git a/cfgmgr/buffermgrd.cpp b/cfgmgr/buffermgrd.cpp index 94176a54fd..fddaac930b 100644 --- a/cfgmgr/buffermgrd.cpp +++ b/cfgmgr/buffermgrd.cpp @@ -21,26 +21,6 @@ using json = nlohmann::json; /* SELECT() function timeout retry time, in millisecond */ #define SELECT_TIMEOUT 1000 -/* - * Following global variables are defined here for the purpose of - * using existing Orch class which is to be refactored soon to - * eliminate the direct exposure of the global variables. - * - * 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; -/* Global database mutex */ -mutex gDbMutex; - void usage() { cout << "Usage: buffermgrd <-l pg_lookup.ini|-a asic_table.json [-p peripheral_table.json] [-z zero_profiles.json]>" << endl; diff --git a/cfgmgr/coppmgrd.cpp b/cfgmgr/coppmgrd.cpp index 60b0a2442a..16c15c1238 100644 --- a/cfgmgr/coppmgrd.cpp +++ b/cfgmgr/coppmgrd.cpp @@ -16,26 +16,6 @@ using namespace swss; /* select() function timeout retry time, in millisecond */ #define SELECT_TIMEOUT 1000 -/* - * Following global variables are defined here for the purpose of - * using existing Orch class which is to be refactored soon to - * eliminate the direct exposure of the global variables. - * - * 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; -/* Global database mutex */ -mutex gDbMutex; - int main(int argc, char **argv) { Logger::linkToDbNative("coppmgrd"); diff --git a/cfgmgr/intfmgrd.cpp b/cfgmgr/intfmgrd.cpp index d07cb9af78..e414590920 100644 --- a/cfgmgr/intfmgrd.cpp +++ b/cfgmgr/intfmgrd.cpp @@ -16,26 +16,6 @@ using namespace swss; /* select() function timeout retry time, in millisecond */ #define SELECT_TIMEOUT 1000 -/* - * Following global variables are defined here for the purpose of - * using existing Orch class which is to be refactored soon to - * eliminate the direct exposure of the global variables. - * - * 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; -/* Global database mutex */ -mutex gDbMutex; - int main(int argc, char **argv) { Logger::linkToDbNative("intfmgrd"); diff --git a/cfgmgr/macsecmgrd.cpp b/cfgmgr/macsecmgrd.cpp index ff7bda9087..263c5b4395 100644 --- a/cfgmgr/macsecmgrd.cpp +++ b/cfgmgr/macsecmgrd.cpp @@ -26,26 +26,6 @@ using namespace swss; MacAddress gMacAddress; -/* - * Following global variables are defined here for the purpose of - * using existing Orch class which is to be refactored soon to - * eliminate the direct exposure of the global variables. - * - * 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; -/* Global database mutex */ -mutex gDbMutex; - static bool received_sigterm = false; static struct sigaction old_sigaction; diff --git a/cfgmgr/natmgr.cpp b/cfgmgr/natmgr.cpp index 43077fbe32..d903544d9b 100644 --- a/cfgmgr/natmgr.cpp +++ b/cfgmgr/natmgr.cpp @@ -6129,7 +6129,7 @@ void NatMgr::doStaticNatTask(Consumer &consumer) else { SWSS_LOG_ERROR("Unknown operation type %s", op.c_str()); - SWSS_LOG_DEBUG("%s", (dumpTuple(consumer, t)).c_str()); + SWSS_LOG_DEBUG("%s", (consumer.dumpTuple(t)).c_str()); it = consumer.m_toSync.erase(it); } } @@ -6472,7 +6472,7 @@ void NatMgr::doStaticNaptTask(Consumer &consumer) else { SWSS_LOG_ERROR("Unknown operation type %s", op.c_str()); - SWSS_LOG_DEBUG("%s", (dumpTuple(consumer, t)).c_str()); + SWSS_LOG_DEBUG("%s", (consumer.dumpTuple(t)).c_str()); it = consumer.m_toSync.erase(it); } } @@ -6859,7 +6859,7 @@ void NatMgr::doNatPoolTask(Consumer &consumer) else { SWSS_LOG_ERROR("Unknown operation type %s", op.c_str()); - SWSS_LOG_DEBUG("%s", (dumpTuple(consumer, t)).c_str()); + SWSS_LOG_DEBUG("%s", (consumer.dumpTuple(t)).c_str()); it = consumer.m_toSync.erase(it); } } @@ -7095,7 +7095,7 @@ void NatMgr::doNatBindingTask(Consumer &consumer) else { SWSS_LOG_ERROR("Unknown operation type %s", op.c_str()); - SWSS_LOG_DEBUG("%s", (dumpTuple(consumer, t)).c_str()); + SWSS_LOG_DEBUG("%s", (consumer.dumpTuple(t)).c_str()); it = consumer.m_toSync.erase(it); } } @@ -7873,7 +7873,7 @@ void NatMgr::doNatAclTableTask(Consumer &consumer) else { SWSS_LOG_INFO("Unknown operation type %s", op.c_str()); - SWSS_LOG_DEBUG("%s", (dumpTuple(consumer, t)).c_str()); + SWSS_LOG_DEBUG("%s", (consumer.dumpTuple(t)).c_str()); it = consumer.m_toSync.erase(it); } } @@ -8137,7 +8137,7 @@ void NatMgr::doNatAclRuleTask(Consumer &consumer) else { SWSS_LOG_INFO("Unknown operation type %s", op.c_str()); - SWSS_LOG_DEBUG("%s", (dumpTuple(consumer, t)).c_str()); + SWSS_LOG_DEBUG("%s", (consumer.dumpTuple(t)).c_str()); it = consumer.m_toSync.erase(it); } } diff --git a/cfgmgr/natmgrd.cpp b/cfgmgr/natmgrd.cpp index db5a77f9a6..0e3a52fadc 100644 --- a/cfgmgr/natmgrd.cpp +++ b/cfgmgr/natmgrd.cpp @@ -39,24 +39,6 @@ using namespace swss; /* select() function timeout retry time, in millisecond */ #define SELECT_TIMEOUT 1000 -/* - * Following global variables are defined here for the purpose of - * using existing Orch class which is to be refactored soon to - * eliminate the direct exposure of the global variables. - * - * 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; diff --git a/cfgmgr/nbrmgrd.cpp b/cfgmgr/nbrmgrd.cpp index 338d8d9d0d..2d325551a2 100644 --- a/cfgmgr/nbrmgrd.cpp +++ b/cfgmgr/nbrmgrd.cpp @@ -20,26 +20,6 @@ using namespace swss; /* select() function timeout retry time, in millisecond */ #define SELECT_TIMEOUT 1000 -/* - * Following global variables are defined here for the purpose of - * using existing Orch class which is to be refactored soon to - * eliminate the direct exposure of the global variables. - * - * 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; -/* Global database mutex */ -mutex gDbMutex; - int main(int argc, char **argv) { Logger::linkToDbNative("nbrmgrd"); diff --git a/cfgmgr/portmgrd.cpp b/cfgmgr/portmgrd.cpp index 944a881d06..99c7974559 100644 --- a/cfgmgr/portmgrd.cpp +++ b/cfgmgr/portmgrd.cpp @@ -15,26 +15,6 @@ using namespace swss; /* select() function timeout retry time, in millisecond */ #define SELECT_TIMEOUT 1000 -/* - * Following global variables are defined here for the purpose of - * using existing Orch class which is to be refactored soon to - * eliminate the direct exposure of the global variables. - * - * 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; -/* Global database mutex */ -mutex gDbMutex; - int main(int argc, char **argv) { Logger::linkToDbNative("portmgrd"); diff --git a/cfgmgr/sflowmgrd.cpp b/cfgmgr/sflowmgrd.cpp index 4672d04a42..2eef82bac7 100644 --- a/cfgmgr/sflowmgrd.cpp +++ b/cfgmgr/sflowmgrd.cpp @@ -15,26 +15,6 @@ using namespace swss; /* select() function timeout retry time, in millisecond */ #define SELECT_TIMEOUT 1000 -/* - * Following global variables are defined here for the purpose of - * using existing Orch class which is to be refactored soon to - * eliminate the direct exposure of the global variables. - * - * 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; -/* Global database mutex */ -mutex gDbMutex; - int main(int argc, char **argv) { Logger::linkToDbNative("sflowmgrd"); diff --git a/cfgmgr/teammgrd.cpp b/cfgmgr/teammgrd.cpp index ff4151c921..a18838c959 100644 --- a/cfgmgr/teammgrd.cpp +++ b/cfgmgr/teammgrd.cpp @@ -12,16 +12,6 @@ using namespace swss; #define SELECT_TIMEOUT 1000 -int gBatchSize = 0; -bool gSwssRecord = false; -bool gLogRotate = false; -ofstream gRecordOfs; -string gRecordFile; -bool gResponsePublisherRecord = false; -bool gResponsePublisherLogRotate = false; -ofstream gResponsePublisherRecordOfs; -string gResponsePublisherRecordFile; - bool received_sigterm = false; static struct sigaction old_sigaction; diff --git a/cfgmgr/tunnelmgrd.cpp b/cfgmgr/tunnelmgrd.cpp index 0a6a84eaeb..69157ba051 100644 --- a/cfgmgr/tunnelmgrd.cpp +++ b/cfgmgr/tunnelmgrd.cpp @@ -19,26 +19,6 @@ using namespace swss; /* select() function timeout retry time, in millisecond */ #define SELECT_TIMEOUT 1000 -/* - * Following global variables are defined here for the purpose of - * using existing Orch class which is to be refactored soon to - * eliminate the direct exposure of the global variables. - * - * 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; -/* Global database mutex */ -mutex gDbMutex; - int main(int argc, char **argv) { Logger::linkToDbNative("tunnelmgrd"); diff --git a/cfgmgr/vlanmgr.cpp b/cfgmgr/vlanmgr.cpp index e74582ce29..ee5b7a7067 100644 --- a/cfgmgr/vlanmgr.cpp +++ b/cfgmgr/vlanmgr.cpp @@ -431,13 +431,13 @@ void VlanMgr::doVlanTask(Consumer &consumer) { SWSS_LOG_ERROR("%s doesn't exist", key.c_str()); } - SWSS_LOG_DEBUG("%s", (dumpTuple(consumer, t)).c_str()); + SWSS_LOG_DEBUG("%s", (consumer.dumpTuple(t)).c_str()); it = consumer.m_toSync.erase(it); } else { SWSS_LOG_ERROR("Unknown operation type %s", op.c_str()); - SWSS_LOG_DEBUG("%s", (dumpTuple(consumer, t)).c_str()); + SWSS_LOG_DEBUG("%s", (consumer.dumpTuple(t)).c_str()); it = consumer.m_toSync.erase(it); } } @@ -539,7 +539,7 @@ void VlanMgr::processUntaggedVlanMembers(string vlan, const string &members) fvVector.push_back(t); KeyOpFieldsValuesTuple tuple = make_tuple(member_key, SET_COMMAND, fvVector); consumer.addToSync(tuple); - SWSS_LOG_DEBUG("%s", (dumpTuple(consumer, tuple)).c_str()); + SWSS_LOG_DEBUG("%s", (consumer.dumpTuple(tuple)).c_str()); } /* * There is pending task from consumer pipe, in this case just skip it. @@ -659,7 +659,7 @@ void VlanMgr::doVlanMemberTask(Consumer &consumer) { SWSS_LOG_DEBUG("%s doesn't exist", kfvKey(t).c_str()); } - SWSS_LOG_DEBUG("%s", (dumpTuple(consumer, t)).c_str()); + SWSS_LOG_DEBUG("%s", (consumer.dumpTuple(t)).c_str()); } else { diff --git a/cfgmgr/vlanmgrd.cpp b/cfgmgr/vlanmgrd.cpp index b69dc78122..84bc19cf08 100644 --- a/cfgmgr/vlanmgrd.cpp +++ b/cfgmgr/vlanmgrd.cpp @@ -23,26 +23,6 @@ using namespace swss; MacAddress gMacAddress; -/* - * Following global variables are defined here for the purpose of - * using existing Orch class which is to be refactored soon to - * eliminate the direct exposure of the global variables. - * - * 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; -/* Global database mutex */ -mutex gDbMutex; - int main(int argc, char **argv) { Logger::linkToDbNative("vlanmgrd"); diff --git a/cfgmgr/vrfmgrd.cpp b/cfgmgr/vrfmgrd.cpp index c7ca49b6bc..3dbc7e447e 100644 --- a/cfgmgr/vrfmgrd.cpp +++ b/cfgmgr/vrfmgrd.cpp @@ -16,26 +16,6 @@ using namespace swss; /* select() function timeout retry time, in millisecond */ #define SELECT_TIMEOUT 1000 -/* - * Following global variables are defined here for the purpose of - * using existing Orch class which is to be refactored soon to - * eliminate the direct exposure of the global variables. - * - * 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; -/* Global database mutex */ -mutex gDbMutex; - int main(int argc, char **argv) { Logger::linkToDbNative("vrfmgrd"); diff --git a/cfgmgr/vxlanmgrd.cpp b/cfgmgr/vxlanmgrd.cpp index d47893a614..c992233c86 100644 --- a/cfgmgr/vxlanmgrd.cpp +++ b/cfgmgr/vxlanmgrd.cpp @@ -21,25 +21,6 @@ using namespace swss; /* select() function timeout retry time, in millisecond */ #define SELECT_TIMEOUT 1000 -/* - * Following global variables are defined here for the purpose of - * using existing Orch class which is to be refactored soon to - * eliminate the direct exposure of the global variables. - * - * 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; -/* Global database mutex */ -mutex gDbMutex; MacAddress gMacAddress; int main(int argc, char **argv) diff --git a/lib/recorder.cpp b/lib/recorder.cpp new file mode 100644 index 0000000000..449039adff --- /dev/null +++ b/lib/recorder.cpp @@ -0,0 +1,121 @@ +#include "recorder.h" +#include "timestamp.h" +#include "logger.h" +#include + +using namespace swss; + +const std::string Recorder::DEFAULT_DIR = "."; +const std::string Recorder::REC_START = "|recording started"; +const std::string Recorder::SWSS_FNAME = "swss.rec"; +const std::string Recorder::SAIREDIS_FNAME = "sairedis.rec"; +const std::string Recorder::RESPPUB_FNAME = "responsepublisher.rec"; + + +Recorder& Recorder::Instance() +{ + static Recorder m_recorder; + return m_recorder; +} + + +SwSSRec::SwSSRec() +{ + /* Set Default values */ + setRecord(true); + setRotate(false); + setLocation(Recorder::DEFAULT_DIR); + setFileName(Recorder::SWSS_FNAME); + setName("SwSS"); +} + + +ResPubRec::ResPubRec() +{ + /* Set Default values */ + setRecord(false); + setRotate(false); + setLocation(Recorder::DEFAULT_DIR); + setFileName(Recorder::RESPPUB_FNAME); + setName("Response Publisher"); +} + + +SaiRedisRec::SaiRedisRec() +{ + /* Set Default values */ + setRecord(true); + setRotate(false); + setLocation(Recorder::DEFAULT_DIR); + setFileName(Recorder::SAIREDIS_FNAME); + setName("SaiRedis"); +} + + +void RecWriter::startRec(bool exit_if_failure) +{ + if (!isRecord()) + { + return ; + } + + fname = getLoc() + "/" + getFile(); + record_ofs.open(fname, std::ofstream::out | std::ofstream::app); + if (!record_ofs.is_open()) + { + SWSS_LOG_ERROR("%s Recorder: Failed to open recording file %s: error %s", getName().c_str(), fname.c_str(), strerror(errno)); + if (exit_if_failure) + { + exit(EXIT_FAILURE); + } + else + { + setRecord(false); + } + } + record_ofs << swss::getTimestamp() << Recorder::REC_START << std::endl; + SWSS_LOG_NOTICE("%s Recorder: Recording started at %s", getName().c_str(), fname.c_str()); +} + + +RecWriter::~RecWriter() +{ + if (record_ofs.is_open()) + { + record_ofs.close(); + } +} + + +void RecWriter::record(const std::string& val) +{ + if (!isRecord()) + { + return ; + } + record_ofs << swss::getTimestamp() << "|" << val << std::endl; + if (isRotate()) + { + setRotate(false); + logfileReopen(); + } +} + + +void RecWriter::logfileReopen() +{ + /* + * On log rotate we will use the same file name, we are assuming that + * logrotate daemon move filename to filename.1 and we will create new + * empty file here. + */ + record_ofs.close(); + record_ofs.open(fname, std::ofstream::out | std::ofstream::app); + + if (!record_ofs.is_open()) + { + SWSS_LOG_ERROR("%s Recorder: Failed to open file %s: %s", getName().c_str(), fname.c_str(), strerror(errno)); + return; + } + SWSS_LOG_INFO("%s Recorder: LogRotate request handled", getName().c_str()); +} diff --git a/lib/recorder.h b/lib/recorder.h new file mode 100644 index 0000000000..971c3a2bb7 --- /dev/null +++ b/lib/recorder.h @@ -0,0 +1,84 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace swss { + +class RecBase { +public: + RecBase() = default; + /* Setters */ + void setRecord(bool record) { m_recording = record; } + void setRotate(bool rotate) { m_rotate = rotate; } + void setLocation(const std::string& loc) { m_location = loc; } + void setFileName(const std::string& name) { m_filename = name; } + void setName(const std::string& name) { m_name = name; } + + /* getters */ + bool isRecord() { return m_recording; } + bool isRotate() { return m_rotate; } + std::string getLoc() { return m_location; } + std::string getFile() { return m_filename; } + std::string getName() { return m_name; } + +private: + bool m_recording; + bool m_rotate; + std::string m_location; + std::string m_filename; + std::string m_name; +}; + +class RecWriter : public RecBase { +public: + RecWriter() = default; + virtual ~RecWriter(); + void startRec(bool exit_if_failure); + void record(const std::string& val); + +protected: + void logfileReopen(); + +private: + std::ofstream record_ofs; + std::string fname; +}; + +class SwSSRec : public RecWriter { +public: + SwSSRec(); +}; + +/* Record Handler for Response Publisher Class */ +class ResPubRec : public RecWriter { +public: + ResPubRec(); +}; + +class SaiRedisRec : public RecBase { +public: + SaiRedisRec(); +}; + +/* Interface to access recorder classes */ +class Recorder { +public: + static Recorder& Instance(); + static const std::string DEFAULT_DIR; + static const std::string REC_START; + static const std::string SWSS_FNAME; + static const std::string SAIREDIS_FNAME; + static const std::string RESPPUB_FNAME; + + Recorder() = default; + /* Individual Handlers */ + SwSSRec swss; + SaiRedisRec sairedis; + ResPubRec respub; +}; + +} diff --git a/orchagent/Makefile.am b/orchagent/Makefile.am index 03ec1e24ed..3ba6fab5f9 100644 --- a/orchagent/Makefile.am +++ b/orchagent/Makefile.am @@ -46,6 +46,7 @@ orchagent_SOURCES = \ main.cpp \ $(top_srcdir)/lib/gearboxutils.cpp \ $(top_srcdir)/lib/subintf.cpp \ + $(top_srcdir)/lib/recorder.cpp \ orchdaemon.cpp \ orch.cpp \ notifications.cpp \ diff --git a/orchagent/main.cpp b/orchagent/main.cpp index 3e938e01f1..daccbc1b27 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -19,8 +19,6 @@ extern "C" { #include #include -#include "timestamp.h" - #include #include @@ -52,24 +50,14 @@ MacAddress gVxlanMacAddress; extern size_t gMaxBulkSize; #define DEFAULT_BATCH_SIZE 128 -int gBatchSize = DEFAULT_BATCH_SIZE; +extern int gBatchSize; -bool gSairedisRecord = true; -bool gSwssRecord = true; -bool gResponsePublisherRecord = false; -bool gLogRotate = false; -bool gResponsePublisherLogRotate = false; bool gSyncMode = false; sai_redis_communication_mode_t gRedisCommunicationMode = SAI_REDIS_COMMUNICATION_MODE_REDIS_ASYNC; string gAsicInstance; extern bool gIsNatSupported; -ofstream gRecordOfs; -string gRecordFile; -ofstream gResponsePublisherRecordOfs; -string gResponsePublisherRecordFile; - #define SAIREDIS_RECORD_ENABLE 0x1 #define SWSS_RECORD_ENABLE (0x1 << 1) #define RESPONSE_PUBLISHER_RECORD_ENABLE (0x1 << 2) @@ -108,9 +96,9 @@ void sighup_handler(int signo) /* * Don't do any logging since they are using mutexes. */ - gLogRotate = true; - gSaiRedisLogRotate = true; - gResponsePublisherLogRotate = true; + Recorder::Instance().swss.setRotate(true); + Recorder::Instance().sairedis.setRotate(true); + Recorder::Instance().respub.setRotate(true); } void syncd_apply_view() @@ -346,10 +334,11 @@ int main(int argc, char **argv) int opt; sai_status_t status; - string record_location = "."; - string swss_rec_filename = "swss.rec"; - string sairedis_rec_filename = "sairedis.rec"; - string responsepublisher_rec_filename = "responsepublisher.rec"; + gBatchSize = DEFAULT_BATCH_SIZE; + string record_location = Recorder::DEFAULT_DIR; + string swss_rec_filename = Recorder::SWSS_FNAME; + string sairedis_rec_filename = Recorder::SAIREDIS_FNAME; + string responsepublisher_rec_filename = Recorder::RESPPUB_FNAME; int record_type = 3; // Only swss and sairedis recordings enabled by default. while ((opt = getopt(argc, argv, "b:m:r:f:j:d:i:hsz:k:")) != -1) @@ -437,8 +426,32 @@ int main(int argc, char **argv) SWSS_LOG_NOTICE("--- Starting Orchestration Agent ---"); + /* Initialize sairedis recording parameters */ + Recorder::Instance().sairedis.setRecord( + (record_type & SAIREDIS_RECORD_ENABLE) == SAIREDIS_RECORD_ENABLE + ); + Recorder::Instance().sairedis.setLocation(record_location); + Recorder::Instance().sairedis.setFileName(sairedis_rec_filename); + + /* Initialize sairedis */ initSaiApi(); - initSaiRedis(record_location, sairedis_rec_filename); + initSaiRedis(); + + /* Initialize remaining recorder parameters */ + Recorder::Instance().swss.setRecord( + (record_type & SWSS_RECORD_ENABLE) == SWSS_RECORD_ENABLE + ); + Recorder::Instance().swss.setLocation(record_location); + Recorder::Instance().swss.setFileName(swss_rec_filename); + Recorder::Instance().swss.startRec(true); + + Recorder::Instance().respub.setRecord( + (record_type & RESPONSE_PUBLISHER_RECORD_ENABLE) == + RESPONSE_PUBLISHER_RECORD_ENABLE + ); + Recorder::Instance().respub.setLocation(record_location); + Recorder::Instance().respub.setFileName(responsepublisher_rec_filename); + Recorder::Instance().respub.startRec(false); sai_attribute_t attr; vector attrs; @@ -450,45 +463,6 @@ int main(int argc, char **argv) attr.value.ptr = (void *)on_fdb_event; attrs.push_back(attr); - // Initialize recording parameters. - 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; - - /* Disable/enable SwSS recording */ - if (gSwssRecord) - { - gRecordFile = record_location + "/" + swss_rec_filename; - gRecordOfs.open(gRecordFile, std::ofstream::out | std::ofstream::app); - if (!gRecordOfs.is_open()) - { - SWSS_LOG_ERROR("Failed to open SwSS recording file %s", gRecordFile.c_str()); - exit(EXIT_FAILURE); - } - gRecordOfs << getTimestamp() << "|recording started" << endl; - } - - // Disable/Enable response publisher recording. - if (gResponsePublisherRecord) - { - gResponsePublisherRecordFile = record_location + "/" + responsepublisher_rec_filename; - gResponsePublisherRecordOfs.open(gResponsePublisherRecordFile, std::ofstream::out | std::ofstream::app); - if (!gResponsePublisherRecordOfs.is_open()) - { - SWSS_LOG_ERROR("Failed to open Response Publisher recording file %s", - gResponsePublisherRecordFile.c_str()); - gResponsePublisherRecord = false; - } - else - { - gResponsePublisherRecordOfs << getTimestamp() << "|recording started" - << endl; - } - } - attr.id = SAI_SWITCH_ATTR_PORT_STATE_CHANGE_NOTIFY; attr.value.ptr = (void *)on_port_state_change; attrs.push_back(attr); diff --git a/orchagent/orch.cpp b/orchagent/orch.cpp index 5607d5c027..3ba2908c93 100644 --- a/orchagent/orch.cpp +++ b/orchagent/orch.cpp @@ -1,7 +1,4 @@ -#include -#include #include -#include #include #include #include "timestamp.h" @@ -16,12 +13,7 @@ using namespace swss; -extern int gBatchSize; - -extern bool gSwssRecord; -extern ofstream gRecordOfs; -extern bool gLogRotate; -extern string gRecordFile; +int gBatchSize = 0; Orch::Orch(DBConnector *db, const string tableName, int pri) { @@ -52,14 +44,6 @@ Orch::Orch(const vector& tables) } } -Orch::~Orch() -{ - if (gRecordOfs.is_open()) - { - gRecordOfs.close(); - } -} - vector Orch::getSelectables() { vector selectables; @@ -74,15 +58,11 @@ void ConsumerBase::addToSync(const KeyOpFieldsValuesTuple &entry) { SWSS_LOG_ENTER(); - string key = kfvKey(entry); string op = kfvOp(entry); /* Record incoming tasks */ - if (gSwssRecord) - { - Orch::recordTuple(*this, entry); - } + Recorder::Instance().swss.record(dumpTuple(entry)); /* * m_toSync is a multimap which will allow one key with multiple values, @@ -566,45 +546,6 @@ void Orch::flushResponses() m_publisher.flush(); } -void Orch::logfileReopen() -{ - gRecordOfs.close(); - - /* - * On log rotate we will use the same file name, we are assuming that - * logrotate daemon move filename to filename.1 and we will create new - * empty file here. - */ - - gRecordOfs.open(gRecordFile, std::ofstream::out | std::ofstream::app); - - if (!gRecordOfs.is_open()) - { - SWSS_LOG_ERROR("failed to open gRecordOfs file %s: %s", gRecordFile.c_str(), strerror(errno)); - return; - } -} - -void Orch::recordTuple(ConsumerBase &consumer, const KeyOpFieldsValuesTuple &tuple) -{ - string s = consumer.dumpTuple(tuple); - - gRecordOfs << getTimestamp() << "|" << s << endl; - - if (gLogRotate) - { - gLogRotate = false; - - logfileReopen(); - } -} - -string Orch::dumpTuple(Consumer &consumer, const KeyOpFieldsValuesTuple &tuple) -{ - string s = consumer.dumpTuple(tuple); - return s; -} - ref_resolve_status Orch::resolveFieldRefArray( type_map &type_maps, const string &field_name, diff --git a/orchagent/orch.h b/orchagent/orch.h index bb39d34589..3b72931d99 100644 --- a/orchagent/orch.h +++ b/orchagent/orch.h @@ -21,6 +21,7 @@ extern "C" { #include "selectabletimer.h" #include "macaddress.h" #include "response_publisher.h" +#include "recorder.h" const char delimiter = ':'; const char list_item_delimiter = ','; @@ -153,6 +154,9 @@ class ConsumerBase : public Executor { // TODO: hide? SyncMap m_toSync; + /* record the tuple */ + void recordTuple(const swss::KeyOpFieldsValuesTuple &tuple); + void addToSync(const swss::KeyOpFieldsValuesTuple &entry); // Returns: the number of entries added to m_toSync @@ -216,7 +220,7 @@ class Orch Orch(swss::DBConnector *db, const std::vector &tableNames); Orch(swss::DBConnector *db, const std::vector &tableNameWithPri); Orch(const std::vector& tables); - virtual ~Orch(); + virtual ~Orch() = default; std::vector getSelectables(); @@ -236,9 +240,6 @@ class Orch virtual void doTask(swss::NotificationConsumer &consumer) { } virtual void doTask(swss::SelectableTimer &timer) { } - /* TODO: refactor recording */ - static void recordTuple(ConsumerBase &consumer, const swss::KeyOpFieldsValuesTuple &tuple); - void dumpPendingTasks(std::vector &ts); /** @@ -248,8 +249,6 @@ class Orch protected: ConsumerMap m_consumerMap; - static void logfileReopen(); - std::string dumpTuple(Consumer &consumer, const swss::KeyOpFieldsValuesTuple &tuple); ref_resolve_status resolveFieldRefValue(type_map&, const std::string&, const std::string&, swss::KeyOpFieldsValuesTuple&, sai_object_id_t&, std::string&); std::set generateIdListFromMap(unsigned long idsMap, sai_uint32_t maxId); unsigned long generateBitMapFromIdsStr(const std::string &idsStr); diff --git a/orchagent/orchdaemon.cpp b/orchagent/orchdaemon.cpp index 8abe3e0a58..a931e9a594 100644 --- a/orchagent/orchdaemon.cpp +++ b/orchagent/orchdaemon.cpp @@ -24,7 +24,6 @@ using namespace swss; extern sai_switch_api_t* sai_switch_api; extern sai_object_id_t gSwitchId; -extern bool gSaiRedisLogRotate; extern void syncd_apply_view(); /* @@ -62,7 +61,6 @@ DebugCounterOrch *gDebugCounterOrch; MonitorOrch *gMonitorOrch; bool gIsNatSupported = false; -bool gSaiRedisLogRotate = false; event_handle_t g_events_handle; #define DEFAULT_MAX_BULK_SIZE 1000 @@ -712,7 +710,8 @@ void OrchDaemon::logRotate() { void OrchDaemon::start() { SWSS_LOG_ENTER(); - gSaiRedisLogRotate = false; + + Recorder::Instance().sairedis.setRotate(false); for (Orch *o : m_orchList) { @@ -758,12 +757,10 @@ void OrchDaemon::start() } // check if logroate is requested - if (gSaiRedisLogRotate) + if (Recorder::Instance().sairedis.isRotate()) { - SWSS_LOG_NOTICE("performing log rotate"); - - gSaiRedisLogRotate = false; - + SWSS_LOG_NOTICE("Performing %s log rotate", Recorder::Instance().sairedis.getName().c_str()); + Recorder::Instance().sairedis.setRotate(false); logRotate(); } diff --git a/orchagent/orchdaemon.h b/orchagent/orchdaemon.h index 6092be26b4..32fab2b9b0 100644 --- a/orchagent/orchdaemon.h +++ b/orchagent/orchdaemon.h @@ -48,7 +48,6 @@ #include using namespace swss; -extern bool gSaiRedisLogRotate; class OrchDaemon { diff --git a/orchagent/p4orch/tests/Makefile.am b/orchagent/p4orch/tests/Makefile.am index 34fd93f59b..671aa9eb80 100644 --- a/orchagent/p4orch/tests/Makefile.am +++ b/orchagent/p4orch/tests/Makefile.am @@ -30,6 +30,7 @@ p4orch_tests_SOURCES = $(ORCHAGENT_DIR)/orch.cpp \ $(ORCHAGENT_DIR)/switch/switch_helper.cpp \ $(ORCHAGENT_DIR)/switchorch.cpp \ $(ORCHAGENT_DIR)/request_parser.cpp \ + $(top_srcdir)/lib/recorder.cpp \ $(ORCHAGENT_DIR)/flex_counter/flex_counter_manager.cpp \ $(ORCHAGENT_DIR)/flex_counter/flow_counter_handler.cpp \ $(P4ORCH_DIR)/p4oidmapper.cpp \ diff --git a/orchagent/p4orch/tests/test_main.cpp b/orchagent/p4orch/tests/test_main.cpp index e76104ce45..787e0622f4 100644 --- a/orchagent/p4orch/tests/test_main.cpp +++ b/orchagent/p4orch/tests/test_main.cpp @@ -37,14 +37,9 @@ sai_object_id_t kMirrorSessionOid2 = 9002; sai_object_id_t gUnderlayIfId; #define DEFAULT_BATCH_SIZE 128 -int gBatchSize = DEFAULT_BATCH_SIZE; #define DEFAULT_MAX_BULK_SIZE 1000 +extern int gBatchSize; size_t gMaxBulkSize = DEFAULT_MAX_BULK_SIZE; -bool gSairedisRecord = true; -bool gSwssRecord = true; -bool gLogRotate = false; -bool gResponsePublisherRecord = false; -bool gResponsePublisherLogRotate = false; bool gSyncMode = false; bool gIsNatSupported = false; @@ -55,8 +50,6 @@ VRFOrch *gVrfOrch; FlowCounterRouteOrch *gFlowCounterRouteOrch; SwitchOrch *gSwitchOrch; Directory gDirectory; -ofstream gRecordOfs; -string gRecordFile; swss::DBConnector *gAppDb; swss::DBConnector *gStateDb; swss::DBConnector *gConfigDb; @@ -180,7 +173,8 @@ void AddVrf() } // namespace int main(int argc, char *argv[]) -{ +{ + gBatchSize = DEFAULT_BATCH_SIZE; testing::InitGoogleTest(&argc, argv); sai_router_interface_api_t router_intfs_api; diff --git a/orchagent/response_publisher.cpp b/orchagent/response_publisher.cpp index 169075faa4..031f1aefef 100644 --- a/orchagent/response_publisher.cpp +++ b/orchagent/response_publisher.cpp @@ -5,13 +5,6 @@ #include #include -#include "timestamp.h" - -extern bool gResponsePublisherRecord; -extern bool gResponsePublisherLogRotate; -extern std::ofstream gResponsePublisherRecordOfs; -extern std::string gResponsePublisherRecordFile; - namespace { @@ -35,27 +28,10 @@ std::string PrependedComponent(const ReturnCode &status) return kOrchagentComponent; } -void PerformLogRotate() -{ - if (!gResponsePublisherLogRotate) - { - return; - } - gResponsePublisherLogRotate = false; - - gResponsePublisherRecordOfs.close(); - gResponsePublisherRecordOfs.open(gResponsePublisherRecordFile); - if (!gResponsePublisherRecordOfs.is_open()) - { - SWSS_LOG_ERROR("Failed to reopen Response Publisher record file %s: %s", gResponsePublisherRecordFile.c_str(), - strerror(errno)); - } -} - void RecordDBWrite(const std::string &table, const std::string &key, const std::vector &attrs, const std::string &op) { - if (!gResponsePublisherRecord) + if (!swss::Recorder::Instance().respub.isRecord()) { return; } @@ -66,16 +42,15 @@ void RecordDBWrite(const std::string &table, const std::string &key, const std:: s += "|" + fvField(attr) + ":" + fvValue(attr); } - PerformLogRotate(); - gResponsePublisherRecordOfs << swss::getTimestamp() << "|" << s << std::endl; + swss::Recorder::Instance().respub.record(s); } void RecordResponse(const std::string &response_channel, const std::string &key, const std::vector &attrs, const std::string &status) { - if (!gResponsePublisherRecord) + if (!swss::Recorder::Instance().respub.isRecord()) { - return; + return; } std::string s = response_channel + ":" + key + "|" + status; @@ -84,8 +59,7 @@ void RecordResponse(const std::string &response_channel, const std::string &key, s += "|" + fvField(attr) + ":" + fvValue(attr); } - PerformLogRotate(); - gResponsePublisherRecordOfs << swss::getTimestamp() << "|" << s << std::endl; + swss::Recorder::Instance().respub.record(s); } } // namespace diff --git a/orchagent/response_publisher.h b/orchagent/response_publisher.h index db882d9c70..ff7bd291e4 100644 --- a/orchagent/response_publisher.h +++ b/orchagent/response_publisher.h @@ -9,6 +9,7 @@ #include "notificationproducer.h" #include "response_publisher_interface.h" #include "table.h" +#include "recorder.h" // This class performs two tasks when publish is called: // 1. Sends a notification into the redis channel. diff --git a/orchagent/saihelper.cpp b/orchagent/saihelper.cpp index 3f3e5ba5cd..d1dc472d7d 100644 --- a/orchagent/saihelper.cpp +++ b/orchagent/saihelper.cpp @@ -75,10 +75,6 @@ sai_my_mac_api_t* sai_my_mac_api; sai_generic_programmable_api_t* sai_generic_programmable_api; extern sai_object_id_t gSwitchId; -extern bool gSairedisRecord; -extern bool gSwssRecord; -extern ofstream gRecordOfs; -extern string gRecordFile; static map hardware_access_map = { @@ -244,7 +240,7 @@ void initSaiApi() sai_log_set(SAI_API_GENERIC_PROGRAMMABLE, SAI_LOG_LEVEL_NOTICE); } -void initSaiRedis(const string &record_location, const std::string &record_filename) +void initSaiRedis() { /** * NOTE: Notice that all Redis attributes here are using SAI_NULL_OBJECT_ID @@ -255,9 +251,11 @@ void initSaiRedis(const string &record_location, const std::string &record_filen sai_attribute_t attr; sai_status_t status; - /* set recording dir before enable recording */ + auto record_filename = Recorder::Instance().sairedis.getFile(); + auto record_location = Recorder::Instance().sairedis.getLoc(); - if (gSairedisRecord) + /* set recording dir before enable recording */ + if (Recorder::Instance().sairedis.isRecord()) { attr.id = SAI_REDIS_SWITCH_ATTR_RECORDING_OUTPUT_DIR; attr.value.s8list.count = (uint32_t)record_location.size(); @@ -286,15 +284,14 @@ void initSaiRedis(const string &record_location, const std::string &record_filen } /* Disable/enable SAI Redis recording */ - attr.id = SAI_REDIS_SWITCH_ATTR_RECORD; - attr.value.booldata = gSairedisRecord; + attr.value.booldata = Recorder::Instance().sairedis.isRecord(); status = sai_switch_api->set_switch_attribute(gSwitchId, &attr); if (status != SAI_STATUS_SUCCESS) { SWSS_LOG_ERROR("Failed to %s SAI Redis recording, rv:%d", - gSairedisRecord ? "enable" : "disable", status); + Recorder::Instance().sairedis.isRecord() ? "enable" : "disable", status); exit(EXIT_FAILURE); } diff --git a/orchagent/saihelper.h b/orchagent/saihelper.h index c7ff8d23ea..b83f894c2e 100644 --- a/orchagent/saihelper.h +++ b/orchagent/saihelper.h @@ -9,7 +9,7 @@ ((attrId) >= SAI_ ## objectType ## _ATTR_ ## attrPrefix ## _START && (attrId) <= SAI_ ## objectType ## _ATTR_ ## attrPrefix ## _END) void initSaiApi(); -void initSaiRedis(const std::string &record_location, const std::string &record_filename); +void initSaiRedis(); sai_status_t initSaiPhyApi(swss::gearbox_phy_t *phy); /* Handling SAI status*/ diff --git a/tests/Makefile.am b/tests/Makefile.am index 0b6831be97..8f2aa131c4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,3 +1,5 @@ +INCLUDES = -I $(top_srcdir)/lib + CFLAGS_SAI = -I /usr/include/sai TESTS = tests @@ -18,7 +20,7 @@ CFLAGS_GTEST = LDADD_GTEST = -L/usr/src/gtest tests_SOURCES = swssnet_ut.cpp request_parser_ut.cpp ../orchagent/request_parser.cpp \ - quoted_ut.cpp + quoted_ut.cpp ../lib/recorder.cpp tests_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI) tests_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI) -I../orchagent diff --git a/tests/mock_tests/Makefile.am b/tests/mock_tests/Makefile.am index 12e8c3ecfa..3b23b1aeba 100644 --- a/tests/mock_tests/Makefile.am +++ b/tests/mock_tests/Makefile.am @@ -56,6 +56,7 @@ tests_SOURCES = aclorch_ut.cpp \ test_failure_handling.cpp \ $(top_srcdir)/lib/gearboxutils.cpp \ $(top_srcdir)/lib/subintf.cpp \ + $(top_srcdir)/lib/recorder.cpp \ $(top_srcdir)/orchagent/orchdaemon.cpp \ $(top_srcdir)/orchagent/orch.cpp \ $(top_srcdir)/orchagent/notifications.cpp \ @@ -144,6 +145,7 @@ tests_LDADD = $(LDADD_GTEST) $(LDADD_SAI) -lnl-genl-3 -lhiredis -lhiredis -lpthr ## portsyncd unit tests tests_portsyncd_SOURCES = portsyncd/portsyncd_ut.cpp \ + $(top_srcdir)/lib/recorder.cpp \ $(top_srcdir)/portsyncd/linksync.cpp \ mock_dbconnector.cpp \ common/mock_shell_command.cpp \ @@ -151,7 +153,7 @@ tests_portsyncd_SOURCES = portsyncd/portsyncd_ut.cpp \ mock_hiredis.cpp \ mock_redisreply.cpp -tests_portsyncd_INCLUDES = -I $(top_srcdir)/portsyncd -I $(top_srcdir)/cfgmgr +tests_portsyncd_INCLUDES = -I $(top_srcdir)/portsyncd -I $(top_srcdir)/cfgmgr -I $(top_srcdir)/lib tests_portsyncd_CXXFLAGS = -Wl,-wrap,if_nameindex -Wl,-wrap,if_freenameindex tests_portsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) tests_portsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(tests_portsyncd_INCLUDES) @@ -163,6 +165,7 @@ tests_portsyncd_LDADD = $(LDADD_GTEST) -lnl-genl-3 -lhiredis -lhiredis \ tests_intfmgrd_SOURCES = intfmgrd/intfmgr_ut.cpp \ $(top_srcdir)/cfgmgr/intfmgr.cpp \ $(top_srcdir)/lib/subintf.cpp \ + $(top_srcdir)/lib/recorder.cpp \ $(top_srcdir)/orchagent/orch.cpp \ $(top_srcdir)/orchagent/request_parser.cpp \ mock_orchagent_main.cpp \ @@ -203,6 +206,7 @@ tests_fpmsyncd_LDADD = $(LDADD_GTEST) $(LDADD_SAI) -lnl-genl-3 -lhiredis -lhired tests_response_publisher_SOURCES = response_publisher/response_publisher_ut.cpp \ $(top_srcdir)/orchagent/response_publisher.cpp \ + $(top_srcdir)/lib/recorder.cpp \ mock_orchagent_main.cpp \ mock_dbconnector.cpp \ mock_table.cpp \ diff --git a/tests/mock_tests/mock_orchagent_main.cpp b/tests/mock_tests/mock_orchagent_main.cpp index ff2f902f39..542e5f3e36 100644 --- a/tests/mock_tests/mock_orchagent_main.cpp +++ b/tests/mock_tests/mock_orchagent_main.cpp @@ -12,14 +12,6 @@ sai_object_id_t gSwitchId = SAI_NULL_OBJECT_ID; MacAddress gMacAddress; MacAddress gVxlanMacAddress; -#define DEFAULT_BATCH_SIZE 128 -int gBatchSize = DEFAULT_BATCH_SIZE; - -bool gSairedisRecord = true; -bool gSwssRecord = true; -bool gLogRotate = false; -ofstream gRecordOfs; -string gRecordFile; string gMySwitchType = "switch"; int32_t gVoqMySwitchId = 0; string gMyHostName = "Linecard1"; diff --git a/tests/mock_tests/mock_orchagent_main.h b/tests/mock_tests/mock_orchagent_main.h index 3d57dff88f..93c1588b9b 100644 --- a/tests/mock_tests/mock_orchagent_main.h +++ b/tests/mock_tests/mock_orchagent_main.h @@ -30,11 +30,6 @@ #include "directory.h" extern int gBatchSize; -extern bool gSwssRecord; -extern bool gSairedisRecord; -extern bool gLogRotate; -extern ofstream gRecordOfs; -extern string gRecordFile; extern MacAddress gMacAddress; extern MacAddress gVxlanMacAddress; diff --git a/tests/mock_tests/response_publisher/response_publisher_ut.cpp b/tests/mock_tests/response_publisher/response_publisher_ut.cpp index 3738ac6d87..9e836bad04 100644 --- a/tests/mock_tests/response_publisher/response_publisher_ut.cpp +++ b/tests/mock_tests/response_publisher/response_publisher_ut.cpp @@ -2,11 +2,6 @@ #include -bool gResponsePublisherRecord{false}; -bool gResponsePublisherLogRotate{false}; -std::ofstream gResponsePublisherRecordOfs; -std::string gResponsePublisherRecordFile; - using namespace swss; TEST(ResponsePublisher, TestPublish)