Support for 'show bgp summary'-like command

Alexander Shikoff minotaur at crete.org.ua
Tue Sep 21 20:17:06 CEST 2010


Hello,

When making a looking glass for bird I met a lack of summary-like
command for bgp.

Attached patch adds 'show bgp summary' command to CLI of birdc. It produces
output that looks like Juniper/Cisco-style output.
Example:

BIRD 1.2.4 ready.
bird> show bgp summary 
Peer                    AS Last state change   Prefixes rcvd/best   State/Last error
193.25.x.x           13249 21:11               0/0                  Passive       
193.25.x.x           20850 21:11               0/0                  Passive       
193.25.x.x           21011 21:11               0/0                  Passive       
193.25.x.x           25372 21:12               3/3                  Established   
193.25.x.x           28097 21:11               0/0                  Passive       
193.25.x.x           35320 21:11               0/0                  Passive       
193.25.x.x           42546 21:11               1/1                  Passive       Socket: Connection closed

My integration of command in nest/config.Y is quite dumb but it works.
If such command is essential for the users then a bird team may
integrate it in more accurate and right way.

Patch is applied to version 1.2.4. It has been tested on FreeBSD 7.2.

-- 
MINO-RIPE
-------------- next part --------------
diff -u --recursive bird-1.2.4-orig/nest/config.Y bird-1.2.4/nest/config.Y
--- bird-1.2.4-orig/nest/config.Y	2010-08-03 18:44:51.000000000 +0300
+++ bird-1.2.4/nest/config.Y	2010-09-21 19:11:30.000000000 +0300
@@ -426,6 +426,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.2.4-orig/nest/proto.c bird-1.2.4/nest/proto.c
--- bird-1.2.4-orig/nest/proto.c	2010-08-03 18:44:51.000000000 +0300
+++ bird-1.2.4/nest/proto.c	2010-09-21 20:54:20.000000000 +0300
@@ -897,6 +897,32 @@
 }
 
 void
+proto_cmd_show_summary(char *name)
+{
+  int cnt = 0;
+  node *nn;
+  struct bgp_proto *bp;
+
+  cli_msg(-1000, "%-15s %10s %-19s %-20s %s", "Peer", "AS", "Last state change", "Prefixes rcvd/best", "State/Last error");
+  WALK_LIST(nn, proto_list)
+    {
+      struct proto *p = SKIP_BACK(struct proto, glob_node, nn);
+
+	if (patmatch(name, p->proto->name))
+	  {
+	    p->proto->show_proto_summary(p);
+	  }
+    }
+
+/*  if (!cnt)
+    cli_msg(8003, "No protocols match");
+  else
+    cli_msg(0, "");*/
+
+  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.2.4-orig/nest/protocol.h bird-1.2.4/nest/protocol.h
--- bird-1.2.4-orig/nest/protocol.h	2010-08-03 18:44:51.000000000 +0300
+++ bird-1.2.4/nest/protocol.h	2010-09-21 20:33:04.000000000 +0300
@@ -52,6 +52,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);
@@ -214,6 +215,8 @@
 void proto_cmd_mrtdump(struct proto *, unsigned int, int);
 
 void proto_apply_cmd(struct proto_spec ps, void (* cmd)(struct proto *, unsigned int, int), int restricted, unsigned int arg);
+void proto_cmd_show_summary(char *);
+
 struct proto *proto_get_named(struct symbol *, struct protocol *);
 
 #define CMD_RELOAD	0
diff -u --recursive bird-1.2.4-orig/proto/bgp/bgp.c bird-1.2.4/proto/bgp/bgp.c
--- bird-1.2.4-orig/proto/bgp/bgp.c	2010-08-03 18:44:51.000000000 +0300
+++ bird-1.2.4/proto/bgp/bgp.c	2010-09-21 21:02:32.000000000 +0300
@@ -1053,6 +1053,29 @@
     }
 }
 
+static void
+bgp_show_proto_summary(struct proto *P)
+{
+  struct bgp_proto *p = (struct bgp_proto *) P;
+  struct bgp_conn *c = p->conn;
+  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(-1000, "%-15I %10u %-19s %-20s %s", 
+		p->cf->remote_ip, 
+		p->remote_as, 
+		tbuf, 
+		rs,
+		ps);
+}
+
 static int
 bgp_reconfigure(struct proto *P, struct proto_config *C)
 {
@@ -1085,5 +1108,7 @@
   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