Skip to content

Commit

Permalink
tests: Check if set metric aigp works
Browse files Browse the repository at this point in the history
Signed-off-by: Donatas Abraitis <[email protected]>
  • Loading branch information
ton31337 committed Oct 8, 2024
1 parent a3d2d30 commit 6c9f358
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
7 changes: 7 additions & 0 deletions tests/topotests/bgp_aigp/r1/bgpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ router bgp 65001
neighbor 192.168.18.8 route-map r8 out
exit-address-family
!
ip prefix-list p71 seq 5 permit 10.0.0.71/32
ip prefix-list p72 seq 5 permit 10.0.0.72/32
!
route-map r8 permit 10
match ip address prefix-list p71
set metric igp
route-map r8 permit 20
match ip address prefix-list p72
set metric aigp
exit
36 changes: 17 additions & 19 deletions tests/topotests/bgp_aigp/test_bgp_aigp.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
r1 receives routes with aigp-metric TLV 111,131 and 112,132 appropriately.
r1 advertises MED from IGP protocol (set metric igp) to r8.
r1 advertises MED from AIGP (set metric aigp) to r8.
"""

import os
Expand Down Expand Up @@ -136,9 +138,16 @@ def _bgp_check_aigp_metric(router, prefix, aigp):
expected = {"paths": [{"aigpMetric": aigp, "valid": True}]}
return topotest.json_cmp(output, expected)

def _bgp_check_received_med(med):
output = json.loads(r8.vtysh_cmd("show bgp ipv4 unicast 10.0.0.71/32 json"))
expected = {"paths": [{"metric": med, "valid": True}]}
def _bgp_check_received_med():
output = json.loads(
r8.vtysh_cmd("show bgp ipv4 unicast 10.0.0.64/28 longer-prefixes json")
)
expected = {
"routes": {
"10.0.0.71/32": [{"valid": True, "metric": 20}],
"10.0.0.72/32": [{"valid": True, "metric": 112}],
}
}
return topotest.json_cmp(output, expected)

def _bgp_check_aigp_metric_bestpath():
Expand Down Expand Up @@ -222,23 +231,12 @@ def _bgp_check_aigp_metric_bestpath():
_, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
assert result is None, "AIGP attribute is not considered in best-path selection"

# r8, check if MED is set to 20 (derived from `set metric igp`)
test_func = functools.partial(_bgp_check_received_med, 20)
_, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
assert result is None, "MED attribute value is not 20"

r1.vtysh_cmd(
"""
configure terminal
route-map r8 permit 10
set metric aigp
"""
)

# r8, check if MED is set to 111 (derived from `set metric aigp`)
test_func = functools.partial(_bgp_check_received_med, 111)
# r8, check if MED is set derived from `set metric igp`, and `set metric aigp`
test_func = functools.partial(_bgp_check_received_med)
_, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
assert result is None, "MED attribute value is not 111"
assert (
result is None
), "MED attribute values are not derived from `set metric [a]igp`"


if __name__ == "__main__":
Expand Down

0 comments on commit 6c9f358

Please sign in to comment.