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

refactor(anta): Refactor the VerifyBFDPeersIntervals test to add detection time #858

Merged
merged 5 commits into from
Jan 8, 2025
Merged
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
4 changes: 4 additions & 0 deletions anta/input_models/bfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class BFDPeer(BaseModel):
"""Multiplier of BFD peer. Required field in the `VerifyBFDPeersIntervals` test."""
protocols: list[BfdProtocol] | None = None
"""List of protocols to be verified. Required field in the `VerifyBFDPeersRegProtocols` test."""
detection_time: int | None = None
"""Detection time of BFD peer in milliseconds. Defines how long to wait without receiving BFD packets before declaring the peer session as down.

Optional field in the `VerifyBFDPeersIntervals` test."""

def __str__(self) -> str:
"""Return a human-readable string representation of the BFDPeer for reporting."""
Expand Down
9 changes: 9 additions & 0 deletions anta/tests/bfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,18 @@ class VerifyBFDPeersIntervals(AntaTest):
1. Confirms that the specified VRF is configured.
2. Verifies that the peer exists in the BFD configuration.
3. Confirms that BFD peer is correctly configured with the `Transmit interval, Receive interval and Multiplier`.
4. Verifies that BFD peer is correctly configured with the `Detection time`, if provided.

Expected Results
----------------
* Success: If all of the following conditions are met:
- All specified peers are found in the BFD configuration within the specified VRF.
- All BFD peers are correctly configured with the `Transmit interval, Receive interval and Multiplier`.
- If provided, the `Detection time` is correctly configured.
* Failure: If any of the following occur:
- A specified peer is not found in the BFD configuration within the specified VRF.
- Any BFD peer not correctly configured with the `Transmit interval, Receive interval and Multiplier`.
- Any BFD peer is not correctly configured with `Detection time`, if provided.

Examples
--------
Expand All @@ -125,6 +128,7 @@ class VerifyBFDPeersIntervals(AntaTest):
tx_interval: 1200
rx_interval: 1200
multiplier: 3
detection_time: 3600
```
"""

Expand All @@ -151,6 +155,7 @@ def test(self) -> None:
tx_interval = bfd_peer.tx_interval
rx_interval = bfd_peer.rx_interval
multiplier = bfd_peer.multiplier
detect_time = bfd_peer.detection_time
carl-baillargeon marked this conversation as resolved.
Show resolved Hide resolved

# Check if BFD peer configured
bfd_output = get_value(
Expand All @@ -166,6 +171,7 @@ def test(self) -> None:
bfd_details = bfd_output.get("peerStatsDetail", {})
op_tx_interval = bfd_details.get("operTxInterval") // 1000
op_rx_interval = bfd_details.get("operRxInterval") // 1000
op_detection_time = bfd_details.get("detectTime") // 1000
detect_multiplier = bfd_details.get("detectMult")

if op_tx_interval != tx_interval:
Expand All @@ -177,6 +183,9 @@ def test(self) -> None:
if detect_multiplier != multiplier:
self.result.is_failure(f"{bfd_peer} - Incorrect Multiplier - Expected: {multiplier} Actual: {detect_multiplier}")

if detect_time and op_detection_time != detect_time:
self.result.is_failure(f"{bfd_peer} - Incorrect Detection Time - Expected: {detect_time} Actual: {op_detection_time}")


class VerifyBFDPeersHealth(AntaTest):
"""Verifies the health of IPv4 BFD peers across all VRFs.
Expand Down
1 change: 1 addition & 0 deletions examples/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ anta.tests.bfd:
tx_interval: 1200
rx_interval: 1200
multiplier: 3
detection_time: 3600
- VerifyBFDPeersRegProtocols:
# Verifies the registered routing protocol of IPv4 BFD peer sessions.
bfd_peers:
Expand Down
119 changes: 117 additions & 2 deletions tests/units/anta_tests/test_bfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"operTxInterval": 1200000,
"operRxInterval": 1200000,
"detectMult": 3,
"detectTime": 3600000,
}
}
}
Expand All @@ -42,6 +43,7 @@
"operTxInterval": 1200000,
"operRxInterval": 1200000,
"detectMult": 3,
"detectTime": 3600000,
}
}
}
Expand All @@ -59,6 +61,55 @@
},
"expected": {"result": "success"},
},
{
"name": "success-detection-time",
"test": VerifyBFDPeersIntervals,
"eos_data": [
{
"vrfs": {
"default": {
"ipv4Neighbors": {
"192.0.255.7": {
"peerStats": {
"": {
"peerStatsDetail": {
"operTxInterval": 1200000,
"operRxInterval": 1200000,
"detectMult": 3,
"detectTime": 3600000,
}
}
}
}
}
},
"MGMT": {
"ipv4Neighbors": {
"192.0.255.70": {
"peerStats": {
"": {
"peerStatsDetail": {
"operTxInterval": 1200000,
"operRxInterval": 1200000,
"detectMult": 3,
"detectTime": 3600000,
}
}
}
}
}
},
}
}
],
"inputs": {
"bfd_peers": [
{"peer_address": "192.0.255.7", "vrf": "default", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3, "detection_time": 3600},
{"peer_address": "192.0.255.70", "vrf": "MGMT", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3, "detection_time": 3600},
]
},
"expected": {"result": "success"},
},
{
"name": "failure-no-peer",
"test": VerifyBFDPeersIntervals,
Expand All @@ -74,6 +125,7 @@
"operTxInterval": 1200000,
"operRxInterval": 1200000,
"detectMult": 3,
"detectTime": 3600000,
}
}
}
Expand All @@ -89,6 +141,7 @@
"operTxInterval": 1200000,
"operRxInterval": 1200000,
"detectMult": 3,
"detectTime": 3600000,
}
}
}
Expand All @@ -100,8 +153,8 @@
],
"inputs": {
"bfd_peers": [
{"peer_address": "192.0.255.7", "vrf": "CS", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3},
{"peer_address": "192.0.255.70", "vrf": "MGMT", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3},
{"peer_address": "192.0.255.7", "vrf": "CS", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3, "detection_time": 3600},
{"peer_address": "192.0.255.70", "vrf": "MGMT", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3, "detection_time": 3600},
]
},
"expected": {
Expand All @@ -127,6 +180,7 @@
"operTxInterval": 1300000,
"operRxInterval": 1200000,
"detectMult": 4,
"detectTime": 4000000,
}
}
}
Expand All @@ -142,6 +196,7 @@
"operTxInterval": 120000,
"operRxInterval": 120000,
"detectMult": 5,
"detectTime": 4000000,
}
}
}
Expand All @@ -168,6 +223,66 @@
],
},
},
{
"name": "failure-incorrect-timers-with-detection-time",
"test": VerifyBFDPeersIntervals,
"eos_data": [
{
"vrfs": {
"default": {
"ipv4Neighbors": {
"192.0.255.7": {
"peerStats": {
"": {
"peerStatsDetail": {
"operTxInterval": 1300000,
"operRxInterval": 1200000,
"detectMult": 4,
"detectTime": 4000000,
}
}
}
}
}
},
"MGMT": {
"ipv4Neighbors": {
"192.0.255.70": {
"peerStats": {
"": {
"peerStatsDetail": {
"operTxInterval": 120000,
"operRxInterval": 120000,
"detectMult": 5,
"detectTime": 4000000,
}
}
}
}
}
},
}
}
],
"inputs": {
"bfd_peers": [
{"peer_address": "192.0.255.7", "vrf": "default", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3, "detection_time": 3600},
{"peer_address": "192.0.255.70", "vrf": "MGMT", "tx_interval": 1200, "rx_interval": 1200, "multiplier": 3, "detection_time": 3600},
]
},
"expected": {
"result": "failure",
"messages": [
"Peer: 192.0.255.7 VRF: default - Incorrect Transmit interval - Expected: 1200 Actual: 1300",
"Peer: 192.0.255.7 VRF: default - Incorrect Multiplier - Expected: 3 Actual: 4",
"Peer: 192.0.255.7 VRF: default - Incorrect Detection Time - Expected: 3600 Actual: 4000",
"Peer: 192.0.255.70 VRF: MGMT - Incorrect Transmit interval - Expected: 1200 Actual: 120",
"Peer: 192.0.255.70 VRF: MGMT - Incorrect Receive interval - Expected: 1200 Actual: 120",
"Peer: 192.0.255.70 VRF: MGMT - Incorrect Multiplier - Expected: 3 Actual: 5",
"Peer: 192.0.255.70 VRF: MGMT - Incorrect Detection Time - Expected: 3600 Actual: 4000",
],
},
},
{
"name": "success",
"test": VerifyBFDSpecificPeers,
Expand Down
Loading