[PATCH] Nest: "Last route change" timestamp for routing tables

Tom Petty tom.petty at bbc.co.uk
Mon Apr 29 12:54:34 CEST 2019


I¹ve written a patch which adds a ³last route change² timestamp to the
routing table statistics. This diff is against the Œmaarten¹ branch, where
the code adding the ³show table statistics² command is currently located.

diff --git a/nest/route.h b/nest/route.h
index c7c44ecc..8472b432 100644
--- a/nest/route.h
+++ b/nest/route.h
@@ -166,6 +166,7 @@ typedef struct rtable {
   uint route_count;			/* Number of routes in the table */
   uint route_updates;			/* Number of accepted route updates */
   uint route_withdraws;			/* Number of accepted route withdraws */
+  btime last_route_change;             /* Time of last route change */
   struct hostcache *hostcache;
   struct rtable_config *config;		/* Configuration of this table */
   struct config *deleted;		/* Table doesn't exist in current
configuration,
diff --git a/nest/rt-table.c b/nest/rt-table.c
index efc1f1d7..116e8756 100644
--- a/nest/rt-table.c
+++ b/nest/rt-table.c
@@ -1143,9 +1143,9 @@ rte_recalculate(struct channel *c, net *net, rte
*new, struct rte_src *src)
  skip_stats1:
 
   if (new_ok)
-    table->route_count++;
+    { table->route_count++; table->last_route_change = current_time(); }
   if (old_ok)
-    table->route_count--;
+    { table->route_count--; table->last_route_change = current_time(); }
 
   if (new)
     rte_is_filtered(new) ? stats->filt_routes++ : stats->imp_routes++;
@@ -1668,6 +1668,7 @@ rt_setup(pool *p, rtable *t, struct rtable_config
*cf)
   t->rt_event->hook = rt_event;
   t->rt_event->data = t;
   t->gc_time = current_time();
+  t->last_route_change = current_time();
 }
 
 /**
@@ -2299,7 +2300,7 @@ rte_update_in(struct channel *c, const net_addr *n,
rte *new, struct rte_src *sr
       *pos = old->next;
       rte_free_quick(old);
       tab->route_count--;
-
+      tab->last_route_change = current_time();
       break;
     }
 
@@ -2333,6 +2334,7 @@ rte_update_in(struct channel *c, const net_addr *n,
rte *new, struct rte_src *sr
   e->next = *pos;
   *pos = e;
   tab->route_count++;
+  tab->last_route_change = current_time();
   return 1;
 
 drop_update:
@@ -2406,6 +2408,7 @@ rt_prune_sync(rtable *t, int all)
 	*ee = e->next;
 	rte_free_quick(e);
 	t->route_count--;
+	t->last_route_change = current_time();
       }
       else
 	ee = &e->next;
@@ -2711,6 +2714,9 @@ rt_get_hostentry(rtable *tab, ip_addr a, ip_addr ll,
rtable *dep)
 static void
 rt_show_table_stats(rtable *tab)
 {
+  byte tm[TM_DATETIME_BUFFER_SIZE];
+  tm_format_time(tm, &config->tf_route, tab->last_route_change);
+
   cli_msg(-1026, "%s:", tab->name);
   cli_msg(-1026, "Table type:\t\t%s", net_label[tab->addr_type]);
   cli_msg(-1026, "Hash table size:\t%u", tab->fib.hash_size);
@@ -2718,6 +2724,7 @@ rt_show_table_stats(rtable *tab)
   cli_msg(-1026, "Total route count:\t%u", tab->route_count);
   cli_msg(-1026, "Route updates:\t\t%u", tab->route_updates);
   cli_msg(-1026, "Route withdraws:\t%u", tab->route_withdraws);
+  cli_msg(-1026, "Last route update:\t%s", tm);
 
   cli_msg(-1026, "");
   cli_msg(-1026, "%-16s %10s %10s %10s %10s", "Protocol", "Routes",
"Preferred", "Updates", "Withdraws");


Thanks, 

Tom P




More information about the Bird-users mailing list