From 01a3e3c87641972bfe8d898fbea2d890858a0d63 Mon Sep 17 00:00:00 2001 From: Vivek Reddy Date: Fri, 23 Jan 2026 10:17:32 +0200 Subject: [PATCH 1/2] [swsconfig] Add custom ZMQ endpoint Signed-off-by: Vivek Reddy --- swssconfig/swssconfig.cpp | 43 ++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/swssconfig/swssconfig.cpp b/swssconfig/swssconfig.cpp index 115988a239f..6e29036a86f 100644 --- a/swssconfig/swssconfig.cpp +++ b/swssconfig/swssconfig.cpp @@ -27,8 +27,10 @@ const string SWSS_CONFIG_DIR = "/etc/swss/config.d/"; void usage() { - cout << "Usage: swssconfig [FILE...]" << endl; + cout << "Usage: swssconfig [OPTIONS] [FILE...]" << endl; cout << " (default config folder is /etc/swss/config.d/)" << endl; + cout << "Options:" << endl; + cout << " -e, --endpoint ENDPOINT ZMQ endpoint address (e.g., tcp://localhost or tcp://127.0.0.1)" << endl; } void dump_db_item(KeyOpFieldsValuesTuple &db_item) @@ -68,7 +70,7 @@ shared_ptr get_table(unordered_map &db_items, set &zmq_tables, std::shared_ptr zmq_client) { - DBConnector db("APPL_DB", 0, false); + DBConnector db("DPU_APPL_DB", 0, true); RedisPipeline pipeline(&db); // dtor of RedisPipeline will automatically flush data unordered_map> table_map; @@ -193,28 +195,41 @@ vector read_directory(const string &path) int main(int argc, char **argv) { vector files; - if (argc == 1) + string zmq_endpoint = ZMQ_LOCAL_ADDRESS; + + // Parse command-line arguments + for (int i = 1; i < argc; i++) { - files = read_directory(SWSS_CONFIG_DIR); - } - if (argc == 2 && !strcmp(argv[1], "-h")) - { - usage(); - exit(EXIT_SUCCESS); - } - else - { - for (auto i = 1; i < argc; i++) + if (!strcmp(argv[i], "-e") || !strcmp(argv[i], "--endpoint")) + { + if (i + 1 < argc) + { + zmq_endpoint = string(argv[++i]); + } + else + { + cerr << "Error: -e/--endpoint requires an argument" << endl; + usage(); + exit(EXIT_FAILURE); + } + } + else { files.push_back(string(argv[i])); } } + + // If no files specified, use default directory + if (files.empty()) + { + files = read_directory(SWSS_CONFIG_DIR); + } auto zmq_tables = load_zmq_tables(); std::shared_ptr zmq_client = nullptr; if (zmq_tables.size() > 0) { - zmq_client = create_zmq_client(ZMQ_LOCAL_ADDRESS); + zmq_client = create_zmq_client(zmq_endpoint); } for (auto i : files) From e1c4d5f02fdf27a2f9e8014a654c3d34f6b0642a Mon Sep 17 00:00:00 2001 From: Vivek Reddy Date: Tue, 10 Feb 2026 10:14:09 +0200 Subject: [PATCH 2/2] Use DB based on endpoint Signed-off-by: Vivek Reddy --- swssconfig/swssconfig.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/swssconfig/swssconfig.cpp b/swssconfig/swssconfig.cpp index 6e29036a86f..ba4fc5c6a32 100644 --- a/swssconfig/swssconfig.cpp +++ b/swssconfig/swssconfig.cpp @@ -68,9 +68,12 @@ shared_ptr get_table(unordered_map &db_items, set &zmq_tables, std::shared_ptr zmq_client) +bool write_db_data(vector &db_items, set &zmq_tables, std::shared_ptr zmq_client, bool use_custom_endpoint) { - DBConnector db("DPU_APPL_DB", 0, true); + // If custom endpoint is used, it's for DPU Orchagent - use DPU_APPL_DB + // Otherwise use APPL_DB + string db_name = use_custom_endpoint ? "DPU_APPL_DB" : "APPL_DB"; + DBConnector db(db_name, 0, true); RedisPipeline pipeline(&db); // dtor of RedisPipeline will automatically flush data unordered_map> table_map; @@ -227,6 +230,8 @@ int main(int argc, char **argv) auto zmq_tables = load_zmq_tables(); std::shared_ptr zmq_client = nullptr; + + bool use_custom_endpoint = (zmq_endpoint != ZMQ_LOCAL_ADDRESS); if (zmq_tables.size() > 0) { zmq_client = create_zmq_client(zmq_endpoint); @@ -253,7 +258,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - if (!write_db_data(db_items, zmq_tables, zmq_client)) + if (!write_db_data(db_items, zmq_tables, zmq_client, use_custom_endpoint)) { SWSS_LOG_ERROR("Failed applying data from JSON file %s", i.c_str()); return EXIT_FAILURE;