bgpd: Show more meaningful outq value in 'show ip bgp summary' output.

'outq' field in 'show ip bgp sum' displays the number of formatted packets
to a peer. Since the route announcement follows an input-buffered pattern
(i.e. adj-rib-out is a separate queue of routes per peer and packets are
formatted from the routes at the time of TCP write), the outq field doesn't
show any interesting data worth watching.

The patch is to display the adj-rib-out queue depth instead.

signed-off-by: pmohapat@cumulusnetworks.com
reviewed-by: dwalton@cumulusnetworks.com
diff --git a/bgpd/bgp_advertise.c b/bgpd/bgp_advertise.c
index ecf531f..1b17b66 100644
--- a/bgpd/bgp_advertise.c
+++ b/bgpd/bgp_advertise.c
@@ -186,10 +186,12 @@
   struct bgp_advertise *adv;
   struct bgp_advertise_attr *baa;
   struct bgp_advertise *next;
+  struct bgp_advertise_fifo *fhead;
 
   adv = adj->adv;
   baa = adv->baa;
   next = NULL;
+  fhead = (struct bgp_advertise_fifo *)&peer->sync[afi][safi]->withdraw;
 
   if (baa)
     {
@@ -201,10 +203,12 @@
 
       /* Unintern BGP advertise attribute.  */
       bgp_advertise_unintern (peer->hash[afi][safi], baa);
+
+      fhead = (struct bgp_advertise_fifo *)&peer->sync[afi][safi]->update;
     }
 
   /* Unlink myself from advertisement FIFO.  */
-  FIFO_DEL (adv);
+  BGP_ADV_FIFO_DEL (fhead, adv);
 
   /* Free memory.  */
   bgp_advertise_free (adj->adv);
@@ -264,7 +268,7 @@
   /* Add new advertisement to advertisement attribute list. */
   bgp_advertise_add (adv->baa, adv);
 
-  FIFO_ADD (&peer->sync[afi][safi]->update, &adv->fifo);
+  BGP_ADV_FIFO_ADD (&peer->sync[afi][safi]->update, &adv->fifo);
 }
 
 void
@@ -298,7 +302,7 @@
       adv->adj = adj;
 
       /* Add to synchronization entry for withdraw announcement.  */
-      FIFO_ADD (&peer->sync[afi][safi]->withdraw, &adv->fifo);
+      BGP_ADV_FIFO_ADD (&peer->sync[afi][safi]->withdraw, &adv->fifo);
 
       /* Schedule packet write. */
       BGP_WRITE_ON (peer->t_write, bgp_write, peer->fd);
@@ -391,9 +395,9 @@
       {
 	sync = XCALLOC (MTYPE_BGP_SYNCHRONISE, 
 	                sizeof (struct bgp_synchronize));
-	FIFO_INIT (&sync->update);
-	FIFO_INIT (&sync->withdraw);
-	FIFO_INIT (&sync->withdraw_low);
+	BGP_ADV_FIFO_INIT (&sync->update);
+	BGP_ADV_FIFO_INIT (&sync->withdraw);
+	BGP_ADV_FIFO_INIT (&sync->withdraw_low);
 	peer->sync[afi][safi] = sync;
 	peer->hash[afi][safi] = hash_create (baa_hash_key, baa_hash_cmp);
       }
diff --git a/bgpd/bgp_advertise.h b/bgpd/bgp_advertise.h
index 51ba626..e2857a3 100644
--- a/bgpd/bgp_advertise.h
+++ b/bgpd/bgp_advertise.h
@@ -23,6 +23,14 @@
 
 #include <lib/fifo.h>
 
+/* BGP advertise FIFO.  */
+struct bgp_advertise_fifo
+{
+  struct bgp_advertise *next;
+  struct bgp_advertise *prev;
+  u_int32_t count;
+};
+
 /* BGP advertise attribute.  */
 struct bgp_advertise_attr
 {
@@ -124,6 +132,24 @@
 #define BGP_ADJ_OUT_ADD(N,A)   BGP_INFO_ADD(N,A,adj_out)
 #define BGP_ADJ_OUT_DEL(N,A)   BGP_INFO_DEL(N,A,adj_out)
 
+#define BGP_ADV_FIFO_ADD(F, N)			\
+  do {						\
+    FIFO_ADD((F), (N));				\
+    (F)->count++;                               \
+  } while (0)
+
+#define BGP_ADV_FIFO_DEL(F, N)			\
+  do {						\
+    FIFO_DEL((N));				\
+    (F)->count--;				\
+  } while (0)
+
+#define BGP_ADV_FIFO_INIT(F)			\
+  do {						\
+    FIFO_INIT((F));				\
+    (F)->count = 0;				\
+  } while (0)
+
 /* Prototypes.  */
 extern void bgp_adj_out_set (struct bgp_node *, struct peer *, struct prefix *,
 		      struct attr *, afi_t, safi_t, struct bgp_info *);
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index 32d1ea0..cd3d9a0 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -7352,14 +7352,16 @@
 
 	  vty_out (vty, "4 ");
 
-	  vty_out (vty, "%5u %7d %7d %8d %4d %4lu ",
+	  vty_out (vty, "%5u %7d %7d %8d %4d %4d ",
 		   peer->as,
 		   peer->open_in + peer->update_in + peer->keepalive_in
 		   + peer->notify_in + peer->refresh_in + peer->dynamic_cap_in,
 		   peer->open_out + peer->update_out + peer->keepalive_out
 		   + peer->notify_out + peer->refresh_out
 		   + peer->dynamic_cap_out,
-		   0, 0, (unsigned long) peer->obuf->count);
+		   0, 0,
+		   peer->sync[afi][safi]->update.count +
+		   peer->sync[afi][safi]->withdraw.count);
 
 	  vty_out (vty, "%8s", 
 		   peer_uptime (peer->uptime, timebuf, BGP_UPTIME_LEN));
diff --git a/lib/fifo.h b/lib/fifo.h
index 6be75b7..47a1e88 100644
--- a/lib/fifo.h
+++ b/lib/fifo.h
@@ -25,6 +25,7 @@
 {
   struct fifo *next;
   struct fifo *prev;
+  u_int32_t count;
 };
 
 #define FIFO_INIT(F)                                  \