From 873382966c2ebfc1ecc8115815b41eea58e9b6ac Mon Sep 17 00:00:00 2001 From: Sarita Patra Date: Tue, 14 May 2019 06:22:19 -0700 Subject: [PATCH] bgpd: display bgp neighbor advertised-routes json warning message Issue 1: Getting an empty json without any warning message, while executing the command "show ip bgp neighbor advertised-routes json" when the bgp instance is not present or getting created. Issue 2: Getting an empty json without any warning message, while executing the command "show ip bgp vrf/view advertised-routes json" when the specified view/vrf is not present. Fix: Display warning message while executing the above cli commands, when the bgp instance, specified vrf is not present. Signed-off-by: Sarita Patra --- bgpd/bgp_vty.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 9a8da359ab..216427af0c 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -295,6 +295,7 @@ int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index, * afi -> The parsed afi if it was included in the show command, returned here * safi -> The parsed safi if it was included in the show command, returned here * bgp -> Pointer to the bgp data structure we need to fill in. + * use_json -> json is configured or not * * The function returns the correct location in the parse tree for the * last token found. @@ -329,8 +330,17 @@ int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty, else { *bgp = bgp_lookup_by_name(vrf_name); if (!*bgp) { - if (use_json) - vty_out(vty, "{}\n"); + if (use_json) { + json_object *json = NULL; + json = json_object_new_object(); + json_object_string_add( + json, "warning", + "View/Vrf is unknown"); + vty_out(vty, "%s\n", + json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); + json_object_free(json); + } else vty_out(vty, "View/Vrf %s is unknown\n", vrf_name); @@ -341,8 +351,17 @@ int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty, } else { *bgp = bgp_get_default(); if (!*bgp) { - if (use_json) - vty_out(vty, "{}\n"); + if (use_json) { + json_object *json = NULL; + json = json_object_new_object(); + json_object_string_add( + json, "warning", + "Default BGP instance not found"); + vty_out(vty, "%s\n", + json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); + json_object_free(json); + } else vty_out(vty, "Default BGP instance not found\n"); -- 2.39.5