From 8a0e854713d36aa28178b760b5d2eab6134b976b Mon Sep 17 00:00:00 2001 From: Arvindsrinivasan Lakshmi Narasimhan Date: Mon, 14 Dec 2020 16:59:43 +0000 Subject: [PATCH 1/5] Handle the swss_log_file and sairedis_log_file optionswq! Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan --- orchagent/main.cpp | 27 ++++++++++++++++++++++----- orchagent/saihelper.cpp | 15 ++++++++++++++- orchagent/saihelper.h | 2 +- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/orchagent/main.cpp b/orchagent/main.cpp index 5370daf371..5438e1f608 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -65,7 +65,7 @@ string gRecordFile; void usage() { - cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-b batch_size] [-m MAC] [-i INST_ID] [-s] [-z mode]" << 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]" << endl; cout << " -h: display this message" << endl; cout << " -r record_type: record orchagent logs with type (default 3)" << endl; cout << " 0: do not record logs" << endl; @@ -78,6 +78,8 @@ void usage() cout << " -i INST_ID: set the ASIC instance_id in multi-asic platform" << endl; cout << " -s: enable synchronous mode (depreacated, use -z)" << endl; cout << " -z: redis communication mode (redis_async|redis_sync|zmq_sync), default: redis_async" << endl; + cout << " -f swss_rec_filename: swss record log filename(default 'swss.rec')" << endl; + cout << " -j sairedis_rec_filename: sairedis record log filename(default sairedis.rec)" << endl; } void sighup_handler(int signo) @@ -161,8 +163,10 @@ int main(int argc, char **argv) sai_status_t status; string record_location = "."; + string swss_rec_filename = "swss.rec"; + string sairedis_rec_filename = "sairedis.rec"; - while ((opt = getopt(argc, argv, "b:m:r:d:i:hsz:")) != -1) + while ((opt = getopt(argc, argv, "b:m:r:f:j:d:i:hs")) != -1) { switch (opt) { @@ -218,7 +222,20 @@ int main(int argc, char **argv) case 'z': sai_deserialize_redis_communication_mode(optarg, gRedisCommunicationMode); break; - + case 'f': + swss_rec_filename = optarg; + if (swss_rec_filename.empty()) + { + swss_rec_filename= "swss.rec"; + } + break; + case 'j': + sairedis_rec_filename = optarg; + if (sairedis_rec_filename.empty()) + { + sairedis_rec_filename= "sairedis.rec"; + } + break; default: /* '?' */ exit(EXIT_FAILURE); } @@ -227,7 +244,7 @@ int main(int argc, char **argv) SWSS_LOG_NOTICE("--- Starting Orchestration Agent ---"); initSaiApi(); - initSaiRedis(record_location); + initSaiRedis(record_location, sairedis_rec_filename); sai_attribute_t attr; vector attrs; @@ -242,7 +259,7 @@ int main(int argc, char **argv) /* Disable/enable SwSS recording */ if (gSwssRecord) { - gRecordFile = record_location + "/" + "swss.rec"; + gRecordFile = record_location + "/" + swss_rec_filename; gRecordOfs.open(gRecordFile, std::ofstream::out | std::ofstream::app); if (!gRecordOfs.is_open()) { diff --git a/orchagent/saihelper.cpp b/orchagent/saihelper.cpp index 8e50eb13d5..1074969bc2 100644 --- a/orchagent/saihelper.cpp +++ b/orchagent/saihelper.cpp @@ -199,7 +199,7 @@ void initSaiApi() sai_log_set((sai_api_t)SAI_API_NAT, SAI_LOG_LEVEL_NOTICE); } -void initSaiRedis(const string &record_location) +void initSaiRedis(const string &record_location, const std::string &record_filename) { /** * NOTE: Notice that all Redis attributes here are using SAI_NULL_OBJECT_ID @@ -225,6 +225,19 @@ void initSaiRedis(const string &record_location) record_location.c_str(), status); exit(EXIT_FAILURE); } + + attr.id = SAI_REDIS_SWITCH_ATTR_RECORDING_FILENAME; + attr.value.s8list.count = (uint32_t)record_filename.size(); + attr.value.s8list.list = (int8_t*)const_cast(record_filename.c_str()); + + status = sai_switch_api->set_switch_attribute(gSwitchId, &attr); + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("Failed to set SAI Redis recording logfile to %s, rv:%d", + record_filename.c_str(), status); + exit(EXIT_FAILURE); + } + } /* Disable/enable SAI Redis recording */ diff --git a/orchagent/saihelper.h b/orchagent/saihelper.h index 34bef06a67..450acf8b69 100644 --- a/orchagent/saihelper.h +++ b/orchagent/saihelper.h @@ -5,5 +5,5 @@ #include void initSaiApi(); -void initSaiRedis(const std::string &record_location); +void initSaiRedis(const std::string &record_location, const std::string &record_filename); sai_status_t initSaiPhyApi(swss::gearbox_phy_t *phy); From 9b48b49b77e3e7081b5b3fbf14e6153e239a509a Mon Sep 17 00:00:00 2001 From: Arvindsrinivasan Lakshmi Narasimhan Date: Tue, 15 Dec 2020 04:08:34 +0000 Subject: [PATCH 2/5] fix merge issue Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan --- orchagent/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/orchagent/main.cpp b/orchagent/main.cpp index 4f89c50794..ca4341b806 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -65,7 +65,7 @@ string gRecordFile; 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]" << 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]" << endl; cout << " -h: display this message" << endl; cout << " -r record_type: record orchagent logs with type (default 3)" << endl; cout << " 0: do not record logs" << endl; @@ -166,7 +166,7 @@ int main(int argc, char **argv) string swss_rec_filename = "swss.rec"; string sairedis_rec_filename = "sairedis.rec"; - while ((opt = getopt(argc, argv, "b:m:r:f:j:d:i:hs")) != -1) + while ((opt = getopt(argc, argv, "b:m:r:f:j:d:i:hsz")) != -1) { switch (opt) { From 1ec9a327123137bec0fb687c531d7dab37e7cddc Mon Sep 17 00:00:00 2001 From: Arvindsrinivasan Lakshmi Narasimhan Date: Tue, 15 Dec 2020 17:41:07 +0000 Subject: [PATCH 3/5] fix another merge issue Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan --- orchagent/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orchagent/main.cpp b/orchagent/main.cpp index ca4341b806..15f782305f 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -166,7 +166,7 @@ int main(int argc, char **argv) string swss_rec_filename = "swss.rec"; string sairedis_rec_filename = "sairedis.rec"; - while ((opt = getopt(argc, argv, "b:m:r:f:j:d:i:hsz")) != -1) + while ((opt = getopt(argc, argv, "b:m:r:f:j:d:i:hsz:")) != -1) { switch (opt) { From ab21658b3826ae647f5a230d121f95ed8fdb52e6 Mon Sep 17 00:00:00 2001 From: Arvindsrinivasan Lakshmi Narasimhan Date: Tue, 29 Dec 2020 05:33:35 +0000 Subject: [PATCH 4/5] address review comments Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan --- orchagent/main.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/orchagent/main.cpp b/orchagent/main.cpp index 15f782305f..146f02c3e3 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -232,17 +232,16 @@ int main(int argc, char **argv) sai_deserialize_redis_communication_mode(optarg, gRedisCommunicationMode); break; case 'f': - swss_rec_filename = optarg; - if (swss_rec_filename.empty()) + + if (optarg) { - swss_rec_filename= "swss.rec"; + swss_rec_filename = optarg; } break; case 'j': - sairedis_rec_filename = optarg; - if (sairedis_rec_filename.empty()) + if (optarg) { - sairedis_rec_filename= "sairedis.rec"; + sairedis_rec_filename = optarg; } break; default: /* '?' */ From ce85a6c21ab0f1eaf492b6c6b15d11f5b8e9b96b Mon Sep 17 00:00:00 2001 From: Arvindsrinivasan Lakshmi Narasimhan Date: Tue, 29 Dec 2020 05:35:43 +0000 Subject: [PATCH 5/5] address review comments Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan --- orchagent/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orchagent/main.cpp b/orchagent/main.cpp index 146f02c3e3..09a4057056 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -79,7 +79,7 @@ void usage() cout << " -s: enable synchronous mode (depreacated, use -z)" << endl; cout << " -z: redis communication mode (redis_async|redis_sync|zmq_sync), default: redis_async" << endl; cout << " -f swss_rec_filename: swss record log filename(default 'swss.rec')" << endl; - cout << " -j sairedis_rec_filename: sairedis record log filename(default sairedis.rec)" << endl; + cout << " -j sairedis_rec_filename: sairedis record log filename(default sairedis.rec)" << endl; } void sighup_handler(int signo)