Skip to content

Commit

Permalink
Merge pull request FRRouting#13728 from opensourcerouting/fix/addpath…
Browse files Browse the repository at this point in the history
…_drop_non_best_addpaths

bgpd: Implement neighbor X addpath-tx-best-selected command
  • Loading branch information
riw777 authored Jun 20, 2023
2 parents 554c2e0 + 78981a8 commit 4d9fb37
Show file tree
Hide file tree
Showing 27 changed files with 478 additions and 36 deletions.
23 changes: 17 additions & 6 deletions bgpd/bgp_addpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ static const struct bgp_addpath_strategy_names strat_names[BGP_ADDPATH_MAX] = {
.human_description = "Advertise bestpath per AS via addpath",
.type_json_name = "addpathTxBestpathPerAS",
.id_json_name = "addpathTxIdBestPerAS"
}
},
{
.config_name = "addpath-tx-best-selected",
.human_name = "Best-Selected",
.human_description = "Advertise best N selected paths via addpath",
.type_json_name = "addpathTxBestSelectedPaths",
.id_json_name = "addpathTxIdBestSelected"
},
};

static const struct bgp_addpath_strategy_names unknown_names = {
Expand Down Expand Up @@ -161,6 +168,8 @@ bool bgp_addpath_tx_path(enum bgp_addpath_strat strat, struct bgp_path_info *pi)
return true;
else
return false;
case BGP_ADDPATH_BEST_SELECTED:
return true;
case BGP_ADDPATH_MAX:
return false;
}
Expand Down Expand Up @@ -356,7 +365,8 @@ void bgp_addpath_type_changed(struct bgp *bgp)
* change take effect.
*/
void bgp_addpath_set_peer_type(struct peer *peer, afi_t afi, safi_t safi,
enum bgp_addpath_strat addpath_type)
enum bgp_addpath_strat addpath_type,
uint8_t paths)
{
struct bgp *bgp = peer->bgp;
enum bgp_addpath_strat old_type;
Expand All @@ -367,6 +377,8 @@ void bgp_addpath_set_peer_type(struct peer *peer, afi_t afi, safi_t safi,
if (safi == SAFI_LABELED_UNICAST)
safi = SAFI_UNICAST;

peer->addpath_best_selected[afi][safi] = paths;

old_type = peer->addpath_type[afi][safi];
if (addpath_type == old_type)
return;
Expand Down Expand Up @@ -411,10 +423,9 @@ void bgp_addpath_set_peer_type(struct peer *peer, afi_t afi, safi_t safi,
tmp_peer)) {
if (tmp_peer->addpath_type[afi][safi] ==
old_type) {
bgp_addpath_set_peer_type(tmp_peer,
afi,
safi,
addpath_type);
bgp_addpath_set_peer_type(
tmp_peer, afi, safi,
addpath_type, paths);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion bgpd/bgp_addpath.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ bool bgp_addpath_tx_path(enum bgp_addpath_strat strat,
* Change the type of addpath used for a peer.
*/
void bgp_addpath_set_peer_type(struct peer *peer, afi_t afi, safi_t safi,
enum bgp_addpath_strat addpath_type);
enum bgp_addpath_strat addpath_type,
uint8_t paths);

void bgp_addpath_update_ids(struct bgp *bgp, struct bgp_dest *dest, afi_t afi,
safi_t safi);
Expand Down
1 change: 1 addition & 0 deletions bgpd/bgp_addpath_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
enum bgp_addpath_strat {
BGP_ADDPATH_ALL = 0,
BGP_ADDPATH_BEST_PER_AS,
BGP_ADDPATH_BEST_SELECTED,
BGP_ADDPATH_MAX,
BGP_ADDPATH_NONE,
};
Expand Down
10 changes: 5 additions & 5 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,11 @@ struct bgp_path_info *bgp_get_imported_bpi_ultimate(struct bgp_path_info *info)

/* Compare two bgp route entity. If 'new' is preferable over 'exist' return 1.
*/
static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
struct bgp_path_info *exist, int *paths_eq,
struct bgp_maxpaths_cfg *mpath_cfg, int debug,
char *pfx_buf, afi_t afi, safi_t safi,
enum bgp_path_selection_reason *reason)
int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
struct bgp_path_info *exist, int *paths_eq,
struct bgp_maxpaths_cfg *mpath_cfg, int debug,
char *pfx_buf, afi_t afi, safi_t safi,
enum bgp_path_selection_reason *reason)
{
const struct prefix *new_p;
struct attr *newattr, *existattr;
Expand Down
5 changes: 5 additions & 0 deletions bgpd/bgp_route.h
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,11 @@ extern void bgp_path_info_add_with_caller(const char *caller,
struct bgp_dest *dest,
struct bgp_path_info *pi);
extern void bgp_aggregate_free(struct bgp_aggregate *aggregate);
extern int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
struct bgp_path_info *exist, int *paths_eq,
struct bgp_maxpaths_cfg *mpath_cfg, int debug,
char *pfx_buf, afi_t afi, safi_t safi,
enum bgp_path_selection_reason *reason);
#define bgp_path_info_add(A, B) \
bgp_path_info_add_with_caller(__func__, (A), (B))
#define bgp_path_info_free(B) bgp_path_info_free_with_caller(__func__, (B))
Expand Down
4 changes: 4 additions & 0 deletions bgpd/bgp_updgrp.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ static void conf_copy(struct peer *dst, struct peer *src, afi_t afi,
dst->afc_nego[afi][safi] = src->afc_nego[afi][safi];
dst->orf_plist[afi][safi] = src->orf_plist[afi][safi];
dst->addpath_type[afi][safi] = src->addpath_type[afi][safi];
dst->addpath_best_selected[afi][safi] =
src->addpath_best_selected[afi][safi];
dst->local_as = src->local_as;
dst->change_local_as = src->change_local_as;
dst->shared_network = src->shared_network;
Expand Down Expand Up @@ -307,6 +309,7 @@ static void *updgrp_hash_alloc(void *p)
* 16. Local-as should match, if configured.
* 17. maximum-prefix-out
* 18. Local-role should also match, if configured.
* 19. Add-Path best selected paths count should match as well
* )
*/
static unsigned int updgrp_hash_key_make(const void *p)
Expand Down Expand Up @@ -340,6 +343,7 @@ static unsigned int updgrp_hash_key_make(const void *p)
key = jhash_1word((peer->flags & PEER_UPDGRP_FLAGS), key);
key = jhash_1word((flags & PEER_UPDGRP_AF_FLAGS), key);
key = jhash_1word((uint32_t)peer->addpath_type[afi][safi], key);
key = jhash_1word(peer->addpath_best_selected[afi][safi], key);
key = jhash_1word((peer->cap & PEER_UPDGRP_CAP_FLAGS), key);
key = jhash_1word((peer->af_cap[afi][safi] & PEER_UPDGRP_AF_CAP_FLAGS),
key);
Expand Down
92 changes: 73 additions & 19 deletions bgpd/bgp_updgrp_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,67 @@ static void adj_free(struct bgp_adj_out *adj)
XFREE(MTYPE_BGP_ADJ_OUT, adj);
}

static void
subgrp_announce_addpath_best_selected(struct bgp_dest *dest,
struct update_subgroup *subgrp)
{
afi_t afi = SUBGRP_AFI(subgrp);
safi_t safi = SUBGRP_SAFI(subgrp);
struct peer *peer = SUBGRP_PEER(subgrp);
enum bgp_path_selection_reason reason;
char pfx_buf[PREFIX2STR_BUFFER] = {};
int paths_eq = 0;
int best_path_count = 0;
struct list *list = list_new();
struct bgp_path_info *pi = NULL;

if (peer->addpath_type[afi][safi] == BGP_ADDPATH_BEST_SELECTED) {
while (best_path_count++ <
peer->addpath_best_selected[afi][safi]) {
struct bgp_path_info *exist = NULL;

for (pi = bgp_dest_get_bgp_path_info(dest); pi;
pi = pi->next) {
if (listnode_lookup(list, pi))
continue;

if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED))
continue;

if (bgp_path_info_cmp(peer->bgp, pi, exist,
&paths_eq, NULL, 0,
pfx_buf, afi, safi,
&reason))
exist = pi;
}

if (exist)
listnode_add(list, exist);
}
}

for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) {
uint32_t id = bgp_addpath_id_for_peer(peer, afi, safi,
&pi->tx_addpath);

if (peer->addpath_type[afi][safi] ==
BGP_ADDPATH_BEST_SELECTED) {
if (listnode_lookup(list, pi))
subgroup_process_announce_selected(
subgrp, pi, dest, afi, safi, id);
else
subgroup_process_announce_selected(
subgrp, NULL, dest, afi, safi, id);
} else {
subgroup_process_announce_selected(subgrp, pi, dest,
afi, safi, id);
}
}

if (list)
list_delete(&list);
}

static void subgrp_withdraw_stale_addpath(struct updwalk_context *ctx,
struct update_subgroup *subgrp)
{
Expand Down Expand Up @@ -125,7 +186,6 @@ static int group_announce_route_walkcb(struct update_group *updgrp, void *arg)
{
struct updwalk_context *ctx = arg;
struct update_subgroup *subgrp;
struct bgp_path_info *pi;
afi_t afi;
safi_t safi;
struct peer *peer;
Expand All @@ -143,7 +203,6 @@ static int group_announce_route_walkcb(struct update_group *updgrp, void *arg)
bgp_dest_to_rnode(ctx->dest));

UPDGRP_FOREACH_SUBGRP (updgrp, subgrp) {

/*
* Skip the subgroups that have coalesce timer running. We will
* walk the entire prefix table for those subgroups when the
Expand All @@ -155,19 +214,8 @@ static int group_announce_route_walkcb(struct update_group *updgrp, void *arg)
if (addpath_capable) {
subgrp_withdraw_stale_addpath(ctx, subgrp);

for (pi = bgp_dest_get_bgp_path_info(ctx->dest);
pi; pi = pi->next) {
/* Skip the bestpath for now */
if (pi == ctx->pi)
continue;

subgroup_process_announce_selected(
subgrp, pi, ctx->dest, afi,
safi,
bgp_addpath_id_for_peer(
peer, afi, safi,
&pi->tx_addpath));
}
subgrp_announce_addpath_best_selected(ctx->dest,
subgrp);

/* Process the bestpath last so the "show [ip]
* bgp neighbor x.x.x.x advertised"
Expand Down Expand Up @@ -689,6 +737,10 @@ void subgroup_announce_table(struct update_subgroup *subgrp,
SET_FLAG(subgrp->sflags, SUBGRP_STATUS_TABLE_REPARSING);

for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) {

if (addpath_capable)
subgrp_announce_addpath_best_selected(dest, subgrp);

for (ri = bgp_dest_get_bgp_path_info(dest); ri; ri = ri->next) {

if (!bgp_check_selected(ri, peer, addpath_capable, afi,
Expand All @@ -706,10 +758,12 @@ void subgroup_announce_table(struct update_subgroup *subgrp,
is_default_prefix(bgp_dest_get_prefix(dest)))
break;

subgroup_process_announce_selected(
subgrp, ri, dest, afi, safi_rib,
bgp_addpath_id_for_peer(peer, afi, safi_rib,
&ri->tx_addpath));
if (CHECK_FLAG(ri->flags, BGP_PATH_SELECTED))
subgroup_process_announce_selected(
subgrp, ri, dest, afi, safi_rib,
bgp_addpath_id_for_peer(
peer, afi, safi_rib,
&ri->tx_addpath));
}
}
UNSET_FLAG(subgrp->sflags, SUBGRP_STATUS_TABLE_REPARSING);
Expand Down
Loading

0 comments on commit 4d9fb37

Please sign in to comment.