Skip to content

Commit

Permalink
bgpd: apply frrbot
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Younsi <[email protected]>
  • Loading branch information
mxyns committed Nov 12, 2024
1 parent 706e774 commit f49f7cf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
7 changes: 3 additions & 4 deletions bgpd/bgp_bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1903,8 +1903,7 @@ static bool bmp_wrqueue_locrib(struct bmp *bmp, struct pullwr *pullwr)

/* retrieve info about the selected path
*/
bool is_vpn = (afi == AFI_L2VPN && safi == SAFI_EVPN) ||
(safi == SAFI_MPLS_VPN);
bool is_vpn = (afi == AFI_L2VPN && safi == SAFI_EVPN) || (safi == SAFI_MPLS_VPN);

struct prefix_rd *prd = is_vpn ? &bqe->rd : NULL;

Expand Down Expand Up @@ -1933,7 +1932,6 @@ static bool bmp_wrqueue_locrib(struct bmp *bmp, struct pullwr *pullwr)
/* loc-rib configured and path is selected */
if (CHECK_FLAG(flags, BMP_MON_LOC_RIB) &&
CHECK_FLAG(bpi->flags, BGP_PATH_SELECTED | BGP_PATH_MULTIPATH)) {

bmp_monitor(bmp, peer, 0, BMP_PEER_TYPE_LOC_RIB_INSTANCE, &bqe->p, prd,
bpi->attr, afi, safi, addpath_rx_id,
bpi->extra ? bpi->extra->bgp_rib_uptime : (time_t)(-1L),
Expand Down Expand Up @@ -4094,7 +4092,8 @@ static int bmp_vrf_itf_state_changed(struct bgp *bgp, struct interface *itf)
bmpbgp = bmp_bgp_find(bgp);
new_state = if_is_up(itf) ? vrf_state_up : vrf_state_down;
if (bmp_bgp_update_vrf_status(bmpbgp, new_state))
bmp_send_all_safe(bmpbgp, bmp_peerstate(bgp->peer_self, new_state == vrf_state_down));
bmp_send_all_safe(bmpbgp,
bmp_peerstate(bgp->peer_self, new_state == vrf_state_down));

return 0;
}
Expand Down
51 changes: 26 additions & 25 deletions tests/topotests/bgp_bmp/test_bgp_bmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def update_expected_files(bmp_actual, expected_prefixes, bmp_log_type, policy, s

# ls /tmp/show*json | while read file; do egrep -v 'prefix|network|metric|ocPrf|version|weight|peerId|vrf|Version|valid|Reason|fe80' $file >$(basename $file); echo >> $(basename $file); done
with open(
f"/tmp/show-bgp-ipv4-{bmp_log_type}-step{step}.json", "w"
f"/tmp/show-bgp-ipv4-{bmp_log_type}-step{step}.json", "w"
) as json_file:
json.dump(filtered_out, json_file, indent=4)

Expand All @@ -215,7 +215,7 @@ def update_expected_files(bmp_actual, expected_prefixes, bmp_log_type, policy, s
continue
filtered_out["routes"]["routeDistinguishers"][rd][pfx] = None
with open(
f"/tmp/show-bgp-ipv6-{bmp_log_type}-step{step}.json", "w"
f"/tmp/show-bgp-ipv6-{bmp_log_type}-step{step}.json", "w"
) as json_file:
json.dump(filtered_out, json_file, indent=4)

Expand Down Expand Up @@ -285,11 +285,11 @@ def check_for_prefixes(expected_prefixes, bmp_log_type, policy, step):
actual = {}
for m in messages:
if (
"bmp_log_type" in m.keys()
and "ip_prefix" in m.keys()
and m["ip_prefix"] in expected_prefixes
and m["bmp_log_type"] == bmp_log_type
and m["policy"] == policy
"bmp_log_type" in m.keys()
and "ip_prefix" in m.keys()
and m["ip_prefix"] in expected_prefixes
and m["bmp_log_type"] == bmp_log_type
and m["policy"] == policy
):
policy_dict = actual.setdefault(m["policy"], {})
bmp_log_type_dict = policy_dict.setdefault(m["bmp_log_type"], {})
Expand All @@ -300,29 +300,29 @@ def check_for_prefixes(expected_prefixes, bmp_log_type, policy, step):
for k, v in sorted(m.items())
# filter out variable keys
if k not in ["timestamp", "seq", "nxhp_link-local"]
and (
# When policy is loc-rib, the peer-distinguisher is 0:0
# for the default VRF or the RD if any or the 0:<vrf_id>.
# 0:<vrf_id> is used to distinguished. RFC7854 says: "If the
# peer is a "Local Instance Peer", it is set to a unique,
# locally defined value." The value is not tested because it
# is variable.
k != "peer_distinguisher"
or policy != LOC_RIB
or v == "0:0"
or not v.startswith("0:")
)
and (
# When policy is loc-rib, the peer-distinguisher is 0:0
# for the default VRF or the RD if any or the 0:<vrf_id>.
# 0:<vrf_id> is used to distinguished. RFC7854 says: "If the
# peer is a "Local Instance Peer", it is set to a unique,
# locally defined value." The value is not tested because it
# is variable.
k != "peer_distinguisher"
or policy != LOC_RIB
or v == "0:0"
or not v.startswith("0:")
)
}

logger.debug(f"messages = {messages}")
logger.debug(f"actual = {actual}")

# build expected JSON files
if (
UPDATE_EXPECTED_JSON
and actual
and set(actual.get(policy, {}).get(bmp_log_type, {}).keys())
== set(expected_prefixes)
UPDATE_EXPECTED_JSON
and actual
and set(actual.get(policy, {}).get(bmp_log_type, {}).keys())
== set(expected_prefixes)
):
update_expected_files(actual, expected_prefixes, bmp_log_type, policy, step)

Expand Down Expand Up @@ -373,7 +373,9 @@ def configure_prefixes(tgen, node, asn, safi, prefixes, vrf=None, update=True):
"{}network {}\n".format(withdraw, ip),
"exit-address-family\n",
]
logger.debug("[{}] setting prefix: ipv{} {} {}".format(node, ip.version, safi, ip))
logger.debug(
"[{}] setting prefix: ipv{} {} {}".format(node, ip.version, safi, ip)
)
tgen.gears[node].vtysh_cmd("".join(cmd))


Expand Down Expand Up @@ -486,7 +488,6 @@ def test_bmp_bgp_vpn():
_test_prefixes(LOC_RIB, vrf="vrf1", step=2)



def multipath_unicast_prefixes(policy, step, vrf=None):
"""
Setup the BMP monitor policy, Add and withdraw ipv4/v6 prefixes.
Expand Down

0 comments on commit f49f7cf

Please sign in to comment.