[PATCH] 'show bgp summary' command

Alexander Shikoff minotaur at crete.org.ua
Thu Nov 17 19:33:51 CET 2011


Hello,

patch adds 'show bgp summary' command in bird 1.3.4.
We're running bird in production environment (an IXP), and the such command
makes diagnostic output more usual and simplifies development of looking 
glasses (we do not need to parse 'show protocols all' output).

-- 
MINO-RIPE
-------------- next part --------------
diff -u --recursive bird-1.3.4.o/nest/config.Y bird-1.3.4/nest/config.Y
--- bird-1.3.4.o/nest/config.Y	2011-11-17 20:21:40.000000000 +0200
+++ bird-1.3.4/nest/config.Y	2011-11-17 20:20:29.000000000 +0200
@@ -427,6 +427,10 @@
 CF_CLI(SHOW SYMBOLS, optsym, [<symbol>], [[Show all known symbolic names]])
 { cmd_show_symbols($3); } ;
 
+CF_CLI_HELP(SHOW BGP, ..., [[Show BGP information]])
+CF_CLI(SHOW BGP SUMMARY,,, [[Show BGP summary]])
+{ proto_cmd_show_summary("BGP"); } ;
+
 CF_CLI_HELP(DUMP, ..., [[Dump debugging information]])
 CF_CLI(DUMP RESOURCES,,, [[Dump all allocated resource]])
 { rdump(&root_pool); cli_msg(0, ""); } ;
diff -u --recursive bird-1.3.4.o/nest/proto.c bird-1.3.4/nest/proto.c
--- bird-1.3.4.o/nest/proto.c	2011-11-17 20:21:40.000000000 +0200
+++ bird-1.3.4/nest/proto.c	2011-11-17 20:20:45.000000000 +0200
@@ -910,6 +910,22 @@
 }
 
 void
+proto_cmd_show_summary(char *name)
+{
+  int cnt = 0;
+  node *n;
+
+  cli_msg(-2002, "Peer\n%12s %-19s %-20s %s", "AS", "Last state change", "Prefixes rcvd/best", "State/Last error" );
+  WALK_LIST(n, proto_list)
+    {
+      struct proto *p = SKIP_BACK(struct proto, glob_node, n);
+      if (patmatch(name, p->proto->name))
+        p->proto->show_proto_summary(p);
+    }
+  cli_msg(0, "");
+}
+
+void
 proto_cmd_disable(struct proto *p, unsigned int arg UNUSED, int cnt UNUSED)
 {
   if (p->disabled)
diff -u --recursive bird-1.3.4.o/nest/protocol.h bird-1.3.4/nest/protocol.h
--- bird-1.3.4.o/nest/protocol.h	2011-11-17 20:21:40.000000000 +0200
+++ bird-1.3.4/nest/protocol.h	2011-11-17 20:20:39.000000000 +0200
@@ -53,6 +53,7 @@
   void (*get_route_info)(struct rte *, byte *buf, struct ea_list *attrs); /* Get route information (for `show route' command) */
   int (*get_attr)(struct eattr *, byte *buf, int buflen);	/* ASCIIfy dynamic attribute (returns GA_*) */
   void (*show_proto_info)(struct proto *);	/* Show protocol info (for `show protocols all' command) */
+  void (*show_proto_summary)(struct proto *);   /* Show protocol one-line summary (for show bgp|ospf -related commands) */
 };
 
 void protos_build(void);
@@ -207,6 +208,7 @@
 void proto_request_feeding(struct proto *p);
 
 void proto_cmd_show(struct proto *, unsigned int, int);
+void proto_cmd_show_summary(char *);
 void proto_cmd_disable(struct proto *, unsigned int, int);
 void proto_cmd_enable(struct proto *, unsigned int, int);
 void proto_cmd_restart(struct proto *, unsigned int, int);
diff -u --recursive bird-1.3.4.o/proto/bgp/bgp.c bird-1.3.4/proto/bgp/bgp.c
--- bird-1.3.4.o/proto/bgp/bgp.c	2011-11-17 20:21:40.000000000 +0200
+++ bird-1.3.4/proto/bgp/bgp.c	2011-11-17 20:21:07.000000000 +0200
@@ -1124,6 +1124,28 @@
     }
 }
 
+static void
+bgp_show_proto_summary(struct proto *P)
+{
+  struct bgp_proto *p = (struct bgp_proto *) P;
+  char rs[20];
+  char ps[256];
+  byte tbuf[TM_DATETIME_BUFFER_SIZE];
+  struct proto_stats *s = &P->stats;
+
+  tm_format_datetime(tbuf, &config->tf_proto, P->last_state_change);
+
+  bsnprintf(rs, sizeof(rs), "%u/%u", s->imp_routes, s->pref_routes);
+  P->proto->get_status(P, ps);
+
+  cli_msg(-1006, "%I\n%12u %-19s %-20s %s",
+               p->cf->remote_ip,
+               p->remote_as,
+               tbuf,
+               rs,
+               ps);
+}
+
 static int
 bgp_reconfigure(struct proto *P, struct proto_config *C)
 {
@@ -1158,5 +1180,6 @@
   get_status:		bgp_get_status,
   get_attr:		bgp_get_attr,
   get_route_info:	bgp_get_route_info,
-  show_proto_info:	bgp_show_proto_info
+  show_proto_info:	bgp_show_proto_info,
+  show_proto_summary:	bgp_show_proto_summary
 };


More information about the Bird-users mailing list