From: Donald Sharp Date: Thu, 16 May 2019 01:11:02 +0000 (-0400) Subject: bgpd: Display best path selection reason X-Git-Tag: base_7.2~331^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=0dc8ee70624c5b018bbbe81f47536b80eda771eb;p=mirror%2Ffrr.git bgpd: Display best path selection reason As part of detailed bgp route detail, include the reason why a route was selected as best path. robot# show bgp ipv4 uni 223.255.254.0 BGP routing table entry for 223.255.254.0/24 Paths: (1 available, best #1, table default) Advertised to non peer-group peers: annie(192.168.201.136) 64539 15096 6939 7473 3758 55415 192.168.201.136 from annie(192.168.201.136) (192.168.201.136) Origin IGP, valid, external, bestpath-from-AS 64539, best (First path received) Last update: Wed May 15 21:15:48 2019 Signed-off-by: Donald Sharp --- diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index d24a152f13..f3a69d4b25 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -7868,6 +7868,79 @@ static void route_vty_out_tx_ids(struct vty *vty, } } +static const char *bgp_path_selection_reason2str( + enum bgp_path_selection_reason reason) +{ + switch (reason) { + case bgp_path_selection_none: + return "Nothing to Select"; + break; + case bgp_path_selection_first: + return "First path received"; + break; + case bgp_path_selection_evpn_sticky_mac: + return "EVPN Sticky Mac"; + break; + case bgp_path_selection_evpn_seq: + return "EVPN sequence number"; + break; + case bgp_path_selection_evpn_lower_ip: + return "EVPN lower IP"; + break; + case bgp_path_selection_weight: + return "Weight"; + break; + case bgp_path_selection_local_pref: + return "Local Pref"; + break; + case bgp_path_selection_local_route: + return "Local Route"; + break; + case bgp_path_selection_confed_as_path: + return "Confederation based AS Path"; + break; + case bgp_path_selection_as_path: + return "AS Path"; + break; + case bgp_path_selection_origin: + return "Origin"; + break; + case bgp_path_selection_med: + return "MED"; + break; + case bgp_path_selection_peer: + return "Peer Type"; + break; + case bgp_path_selection_confed: + return "Confed Peer Type"; + break; + case bgp_path_selection_igp_metric: + return "IGP Metric"; + break; + case bgp_path_selection_older: + return "Older Path"; + break; + case bgp_path_selection_router_id: + return "Router ID"; + break; + case bgp_path_selection_cluster_length: + return "Cluser length"; + break; + case bgp_path_selection_stale: + return "Path Staleness"; + break; + case bgp_path_selection_local_configured: + return "Locally configured route"; + break; + case bgp_path_selection_neighbor_ip: + return "Neighbor IP"; + break; + case bgp_path_selection_default: + return "Nothing left to compare"; + break; + } +} + void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_node *bn, struct bgp_path_info *path, afi_t afi, safi_t safi, json_object *json_paths) @@ -8463,8 +8536,14 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, json_object_new_object(); json_object_boolean_true_add(json_bestpath, "overall"); - } else + json_object_string_add(json_bestpath, + "selectionReason", + bgp_path_selection_reason2str(bn->reason)); + } else { vty_out(vty, ", best"); + vty_out(vty, " (%s)", + bgp_path_selection_reason2str(bn->reason)); + } } if (json_bestpath)