diff --git a/configure.ac b/configure.ac old mode 100644 new mode 100755 index 43fe79fab..5cddce073 --- a/configure.ac +++ b/configure.ac @@ -297,6 +297,7 @@ AC_OUTPUT(Makefile unittest/vslib/Makefile unittest/syncd/Makefile unittest/proxylib/Makefile + unittest/saidump/Makefile pyext/Makefile pyext/py2/Makefile pyext/py3/Makefile) diff --git a/saidump/Makefile.am b/saidump/Makefile.am old mode 100644 new mode 100755 index 46c51d0fc..c4515cc99 --- a/saidump/Makefile.am +++ b/saidump/Makefile.am @@ -2,8 +2,11 @@ AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/lib bin_PROGRAMS = saidump -saidump_SOURCES = saidump.cpp +saidump_SOURCES = main.cpp saidump.cpp saidump_CPPFLAGS = $(CODE_COVERAGE_CPPFLAGS) saidump_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS) saidump_LDADD = -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta \ -L$(top_srcdir)/lib/.libs -lsairedis -lzmq $(CODE_COVERAGE_LIBS) + +noinst_LIBRARIES = libsaidump.a +libsaidump_a_SOURCES = saidump.cpp diff --git a/saidump/main.cpp b/saidump/main.cpp new file mode 100755 index 000000000..42780f54c --- /dev/null +++ b/saidump/main.cpp @@ -0,0 +1,19 @@ +#include "saidump.h" + +using namespace syncd; + +int main(int argc, char **argv) +{ + SWSS_LOG_ENTER(); + swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_INFO); + + SaiDump m_saiDump; + + if(SAI_STATUS_SUCCESS != m_saiDump.handleCmdLine(argc, argv)) + { + return EXIT_FAILURE; + } + + m_saiDump.dumpFromRedisDb(); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/saidump/saidump.cpp b/saidump/saidump.cpp index 42441b4a3..83f55d777 100755 --- a/saidump/saidump.cpp +++ b/saidump/saidump.cpp @@ -1,45 +1,7 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -extern "C" { -#include -} - -#include "swss/table.h" -#include "meta/sai_serialize.h" -#include "sairediscommon.h" -#include - -#include - -// TODO split to multiple cpp - -using namespace swss; -using json = nlohmann::json; +#include "saidump.h" +using namespace syncd; -// Default value: 100 MB -constexpr int64_t RDB_JSON_MAX_SIZE = 1024 * 1024 * 100; - -struct CmdOptions -{ - bool skipAttributes; - bool dumpTempView; - bool dumpGraph; - std::string rdbJsonFile; - uint64_t rdbJSonSizeLimit; -}; - - -static CmdOptions g_cmdOptions; -static std::map g_oid_map; - -void printUsage() +void SaiDump::printUsage() { SWSS_LOG_ENTER(); @@ -56,15 +18,14 @@ void printUsage() std::cout << " Print out this message" << std::endl; } -CmdOptions handleCmdLine(int argc, char **argv) +sai_status_t SaiDump::handleCmdLine(int argc, char **argv) { SWSS_LOG_ENTER(); - CmdOptions options; - - options.dumpTempView = false; - options.dumpGraph = false; - options.rdbJSonSizeLimit = RDB_JSON_MAX_SIZE; + sai_status_t status = SAI_STATUS_SUCCESS; + dumpTempView = false; + dumpGraph = false; + rdbJSonSizeLimit = RDB_JSON_MAX_SIZE; const char* const optstring = "gtr:m:h"; uint64_t result = 0; @@ -94,17 +55,20 @@ CmdOptions handleCmdLine(int argc, char **argv) { case 'g': SWSS_LOG_NOTICE("Dumping graph"); - options.dumpGraph = true; + dumpGraph = true; + status = SAI_STATUS_SUCCESS; break; case 't': SWSS_LOG_NOTICE("Dumping temp view"); - options.dumpTempView = true; + dumpTempView = true; + status = SAI_STATUS_SUCCESS; break; case 'r': SWSS_LOG_NOTICE("Dumping from %s", optarg); - options.rdbJsonFile = std::string(optarg); + rdbJsonFile = std::string(optarg); + status = SAI_STATUS_SUCCESS; break; case 'm': @@ -124,9 +88,9 @@ CmdOptions handleCmdLine(int argc, char **argv) exit(EXIT_SUCCESS); } - options.rdbJSonSizeLimit = result * 1024 * 1024; - SWSS_LOG_NOTICE("Configure the RDB JSON MAX size to %llu MB", options.rdbJSonSizeLimit / 1024 / 1024); - + rdbJSonSizeLimit = result * 1024 * 1024; + SWSS_LOG_NOTICE("Configure the RDB JSON MAX size to %llu MB", rdbJSonSizeLimit / 1024 / 1024); + status = SAI_STATUS_SUCCESS; break; case 'h': @@ -143,11 +107,10 @@ CmdOptions handleCmdLine(int argc, char **argv) exit(EXIT_FAILURE); } } - - return options; + return status; } -size_t get_max_attr_len(const TableMap& map) +size_t SaiDump::get_max_attr_len(const swss::TableMap& map) { SWSS_LOG_ENTER(); @@ -161,7 +124,7 @@ size_t get_max_attr_len(const TableMap& map) return max; } -std::string pad_string(std::string s, size_t pad) +std::string SaiDump::pad_string(std::string s, size_t pad) { SWSS_LOG_ENTER(); @@ -175,7 +138,7 @@ std::string pad_string(std::string s, size_t pad) return s; } -const TableMap* get_table_map(sai_object_id_t object_id) +const swss::TableMap* SaiDump::get_table_map(sai_object_id_t object_id) { SWSS_LOG_ENTER(); @@ -190,7 +153,7 @@ const TableMap* get_table_map(sai_object_id_t object_id) return it->second; } -void print_attributes(size_t indent, const TableMap& map) +void SaiDump::print_attributes(size_t indent, const swss::TableMap& map) { SWSS_LOG_ENTER(); @@ -218,7 +181,7 @@ void print_attributes(size_t indent, const TableMap& map) #define GV_ROOT_COLOR "0.650 0.200 1.000" #define GV_NODE_COLOR "0.650 0.500 1.000" -void dumpGraph(const TableDump& td) +void SaiDump::dumpGraphFun(const swss::TableDump& td) { SWSS_LOG_ENTER(); @@ -451,7 +414,7 @@ void dumpGraph(const TableDump& td) /** * @brief Process the input JSON file to make sure it's a valid JSON file for the JSON library. */ -static sai_status_t preProcessFile(const std::string file_name) +sai_status_t SaiDump::preProcessFile(const std::string file_name) { SWSS_LOG_ENTER(); @@ -465,11 +428,11 @@ static sai_status_t preProcessFile(const std::string file_name) input_file.seekg(0, std::ios::end); // Move to the end of the file uint64_t file_size = input_file.tellg(); // Get the current position - SWSS_LOG_NOTICE("Get %s's size %" PRIu64 " Bytes, limit: %" PRIu64 " MB.", file_name.c_str(), file_size, g_cmdOptions.rdbJSonSizeLimit / 1024 / 1024); + SWSS_LOG_NOTICE("Get %s's size %" PRIu64 " Bytes, limit: %" PRIu64 " MB.", file_name.c_str(), file_size, rdbJSonSizeLimit / 1024 / 1024); - if (file_size >= g_cmdOptions.rdbJSonSizeLimit) + if (file_size >= rdbJSonSizeLimit) { - SWSS_LOG_ERROR_AND_STDERR("Get %s's size failure or its size %" PRIu64 " >= %" PRIu64 " MB.", file_name.c_str(), file_size, g_cmdOptions.rdbJSonSizeLimit / 1024 / 1024); + SWSS_LOG_ERROR_AND_STDERR("Get %s's size failure or its size %" PRIu64 " >= %" PRIu64 " MB.", file_name.c_str(), file_size, rdbJSonSizeLimit / 1024 / 1024); return SAI_STATUS_FAILURE; } @@ -502,7 +465,7 @@ static sai_status_t preProcessFile(const std::string file_name) return SAI_STATUS_SUCCESS; } -static void traverseJson(const json & jsn) +void SaiDump::traverseJson(const nlohmann::json & jsn) { SWSS_LOG_ENTER(); if (jsn.is_object()) @@ -533,14 +496,14 @@ static void traverseJson(const json & jsn) } std::cout << item_name << " " << std::endl; - json jsn_sub = it.value(); + nlohmann::json jsn_sub = it.value(); if (!it->is_object()) { continue; } - TableMap map; + swss::TableMap map; for (auto it_sub = jsn_sub.begin(); it_sub != jsn_sub.end(); ++it_sub) { @@ -574,71 +537,61 @@ static void traverseJson(const json & jsn) } } -static sai_status_t dumpFromRedisRdbJson(const std::string file_name) +sai_status_t SaiDump::dumpFromRedisRdbJson() { SWSS_LOG_ENTER(); - std::ifstream input_file(file_name); + if (SAI_STATUS_FAILURE == preProcessFile(rdbJsonFile)) + { + return SAI_STATUS_FAILURE; + } + + std::ifstream input_file(rdbJsonFile); if (!input_file.is_open()) { - SWSS_LOG_ERROR_AND_STDERR("The file %s does not exist for dumping from Redis RDB JSON file.", file_name.c_str()); + SWSS_LOG_ERROR_AND_STDERR("The file %s does not exist for dumping from Redis RDB JSON file.", rdbJsonFile.c_str()); return SAI_STATUS_FAILURE; } try { // Parse the JSON data from the file (validation) - json jsonData; + nlohmann::json jsonData; input_file >> jsonData; traverseJson(jsonData); return SAI_STATUS_SUCCESS; } catch (std::exception &ex) { - SWSS_LOG_ERROR_AND_STDERR("JSON file %s is invalid.", file_name.c_str()); + SWSS_LOG_ERROR_AND_STDERR("JSON file %s is invalid.", rdbJsonFile.c_str()); SWSS_LOG_ERROR_AND_STDERR("JSON parsing error: %s.", ex.what()); } return SAI_STATUS_FAILURE; } -int main(int argc, char **argv) +void SaiDump::dumpFromRedisDb() { - swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG); - SWSS_LOG_ENTER(); - - swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_NOTICE); - - swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_INFO); - - g_cmdOptions = handleCmdLine(argc, argv); - - - if (g_cmdOptions.rdbJsonFile.size() > 0) + if (rdbJsonFile.size() > 0) { - if (SAI_STATUS_FAILURE == preProcessFile(g_cmdOptions.rdbJsonFile)) - { - return EXIT_FAILURE; - } - - return dumpFromRedisRdbJson(g_cmdOptions.rdbJsonFile); + dumpFromRedisRdbJson(); + return; } swss::DBConnector db("ASIC_DB", 0); std::string table = ASIC_STATE_TABLE; - if (g_cmdOptions.dumpTempView) + if (dumpTempView) { table = TEMP_PREFIX + table; } swss::Table t(&db, table); - TableDump dump; - + swss::TableDump dump; t.dump(dump); for (const auto&key: dump) @@ -656,16 +609,14 @@ int main(int argc, char **argv) { sai_object_id_t object_id; sai_deserialize_object_id(str_object_id, object_id); - g_oid_map[object_id] = &key.second; } } - if (g_cmdOptions.dumpGraph) + if (dumpGraph) { - dumpGraph(dump); - - return EXIT_SUCCESS; + dumpGraphFun(dump); + return; } for (const auto&key: dump) @@ -673,15 +624,10 @@ int main(int argc, char **argv) auto start = key.first.find_first_of(":"); auto str_object_type = key.first.substr(0, start); auto str_object_id = key.first.substr(start + 1); - std::cout << str_object_type << " " << str_object_id << " " << std::endl; size_t indent = 4; - print_attributes(indent, key.second); - std::cout << std::endl; } - - return EXIT_SUCCESS; } diff --git a/saidump/saidump.h b/saidump/saidump.h new file mode 100755 index 000000000..a8435531e --- /dev/null +++ b/saidump/saidump.h @@ -0,0 +1,50 @@ +#pragma once + +extern "C" { +#include +} +#include +#include +#include +#include +#include +#include "swss/table.h" +#include "meta/sai_serialize.h" +#include "sairediscommon.h" +#include + +// Default value: 100MB +static constexpr int64_t RDB_JSON_MAX_SIZE = 1024 * 1024 * 100; + +namespace syncd +{ + class SaiDump + { + public: + SaiDump() = default; + ~SaiDump() = default; + sai_status_t handleCmdLine(int argc, char **argv); + void dumpFromRedisDb(); + void printUsage(); + sai_status_t dumpFromRedisRdbJson(); + sai_status_t preProcessFile(const std::string file_name); + void traverseJson(const nlohmann::json & jsn); + + public: + std::string rdbJsonFile; + uint64_t rdbJSonSizeLimit; + + private: + bool skipAttributes; + bool dumpTempView; + bool dumpGraph; + std::map g_oid_map; + + private: + size_t get_max_attr_len(const swss::TableMap& map); + std::string pad_string(std::string s, size_t pad); + const swss::TableMap* get_table_map(sai_object_id_t object_id); + void dumpGraphFun(const swss::TableDump& td); + void print_attributes(size_t indent, const swss::TableMap& map); + }; +} diff --git a/tests/checkwhitespace.sh b/tests/checkwhitespace.sh index 24ce0f5df..61b6f0d42 100755 --- a/tests/checkwhitespace.sh +++ b/tests/checkwhitespace.sh @@ -7,7 +7,7 @@ grep -v SAI/ | grep -v debian/ | grep -v _wrap.cpp | perl -ne 'print if /\.(c|cpp|h|hpp|am|sh|pl|pm|install|dirs|links|json|ini|yml|pws|md|py|cfg|conf|i|ac)$/' | -xargs grep -P "\\s\$" +xargs grep -nrP "\\s\$" if [ $? -eq 0 ]; then echo ERROR: some files contain white spaces at the end of line, please fix diff --git a/unittest/Makefile.am b/unittest/Makefile.am old mode 100644 new mode 100755 index 8cd9711fc..6dbf301d8 --- a/unittest/Makefile.am +++ b/unittest/Makefile.am @@ -1 +1 @@ -SUBDIRS = meta lib vslib syncd proxylib +SUBDIRS = meta lib vslib syncd proxylib saidump diff --git a/unittest/saidump/Makefile.am b/unittest/saidump/Makefile.am new file mode 100755 index 000000000..0519d4ca6 --- /dev/null +++ b/unittest/saidump/Makefile.am @@ -0,0 +1,13 @@ +AM_CXXFLAGS = $(SAIINC) -I$(top_srcdir)/saidump -I$(top_srcdir)/lib -I$(top_srcdir)/vslib -I$(top_srcdir)/meta + +bin_PROGRAMS = tests + +LDADD_GTEST = -L/usr/src/gtest -lgtest -lgtest_main + +tests_SOURCES = main.cpp + +tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON) +tests_LDFLAGS = -D_UNITTEST_ +tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/saidump/libsaidump.a -lhiredis -lswsscommon -lnl-genl-3 -lnl-nf-3 -lnl-route-3 -lnl-3 -lpthread -L$(top_srcdir)/lib/.libs -lsairedis -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS) + +TESTS = tests \ No newline at end of file diff --git a/unittest/saidump/dump.json b/unittest/saidump/dump.json new file mode 100755 index 000000000..33971c622 --- /dev/null +++ b/unittest/saidump/dump.json @@ -0,0 +1,107 @@ +[{ +"ROUTE_TABLE:192.169.240.128/25":{"protocol":"bgp","nexthop":"10.0.0.19,10.0.0.23","ifname":"Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:20c0:b9e0:0:80::/64":{"protocol":"bgp","nexthop":"fc00::e,fc00::16","ifname":"Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:20c0:b910:0:80::/64":{"protocol":"bgp","nexthop":"fc00::e,fc00::16","ifname":"Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:192.184.144.0/25":{"protocol":"bgp","nexthop":"10.0.0.1,10.0.0.5","ifname":"Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:20c0:b430:0:80::/64":{"protocol":"bgp","nexthop":"fc00::2,fc00::a","ifname":"Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:192.200.16.128/25":{"protocol":"bgp","nexthop":"10.0.0.1,10.0.0.5,10.0.0.7,10.0.0.11","ifname":"Ethernet-IB0,Ethernet-IB0,Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:20c0:d690::/64":{"protocol":"bgp","nexthop":"fc00::2,fc00::a,fc00::e,fc00::16","ifname":"Ethernet-IB0,Ethernet-IB0,Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:192.216.160.128/25":{"protocol":"bgp","nexthop":"10.0.0.1,10.0.0.5,10.0.0.7,10.0.0.11","ifname":"Ethernet-IB0,Ethernet-IB0,Ethernet-IB0,Ethernet-IB0"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board181:asic0:Ethernet136:5-6":{"profile":"egress_lossy_profile"}, +"ROUTE_TABLE:192.194.224.0/25":{"protocol":"bgp","nexthop":"10.0.0.7,10.0.0.11","ifname":"Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:192.203.112.128/25":{"protocol":"bgp","nexthop":"10.0.0.1,10.0.0.5,10.0.0.7,10.0.0.11","ifname":"Ethernet-IB0,Ethernet-IB0,Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:192.189.80.0/25":{"protocol":"bgp","nexthop":"10.0.0.7,10.0.0.11","ifname":"Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:20c0:d380:0:80::/64":{"protocol":"bgp","nexthop":"fc00::2,fc00::a,fc00::e,fc00::16","ifname":"Ethernet-IB0,Ethernet-IB0,Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:fc00::2e":{"protocol":"kernel","nexthop":"::","ifname":"Ethernet-IB0"}, +"ROUTE_TABLE:20c0:cc10::/64":{"protocol":"bgp","nexthop":"fc00::2,fc00::a,fc00::e,fc00::16","ifname":"Ethernet-IB0,Ethernet-IB0,Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:192.212.32.128/25":{"protocol":"bgp","nexthop":"10.0.0.1,10.0.0.5,10.0.0.7,10.0.0.11","ifname":"Ethernet-IB0,Ethernet-IB0,Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:20c0:b1a0::/64":{"protocol":"bgp","nexthop":"fc00::2,fc00::a","ifname":"Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:192.199.16.128/25":{"protocol":"bgp","nexthop":"10.0.0.7,10.0.0.11","ifname":"Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:192.169.64.128/25":{"protocol":"bgp","nexthop":"10.0.0.19,10.0.0.23","ifname":"Ethernet-IB0,Ethernet-IB0"}, +"NEIGH_TABLE:Ethernet136:10.0.0.17":{"neigh":"be:fc:32:7d:1c:7e","family":"IPv4"}, +"ROUTE_TABLE:192.199.0.0/25":{"protocol":"bgp","nexthop":"10.0.0.7,10.0.0.11","ifname":"Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:192.174.128.0/25":{"protocol":"bgp","nexthop":"10.0.0.1,10.0.0.5","ifname":"Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:20c0:c940:0:80::/64":{"protocol":"bgp","nexthop":"fc00::2,fc00::a,fc00::e,fc00::16","ifname":"Ethernet-IB0,Ethernet-IB0,Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:192.209.112.0/25":{"protocol":"bgp","nexthop":"10.0.0.1,10.0.0.5,10.0.0.7,10.0.0.11","ifname":"Ethernet-IB0,Ethernet-IB0,Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:192.210.208.128/25":{"protocol":"bgp","nexthop":"10.0.0.1,10.0.0.5,10.0.0.7,10.0.0.11","ifname":"Ethernet-IB0,Ethernet-IB0,Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:20c0:ada0:0:80::/64":{"protocol":"bgp","nexthop":"fc00::2,fc00::a","ifname":"Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:192.204.96.0/25":{"protocol":"bgp","nexthop":"10.0.0.1,10.0.0.5,10.0.0.7,10.0.0.11","ifname":"Ethernet-IB0,Ethernet-IB0,Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:20c0:b2d0:0:80::/64":{"protocol":"bgp","nexthop":"fc00::2,fc00::a","ifname":"Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:20c0:b950::/64":{"protocol":"bgp","nexthop":"fc00::e,fc00::16","ifname":"Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:192.197.32.128/25":{"protocol":"bgp","nexthop":"10.0.0.7,10.0.0.11","ifname":"Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:192.207.160.128/25":{"protocol":"bgp","nexthop":"10.0.0.1,10.0.0.5,10.0.0.7,10.0.0.11","ifname":"Ethernet-IB0,Ethernet-IB0,Ethernet-IB0,Ethernet-IB0"}, +"ROUTE_TABLE:192.172.64.0/25":{"protocol":"bgp","nexthop":"10.0.0.1,10.0.0.5","ifname":"Ethernet-IB0,Ethernet-IB0"}, +"INTF_TABLE:Loopback4096":{"NULL":"NULL","mac_addr":"00:00:00:00:00:00"}}, +{ +"ROUTE_TABLE:10.1.0.2":{"nexthop":"3.3.3.18,3.3.3.20","ifname":"Ethernet-IB0,Ethernet-IB0","weight":"1,1"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic0:Ethernet136:5-6":{"profile":"egress_lossy_profile"}, +"SYSTEM_PORT_TABLE:ixre-egl-board41|asic0|Ethernet112":{"core_index":"0","core_port_index":"15","num_voq":"8","speed":"400000","switch_id":"18","system_port_id":"57"}, +"SYSTEM_PORT_TABLE:ixre-egl-board40|asic1|Ethernet280":{"core_index":"0","core_port_index":"18","num_voq":"8","speed":"400000","switch_id":"2","system_port_id":"39"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic1:Ethernet176:3-4":{"profile":"egress_lossless_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic0:Ethernet64:5-6":{"profile":"egress_lossy_profile"}, +"SYSTEM_PORT_TABLE:ixre-egl-board40|asic0|Ethernet-IB0":{"core_index":"0","core_port_index":"19","num_voq":"8","speed":"10000","switch_id":"0","system_port_id":"19"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board40:asic1:Ethernet176:3-4":{"profile":"egress_lossless_profile"}, +"SYSTEM_PORT_TABLE:ixre-egl-board40|asic1|Ethernet208":{"core_index":"1","core_port_index":"9","num_voq":"8","speed":"400000","switch_id":"2","system_port_id":"30"}, +"INTF_TABLE:Ethernet136:10.0.0.4/31":{"scope":"global","family":"IPv4"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board40:asic1:Ethernet224:3-4":{"profile":"egress_lossless_profile"}, +"BUFFER_PROFILE_TABLE:egress_lossy_profile":{"dynamic_th":"-1","pool":"ingress_lossless_pool","size":"0"}, +"ROUTE_TABLE:10.0.0.10/31":{"nexthop":"3.3.3.2","ifname":"Ethernet-IB0"}, +"SYSTEM_PORT_TABLE:ixre-egl-board41|asic0|Ethernet-IB0":{"core_index":"0","core_port_index":"19","num_voq":"8","speed":"10000","switch_id":"18","system_port_id":"61"}, +"SYSTEM_PORT_TABLE:ixre-egl-board40|asic0|Ethernet64":{"core_index":"1","core_port_index":"9","num_voq":"8","speed":"400000","switch_id":"0","system_port_id":"9"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic0:Ethernet0:5-6":{"profile":"egress_lossy_profile"}, +"BUFFER_PG_TABLE:Ethernet80:0":{"profile":"ingress_lossy_profile"}, +"SYSTEM_PORT_TABLE:ixre-egl-board41|asic1|Ethernet-Rec1":{"core_index":"1","core_port_index":"20","num_voq":"8","speed":"10000","switch_id":"20","system_port_id":"83"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic1:Ethernet224:0-2":{"profile":"egress_lossy_profile"}, +"ROUTE_TABLE:10.0.0.4/31":{"nexthop":"0.0.0.0","ifname":"Ethernet136"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic0:Ethernet120:3-4":{"profile":"egress_lossless_profile"}, +"PORT_TABLE:Ethernet104":{"alias":"Ethernet14/1","asic_port_name":"Eth104","coreid":"0","coreportid":"14","description":"Ethernet14/1","index":"14","lanes":"32,33,34,35,36,37,38,39","mtu":"9100","numvoq":"8","pfc_asym":"off","role":"Ext","speed":"400000","tpid":"0x8100","admin_status":"down","oper_status":"down"}, +"ROUTE_TABLE:3333::3:1":{"nexthop":"::","ifname":"Ethernet-IB0"}, +"INTF_TABLE:Ethernet-IB0:3.3.3.1/32":{"scope":"global","family":"IPv4"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic1:Ethernet272:0-2":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic0:Ethernet8:5-6":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board40:asic0:Ethernet104:0-2":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic0:Ethernet96:0-2":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic0:Ethernet8:3-4":{"profile":"egress_lossless_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic0:Ethernet72:0-2":{"profile":"egress_lossy_profile"}, +"LAG_MEMBER_TABLE:PortChannel102:Ethernet80":{"status":"disabled"}, +"SYSTEM_PORT_TABLE:ixre-egl-board41|asic1|Ethernet192":{"core_index":"1","core_port_index":"7","num_voq":"8","speed":"400000","switch_id":"20","system_port_id":"70"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board40:asic1:Ethernet160:3-4":{"profile":"egress_lossless_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board40:asic0:Ethernet96:5-6":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board40:asic1:Ethernet264:3-4":{"profile":"egress_lossless_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board40:asic1:Ethernet272:5-6":{"profile":"egress_lossy_profile"}, +"BUFFER_POOL_TABLE:ingress_lossless_pool":{"mode":"dynamic","size":"6441610000","type":"both","xoff":"11354112"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic1:Ethernet192:5-6":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board40:asic1:Ethernet272:3-4":{"profile":"egress_lossless_profile"}, +"LAG_MEMBER_TABLE:PortChannel102:Ethernet32":{"status":"disabled"}, +"SYSTEM_PORT_TABLE:ixre-egl-board41|asic1|Ethernet184":{"core_index":"1","core_port_index":"6","num_voq":"8","speed":"400000","switch_id":"20","system_port_id":"69"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic1:Ethernet208:0-2":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board40:asic1:Ethernet248:0-2":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board40:asic0:Ethernet72:0-2":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board40:asic0:Ethernet32:3-4":{"profile":"egress_lossless_profile"}, +"INTF_TABLE:PortChannel102:10.0.0.0/31":{"scope":"global","family":"IPv4"}, +"PORT_TABLE:Ethernet32":{"mtu":"9100","admin_status":"up","alias":"Ethernet5/1","asic_port_name":"Eth32","coreid":"1","coreportid":"5","description":"ARISTA01T3:Ethernet1","index":"5","lanes":"104,105,106,107,108,109,110,111","numvoq":"8","pfc_asym":"off","role":"Ext","speed":"400000","tpid":"0x8100","oper_status":"up"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board40:asic1:Ethernet168:5-6":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic1:Ethernet176:0-2":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic0:Ethernet56:5-6":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic0:Ethernet96:3-4":{"profile":"egress_lossless_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board40:asic0:Ethernet120:5-6":{"profile":"egress_lossy_profile"}, +"BUFFER_PROFILE_TABLE:ingress_lossy_profile":{"dynamic_th":"0","pool":"ingress_lossless_pool","size":"1280","xon_offset":"2560"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic0:Ethernet48:0-2":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic1:Ethernet200:0-2":{"profile":"egress_lossy_profile"}, +"COPP_TABLE:queue1_group1":{"cbs":"6000","cir":"6000","meter_type":"packets","mode":"sr_tcm","queue":"1","red_action":"drop","trap_action":"trap","trap_priority":"1","trap_ids":"ip2me"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board40:asic1:Ethernet184:3-4":{"profile":"egress_lossless_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic1:Ethernet248:5-6":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic1:Ethernet256:3-4":{"profile":"egress_lossless_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board40:asic0:Ethernet88:5-6":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board40:asic0:Ethernet48:3-4":{"profile":"egress_lossless_profile"}, +"SYSTEM_PORT_TABLE:ixre-egl-board40|asic1|Ethernet224":{"core_index":"0","core_port_index":"11","num_voq":"8","speed":"400000","switch_id":"2","system_port_id":"32"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic0:Ethernet24:0-2":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board40:asic1:Ethernet168:0-2":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic0:Ethernet56:3-4":{"profile":"egress_lossless_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic1:Ethernet272:5-6":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board40:asic1:Ethernet208:5-6":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic0:Ethernet96:5-6":{"profile":"egress_lossy_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic1:Ethernet152:3-4":{"profile":"egress_lossless_profile"}, +"BUFFER_QUEUE_TABLE:ixre-egl-board41:asic0:Ethernet40:5-6":{"profile":"egress_lossy_profile"}, +"INTF_TABLE:Loopback0":{"NULL":"NULL","mac_addr":"00:00:00:00:00:00"} +}] \ No newline at end of file diff --git a/unittest/saidump/main.cpp b/unittest/saidump/main.cpp new file mode 100755 index 000000000..73eaf410c --- /dev/null +++ b/unittest/saidump/main.cpp @@ -0,0 +1,63 @@ +#include +#include "meta/sai_serialize.h" +#include "saidump.h" +#define ARGVN 5 + +TEST(SaiDump, printUsage) +{ + SWSS_LOG_ENTER(); + testing::internal::CaptureStdout(); + syncd::SaiDump m_saiDump; + m_saiDump.printUsage(); + std::string output = testing::internal::GetCapturedStdout(); + EXPECT_EQ(true, output.find("Usage: saidump [-t] [-g] [-r] [-m] [-h]") != std::string::npos); +} + +TEST(SaiDump, handleCmdLine) +{ + SWSS_LOG_ENTER(); + const char *arr[] = {"saidump", "-r", "./dump.json", "-m", "100"}; + char **argv = new char *[ARGVN]; + + for (int i = 0; i < ARGVN; ++i) + { + argv[i] = const_cast(arr[i]); + } + + syncd::SaiDump m_saiDump; + m_saiDump.handleCmdLine(ARGVN, argv); + delete[] argv; + EXPECT_EQ(m_saiDump.rdbJsonFile, "./dump.json"); + EXPECT_EQ(m_saiDump.rdbJSonSizeLimit, RDB_JSON_MAX_SIZE); +} + + +TEST(SaiDump, dumpFromRedisRdbJson) +{ + SWSS_LOG_ENTER(); + syncd::SaiDump m_saiDump; + m_saiDump.rdbJsonFile = ""; + EXPECT_EQ(SAI_STATUS_FAILURE, m_saiDump.dumpFromRedisRdbJson()); + m_saiDump.rdbJsonFile = "./dump.json"; + EXPECT_EQ(SAI_STATUS_SUCCESS, m_saiDump.dumpFromRedisRdbJson()); +} + +TEST(SaiDump, preProcessFile) +{ + SWSS_LOG_ENTER(); + syncd::SaiDump m_saiDump; + EXPECT_EQ(SAI_STATUS_FAILURE, m_saiDump.preProcessFile("")); + m_saiDump.rdbJSonSizeLimit = 0; + EXPECT_EQ(SAI_STATUS_FAILURE, m_saiDump.preProcessFile("./dump.json")); + m_saiDump.rdbJSonSizeLimit = RDB_JSON_MAX_SIZE; + EXPECT_EQ(SAI_STATUS_SUCCESS, m_saiDump.preProcessFile("./dump.json")); + m_saiDump.rdbJsonFile = "./dump.json"; + EXPECT_EQ(SAI_STATUS_SUCCESS, m_saiDump.dumpFromRedisRdbJson()); +} + +int main(int argc, char *argv[]) +{ + SWSS_LOG_ENTER(); + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file