From c27ad092a8ee3b8f7bde65f25c183f90abc9f494 Mon Sep 17 00:00:00 2001 From: Chromico Rek Date: Sat, 23 Jul 2022 01:28:01 +0400 Subject: [PATCH] topotato: bgp default originate route map match Authored-by: Chromico Rek Signed-off-by: David Lamparter --- test_bgp_default-originate_route-map_match.py | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 test_bgp_default-originate_route-map_match.py diff --git a/test_bgp_default-originate_route-map_match.py b/test_bgp_default-originate_route-map_match.py new file mode 100644 index 0000000..39e14f3 --- /dev/null +++ b/test_bgp_default-originate_route-map_match.py @@ -0,0 +1,114 @@ +from topotato import * + +""" +Test if default-originate works with ONLY match operations. +""" + + +@topology_fixture() +def allproto_topo(topo): + """ + [ r1 ] + | + { s1 } + | + [ r2 ] + + """ + topo.router("r1").lo_ip4.append("172.16.255.254/32") + topo.router("r1").iface_to("s1").ip4.append("192.168.255.1/24") + topo.router("r2").iface_to("s1").ip4.append("192.168.255.2/24") + + +class Configs(FRRConfigs): + routers = ["r1", "r2"] + + zebra = """ + #% extends "boilerplate.conf" + #% block main + #% if router.name == 'r1' + interface lo + ip address {{ routers.r1.lo_ip4[0] }} + ! + #% endif + #% for iface in router.ifaces + interface {{ iface.ifname }} + ip address {{ iface.ip4[0] }} + ! + #% endfor + ip forwarding + ! + #% endblock + """ + + bgpd = """ + #% block main + #% if router.name == 'r2' + router bgp 65001 + no bgp ebgp-requires-policy + neighbor {{ routers.r1.ifaces[0].ip4[0].ip }} remote-as 65000 + neighbor {{ routers.r1.ifaces[0].ip4[0].ip }} timers 3 10 + address-family ipv4 unicast + redistribute connected + exit-address-family + ! + #% elif router.name == 'r1' + router bgp 65000 + no bgp ebgp-requires-policy + neighbor {{ routers.r2.ifaces[0].ip4[0].ip }} remote-as 65001 + neighbor {{ routers.r2.ifaces[0].ip4[0].ip }} timers 3 10 + address-family ipv4 unicast + redistribute connected + network 192.168.13.0/24 route-map internal + neighbor {{ routers.r2.ifaces[0].ip4[0].ip }} default-originate route-map default + exit-address-family + ! + bgp community-list standard default seq 5 permit 65000:1 + ! + route-map default permit 10 + match community default + ! + route-map internal permit 10 + set community 65000:1 + ! + #% endif + #% endblock + """ + + +@config_fixture(Configs) +def configs(config, allproto_topo): + return config + + +@instance_fixture() +def testenv(configs): + return FRRNetworkInstance(configs.topology, configs).prepare() + + +class BGPDefaultOriginateRouteMapMatch(TestBase): + instancefn = testenv + + # Establish BGP connection + @topotatofunc + def bgp_converge(self, topo, r1, r2): + expected = { + str(r1.ifaces[0].ip4[0].ip): { + "bgpState": "Established", + "addressFamilyInfo": {"ipv4Unicast": {"acceptedPrefixCounter": 3}}, + } + } + yield from AssertVtysh.make( + r2, + "bgpd", + f"show ip bgp neighbor {r1.ifaces[0].ip4[0].ip} json", + maxwait=5.0, + compare=expected, + ) + + @topotatofunc + def bgp_default_route_is_valid(self, topo, r1, r2): + expected = {"paths": [{"valid": True}]} + yield from AssertVtysh.make( + r2, "bgpd", f"show ip bgp 0.0.0.0/0 json", maxwait=5.0, compare=expected + )