]> git.puffer.fish Git - matthieu/frr.git/commitdiff
tests: Check if MED can be derived from `set metric igp|aigp`
authorDonatas Abraitis <donatas@opensourcerouting.org>
Tue, 8 Oct 2024 18:36:13 +0000 (21:36 +0300)
committerDonatas Abraitis <donatas@opensourcerouting.org>
Tue, 15 Oct 2024 14:42:51 +0000 (17:42 +0300)
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
tests/topotests/bgp_aigp/r1/bgpd.conf
tests/topotests/bgp_aigp/r1/zebra.conf
tests/topotests/bgp_aigp/r8/bgpd.conf [new file with mode: 0644]
tests/topotests/bgp_aigp/r8/zebra.conf [new file with mode: 0644]
tests/topotests/bgp_aigp/test_bgp_aigp.py

index 74a0215bc47608adee9324fefac730291f72b398..d99192421a395074ed912e532a5b5e9606af69cb 100644 (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
index 0ed22d37be8b964c1be009ae65c07b2dd96eb5c1..7ac4bb5de9a3fc4f04981765026fafdba864ff67 100644 (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
+!
diff --git a/tests/topotests/bgp_aigp/r8/bgpd.conf b/tests/topotests/bgp_aigp/r8/bgpd.conf
new file mode 100644 (file)
index 0000000..c50c3ce
--- /dev/null
@@ -0,0 +1,4 @@
+router bgp 65008
+ no bgp ebgp-requires-policy
+ neighbor 192.168.18.1 remote-as external
+!
diff --git a/tests/topotests/bgp_aigp/r8/zebra.conf b/tests/topotests/bgp_aigp/r8/zebra.conf
new file mode 100644 (file)
index 0000000..f754527
--- /dev/null
@@ -0,0 +1,4 @@
+!
+interface r8-eth0
+ ip address 192.168.18.8/24
+!
index 0d859adc53f4cf3150cdc369f6975d2d24ffd5d4..92b54d0ae102cf61e1be9249dcc66066e7104969 100644 (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:]