Skip to content

Commit a836ef7

Browse files
zjswhhhyxieca
authored andcommitted
Use Vlan MAC as src MAC for link prober by default (#93)
What is the motivation for this PR? In active-standby, scenario ICMP request is replied by server host and duplicated by smart cable. In active-active scenario, ICMP is replied by FPGA, and it will simply reverse src MAC and dest MAC. If we continue to use device MAC address as src MAC in active-active scenarios, heartbeats won't be duplicated to both sides. How did you do it? Get Vlan MAC address when initializing, and use it for link prober by default. Add handlers to support switching between using Vlan MAC and ToR MAC. To use ToR MAC, set src_mac field in MUX_LINKMGR|LINK_PROBER table in CONFIG DB to value ToRMac. How did you verify/test it? Tested on dualToR testbeds, captured the ICMP requests and replies: Able to see src MAC as Vlan MAC by default Able to see src MAC switch to Device MAC after updating CONFIG DB entry Able to see replies flood back to both sides. sign-off: Jing Zhang [email protected]
1 parent a828e86 commit a836ef7

16 files changed

+374
-3
lines changed

src/DbInterface.cpp

+66
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,69 @@ void DbInterface::getTorMacAddress(std::shared_ptr<swss::DBConnector> configDbCo
541541
}
542542
}
543543

544+
//
545+
// ---> getVlanNames(std::shared_ptr<swss::DBConnector> configDbConnector);
546+
//
547+
// get vlan names
548+
//
549+
void DbInterface::getVlanNames(std::shared_ptr<swss::DBConnector> configDbConnector)
550+
{
551+
MUXLOGINFO("Reading Vlan MAC Address");
552+
swss::Table configDbVlanTable(configDbConnector.get(), CFG_VLAN_TABLE_NAME);
553+
std::vector<std::string> vlanNames;
554+
555+
configDbVlanTable.getKeys(vlanNames);
556+
getVlanMacAddress(vlanNames);
557+
}
558+
559+
//
560+
// ---> getVlanMacAddress(std::vector<std::string> &vlanNames);
561+
//
562+
// retrieve Vlan MAC address informtaion
563+
//
564+
void DbInterface::getVlanMacAddress(std::vector<std::string> &vlanNames)
565+
{
566+
MUXLOGINFO("Reading Vlan MAC Address");
567+
568+
if (vlanNames.size() > 0) {
569+
std::shared_ptr<swss::DBConnector> configDbPtr = std::make_shared<swss::DBConnector> ("CONFIG_DB", 0);
570+
swss::Table configDbVlanTable(configDbPtr.get(), CFG_VLAN_TABLE_NAME);
571+
const std::string vlanName = vlanNames[0];
572+
const std::string field = "mac";
573+
std::string mac;
574+
575+
if (configDbVlanTable.hget(vlanName, field, mac)) {
576+
processVlanMacAddress(mac);
577+
} else {
578+
MUXLOGWARNING(boost::format("MAC address is not found for %s, fall back to use device MAC for link prober.") % vlanName);
579+
mMuxManagerPtr->setIfUseTorMacAsSrcMac(true);
580+
}
581+
} else {
582+
MUXLOGWARNING("VLAN table is not found in CONFIG DB, fall back to use device MAC for link prober.");
583+
mMuxManagerPtr->setIfUseTorMacAsSrcMac(true);
584+
}
585+
}
586+
587+
//
588+
// ---> processVlanMacAddress(std::string& mac);
589+
//
590+
// process Vlan Mac Address
591+
//
592+
void DbInterface::processVlanMacAddress(std::string& mac)
593+
{
594+
try {
595+
swss::MacAddress swssMacAddress(mac);
596+
std::array<uint8_t, ETHER_ADDR_LEN> macAddress;
597+
598+
memcpy(macAddress.data(), swssMacAddress.getMac(), macAddress.size());
599+
mMuxManagerPtr->setVlanMacAddress(macAddress);
600+
}
601+
catch (const std::invalid_argument &invalidArgument) {
602+
MUXLOGWARNING("Invalid Vlan MAC address " + mac);
603+
mMuxManagerPtr->setIfUseTorMacAsSrcMac(true);
604+
}
605+
}
606+
544607
//
545608
// ---> processLoopback2InterfaceInfo(std::vector<std::string> &loopbackIntfs)
546609
//
@@ -848,6 +911,8 @@ void DbInterface::processMuxLinkmgrConfigNotifiction(std::deque<swss::KeyOpField
848911
mMuxManagerPtr->setSuspendTimeout_msec(boost::lexical_cast<uint32_t> (v));
849912
} else if (f == "use_well_known_mac") {
850913
mMuxManagerPtr->setUseWellKnownMacActiveActive(v == "enable");
914+
} else if (f == "src_mac") {
915+
mMuxManagerPtr->processSrcMac(v == "ToRMac");
851916
}
852917

853918
MUXLOGINFO(boost::format("key: %s, Operation: %s, f: %s, v: %s") %
@@ -1272,6 +1337,7 @@ void DbInterface::handleSwssNotification()
12721337
swss::SubscriberStateTable stateDbPeerMuxTable(stateDbPtr.get(), STATE_PEER_HW_FORWARDING_STATE_TABLE_NAME);
12731338

12741339
getTorMacAddress(configDbPtr);
1340+
getVlanNames(configDbPtr);
12751341
getLoopback2InterfaceInfo(configDbPtr);
12761342
getPortCableType(configDbPtr);
12771343
getServerIpAddress(configDbPtr);

src/DbInterface.h

+31
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,37 @@ class DbInterface
421421
*/
422422
void getTorMacAddress(std::shared_ptr<swss::DBConnector> configDbConnector);
423423

424+
/**
425+
* @method getVlanNames
426+
*
427+
* @brief get vlan names
428+
*
429+
* @param configDbConnector config db connector
430+
*
431+
* @return none
432+
*/
433+
void getVlanNames(std::shared_ptr<swss::DBConnector> configDbConnector);
434+
435+
/**
436+
* @method getVlanMacAddress
437+
*
438+
* @brief retrieve Vlan MAC address information
439+
*
440+
* @param vlanNames (in) vlan names
441+
*
442+
* @return none
443+
*/
444+
void getVlanMacAddress(std::vector<std::string> &vlanNames);
445+
446+
/**
447+
* @method processVlanMacAddress
448+
*
449+
* @brief process Vlan Mac Address
450+
*
451+
* @return none
452+
*/
453+
void processVlanMacAddress(std::string& mac);
454+
424455
/**
425456
*@method processLoopback2InterfaceInfo
426457
*

src/MuxManager.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,25 @@ void MuxManager::processGetServerMacAddress(
302302
}
303303
}
304304

305+
//
306+
// ---> processSrcMac(bool useTorMac);
307+
//
308+
// processs src mac config
309+
//
310+
void MuxManager::processSrcMac(bool useTorMac)
311+
{
312+
if (mMuxConfig.getIfEnableUseTorMac() != useTorMac) {
313+
setIfUseTorMacAsSrcMac(useTorMac);
314+
315+
PortMapIterator portMapIterator = mPortMap.begin();
316+
while (portMapIterator != mPortMap.end()) {
317+
portMapIterator->second->handleSrcMacAddressUpdate();
318+
portMapIterator ++;
319+
}
320+
}
321+
}
322+
323+
305324
//
306325
// ---> processGetMuxState(const std::string &portName, const std::string &muxState);
307326
//

src/MuxManager.h

+33
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,39 @@ class MuxManager
170170
*/
171171
inline void setTorMacAddress(std::array<uint8_t, ETHER_ADDR_LEN> &address) {mMuxConfig.setTorMacAddress(address);};
172172

173+
/**
174+
* @method setVlanMacAddress
175+
*
176+
* @brief setter for Vlan Mac Address
177+
*
178+
* @param address (in) Vlan mac address
179+
*
180+
* @return none
181+
*/
182+
inline void setVlanMacAddress(std::array<uint8_t, ETHER_ADDR_LEN> &address) {mMuxConfig.setVlanMacAddress(address);};
183+
184+
/**
185+
* @method setIfUseTorMacAsSrcMac
186+
*
187+
* @brief setter for flag whether use ToR MAC address as link prober src MAC
188+
*
189+
* @param useTorMac (in) bool
190+
*
191+
* @return none
192+
*/
193+
void setIfUseTorMacAsSrcMac(bool useTorMac) {mMuxConfig.setIfUseTorMacAsSrcMac(useTorMac);};
194+
195+
/**
196+
* @method processSrcMac
197+
*
198+
* @brief processs src mac config
199+
*
200+
* @param enable (in) bool
201+
*
202+
* @return none
203+
*/
204+
void processSrcMac(bool useTorMac);
205+
173206
/**
174207
*@method setSuspendTimeout_msec
175208
*

src/MuxPort.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,22 @@ void MuxPort::handleUseWellKnownMacAddress()
198198
)));
199199
}
200200

201+
//
202+
// ---> handleSrcMacAddressUpdate();
203+
//
204+
// handles src mac address config update
205+
//
206+
void MuxPort::handleSrcMacAddressUpdate()
207+
{
208+
MUXLOGDEBUG(mMuxPortConfig.getPortName());
209+
210+
boost::asio::io_service &ioService = mStrand.context();
211+
ioService.post(mStrand.wrap(boost::bind(
212+
&link_manager::LinkManagerStateMachineBase::handleSrcMacConfigNotification,
213+
mLinkManagerStateMachinePtr.get()
214+
)));
215+
}
216+
201217
//
202218
// ---> handleGetMuxState(const std::string &muxState);
203219
//

src/MuxPort.h

+9
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ class MuxPort: public std::enable_shared_from_this<MuxPort>
301301
*/
302302
void handleUseWellKnownMacAddress();
303303

304+
/**
305+
* @method handleSrcMacAddressUpdate
306+
*
307+
* @brief handles src mac address config update
308+
*
309+
* @return none
310+
*/
311+
void handleSrcMacAddressUpdate();
312+
304313
/**
305314
*@method handleGetMuxState
306315
*

src/common/MuxConfig.h

+43
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,28 @@ class MuxConfig
166166
*/
167167
inline void setTorMacAddress(const std::array<uint8_t, ETHER_ADDR_LEN> &address) {mTorMacAddress = address;};
168168

169+
/**
170+
* @method setVlanMacAddress
171+
*
172+
* @brief setter for Vlan MAC address
173+
*
174+
* @param address (in) Vlan MAC address
175+
*
176+
* @return none
177+
*/
178+
inline void setVlanMacAddress(const std::array<uint8_t, ETHER_ADDR_LEN> &address) {mVlanMacAddress = address;};
179+
180+
/**
181+
* @method setIfUseTorMacAsSrcMac
182+
*
183+
* @brief setter for flag whether use ToR MAC address as link prober src MAC
184+
*
185+
* @param enable (in) bool
186+
*
187+
* @return none
188+
*/
189+
inline void setIfUseTorMacAsSrcMac(bool enable) {mEnableUseTorMac = enable;};
190+
169191
/**
170192
*@method setLoopbackIpv4Address
171193
*
@@ -258,6 +280,15 @@ class MuxConfig
258280
*/
259281
inline const std::array<uint8_t, ETHER_ADDR_LEN>& getTorMacAddress() const {return mTorMacAddress;};
260282

283+
/**
284+
* @method getVlanMacAddress
285+
*
286+
* @brief getter for Vlan MAC address
287+
*
288+
* @return Vlan MAC address
289+
*/
290+
inline const std::array<uint8_t, ETHER_ADDR_LEN>& getVlanMacAddress() const {return mVlanMacAddress;};
291+
261292
/**
262293
*@method getLoopbackIpv4Address
263294
*
@@ -334,6 +365,15 @@ class MuxConfig
334365
*/
335366
inline void setUseWellKnownMacActiveActive(bool useWellKnownMacActiveActive) { mUseWellKnownMacActiveActive = useWellKnownMacActiveActive; };
336367

368+
/**
369+
* @method getIfEnableUseTorMac
370+
*
371+
* @brief check if use ToR MAC address as src MAC for link prober
372+
*
373+
* @return if use ToR MAC
374+
*/
375+
inline bool getIfEnableUseTorMac() {return mEnableUseTorMac;};
376+
337377
private:
338378
uint8_t mNumberOfThreads = 5;
339379
uint32_t mTimeoutIpv4_msec = 100;
@@ -350,7 +390,10 @@ class MuxConfig
350390
bool mEnableDefaultRouteFeature = false;
351391
bool mUseWellKnownMacActiveActive = true;
352392

393+
bool mEnableUseTorMac = false;
394+
353395
std::array<uint8_t, ETHER_ADDR_LEN> mTorMacAddress;
396+
std::array<uint8_t, ETHER_ADDR_LEN> mVlanMacAddress;
354397
boost::asio::ip::address mLoopbackIpv4Address = boost::asio::ip::make_address("10.212.64.0");
355398
};
356399

src/common/MuxPortConfig.h

+18
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,15 @@ class MuxPortConfig
210210
*/
211211
inline const std::array<uint8_t, ETHER_ADDR_LEN>& getTorMacAddress() const {return mMuxConfig.getTorMacAddress();};
212212

213+
/**
214+
* @method getVlanMacAddress
215+
*
216+
* @brief getter for Vlan MAC address
217+
*
218+
* @return Vlan MAC address
219+
*/
220+
inline const std::array<uint8_t, ETHER_ADDR_LEN>& getVlanMacAddress() const {return mMuxConfig.getVlanMacAddress();};
221+
213222
/**
214223
*@method getLoopbackIpv4Address
215224
*
@@ -360,6 +369,15 @@ class MuxPortConfig
360369
*/
361370
inline void setLastUpdatedMacAddress(const std::array<uint8_t, ETHER_ADDR_LEN> &address) {mLastUpdatedMacAddress = address;};
362371

372+
/**
373+
* @method ifEnableUseTorMac
374+
*
375+
* @brief check if use ToR MAC address as src MAC for link prober
376+
*
377+
* @reutrn if use ToR MAC
378+
*/
379+
inline bool ifEnableUseTorMac() {return mMuxConfig.getIfEnableUseTorMac();};
380+
363381
private:
364382
MuxConfig &mMuxConfig;
365383
std::string mPortName;

src/link_manager/LinkManagerStateMachineActiveActive.h

-1
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,6 @@ class ActiveActiveStateMachine : public LinkManagerStateMachineBase,
570570

571571
boost::function<void()> mInitializeProberFnPtr;
572572
boost::function<void()> mStartProbingFnPtr;
573-
boost::function<void()> mUpdateEthernetFrameFnPtr;
574573
boost::function<void()> mProbePeerTorFnPtr;
575574
boost::function<void(uint32_t suspendTime_msec)> mSuspendTxFnPtr;
576575
boost::function<void()> mResumeTxFnPtr;

src/link_manager/LinkManagerStateMachineActiveStandby.h

-1
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,6 @@ class ActiveStandbyStateMachine: public LinkManagerStateMachineBase,
835835

836836
boost::function<void ()> mInitializeProberFnPtr;
837837
boost::function<void ()> mStartProbingFnPtr;
838-
boost::function<void ()> mUpdateEthernetFrameFnPtr;
839838
boost::function<void ()> mProbePeerTorFnPtr;
840839
boost::function<void (uint32_t suspendTime_msec)> mSuspendTxFnPtr;
841840
boost::function<void ()> mResumeTxFnPtr;

src/link_manager/LinkManagerStateMachineBase.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,33 @@ void LinkManagerStateMachineBase::handleGetServerMacAddressNotification(std::arr
139139
MUXLOGINFO(mMuxPortConfig.getPortName());
140140
}
141141

142+
//
143+
// ---> handleSrcMacConfigNotification();
144+
//
145+
// handle src mac config notification
146+
//
147+
void LinkManagerStateMachineBase::handleSrcMacConfigNotification()
148+
{
149+
MUXLOGDEBUG(mMuxPortConfig.getPortName());
150+
151+
if (mUpdateEthernetFrameFnPtr) {
152+
mUpdateEthernetFrameFnPtr();
153+
} else {
154+
std::array<uint8_t, ETHER_ADDR_LEN> address = (mMuxPortConfig.ifEnableUseTorMac())? mMuxPortConfig.getTorMacAddress() : mMuxPortConfig.getVlanMacAddress() ;
155+
std::array<char, 3 * ETHER_ADDR_LEN> addressStr = {0};
156+
snprintf(
157+
addressStr.data(), addressStr.size(), "%02x:%02x:%02x:%02x:%02x:%02x",
158+
address[0], address[1], address[2], address[3], address[4], address[5]
159+
);
160+
161+
MUXLOGERROR(boost::format("%s: failed to update Ethernet frame with src mac '%s', link prober init state: %d") %
162+
mMuxPortConfig.getPortName() %
163+
addressStr.data() %
164+
mComponentInitState.test(LinkProberComponent)
165+
);
166+
}
167+
}
168+
142169
//
143170
// ---> handleUseWellKnownMacAddressNotification();
144171
//

0 commit comments

Comments
 (0)