-
Notifications
You must be signed in to change notification settings - Fork 520
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
[fpmsyncd] Implement pending route suppression feature #2551
Changes from 26 commits
ad39a92
8521ddf
b7a4a52
51c6f56
728d8f7
4c59435
22abcf0
4c87474
e04a3fb
435ca0b
ae2ec35
75fac9a
2a67069
5c94391
8926ddd
277c6ed
41e4747
7f902d2
b38772d
beedfcb
41165ef
2cb0668
c406539
97d984e
e87dfb5
75f55b8
a7db827
e9dc153
c8d7d0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include <swss/selectable.h> | ||
#include <libnl3/netlink/netlink.h> | ||
|
||
#include "fpm/fpm.h" | ||
|
||
namespace swss | ||
{ | ||
|
||
/** | ||
* @brief FPM zebra communication interface | ||
*/ | ||
class FpmInterface : public Selectable | ||
{ | ||
public: | ||
virtual ~FpmInterface() = default; | ||
|
||
/** | ||
* @brief Send netlink message through FPM socket | ||
* @param msg Netlink message | ||
* @return True on success, otherwise false is returned | ||
*/ | ||
virtual bool send(nlmsghdr* nl_hdr) = 0; | ||
}; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,14 @@ | |
#include "select.h" | ||
#include "selectabletimer.h" | ||
#include "netdispatcher.h" | ||
#include "netlink.h" | ||
#include "notificationconsumer.h" | ||
#include "subscriberstatetable.h" | ||
#include "warmRestartHelper.h" | ||
#include "fpmsyncd/fpmlink.h" | ||
#include "fpmsyncd/routesync.h" | ||
|
||
#include <netlink/route/route.h> | ||
|
||
using namespace std; | ||
using namespace swss; | ||
|
@@ -47,21 +51,47 @@ static bool eoiuFlagsSet(Table &bgpStateTable) | |
int main(int argc, char **argv) | ||
{ | ||
swss::Logger::linkToDbNative("fpmsyncd"); | ||
|
||
const auto routeResponseChannelName = std::string("APPL_DB_") + APP_ROUTE_TABLE_NAME + "_RESPONSE_CHANNEL"; | ||
|
||
DBConnector db("APPL_DB", 0); | ||
DBConnector cfgDb("CONFIG_DB", 0); | ||
SubscriberStateTable deviceMetadataTableSubscriber(&cfgDb, CFG_DEVICE_METADATA_TABLE_NAME); | ||
Table deviceMetadataTable(&cfgDb, CFG_DEVICE_METADATA_TABLE_NAME); | ||
DBConnector applStateDb("APPL_STATE_DB", 0); | ||
std::unique_ptr<NotificationConsumer> routeResponseChannel; | ||
|
||
RedisPipeline pipeline(&db); | ||
RouteSync sync(&pipeline); | ||
|
||
DBConnector stateDb("STATE_DB", 0); | ||
Table bgpStateTable(&stateDb, STATE_BGP_TABLE_NAME); | ||
|
||
NetLink netlink; | ||
|
||
netlink.registerGroup(RTNLGRP_LINK); | ||
|
||
NetDispatcher::getInstance().registerMessageHandler(RTM_NEWROUTE, &sync); | ||
NetDispatcher::getInstance().registerMessageHandler(RTM_DELROUTE, &sync); | ||
NetDispatcher::getInstance().registerMessageHandler(RTM_NEWLINK, &sync); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stepanblyschak what's the usage for RTM_NETLINK? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I listen for newlink/dellink events to refill link cache - https://github.com/sonic-net/sonic-swss/pull/2551/files#diff-0555c0a4f1e207c410ac8ab7d4a44f48a0925da2ed14c57499a4e9175223be57R607. E.g, we need link cache to map VRF linux interface name to VRF if_index to pass to FRR. In case VRF linux interface is removed and then re-created with the same name the link cache will have an invalid entry. So I refill the cache on newlink/dellink events. |
||
NetDispatcher::getInstance().registerMessageHandler(RTM_DELLINK, &sync); | ||
|
||
rtnl_route_read_protocol_names(DefaultRtProtoPath); | ||
|
||
std::string suppressionEnabledStr; | ||
deviceMetadataTable.hget("localhost", "suppress-fib-pending", suppressionEnabledStr); | ||
if (suppressionEnabledStr == "enabled") | ||
{ | ||
routeResponseChannel = std::make_unique<NotificationConsumer>(&applStateDb, routeResponseChannelName); | ||
sync.setSuppressionEnabled(true); | ||
} | ||
|
||
while (true) | ||
{ | ||
try | ||
{ | ||
FpmLink fpm(&sync); | ||
|
||
Select s; | ||
SelectableTimer warmStartTimer(timespec{0, 0}); | ||
// Before eoiu flags detected, check them periodically. It also stop upon detection of reconciliation done. | ||
|
@@ -80,6 +110,13 @@ int main(int argc, char **argv) | |
cout << "Connected!" << endl; | ||
|
||
s.addSelectable(&fpm); | ||
s.addSelectable(&netlink); | ||
s.addSelectable(&deviceMetadataTableSubscriber); | ||
|
||
if (sync.isSuppressionEnabled()) | ||
{ | ||
s.addSelectable(routeResponseChannel.get()); | ||
} | ||
|
||
/* If warm-restart feature is enabled, execute 'restoration' logic */ | ||
bool warmStartEnabled = sync.m_warmStartHelper.checkAndStart(); | ||
|
@@ -139,11 +176,8 @@ int main(int argc, char **argv) | |
SWSS_LOG_NOTICE("Warm-Restart EOIU hold timer expired."); | ||
} | ||
|
||
if (sync.m_warmStartHelper.inProgress()) | ||
{ | ||
sync.m_warmStartHelper.reconcile(); | ||
SWSS_LOG_NOTICE("Warm-Restart reconciliation processed."); | ||
} | ||
sync.onWarmStartEnd(applStateDb); | ||
|
||
// remove the one-shot timer. | ||
s.removeSelectable(temps); | ||
pipeline.flush(); | ||
|
@@ -182,6 +216,67 @@ int main(int argc, char **argv) | |
s.removeSelectable(&eoiuCheckTimer); | ||
} | ||
} | ||
else if (temps == &deviceMetadataTableSubscriber) | ||
{ | ||
std::deque<KeyOpFieldsValuesTuple> keyOpFvsQueue; | ||
deviceMetadataTableSubscriber.pops(keyOpFvsQueue); | ||
|
||
for (const auto& keyOpFvs: keyOpFvsQueue) | ||
{ | ||
const auto& key = kfvKey(keyOpFvs); | ||
const auto& op = kfvOp(keyOpFvs); | ||
const auto& fvs = kfvFieldsValues(keyOpFvs); | ||
|
||
if (op != SET_COMMAND) | ||
{ | ||
continue; | ||
} | ||
|
||
if (key != "localhost") | ||
{ | ||
continue; | ||
} | ||
|
||
for (const auto& fv: fvs) | ||
{ | ||
const auto& field = fvField(fv); | ||
const auto& value = fvValue(fv); | ||
|
||
if (field != "suppress-fib-pending") | ||
{ | ||
continue; | ||
} | ||
|
||
bool shouldEnable = (value == "enabled"); | ||
|
||
if (shouldEnable && !sync.isSuppressionEnabled()) | ||
{ | ||
routeResponseChannel = std::make_unique<NotificationConsumer>(&applStateDb, routeResponseChannelName); | ||
sync.setSuppressionEnabled(true); | ||
s.addSelectable(routeResponseChannel.get()); | ||
} | ||
else if (!shouldEnable && sync.isSuppressionEnabled()) | ||
{ | ||
sync.setSuppressionEnabled(false); | ||
StormLiangMS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
s.removeSelectable(routeResponseChannel.get()); | ||
routeResponseChannel.reset(); | ||
} | ||
} // end for fvs | ||
} // end for keyOpFvsQueue | ||
} | ||
else if (routeResponseChannel && (temps == routeResponseChannel.get())) | ||
{ | ||
std::deque<KeyOpFieldsValuesTuple> notifications; | ||
routeResponseChannel->pops(notifications); | ||
|
||
for (const auto& notification: notifications) | ||
{ | ||
const auto& key = kfvKey(notification); | ||
const auto& fieldValues = kfvFieldsValues(notification); | ||
|
||
sync.onRouteResponse(key, fieldValues); | ||
} | ||
} | ||
else if (!warmStartEnabled || sync.m_warmStartHelper.isReconciled()) | ||
{ | ||
pipeline.flush(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wording issue, then -> than
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed