12
12
#include " macaddress.h"
13
13
#include < string.h>
14
14
#include < arpa/inet.h>
15
+ #include < chrono>
15
16
16
17
using namespace std ;
17
18
using namespace swss ;
@@ -41,6 +42,13 @@ using namespace swss;
41
42
42
43
#define ETHER_ADDR_STRLEN (3 *ETH_ALEN)
43
44
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
+
44
52
RouteSync::RouteSync (RedisPipeline *pipeline) :
45
53
m_routeTable(pipeline, APP_ROUTE_TABLE_NAME, true ),
46
54
m_vnet_routeTable(pipeline, APP_VNET_RT_TABLE_NAME, true ),
@@ -51,6 +59,19 @@ RouteSync::RouteSync(RedisPipeline *pipeline) :
51
59
m_nl_sock = nl_socket_alloc ();
52
60
nl_connect (m_nl_sock, NETLINK_ROUTE);
53
61
rtnl_link_alloc_cache (m_nl_sock, AF_UNSPEC, &m_link_cache);
62
+
63
+ /* TODO: read from configDb */
64
+ RED_THRESHOLD = 500 ;
65
+ ORANGE_THREASHOLD = 100 ;
66
+ currentRedroutes = 0 ;
67
+ currentOrangeroutes = 0 ;
68
+ /* update the time at start */
69
+ lastRedUpdated = getTimeEpochMsec ();
70
+ lastOrangeUpdated = lastRedUpdated;
71
+ /* BGP_ROUTE_UPDATES Table */
72
+ DBConnector stateDb (" STATE_DB" , 0 );
73
+ Table bgpChurnTable (&stateDb, " BGP_ROUTE_UPDATES" );
74
+ this ->bgpChurnTable = bgpChurnTable;
54
75
}
55
76
56
77
char *RouteSync::prefixMac2Str (char *mac, char *buf, int size)
@@ -723,6 +744,10 @@ void RouteSync::onRouteMsg(int nlmsg_type, struct nl_object *obj, char *vrf)
723
744
fvVector.push_back (nh);
724
745
fvVector.push_back (idx);
725
746
747
+ SWSS_LOG_NOTICE (" PC: fpmsyncd debug image" );
748
+
749
+ this ->updateRouteFrequencyStats ();
750
+
726
751
if (!warmRestartInProgress)
727
752
{
728
753
m_routeTable.set (destipprefix, fvVector);
@@ -962,3 +987,25 @@ string RouteSync::getNextHopIf(struct rtnl_route *route_obj)
962
987
963
988
return result;
964
989
}
990
+
991
+ void RouteSync::updateRouteFrequencyStats () {
992
+
993
+ ++currentRedroutes;
994
+ ++currentOrangeroutes;
995
+
996
+ if (currentRedroutes >= RED_THRESHOLD) {
997
+ uint64_t curTime = getTimeEpochMsec ();
998
+ SWSS_LOG_NOTICE (" Red TH: %d routes are updated in %ld msecs\n " , currentRedroutes, curTime-lastRedUpdated);
999
+ bgpChurnTable.hset (" ROUTE_CHURN_FREQUENCY" , " RED_THRESHOLD" , std::to_string ((currentRedroutes*1000 )/(curTime-lastRedUpdated)));
1000
+ lastRedUpdated = curTime;
1001
+ currentRedroutes = 0 ;
1002
+ }
1003
+
1004
+ if (currentOrangeroutes >= ORANGE_THREASHOLD) {
1005
+ uint64_t curTime = getTimeEpochMsec ();
1006
+ SWSS_LOG_NOTICE (" Orange TH: %d routes are updated in %ld msecs\n " , currentOrangeroutes, curTime-lastOrangeUpdated);
1007
+ bgpChurnTable.hset (" ROUTE_CHURN_FREQUENCY" , " ORANGE_THRESHOLD" , std::to_string ((currentOrangeroutes*1000 )/(curTime-lastOrangeUpdated)));
1008
+ lastOrangeUpdated = curTime;
1009
+ currentOrangeroutes = 0 ;
1010
+ }
1011
+ }
0 commit comments