Skip to content

Commit 373aa10

Browse files
author
Praveen Chaudhary
committed
[fpmsyncd]: Route update frequency stats.
Changes: read threshold from config. write frequency of route update per sec in state db. Signed-off-by: Praveen Chaudhary <[email protected]> RB= G=lnos-reviewers R=pchaudhary,pmao,samaity,zxu A=
1 parent 687fc9c commit 373aa10

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

fpmsyncd/routesync.cpp

+88
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "macaddress.h"
1313
#include <string.h>
1414
#include <arpa/inet.h>
15+
#include <chrono>
1516

1617
using namespace std;
1718
using namespace swss;
@@ -41,6 +42,13 @@ using namespace swss;
4142

4243
#define ETHER_ADDR_STRLEN (3*ETH_ALEN)
4344

45+
46+
/* helper function for time */
47+
uint64_t getTimeEpochMsec() {
48+
using namespace std::chrono;
49+
return duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
50+
}
51+
4452
RouteSync::RouteSync(RedisPipeline *pipeline) :
4553
m_routeTable(pipeline, APP_ROUTE_TABLE_NAME, true),
4654
m_vnet_routeTable(pipeline, APP_VNET_RT_TABLE_NAME, true),
@@ -51,6 +59,34 @@ RouteSync::RouteSync(RedisPipeline *pipeline) :
5159
m_nl_sock = nl_socket_alloc();
5260
nl_connect(m_nl_sock, NETLINK_ROUTE);
5361
rtnl_link_alloc_cache(m_nl_sock, AF_UNSPEC, &m_link_cache);
62+
63+
/* Initailize with defaults*/
64+
RED_THRESHOLD = 500;
65+
ORANGE_THRESHOLD = 100;
66+
countRedroute = 0;
67+
countOrangeroute = 0;
68+
69+
/* update the time at start */
70+
lastRedUpdated = getTimeEpochMsec();
71+
lastOrangeUpdated = lastRedUpdated;
72+
73+
/* READ THESHOLD CONFIG from BGP_ROUTE_THRESHOLD Table*/
74+
this->cfgDb = new DBConnector("CONFIG_DB", 0);
75+
this->cfgRouteThTable = new Table(this->cfgDb, "BGP_ROUTE_THRESHOLD");
76+
77+
/* WRITE STATS in BGP_ROUTE_UPDATE_FREQUENCY Table STATE DB*/
78+
this->stateDb = new DBConnector("STATE_DB", 0);
79+
this->bgpRouteFreqTable = new Table(this->stateDb, "BGP_ROUTE_UPDATE_FREQUENCY");
80+
81+
/* Remove later */
82+
SWSS_LOG_NOTICE("PC: fpmsyncd debug image");
83+
}
84+
85+
RouteSync::~RouteSync() {
86+
delete cfgRouteThTable;
87+
delete bgpRouteFreqTable;
88+
delete cfgDb;
89+
delete stateDb;
5490
}
5591

5692
char *RouteSync::prefixMac2Str(char *mac, char *buf, int size)
@@ -443,6 +479,8 @@ void RouteSync::onEvpnRouteMsg(struct nlmsghdr *h, int len)
443479

444480
if (nlmsg_type == RTM_DELROUTE)
445481
{
482+
/* update route change frequency */
483+
updateRouteFrequencyStats();
446484
if (!warmRestartInProgress)
447485
{
448486
m_routeTable.del(destipprefix);
@@ -519,6 +557,8 @@ void RouteSync::onEvpnRouteMsg(struct nlmsghdr *h, int len)
519557
fvVector.push_back(intf);
520558
fvVector.push_back(vni);
521559
fvVector.push_back(mac);
560+
/* update route change frequency */
561+
updateRouteFrequencyStats();
522562

523563
if (!warmRestartInProgress)
524564
{
@@ -643,6 +683,8 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
643683

644684
if (nlmsg_type == RTM_DELROUTE)
645685
{
686+
/* update route change frequency */
687+
updateRouteFrequencyStats();
646688
if (!warmRestartInProgress)
647689
{
648690
m_routeTable.del(destipprefix);
@@ -723,6 +765,9 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
723765
fvVector.push_back(nh);
724766
fvVector.push_back(idx);
725767

768+
/* update route change frequency */
769+
updateRouteFrequencyStats();
770+
726771
if (!warmRestartInProgress)
727772
{
728773
m_routeTable.set(destipprefix, fvVector);
@@ -775,6 +820,9 @@ void RouteSync::onVnetRouteMsg(int nlmsg_type, struct nl_object *obj, string vne
775820

776821
if (nlmsg_type == RTM_DELROUTE)
777822
{
823+
/* update route change frequency */
824+
updateRouteFrequencyStats();
825+
778826
/* Duplicated delete as we do not know if it is a VXLAN tunnel route*/
779827
m_vnet_routeTable.del(vnet_dip);
780828
m_vnet_tunnelTable.del(vnet_dip);
@@ -813,6 +861,9 @@ void RouteSync::onVnetRouteMsg(int nlmsg_type, struct nl_object *obj, string vne
813861
return;
814862
}
815863

864+
/* update route change frequency */
865+
updateRouteFrequencyStats();
866+
816867
/* Get nexthop lists */
817868
string nexthops = getNextHopGw(route_obj);
818869
string ifnames = getNextHopIf(route_obj);
@@ -962,3 +1013,40 @@ string RouteSync::getNextHopIf(struct rtnl_route *route_obj)
9621013

9631014
return result;
9641015
}
1016+
1017+
void RouteSync::updateRouteFrequencyStats() {
1018+
1019+
++countRedroute;
1020+
++countOrangeroute;
1021+
1022+
/* Read Config DB for Threshold Value */
1023+
string value;
1024+
string CONFIG_KEY = "ROUTE_UPDATE_THRESHOLD";
1025+
bool ret = cfgRouteThTable->hget(CONFIG_KEY, "RED_THRESHOLD", value);
1026+
if (ret)
1027+
RED_THRESHOLD = (u_int16_t)std::stoi(value);
1028+
ret = cfgRouteThTable->hget(CONFIG_KEY, "ORANGE_THRESHOLD", value);
1029+
if (ret)
1030+
ORANGE_THRESHOLD = (u_int16_t)std::stoi(value);
1031+
1032+
1033+
string STATE_DB_KEY = "ROUTE_UPDATE_FREQUENCY";
1034+
if (countRedroute >= RED_THRESHOLD) {
1035+
uint64_t curTime = getTimeEpochMsec();
1036+
double timeDiff = (double)(curTime-lastRedUpdated)/1000.00;
1037+
/*TODO: change log level*/
1038+
SWSS_LOG_NOTICE("Red TH: %d routes are updated in %.3f secs\n", countRedroute, timeDiff);
1039+
bgpRouteFreqTable->hset(STATE_DB_KEY, "RED_THRESHOLD", std::to_string(countRedroute/timeDiff));
1040+
lastRedUpdated = curTime;
1041+
countRedroute = 0;
1042+
}
1043+
1044+
if (countOrangeroute >= ORANGE_THRESHOLD) {
1045+
uint64_t curTime = getTimeEpochMsec();
1046+
double timeDiff = (double)(curTime-lastOrangeUpdated)/1000.00;
1047+
SWSS_LOG_NOTICE("Orange TH: %d routes are updated in %.3f secs\n", countOrangeroute, timeDiff);
1048+
bgpRouteFreqTable->hset(STATE_DB_KEY, "ORANGE_THRESHOLD", std::to_string(countOrangeroute/timeDiff));
1049+
lastOrangeUpdated = curTime;
1050+
countOrangeroute = 0;
1051+
}
1052+
}

fpmsyncd/routesync.h

+24
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class RouteSync : public NetMsg
2222
enum { MAX_ADDR_SIZE = 64 };
2323

2424
RouteSync(RedisPipeline *pipeline);
25+
virtual ~RouteSync();
2526

2627
virtual void onMsg(int nlmsg_type, struct nl_object *obj);
2728

@@ -75,6 +76,29 @@ class RouteSync : public NetMsg
7576

7677
/* Get next hop interfaces */
7778
string getNextHopIf(struct rtnl_route *route_obj);
79+
80+
void updateRouteFrequencyStats();
81+
82+
/* User Configured Threshold */
83+
uint16_t RED_THRESHOLD;
84+
uint16_t ORANGE_THRESHOLD;
85+
86+
/* Current route updates count */
87+
uint16_t countRedroute;
88+
uint16_t countOrangeroute;
89+
90+
/* timestamp for last frequency update */
91+
uint64_t lastRedUpdated;
92+
uint64_t lastOrangeUpdated;
93+
94+
/* Read Config from below Table in CONFIG_DB*/
95+
DBConnector *cfgDb;
96+
Table *cfgRouteThTable;
97+
98+
/* Write Frequency updates to below Table in STATE_DB*/
99+
DBConnector *stateDb;
100+
Table *bgpRouteFreqTable;
101+
78102
};
79103

80104
}

0 commit comments

Comments
 (0)