summaryrefslogtreecommitdiffstats
path: root/tests/topotests/bgp_ebgp_requires_policy
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:53:30 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:53:30 +0000
commit2c7cac91ed6e7db0f6937923d2b57f97dbdbc337 (patch)
treec05dc0f8e6aa3accc84e3e5cffc933ed94941383 /tests/topotests/bgp_ebgp_requires_policy
parentInitial commit. (diff)
downloadfrr-upstream.tar.xz
frr-upstream.zip
Adding upstream version 8.4.4.upstream/8.4.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/topotests/bgp_ebgp_requires_policy')
-rw-r--r--tests/topotests/bgp_ebgp_requires_policy/__init__.py0
-rw-r--r--tests/topotests/bgp_ebgp_requires_policy/r1/bgpd.conf12
-rw-r--r--tests/topotests/bgp_ebgp_requires_policy/r1/zebra.conf9
-rw-r--r--tests/topotests/bgp_ebgp_requires_policy/r2/bgpd.conf5
-rw-r--r--tests/topotests/bgp_ebgp_requires_policy/r2/zebra.conf6
-rw-r--r--tests/topotests/bgp_ebgp_requires_policy/r3/bgpd.conf6
-rw-r--r--tests/topotests/bgp_ebgp_requires_policy/r3/zebra.conf9
-rw-r--r--tests/topotests/bgp_ebgp_requires_policy/r4/bgpd.conf5
-rw-r--r--tests/topotests/bgp_ebgp_requires_policy/r4/zebra.conf6
-rw-r--r--tests/topotests/bgp_ebgp_requires_policy/r5/bgpd.conf7
-rw-r--r--tests/topotests/bgp_ebgp_requires_policy/r5/zebra.conf9
-rw-r--r--tests/topotests/bgp_ebgp_requires_policy/r6/bgpd.conf4
-rw-r--r--tests/topotests/bgp_ebgp_requires_policy/r6/zebra.conf6
-rw-r--r--tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py171
14 files changed, 255 insertions, 0 deletions
diff --git a/tests/topotests/bgp_ebgp_requires_policy/__init__.py b/tests/topotests/bgp_ebgp_requires_policy/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/topotests/bgp_ebgp_requires_policy/__init__.py
diff --git a/tests/topotests/bgp_ebgp_requires_policy/r1/bgpd.conf b/tests/topotests/bgp_ebgp_requires_policy/r1/bgpd.conf
new file mode 100644
index 0000000..add37ee
--- /dev/null
+++ b/tests/topotests/bgp_ebgp_requires_policy/r1/bgpd.conf
@@ -0,0 +1,12 @@
+router bgp 65000
+ neighbor 192.168.255.2 remote-as 1000
+ neighbor 192.168.255.2 timers 3 10
+ neighbor 192.168.255.2 local-as 500
+ address-family ipv4 unicast
+ redistribute connected
+ neighbor 192.168.255.2 route-map outgoing out
+!
+ip prefix-list peer-out permit 172.16.255.254/32
+route-map outgoing permit 10
+ match ip address prefix-list peer-out
+!
diff --git a/tests/topotests/bgp_ebgp_requires_policy/r1/zebra.conf b/tests/topotests/bgp_ebgp_requires_policy/r1/zebra.conf
new file mode 100644
index 0000000..0a283c0
--- /dev/null
+++ b/tests/topotests/bgp_ebgp_requires_policy/r1/zebra.conf
@@ -0,0 +1,9 @@
+!
+interface lo
+ ip address 172.16.255.254/32
+!
+interface r1-eth0
+ ip address 192.168.255.1/24
+!
+ip forwarding
+!
diff --git a/tests/topotests/bgp_ebgp_requires_policy/r2/bgpd.conf b/tests/topotests/bgp_ebgp_requires_policy/r2/bgpd.conf
new file mode 100644
index 0000000..802c327
--- /dev/null
+++ b/tests/topotests/bgp_ebgp_requires_policy/r2/bgpd.conf
@@ -0,0 +1,5 @@
+router bgp 1000
+ no bgp ebgp-requires-policy
+ neighbor 192.168.255.1 remote-as 500
+ neighbor 192.168.255.1 timers 3 10
+!
diff --git a/tests/topotests/bgp_ebgp_requires_policy/r2/zebra.conf b/tests/topotests/bgp_ebgp_requires_policy/r2/zebra.conf
new file mode 100644
index 0000000..606c17b
--- /dev/null
+++ b/tests/topotests/bgp_ebgp_requires_policy/r2/zebra.conf
@@ -0,0 +1,6 @@
+!
+interface r2-eth0
+ ip address 192.168.255.2/24
+!
+ip forwarding
+!
diff --git a/tests/topotests/bgp_ebgp_requires_policy/r3/bgpd.conf b/tests/topotests/bgp_ebgp_requires_policy/r3/bgpd.conf
new file mode 100644
index 0000000..1280b42
--- /dev/null
+++ b/tests/topotests/bgp_ebgp_requires_policy/r3/bgpd.conf
@@ -0,0 +1,6 @@
+router bgp 65000
+ neighbor 192.168.255.2 remote-as 1000
+ neighbor 192.168.255.2 timers 3 10
+ neighbor 192.168.255.2 local-as 500
+ address-family ipv4 unicast
+ redistribute connected
diff --git a/tests/topotests/bgp_ebgp_requires_policy/r3/zebra.conf b/tests/topotests/bgp_ebgp_requires_policy/r3/zebra.conf
new file mode 100644
index 0000000..39499a1
--- /dev/null
+++ b/tests/topotests/bgp_ebgp_requires_policy/r3/zebra.conf
@@ -0,0 +1,9 @@
+!
+interface lo
+ ip address 172.16.255.254/32
+!
+interface r3-eth0
+ ip address 192.168.255.1/24
+!
+ip forwarding
+!
diff --git a/tests/topotests/bgp_ebgp_requires_policy/r4/bgpd.conf b/tests/topotests/bgp_ebgp_requires_policy/r4/bgpd.conf
new file mode 100644
index 0000000..802c327
--- /dev/null
+++ b/tests/topotests/bgp_ebgp_requires_policy/r4/bgpd.conf
@@ -0,0 +1,5 @@
+router bgp 1000
+ no bgp ebgp-requires-policy
+ neighbor 192.168.255.1 remote-as 500
+ neighbor 192.168.255.1 timers 3 10
+!
diff --git a/tests/topotests/bgp_ebgp_requires_policy/r4/zebra.conf b/tests/topotests/bgp_ebgp_requires_policy/r4/zebra.conf
new file mode 100644
index 0000000..b859115
--- /dev/null
+++ b/tests/topotests/bgp_ebgp_requires_policy/r4/zebra.conf
@@ -0,0 +1,6 @@
+!
+interface r4-eth0
+ ip address 192.168.255.2/24
+!
+ip forwarding
+!
diff --git a/tests/topotests/bgp_ebgp_requires_policy/r5/bgpd.conf b/tests/topotests/bgp_ebgp_requires_policy/r5/bgpd.conf
new file mode 100644
index 0000000..60b29f6
--- /dev/null
+++ b/tests/topotests/bgp_ebgp_requires_policy/r5/bgpd.conf
@@ -0,0 +1,7 @@
+router bgp 65000
+ no bgp ebgp-requires-policy
+ neighbor 192.168.255.2 remote-as 65000
+ neighbor 192.168.255.2 timers 3 10
+ address-family ipv4 unicast
+ redistribute connected
+!
diff --git a/tests/topotests/bgp_ebgp_requires_policy/r5/zebra.conf b/tests/topotests/bgp_ebgp_requires_policy/r5/zebra.conf
new file mode 100644
index 0000000..7ef77a6
--- /dev/null
+++ b/tests/topotests/bgp_ebgp_requires_policy/r5/zebra.conf
@@ -0,0 +1,9 @@
+!
+interface lo
+ ip address 172.16.255.254/32
+!
+interface r5-eth0
+ ip address 192.168.255.1/24
+!
+ip forwarding
+!
diff --git a/tests/topotests/bgp_ebgp_requires_policy/r6/bgpd.conf b/tests/topotests/bgp_ebgp_requires_policy/r6/bgpd.conf
new file mode 100644
index 0000000..7ad5d92
--- /dev/null
+++ b/tests/topotests/bgp_ebgp_requires_policy/r6/bgpd.conf
@@ -0,0 +1,4 @@
+router bgp 65000
+ neighbor 192.168.255.1 remote-as 65000
+ neighbor 192.168.255.1 timers 3 10
+!
diff --git a/tests/topotests/bgp_ebgp_requires_policy/r6/zebra.conf b/tests/topotests/bgp_ebgp_requires_policy/r6/zebra.conf
new file mode 100644
index 0000000..1c617c4
--- /dev/null
+++ b/tests/topotests/bgp_ebgp_requires_policy/r6/zebra.conf
@@ -0,0 +1,6 @@
+!
+interface r6-eth0
+ ip address 192.168.255.2/24
+!
+ip forwarding
+!
diff --git a/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py b/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py
new file mode 100644
index 0000000..e6fe22b
--- /dev/null
+++ b/tests/topotests/bgp_ebgp_requires_policy/test_bgp_ebgp_requires_policy.py
@@ -0,0 +1,171 @@
+#!/usr/bin/env python
+
+#
+# bgp_ebgp_requires_policy.py
+# Part of NetDEF Topology Tests
+#
+# Copyright (c) 2019 by
+# Donatas Abraitis <donatas.abraitis@gmail.com>
+#
+# Permission to use, copy, modify, and/or distribute this software
+# for any purpose with or without fee is hereby granted, provided
+# that the above copyright notice and this permission notice appear
+# in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
+# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+# OF THIS SOFTWARE.
+#
+
+"""
+bgp_ebgp_requires_policy.py:
+
+Test if eBGP sender without a filter applied to the peer is allowed
+to send advertisements.
+
+Scenario 1:
+ r1 has a filter applied for outgoing direction,
+ r2 receives 192.168.255.1/32.
+
+Scenario 2:
+ r3 hasn't a filter appied for outgoing direction,
+ r4 does not receive 192.168.255.1/32.
+
+Scenario 3:
+ r5 and r6 establish iBGP session which in turn should ignore
+ RFC8212. All routes for both directions MUST work.
+"""
+
+import os
+import sys
+import json
+import pytest
+import functools
+
+CWD = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(CWD, "../"))
+
+# pylint: disable=C0413
+from lib import topotest
+from lib.topogen import Topogen, TopoRouter, get_topogen
+from lib.topolog import logger
+
+pytestmark = [pytest.mark.bgpd]
+
+
+def build_topo(tgen):
+ for routern in range(1, 7):
+ tgen.add_router("r{}".format(routern))
+
+ # Scenario 1.
+ switch = tgen.add_switch("s1")
+ switch.add_link(tgen.gears["r1"])
+ switch.add_link(tgen.gears["r2"])
+
+ # Scenario 2.
+ switch = tgen.add_switch("s2")
+ switch.add_link(tgen.gears["r3"])
+ switch.add_link(tgen.gears["r4"])
+
+ # Scenario 3.
+ switch = tgen.add_switch("s3")
+ switch.add_link(tgen.gears["r5"])
+ switch.add_link(tgen.gears["r6"])
+
+
+def setup_module(mod):
+ tgen = Topogen(build_topo, mod.__name__)
+ tgen.start_topology()
+
+ router_list = tgen.routers()
+
+ for i, (rname, router) in enumerate(router_list.items(), 1):
+ router.load_config(
+ TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
+ )
+ router.load_config(
+ TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
+ )
+
+ tgen.start_router()
+
+
+def teardown_module(mod):
+ tgen = get_topogen()
+ tgen.stop_topology()
+
+
+def test_ebgp_requires_policy():
+ tgen = get_topogen()
+
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+
+ def _bgp_converge(router):
+ output = json.loads(
+ tgen.gears[router].vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")
+ )
+ expected = {"192.168.255.1": {"bgpState": "Established"}}
+ return topotest.json_cmp(output, expected)
+
+ def _bgp_has_routes(router):
+ output = json.loads(
+ tgen.gears[router].vtysh_cmd(
+ "show ip bgp neighbor 192.168.255.1 routes json"
+ )
+ )
+ expected = {"routes": {"172.16.255.254/32": [{"valid": True}]}}
+ return topotest.json_cmp(output, expected)
+
+ def _bgp_advertised_routes(router):
+ output = json.loads(
+ tgen.gears[router].vtysh_cmd(
+ "show ip bgp neighbor 192.168.255.2 advertised-routes json"
+ )
+ )
+ expected = {
+ "advertisedRoutes": {},
+ "totalPrefixCounter": 0,
+ "filteredPrefixCounter": 0,
+ }
+ return topotest.json_cmp(output, expected)
+
+ # Scenario 1.
+ logger.info("Scenario 1: r2 receives 192.168.255.1/32 from r1")
+ test_func = functools.partial(_bgp_converge, "r2")
+ success, result = topotest.run_and_expect(test_func, None, count=120, wait=0.5)
+ assert success is True, "Failed bgp convergence (r2)"
+
+ test_func = functools.partial(_bgp_has_routes, "r2")
+ success, result = topotest.run_and_expect(test_func, None, count=120, wait=0.5)
+ assert success is True, "r2 does not receive 192.168.255.1/32"
+
+ # Scenario 2.
+ logger.info("Scenario 2: r3 must not send 192.168.255.1/32 to r4")
+ test_func = functools.partial(_bgp_converge, "r4")
+ success, result = topotest.run_and_expect(test_func, None, count=120, wait=0.5)
+ assert success is True, "Failed bgp convergence (r4)"
+
+ test_func = functools.partial(_bgp_advertised_routes, "r3")
+ success, result = topotest.run_and_expect(test_func, None, count=120, wait=0.5)
+ assert success is True, "r3 announced 192.168.255.1/32 to r4"
+
+ # Scenario 3.
+ logger.info("Scenario 3: r6 receives 192.168.255.1/32 from r5 (iBGP)")
+ test_func = functools.partial(_bgp_converge, "r6")
+ success, result = topotest.run_and_expect(test_func, None, count=120, wait=0.5)
+ assert success is True, "Failed bgp convergence (r6)"
+
+ test_func = functools.partial(_bgp_has_routes, "r6")
+ success, result = topotest.run_and_expect(test_func, None, count=120, wait=0.5)
+ assert success is True, "r6 does not receive 192.168.255.1/32"
+
+
+if __name__ == "__main__":
+ args = ["-s"] + sys.argv[1:]
+ sys.exit(pytest.main(args))