@@ -163,6 +163,31 @@ RouteSync::RouteSync(RedisPipeline *pipeline) :
163163 rtnl_link_alloc_cache (m_nl_sock, AF_UNSPEC, &m_link_cache);
164164}
165165
166+ void RouteSync::setRouteWithWarmRestart (const std::string& key,
167+ const std::vector<FieldValueTuple>& fvVector,
168+ shared_ptr<ProducerStateTable> table,
169+ const std::string& cmd)
170+ {
171+ bool warmRestartInProgress = m_warmStartHelper.inProgress ();
172+
173+ if (!warmRestartInProgress)
174+ {
175+ if (cmd == SET_COMMAND)
176+ {
177+ table->set (key, fvVector);
178+ }
179+ else if (cmd == DEL_COMMAND)
180+ {
181+ table->del (key);
182+ }
183+ }
184+ else
185+ {
186+ const KeyOpFieldsValuesTuple kfv = std::make_tuple (key, cmd, fvVector);
187+ m_warmStartHelper.insertRefreshMap (kfv);
188+ }
189+ }
190+
166191char *RouteSync::prefixMac2Str (char *mac, char *buf, int size)
167192{
168193 char *ptr = buf;
@@ -448,7 +473,7 @@ bool RouteSync::parseSrv6MySid(struct rtattr *tb[], string &block_len,
448473 return true ;
449474}
450475
451- void RouteSync::getEvpnNextHopSep (string& nexthops, string& vni_list,
476+ void RouteSync::getEvpnNextHopSep (string& nexthops, string& vni_list,
452477 string& mac_list, string& intf_list)
453478{
454479 nexthops += NHG_DELIMITER;
@@ -778,27 +803,12 @@ void RouteSync::onEvpnRouteMsg(struct nlmsghdr *h, int len)
778803 * Upon arrival of a delete msg we could either push the change right away,
779804 * or we could opt to defer it if we are going through a warm-reboot cycle.
780805 */
781- bool warmRestartInProgress = m_warmStartHelper.inProgress ();
782-
783806 if (nlmsg_type == RTM_DELROUTE)
784807 {
785- if (!warmRestartInProgress)
786- {
787- m_routeTable->del (destipprefix);
788- return ;
789- }
790- else
791- {
792- SWSS_LOG_INFO (" Warm-Restart mode: Receiving delete msg: %s" ,
793- destipprefix);
794-
795- vector<FieldValueTuple> fvVector;
796- const KeyOpFieldsValuesTuple kfv = std::make_tuple (destipprefix,
797- DEL_COMMAND,
798- fvVector);
799- m_warmStartHelper.insertRefreshMap (kfv);
800- return ;
801- }
808+ vector<FieldValueTuple> fvVector;
809+ setRouteWithWarmRestart (destipprefix, fvVector, m_routeTable, DEL_COMMAND);
810+ SWSS_LOG_INFO (" RouteTable del msg: %s" , destipprefix);
811+ return ;
802812 }
803813 else if (nlmsg_type != RTM_NEWROUTE)
804814 {
@@ -862,29 +872,11 @@ void RouteSync::onEvpnRouteMsg(struct nlmsghdr *h, int len)
862872 fvVector.push_back (vni);
863873 fvVector.push_back (mac);
864874 fvVector.push_back (proto);
865-
866- if (!warmRestartInProgress)
867- {
868- m_routeTable->set (destipprefix, fvVector);
869- SWSS_LOG_DEBUG (" RouteTable set msg: %s vtep:%s vni:%s mac:%s intf:%s protocol:%s" ,
870- destipprefix, nexthops.c_str (), vni_list.c_str (), mac_list.c_str (), intf_list.c_str (),
871- proto_str.c_str ());
872- }
873-
874- /*
875- * During routing-stack restarting scenarios route-updates will be temporarily
876- * put on hold by warm-reboot logic.
877- */
878- else
879- {
880- SWSS_LOG_INFO (" Warm-Restart mode: RouteTable set msg: %s vtep:%s vni:%s mac:%s" ,
881- destipprefix, nexthops.c_str (), vni_list.c_str (), mac_list.c_str ());
882-
883- const KeyOpFieldsValuesTuple kfv = std::make_tuple (destipprefix,
884- SET_COMMAND,
885- fvVector);
886- m_warmStartHelper.insertRefreshMap (kfv);
887- }
875+
876+ setRouteWithWarmRestart (destipprefix, fvVector, m_routeTable, SET_COMMAND);
877+ SWSS_LOG_INFO (" RouteTable set EVPN msg: %s vtep:%s vni:%s mac:%s intf:%s protocol:%s" ,
878+ destipprefix, nexthops.c_str (), vni_list.c_str (), mac_list.c_str (), intf_list.c_str (),
879+ proto_str.c_str ());
888880 return ;
889881}
890882
@@ -1086,36 +1078,24 @@ void RouteSync::onSrv6SteerRouteMsg(struct nlmsghdr *h, int len)
10861078 return ;
10871079 }
10881080
1089- bool warmRestartInProgress = m_warmStartHelper.inProgress ();
1090-
10911081 if (nlmsg_type == RTM_DELROUTE)
10921082 {
1093- string srv6SidListTableKey = routeTableKey;
1083+ string routeTableKeyStr = string (routeTableKey);
1084+ string srv6SidListTableKey = routeTableKeyStr;
10941085
1095- if (!warmRestartInProgress)
1096- {
1097- m_routeTable->del (routeTableKey);
1098- m_srv6SidListTable.del (srv6SidListTableKey);
1099- return ;
1100- }
1101- else
1102- {
1103- SWSS_LOG_INFO (" Warm-Restart mode: Receiving delete msg: %s" ,
1104- routeTableKey);
11051086
1106- vector<FieldValueTuple> fvVector;
1107- const KeyOpFieldsValuesTuple kfv = std::make_tuple (routeTableKey,
1108- DEL_COMMAND,
1109- fvVector);
1110- m_warmStartHelper.insertRefreshMap (kfv);
1111- return ;
1112- }
1087+ vector<FieldValueTuple> fvVector;
1088+ setRouteWithWarmRestart (routeTableKeyStr, fvVector, m_routeTable, DEL_COMMAND);
1089+ SWSS_LOG_INFO (" SRV6 RouteTable del msg: %s" , routeTableKeyStr.c_str ());
1090+ m_srv6SidListTable.del (srv6SidListTableKey);
1091+ return ;
11131092 }
11141093 else if (nlmsg_type == RTM_NEWROUTE)
11151094 {
1095+ string routeTableKeyStr = string (routeTableKey);
11161096 /* Write SID list to SRV6_SID_LIST_TABLE */
11171097
1118- string srv6SidListTableKey = routeTableKey ;
1098+ string srv6SidListTableKey = routeTableKeyStr ;
11191099
11201100 vector<FieldValueTuple> fvVectorSidList;
11211101
@@ -1138,28 +1118,9 @@ void RouteSync::onSrv6SteerRouteMsg(struct nlmsghdr *h, int len)
11381118 FieldValueTuple seg_src (" seg_src" , src_addr_str);
11391119 fvVectorRoute.push_back (seg_src);
11401120 }
1141- if (!warmRestartInProgress)
1142- {
1143- m_routeTable->set (routeTableKey, fvVectorRoute);
1144- SWSS_LOG_DEBUG (" RouteTable set msg: %s vpn_sid: %s src_addr:%s" ,
1145- routeTableKey, vpn_sid_str.c_str (),
1146- src_addr_str.c_str ());
1147- }
1148-
1149- /*
1150- * During routing-stack restarting scenarios route-updates will be
1151- * temporarily put on hold by warm-reboot logic.
1152- */
1153- else
1154- {
1155- SWSS_LOG_INFO (
1156- " Warm-Restart mode: RouteTable set msg: %s vpn_sid:%s src_addr:%s" ,
1157- routeTableKey, vpn_sid_str.c_str (), src_addr_str.c_str ());
1158-
1159- const KeyOpFieldsValuesTuple kfv =
1160- std::make_tuple (routeTableKey, SET_COMMAND, fvVectorRoute);
1161- m_warmStartHelper.insertRefreshMap (kfv);
1162- }
1121+ setRouteWithWarmRestart (routeTableKeyStr, fvVectorRoute, m_routeTable, SET_COMMAND);
1122+ SWSS_LOG_INFO (" SRV6 RouteTable set msg: %s vpn_sid:%s src_addr:%s" ,
1123+ routeTableKeyStr.c_str (), vpn_sid_str.c_str (), src_addr_str.c_str ());
11631124 }
11641125
11651126 return ;
@@ -1607,27 +1568,13 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
16071568 * Upon arrival of a delete msg we could either push the change right away,
16081569 * or we could opt to defer it if we are going through a warm-reboot cycle.
16091570 */
1610- bool warmRestartInProgress = m_warmStartHelper.inProgress ();
1611-
16121571 if (nlmsg_type == RTM_DELROUTE)
16131572 {
1614- if (!warmRestartInProgress)
1615- {
1616- m_routeTable->del (destipprefix);
1617- return ;
1618- }
1619- else
1620- {
1621- SWSS_LOG_INFO (" Warm-Restart mode: Receiving delete msg: %s" ,
1622- destipprefix);
1573+ vector<FieldValueTuple> fvVector;
1574+ setRouteWithWarmRestart (destipprefix, fvVector, m_routeTable, DEL_COMMAND);
1575+ SWSS_LOG_INFO (" RouteTable del msg: %s" , destipprefix);
1576+ return ;
16231577
1624- vector<FieldValueTuple> fvVector;
1625- const KeyOpFieldsValuesTuple kfv = std::make_tuple (destipprefix,
1626- DEL_COMMAND,
1627- fvVector);
1628- m_warmStartHelper.insertRefreshMap (kfv);
1629- return ;
1630- }
16311578 }
16321579 else if (nlmsg_type != RTM_NEWROUTE)
16331580 {
@@ -1651,7 +1598,8 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
16511598 FieldValueTuple fv (" blackhole" , " true" );
16521599 fvVector.push_back (fv);
16531600 fvVector.push_back (proto);
1654- m_routeTable->set (destipprefix, fvVector);
1601+ setRouteWithWarmRestart (destipprefix, fvVector, m_routeTable, SET_COMMAND);
1602+ SWSS_LOG_INFO (" RouteTable set blackhole msg: %s" , destipprefix);
16551603 return ;
16561604 }
16571605 case RTN_UNICAST:
@@ -1671,6 +1619,7 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
16711619 string gw_list;
16721620 string intf_list;
16731621 string mpls_list;
1622+ string weights;
16741623
16751624 string nhg_id_key;
16761625 uint32_t nhg_id = rtnl_route_get_nh_id (route_obj);
@@ -1721,7 +1670,7 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
17211670 /* Get nexthop lists */
17221671
17231672 getNextHopList (route_obj, gw_list, mpls_list, intf_list);
1724- string weights = getNextHopWt (route_obj);
1673+ weights = getNextHopWt (route_obj);
17251674
17261675 vector<string> alsv = tokenize (intf_list, NHG_DELIMITER);
17271676
@@ -1731,25 +1680,9 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
17311680 {
17321681 SWSS_LOG_DEBUG (" Skip routes to eth0 or docker0: %s %s %s" ,
17331682 destipprefix, gw_list.c_str (), intf_list.c_str ());
1734-
1735- if (!warmRestartInProgress)
1736- {
1737- SWSS_LOG_NOTICE (" RouteTable del msg for route with only one nh on eth0/docker0: %s %s %s %s" ,
1738- destipprefix, gw_list.c_str (), intf_list.c_str (), mpls_list.c_str ());
1739-
1740- m_routeTable->del (destipprefix);
1741- }
1742- else
1743- {
1744- SWSS_LOG_NOTICE (" Warm-Restart mode: Receiving delete msg for route with only nh on eth0/docker0: %s %s %s %s" ,
1745- destipprefix, gw_list.c_str (), intf_list.c_str (), mpls_list.c_str ());
1746-
1747- vector<FieldValueTuple> fvVector;
1748- const KeyOpFieldsValuesTuple kfv = std::make_tuple (destipprefix,
1749- DEL_COMMAND,
1750- fvVector);
1751- m_warmStartHelper.insertRefreshMap (kfv);
1752- }
1683+ vector<FieldValueTuple> fvVector;
1684+ setRouteWithWarmRestart (destipprefix, fvVector, m_routeTable, DEL_COMMAND);
1685+ SWSS_LOG_INFO (" RouteTable del msg for eth0/docker0 route: %s" , destipprefix);
17531686 return ;
17541687 }
17551688 }
@@ -1789,34 +1722,18 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
17891722 }
17901723 }
17911724
1792- if (!warmRestartInProgress )
1725+ if (nhg_id )
17931726 {
1794- if (nhg_id)
1795- {
1796- m_routeTable->set (destipprefix, fvVector);
1797- SWSS_LOG_INFO (" RouteTable set msg: %s %d " , destipprefix, nhg_id);
1798- }
1799- else
1800- {
1801- m_routeTable->set (destipprefix, fvVector);
1802- SWSS_LOG_INFO (" RouteTable set msg: %s %s %s %s" , destipprefix,
1803- gw_list.c_str (), intf_list.c_str (), mpls_list.c_str ());
1804- }
1727+ setRouteWithWarmRestart (destipprefix, fvVector, m_routeTable, SET_COMMAND);
1728+ SWSS_LOG_INFO (" RouteTable set msg with NHG: %s nhg_id:%d" , destipprefix, nhg_id);
18051729 }
1806-
1807- /*
1808- * During routing-stack restarting scenarios route-updates will be temporarily
1809- * put on hold by warm-reboot logic.
1810- */
18111730 else
18121731 {
1813- SWSS_LOG_INFO (" Warm-Restart mode: RouteTable set msg: %s %s %s %s" , destipprefix,
1814- gw_list.c_str (), intf_list.c_str (), mpls_list.c_str ());
1815-
1816- const KeyOpFieldsValuesTuple kfv = std::make_tuple (destipprefix,
1817- SET_COMMAND,
1818- fvVector);
1819- m_warmStartHelper.insertRefreshMap (kfv);
1732+ setRouteWithWarmRestart (destipprefix, fvVector, m_routeTable, SET_COMMAND);
1733+ SWSS_LOG_INFO (" RouteTable set msg: %s nexthop:%s ifname:%s mpls:%s weight:%s" ,
1734+ destipprefix, gw_list.c_str (), intf_list.c_str (),
1735+ mpls_list.empty () ? " na" : mpls_list.c_str (),
1736+ weights.empty () ? " na" : weights.c_str ());
18201737 }
18211738}
18221739
@@ -1962,7 +1879,9 @@ void RouteSync::onLabelRouteMsg(int nlmsg_type, struct nl_object *obj)
19621879
19631880 if (nlmsg_type == RTM_DELROUTE)
19641881 {
1965- m_label_routeTable->del (destaddr);
1882+ vector<FieldValueTuple> fvVector;
1883+ setRouteWithWarmRestart (destaddr, fvVector, m_label_routeTable, DEL_COMMAND);
1884+ SWSS_LOG_INFO (" LabelRouteTable del msg: %s" , destaddr);
19661885 return ;
19671886 }
19681887 else if (nlmsg_type != RTM_NEWROUTE)
@@ -1995,7 +1914,8 @@ void RouteSync::onLabelRouteMsg(int nlmsg_type, struct nl_object *obj)
19951914 FieldValueTuple fv (" blackhole" , " true" );
19961915 fvVector.push_back (fv);
19971916 fvVector.push_back (proto);
1998- m_label_routeTable->set (destaddr, fvVector);
1917+ setRouteWithWarmRestart (destaddr, fvVector, m_label_routeTable, SET_COMMAND);
1918+ SWSS_LOG_INFO (" LabelRouteTable set blackhole msg: %s" , destaddr);
19991919 return ;
20001920 }
20011921 case RTN_UNICAST:
@@ -2038,7 +1958,7 @@ void RouteSync::onLabelRouteMsg(int nlmsg_type, struct nl_object *obj)
20381958 }
20391959 fvVector.push_back (mpls_pop);
20401960
2041- m_label_routeTable-> set (destaddr, fvVector);
1961+ setRouteWithWarmRestart (destaddr, fvVector, m_label_routeTable, SET_COMMAND );
20421962 SWSS_LOG_INFO (" LabelRouteTable set msg: %s %s %s %s" , destaddr,
20431963 gw_list.c_str (), intf_list.c_str (), mpls_list.c_str ());
20441964}
0 commit comments