]> git.proxmox.com Git - mirror_frr.git/commitdiff
Get route counts right for show ip route summary
authorDinesh G Dutt <ddutt@cumulusnetworks.com>
Thu, 21 Apr 2016 05:27:29 +0000 (22:27 -0700)
committerDinesh G Dutt <ddutt@cumulusnetworks.com>
Thu, 21 Apr 2016 19:15:59 +0000 (12:15 -0700)
Ticket: CM-9974
Reviewed By: CCR-4531
Testing Done: Testing with both single & multiple NHs

Zebra is counting each NH as a separate route which leads to all wrong
stats. Count routes, not NHs.

zebra/zebra_vty.c

index 97a60460c6e3e02d7b83dac3833c1566ce234505..ad7447b825c62ff9824eef125b3a1ebd1cb117b8 100644 (file)
@@ -2587,65 +2587,66 @@ vty_show_ip_route_summary (struct vty *vty, struct route_table *table)
 {
   struct route_node *rn;
   struct rib *rib;
-  struct nexthop *nexthop;
 #define ZEBRA_ROUTE_IBGP  ZEBRA_ROUTE_MAX
 #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
   u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
   u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
   u_int32_t i;
+  u_int32_t is_ibgp;
 
   memset (&rib_cnt, 0, sizeof(rib_cnt));
   memset (&fib_cnt, 0, sizeof(fib_cnt));
   for (rn = route_top (table); rn; rn = route_next (rn))
     RNODE_FOREACH_RIB (rn, rib)
-      for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
-        {
-         rib_cnt[ZEBRA_ROUTE_TOTAL]++;
-         rib_cnt[rib->type]++;
-         if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
-             || nexthop_has_fib_child(nexthop))
-           {
-             fib_cnt[ZEBRA_ROUTE_TOTAL]++;
-             fib_cnt[rib->type]++;
-           }
-         if (rib->type == ZEBRA_ROUTE_BGP && 
-             CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP)) 
-           {
-             rib_cnt[ZEBRA_ROUTE_IBGP]++;
-             if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)
-                 || nexthop_has_fib_child(nexthop))
-               fib_cnt[ZEBRA_ROUTE_IBGP]++;
-           }
-       }
+      {
+        is_ibgp = (rib->type == ZEBRA_ROUTE_BGP &&
+                   CHECK_FLAG (rib->flags, ZEBRA_FLAG_IBGP));
+
+        rib_cnt[ZEBRA_ROUTE_TOTAL]++;
+        if (is_ibgp)
+          rib_cnt[ZEBRA_ROUTE_IBGP]++;
+        else
+          rib_cnt[rib->type]++;
+
+        if (CHECK_FLAG (rib->flags, ZEBRA_FLAG_SELECTED))
+          {
+            fib_cnt[ZEBRA_ROUTE_TOTAL]++;
+
+            if (is_ibgp)
+              fib_cnt[ZEBRA_ROUTE_IBGP]++;
+            else
+              fib_cnt[rib->type]++;
+          }
+      }
 
   vty_out (vty, "%-20s %-20s %s  (vrf %s)%s",
            "Route Source", "Routes", "FIB",
            ((rib_table_info_t *)table->info)->zvrf->name,
            VTY_NEWLINE);
 
-  for (i = 0; i < ZEBRA_ROUTE_MAX; i++) 
+  for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
     {
       if (rib_cnt[i] > 0)
-       {
-         if (i == ZEBRA_ROUTE_BGP)
-           {
-             vty_out (vty, "%-20s %-20d %-20d %s", "ebgp", 
-                      rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
-                      fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
-                      VTY_NEWLINE);
-             vty_out (vty, "%-20s %-20d %-20d %s", "ibgp", 
-                      rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
-                      VTY_NEWLINE);
-           }
-         else 
-           vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i), 
-                    rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
-       }
+        {
+          if (i == ZEBRA_ROUTE_BGP)
+            {
+              vty_out (vty, "%-20s %-20d %-20d %s", "ebgp",
+                       rib_cnt[ZEBRA_ROUTE_BGP] - rib_cnt[ZEBRA_ROUTE_IBGP],
+                       fib_cnt[ZEBRA_ROUTE_BGP] - fib_cnt[ZEBRA_ROUTE_IBGP],
+                       VTY_NEWLINE);
+              vty_out (vty, "%-20s %-20d %-20d %s", "ibgp",
+                       rib_cnt[ZEBRA_ROUTE_IBGP], fib_cnt[ZEBRA_ROUTE_IBGP],
+                       VTY_NEWLINE);
+            }
+          else
+            vty_out (vty, "%-20s %-20d %-20d %s", zebra_route_string(i),
+                     rib_cnt[i], fib_cnt[i], VTY_NEWLINE);
+        }
     }
 
   vty_out (vty, "------%s", VTY_NEWLINE);
-  vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL], 
-          fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);  
+  vty_out (vty, "%-20s %-20d %-20d %s", "Totals", rib_cnt[ZEBRA_ROUTE_TOTAL],
+           fib_cnt[ZEBRA_ROUTE_TOTAL], VTY_NEWLINE);
   vty_out (vty, "%s", VTY_NEWLINE);
 }