Skip to content

Commit

Permalink
Merge branch 'master' into dev-ntp-configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
fastiuk authored Oct 4, 2023
2 parents 808b08b + b0f148e commit 97143f5
Show file tree
Hide file tree
Showing 14 changed files with 255 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ lib_LTLIBRARIES =
bin_PROGRAMS =

if DEBUG
DBGFLAGS = -ggdb -DDEBUG
DBGFLAGS = -ggdb -DDEBUG -gdwarf-5
else
DBGFLAGS = -g -DNDEBUG
endif
Expand Down
2 changes: 2 additions & 0 deletions common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ common_libswsscommon_la_SOURCES = \
common_libswsscommon_la_CXXFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(LIBNL_CFLAGS) $(CODE_COVERAGE_CXXFLAGS)
common_libswsscommon_la_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(LIBNL_CPPFLAGS) $(CODE_COVERAGE_CPPFLAGS)
common_libswsscommon_la_LIBADD = -lpthread $(LIBNL_LIBS) $(CODE_COVERAGE_LIBS) -lzmq -lboost_serialization -luuid -lyang
common_libswsscommon_la_LDFLAGS = -Wl,-z,now $(LDFLAGS)

common_swssloglevel_SOURCES = \
common/loglevel.cpp \
Expand All @@ -84,3 +85,4 @@ common_swssloglevel_SOURCES = \
common_swssloglevel_CXXFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CODE_COVERAGE_CXXFLAGS)
common_swssloglevel_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CODE_COVERAGE_CPPFLAGS)
common_swssloglevel_LDADD = common/libswsscommon.la $(CODE_COVERAGE_LIBS)
common_swssloglevel_LDFLAGS = -Wl,-z,now $(LDFLAGS)
4 changes: 1 addition & 3 deletions common/events_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,7 @@ struct serialization
int
deserialize(const string& s, Map& data)
{
if (s.size() < 2) { // zmq identifying message of length 1
return 0;
}

try {
istringstream ss(s);
boost::archive::text_iarchive iarch(ss);
Expand Down
5 changes: 5 additions & 0 deletions common/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,11 @@ namespace swss {
#define CFG_DTEL_QUEUE_REPORT_TABLE_NAME "DTEL_QUEUE_REPORT"
#define CFG_DTEL_EVENT_TABLE_NAME "DTEL_EVENT"

#define CFG_FABRIC_MONITOR_DATA_TABLE_NAME "FABRIC_MONITOR"
#define CFG_FABRIC_MONITOR_PORT_TABLE_NAME "FABRIC_PORT"
#define APP_FABRIC_MONITOR_DATA_TABLE_NAME "FABRIC_MONITOR_TABLE"
#define APP_FABRIC_MONITOR_PORT_TABLE_NAME "FABRIC_PORT_TABLE"

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ CFLAGS_COMMON+=" -Wvariadic-macros"
CFLAGS_COMMON+=" -Wno-write-strings"
CFLAGS_COMMON+=" -Wno-missing-format-attribute"
CFLAGS_COMMON+=" -Wno-long-long"
CFLAGS_COMMON+=" -fstack-protector-strong"

AC_SUBST(CFLAGS_COMMON)

Expand Down
4 changes: 2 additions & 2 deletions pyext/py2/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ pkgpython_PYTHON = pyext/py2/swsscommon.py pyext/py2/__init__.py
pkgpyexec_LTLIBRARIES = pyext/py2/_swsscommon.la

pyext_py2__swsscommon_la_SOURCES = pyext/py2/swsscommon_wrap.cpp
pyext_py2__swsscommon_la_CPPFLAGS = -std=c++11 -Icommon -I/usr/include/python$(PYTHON_VERSION)
pyext_py2__swsscommon_la_LDFLAGS = -module
pyext_py2__swsscommon_la_CPPFLAGS = -std=c++11 -Icommon -I/usr/include/python$(PYTHON_VERSION) -fstack-protector-strong
pyext_py2__swsscommon_la_LDFLAGS = -module -Wl,-z,now
pyext_py2__swsscommon_la_LIBADD = common/libswsscommon.la -lpython$(PYTHON_VERSION)

pyext/py2/swsscommon_wrap.cpp: $(SWIG_SOURCES)
Expand Down
4 changes: 2 additions & 2 deletions pyext/py3/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ pkgpython3_PYTHON = pyext/py3/swsscommon.py pyext/py3/__init__.py
pkgpy3exec_LTLIBRARIES = pyext/py3/_swsscommon.la

pyext_py3__swsscommon_la_SOURCES = pyext/py3/swsscommon_wrap.cpp
pyext_py3__swsscommon_la_CPPFLAGS = -std=c++11 -Icommon -I/usr/include/python$(PYTHON3_VERSION)
pyext_py3__swsscommon_la_LDFLAGS = -module
pyext_py3__swsscommon_la_CPPFLAGS = -std=c++11 -Icommon -I/usr/include/python$(PYTHON3_VERSION) -fstack-protector-strong
pyext_py3__swsscommon_la_LDFLAGS = -module -Wl,-z,now
pyext_py3__swsscommon_la_LIBADD = common/libswsscommon.la $(PYTHON3_BLDLIBRARY)

pyext/py3/swsscommon_wrap.cpp: $(SWIG_SOURCES)
Expand Down
2 changes: 2 additions & 0 deletions sonic-db-cli/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ sonic_db_cli_libsonicdbcli_la_SOURCES = sonic-db-cli/sonic-db-cli.cpp
sonic_db_cli_libsonicdbcli_la_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON)
sonic_db_cli_libsonicdbcli_la_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON)
sonic_db_cli_libsonicdbcli_la_LIBADD = common/libswsscommon.la -lpthread
sonic_db_cli_libsonicdbcli_la_LDFLAGS = -Wl,-z,now $(LDFLAGS)

bin_PROGRAMS += sonic-db-cli/sonic-db-cli
sonic_db_cli_sonic_db_cli_SOURCES = sonic-db-cli/sonic-db-cli.cpp sonic-db-cli/main.cpp
sonic_db_cli_sonic_db_cli_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON)
sonic_db_cli_sonic_db_cli_CPPFLAGS = $(DBGFLAGS) $(AM_CPPFLAGS) $(CFLAGS_COMMON)
sonic_db_cli_sonic_db_cli_LDADD = common/libswsscommon.la -lpthread
sonic_db_cli_sonic_db_cli_LDFLAGS = -Wl,-z,now $(LDFLAGS)
41 changes: 19 additions & 22 deletions sonic-db-cli/sonic-db-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ string handleSingleOperation(
const string& netns,
const string& db_name,
const string& operation,
bool isTcpConn)
bool useUnixSocket)
{
shared_ptr<DBConnector> client;
auto host = SonicDBConfig::getDbHostname(db_name, netns);
string message = "Could not connect to Redis at " + host + ":";
try
{
auto db_id = SonicDBConfig::getDbId(db_name, netns);
if (!isTcpConn && db_name != "redis_chassis.server")
if (useUnixSocket && db_name != "redis_chassis.server")
{
auto db_socket = SonicDBConfig::getDbSock(db_name);
auto db_socket = SonicDBConfig::getDbSock(db_name, netns);
message += db_name + ": Connection refused";
client = make_shared<DBConnector>(db_id, db_socket, 0);
}
Expand Down Expand Up @@ -89,15 +89,15 @@ string handleSingleOperation(
int handleAllInstances(
const string& netns,
const string& operation,
bool isTcpConn)
bool useUnixSocket)
{
auto db_names = SonicDBConfig::getDbList(netns);
// Operate All Redis Instances in Parallel
// TODO: if one of the operations failed, it could fail quickly and not necessary to wait all other operations
list<future<string>> responses;
for (auto& db_name : db_names)
{
future<string> response = std::async(std::launch::async, handleSingleOperation, netns, db_name, operation, isTcpConn);
future<string> response = std::async(std::launch::async, handleSingleOperation, netns, db_name, operation, useUnixSocket);
responses.push_back(std::move(response));
}

Expand Down Expand Up @@ -133,22 +133,22 @@ int executeCommands(
const string& db_name,
vector<string>& commands,
const string& netns,
bool isTcpConn)
bool useUnixSocket)
{
shared_ptr<DBConnector> client = nullptr;
try
{
int db_id = SonicDBConfig::getDbId(db_name, netns);
if (isTcpConn)
if (useUnixSocket)
{
auto host = SonicDBConfig::getDbHostname(db_name, netns);
auto port = SonicDBConfig::getDbPort(db_name, netns);
client = make_shared<DBConnector>(db_id, host, port, 0);
auto db_socket = SonicDBConfig::getDbSock(db_name, netns);
client = make_shared<DBConnector>(db_id, db_socket, 0);
}
else
{
auto db_socket = SonicDBConfig::getDbSock(db_name);
client = make_shared<DBConnector>(db_id, db_socket, 0);
auto host = SonicDBConfig::getDbHostname(db_name, netns);
auto port = SonicDBConfig::getDbPort(db_name, netns);
client = make_shared<DBConnector>(db_id, host, port, 0);
}
}
catch (const exception& e)
Expand Down Expand Up @@ -279,19 +279,16 @@ int sonic_db_cli(
{
auto dbOrOperation = options.m_db_or_op;
auto netns = options.m_namespace;
bool isTcpConn = !options.m_unixsocket;
bool useUnixSocket = options.m_unixsocket;
// Load the database config for the namespace
if (!netns.empty())
{
initializeGlobalConfig();

// Use the unix domain connectivity if namespace not empty.
useUnixSocket = true;
}
else
{
// Use the tcp connectivity if namespace is local and unixsocket cmd_option is present.
isTcpConn = true;
netns = "";
}


if (options.m_cmd.size() != 0)
{
auto commands = options.m_cmd;
Expand All @@ -301,7 +298,7 @@ int sonic_db_cli(
initializeConfig();
}

return executeCommands(dbOrOperation, commands, netns, isTcpConn);
return executeCommands(dbOrOperation, commands, netns, useUnixSocket);
}
else if (dbOrOperation == "PING"
|| dbOrOperation == "SAVE"
Expand All @@ -317,7 +314,7 @@ int sonic_db_cli(
initializeConfig();
}

return handleAllInstances(netns, dbOrOperation, isTcpConn);
return handleAllInstances(netns, dbOrOperation, useUnixSocket);
}
catch (const exception& e)
{
Expand Down
32 changes: 16 additions & 16 deletions tests/cli_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ TEST(sonic_db_cli, test_cli_multi_ns_cmd)
char *args[7];
args[0] = "sonic-db-cli";
args[1] = "-n";
args[2] = "asic0";
args[2] = "asic2";
args[3] = "TEST_DB";

// set key to test DB
Expand Down Expand Up @@ -409,7 +409,7 @@ TEST(sonic_db_cli, test_cli_unix_socket_cmd)
args[0] = "sonic-db-cli";
args[1] = "-s";
args[2] = "-n";
args[3] = "asic0";
args[3] = "asic2";
args[4] = "TEST_DB";

// set key to test DB
Expand All @@ -431,7 +431,7 @@ TEST(sonic_db_cli, test_cli_eval_cmd)
char *args[11];
args[0] = "sonic-db-cli";
args[1] = "-n";
args[2] = "asic0";
args[2] = "asic2";
args[3] = "TEST_DB";

// run eval command: EVAL "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" 2 k1 k2 v1 v2
Expand All @@ -450,33 +450,33 @@ TEST(sonic_db_cli, test_parallel_cmd) {
char *args[7];
args[0] = "sonic-db-cli";
args[1] = "-n";
args[2] = "asic0";
args[2] = "asic2";
args[4] = "SAVE";

auto db_names = swss::SonicDBConfig::getDbList("asic0");
auto db_names = swss::SonicDBConfig::getDbList("asic2");
for (auto& db_name : db_names)
{
generateTestData("asic0", const_cast<char*>(db_name.c_str()));
generateTestData("asic2", const_cast<char*>(db_name.c_str()));
}
db_names = swss::SonicDBConfig::getDbList("asic1");
db_names = swss::SonicDBConfig::getDbList("asic3");
for (auto& db_name : db_names)
{
generateTestData("asic1", const_cast<char*>(db_name.c_str()));
generateTestData("asic3", const_cast<char*>(db_name.c_str()));
}

// save 2 DBs and get save DB performance
auto begin_time = clock();
db_names = swss::SonicDBConfig::getDbList("asic0");
args[2] = "asic0";
db_names = swss::SonicDBConfig::getDbList("asic2");
args[2] = "asic2";
for (auto& db_name : db_names)
{
args[3] = const_cast<char*>(db_name.c_str());
optind = 0;
sonic_db_cli(5, args);
}

db_names = swss::SonicDBConfig::getDbList("asic1");
args[2] = "asic1";
db_names = swss::SonicDBConfig::getDbList("asic3");
args[2] = "asic3";
for (auto& db_name : db_names)
{
args[3] = const_cast<char*>(db_name.c_str());
Expand All @@ -487,15 +487,15 @@ TEST(sonic_db_cli, test_parallel_cmd) {
auto sequential_time = float( clock () - begin_time );

// prepare data
db_names = swss::SonicDBConfig::getDbList("asic0");
db_names = swss::SonicDBConfig::getDbList("asic2");
for (auto& db_name : db_names)
{
generateTestData("asic0", const_cast<char*>(db_name.c_str()));
generateTestData("asic2", const_cast<char*>(db_name.c_str()));
}
db_names = swss::SonicDBConfig::getDbList("asic1");
db_names = swss::SonicDBConfig::getDbList("asic3");
for (auto& db_name : db_names)
{
generateTestData("asic0", const_cast<char*>(db_name.c_str()));
generateTestData("asic3", const_cast<char*>(db_name.c_str()));
}

// save 2 DBs in parallel, and get save DB performance
Expand Down
7 changes: 2 additions & 5 deletions tests/events_common_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,17 @@ TEST(events_common, send_recv)
void *sock_p1 = zmq_socket (zmq_ctx, ZMQ_PAIR);
EXPECT_EQ(0, zmq_bind (sock_p1, path));

string source("Hello"), source1, source2("#");
string source("Hello"), source1;

map<string, string> m = {{"foo", "bar"}, {"hello", "world"}, {"good", "day"}};
map<string, string> m1, m2;
map<string, string> m1;

EXPECT_EQ(0, zmq_message_send(sock_p0, source, m));

EXPECT_EQ(0, zmq_message_read(sock_p1, 0, source1, m1));

EXPECT_EQ(source, source1);
EXPECT_EQ(m, m1);

EXPECT_EQ(0, deserialize(source2, m2));

zmq_close(sock_p0);
zmq_close(sock_p1);
zmq_ctx_term(zmq_ctx);
Expand Down
Loading

0 comments on commit 97143f5

Please sign in to comment.