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

feat(anta): Added the test case to verify BGP NLRI prefixes #792

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

vitthalmagadum
Copy link
Contributor

Description

Verifies BGP IPv4 peer(s) consistency of NLRIs received and accepted in a BGP session.

Expected Results
----------------
* Success: The test will pass if the `nlrisReceived` equals `nlrisAccepted`, indicating that all received NLRIs were accepted..
* Failure: The test will fail if the `nlrisReceived` is not equal to `nlrisAccepted`, indicating that some NLRIs were rejected or filtered out.

Fixes #786

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have run pre-commit for code linting and typing (pre-commit run)
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes (tox -e testenv)

Comment on lines 1414 to 1415
* Success: The test will pass if the `nlrisReceived` equals `nlrisAccepted`, indicating that all received NLRIs were accepted..
* Failure: The test will fail if the `nlrisReceived` is not equal to `nlrisAccepted`, indicating that some NLRIs were rejected or filtered out.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Success: The test will pass if the `nlrisReceived` equals `nlrisAccepted`, indicating that all received NLRIs were accepted..
* Failure: The test will fail if the `nlrisReceived` is not equal to `nlrisAccepted`, indicating that some NLRIs were rejected or filtered out.
* Success: The test will pass if the `NLRI Rcd` equals `NLRI Acc`, indicating that all received NLRIs were accepted.
* Failure: The test will fail if the `NLRI Rcd` is not equal to `NLRI Acc`, indicating that some NLRIs were rejected or filtered out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

continue

# Verifies the NLRIs received is equal to accepted.
if (nlri_rec := get_value(peer_details, "ipv4Unicast.nlrisReceived")) != (nlri_acc := get_value(peer_details, "ipv4Unicast.nlrisAccepted")):
Copy link
Contributor

Choose a reason for hiding this comment

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

The ipv4Unicast is not static we can have different AFI.

wan1-dc1(config-router-bgp)#show bgp summary
BGP summary information for VRF default
Router identifier 10.100.254.1, local AS number 65000
Neighbor            AS Session State AFI/SAFI                AFI/SAFI State   NLRI Rcd   NLRI Acc
---------- ----------- ------------- ----------------------- -------------- ---------- ----------
10.255.0.1       65000 Established   IPv4 SR-TE              Negotiated              8          8
10.255.0.1       65000 Established   IPv4 Dps                Negotiated              9          9
10.255.0.1       65000 Established   L2VPN EVPN              Negotiated             52         52
10.255.0.1       65000 Established   Link State Link State   Negotiated              0          0
10.255.0.2       65000 Established   IPv4 SR-TE              Negotiated              8          8
10.255.0.2       65000 Established   IPv4 Dps                Negotiated              9          9
10.255.0.2       65000 Established   L2VPN EVPN              Negotiated             52         52
10.255.0.2       65000 Established   Link State Link State   Negotiated              0          0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added support for AFI and SAFI

# Verifies the NLRIs received is equal to accepted.
if (nlri_rec := get_value(peer_details, "ipv4Unicast.nlrisReceived")) != (nlri_acc := get_value(peer_details, "ipv4Unicast.nlrisAccepted")):
failures[peer_address] = {
vrf: f"The NLRIs received and accepted should be consistent, but found NLRI received `{nlri_rec}` and NLRI accepted `{nlri_acc}` instead."
Copy link
Contributor

Choose a reason for hiding this comment

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

As testcase description is clear what the test is so having The NLRIs received and accepted should be consistent, but found line for each peer is not ok as you are already mentioning it in self.result.is_failure

So just NLRI received {nlri_rec} and NLRI accepted {nlri_acc} is enough or {"NLRI received" "{nlri_rec}, "NLRI accepted": {nlri_acc}}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.


Expected Results
----------------
* Success: The test will pass if the `prefixReceived` equals `prefixAccepted`, indicating that all received prefix(s) were accepted.
Copy link
Contributor

Choose a reason for hiding this comment

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

prefixReceived and prefixAccepted seems to be json keys, please use text heading of command output in doc string and failure message to for ease of understanding

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

command_output = command.json_output
afi = command.params.afi
safi = command.params.safi if hasattr(command.params, "safi") else None
afi_vrf = command.params.vrf if hasattr(command.params, "vrf") else "default"
Copy link
Contributor

Choose a reason for hiding this comment

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

default is the default vrf then i dont think we need any condition to parse the vrf. Same for safi

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

bgp:
- VerifyBGPPeerPrefixes:
address_families:
- afi: ipv4
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we have to check for specific peer for specific AFI/SAFI. Please recheck.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated. Thanks!


# Update the peer details as per input peer addresses for verification.
if bgp_peers:
details: dict[Any, Any] = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use the more meaning full variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

Comment on lines 178 to 198
if (prefix_acc and prefix_rcv) == "Not Found":
failure[peer] = {"prefix received": prefix_rcv, "prefix accepted": prefix_acc}
continue
if prefix_rcv != prefix_acc:
failure[peer] = {"prefix received": prefix_rcv, "prefix accepted": prefix_acc}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (prefix_acc and prefix_rcv) == "Not Found":
failure[peer] = {"prefix received": prefix_rcv, "prefix accepted": prefix_acc}
continue
if prefix_rcv != prefix_acc:
failure[peer] = {"prefix received": prefix_rcv, "prefix accepted": prefix_acc}
if (prefix_acc and prefix_rcv) == "Not Found" or prefix_rcv != prefix_acc:
failure[peer] = {"prefix received": prefix_rcv, "prefix accepted": prefix_acc}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

continue

# Verify the received and accepted prefix(s).
failure_logs = _get_inconsistent_peers(peer_details, peers)
Copy link
Contributor

Choose a reason for hiding this comment

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

please separate out the variable name by input or actual peers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated. Thanks!!

Copy link
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Copy link
Contributor

Conflicts have been resolved. A maintainer will review the pull request shortly.

Comment on lines 167 to 174
"""Identify BGP peers with inconsistency of prefix(s) received and accepted in a BGP session.

bgp_peers: list of IPv4 address of a BGP peer to be verified. If not provided, test will verifies all the BGP peers.

Parameters
----------
peer_details: The BGP peer data dictionary.
bgp_peers: The list of IPv4 address of a BGP peer(s) to be verified.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please correct the doc string format.

@@ -678,4 +691,4 @@ anta.tests.routing:
- endpoint: 1.0.0.14/32
vias:
- type: ip
nexthop: 1.1.1.1
nexthop: 1.1.1.1
Copy link
Contributor

Choose a reason for hiding this comment

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

please add an empty line at the end

Copy link

codspeed-hq bot commented Oct 1, 2024

CodSpeed Performance Report

Merging #792 will not alter performance

Comparing vitthalmagadum:issue_786 (7594a4c) with main (fc644a1)

Summary

✅ 4 untouched benchmarks

"result": "failure",
"messages": [
"The following BGP address family(s), peers are not configured or prefix(s) received and accepted are not consistent:\n"
"{'ipv4': {'unicast': {'10.100.0.8': {'prefix received': 18, 'prefix accepted': 17}, '10.100.0.10': {'prefix received': 20, 'prefix accepted': 15}},"
Copy link
Contributor

Choose a reason for hiding this comment

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

please add the information of vrf in failure log

Copy link

sonarcloud bot commented Oct 4, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the test case to verify BGP NLRI prefixes
3 participants