Merge pull request #251 from donaldsharp/bgp_view

BGP Display
This commit is contained in:
Martin Winter 2017-03-07 06:51:10 -08:00 committed by GitHub
commit 2989c6c960
3 changed files with 47 additions and 121 deletions

View File

@ -5267,7 +5267,7 @@ bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
struct bgp_table *table;
/* MPLS-VPN aggregation is not yet supported. */
if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP) || (safi = SAFI_EVPN))
if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP) || (safi == SAFI_EVPN))
return;
table = bgp->aggregate[afi][safi];
@ -5304,7 +5304,7 @@ bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
struct bgp_table *table;
/* MPLS-VPN aggregation is not yet supported. */
if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP) || (safi = SAFI_EVPN))
if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP) || (safi == SAFI_EVPN))
return;
table = bgp->aggregate[afi][safi];
@ -6097,7 +6097,7 @@ route_vty_out (struct vty *vty, struct prefix *p,
* neccessarily the same as the prefix address family.
* Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
*/
if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN) || (safi = SAFI_EVPN))
if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN) || (safi == SAFI_EVPN))
{
if (attr->extra)
{
@ -6129,7 +6129,7 @@ route_vty_out (struct vty *vty, struct prefix *p,
{
json_nexthop_global = json_object_new_object();
if ((safi == SAFI_MPLS_VPN) || (safi = SAFI_EVPN))
if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_EVPN))
json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->extra->mp_nexthop_global_in));
else
json_object_string_add(json_nexthop_global, "ip", inet_ntoa (attr->nexthop));
@ -6139,7 +6139,7 @@ route_vty_out (struct vty *vty, struct prefix *p,
}
else
{
if ((safi == SAFI_MPLS_VPN) || (safi = SAFI_EVPN))
if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_EVPN))
vty_out (vty, "%-16s",
inet_ntoa (attr->extra->mp_nexthop_global_in));
else
@ -8358,7 +8358,6 @@ DEFUN (show_ip_bgp,
"Display route and more specific routes\n"
JSON_STR)
{
vrf_id_t vrf = VRF_DEFAULT;
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
int exact_match = 0;
@ -8366,23 +8365,13 @@ DEFUN (show_ip_bgp,
struct bgp *bgp = NULL;
int idx = 0;
bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf);
bgp_vty_find_and_parse_afi_safi_bgp (vty, argv, argc, &idx, &afi, &safi, &bgp);
if (!idx)
return CMD_WARNING;
int uj = use_json (argc, argv);
if (uj) argc--;
bgp = bgp_lookup_by_vrf_id (vrf);
if (bgp == NULL)
{
if (vrf == VRF_DEFAULT)
vty_out (vty, "Can't find BGP instance (default)%s", VTY_NEWLINE);
else
vty_out (vty, "Can't find BGP instance %d%s", vrf, VTY_NEWLINE);
return CMD_WARNING;
}
if (argv_find(argv, argc, "cidr-only", &idx))
return bgp_show (vty, bgp, afi, safi, bgp_show_type_cidr_only, NULL, uj);
@ -8465,7 +8454,6 @@ DEFUN (show_ip_bgp_route,
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
vrf_id_t vrf = VRF_DEFAULT;;
char *prefix = NULL;
struct bgp *bgp = NULL;
enum bgp_path_type path_type;
@ -8473,20 +8461,11 @@ DEFUN (show_ip_bgp_route,
int idx = 0;
bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf);
bgp_vty_find_and_parse_afi_safi_bgp (vty, argv, argc, &idx, &afi, &safi, &bgp);
if (!idx)
return CMD_WARNING;
if (vrf != VRF_ALL)
{
bgp = bgp_lookup_by_vrf_id (vrf);
if (bgp == NULL)
{
vty_out (vty, "Can't find BGP instance %s%s", argv[5]->arg, VTY_NEWLINE);
return CMD_WARNING;
}
}
else
if (!bgp)
{
vty_out (vty, "Specified 'all' vrf's but this command currently only works per view/vrf%s", VTY_NEWLINE);
return CMD_WARNING;
@ -8534,12 +8513,12 @@ DEFUN (show_ip_bgp_regexp,
"Display routes matching the AS path regular expression\n"
"A regular-expression to match the BGP AS paths\n")
{
vrf_id_t vrf = VRF_DEFAULT;
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
struct bgp *bgp = NULL;
int idx = 0;
bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf);
bgp_vty_find_and_parse_afi_safi_bgp (vty, argv, argc, &idx, &afi, &safi, &bgp);
if (!idx)
return CMD_WARNING;
@ -8564,12 +8543,12 @@ DEFUN (show_ip_bgp_instance_all,
BGP_SAFI_HELP_STR
JSON_STR)
{
vrf_id_t vrf = VRF_DEFAULT;
afi_t afi = AFI_IP;
safi_t safi = SAFI_UNICAST;
struct bgp *bgp = NULL;
int idx = 0;
bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf);
bgp_vty_find_and_parse_afi_safi_bgp (vty, argv, argc, &idx, &afi, &safi, &bgp);
if (!idx)
return CMD_WARNING;
@ -9253,41 +9232,19 @@ DEFUN (show_ip_bgp_instance_neighbor_prefix_counts,
"Display detailed prefix count information\n"
JSON_STR)
{
vrf_id_t vrf = VRF_DEFAULT;
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
struct peer *peer;
int idx = 0;
struct bgp *bgp = NULL;
bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf);
bgp_vty_find_and_parse_afi_safi_bgp (vty, argv, argc, &idx, &afi, &safi, &bgp);
if (!idx)
return CMD_WARNING;
int uj = use_json (argc, argv);
if (uj) argc--;
if (vrf != VRF_ALL)
{
bgp = bgp_lookup_by_vrf_id (vrf);
if (bgp == NULL)
{
if (uj)
{
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "Can't find BGP view");
vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
json_object_free(json_no);
}
else
vty_out (vty, "Can't find BGP instance %s%s", argv[5]->arg, VTY_NEWLINE);
return CMD_WARNING;
}
}
else
bgp = NULL;
argv_find (argv, argc, "neighbors", &idx);
peer = peer_lookup_in_view (vty, bgp, argv[idx+1]->arg, uj);
if (! peer)
@ -9629,7 +9586,6 @@ DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
"Name of the route map\n"
JSON_STR)
{
vrf_id_t vrf = VRF_DEFAULT;
afi_t afi = AFI_IP6;
safi_t safi = SAFI_UNICAST;
char *rmap_name = NULL;
@ -9640,29 +9596,13 @@ DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
int idx = 0;
bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf);
bgp_vty_find_and_parse_afi_safi_bgp (vty, argv, argc, &idx, &afi, &safi, &bgp);
if (!idx)
return CMD_WARNING;
int uj = use_json (argc, argv);
if (uj) argc--;
bgp = bgp_lookup_by_vrf_id (vrf);
if (bgp == NULL)
{
if (uj)
{
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "Can't find BGP view");
vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
json_object_free(json_no);
}
else
vty_out (vty, "Can't find BGP instance %s%s", argv[5]->arg, VTY_NEWLINE);
return CMD_WARNING;
}
/* neighbors <A.B.C.D|X:X::X:X|WORD> */
argv_find (argv, argc, "neighbors", &idx);
peerstr = argv[++idx]->arg;
@ -9809,7 +9749,6 @@ DEFUN (show_ip_bgp_neighbor_routes,
"Display routes learned from neighbor\n"
JSON_STR)
{
vrf_id_t vrf = VRF_DEFAULT;
char *peerstr = NULL;
struct bgp *bgp = NULL;
afi_t afi = AFI_IP6;
@ -9819,34 +9758,13 @@ DEFUN (show_ip_bgp_neighbor_routes,
int idx = 0;
bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf);
bgp_vty_find_and_parse_afi_safi_bgp (vty, argv, argc, &idx, &afi, &safi, &bgp);
if (!idx)
return CMD_WARNING;
int uj = use_json (argc, argv);
if (uj) argc--;
if (vrf != VRF_ALL)
{
bgp = bgp_lookup_by_vrf_id (vrf);
if (bgp == NULL)
{
if (uj)
{
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "Can't find BGP view");
vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
json_object_free(json_no);
}
else
vty_out (vty, "Can't find BGP instance %s%s", argv[5]->arg, VTY_NEWLINE);
return CMD_WARNING;
}
}
else
bgp = NULL;
/* neighbors <A.B.C.D|X:X::X:X|WORD> */
argv_find (argv, argc, "neighbors", &idx);
peerstr = argv[++idx]->arg;

View File

@ -214,10 +214,10 @@ argv_find_and_parse_safi (struct cmd_token **argv, int argc, int *index, safi_t
}
/*
* bgp_vty_find_and_parse_afi_safi_vrf
* bgp_vty_find_and_parse_afi_safi_bgp
*
* For a given 'show ...' command, correctly parse the afi/safi/vrf out from it
* This function *assumes* that the calling function pre-sets the afi/safi/vrf
* For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
* This function *assumes* that the calling function pre-sets the afi/safi/bgp
* to appropriate values for the calling function. This is to allow the
* calling function to make decisions appropriate for the show command
* that is being parsed.
@ -238,7 +238,7 @@ argv_find_and_parse_safi (struct cmd_token **argv, int argc, int *index, safi_t
* idx -> The current place in the command, generally should be 0 for this function
* 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
* vrf -> The parsed vrf id if it was included in the show command, returned here
* bgp -> Pointer to the bgp data structure we need to fill in.
*
* The function returns the correct location in the parse tree for the
* last token found.
@ -247,14 +247,14 @@ argv_find_and_parse_safi (struct cmd_token **argv, int argc, int *index, safi_t
* it found the last token.
*/
int
bgp_vty_find_and_parse_afi_safi_vrf (struct vty *vty, struct cmd_token **argv, int argc, int *idx,
afi_t *afi, safi_t *safi, vrf_id_t *vrf)
bgp_vty_find_and_parse_afi_safi_bgp (struct vty *vty, struct cmd_token **argv, int argc, int *idx,
afi_t *afi, safi_t *safi, struct bgp **bgp)
{
char *vrf_name = NULL;
assert (afi);
assert (safi);
assert (vrf && *vrf != VRF_UNKNOWN);
assert (bgp);
if (argv_find (argv, argc, "ip", idx))
*afi = AFI_IP;
@ -263,26 +263,34 @@ bgp_vty_find_and_parse_afi_safi_vrf (struct vty *vty, struct cmd_token **argv, i
{
vrf_name = argv[*idx + 1]->arg;
*idx += 2;
if (strmatch (vrf_name, "all"))
*bgp = NULL;
else
{
*bgp = bgp_lookup_by_name (vrf_name);
if (!*bgp)
{
vty_out (vty, "View/Vrf specified is unknown: %s%s", vrf_name, VTY_NEWLINE);
*idx = 0;
return 0;
}
}
}
else
{
*bgp = bgp_get_default ();
if (!*bgp)
{
vty_out (vty, "Unable to find default BGP instance%s", VTY_NEWLINE);
*idx = 0;
return 0;
}
}
if (argv_find_and_parse_afi (argv, argc, idx, afi))
argv_find_and_parse_safi (argv, argc, idx, safi);
if (vrf_name)
{
if (strmatch(vrf_name, "all"))
*vrf = VRF_ALL;
else
*vrf = vrf_name_to_id (vrf_name);
}
if (*vrf == VRF_UNKNOWN)
{
vty_out (vty, "View/Vrf specified is unknown: %s", vrf_name);
*idx = 0;
return 0;
}
*idx += 1;
return *idx;
}

View File

@ -64,6 +64,6 @@ extern int
argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index, safi_t *safi);
extern int
bgp_vty_find_and_parse_afi_safi_vrf (struct vty *vty, struct cmd_token **argv, int argc, int *idx,
afi_t *afi, safi_t *safi, vrf_id_t *vrf);
bgp_vty_find_and_parse_afi_safi_bgp (struct vty *vty, struct cmd_token **argv, int argc, int *idx,
afi_t *afi, safi_t *safi, struct bgp **bgp);
#endif /* _QUAGGA_BGP_VTY_H */