Skip to content

Commit

Permalink
bgpd: bmp loc-rib missing features (peer state, stats)
Browse files Browse the repository at this point in the history
bgpd: bmp loc-rib peer up/down for vrfs
bgpd: include ecmp path into bmp loc-rib statistics

Signed-off-by: Maxence Younsi <[email protected]>
  • Loading branch information
mxyns committed Nov 21, 2023
1 parent 8710d38 commit 2c81a1c
Show file tree
Hide file tree
Showing 10 changed files with 354 additions and 139 deletions.
380 changes: 276 additions & 104 deletions bgpd/bgp_bmp.c

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions bgpd/bgp_bmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,19 @@ PREDECL_HASH(bmp_bgph);

#define BMP_PEER_DOWN_NO_RELEVANT_EVENT_CODE 0x00

enum bmp_vrf_state {
vrf_state_down = -1,
vrf_state_unknown = 0,
vrf_state_up = 1,
};

struct bmp_bgp {
struct bmp_bgph_item bbi;

struct bgp *bgp;

enum bmp_vrf_state vrf_up;

struct bmp_targets_head targets;

struct bmp_mirrorq_head mirrorq;
Expand All @@ -345,12 +354,16 @@ struct bmp_bgp {
uint32_t startup_delay_ms;
};

extern bool bmp_bgp_update_vrf_status(struct bmp_bgp *bmpbgp,
enum bmp_vrf_state force);

enum {
BMP_PEERDOWN_LOCAL_NOTIFY = 1,
BMP_PEERDOWN_LOCAL_FSM = 2,
BMP_PEERDOWN_REMOTE_NOTIFY = 3,
BMP_PEERDOWN_REMOTE_CLOSE = 4,
BMP_PEERDOWN_ENDMONITOR = 5,
BMP_PEERDOWN_LOCAL_TLV = 6,
};

enum {
Expand Down
7 changes: 7 additions & 0 deletions bgpd/bgp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ static __attribute__((__noreturn__)) void bgp_exit(int status)

static int bgp_vrf_new(struct vrf *vrf)
{
zlog_info("BGP VRF CREATE %s", vrf->name);

if (BGP_DEBUG(zebra, ZEBRA))
zlog_debug("VRF Created: %s(%u)", vrf->name, vrf->vrf_id);

Expand All @@ -265,6 +267,7 @@ static int bgp_vrf_new(struct vrf *vrf)

static int bgp_vrf_delete(struct vrf *vrf)
{
zlog_info("BGP VRF DELETE %s", vrf->name);
if (BGP_DEBUG(zebra, ZEBRA))
zlog_debug("VRF Deletion: %s(%u)", vrf->name, vrf->vrf_id);

Expand All @@ -276,6 +279,8 @@ static int bgp_vrf_enable(struct vrf *vrf)
struct bgp *bgp;
vrf_id_t old_vrf_id;

zlog_info("BGP VRF ENABLE %s", vrf->name);

if (BGP_DEBUG(zebra, ZEBRA))
zlog_debug("VRF enable add %s id %u", vrf->name, vrf->vrf_id);

Expand Down Expand Up @@ -308,6 +313,8 @@ static int bgp_vrf_disable(struct vrf *vrf)
{
struct bgp *bgp;

zlog_info("BGP VRF DISABLE %s", vrf->name);

if (vrf->vrf_id == VRF_DEFAULT)
return 0;

Expand Down
3 changes: 0 additions & 3 deletions bgpd/bgp_mpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,6 @@ void bgp_mpath_diff_insert(struct bgp_mpath_diff_head *diff,
bgp_path_info_lock(bpi);
bgp_dest_lock_node(bpi->net);
bgp_mpath_diff_add_tail(diff, item);
zlog_info("%s: added %p to %s, cnt=%d", __func__, bpi,
update ? "update" : "withdraw",
(int)bgp_mpath_diff_count(diff));
}

void bgp_mpath_diff_clear(struct bgp_mpath_diff_head *diff)
Expand Down
53 changes: 31 additions & 22 deletions bgpd/bgp_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,29 +643,10 @@ void bgp_keepalive_send(struct peer *peer)
bgp_writes_on(peer->connection);
}

/*
* Creates a BGP Open packet and appends it to the peer's output queue.
* Sets capabilities as necessary.
*/
void bgp_open_send(struct peer_connection *connection)
{
struct stream *s;
uint16_t send_holdtime;
as_t local_as;
struct peer *peer = connection->peer;

if (CHECK_FLAG(peer->flags, PEER_FLAG_TIMER))
send_holdtime = peer->holdtime;
else
send_holdtime = peer->bgp->default_holdtime;
struct stream *bgp_open_make(struct peer *peer, uint16_t send_holdtime,
as_t local_as) {

/* local-as Change */
if (peer->change_local_as)
local_as = peer->change_local_as;
else
local_as = peer->local_as;

s = stream_new(BGP_STANDARD_MESSAGE_MAX_PACKET_SIZE);
struct stream *s = stream_new(BGP_STANDARD_MESSAGE_MAX_PACKET_SIZE);

/* Make open packet. */
bgp_packet_set_marker(s, BGP_MSG_OPEN);
Expand Down Expand Up @@ -697,6 +678,34 @@ void bgp_open_send(struct peer_connection *connection)
/* Set BGP packet length. */
bgp_packet_set_size(s);

return s;
}

/*
* Creates a BGP Open packet and appends it to the peer's output queue.
* Sets capabilities as necessary.
*/
void bgp_open_send(struct peer_connection *connection)
{
struct stream *s;
uint16_t send_holdtime;
as_t local_as;
struct peer *peer = connection->peer;

if (CHECK_FLAG(peer->flags, PEER_FLAG_TIMER)) {
send_holdtime = peer->holdtime;
} else {
send_holdtime = peer->bgp->default_holdtime;
}

/* local-as Change */
if (peer->change_local_as)
local_as = peer->change_local_as;
else
local_as = peer->local_as;

s = bgp_open_make(peer, send_holdtime, local_as);

if (bgp_debug_neighbor_events(peer))
zlog_debug(
"%s sending OPEN, version %d, my as %u, holdtime %d, id %pI4",
Expand Down
3 changes: 3 additions & 0 deletions bgpd/bgp_packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ DECLARE_HOOK(bgp_packet_send,

/* Packet send and receive function prototypes. */
extern void bgp_keepalive_send(struct peer *peer);
extern struct stream *bgp_open_make(struct peer *peer,
uint16_t send_holdtime,
as_t local_as);
extern void bgp_open_send(struct peer_connection *connection);
extern void bgp_notify_send(struct peer_connection *connection, uint8_t code,
uint8_t sub_code);
Expand Down
25 changes: 16 additions & 9 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -3505,18 +3505,13 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest,
}

/* TODO BMP insert rib update hook */
if (old_select) {
if (old_select->peer)
old_select->peer->stat_loc_rib_count[afi][safi]--;
if (old_select)
bgp_path_info_unset_flag(dest, old_select, BGP_PATH_SELECTED);
}

if (new_select) {
if (debug)
zlog_debug("%s: setting SELECTED flag", __func__);

if (new_select->peer)
new_select->peer->stat_loc_rib_count[afi][safi]++;

bgp_path_info_set_flag(dest, new_select, BGP_PATH_SELECTED);
bgp_path_info_unset_flag(dest, new_select,
BGP_PATH_ATTR_CHANGED);
Expand Down Expand Up @@ -3594,12 +3589,24 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest,
if (old_select || new_select)
hook_call(bgp_process_main_one_end, bgp,
old_select && !new_select ? old_select : new_select);
if (old_select && old_select->peer)
old_select->peer->stat_loc_rib_count[afi][safi]--;

if (new_select && new_select->peer)
new_select->peer->stat_loc_rib_count[afi][safi]++;

struct bgp_path_info *mpath;
frr_each (bgp_mpath_diff, &mpath_diff, diff) {
if (!diff->path)
mpath = diff->path;

if (!mpath)
continue;

hook_call(bgp_process_main_one_end, bgp, diff->path);
if (mpath->peer)
mpath->peer->stat_loc_rib_count[afi][safi] += diff->update ? 1 : -1;

hook_call(bgp_process_main_one_end, bgp, mpath);

}
bgp_mpath_diff_clear(&mpath_diff);
bgp_mpath_diff_fini(&mpath_diff);
Expand Down
1 change: 0 additions & 1 deletion bgpd/bgp_updgrp_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ static int group_announce_route_walkcb(struct update_group *updgrp, void *arg)
bgp_adj_out_updated(
subgrp, ctx->dest, NULL,
0, NULL, false, true,

__func__);
}
}
Expand Down
7 changes: 7 additions & 0 deletions bgpd/bgpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ DEFINE_QOBJ_TYPE(bgp_master);
DEFINE_QOBJ_TYPE(bgp);
DEFINE_QOBJ_TYPE(peer);
DEFINE_HOOK(bgp_inst_delete, (struct bgp *bgp), (bgp));
DEFINE_HOOK(bgp_instance_state, (struct bgp *bgp), (bgp));

/* BGP process wide configuration. */
static struct bgp_master bgp_master;
Expand Down Expand Up @@ -3735,6 +3736,9 @@ void bgp_instance_up(struct bgp *bgp)
struct peer *peer;
struct listnode *node, *next;

/* notify BMP of instance state changed */
hook_call(bgp_instance_state, bgp);

bgp_set_redist_vrf_bitmaps(bgp, true);

/* Register with zebra. */
Expand All @@ -3760,6 +3764,9 @@ void bgp_instance_down(struct bgp *bgp)
struct listnode *node;
struct listnode *next;

/* notify BMP of instance state changed */
hook_call(bgp_instance_state, bgp);

/* Stop timers. */
if (bgp->t_rmap_def_originate_eval)
EVENT_OFF(bgp->t_rmap_def_originate_eval);
Expand Down
1 change: 1 addition & 0 deletions bgpd/bgpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ DECLARE_HOOK(bgp_inst_config_write,
(bgp, vty));
DECLARE_HOOK(bgp_snmp_traps_config_write, (struct vty *vty), (vty));
DECLARE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
DECLARE_HOOK(bgp_instance_state, (struct bgp *bgp), (bgp));

/* Thread callback information */
struct afi_safi_info {
Expand Down

0 comments on commit 2c81a1c

Please sign in to comment.