Skip to content

Commit fa8f09f

Browse files
authored
Merge branch 'master' into dev-reset-local-users-password
2 parents 0541aed + 898aa5d commit fa8f09f

File tree

8 files changed

+94
-12
lines changed

8 files changed

+94
-12
lines changed

.azure-pipelines/test-docker-sonic-vs-template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
7777
# run pytests in sets of 20
7878
all_tests=$(ls test_*.py)
79-
all_tests="${all_tests} p4rt"
79+
all_tests="${all_tests} p4rt dash"
8080
test_set=()
8181
for test in ${all_tests}; do
8282
test_set+=("${test}")

common/events_common.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,23 @@ struct serialization
310310
more = 0;
311311
zmq_msg_init(&msg);
312312
int rc = zmq_msg_recv(&msg, sock, flag);
313-
if (rc != -1) {
313+
if (rc == 1) {
314+
char control_character = *(char*)zmq_msg_data(&msg);
315+
if (control_character == 0x01 || control_character == 0x00) {
316+
SWSS_LOG_INFO("Received subscription/unsubscription message when XSUB connect to XPUB: %c", control_character);
317+
} else {
318+
SWSS_LOG_DEBUG("Received non subscription based control character: %c", control_character);
319+
}
320+
rc = 0;
321+
} else if (rc != -1) {
314322
size_t more_size = sizeof (more);
315323

316324
zmq_getsockopt (sock, ZMQ_RCVMORE, &more, &more_size);
317325

318326
rc = zmsg_to_map(msg, data);
319327
RET_ON_ERR(rc == 0, "Failed to deserialize part rc=%d", rc);
320328
/* read more flag if message read fails to de-serialize */
321-
}
322-
else {
329+
} else {
323330
/* override with zmq err */
324331
rc = zmq_errno();
325332
if (rc != 11) {
@@ -332,7 +339,7 @@ struct serialization
332339
return rc;
333340
}
334341

335-
342+
336343
template<typename DT>
337344
int
338345
zmq_send_part(void *sock, int flag, const DT &data)

common/schema.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ namespace swss {
2323
#define CHASSIS_APP_DB 12
2424
#define CHASSIS_STATE_DB 13
2525
#define APPL_STATE_DB 14
26+
#define DPU_APPL_DB 15
27+
#define DPU_APPL_STATE_DB 16
28+
#define DPU_STATE_DB 17
29+
#define DPU_COUNTERS_DB 18
2630
#define EVENT_DB 19
2731
#define BMP_STATE_DB 20
2832

@@ -213,6 +217,7 @@ namespace swss {
213217
#define COUNTERS_DEBUG_NAME_SWITCH_STAT_MAP "COUNTERS_DEBUG_NAME_SWITCH_STAT_MAP"
214218
#define COUNTERS_TUNNEL_TYPE_MAP "COUNTERS_TUNNEL_TYPE_MAP"
215219
#define COUNTERS_TUNNEL_NAME_MAP "COUNTERS_TUNNEL_NAME_MAP"
220+
#define COUNTERS_ENI_NAME_MAP "COUNTERS_ENI_NAME_MAP"
216221
#define COUNTERS_ROUTE_NAME_MAP "COUNTERS_ROUTE_NAME_MAP"
217222
#define COUNTERS_ROUTE_TO_PATTERN_MAP "COUNTERS_ROUTE_TO_PATTERN_MAP"
218223
#define COUNTERS_FABRIC_QUEUE_NAME_MAP "COUNTERS_FABRIC_QUEUE_NAME_MAP"
@@ -250,6 +255,7 @@ namespace swss {
250255
#define QUEUE_COUNTER_ID_LIST "QUEUE_COUNTER_ID_LIST"
251256
#define QUEUE_ATTR_ID_LIST "QUEUE_ATTR_ID_LIST"
252257
#define BUFFER_POOL_COUNTER_ID_LIST "BUFFER_POOL_COUNTER_ID_LIST"
258+
#define ENI_COUNTER_ID_LIST "ENI_COUNTER_ID_LIST"
253259
#define PFC_WD_STATE_TABLE "PFC_WD_STATE_TABLE"
254260
#define PFC_WD_PORT_COUNTER_ID_LIST "PORT_COUNTER_ID_LIST"
255261
#define PFC_WD_QUEUE_COUNTER_ID_LIST "QUEUE_COUNTER_ID_LIST"

common/zmqclient.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ using namespace std;
1616
namespace swss {
1717

1818
ZmqClient::ZmqClient(const std::string& endpoint)
19+
:ZmqClient(endpoint, "")
1920
{
20-
initialize(endpoint);
21+
}
22+
23+
ZmqClient::ZmqClient(const std::string& endpoint, const std::string& vrf)
24+
{
25+
initialize(endpoint, vrf);
2126
}
2227

2328
ZmqClient::~ZmqClient()
@@ -39,12 +44,13 @@ ZmqClient::~ZmqClient()
3944
}
4045
}
4146

42-
void ZmqClient::initialize(const std::string& endpoint)
47+
void ZmqClient::initialize(const std::string& endpoint, const std::string& vrf)
4348
{
4449
m_connected = false;
4550
m_endpoint = endpoint;
4651
m_context = nullptr;
4752
m_socket = nullptr;
53+
m_vrf = vrf;
4854

4955
connect();
5056
}
@@ -89,6 +95,11 @@ void ZmqClient::connect()
8995
int high_watermark = MQ_WATERMARK;
9096
zmq_setsockopt(m_socket, ZMQ_SNDHWM, &high_watermark, sizeof(high_watermark));
9197

98+
if (!m_vrf.empty())
99+
{
100+
zmq_setsockopt(m_socket, ZMQ_BINDTODEVICE, m_vrf.c_str(), m_vrf.length());
101+
}
102+
92103
SWSS_LOG_NOTICE("connect to zmq endpoint: %s", m_endpoint.c_str());
93104
int rc = zmq_connect(m_socket, m_endpoint.c_str());
94105
if (rc != 0)

common/zmqclient.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class ZmqClient
1313
{
1414
public:
1515
ZmqClient(const std::string& endpoint);
16+
ZmqClient(const std::string& endpoint, const std::string& vrf);
1617
~ZmqClient();
1718

1819
bool isConnected();
@@ -24,11 +25,12 @@ class ZmqClient
2425
const std::vector<KeyOpFieldsValuesTuple>& kcos,
2526
std::vector<char>& sendbuffer);
2627
private:
27-
void initialize(const std::string& endpoint);
28-
28+
void initialize(const std::string& endpoint, const std::string& vrf);
2929

3030
std::string m_endpoint;
3131

32+
std::string m_vrf;
33+
3234
void* m_context;
3335

3436
void* m_socket;

common/zmqserver.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ using namespace std;
1212
namespace swss {
1313

1414
ZmqServer::ZmqServer(const std::string& endpoint)
15-
: m_endpoint(endpoint)
15+
: ZmqServer(endpoint, "")
16+
{
17+
}
18+
19+
ZmqServer::ZmqServer(const std::string& endpoint, const std::string& vrf)
20+
: m_endpoint(endpoint),
21+
m_vrf(vrf)
1622
{
1723
m_buffer.resize(MQ_RESPONSE_MAX_COUNT);
1824
m_runThread = true;
@@ -92,6 +98,11 @@ void ZmqServer::mqPollThread()
9298
int high_watermark = MQ_WATERMARK;
9399
zmq_setsockopt(socket, ZMQ_RCVHWM, &high_watermark, sizeof(high_watermark));
94100

101+
if (!m_vrf.empty())
102+
{
103+
zmq_setsockopt(socket, ZMQ_BINDTODEVICE, m_vrf.c_str(), m_vrf.length());
104+
}
105+
95106
int rc = zmq_bind(socket, m_endpoint.c_str());
96107
if (rc != 0)
97108
{

common/zmqserver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class ZmqServer
3131
static constexpr int DEFAULT_POP_BATCH_SIZE = 128;
3232

3333
ZmqServer(const std::string& endpoint);
34+
ZmqServer(const std::string& endpoint, const std::string& vrf);
3435
~ZmqServer();
3536

3637
void registerMessageHandler(
@@ -53,6 +54,8 @@ class ZmqServer
5354

5455
std::string m_endpoint;
5556

57+
std::string m_vrf;
58+
5659
std::map<std::string, std::map<std::string, ZmqMessageHandler*>> m_HandlerMap;
5760
};
5861

tests/events_common_ut.cpp

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,51 @@ TEST(events_common, send_recv)
9797
zmq_ctx_term(zmq_ctx);
9898
}
9999

100+
TEST(events_common, send_recv_control_character)
101+
{
102+
#if 0
103+
{
104+
/* Direct log messages to stdout */
105+
string dummy, op("STDOUT");
106+
swss::Logger::swssOutputNotify(dummy, op);
107+
swss::Logger::setMinPrio(swss::Logger::SWSS_DEBUG);
108+
}
109+
#endif
100110

111+
char *path = "tcp://127.0.0.1:5570";
112+
void *zmq_ctx = zmq_ctx_new();
113+
void *sock_p0 = zmq_socket (zmq_ctx, ZMQ_PAIR);
114+
EXPECT_EQ(0, zmq_connect (sock_p0, path));
101115

116+
void *sock_p1 = zmq_socket (zmq_ctx, ZMQ_PAIR);
117+
EXPECT_EQ(0, zmq_bind (sock_p1, path));
102118

119+
string source;
120+
map<string, string> m;
121+
122+
// Subscription based control character test
123+
zmq_msg_t sub_msg;
124+
zmq_msg_init_size(&sub_msg, 1);
125+
*(char*)zmq_msg_data(&sub_msg) = 0x01;
126+
EXPECT_EQ(1, zmq_msg_send(&sub_msg, sock_p0, 0));
127+
zmq_msg_close(&sub_msg);
128+
// First part will be read only and will return as 0, but will not be deserialized event
129+
EXPECT_EQ(0, zmq_message_read(sock_p1, 0, source, m));
130+
EXPECT_EQ("", source);
131+
EXPECT_EQ(0, m.size());
132+
133+
// Non-subscription based control character test
134+
zmq_msg_t ctrl_msg;
135+
zmq_msg_init_size(&ctrl_msg, 1);
136+
*(char*)zmq_msg_data(&ctrl_msg) = 0x07;
137+
EXPECT_EQ(1, zmq_msg_send(&ctrl_msg, sock_p0, 0));
138+
zmq_msg_close(&ctrl_msg);
139+
// First part will be read only and will return as 0, but will not be deserialized event
140+
EXPECT_EQ(0, zmq_message_read(sock_p1, 0, source, m));
141+
EXPECT_EQ("", source);
142+
EXPECT_EQ(0, m.size());
103143

104-
105-
144+
zmq_close(sock_p0);
145+
zmq_close(sock_p1);
146+
zmq_ctx_term(zmq_ctx);
147+
}

0 commit comments

Comments
 (0)