From 01eced229d86389c75d222c44dafc65e9f73a68a Mon Sep 17 00:00:00 2001 From: Ameya Dharkar Date: Fri, 2 Nov 2018 14:40:44 -0700 Subject: [PATCH 1/2] bgpd: Display default local preference and local AS for BGP show commands 1. "show bgp ipv4/ipv6 [json]" 2. "show bgp ipv4/ipv6 neighbor routes [json]" 3. "show bgp ipv4/ipv6 neighbors advertised-routes [json]" In the above show commands, when a BGP path is displayed, we do not display the local preference if it is EBGP route. Route calculation assumes the default local preference. But, we can change the default local preference using configuration in FRR. In this case, user should know the default local preference value that is being used in the route calculation. Thus, adding a new field 'default local preferece' in the show commands where a BGP path is displayed. When a BGP path is displayed in the above show commands, as-path does not include the local AS. So, user has to execute another show command to display the local-AS. To avoid this, adding a new field local-AS to above show commands. Signed-off-by: Ameya Dharkar --- bgpd/bgp_route.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 74e4276c06..081c400ec4 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -8427,12 +8427,14 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, if (use_json && !*json_header_depth) { vty_out(vty, "{\n \"vrfId\": %d,\n \"vrfName\": \"%s\",\n \"tableVersion\": %" PRId64 - ",\n \"routerId\": \"%s\",\n \"routes\": { ", + ",\n \"routerId\": \"%s\",\n \"defaultLocPrf\": %u,\n" + " \"localAS\": %u,\n \"routes\": { ", bgp->vrf_id == VRF_UNKNOWN ? -1 : (int)bgp->vrf_id, bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ? VRF_DEFAULT_NAME : bgp->name, - table->version, inet_ntoa(bgp->router_id)); + table->version, inet_ntoa(bgp->router_id), + bgp->default_local_pref, bgp->as); *json_header_depth = 2; if (rd) { vty_out(vty, " \"routeDistinguishers\" : {"); @@ -8599,6 +8601,9 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, else vty_out(vty, "%u", bgp->vrf_id); vty_out(vty, "\n"); + vty_out(vty, "Default local pref %u, ", + bgp->default_local_pref); + vty_out(vty, "local AS %u\n", bgp->as); vty_out(vty, BGP_SHOW_SCODE_HEADER); vty_out(vty, BGP_SHOW_NCODE_HEADER); vty_out(vty, BGP_SHOW_OCODE_HEADER); @@ -10454,6 +10459,9 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi, table->version); json_object_string_add(json, "bgpLocalRouterId", inet_ntoa(bgp->router_id)); + json_object_int_add(json, "defaultLocPrf", + bgp->default_local_pref); + json_object_int_add(json, "localAS", bgp->as); json_object_object_add(json, "bgpStatusCodes", json_scode); json_object_object_add(json, "bgpOriginCodes", @@ -10470,6 +10478,9 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi, else vty_out(vty, "%u", bgp->vrf_id); vty_out(vty, "\n"); + vty_out(vty, "Default local pref %u, ", + bgp->default_local_pref); + vty_out(vty, "local AS %u\n", bgp->as); vty_out(vty, BGP_SHOW_SCODE_HEADER); vty_out(vty, BGP_SHOW_NCODE_HEADER); vty_out(vty, BGP_SHOW_OCODE_HEADER); @@ -10497,6 +10508,11 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi, "bgpLocalRouterId", inet_ntoa( bgp->router_id)); + json_object_int_add(json, + "defaultLocPrf", + bgp->default_local_pref); + json_object_int_add(json, + "localAS", bgp->as); json_object_object_add( json, "bgpStatusCodes", json_scode); @@ -10515,6 +10531,11 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi, vty_out(vty, "%u", bgp->vrf_id); vty_out(vty, "\n"); + vty_out(vty, + "Default local pref %u, ", + bgp->default_local_pref); + vty_out(vty, "local AS %u\n", + bgp->as); vty_out(vty, BGP_SHOW_SCODE_HEADER); vty_out(vty, @@ -10576,6 +10597,13 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi, "bgpLocalRouterId", inet_ntoa( bgp->router_id)); + json_object_int_add( + json, "defaultLocPrf", + bgp->default_local_pref + ); + json_object_int_add( + json, "localAS", + bgp->as); json_object_object_add( json, "bgpStatusCodes", @@ -10601,6 +10629,13 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi, "%u", bgp->vrf_id); vty_out(vty, "\n"); + vty_out(vty, + "Default local pref %u, ", + bgp->default_local_pref + ); + vty_out(vty, + "local AS %u\n", + bgp->as); vty_out(vty, BGP_SHOW_SCODE_HEADER); vty_out(vty, From 436df704e4f3c32a11eb03ce6cf558a0fec85fbe Mon Sep 17 00:00:00 2001 From: Ameya Dharkar Date: Wed, 5 Dec 2018 11:26:32 -0800 Subject: [PATCH 2/2] bgp: new topotest BGP templates to display default local preference and local-AS in BGP commands This commit adds a template for "show bgp ipv4/ipv6" display to include default local preference and local-AS O/P. Signed-off-by: Ameya Dharkar --- .../r1/show_bgp_ipv4-post6.1.ref | 9 ++++ .../r1/show_bgp_ipv6_post6.1.ref | 9 ++++ .../r1/show_ip_bgp_view_1-post6.1.ref | 42 +++++++++++++++++++ .../r1/show_ip_bgp_view_2-post6.1.ref | 31 ++++++++++++++ .../r1/show_ip_bgp_view_3-post6.1.ref | 42 +++++++++++++++++++ 5 files changed, 133 insertions(+) create mode 100644 tests/topotests/all-protocol-startup/r1/show_bgp_ipv4-post6.1.ref create mode 100644 tests/topotests/all-protocol-startup/r1/show_bgp_ipv6_post6.1.ref create mode 100644 tests/topotests/bgp_multiview_topo1/r1/show_ip_bgp_view_1-post6.1.ref create mode 100644 tests/topotests/bgp_multiview_topo1/r1/show_ip_bgp_view_2-post6.1.ref create mode 100644 tests/topotests/bgp_multiview_topo1/r1/show_ip_bgp_view_3-post6.1.ref diff --git a/tests/topotests/all-protocol-startup/r1/show_bgp_ipv4-post6.1.ref b/tests/topotests/all-protocol-startup/r1/show_bgp_ipv4-post6.1.ref new file mode 100644 index 0000000000..d36d045397 --- /dev/null +++ b/tests/topotests/all-protocol-startup/r1/show_bgp_ipv4-post6.1.ref @@ -0,0 +1,9 @@ +BGP table version is 1, local router ID is 192.168.0.1, vrf id 0 +Default local pref 100, local AS 100 +Status codes: s suppressed, d damped, h history, * valid, > best, = multipath, + i internal, r RIB-failure, S Stale, R Removed +Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self +Origin codes: i - IGP, e - EGP, ? - incomplete + + Network Next Hop Metric LocPrf Weight Path +*> 192.168.0.0/24 0.0.0.0 0 32768 i diff --git a/tests/topotests/all-protocol-startup/r1/show_bgp_ipv6_post6.1.ref b/tests/topotests/all-protocol-startup/r1/show_bgp_ipv6_post6.1.ref new file mode 100644 index 0000000000..de91b247d8 --- /dev/null +++ b/tests/topotests/all-protocol-startup/r1/show_bgp_ipv6_post6.1.ref @@ -0,0 +1,9 @@ +BGP table version is 1, local router ID is 192.168.0.1, vrf id 0 +Default local pref 100, local AS 100 +Status codes: s suppressed, d damped, h history, * valid, > best, = multipath, + i internal, r RIB-failure, S Stale, R Removed +Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self +Origin codes: i - IGP, e - EGP, ? - incomplete + + Network Next Hop Metric LocPrf Weight Path +*> fc00::/64 :: 0 32768 i diff --git a/tests/topotests/bgp_multiview_topo1/r1/show_ip_bgp_view_1-post6.1.ref b/tests/topotests/bgp_multiview_topo1/r1/show_ip_bgp_view_1-post6.1.ref new file mode 100644 index 0000000000..2cf87487ab --- /dev/null +++ b/tests/topotests/bgp_multiview_topo1/r1/show_ip_bgp_view_1-post6.1.ref @@ -0,0 +1,42 @@ +BGP table version is XXX, local router ID is 172.30.1.1, vrf id - +Default local pref 100, local AS 100 +Status codes: s suppressed, d damped, h history, * valid, > best, = multipath, + i internal, r RIB-failure, S Stale, R Removed +Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self +Origin codes: i - IGP, e - EGP, ? - incomplete + + Network Next Hop Metric LocPrf Weight Path +* 10.0.1.0/24 172.16.1.5 0 65005 i +* 172.16.1.2 0 65002 i +*> 172.16.1.1 0 65001 i +*> 10.101.0.0/24 172.16.1.1 100 0 65001 i +*> 10.101.1.0/24 172.16.1.1 100 0 65001 i +*> 10.101.2.0/24 172.16.1.1 100 0 65001 i +*> 10.101.3.0/24 172.16.1.1 100 0 65001 i +*> 10.101.4.0/24 172.16.1.1 100 0 65001 i +*> 10.101.5.0/24 172.16.1.1 100 0 65001 i +*> 10.101.6.0/24 172.16.1.1 100 0 65001 i +*> 10.101.7.0/24 172.16.1.1 100 0 65001 i +*> 10.101.8.0/24 172.16.1.1 100 0 65001 i +*> 10.101.9.0/24 172.16.1.1 100 0 65001 i +*> 10.102.0.0/24 172.16.1.2 100 0 65002 i +*> 10.102.1.0/24 172.16.1.2 100 0 65002 i +*> 10.102.2.0/24 172.16.1.2 100 0 65002 i +*> 10.102.3.0/24 172.16.1.2 100 0 65002 i +*> 10.102.4.0/24 172.16.1.2 100 0 65002 i +*> 10.102.5.0/24 172.16.1.2 100 0 65002 i +*> 10.102.6.0/24 172.16.1.2 100 0 65002 i +*> 10.102.7.0/24 172.16.1.2 100 0 65002 i +*> 10.102.8.0/24 172.16.1.2 100 0 65002 i +*> 10.102.9.0/24 172.16.1.2 100 0 65002 i +*> 10.105.0.0/24 172.16.1.5 100 0 65005 i +*> 10.105.1.0/24 172.16.1.5 100 0 65005 i +*> 10.105.2.0/24 172.16.1.5 100 0 65005 i +*> 10.105.3.0/24 172.16.1.5 100 0 65005 i +*> 10.105.4.0/24 172.16.1.5 100 0 65005 i +*> 10.105.5.0/24 172.16.1.5 100 0 65005 i +*> 10.105.6.0/24 172.16.1.5 100 0 65005 i +*> 10.105.7.0/24 172.16.1.5 100 0 65005 i +*> 10.105.8.0/24 172.16.1.5 100 0 65005 i +*> 10.105.9.0/24 172.16.1.5 100 0 65005 i +*> 172.20.0.0/28 0.0.0.0 0 32768 i diff --git a/tests/topotests/bgp_multiview_topo1/r1/show_ip_bgp_view_2-post6.1.ref b/tests/topotests/bgp_multiview_topo1/r1/show_ip_bgp_view_2-post6.1.ref new file mode 100644 index 0000000000..9d1b948b5c --- /dev/null +++ b/tests/topotests/bgp_multiview_topo1/r1/show_ip_bgp_view_2-post6.1.ref @@ -0,0 +1,31 @@ +BGP table version is XXX, local router ID is 172.30.1.1, vrf id - +Default local pref 100, local AS 100 +Status codes: s suppressed, d damped, h history, * valid, > best, = multipath, + i internal, r RIB-failure, S Stale, R Removed +Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self +Origin codes: i - IGP, e - EGP, ? - incomplete + + Network Next Hop Metric LocPrf Weight Path +* 10.0.1.0/24 172.16.1.4 0 65004 i +*> 172.16.1.3 0 65003 i +*> 10.103.0.0/24 172.16.1.3 100 0 65003 i +*> 10.103.1.0/24 172.16.1.3 100 0 65003 i +*> 10.103.2.0/24 172.16.1.3 100 0 65003 i +*> 10.103.3.0/24 172.16.1.3 100 0 65003 i +*> 10.103.4.0/24 172.16.1.3 100 0 65003 i +*> 10.103.5.0/24 172.16.1.3 100 0 65003 i +*> 10.103.6.0/24 172.16.1.3 100 0 65003 i +*> 10.103.7.0/24 172.16.1.3 100 0 65003 i +*> 10.103.8.0/24 172.16.1.3 100 0 65003 i +*> 10.103.9.0/24 172.16.1.3 100 0 65003 i +*> 10.104.0.0/24 172.16.1.4 100 0 65004 i +*> 10.104.1.0/24 172.16.1.4 100 0 65004 i +*> 10.104.2.0/24 172.16.1.4 100 0 65004 i +*> 10.104.3.0/24 172.16.1.4 100 0 65004 i +*> 10.104.4.0/24 172.16.1.4 100 0 65004 i +*> 10.104.5.0/24 172.16.1.4 100 0 65004 i +*> 10.104.6.0/24 172.16.1.4 100 0 65004 i +*> 10.104.7.0/24 172.16.1.4 100 0 65004 i +*> 10.104.8.0/24 172.16.1.4 100 0 65004 i +*> 10.104.9.0/24 172.16.1.4 100 0 65004 i +*> 172.20.0.0/28 0.0.0.0 9999 32768 100 100 100 100 100 i diff --git a/tests/topotests/bgp_multiview_topo1/r1/show_ip_bgp_view_3-post6.1.ref b/tests/topotests/bgp_multiview_topo1/r1/show_ip_bgp_view_3-post6.1.ref new file mode 100644 index 0000000000..8b66fa67ec --- /dev/null +++ b/tests/topotests/bgp_multiview_topo1/r1/show_ip_bgp_view_3-post6.1.ref @@ -0,0 +1,42 @@ +BGP table version is XXX, local router ID is 172.30.1.1, vrf id - +Default local pref 100, local AS 100 +Status codes: s suppressed, d damped, h history, * valid, > best, = multipath, + i internal, r RIB-failure, S Stale, R Removed +Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self +Origin codes: i - IGP, e - EGP, ? - incomplete + + Network Next Hop Metric LocPrf Weight Path +* 10.0.1.0/24 172.16.1.8 0 65008 i +* 172.16.1.7 0 65007 i +*> 172.16.1.6 0 65006 i +*> 10.106.0.0/24 172.16.1.6 100 0 65006 i +*> 10.106.1.0/24 172.16.1.6 100 0 65006 i +*> 10.106.2.0/24 172.16.1.6 100 0 65006 i +*> 10.106.3.0/24 172.16.1.6 100 0 65006 i +*> 10.106.4.0/24 172.16.1.6 100 0 65006 i +*> 10.106.5.0/24 172.16.1.6 100 0 65006 i +*> 10.106.6.0/24 172.16.1.6 100 0 65006 i +*> 10.106.7.0/24 172.16.1.6 100 0 65006 i +*> 10.106.8.0/24 172.16.1.6 100 0 65006 i +*> 10.106.9.0/24 172.16.1.6 100 0 65006 i +*> 10.107.0.0/24 172.16.1.7 100 0 65007 i +*> 10.107.1.0/24 172.16.1.7 100 0 65007 i +*> 10.107.2.0/24 172.16.1.7 100 0 65007 i +*> 10.107.3.0/24 172.16.1.7 100 0 65007 i +*> 10.107.4.0/24 172.16.1.7 100 0 65007 i +*> 10.107.5.0/24 172.16.1.7 100 0 65007 i +*> 10.107.6.0/24 172.16.1.7 100 0 65007 i +*> 10.107.7.0/24 172.16.1.7 100 0 65007 i +*> 10.107.8.0/24 172.16.1.7 100 0 65007 i +*> 10.107.9.0/24 172.16.1.7 100 0 65007 i +*> 10.108.0.0/24 172.16.1.8 100 0 65008 i +*> 10.108.1.0/24 172.16.1.8 100 0 65008 i +*> 10.108.2.0/24 172.16.1.8 100 0 65008 i +*> 10.108.3.0/24 172.16.1.8 100 0 65008 i +*> 10.108.4.0/24 172.16.1.8 100 0 65008 i +*> 10.108.5.0/24 172.16.1.8 100 0 65008 i +*> 10.108.6.0/24 172.16.1.8 100 0 65008 i +*> 10.108.7.0/24 172.16.1.8 100 0 65008 i +*> 10.108.8.0/24 172.16.1.8 100 0 65008 i +*> 10.108.9.0/24 172.16.1.8 100 0 65008 i +*> 172.20.0.0/28 0.0.0.0 0 32768 i