]> git.puffer.fish Git - matthieu/frr.git/commitdiff
tests: Check if BLACKHOLE community prefixes are visible inside local AS
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Sun, 24 Jan 2021 08:59:27 +0000 (10:59 +0200)
committerDonatas Abraitis <donatas.abraitis@gmail.com>
Mon, 25 Jan 2021 07:11:01 +0000 (09:11 +0200)
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
tests/topotests/bgp_blackhole_community/r2/bgpd.conf
tests/topotests/bgp_blackhole_community/r2/zebra.conf
tests/topotests/bgp_blackhole_community/r4/bgpd.conf [new file with mode: 0644]
tests/topotests/bgp_blackhole_community/r4/zebra.conf [new file with mode: 0644]
tests/topotests/bgp_blackhole_community/test_bgp_blackhole_community.py

index a4fb45e1ff1e9d74809848719a07d1b048ee2ca8..5a69b99810cd2bc9748d1d697c614f4c980e3fce 100644 (file)
@@ -3,4 +3,5 @@ router bgp 65002
   no bgp ebgp-requires-policy
   neighbor r2-eth0 interface remote-as external
   neighbor r2-eth1 interface remote-as external
+  neighbor r2-eth2 interface remote-as internal
 !
index 307e5187ca7c4bfea42f183209f708e6282e9348..cf6fb6d9848cde1517ae9df4c02d6f18e0964b09 100644 (file)
@@ -5,5 +5,8 @@ interface r2-eth0
 interface r2-eth1
  ip address 192.168.1.1/24
 !
+interface r2-eth2
+ ip address 192.168.2.1/24
+!
 ip forwarding
 !
diff --git a/tests/topotests/bgp_blackhole_community/r4/bgpd.conf b/tests/topotests/bgp_blackhole_community/r4/bgpd.conf
new file mode 100644 (file)
index 0000000..40dd72f
--- /dev/null
@@ -0,0 +1,5 @@
+!
+router bgp 65002
+  no bgp ebgp-requires-policy
+  neighbor r4-eth0 interface remote-as internal
+!
diff --git a/tests/topotests/bgp_blackhole_community/r4/zebra.conf b/tests/topotests/bgp_blackhole_community/r4/zebra.conf
new file mode 100644 (file)
index 0000000..e2ccaed
--- /dev/null
@@ -0,0 +1,6 @@
+!
+interface r4-eth0
+ ip address 192.168.2.2/24
+!
+ip forwarding
+!
index b61ad354e2af3a05824713ee610dfd0faee718a6..a856c9278fd6833a7febc95aa30a00f73846ee3d 100644 (file)
@@ -21,7 +21,7 @@
 
 """
 Test if 172.16.255.254/32 tagged with BLACKHOLE community is not
-re-advertised downstream.
+re-advertised downstream outside local AS.
 """
 
 import os
@@ -38,13 +38,14 @@ from lib import topotest
 from lib.topogen import Topogen, TopoRouter, get_topogen
 from lib.topolog import logger
 from mininet.topo import Topo
+from lib.common_config import step
 
 
 class TemplateTopo(Topo):
     def build(self, *_args, **_opts):
         tgen = get_topogen(self)
 
-        for routern in range(1, 4):
+        for routern in range(1, 5):
             tgen.add_router("r{}".format(routern))
 
         switch = tgen.add_switch("s1")
@@ -55,6 +56,10 @@ class TemplateTopo(Topo):
         switch.add_link(tgen.gears["r2"])
         switch.add_link(tgen.gears["r3"])
 
+        switch = tgen.add_switch("s3")
+        switch.add_link(tgen.gears["r2"])
+        switch.add_link(tgen.gears["r4"])
+
 
 def setup_module(mod):
     tgen = Topogen(TemplateTopo, mod.__name__)
@@ -88,10 +93,10 @@ def test_bgp_blackhole_community():
         output = json.loads(
             tgen.gears["r2"].vtysh_cmd("show ip bgp 172.16.255.254/32 json")
         )
-        expected = {"paths": [{"community": {"list": ["blackhole", "noAdvertise"]}}]}
+        expected = {"paths": [{"community": {"list": ["blackhole", "noExport"]}}]}
         return topotest.json_cmp(output, expected)
 
-    def _bgp_no_advertise():
+    def _bgp_no_advertise_ebgp():
         output = json.loads(
             tgen.gears["r2"].vtysh_cmd(
                 "show ip bgp neighbor r2-eth1 advertised-routes json"
@@ -105,15 +110,43 @@ def test_bgp_blackhole_community():
 
         return topotest.json_cmp(output, expected)
 
+    def _bgp_no_advertise_ibgp():
+        output = json.loads(
+            tgen.gears["r2"].vtysh_cmd(
+                "show ip bgp neighbor r2-eth2 advertised-routes json"
+            )
+        )
+        expected = {
+            "advertisedRoutes": {"172.16.255.254/32": {}},
+            "totalPrefixCounter": 2,
+        }
+
+        return topotest.json_cmp(output, expected)
+
     test_func = functools.partial(_bgp_converge)
     success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
 
     assert result is None, 'Failed bgp convergence in "{}"'.format(tgen.gears["r2"])
 
-    test_func = functools.partial(_bgp_no_advertise)
+    step("Check if 172.16.255.254/32 is not advertised to eBGP peers")
+
+    test_func = functools.partial(_bgp_no_advertise_ebgp)
+    success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
+
+    assert (
+        result is None
+    ), 'Advertised blackhole tagged prefix to eBGP peers in "{}"'.format(
+        tgen.gears["r2"]
+    )
+
+    step("Check if 172.16.255.254/32 is advertised to iBGP peers")
+
+    test_func = functools.partial(_bgp_no_advertise_ibgp)
     success, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
 
-    assert result is None, 'Advertised blackhole tagged prefix in "{}"'.format(
+    assert (
+        result is None
+    ), 'Withdrawn blackhole tagged prefix to iBGP peers in "{}"'.format(
         tgen.gears["r2"]
     )