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

Changes to read route tag value from Netlink Message and take appropriate action #3353

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion fpmsyncd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fpmsyncd_SOURCES = fpmsyncd.cpp fpmlink.cpp routesync.cpp $(top_srcdir)/warmrest

fpmsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN)
fpmsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_ASAN)
fpmsyncd_LDADD = $(LDFLAGS_ASAN) -lnl-3 -lnl-route-3 -lswsscommon
fpmsyncd_LDADD = $(LDFLAGS_ASAN) -lnl-3 -lnl-route-3 -lswsscommon -lyaml-cpp

if GCOV_ENABLED
fpmsyncd_SOURCES += ../gcovpreload/gcovpreload.cpp
Expand Down
30 changes: 30 additions & 0 deletions fpmsyncd/routesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "converter.h"
#include <string.h>
#include <arpa/inet.h>
#include <yaml-cpp/yaml.h>

using namespace std;
using namespace swss;
Expand Down Expand Up @@ -86,6 +87,20 @@ RouteSync::RouteSync(RedisPipeline *pipeline) :
m_nl_sock = nl_socket_alloc();
nl_connect(m_nl_sock, NETLINK_ROUTE);
rtnl_link_alloc_cache(m_nl_sock, AF_UNSPEC, &m_link_cache);

YAML::Node root;
try
{
root = YAML::LoadFile("/etc/sonic/constants.yml");
route_tag_not_to_appdb = root["constants"]["bgp"]["route_do_not_send_appdb_tag"].as<int>();
route_tag_fallback_to_default_route = root["constants"]["bgp"]["route_eligible_for_fallback_to_default_tag"].as<int>();
}
catch (const exception &e)
{
cout << "Exception \"" << e.what() << "\" had been thrown in daemon in loading constants.yml" << endl;
route_tag_not_to_appdb = 0xffffffff;
route_tag_fallback_to_default_route = 0xffffffff;
}
}

char *RouteSync::prefixMac2Str(char *mac, char *buf, int size)
Expand Down Expand Up @@ -667,6 +682,8 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
struct rtnl_route *route_obj = (struct rtnl_route *)obj;
struct nl_addr *dip;
char destipprefix[IFNAMSIZ + MAX_ADDR_SIZE + 2] = {0};
uint32_t tag = 0;
bool route_eligible_for_fallback_to_default_route = false;

if (vrf)
{
Expand All @@ -693,6 +710,13 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
destipprefix[strlen(vrf)] = ':';
}

tag = rtnl_route_get_priority(route_obj);

if (tag == route_tag_not_to_appdb)
Copy link
Contributor

Choose a reason for hiding this comment

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

As I understand on pizza box, route_tag_not_to_appdb is zero. If for any route the priority is zero then route will not be added to app_db. So the route will always has non-zero priority?

Copy link
Contributor Author

@abdosi abdosi Nov 13, 2024

Choose a reason for hiding this comment

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

it should not be zero. It always reads from constants.yml. Only time this will be zero in case of fail condition of loading/reading the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it should not be zero. It always reads from constants.yml. Updated the fail case to be non-zero as 0xffffffff

return;
else if (tag == route_tag_fallback_to_default_route)
route_eligible_for_fallback_to_default_route = true;

dip = rtnl_route_get_dst(route_obj);
nl_addr2str(dip, destipprefix + strlen(destipprefix), MAX_ADDR_SIZE);

Expand Down Expand Up @@ -833,6 +857,12 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
fvVector.push_back(wt);
}

if (route_eligible_for_fallback_to_default_route)
{
FieldValueTuple tag("fallback_to_default_route", "true");
fvVector.push_back(tag);
}

if (!warmRestartInProgress)
{
m_routeTable.set(destipprefix, fvVector);
Expand Down
2 changes: 2 additions & 0 deletions fpmsyncd/routesync.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class RouteSync : public NetMsg
ProducerStateTable m_vnet_tunnelTable;
struct nl_cache *m_link_cache;
struct nl_sock *m_nl_sock;
uint32_t route_tag_not_to_appdb;
uint32_t route_tag_fallback_to_default_route;

bool m_isSuppressionEnabled{false};
FpmInterface* m_fpmInterface {nullptr};
Expand Down
2 changes: 1 addition & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ tests_SOURCES = swssnet_ut.cpp request_parser_ut.cpp ../orchagent/request_parser
tests_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI)
tests_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI) -I../orchagent
tests_LDADD = $(LDADD_GTEST) -lnl-genl-3 -lhiredis -lhiredis -lpthread \
-lswsscommon -lswsscommon -lgtest -lgtest_main
-lswsscommon -lswsscommon -lyaml-cpp -lgtest -lgtest_main
6 changes: 3 additions & 3 deletions tests/mock_tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ tests_teammgrd_INCLUDES = $(tests_INCLUDES) -I$(top_srcdir)/cfgmgr -I$(top_srcdi
tests_teammgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI)
tests_teammgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI) $(tests_teammgrd_INCLUDES)
tests_teammgrd_LDADD = $(LDADD_GTEST) $(LDADD_SAI) -lnl-genl-3 -lhiredis -lhiredis \
-lswsscommon -lswsscommon -lgtest -lgtest_main -lzmq -lnl-3 -lnl-route-3 -lpthread -lgmock -lgmock_main
-lswsscommon -lswsscommon -lyaml-cpp -lgtest -lgtest_main -lzmq -lnl-3 -lnl-route-3 -lpthread -lgmock -lgmock_main

## fpmsyncd unit tests

Expand All @@ -246,7 +246,7 @@ tests_fpmsyncd_INCLUDES = $(tests_INCLUDES) -I$(top_srcdir)/tests_fpmsyncd -I$(t
tests_fpmsyncd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI)
tests_fpmsyncd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI) $(tests_fpmsyncd_INCLUDES)
tests_fpmsyncd_LDADD = $(LDADD_GTEST) $(LDADD_SAI) -lnl-genl-3 -lhiredis -lhiredis \
-lswsscommon -lswsscommon -lgtest -lgtest_main -lzmq -lnl-3 -lnl-route-3 -lpthread -lgmock -lgmock_main
-lswsscommon -lswsscommon -lyaml-cpp -lgtest -lgtest_main -lzmq -lnl-3 -lnl-route-3 -lpthread -lgmock -lgmock_main

## response publisher unit tests

Expand All @@ -263,5 +263,5 @@ tests_response_publisher_INCLUDES = $(tests_INCLUDES)
tests_response_publisher_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI)
tests_response_publisher_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI) $(tests_response_publisher_INCLUDES)
tests_response_publisher_LDADD = $(LDADD_GTEST) $(LDADD_SAI) -lnl-genl-3 -lhiredis -lhiredis \
-lswsscommon -lswsscommon -lgtest -lgtest_main -lzmq -lnl-3 -lnl-route-3 -lpthread
-lswsscommon -lswsscommon -lyaml-cpp -lgtest -lgtest_main -lzmq -lnl-3 -lnl-route-3 -lpthread

Loading