Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Vlan MAC as src MAC for link prober by default #93

Merged
merged 9 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/DbInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,56 @@ void DbInterface::getTorMacAddress(std::shared_ptr<swss::DBConnector> configDbCo
}
}

//
// ---> getVlanMacAddress(std::shared_ptr<swss::DBConnector> configDbConnector);
//
// retrieve Vlan MAC address informtaion
//
void DbInterface::getVlanMacAddress(std::shared_ptr<swss::DBConnector> configDbConnector)
{
MUXLOGINFO("Reading Vlan MAC Address");
swss::Table configDbVlanTable(configDbConnector.get(), CFG_VLAN_TABLE_NAME);
std::vector<std::string> vlanNames;

configDbVlanTable.getKeys(vlanNames);

if (vlanNames.size() > 0) {
const std::string vlanName = vlanNames[0];
const std::string field = "mac";
std::string mac;

if (configDbVlanTable.hget(vlanName, field, mac)) {
processVlanMacAddress(mac);
} else {
MUXLOGWARNING(boost::format("MAC address is not found for %s, fall back to use device MAC for link prober.") % vlanName);
mMuxManagerPtr->setIfUseTorMacAsSrcMac(true);
}
} else {
MUXLOGWARNING("VLAN table is not found in CONFIG DB, fall back to use device MAC for link prober.");
mMuxManagerPtr->setIfUseTorMacAsSrcMac(true);
}
}

//
// ---> processVlanMacAddress(std::string& mac);
//
// process Vlan Mac Address
//
void DbInterface::processVlanMacAddress(std::string& mac)
{
try {
swss::MacAddress swssMacAddress(mac);
std::array<uint8_t, ETHER_ADDR_LEN> macAddress;

memcpy(macAddress.data(), swssMacAddress.getMac(), macAddress.size());
mMuxManagerPtr->setVlanMacAddress(macAddress);
}
catch (const std::invalid_argument &invalidArgument) {
MUXLOGWARNING("Invalid Vlan MAC address " + mac);
mMuxManagerPtr->setIfUseTorMacAsSrcMac(true);
}
}

//
// ---> processLoopback2InterfaceInfo(std::vector<std::string> &loopbackIntfs)
//
Expand Down Expand Up @@ -848,6 +898,8 @@ void DbInterface::processMuxLinkmgrConfigNotifiction(std::deque<swss::KeyOpField
mMuxManagerPtr->setSuspendTimeout_msec(boost::lexical_cast<uint32_t> (v));
} else if (f == "use_well_known_mac") {
mMuxManagerPtr->setUseWellKnownMacActiveActive(v == "enable");
} else if (f == "src_mac") {
mMuxManagerPtr->processSrcMac(v == "ToRMac");
yxieca marked this conversation as resolved.
Show resolved Hide resolved
}

MUXLOGINFO(boost::format("key: %s, Operation: %s, f: %s, v: %s") %
Expand Down Expand Up @@ -1272,6 +1324,7 @@ void DbInterface::handleSwssNotification()
swss::SubscriberStateTable stateDbPeerMuxTable(stateDbPtr.get(), STATE_PEER_HW_FORWARDING_STATE_TABLE_NAME);

getTorMacAddress(configDbPtr);
getVlanMacAddress(configDbPtr);
getLoopback2InterfaceInfo(configDbPtr);
getPortCableType(configDbPtr);
getServerIpAddress(configDbPtr);
Expand Down
18 changes: 18 additions & 0 deletions src/DbInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,24 @@ class DbInterface
*/
void getTorMacAddress(std::shared_ptr<swss::DBConnector> configDbConnector);

/**
* @method getVlanMacAddress
*
* @brief retrieve Vlan MAC address information
*
* @return none
*/
void getVlanMacAddress(std::shared_ptr<swss::DBConnector> configDbConnector);

/**
* @method processVlanMacAddress
*
* @brief process Vlan Mac Address
*
* @return none
*/
void processVlanMacAddress(std::string& mac);

/**
*@method processLoopback2InterfaceInfo
*
Expand Down
19 changes: 19 additions & 0 deletions src/MuxManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,25 @@ void MuxManager::processGetServerMacAddress(
}
}

//
// ---> processSrcMac(bool useTorMac);
//
// processs src mac config
//
void MuxManager::processSrcMac(bool useTorMac)
{
if (mMuxConfig.getIfEnableUseTorMac() != useTorMac) {
setIfUseTorMacAsSrcMac(useTorMac);

PortMapIterator portMapIterator = mPortMap.begin();
while (portMapIterator != mPortMap.end()) {
portMapIterator->second->handleSrcMacAddressUpdate();
portMapIterator ++;
}
}
}


//
// ---> processGetMuxState(const std::string &portName, const std::string &muxState);
//
Expand Down
33 changes: 33 additions & 0 deletions src/MuxManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,39 @@ class MuxManager
*/
inline void setTorMacAddress(std::array<uint8_t, ETHER_ADDR_LEN> &address) {mMuxConfig.setTorMacAddress(address);};

/**
* @method setVlanMacAddress
*
* @brief setter for Vlan Mac Address
*
* @param address (in) Vlan mac address
*
* @return none
*/
inline void setVlanMacAddress(std::array<uint8_t, ETHER_ADDR_LEN> &address) {mMuxConfig.setVlanMacAddress(address);};

/**
* @method setIfUseTorMacAsSrcMac
*
* @brief setter for flag whether use ToR MAC address as link prober src MAC
*
* @param useTorMac (in) bool
*
* @return none
*/
void setIfUseTorMacAsSrcMac(bool useTorMac) {mMuxConfig.setIfUseTorMacAsSrcMac(useTorMac);};

/**
* @method processSrcMac
*
* @brief processs src mac config
*
* @param enable (in) bool
*
* @return none
*/
void processSrcMac(bool useTorMac);

/**
*@method setSuspendTimeout_msec
*
Expand Down
16 changes: 16 additions & 0 deletions src/MuxPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,22 @@ void MuxPort::handleUseWellKnownMacAddress()
)));
}

//
// ---> handleSrcMacAddressUpdate();
//
// handles src mac address config update
//
void MuxPort::handleSrcMacAddressUpdate()
{
MUXLOGDEBUG(mMuxPortConfig.getPortName());

boost::asio::io_service &ioService = mStrand.context();
ioService.post(mStrand.wrap(boost::bind(
&link_manager::LinkManagerStateMachineBase::handleSrcMacConfigNotification,
mLinkManagerStateMachinePtr.get()
)));
}

//
// ---> handleGetMuxState(const std::string &muxState);
//
Expand Down
9 changes: 9 additions & 0 deletions src/MuxPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,15 @@ class MuxPort: public std::enable_shared_from_this<MuxPort>
*/
void handleUseWellKnownMacAddress();

/**
* @method handleSrcMacAddressUpdate
*
* @brief handles src mac address config update
*
* @return none
*/
void handleSrcMacAddressUpdate();

/**
*@method handleGetMuxState
*
Expand Down
43 changes: 43 additions & 0 deletions src/common/MuxConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,28 @@ class MuxConfig
*/
inline void setTorMacAddress(const std::array<uint8_t, ETHER_ADDR_LEN> &address) {mTorMacAddress = address;};

/**
* @method setVlanMacAddress
*
* @brief setter for Vlan MAC address
*
* @param address (in) Vlan MAC address
*
* @return none
*/
inline void setVlanMacAddress(const std::array<uint8_t, ETHER_ADDR_LEN> &address) {mVlanMacAddress = address;};

/**
* @method setIfUseTorMacAsSrcMac
*
* @brief setter for flag whether use ToR MAC address as link prober src MAC
*
* @param enable (in) bool
*
* @return none
*/
inline void setIfUseTorMacAsSrcMac(bool enable) {mEnableUseTorMac = enable;};

/**
*@method setLoopbackIpv4Address
*
Expand Down Expand Up @@ -258,6 +280,15 @@ class MuxConfig
*/
inline const std::array<uint8_t, ETHER_ADDR_LEN>& getTorMacAddress() const {return mTorMacAddress;};

/**
* @method getVlanMacAddress
*
* @brief getter for Vlan MAC address
*
* @return Vlan MAC address
*/
inline const std::array<uint8_t, ETHER_ADDR_LEN>& getVlanMacAddress() const {return mVlanMacAddress;};

/**
*@method getLoopbackIpv4Address
*
Expand Down Expand Up @@ -334,6 +365,15 @@ class MuxConfig
*/
inline void setUseWellKnownMacActiveActive(bool useWellKnownMacActiveActive) { mUseWellKnownMacActiveActive = useWellKnownMacActiveActive; };

/**
* @method getIfEnableUseTorMac
*
* @brief check if use ToR MAC address as src MAC for link prober
*
* @return if use ToR MAC
*/
inline bool getIfEnableUseTorMac() {return mEnableUseTorMac;};

private:
uint8_t mNumberOfThreads = 5;
uint32_t mTimeoutIpv4_msec = 100;
Expand All @@ -350,7 +390,10 @@ class MuxConfig
bool mEnableDefaultRouteFeature = false;
bool mUseWellKnownMacActiveActive = true;

bool mEnableUseTorMac = false;

std::array<uint8_t, ETHER_ADDR_LEN> mTorMacAddress;
std::array<uint8_t, ETHER_ADDR_LEN> mVlanMacAddress;
boost::asio::ip::address mLoopbackIpv4Address = boost::asio::ip::make_address("10.212.64.0");
};

Expand Down
18 changes: 18 additions & 0 deletions src/common/MuxPortConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ class MuxPortConfig
*/
inline const std::array<uint8_t, ETHER_ADDR_LEN>& getTorMacAddress() const {return mMuxConfig.getTorMacAddress();};

/**
* @method getVlanMacAddress
*
* @brief getter for Vlan MAC address
*
* @return Vlan MAC address
*/
inline const std::array<uint8_t, ETHER_ADDR_LEN>& getVlanMacAddress() const {return mMuxConfig.getVlanMacAddress();};

/**
*@method getLoopbackIpv4Address
*
Expand Down Expand Up @@ -360,6 +369,15 @@ class MuxPortConfig
*/
inline void setLastUpdatedMacAddress(const std::array<uint8_t, ETHER_ADDR_LEN> &address) {mLastUpdatedMacAddress = address;};

/**
* @method ifEnableUseTorMac
*
* @brief check if use ToR MAC address as src MAC for link prober
*
* @reutrn if use ToR MAC
*/
inline bool ifEnableUseTorMac() {return mMuxConfig.getIfEnableUseTorMac();};

private:
MuxConfig &mMuxConfig;
std::string mPortName;
Expand Down
1 change: 0 additions & 1 deletion src/link_manager/LinkManagerStateMachineActiveActive.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,6 @@ class ActiveActiveStateMachine : public LinkManagerStateMachineBase,

boost::function<void()> mInitializeProberFnPtr;
boost::function<void()> mStartProbingFnPtr;
boost::function<void()> mUpdateEthernetFrameFnPtr;
boost::function<void()> mProbePeerTorFnPtr;
boost::function<void(uint32_t suspendTime_msec)> mSuspendTxFnPtr;
boost::function<void()> mResumeTxFnPtr;
Expand Down
1 change: 0 additions & 1 deletion src/link_manager/LinkManagerStateMachineActiveStandby.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,6 @@ class ActiveStandbyStateMachine: public LinkManagerStateMachineBase,

boost::function<void ()> mInitializeProberFnPtr;
boost::function<void ()> mStartProbingFnPtr;
boost::function<void ()> mUpdateEthernetFrameFnPtr;
boost::function<void ()> mProbePeerTorFnPtr;
boost::function<void (uint32_t suspendTime_msec)> mSuspendTxFnPtr;
boost::function<void ()> mResumeTxFnPtr;
Expand Down
27 changes: 27 additions & 0 deletions src/link_manager/LinkManagerStateMachineBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,33 @@ void LinkManagerStateMachineBase::handleGetServerMacAddressNotification(std::arr
MUXLOGINFO(mMuxPortConfig.getPortName());
}

//
// ---> handleSrcMacConfigNotification();
//
// handle src mac config notification
//
void LinkManagerStateMachineBase::handleSrcMacConfigNotification()
{
MUXLOGDEBUG(mMuxPortConfig.getPortName());

if (mUpdateEthernetFrameFnPtr) {
mUpdateEthernetFrameFnPtr();
} else {
std::array<uint8_t, ETHER_ADDR_LEN> address = (mMuxPortConfig.ifEnableUseTorMac())? mMuxPortConfig.getTorMacAddress() : mMuxPortConfig.getVlanMacAddress() ;
std::array<char, 3 * ETHER_ADDR_LEN> addressStr = {0};
snprintf(
addressStr.data(), addressStr.size(), "%02x:%02x:%02x:%02x:%02x:%02x",
address[0], address[1], address[2], address[3], address[4], address[5]
);

MUXLOGERROR(boost::format("%s: failed to update Ethernet frame with src mac '%s', link prober init state: %d") %
mMuxPortConfig.getPortName() %
addressStr.data() %
mComponentInitState.test(LinkProberComponent)
);
}
}

//
// ---> handleUseWellKnownMacAddressNotification();
//
Expand Down
11 changes: 11 additions & 0 deletions src/link_manager/LinkManagerStateMachineBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,15 @@ class LinkManagerStateMachineBase : public common::StateMachine {
*/
virtual void handleGetServerMacAddressNotification(std::array<uint8_t, ETHER_ADDR_LEN> address);

/**
* @method handleSrcMacConfigNotification
*
* @brief handle src mac config notification
*
* @return none
*/
void handleSrcMacConfigNotification();

/**
*@method handleUseWellKnownMacAddressNotification
*
Expand Down Expand Up @@ -561,6 +570,8 @@ class LinkManagerStateMachineBase : public common::StateMachine {
static std::vector<std::string> mLinkStateName;
static std::vector<std::string> mLinkHealthName;

boost::function<void ()> mUpdateEthernetFrameFnPtr;

private:
TransitionFunction mStateTransitionHandler[link_prober::LinkProberState::Label::Count]
[mux_state::MuxState::Label::Count]
Expand Down
6 changes: 5 additions & 1 deletion src/link_prober/LinkProber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,11 @@ void LinkProber::initializeSendBuffer()
{
ether_header *ethHeader = reinterpret_cast<ether_header *> (mTxBuffer.data());
memcpy(ethHeader->ether_dhost, mMuxPortConfig.getBladeMacAddress().data(), sizeof(ethHeader->ether_dhost));
memcpy(ethHeader->ether_shost, mMuxPortConfig.getTorMacAddress().data(), sizeof(ethHeader->ether_shost));
if (mMuxPortConfig.ifEnableUseTorMac()) {
memcpy(ethHeader->ether_shost, mMuxPortConfig.getTorMacAddress().data(), sizeof(ethHeader->ether_shost));
} else {
memcpy(ethHeader->ether_shost, mMuxPortConfig.getVlanMacAddress().data(), sizeof(ethHeader->ether_shost));
}
ethHeader->ether_type = htons(ETHERTYPE_IP);

iphdr *ipHeader = reinterpret_cast<iphdr *> (mTxBuffer.data() + sizeof(ether_header));
Expand Down
Loading