Skip to content

Commit

Permalink
topotato: improve test_bgp_set_aspath_replace.py
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Mangar <[email protected]>
Co-authored-by: Bruno Bernard <[email protected]>
  • Loading branch information
2 people authored and eqvinox committed Dec 13, 2022
1 parent 202a0be commit 32a102c
Showing 1 changed file with 37 additions and 41 deletions.
78 changes: 37 additions & 41 deletions test_bgp_set_aspath_replace.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
from topotato import *
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2022 Nathan Mangar

"""
Test if `set as-path replace` is working correctly for route-maps.
"""

__topotests_file__ = "bgp_set_aspath_replace/test_bgp_set_aspath_replace.py"
__topotests_gitrev__ = "77e3d82167b97a1ff4abe59d6e4f12086a61d9f9"

# pylint: disable=invalid-name, missing-class-docstring, missing-function-docstring, line-too-long, consider-using-f-string, wildcard-import, unused-wildcard-import, f-string-without-interpolation, too-few-public-methods

from topotato import *


@topology_fixture()
def allproto_topo(topo):
def topology(topo):
"""
[ r1 ]
|
{ s1 }--[ r3 ]
| |
[ r2 ]--{ s2 }
"""

topo.router("r3").lo_ip4.append("172.16.255.31/32")
topo.router("r3").lo_ip4.append("172.16.255.32/32")
topo.router("r1").iface_to("s1").ip4.append("192.168.1.1/24")
topo.router("r2").iface_to("s1").ip4.append("192.168.1.2/24")
topo.router("r2").iface_to("s2").ip4.append("192.168.2.2/24")
topo.router("r3").iface_to("s1").ip4.append("192.168.2.1/24")


class Configs(FRRConfigs):
Expand All @@ -30,6 +34,12 @@ class Configs(FRRConfigs):
zebra = """
#% extends "boilerplate.conf"
#% block main
#% if router.name == 'r3'
interface lo
ip address {{ routers.r3.lo_ip4[0] }}
ip address {{ routers.r3.lo_ip4[0] }}
!
#% endif
#% for iface in router.ifaces
interface {{ iface.ifname }}
ip address {{ iface.ip4[0] }}
Expand All @@ -41,73 +51,59 @@ class Configs(FRRConfigs):
"""

bgpd = """
#% block main
#% block main
#% if router.name == 'r1'
router bgp 65001
no bgp ebgp-requires-policy
neighbor 192.168.1.2 remote-as external
neighbor 192.168.1.2 timers 3 10
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} remote-as external
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} timers 3 10
address-family ipv4 unicast
neighbor 192.168.1.2 route-map r2 in
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} route-map r2 in
exit-address-family
!
ip prefix-list p1 seq 5 permit 172.16.255.31/32
ip prefix-list p1 seq 5 permit {{ routers.r3.lo_ip4[0] }}
!
route-map r2 permit 10
match ip address prefix-list p1
set as-path replace 65003
route-map r2 permit 20
set as-path replace any
!
#% endif
#% if router.name == 'r2'
#% elif router.name == 'r2'
router bgp 65002
no bgp ebgp-requires-policy
neighbor 192.168.1.1 remote-as external
neighbor 192.168.1.1 timers 3 10
neighbor 192.168.2.1 remote-as external
neighbor 192.168.2.1 timers 3 10
neighbor {{ routers.r1.iface_to('s1').ip4[0].ip }} remote-as external
neighbor {{ routers.r1.iface_to('s1').ip4[0].ip }} timers 3 10
neighbor {{ routers.r3.iface_to('s2').ip4[0].ip }} remote-as external
neighbor {{ routers.r3.iface_to('s2').ip4[0].ip }} timers 3 10
!
#% endif
#% if router.name == 'r3'
#% elif router.name == 'r3'
router bgp 65003
no bgp ebgp-requires-policy
neighbor 192.168.2.2 remote-as external
neighbor 192.168.2.2 timers 3 10
neighbor {{ routers.r2.iface_to('s2').ip4[0].ip }} remote-as external
neighbor {{ routers.r2.iface_to('s2').ip4[0].ip }} timers 3 10
address-family ipv4 unicast
redistribute connected
exit-address-family
!
#% endif
#% endblock
"""


@config_fixture(Configs)
def configs(config, allproto_topo):
return config


@instance_fixture()
def testenv(configs):
return FRRNetworkInstance(configs.topology, configs).prepare()

#% endblock
"""

class BGPSetAspathReplace(TestBase):
instancefn = testenv

class BGPSetAspathReplace(TestBase, AutoFixture, topo=topology, configs=Configs):
@topotatofunc
def bgp_converge(self, topo, r1, r2, r3):
def bgp_converge(self, _, r1, r3):
expected = {
"routes": {
"172.16.255.31/32": [{"path": "65002 65001"}],
"172.16.255.32/32": [{"path": "65001 65001"}],
str(r3.lo_ip4[0]): [{"path": "65002 65001"}],
str(r3.lo_ip4[1]): [{"path": "65001 65001"}],
}
}
yield from AssertVtysh.make(
r1,
"bgpd",
f"show bgp ipv4 unicast json",
maxwait=6.0,
maxwait=5.0,
compare=expected,
)

0 comments on commit 32a102c

Please sign in to comment.