]> git.puffer.fish Git - mirror/frr.git/commitdiff
pimd: Add basic nexthop lookup cached information.
authorDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 27 Oct 2016 15:54:55 +0000 (11:54 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 22 Dec 2016 01:26:12 +0000 (20:26 -0500)
Cache the last time we looked up the nexthop for this particular
address.  Store time to usec accuracy.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
pimd/pim_cmd.c
pimd/pim_rpf.c
pimd/pim_rpf.h
pimd/pim_zebra.c

index 54750d475cb521635cb178714fb563040c6a15df..d11c2f21f4906e2a3262ea51f23964756e9869d2 100644 (file)
@@ -1853,6 +1853,7 @@ static void show_rpf_refresh_stats(struct vty *vty, time_t now, json_object *jso
     json_object_int_add(json, "rpfCacheRefreshEvents", qpim_rpf_cache_refresh_events);
     json_object_string_add(json, "rpfCacheRefreshLast", refresh_uptime);
     json_object_int_add(json, "nexthopLookups", qpim_nexthop_lookups);
+    json_object_int_add(json, "nexthopLookupsAvoided", nexthop_lookups_avoided);
   } else {
     vty_out(vty,
             "RPF Cache Refresh Delay:    %ld msecs%s"
@@ -1860,13 +1861,15 @@ static void show_rpf_refresh_stats(struct vty *vty, time_t now, json_object *jso
             "RPF Cache Refresh Requests: %lld%s"
             "RPF Cache Refresh Events:   %lld%s"
             "RPF Cache Refresh Last:     %s%s"
-            "Nexthop Lookups:            %lld%s",
+            "Nexthop Lookups:            %lld%s"
+           "Nexthop Lookups Avoided:    %lld%s",
             qpim_rpf_cache_refresh_delay_msec, VTY_NEWLINE,
             pim_time_timer_remain_msec(qpim_rpf_cache_refresher), VTY_NEWLINE,
             (long long)qpim_rpf_cache_refresh_requests, VTY_NEWLINE,
             (long long)qpim_rpf_cache_refresh_events, VTY_NEWLINE,
             refresh_uptime, VTY_NEWLINE,
-            (long long) qpim_nexthop_lookups, VTY_NEWLINE);
+            (long long) qpim_nexthop_lookups, VTY_NEWLINE,
+           (long long)nexthop_lookups_avoided, VTY_NEWLINE);
   }
 }
 
index d32d65fd4c2d94f33d588c9d6d3eca914937fac5..2b16529627b7d615d88fc8577e612f66e452cffd 100644 (file)
 #include "pim_iface.h"
 #include "pim_zlookup.h"
 #include "pim_ifchannel.h"
+#include "pim_time.h"
+
+static long long last_route_change_time = -1;
+long long nexthop_lookups_avoided = 0;
 
 static struct in_addr pim_rpf_find_rpf_addr(struct pim_upstream *up);
 
+void
+pim_rpf_set_refresh_time (void)
+{
+  last_route_change_time = pim_time_monotonic_usec();
+  if (PIM_DEBUG_TRACE)
+    zlog_debug ("%s: New last route change time: %lld",
+               __PRETTY_FUNCTION__, last_route_change_time);
+}
+
 int pim_nexthop_lookup(struct pim_nexthop *nexthop, struct in_addr addr, int neighbor_needed)
 {
   struct pim_zlookup_nexthop nexthop_tab[MULTIPATH_NUM];
@@ -46,6 +59,36 @@ int pim_nexthop_lookup(struct pim_nexthop *nexthop, struct in_addr addr, int nei
   int found = 0;
   int i = 0;
 
+  if ((nexthop->last_lookup.s_addr == addr.s_addr) &&
+      (nexthop->last_lookup_time > last_route_change_time))
+    {
+      if (PIM_DEBUG_TRACE)
+       {
+         char addr_str[INET_ADDRSTRLEN];
+         pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+         zlog_debug ("%s: Using last lookup for %s at %lld, %lld",
+                     __PRETTY_FUNCTION__,
+                     addr_str,
+                     nexthop->last_lookup_time,
+                     last_route_change_time);
+       }
+      nexthop_lookups_avoided++;
+      return 0;
+    }
+  else
+    {
+      if (PIM_DEBUG_TRACE)
+       {
+         char addr_str[INET_ADDRSTRLEN];
+         pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str));
+         zlog_debug ("%s: Looking up: %s, last lookup time: %lld, %lld",
+                     __PRETTY_FUNCTION__,
+                     addr_str,
+                     nexthop->last_lookup_time,
+                     last_route_change_time);
+       }
+    }
+
   memset (nexthop_tab, 0, sizeof (struct pim_zlookup_nexthop) * MULTIPATH_NUM);
   num_ifindex = zclient_lookup_nexthop(nexthop_tab,
                                       MULTIPATH_NUM,
@@ -124,11 +167,16 @@ int pim_nexthop_lookup(struct pim_nexthop *nexthop, struct in_addr addr, int nei
       nexthop->mrib_nexthop_addr        = nexthop_tab[0].nexthop_addr;
       nexthop->mrib_metric_preference   = nexthop_tab[0].protocol_distance;
       nexthop->mrib_route_metric        = nexthop_tab[0].route_metric;
-
+      nexthop->last_lookup              = addr;
+      nexthop->last_lookup_time         = pim_time_monotonic_usec();
       return 0;
     }
   else
-    return -1;
+    {
+      nexthop->last_lookup              = addr;
+      nexthop->last_lookup_time         = pim_time_monotonic_usec();
+      return -1;
+    }
 }
 
 static int nexthop_mismatch(const struct pim_nexthop *nh1,
index b93c934116c2c5e1400de7623e8cf4d20db7f1df..b267a9b6fab304d9bb541b4e6c7fe5cbb31be832 100644 (file)
@@ -40,6 +40,8 @@
     units applicable to the unicast routing protocol used.
 */
 struct pim_nexthop {
+  struct in_addr    last_lookup;
+  long long         last_lookup_time;
   struct interface *interface;              /* RPF_interface(S) */
   struct prefix     mrib_nexthop_addr;      /* MRIB.next_hop(S) */
   uint32_t          mrib_metric_preference; /* MRIB.pref(S) */
@@ -59,9 +61,13 @@ enum pim_rpf_result {
 
 struct pim_upstream;
 
+extern long long nexthop_lookups_avoided;
+
 int pim_nexthop_lookup(struct pim_nexthop *nexthop, struct in_addr addr, int neighbor_needed);
 enum pim_rpf_result pim_rpf_update(struct pim_upstream *up, struct in_addr *old_rpf_addr);
 
 int pim_rpf_addr_is_inaddr_none (struct pim_rpf *rpf);
 int pim_rpf_addr_is_inaddr_any (struct pim_rpf *rpf);
+
+void pim_rpf_set_refresh_time (void);
 #endif /* PIM_RPF_H */
index eac618b4389f7afb29411dcec68ac30e59824471..e2a71c6e7ff8f2e7088b492a3cbcc2443823dca2 100644 (file)
@@ -550,6 +550,8 @@ static void sched_rpf_cache_refresh()
 {
   ++qpim_rpf_cache_refresh_requests;
 
+  pim_rpf_set_refresh_time ();
+
   if (qpim_rpf_cache_refresher) {
     /* Refresh timer is already running */
     return;