From f21f91a99917ce0c36a47f1f17b102e6de29e9ef Mon Sep 17 00:00:00 2001 From: abdosi <58047199+abdosi@users.noreply.github.com> Date: Thu, 17 Oct 2024 17:44:12 -0700 Subject: [PATCH 1/6] Update values_store.cpp --- tlm_teamd/values_store.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tlm_teamd/values_store.cpp b/tlm_teamd/values_store.cpp index f883d22fd3..a955d36be7 100644 --- a/tlm_teamd/values_store.cpp +++ b/tlm_teamd/values_store.cpp @@ -366,7 +366,13 @@ void ValuesStore::update(const std::vector & dumps) { const auto & storage = from_json(dumps); const auto & old_keys = get_old_keys(storage); - remove_keys_db(old_keys); + // Do not delete te key from State Db. State DB LAB_TABLE entry is created/deleted + // from teamsyncd on detecting netlink of teamd dev as up/down. For some reason + // if we do not get state dump from teamdctl it might be transient issue. If it is + // persistent issue then teamsyncd might be able to catch it and delete state db entry + // or we can keep entry in it's current state as best effort. Similar to try_add_lag which is best effort + // to connect to teamdctl and if it fails we do not delete State Db entry. + //remove_keys_db(old_keys); remove_keys_storage(old_keys); const auto & keys_to_refresh = update_storage(storage); update_db(storage, keys_to_refresh); From f609c8da8c08b36008507d9050bafa5a09b9e0ee Mon Sep 17 00:00:00 2001 From: abdosi <58047199+abdosi@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:49:32 -0700 Subject: [PATCH 2/6] Update values_store.cpp --- tlm_teamd/values_store.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tlm_teamd/values_store.cpp b/tlm_teamd/values_store.cpp index a955d36be7..957194b4c5 100644 --- a/tlm_teamd/values_store.cpp +++ b/tlm_teamd/values_store.cpp @@ -281,6 +281,14 @@ void ValuesStore::remove_keys_db(const std::vector & keys) const auto & p = split_key(key); const auto & table_name = p.first; const auto & table_key = p.second; + // Do not delete te key from State Db for table LAB_TABLE. LAB_TABLE entry is created/deleted + // from teamsyncd on detecting netlink of teamd dev as up/down. For some reason + // if we do not get state dump from teamdctl it might be transient issue. If it is + // persistent issue then teamsyncd might be able to catch it and delete state db entry + // or we can keep entry in it's current state as best effort. Similar to try_add_lag which is best effort + // to connect to teamdctl and if it fails we do not delete State Db entry. + if (table_name == "LAG_TABLE") + continue; swss::Table table(m_db, table_name); table.del(table_key); } @@ -366,13 +374,7 @@ void ValuesStore::update(const std::vector & dumps) { const auto & storage = from_json(dumps); const auto & old_keys = get_old_keys(storage); - // Do not delete te key from State Db. State DB LAB_TABLE entry is created/deleted - // from teamsyncd on detecting netlink of teamd dev as up/down. For some reason - // if we do not get state dump from teamdctl it might be transient issue. If it is - // persistent issue then teamsyncd might be able to catch it and delete state db entry - // or we can keep entry in it's current state as best effort. Similar to try_add_lag which is best effort - // to connect to teamdctl and if it fails we do not delete State Db entry. - //remove_keys_db(old_keys); + remove_keys_db(old_keys); remove_keys_storage(old_keys); const auto & keys_to_refresh = update_storage(storage); update_db(storage, keys_to_refresh); From adff6c4080668bc78f6fb7efba4b597250f241d9 Mon Sep 17 00:00:00 2001 From: abdosi <58047199+abdosi@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:56:23 -0700 Subject: [PATCH 3/6] Update values_store.cpp --- tlm_teamd/values_store.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tlm_teamd/values_store.cpp b/tlm_teamd/values_store.cpp index 015ed62524..957194b4c5 100644 --- a/tlm_teamd/values_store.cpp +++ b/tlm_teamd/values_store.cpp @@ -374,13 +374,7 @@ void ValuesStore::update(const std::vector & dumps) { const auto & storage = from_json(dumps); const auto & old_keys = get_old_keys(storage); - // Do not delete te key from State Db. State DB LAB_TABLE entry is created/deleted - // from teamsyncd on detecting netlink of teamd dev as up/down. For some reason - // if we do not get state dump from teamdctl it might be transient issue. If it is - // persistent issue then teamsyncd might be able to catch it and delete state db entry - // or we can keep entry in it's current state as best effort. Similar to try_add_lag which is best effort - // to connect to teamdctl and if it fails we do not delete State Db entry. - //remove_keys_db(old_keys); + remove_keys_db(old_keys); remove_keys_storage(old_keys); const auto & keys_to_refresh = update_storage(storage); update_db(storage, keys_to_refresh); From 1465f0556066808da97348c28223f2754f498d94 Mon Sep 17 00:00:00 2001 From: Abhishek Dosi Date: Tue, 5 Nov 2024 02:03:27 +0000 Subject: [PATCH 4/6] Added support to compile and load code to read yaml file in routesync.cpp. In routesyncd we read tag from constants.yml and take action of not to send route to appdb and also fallback to default route. Signed-off-by: Abhishek Dosi --- fpmsyncd/Makefile.am | 2 +- fpmsyncd/routesync.cpp | 30 ++++++++++++++++++++++++++++++ fpmsyncd/routesync.h | 2 ++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/fpmsyncd/Makefile.am b/fpmsyncd/Makefile.am index 74d36b36c7..d275d35b74 100644 --- a/fpmsyncd/Makefile.am +++ b/fpmsyncd/Makefile.am @@ -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 diff --git a/fpmsyncd/routesync.cpp b/fpmsyncd/routesync.cpp index 0f6ee41188..735895de19 100644 --- a/fpmsyncd/routesync.cpp +++ b/fpmsyncd/routesync.cpp @@ -13,6 +13,7 @@ #include "converter.h" #include #include +#include using namespace std; using namespace swss; @@ -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(); + route_tag_fallback_to_default_route = root["constants"]["bgp"]["route_eligible_for_fallback_to_default_tag"].as(); + } + catch (const exception &e) + { + cout << "Exception \"" << e.what() << "\" had been thrown in daemon in loading constants.yml" << endl; + route_tag_not_to_appdb = 0; + route_tag_fallback_to_default_route = 0; + } } char *RouteSync::prefixMac2Str(char *mac, char *buf, int size) @@ -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) { @@ -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) + 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); @@ -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); diff --git a/fpmsyncd/routesync.h b/fpmsyncd/routesync.h index eb07eb8f15..ccc2953b3c 100644 --- a/fpmsyncd/routesync.h +++ b/fpmsyncd/routesync.h @@ -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}; From 3b456ae6503a58a295ad89c52a87abc94788cfd2 Mon Sep 17 00:00:00 2001 From: Abhishek Dosi Date: Thu, 14 Nov 2024 21:07:27 +0000 Subject: [PATCH 5/6] Added some more fixes Signed-off-by: Abhishek Dosi --- fpmsyncd/routesync.cpp | 4 ++-- tests/Makefile.am | 2 +- tests/mock_tests/Makefile.am | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fpmsyncd/routesync.cpp b/fpmsyncd/routesync.cpp index 735895de19..8358e71319 100644 --- a/fpmsyncd/routesync.cpp +++ b/fpmsyncd/routesync.cpp @@ -98,8 +98,8 @@ RouteSync::RouteSync(RedisPipeline *pipeline) : catch (const exception &e) { cout << "Exception \"" << e.what() << "\" had been thrown in daemon in loading constants.yml" << endl; - route_tag_not_to_appdb = 0; - route_tag_fallback_to_default_route = 0; + route_tag_not_to_appdb = 0xffffffff; + route_tag_fallback_to_default_route = 0xffffffff; } } diff --git a/tests/Makefile.am b/tests/Makefile.am index 8f2aa131c4..1dbbf654f7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 diff --git a/tests/mock_tests/Makefile.am b/tests/mock_tests/Makefile.am index 0f5afa4486..d7b9bebde6 100644 --- a/tests/mock_tests/Makefile.am +++ b/tests/mock_tests/Makefile.am @@ -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 @@ -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 @@ -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 From bcc259b42d0ff71a85f8632978ba6ad2de0ee360 Mon Sep 17 00:00:00 2001 From: Abhishek Dosi Date: Thu, 14 Nov 2024 21:08:50 +0000 Subject: [PATCH 6/6] Fix indendation Signed-off-by: Abhishek Dosi --- fpmsyncd/routesync.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fpmsyncd/routesync.cpp b/fpmsyncd/routesync.cpp index 8358e71319..13f13c3dd4 100644 --- a/fpmsyncd/routesync.cpp +++ b/fpmsyncd/routesync.cpp @@ -715,7 +715,7 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf) if (tag == route_tag_not_to_appdb) return; else if (tag == route_tag_fallback_to_default_route) - route_eligible_for_fallback_to_default_route = true; + route_eligible_for_fallback_to_default_route = true; dip = rtnl_route_get_dst(route_obj); nl_addr2str(dip, destipprefix + strlen(destipprefix), MAX_ADDR_SIZE);