Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bgpd: bmp loc-rib peer up/down for vrfs #17001

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
266 changes: 231 additions & 35 deletions bgpd/bgp_bmp.c

Large diffs are not rendered by default.

24 changes: 19 additions & 5 deletions bgpd/bgp_bmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,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 @@ -280,12 +289,17 @@ struct bmp_bgp {
size_t mirror_qsizelimit;
};

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,
/* RFC7854 - 10.8 */
BMP_PEERDOWN_LOCAL_NOTIFY = 1,
BMP_PEERDOWN_LOCAL_FSM = 2,
BMP_PEERDOWN_REMOTE_NOTIFY = 3,
BMP_PEERDOWN_REMOTE_CLOSE = 4,
BMP_PEERDOWN_ENDMONITOR = 5,
/* RFC9069 - 8.4 */
BMP_PEERDOWN_LOCAL_TLV = 6,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this https://datatracker.ietf.org/doc/html/rfc7854#section-10.8 Peer Down type, is it defined somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

};

enum {
Expand Down
51 changes: 29 additions & 22 deletions bgpd/bgp_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,31 +641,11 @@ 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 *bgp_open_make(struct peer *peer, uint16_t send_holdtime, as_t local_as)
{
struct stream *s;
uint16_t send_holdtime;
as_t local_as;
struct peer *peer = connection->peer;
struct stream *s = stream_new(BGP_STANDARD_MESSAGE_MAX_PACKET_SIZE);
bool ext_opt_params = false;

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 = stream_new(BGP_STANDARD_MESSAGE_MAX_PACKET_SIZE);

/* Make open packet. */
bgp_packet_set_marker(s, BGP_MSG_OPEN);

Expand Down Expand Up @@ -704,6 +684,33 @@ void bgp_open_send(struct peer_connection *connection)
ext_opt_params ? " (Extended)" : "", BGP_VERSION_4,
local_as, send_holdtime, &peer->local_id);

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);

/* Dump packet if debug option is set. */
/* bgp_packet_dump (s); */
hook_call(bgp_packet_send, peer, BGP_MSG_OPEN, stream_get_endp(s), s);
Expand Down
1 change: 1 addition & 0 deletions bgpd/bgp_packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ 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
7 changes: 7 additions & 0 deletions bgpd/bgpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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 @@ -3929,6 +3930,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 Down Expand Up @@ -3957,6 +3961,9 @@ void bgp_instance_down(struct bgp *bgp)
/* Cleanup evpn instance state */
bgp_evpn_instance_down(bgp);

/* 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 @@ -880,6 +880,7 @@ DECLARE_HOOK(bgp_snmp_traps_config_write, (struct vty *vty), (vty));
DECLARE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
DECLARE_HOOK(bgp_hook_vrf_update, (struct vrf *vrf, bool enabled),
(vrf, enabled));
DECLARE_HOOK(bgp_instance_state, (struct bgp *bgp), (bgp));

/* Thread callback information */
struct afi_safi_info {
Expand Down
73 changes: 64 additions & 9 deletions tests/topotests/bgp_bmp/test_bgp_bmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,34 @@ def check_for_prefixes(expected_prefixes, bmp_log_type, policy, labels=None):
return True


def check_for_peer_message(expected_peers, bmp_log_type):
"""
Check for the presence of a peer up message for the peer
"""
global SEQ
# we care only about the new messages
messages = [
m for m in sorted(get_bmp_messages(), key=lambda d: d["seq"]) if m["seq"] > SEQ
]

# get the list of pairs (prefix, policy, seq) for the given message type
peers = [
m["peer_ip"]
for m in messages
if "peer_ip" in m.keys() and m["bmp_log_type"] == bmp_log_type
]

# check for prefixes
for ep in expected_peers:
if ep not in peers:
msg = "The peer {} is not present in the {} log messages."
logger.debug(msg.format(ep, bmp_log_type))
return False

SEQ = messages[-1]["seq"]
return True


def set_bmp_policy(tgen, node, asn, target, safi, policy, vrf=None):
"""
Configure the bmp policy.
Expand Down Expand Up @@ -234,15 +262,11 @@ def vpn_prefixes(policy):

prefixes = ["172.31.10.1/32", "2001::2222/128"]

if policy == PRE_POLICY:
# labels are not yet supported in adj-RIB-in. Do not test for the moment
labels = None
else:
# "label vpn export" value in r2/bgpd.conf
labels = {
"172.31.10.1/32": 102,
"2001::2222/128": 105,
}
# "label vpn export" value in r2/bgpd.conf
labels = {
"172.31.10.1/32": 102,
"2001::2222/128": 105,
}

# add prefixes
configure_prefixes(tgen, "r2", 65502, "unicast", prefixes, vrf="vrf1")
Expand Down Expand Up @@ -280,6 +304,20 @@ def check_for_log_file():
assert success, "The BMP server is not logging"


def test_peer_up():
"""
Checking for BMP peers up messages
"""

peers = ["192.168.0.2", "192:168::2"]

logger.info("checking for BMP peers up messages")

test_func = partial(check_for_peer_message, peers, "peer up")
success, _ = topotest.run_and_expect(test_func, True, wait=0.5)
assert success, "Checking the updated prefixes has been failed !."


def test_bmp_bgp_unicast():
"""
Add/withdraw bgp unicast prefixes and check the bmp logs.
Expand All @@ -302,6 +340,23 @@ def test_bmp_bgp_vpn():
vpn_prefixes(LOC_RIB)


def test_peer_down():
"""
Checking for BMP peers down messages
"""
tgen = get_topogen()

tgen.gears["r2"].vtysh_cmd("clear bgp *")

peers = ["192.168.0.2", "192:168::2"]

logger.info("checking for BMP peers down messages")

test_func = partial(check_for_peer_message, peers, "peer down")
success, _ = topotest.run_and_expect(test_func, True, wait=0.5)
assert success, "Checking the updated prefixes has been failed !."


if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))
Empty file.
23 changes: 23 additions & 0 deletions tests/topotests/bgp_bmp_vrf/r1/bgpd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
router bgp 65501 vrf vrf1
bgp router-id 192.168.0.1
bgp log-neighbor-changes
no bgp ebgp-requires-policy
neighbor 192.168.0.2 remote-as 65502
neighbor 192:168::2 remote-as 65502
!
bmp targets bmp1
bmp connect 192.0.2.10 port 1789 min-retry 100 max-retry 10000
exit
!

address-family ipv4 unicast
neighbor 192.168.0.2 activate
neighbor 192.168.0.2 soft-reconfiguration inbound
no neighbor 192:168::2 activate
exit-address-family
!
address-family ipv6 unicast
neighbor 192:168::2 activate
neighbor 192:168::2 soft-reconfiguration inbound
exit-address-family
!
7 changes: 7 additions & 0 deletions tests/topotests/bgp_bmp_vrf/r1/zebra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
interface r1-eth0
ip address 192.0.2.1/24
!
interface r1-eth1
ip address 192.168.0.1/24
ipv6 address 192:168::1/64
!
19 changes: 19 additions & 0 deletions tests/topotests/bgp_bmp_vrf/r2/bgpd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
router bgp 65502
bgp router-id 192.168.0.2
bgp log-neighbor-changes
no bgp ebgp-requires-policy
no bgp network import-check
neighbor 192.168.0.1 remote-as 65501
neighbor 192:168::1 remote-as 65501
!
address-family ipv4 unicast
neighbor 192.168.0.1 activate
no neighbor 192:168::1 activate
redistribute connected
exit-address-family
!
address-family ipv6 unicast
neighbor 192:168::1 activate
redistribute connected
exit-address-family
!
8 changes: 8 additions & 0 deletions tests/topotests/bgp_bmp_vrf/r2/zebra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
interface r2-eth0
ip address 192.168.0.2/24
ipv6 address 192:168::2/64
!
interface r2-eth1
ip address 172.31.0.2/24
ipv6 address 172:31::2/64
!
Loading
Loading