BIRD-1.3.8 - show bgp summary command (rcvd/best/export)

Roman Skopenko te at uatel.net.ua
Sat Dec 1 20:58:16 CET 2012


hi

I improved the patch for bgp summary from this maillist to show export prefixes.
So, now you can see full BGP peers statistics (may be useful for 0dm1ns and looking glass).

example outputs:

BIRD 1.3.8 ready.
bird> show bgp summary
Peer                    AS Last state change   Prfx rcvd/best/export  State
1.1.1.1               1212 2012-11-20 05:00:44 428680/420360/14       Established
2.2.2.2               1010 2012-11-20 05:00:44 54560/54086/14         Established
3.3.3.3              50001 2012-11-20 05:00:44 1/1/1                  Established
4.4.4.4              40001 2012-11-20 05:00:49 3/3/423843             Established
5.5.5.5              33333 2012-11-20 05:00:43 1/1/1                  Established
6.6.6.6              44444 2012-11-20 05:04:51 6/6/418044             Established
7.7.7.7               8764 2012-11-20 05:00:44 2/2/1                  Established
9.9.9.9              11111 2012-11-20 05:00:44 1/1/1                  Established

bird> s b s Uplink1
Peer                    AS Last state change   Prfx rcvd/best/export  State
1.1.1.1               1212 2012-11-20 05:00:44 428680/420360/14       Established

-- 
Best wishes
-------------- next part --------------
diff -u proto/bgp/bgp.c.orig proto/bgp/bgp.c
--- proto/bgp/bgp.c.orig	2012-01-10 14:42:47.000000000 +0200
+++ proto/bgp/bgp.c	2012-02-28 12:12:35.000000000 +0200
@@ -76,7 +76,7 @@
 static void bgp_connect(struct bgp_proto *p);
 static void bgp_active(struct bgp_proto *p);
 static sock *bgp_setup_listen_sk(ip_addr addr, unsigned port, u32 flags);
-
+static void bgp_sh_proto_summary(struct proto *p);
 
 /**
  * bgp_open - open a BGP instance
@@ -1174,6 +1174,86 @@
     }
 }
 
+void 
+bgp_sh_summary(struct symbol *sym)
+{
+  struct proto_config *pc, *q;
+  struct proto *p;
+
+  pc = NULL;
+  if (sym) 
+    {
+      if (sym->class != SYM_PROTO)
+        cf_error("%s: Not a protocol", sym->name);
+      pc = (struct proto_config *)sym->def;
+      if ( pc->protocol != &proto_bgp ) 
+        cf_error("%s: Not a BGP protocol", sym->name);
+
+#ifdef IPV6
+      cli_msg(-2002, "Peer\n%12s %-19s %-22s %s", "AS", "Last state change", "Prfx rcvd/best/export", "State" );
+#else
+      cli_msg(-2002, "%-15s %10s %-19s %-22s %s", "Peer", "AS", "Last state change", "Prfx rcvd/best/export", "State" );
+#endif
+      bgp_sh_proto_summary(pc->proto);
+    }
+  else
+    {
+      p = NULL;
+      WALK_LIST(q, config->protos)
+        {
+          if (q->protocol == &proto_bgp && q->proto)
+       	    {
+              if (p == NULL)
+                {
+#ifdef IPV6
+                  cli_msg(-2002, "Peer\n%12s %-19s %-22s %s", "AS", "Last state change", "Prfx rcvd/best/export", "State" );
+#else
+                  cli_msg(-2002, "%-15s %10s %-19s %-22s %s", "Peer", "AS", "Last state change", "Prfx rcvd/best/export", "State" );
+#endif
+                }
+              p = q->proto;
+              bgp_sh_proto_summary(p);
+            }
+        }
+
+      if (p == NULL)
+        cli_msg(-1006, "No protocols match");
+    }
+  cli_msg(0, "");
+}
+
+static void 
+bgp_sh_proto_summary(struct proto *p) 
+{
+  struct bgp_proto *bp;
+  byte tbuf[TM_DATETIME_BUFFER_SIZE];
+  char rs[22];
+  char ps[256];
+
+  /* Get protocol data */
+  tm_format_datetime(tbuf, &config->tf_proto, p->last_state_change);
+
+  struct proto_stats *s = &p->stats;
+  bsnprintf(rs, sizeof(rs), "%u/%u/%u", s->imp_routes, s->pref_routes, s->exp_routes);
+
+  p->proto->get_status(p, ps);
+
+  /* Get BGP protocol from protocol */
+  bp = (struct bgp_proto *) p;
+
+  /* Display summary */
+#ifdef IPV6
+  cli_msg(-1006, "%I\n%12u %-19s %-22s %s",
+#else
+  cli_msg(-1006, "%-15I %10u %-19s %-22s %s",
+#endif
+		bp->cf->remote_ip,
+		bp->remote_as,
+		tbuf,
+		rs,
+		ps); 
+}
+
 struct protocol proto_bgp = {
   name:			"BGP",
   template:		"bgp%d",
diff -u proto/bgp/bgp.h.orig proto/bgp/bgp.h
--- proto/bgp/bgp.h.orig	2012-01-10 14:42:47.000000000 +0200
+++ proto/bgp/bgp.h	2012-02-28 12:12:35.000000000 +0200
@@ -313,4 +313,6 @@
 #define BGP_AF BGP_AF_IPV4
 #endif
 
+void bgp_sh_summary(struct symbol *sym);
+
 #endif
diff -u proto/bgp/config.Y.orig proto/bgp/config.Y
--- proto/bgp/config.Y.orig	2012-01-10 14:42:47.000000000 +0200
+++ proto/bgp/config.Y	2012-02-28 12:18:37.000000000 +0200
@@ -133,6 +133,11 @@
 
 CF_ENUM(T_ENUM_BGP_ORIGIN, ORIGIN_, IGP, EGP, INCOMPLETE)
 
+CF_CLI_HELP(SHOW BGP, , [[Show BGP protocol information]])
+
+CF_CLI(SHOW BGP SUMMARY, optsym, [<name>], [[Show BGP peers summary]])
+{ bgp_sh_summary($4); }; 
+
 CF_CODE
 
 CF_END


More information about the Bird-users mailing list