Re: add number of prefixed received to bgpctl -j sh

2021-12-12 Thread Denis Fondras
Le Sun, Dec 12, 2021 at 04:05:39PM +0100, Claudio Jeker a écrit :
> I did not do this because it is not supposed to be the same as the human
> ouutput.
> 

Oh, that's fine then :)



Re: add number of prefixed received to bgpctl -j sh

2021-12-12 Thread Claudio Jeker
On Sun, Dec 12, 2021 at 03:22:37PM +0100, Denis Fondras wrote:
> Le Sun, Dec 12, 2021 at 01:43:06PM +, Stuart Henderson a écrit :
> > On 2021/12/12 14:13, Denis Fondras wrote:
> > > Number of received prefixes appear in `bgpctl sh` but not in `bgpctl -j 
> > > sh`.
> > > 
> > > Here is a diff to add this piece of information.
> > > 
> > > OK ?
> > 
> > Makes sense, but if prefix_cnt is added, max_prefix probably should be too
> > 
> 
> If order of appearance is not important, there is no need to check for state 
> ==
> ESTABLISHED twice.
> 
> Index: output_json.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpctl/output_json.c,v
> retrieving revision 1.12
> diff -u -p -r1.12 output_json.c
> --- output_json.c 27 Jul 2021 07:42:37 -  1.12
> +++ output_json.c 12 Dec 2021 14:16:58 -
> @@ -311,10 +311,13 @@ json_neighbor(struct peer *p, struct par
>   struct in_addr ina;
>   ina.s_addr = p->remote_bgpid;
>   json_do_printf("bgpid", "%s", inet_ntoa(ina));
> + json_do_uint("received_prefixes", p->stats.prefix_cnt);
>   }
>   json_do_printf("state", "%s", statenames[p->state]);
>   json_do_printf("last_updown", "%s", fmt_monotime(p->stats.last_updown));
>   json_do_int("last_updown_sec", get_monotime(p->stats.last_updown));
> + if (p->conf.max_prefix != 0)
> + json_do_uint("max_prefix", p->conf.max_prefix);
>  
>   switch (res->action) {
>   case SHOW:
> 

I did not do this because it is not supposed to be the same as the human
ouutput.

'bgpctl -j sh' output should allow an API to enumerate all peers.
Then 'bgpctl -j show nei XYZ' should be used to get everything and much
more then 'bgpctl show nei' shows. This includes all the stats most of the
config, connection setting, negotiated capabilities etc.

So just change to 'bgpctl -j show nei' to get the additional info.
-- 
:wq Claudio



Re: add number of prefixed received to bgpctl -j sh

2021-12-12 Thread Denis Fondras
Le Sun, Dec 12, 2021 at 01:43:06PM +, Stuart Henderson a écrit :
> On 2021/12/12 14:13, Denis Fondras wrote:
> > Number of received prefixes appear in `bgpctl sh` but not in `bgpctl -j sh`.
> > 
> > Here is a diff to add this piece of information.
> > 
> > OK ?
> 
> Makes sense, but if prefix_cnt is added, max_prefix probably should be too
> 

If order of appearance is not important, there is no need to check for state ==
ESTABLISHED twice.

Index: output_json.c
===
RCS file: /cvs/src/usr.sbin/bgpctl/output_json.c,v
retrieving revision 1.12
diff -u -p -r1.12 output_json.c
--- output_json.c   27 Jul 2021 07:42:37 -  1.12
+++ output_json.c   12 Dec 2021 14:16:58 -
@@ -311,10 +311,13 @@ json_neighbor(struct peer *p, struct par
struct in_addr ina;
ina.s_addr = p->remote_bgpid;
json_do_printf("bgpid", "%s", inet_ntoa(ina));
+   json_do_uint("received_prefixes", p->stats.prefix_cnt);
}
json_do_printf("state", "%s", statenames[p->state]);
json_do_printf("last_updown", "%s", fmt_monotime(p->stats.last_updown));
json_do_int("last_updown_sec", get_monotime(p->stats.last_updown));
+   if (p->conf.max_prefix != 0)
+   json_do_uint("max_prefix", p->conf.max_prefix);
 
switch (res->action) {
case SHOW:



Re: add number of prefixed received to bgpctl -j sh

2021-12-12 Thread Stuart Henderson
On 2021/12/12 14:13, Denis Fondras wrote:
> Number of received prefixes appear in `bgpctl sh` but not in `bgpctl -j sh`.
> 
> Here is a diff to add this piece of information.
> 
> OK ?

Makes sense, but if prefix_cnt is added, max_prefix probably should be too

> Index: output_json.c
> ===
> RCS file: /cvs/src/usr.sbin/bgpctl/output_json.c,v
> retrieving revision 1.12
> diff -u -p -r1.12 output_json.c
> --- output_json.c 27 Jul 2021 07:42:37 -  1.12
> +++ output_json.c 12 Dec 2021 13:10:18 -
> @@ -315,6 +315,8 @@ json_neighbor(struct peer *p, struct par
>   json_do_printf("state", "%s", statenames[p->state]);
>   json_do_printf("last_updown", "%s", fmt_monotime(p->stats.last_updown));
>   json_do_int("last_updown_sec", get_monotime(p->stats.last_updown));
> + if (p->state == STATE_ESTABLISHED)
> + json_do_uint("received_prefixes", p->stats.prefix_cnt);
>  
>   switch (res->action) {
>   case SHOW:
> 



add number of prefixed received to bgpctl -j sh

2021-12-12 Thread Denis Fondras
Number of received prefixes appear in `bgpctl sh` but not in `bgpctl -j sh`.

Here is a diff to add this piece of information.

OK ?

Index: output_json.c
===
RCS file: /cvs/src/usr.sbin/bgpctl/output_json.c,v
retrieving revision 1.12
diff -u -p -r1.12 output_json.c
--- output_json.c   27 Jul 2021 07:42:37 -  1.12
+++ output_json.c   12 Dec 2021 13:10:18 -
@@ -315,6 +315,8 @@ json_neighbor(struct peer *p, struct par
json_do_printf("state", "%s", statenames[p->state]);
json_do_printf("last_updown", "%s", fmt_monotime(p->stats.last_updown));
json_do_int("last_updown_sec", get_monotime(p->stats.last_updown));
+   if (p->state == STATE_ESTABLISHED)
+   json_do_uint("received_prefixes", p->stats.prefix_cnt);
 
switch (res->action) {
case SHOW: