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

[fpmsyncd] Implement pending route suppression feature #2551

Merged
merged 29 commits into from
Mar 19, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ad39a92
[fpmsyncd] record protocol in APPL_DB
stepanblyschak Nov 16, 2022
8521ddf
[fpm] add send netlink message API
stepanblyschak Nov 16, 2022
b7a4a52
[fpmsyncd] send offload reply messages
stepanblyschak Nov 16, 2022
51c6f56
[fpmsyncd] implement feedback mechanism
stepanblyschak Nov 16, 2022
728d8f7
[fpmsyncd] support warm restart with responses
stepanblyschak Nov 16, 2022
4c59435
add response channel to select
stepanblyschak Nov 17, 2022
22abcf0
move files
stepanblyschak Nov 17, 2022
4c87474
add more test cases
stepanblyschak Nov 17, 2022
e04a3fb
add a define
stepanblyschak Nov 21, 2022
435ca0b
modify mock fpm to work with older gmock
stepanblyschak Nov 21, 2022
ae2ec35
change field name
stepanblyschak Nov 25, 2022
75fac9a
fix some review comments
stepanblyschak Nov 28, 2022
2a67069
remove cyclic depdency from RouteSync
stepanblyschak Nov 28, 2022
5c94391
break cycle
stepanblyschak Nov 28, 2022
8926ddd
style
stepanblyschak Nov 28, 2022
277c6ed
add comments
stepanblyschak Nov 29, 2022
41e4747
set NLM_F_REQUEST flag
stepanblyschak Dec 16, 2022
7f902d2
fi
stepanblyschak Jan 3, 2023
b38772d
debugh
stepanblyschak Jan 3, 2023
beedfcb
Revert "debugh"
stepanblyschak Jan 3, 2023
41165ef
refresh link cache on NEWLINK/DELLINK because in case of Vrf delation…
stepanblyschak Jan 16, 2023
2cb0668
dont set offload flag twice
stepanblyschak Jan 16, 2023
c406539
add vs test for offload
stepanblyschak Jan 18, 2023
97d984e
use kernel proto in unit tests
stepanblyschak Feb 1, 2023
e87dfb5
add return after receiving newlink/dellink
stepanblyschak Feb 15, 2023
75f55b8
Update test_route.py
stepanblyschak Feb 17, 2023
a7db827
Merge branch 'master' of github.com:azure/sonic-swss into fpm-response
stepanblyschak Mar 6, 2023
e9dc153
fix typo
stepanblyschak Mar 6, 2023
c8d7d0c
send offload flag for all routes when switching from suppression enab…
stepanblyschak Mar 9, 2023
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
27 changes: 27 additions & 0 deletions fpmsyncd/fpminterface.h
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;
};

}
39 changes: 39 additions & 0 deletions fpmsyncd/fpmlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,17 @@ FpmLink::FpmLink(RouteSync *rsync, unsigned short port) :

m_server_up = true;
m_messageBuffer = new char[m_bufSize];
m_sendBuffer = new char[m_bufSize];

m_routesync->onFpmConnected(*this);
}

FpmLink::~FpmLink()
{
m_routesync->onFpmDisconnected();

delete[] m_messageBuffer;
delete[] m_sendBuffer;
if (m_connected)
close(m_connection_socket);
if (m_server_up)
Expand Down Expand Up @@ -277,3 +283,36 @@ void FpmLink::processFpmMessage(fpm_msg_hdr_t* hdr)
nlmsg_free(msg);
}
}

bool FpmLink::send(nlmsghdr* nl_hdr)
{
fpm_msg_hdr_t hdr{};

size_t len = fpm_msg_align(sizeof(hdr) + nl_hdr->nlmsg_len);

if (len > m_bufSize)
{
SWSS_LOG_THROW("Message length %zu is greater then the send buffer size %d", len, m_bufSize);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wording issue, then -> than

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed

}

hdr.version = FPM_PROTO_VERSION;
hdr.msg_type = FPM_MSG_TYPE_NETLINK;
hdr.msg_len = htons(static_cast<uint16_t>(len));

memcpy(m_sendBuffer, &hdr, sizeof(hdr));
memcpy(m_sendBuffer + sizeof(hdr), nl_hdr, nl_hdr->nlmsg_len);

size_t sent = 0;
while (sent != len)
{
auto rc = ::send(m_connection_socket, m_sendBuffer + sent, len - sent, 0);
if (rc == -1)
{
SWSS_LOG_ERROR("Failed to send FPM message: %s", strerror(errno));
return false;
}
sent += rc;
}

return true;
}
7 changes: 5 additions & 2 deletions fpmsyncd/fpmlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
#include <unistd.h>
#include <exception>

#include "selectable.h"
#include "fpm/fpm.h"
#include "fpmsyncd/fpminterface.h"
#include "fpmsyncd/routesync.h"

namespace swss {

class FpmLink : public Selectable {
class FpmLink : public FpmInterface {
public:
const int MSG_BATCH_SIZE;
FpmLink(RouteSync *rsync, unsigned short port = FPM_DEFAULT_PORT);
Expand All @@ -41,10 +41,13 @@ class FpmLink : public Selectable {

void processFpmMessage(fpm_msg_hdr_t* hdr);

bool send(nlmsghdr* nl_hdr) override;

private:
RouteSync *m_routesync;
unsigned int m_bufSize;
char *m_messageBuffer;
char *m_sendBuffer;
unsigned int m_pos;

bool m_connected;
Expand Down
105 changes: 100 additions & 5 deletions fpmsyncd/fpmsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stepanblyschak what's the usage for RTM_NETLINK?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Loading