Skip to content

Commit 459adb4

Browse files
committed
use swss/warm_start.h
1 parent 027b446 commit 459adb4

File tree

9 files changed

+125
-111
lines changed

9 files changed

+125
-111
lines changed

src/DbInterface.cpp

Lines changed: 46 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,52 @@ void DbInterface::getSoCIpAddress(std::shared_ptr<swss::DBConnector> configDbCon
723723
processSoCIpAddress(entries);
724724
}
725725

726+
// ---> warmRestartReconciliation(const std::string &portName);
727+
//
728+
// port warm restart reconciliation procedure
729+
//
730+
void DbInterface::warmRestartReconciliation(const std::string &portName)
731+
{
732+
MUXLOGDEBUG(portName);
733+
734+
setMuxMode(portName, "auto");
735+
mMuxManagerPtr->updateWarmRestartReconciliationCount(-1);
736+
}
737+
738+
//
739+
// ---> setMuxMode
740+
//
741+
// set config db mux mode
742+
//
743+
void DbInterface::setMuxMode(const std::string &portName, const std::string state)
744+
{
745+
MUXLOGDEBUG(portName);
746+
747+
boost::asio::io_service &ioService = mStrand.context();
748+
ioService.post(mStrand.wrap(boost::bind(
749+
&DbInterface::handleSetMuxMode,
750+
this,
751+
portName,
752+
state
753+
)));
754+
}
755+
756+
//
757+
// ---> handleSetMuxmode
758+
//
759+
// handle set mux mode
760+
//
761+
void DbInterface::handleSetMuxMode(const std::string &portName, const std::string state)
762+
{
763+
MUXLOGWARNING(boost::format("%s: configuring mux mode to %s after warm restart") % portName % state);
764+
765+
std::shared_ptr<swss::DBConnector> configDbPtr = std::make_shared<swss::DBConnector> ("CONFIG_DB", 0);
766+
std::shared_ptr<swss::Table> configDbMuxCableTablePtr = std::make_shared<swss::Table> (
767+
configDbPtr.get(), CFG_MUX_CABLE_TABLE_NAME
768+
);
769+
configDbMuxCableTablePtr->hset(portName, "state", state);
770+
}
771+
726772
//
727773
// ---> processMuxPortConfigNotifiction(std::deque<swss::KeyOpFieldsValuesTuple> &entries);
728774
//
@@ -1145,71 +1191,6 @@ void DbInterface::handleDefaultRouteStateNotification(swss::SubscriberStateTable
11451191
processDefaultRouteStateNotification(entries);
11461192
}
11471193

1148-
//
1149-
// ---> getWarmRestartFlag();
1150-
//
1151-
// get flag to check if system is in warm reboot context
1152-
//
1153-
void DbInterface::getWarmRestartFlag(std::shared_ptr<swss::DBConnector> stateDbConnector)
1154-
{
1155-
MUXLOGINFO("Reading Warm Restart Flag");
1156-
1157-
swss::Table stateDbWarmRestartEnableTable(stateDbConnector.get(), WARM_RESTART_ENABLE_TABLE_NAME);
1158-
const std::string key = "system";
1159-
const std::string field = "enable";
1160-
std::string flag;
1161-
1162-
if (stateDbWarmRestartEnableTable.hget(key, field, flag)) {
1163-
mMuxManagerPtr->processWarmRestartFlag(flag);
1164-
} else {
1165-
MUXLOGINFO("Warm restart flag is not found");
1166-
}
1167-
}
1168-
1169-
//
1170-
// ---> checkWarmRestart(const std::string portName);
1171-
//
1172-
// check if warm restart is on when port completes reconciliation
1173-
//
1174-
void DbInterface::checkWarmRestart(const std::string &portName)
1175-
{
1176-
MUXLOGDEBUG(portName);
1177-
1178-
if (mMuxManagerPtr->getWarmRestartFlag()) {
1179-
setMuxMode(portName, "auto");
1180-
mMuxManagerPtr->updateWarmRestartReconciliationCount(-1);
1181-
}
1182-
}
1183-
1184-
//
1185-
// ---> setMuxReconciled
1186-
//
1187-
// set warm reboot linkmgrd table entry to reconciled
1188-
//
1189-
void DbInterface::setMuxReconciled()
1190-
{
1191-
boost::asio::io_service &ioService = mStrand.context();
1192-
ioService.post(mStrand.wrap(boost::bind(
1193-
&DbInterface::handleSetMuxReconciled,
1194-
this
1195-
)));
1196-
}
1197-
1198-
//
1199-
// ---> handleSetMuxReconciled
1200-
//
1201-
// handle set linkmgrd reconciled
1202-
//
1203-
void DbInterface::handleSetMuxReconciled()
1204-
{
1205-
MUXLOGWARNING("Setting linkmgrd as reconciled in state db now");
1206-
1207-
std::shared_ptr<swss::Table> stateDbWarmRestartTablePtr = std::make_shared<swss::Table> (
1208-
mStateDbPtr.get(), WARM_RESTART_TABLE_NAME
1209-
);
1210-
stateDbWarmRestartTablePtr->hset("linkmgrd", "state", "reconciled");
1211-
}
1212-
12131194
//
12141195
// ---> setMuxMode
12151196
//

src/DbInterface.h

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -274,24 +274,15 @@ class DbInterface
274274
void setMuxMode(const std::string &portName, const std::string state);
275275

276276
/**
277-
* @method setMuxReconciled
277+
* @method warmRestartReconciliation
278278
*
279-
* @brief set warm reboot linkmgrd table entry to reconciled
280-
*
281-
* @return none
282-
*/
283-
void setMuxReconciled();
284-
285-
/**
286-
* @method checkWarmRestart
287-
*
288-
* @brief check if warm restart is on when port completes reconciliation
279+
* @brief port warm restart reconciliation procedure
289280
*
290281
* @param portName(in) Mux port name
291282
*
292283
* @return none
293284
*/
294-
virtual void checkWarmRestart(const std::string &portName);
285+
virtual void warmRestartReconciliation(const std::string &portName);
295286

296287
private:
297288
friend class test::MuxManagerTest;
@@ -407,15 +398,6 @@ class DbInterface
407398
const uint64_t expectedPacketCount
408399
);
409400

410-
/**
411-
* @method handleSetMuxReconciled
412-
*
413-
* @brief handle set linkmgrd reconciled
414-
*
415-
* @return none
416-
*/
417-
virtual void handleSetMuxReconciled();
418-
419401
/**
420402
* @method handleSetMuxMode
421403
*

src/LinkMgrdMain.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <boost/lexical_cast.hpp>
2727
#include <boost/program_options.hpp>
2828

29+
#include "swss/warm_restart.h"
30+
2931
#include "MuxManager.h"
3032
#include "MuxPort.h"
3133
#include "common/MuxConfig.h"
@@ -123,6 +125,13 @@ int main(int argc, const char* argv[])
123125
// initialize static data
124126
link_prober::IcmpPayload::generateGuid();
125127

128+
// warm restart static
129+
swss::WarmStart::initialize("linkmgrd", "mux");
130+
swss::WarmStart::checkWarmStart("linkmgrd", "mux");
131+
if (swss::WarmStart::isWarmStart()) {
132+
swss::WarmStart::setWarmStartState("linkmgrd", swss::WarmStart::INITIALIZED);
133+
}
134+
126135
std::shared_ptr<mux::MuxManager> muxManagerPtr = std::make_shared<mux::MuxManager> ();
127136
muxManagerPtr->initialize(measureSwitchover, defaultRoute);
128137
muxManagerPtr->run();

src/MuxManager.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
#include <boost/bind/bind.hpp>
3030

31+
#include "swss/warm_restart.h"
32+
3133
#include "common/MuxException.h"
3234
#include "common/MuxLogger.h"
3335
#include "MuxManager.h"
@@ -78,13 +80,19 @@ void MuxManager::setUseWellKnownMacActiveActive(bool useWellKnownMac)
7880
//
7981
void MuxManager::initialize(bool enable_feature_measurement, bool enable_feature_default_route)
8082
{
83+
8184
for (uint8_t i = 0; (mMuxConfig.getNumberOfThreads() > 2) &&
8285
(i < mMuxConfig.getNumberOfThreads() - 2); i++) {
8386
mThreadGroup.create_thread(
8487
boost::bind(&boost::asio::io_service::run, &mIoService)
8588
);
8689
}
8790

91+
if (swss::WarmStart::isWarmStart()) {
92+
MUXLOGINFO("Detected warm restart context, starting reconciliation timer.");
93+
startWarmRestartReconciliationTimer(swss::WarmStart::getWarmStartTimer("linkmgrd", "mux"));
94+
}
95+
8896
mDbInterfacePtr->initialize();
8997

9098
mMuxConfig.enableSwitchoverMeasurement(enable_feature_measurement);
@@ -471,6 +479,7 @@ void MuxManager::handleProcessTerminate()
471479
mDbInterfacePtr->getBarrier().wait();
472480
}
473481

482+
<<<<<<< HEAD
474483
//
475484
// ---> generateServerMac();
476485
//
@@ -504,6 +513,8 @@ void MuxManager::processWarmRestartFlag(const std::string &flag)
504513
}
505514
}
506515

516+
=======
517+
>>>>>>> c8fdafd... use swss/warm_start.h
507518
// ---> updateWarmRestartReconciliationCount(int increment);
508519
//
509520
// update warm restart reconciliation count
@@ -540,10 +551,10 @@ void MuxManager::handleUpdateReconciliationCount(int increment)
540551
//
541552
// start warm restart reconciliation timer
542553
//
543-
void MuxManager::startWarmRestartReconciliationTimer()
554+
void MuxManager::startWarmRestartReconciliationTimer(uint32_t timeout)
544555
{
545556
mReconciliationTimer.expires_from_now(boost::posix_time::seconds(
546-
mMuxConfig.getMuxReconciliationTimeout_sec()
557+
timeout == 0? mMuxConfig.getMuxReconciliationTimeout_sec():timeout
547558
));
548559
mReconciliationTimer.async_wait(mStrand.wrap(boost::bind(
549560
&MuxManager::handleWarmRestartReconciliationTimeout,
@@ -562,7 +573,7 @@ void MuxManager::handleWarmRestartReconciliationTimeout(const boost::system::err
562573
MUXLOGWARNING("Reconciliation timed out after warm restart, set service to reconciled now.");
563574
}
564575

565-
mDbInterfacePtr->setMuxReconciled();
576+
swss::WarmStart::setWarmStartState("linkmgrd", swss::WarmStart::RECONCILED);
566577
}
567578

568579
} /* namespace mux */

src/MuxManager.h

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -399,24 +399,6 @@ class MuxManager
399399
*/
400400
void addOrUpdateDefaultRouteState(bool is_v4, const std::string &routeState);
401401

402-
/**
403-
* @method processWarmRestartFlag
404-
*
405-
* @brief process warm restart flag
406-
*
407-
* @return
408-
*/
409-
void processWarmRestartFlag(const std::string &flag);
410-
411-
/**
412-
* @method getWarmRestartFlag
413-
*
414-
* @brief getter for warm restart flag
415-
*
416-
* @return warm restart flag
417-
*/
418-
bool getWarmRestartFlag() {return mWarmRestartFlag == "true"? true:false;};
419-
420402
/**
421403
* @method updateWarmRestartReconciliationCount
422404
*
@@ -523,6 +505,38 @@ class MuxManager
523505
*/
524506
void setDbInterfacePtr(std::shared_ptr<mux::DbInterface> dbInterfacePtr) {mDbInterfacePtr = dbInterfacePtr;};
525507

508+
private:
509+
/**
510+
* @method startWarmRestartReconciliationTimer
511+
*
512+
* @brief start warm restart reconciliation timer
513+
*
514+
* @return none
515+
*/
516+
void startWarmRestartReconciliationTimer(uint32_t timeout=0);
517+
518+
/**
519+
* @method handleWarmRestartReconciliationTimeout
520+
*
521+
* @brief handle warm restart reconciliationTimeout
522+
*
523+
* @param errorCode (in) Boost error code
524+
*
525+
* @return none
526+
*/
527+
void handleWarmRestartReconciliationTimeout(const boost::system::error_code errorCode);
528+
529+
/**
530+
* @method handleUpdateReconciliationCount
531+
*
532+
* @brief handler of updating reconciliation port count
533+
*
534+
* @param increment
535+
*
536+
* @return none
537+
*/
538+
void handleUpdateReconciliationCount(int increment);
539+
526540
private:
527541
common::MuxConfig mMuxConfig;
528542

@@ -533,6 +547,7 @@ class MuxManager
533547

534548
boost::asio::io_service::strand mStrand;
535549
boost::asio::deadline_timer mReconciliationTimer;
550+
uint16_t mPortReconciliationCount = 0;
536551

537552
std::shared_ptr<mux::DbInterface> mDbInterfacePtr;
538553

src/MuxPort.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include <boost/random/uniform_int_distribution.hpp>
3737
#include <boost/random/mersenne_twister.hpp>
3838

39+
#include "swss/warm_restart.h"
40+
3941
#include "MuxPort.h"
4042
#include "common/MuxException.h"
4143
#include "common/MuxLogger.h"
@@ -364,4 +366,16 @@ void MuxPort::resetPckLossCount()
364366
)));
365367
}
366368

369+
//
370+
// ---> warmRestartReconciliation();
371+
//
372+
// brief port warm restart reconciliation procedure
373+
//
374+
void MuxPort::warmRestartReconciliation()
375+
{
376+
if (swss::WarmStart::isWarmStart() && mMuxPortConfig.getMode() != common::MuxPortConfig::Mode::Auto) {
377+
mDbInterfacePtr->warmRestartReconciliation(mMuxPortConfig.getPortName());
378+
}
379+
}
380+
367381
} /* namespace mux */

src/MuxPort.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,13 @@ class MuxPort: public std::enable_shared_from_this<MuxPort>
380380
void resetPckLossCount();
381381

382382
/**
383-
* @method checkWarmRestart
383+
* @method warmRestartReconciliation
384384
*
385-
* @brief check if warm restart was going on, if yes, set config db mux mode to auto
385+
* @brief port warm restart reconciliation procedure
386386
*
387387
* @return none
388388
*/
389-
void checkWarmRestart(){mDbInterfacePtr->checkWarmRestart(mMuxPortConfig.getPortName());};
389+
void warmRestartReconciliation();
390390

391391
protected:
392392
friend class test::MuxManagerTest;

src/common/MuxConfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ class MuxConfig
356356
bool mEnableSwitchoverMeasurement = false;
357357
uint32_t mDecreasedTimeoutIpv4_msec = 10;
358358

359+
uint32_t mMuxReconciliationTimeout_sec = 10;
360+
359361
bool mEnableDefaultRouteFeature = false;
360362
bool mUseWellKnownMacActiveActive = true;
361363

src/link_manager/LinkManagerStateMachineActiveStandby.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ void ActiveStandbyStateMachine::activateStateMachine()
427427

428428
updateMuxLinkmgrState();
429429

430-
mMuxPortPtr->checkWarmRestart();
430+
mMuxPortPtr->warmRestartReconciliation();
431431
}
432432
}
433433

0 commit comments

Comments
 (0)