Skip to content

Commit 9c8a16e

Browse files
authored
Separate I2C mux state probing and gRPC forwarding state probing (#86)
What is the motivation for this PR? Current implementation used the same APP DB table for active-active port forwarding state probing and active-standby port mux state probing. This is breaking CLI tests in pre-test. How did you do it? use tables below for active-active port forwarding state probing. #define APP_FORWARDING_STATE_COMMAND_TABLE_NAME "FORWARDING_STATE_COMMAND" #define APP_FORWARDING_STATE_RESPONSE_TABLE_NAME "FORWARDING_STATE_RESPONSE" RESPONSE table expects forwarding state response for both SELF and PEER. Rename some table names & handler functions to avoid confusion. How did you verify/test it? Unit tests.
1 parent 491c4ee commit 9c8a16e

File tree

6 files changed

+200
-27
lines changed

6 files changed

+200
-27
lines changed

src/DbInterface.cpp

+115-14
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,23 @@ void DbInterface::probeMuxState(const std::string &portName)
132132
)));
133133
}
134134

135+
//
136+
// ---> probeForwardingState(const std::string &portName)
137+
//
138+
// trigger tranceiver daemon to read Fowarding state using gRPC
139+
//
140+
void DbInterface::probeForwardingState(const std::string &portName)
141+
{
142+
MUXLOGDEBUG(portName);
143+
144+
boost::asio::io_service &ioService = mStrand.context();
145+
ioService.post(mStrand.wrap(boost::bind(
146+
&DbInterface::handleProbeForwardingState,
147+
this,
148+
portName
149+
)));
150+
}
151+
135152
//
136153
// ---> setMuxLinkmgrState(const std::string &portName, link_manager::ActiveStandbyStateMachine::Label label);
137154
//
@@ -251,11 +268,14 @@ void DbInterface::initialize()
251268
mAppDbMuxTablePtr = std::make_shared<swss::ProducerStateTable> (
252269
mAppDbPtr.get(), APP_MUX_CABLE_TABLE_NAME
253270
);
271+
mAppDbPeerMuxTablePtr = std::make_shared<swss::ProducerStateTable> (
272+
mAppDbPtr.get(), APP_PEER_HW_FORWARDING_STATE_TABLE_NAME
273+
);
254274
mAppDbMuxCommandTablePtr = std::make_shared<swss::Table> (
255275
mAppDbPtr.get(), APP_MUX_CABLE_COMMAND_TABLE_NAME
256276
);
257-
mAppDbPeerMuxCommandTablePtr = std::make_shared<swss::Table> (
258-
mAppDbPtr.get(), PEER_FORWARDING_STATE_COMMAND_TABLE
277+
mAppDbForwardingCommandTablePtr = std::make_shared<swss::Table> (
278+
mAppDbPtr.get(), APP_FORWARDING_STATE_COMMAND_TABLE_NAME
259279
);
260280
mStateDbMuxLinkmgrTablePtr = std::make_shared<swss::Table> (
261281
mStateDbPtr.get(), STATE_MUX_LINKMGR_TABLE_NAME
@@ -352,7 +372,7 @@ void DbInterface::handleSetPeerMuxState(const std::string portName, mux_state::M
352372
std::vector<swss::FieldValueTuple> values = {
353373
{"state", mMuxState[label]},
354374
};
355-
mAppDbPeerMuxCommandTablePtr->set(portName, values);
375+
mAppDbPeerMuxTablePtr->set(portName, values);
356376
}
357377
}
358378

@@ -368,6 +388,18 @@ void DbInterface::handleProbeMuxState(const std::string portName)
368388
mAppDbMuxCommandTablePtr->hset(portName, "command", "probe");
369389
}
370390

391+
//
392+
// ---> handleProbeForwardingState(const std::string portName)
393+
//
394+
// trigger xcvrd to read forwarding state using gRPC
395+
//
396+
void DbInterface::handleProbeForwardingState(const std::string portName)
397+
{
398+
MUXLOGDEBUG(portName);
399+
400+
mAppDbForwardingCommandTablePtr->hset(portName, "command", "probe");
401+
}
402+
371403
//
372404
// ---> handleSetMuxLinkmgrState(const std::string portName, link_manager::ActiveStandbyStateMachine::Label label);
373405
//
@@ -988,6 +1020,56 @@ void DbInterface::processMuxResponseNotifiction(std::deque<swss::KeyOpFieldsValu
9881020
}
9891021
}
9901022

1023+
//
1024+
// ---> processForwardingResponseNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries);
1025+
//
1026+
// process forwarding response (from xcvrd probing) notification
1027+
//
1028+
void DbInterface::processForwardingResponseNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries)
1029+
{
1030+
for (auto &entry: entries) {
1031+
std::string port = kfvKey(entry);
1032+
std::string oprtation = kfvOp(entry);
1033+
std::vector<swss::FieldValueTuple> fieldValues = kfvFieldsValues(entry);
1034+
1035+
std::vector<swss::FieldValueTuple>::const_iterator cit_self = std::find_if(
1036+
fieldValues.cbegin(),
1037+
fieldValues.cend(),
1038+
[] (const swss::FieldValueTuple &fv) {return fvField(fv) == "response";}
1039+
);
1040+
if (cit_self != fieldValues.cend()) {
1041+
const std::string f = cit_self->first;
1042+
const std::string v = cit_self->second;
1043+
1044+
MUXLOGDEBUG(boost::format("port: %s, operation: %s, f: %s, v: %s") %
1045+
port %
1046+
oprtation %
1047+
f %
1048+
v
1049+
);
1050+
mMuxManagerPtr->processProbeMuxState(port, v);
1051+
}
1052+
1053+
std::vector<swss::FieldValueTuple>::const_iterator cit_peer = std::find_if(
1054+
fieldValues.cbegin(),
1055+
fieldValues.cend(),
1056+
[] (const swss::FieldValueTuple &fv) {return fvField(fv) == "response_peer";}
1057+
);
1058+
if (cit_peer != fieldValues.cend()) {
1059+
const std::string f = cit_peer->first;
1060+
const std::string v = cit_peer->second;
1061+
1062+
MUXLOGDEBUG(boost::format("port: %s, operation: %s, f: %s, v: %s") %
1063+
port %
1064+
oprtation %
1065+
f %
1066+
v
1067+
);
1068+
mMuxManagerPtr->processPeerMuxState(port, v);
1069+
}
1070+
}
1071+
}
1072+
9911073
//
9921074
// ---> handleMuxResponseNotifiction(swss::SubscriberStateTable &appdbPortTable);
9931075
//
@@ -1001,12 +1083,26 @@ void DbInterface::handleMuxResponseNotifiction(swss::SubscriberStateTable &appdb
10011083
processMuxResponseNotifiction(entries);
10021084
}
10031085

1086+
//
1087+
// ---> handleForwardingResponseNotification(swss::SubscriberStateTable &appdbForwardingResponseTable)
1088+
//
1089+
// handle fowarding response (from xcvrd) notification
1090+
//
1091+
void DbInterface::handleForwardingResponseNotification(swss::SubscriberStateTable &appdbForwardingResponseTable)
1092+
{
1093+
std::deque<swss::KeyOpFieldsValuesTuple> entries;
1094+
1095+
appdbForwardingResponseTable.pops(entries);
1096+
processForwardingResponseNotification(entries);
1097+
}
1098+
1099+
10041100
//
10051101
// ---> processPeerMuxResponseNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries);
10061102
//
1007-
// process peer MUX response (from xcvrd) notification
1103+
// process peer MUX state (from xcvrd) notification
10081104
//
1009-
void DbInterface::processPeerMuxResponseNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries)
1105+
void DbInterface::processPeerMuxNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries)
10101106
{
10111107
for (auto &entry: entries) {
10121108
std::string port = kfvKey(entry);
@@ -1034,16 +1130,16 @@ void DbInterface::processPeerMuxResponseNotification(std::deque<swss::KeyOpField
10341130
}
10351131

10361132
//
1037-
// ---> handlePeerMuxResponseNotification(swss::SubscriberStateTable &stateDbPeerMuxResponseTable);
1133+
// ---> handlePeerMuxStateNotification(swss::SubscriberStateTable &stateDbPeerMuxTable);
10381134
//
1039-
// handles peer MUX response (from xcvrd) notification
1135+
// handles peer MUX notification (from xcvrd)
10401136
//
1041-
void DbInterface::handlePeerMuxResponseNotification(swss::SubscriberStateTable &stateDbPeerMuxResponseTable)
1137+
void DbInterface::handlePeerMuxStateNotification(swss::SubscriberStateTable &stateDbPeerMuxTable)
10421138
{
10431139
std::deque<swss::KeyOpFieldsValuesTuple> entries;
10441140

1045-
stateDbPeerMuxResponseTable.pops(entries);
1046-
processPeerMuxResponseNotification(entries);
1141+
stateDbPeerMuxTable.pops(entries);
1142+
processPeerMuxNotification(entries);
10471143
}
10481144

10491145
//
@@ -1164,14 +1260,16 @@ void DbInterface::handleSwssNotification()
11641260
swss::SubscriberStateTable appDbPortTable(appDbPtr.get(), APP_PORT_TABLE_NAME);
11651261
// for command responses from the driver
11661262
swss::SubscriberStateTable appDbMuxResponseTable(appDbPtr.get(), APP_MUX_CABLE_RESPONSE_TABLE_NAME);
1263+
// for command response of forwarding state probing from driver
1264+
swss::SubscriberStateTable appDbForwardingResponseTable(appDbPtr.get(), APP_FORWARDING_STATE_RESPONSE_TABLE_NAME);
11671265
// for getting state db MUX state when orchagent updates it
11681266
swss::SubscriberStateTable stateDbPortTable(stateDbPtr.get(), STATE_MUX_CABLE_TABLE_NAME);
11691267
// for getting state db default route state
11701268
swss::SubscriberStateTable stateDbRouteTable(stateDbPtr.get(), STATE_ROUTE_TABLE_NAME);
11711269
// for getting peer's link status
11721270
swss::SubscriberStateTable stateDbMuxInfoTable(stateDbPtr.get(), MUX_CABLE_INFO_TABLE);
11731271
// for getting peer's admin forwarding state
1174-
swss::SubscriberStateTable stateDbPeerMuxResponseTable(stateDbPtr.get(), PEER_FORWARDING_STATE_RESPONSE_TABLE);
1272+
swss::SubscriberStateTable stateDbPeerMuxTable(stateDbPtr.get(), STATE_PEER_HW_FORWARDING_STATE_TABLE_NAME);
11751273

11761274
getTorMacAddress(configDbPtr);
11771275
getLoopback2InterfaceInfo(configDbPtr);
@@ -1192,10 +1290,11 @@ void DbInterface::handleSwssNotification()
11921290
swssSelect.addSelectable(&configDbMuxTable);
11931291
swssSelect.addSelectable(&appDbPortTable);
11941292
swssSelect.addSelectable(&appDbMuxResponseTable);
1293+
swssSelect.addSelectable(&appDbForwardingResponseTable);
11951294
swssSelect.addSelectable(&stateDbPortTable);
11961295
swssSelect.addSelectable(&stateDbRouteTable);
11971296
swssSelect.addSelectable(&stateDbMuxInfoTable);
1198-
swssSelect.addSelectable(&stateDbPeerMuxResponseTable);
1297+
swssSelect.addSelectable(&stateDbPeerMuxTable);
11991298
swssSelect.addSelectable(&netlinkNeighbor);
12001299

12011300
while (mPollSwssNotifcation) {
@@ -1220,14 +1319,16 @@ void DbInterface::handleSwssNotification()
12201319
handleLinkStateNotifiction(appDbPortTable);
12211320
} else if (selectable == static_cast<swss::Selectable *> (&appDbMuxResponseTable)) {
12221321
handleMuxResponseNotifiction(appDbMuxResponseTable);
1322+
} else if (selectable == static_cast<swss::Selectable *> (&appDbForwardingResponseTable)) {
1323+
handleForwardingResponseNotification(appDbForwardingResponseTable);
12231324
} else if (selectable == static_cast<swss::Selectable *> (&stateDbPortTable)) {
12241325
handleMuxStateNotifiction(stateDbPortTable);
12251326
} else if (selectable == static_cast<swss::Selectable *> (&stateDbRouteTable)) {
12261327
handleDefaultRouteStateNotification(stateDbRouteTable);
12271328
} else if (selectable == static_cast<swss::Selectable *> (&stateDbMuxInfoTable)) {
12281329
handlePeerLinkStateNotification(stateDbMuxInfoTable);
1229-
} else if (selectable == static_cast<swss::Selectable *> (&stateDbPeerMuxResponseTable)) {
1230-
handlePeerMuxResponseNotification(stateDbPeerMuxResponseTable);
1330+
} else if (selectable == static_cast<swss::Selectable *> (&stateDbPeerMuxTable)) {
1331+
handlePeerMuxStateNotification(stateDbPeerMuxTable);
12311332
} else if (selectable == static_cast<swss::Selectable *> (&netlinkNeighbor)) {
12321333
continue;
12331334
} else {

src/DbInterface.h

+58-12
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ namespace mux
4646
{
4747
#define MUX_CABLE_INFO_TABLE "MUX_CABLE_INFO"
4848
#define LINK_PROBE_STATS_TABLE_NAME "LINK_PROBE_STATS"
49-
#define PEER_FORWARDING_STATE_COMMAND_TABLE "HW_FORWARDING_STATE_PEER"
50-
#define PEER_FORWARDING_STATE_RESPONSE_TABLE "HW_MUX_CABLE_TABLE_PEER"
49+
50+
#define APP_FORWARDING_STATE_COMMAND_TABLE_NAME "FORWARDING_STATE_COMMAND"
51+
#define APP_FORWARDING_STATE_RESPONSE_TABLE_NAME "FORWARDING_STATE_RESPONSE"
52+
53+
#define APP_PEER_HW_FORWARDING_STATE_TABLE_NAME "HW_FORWARDING_STATE_PEER"
54+
#define STATE_PEER_HW_FORWARDING_STATE_TABLE_NAME "HW_MUX_CABLE_TABLE_PEER"
5155

5256
class MuxManager;
5357
using ServerIpPortMap = std::map<boost::asio::ip::address, std::string>;
@@ -158,6 +162,17 @@ class DbInterface
158162
*/
159163
virtual void probeMuxState(const std::string &portName);
160164

165+
/**
166+
* @method probeForwardingState
167+
*
168+
* @brief trigger tranceiver daemon to read Fowarding state using gRPC
169+
*
170+
* @param portName (in) MUX/port name
171+
*
172+
* @return none
173+
*/
174+
virtual void probeForwardingState(const std::string &portName);
175+
161176
/**
162177
*@method setMuxLinkmgrState
163178
*
@@ -308,6 +323,17 @@ class DbInterface
308323
*/
309324
void handleProbeMuxState(const std::string portName);
310325

326+
/**
327+
* @method handleProbeForwardingState
328+
*
329+
* @brief trigger xcvrd to read forwarding state using gRPC
330+
*
331+
* @param portName (in) MUX/port name
332+
*
333+
* @return none
334+
*/
335+
void handleProbeForwardingState(const std::string portName);
336+
311337
/**
312338
*@method handleSetMuxLinkmgrState
313339
*
@@ -582,6 +608,17 @@ class DbInterface
582608
*/
583609
inline void processMuxResponseNotifiction(std::deque<swss::KeyOpFieldsValuesTuple> &entries);
584610

611+
/**
612+
* @method processForwardingResponseNotification
613+
*
614+
* @brief process forwarding response (from xcvrd probing) notification
615+
*
616+
* @param entries (in) reference to app db entries
617+
*
618+
* @return none
619+
*/
620+
inline void processForwardingResponseNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries);
621+
585622
/**
586623
*@method handleMuxResponseNotifiction
587624
*
@@ -594,26 +631,33 @@ class DbInterface
594631
void handleMuxResponseNotifiction(swss::SubscriberStateTable &appdbPortTable);
595632

596633
/**
597-
*@method processPeerMuxResponseNotification
634+
* @method handleForwardingResponseNotification
635+
*
636+
* @brief handle forwarding state response (from xcvrd probing) notification
637+
*/
638+
void handleForwardingResponseNotification(swss::SubscriberStateTable &appdbForwardingResponseTable);
639+
640+
/**
641+
*@method processPeerMuxNotification
598642
*
599-
*@brief process peer MUX response (from xcvrd) notification
643+
*@brief process peer MUX state (from xcvrd) notification
600644
*
601-
*@param entries (in) reference to app db peer mux response table entries
645+
*@param entries (in) reference to state db peer mux table entries
602646
*
603647
*@return none
604648
*/
605-
inline void processPeerMuxResponseNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries);
649+
inline void processPeerMuxNotification(std::deque<swss::KeyOpFieldsValuesTuple> &entries);
606650

607651
/**
608-
*@method handlePeerMuxResponseNotification
652+
*@method handlePeerMuxStateNotification
609653
*
610-
*@brief handles peer MUX response (from xcvrd) notification
654+
*@brief handles peer MUX notification (from xcvrd)
611655
*
612-
*@param appdbPortTable (in) reference to app db peer mux response table
656+
*@param stateDbPeerMuxTable (in) reference to state db peer hw forwarding table
613657
*
614658
*@return none
615659
*/
616-
void handlePeerMuxResponseNotification(swss::SubscriberStateTable &stateDbPeerMuxResponseTable);
660+
void handlePeerMuxStateNotification(swss::SubscriberStateTable &stateDbPeerMuxTable);
617661

618662
/**
619663
*@method processMuxStateNotifiction
@@ -684,10 +728,12 @@ class DbInterface
684728

685729
// for communicating with orchagent
686730
std::shared_ptr<swss::ProducerStateTable> mAppDbMuxTablePtr;
731+
// for communication with driver (setting peer's forwarding state)
732+
std::shared_ptr<swss::ProducerStateTable> mAppDbPeerMuxTablePtr;
687733
// for communicating with the driver (probing the mux)
688734
std::shared_ptr<swss::Table> mAppDbMuxCommandTablePtr;
689-
// for communicating with xcvrd to set peer mux state
690-
std::shared_ptr<swss::Table> mAppDbPeerMuxCommandTablePtr;
735+
// for communication with the driver (probing forwarding state)
736+
std::shared_ptr<swss::Table> mAppDbForwardingCommandTablePtr;
691737
// for writing the current mux linkmgr health
692738
std::shared_ptr<swss::Table> mStateDbMuxLinkmgrTablePtr;
693739
// for writing mux metrics

src/MuxPort.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,23 @@ void MuxPort::resetPckLossCount()
364364
)));
365365
}
366366

367+
//
368+
// ---> probeMuxState()
369+
//
370+
// trigger xcvrd to read MUX state using i2c
371+
//
372+
void MuxPort::probeMuxState()
373+
{
374+
switch (mMuxPortConfig.getPortCableType()) {
375+
case common::MuxPortConfig::PortCableType::ActiveActive:
376+
mDbInterfacePtr->probeForwardingState(mMuxPortConfig.getPortName());
377+
break;
378+
case common::MuxPortConfig::PortCableType::ActiveStandby:
379+
mDbInterfacePtr->probeMuxState(mMuxPortConfig.getPortName());
380+
break;
381+
default:
382+
break;
383+
}
384+
}
385+
367386
} /* namespace mux */

src/MuxPort.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class MuxPort: public std::enable_shared_from_this<MuxPort>
145145
*
146146
*@return label of MUX state
147147
*/
148-
inline void probeMuxState() {mDbInterfacePtr->probeMuxState(mMuxPortConfig.getPortName());};
148+
void probeMuxState();
149149

150150
/**
151151
*@method setMuxLinkmgrState

test/FakeDbInterface.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ void FakeDbInterface::probeMuxState(const std::string &portName)
6060
mProbeMuxStateInvokeCount++;
6161
}
6262

63+
void FakeDbInterface::probeForwardingState(const std::string &portName)
64+
{
65+
mProbeForwardingStateInvokeCount++;
66+
}
67+
6368
void FakeDbInterface::setMuxLinkmgrState(const std::string &portName, link_manager::ActiveStandbyStateMachine::Label label)
6469
{
6570
mSetMuxLinkmgrStateInvokeCount++;

0 commit comments

Comments
 (0)