tests: Check if MED can be derived from set metric igp|aigp

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
This commit is contained in:
Donatas Abraitis 2024-10-08 21:36:13 +03:00
parent f677fc8db3
commit 8d39cfd613
5 changed files with 51 additions and 1 deletions

View file

@ -9,4 +9,13 @@ router bgp 65001
neighbor 10.0.0.3 timers 1 3
neighbor 10.0.0.3 timers connect 1
neighbor 10.0.0.3 update-source lo
neighbor 192.168.18.8 remote-as external
neighbor 192.168.18.8 timers 1 3
neighbor 192.168.18.8 timers connect 1
address-family ipv4
neighbor 192.168.18.8 route-map r8 out
exit-address-family
!
route-map r8 permit 10
set metric igp
exit

View file

@ -8,3 +8,6 @@ interface r1-eth0
interface r1-eth1
ip address 192.168.13.1/24
!
interface r1-eth2
ip address 192.168.18.1/24
!

View file

@ -0,0 +1,4 @@
router bgp 65008
no bgp ebgp-requires-policy
neighbor 192.168.18.1 remote-as external
!

View file

@ -0,0 +1,4 @@
!
interface r8-eth0
ip address 192.168.18.8/24
!

View file

@ -15,6 +15,8 @@ r2 and r3 receives those routes with aigp-metric TLV increased by 20,
and 10 appropriately.
r1 receives routes with aigp-metric TLV 81, 91 and 82, 92 respectively.
r1 advertises MED from IGP protocol (set metric igp) to r8.
"""
import os
@ -34,7 +36,7 @@ pytestmark = [pytest.mark.bgpd]
def build_topo(tgen):
for routern in range(1, 8):
for routern in range(1, 9):
tgen.add_router("r{}".format(routern))
switch = tgen.add_switch("s1")
@ -65,6 +67,10 @@ def build_topo(tgen):
switch.add_link(tgen.gears["r6"])
switch.add_link(tgen.gears["r7"])
switch = tgen.add_switch("s8")
switch.add_link(tgen.gears["r1"])
switch.add_link(tgen.gears["r8"])
def setup_module(mod):
tgen = Topogen(build_topo, mod.__name__)
@ -102,6 +108,7 @@ def test_bgp_aigp():
r3 = tgen.gears["r3"]
r4 = tgen.gears["r4"]
r5 = tgen.gears["r5"]
r8 = tgen.gears["r8"]
def _bgp_converge():
output = json.loads(r1.vtysh_cmd("show bgp ipv4 unicast 10.0.0.71/32 json"))
@ -143,6 +150,11 @@ def test_bgp_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}]}
return topotest.json_cmp(output, expected)
def _bgp_check_aigp_metric_bestpath():
output = json.loads(
r1.vtysh_cmd(
@ -252,6 +264,24 @@ def test_bgp_aigp():
_, 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)
_, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
assert result is None, "MED attribute value is not 111"
if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]