Skip to content

Commit

Permalink
topotato: wip test_bgp_default_originate_timer.py
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Mangar <[email protected]>
  • Loading branch information
Nathan Mangar committed Aug 18, 2023
1 parent 59d16e7 commit 6138071
Showing 1 changed file with 166 additions and 0 deletions.
166 changes: 166 additions & 0 deletions test_bgp_default_originate_timer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2023 Nathan Mangar

"""
Check if `bgp default-originate timer` commands takes an effect:
1. Set bgp default-originate timer 3600
2. No default route is advertised because the timer is running for 3600 seconds
3. We reduce it to 10 seconds
4. Default route is advertised
"""


__topotests_file__ = "bgp_default_originate_timer/test_bgp_default_originate_timer.py"
__topotests_gitrev__ = "1bfbdc17f20fe4e9d66c9adcbfa48b7a7adfdc29"

# 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 topology(topo):
"""
[ r1 ]--{ s2 }
| |
{ s1 }--[ r3 ]
|
[ r2 ]
"""

topo.router("r1").lo_ip4.append("172.16.255.1/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("r1").iface_to("s2").ip4.append("192.168.2.1/24")
topo.router("r3").iface_to("s1").ip4.append("192.168.2.2/24")


class Configs(FRRConfigs):
routers = ["r1", "r2", "r3"]

zebra = """
#% extends "boilerplate.conf"
#% block main
#% for iface in router.ifaces
interface {{ iface.ifname }}
ip address {{ iface.ip4[0] }}
!
#% endfor
#% endblock
"""

bgpd = """
#% extends "boilerplate.conf"
#% block main
#% if router.name == 'r1'
router bgp 65001
no bgp ebgp-requires-policy
bgp default-originate timer 3600
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} remote-as external
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} timers 1 3
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} timers connect 1
neighbor {{ routers.r3.iface_to('s1').ip4[0].ip }} remote-as external
neighbor {{ routers.r3.iface_to('s1').ip4[0].ip }} timers 1 3
neighbor {{ routers.r3.iface_to('s1').ip4[0].ip }} timers connect 1
address-family ipv4
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} default-originate route-map default
exit-address-family
!
bgp community-list standard r3 seq 5 permit 65003:1
!
route-map default permit 10
match community r3
exit
#% elif router.name == 'r2'
router bgp 65002
no bgp ebgp-requires-policy
neighbor {{ routers.r1.iface_to('s1').ip4[0].ip }} remote-as external
neighbor {{ routers.r1.iface_to('s1').ip4[0].ip }} timers 1 3
neighbor {{ routers.r1.iface_to('s1').ip4[0].ip }} timers connect 1
!
#% elif router.name == 'r3'
router bgp 65003
no bgp ebgp-requires-policy
neighbor {{ routers.r1.iface_to('s2').ip4[0].ip }} remote-as external
neighbor {{ routers.r1.iface_to('s2').ip4[0].ip }} timers 1 3
neighbor {{ routers.r1.iface_to('s2').ip4[0].ip }} timers connect 1
address-family ipv4 unicast
redistribute connected route-map r1
exit-address-family
!
route-map r1 permit 10
set community 65003:1
exit
#% endif
#% endblock
"""


class BGPDefaultOriginateTimer(TestBase, AutoFixture, topo=topology, configs=Configs):
@topotatofunc
def bgp_default_received_from_r1(self, _, r1, r2):
expected = {
"paths": [
{
"nexthops": [
{
"hostname": "r1",
"ip": str(r1.iface_to("s1").ip4[0].ip),
}
],
}
],
}

yield from AssertVtysh.make(
r2,
"bgpd",
f"show bgp ipv4 unicast 0.0.0.0/0 json",
maxwait=10.0,
compare=expected,
)

@topotatofunc
def bgp_default_received_from_r1_2(self, _, r1, r2, r3):
expected = {
"paths": [
{
"nexthops": [
{
"hostname": "r1",
"ip": str(r1.iface_to("s1").ip4[0].ip),
}
],
}
],
}

yield from AssertVtysh.make(
r1,
"vtysh",
"""
configure terminal
router bgp
bgp default-originate timer 10
""",
compare="",
)

yield from AssertVtysh.make(
r3,
"vtysh",
"""
configure terminal
route-map r1 permit 10
set metric 1
""",
compare="",
)

yield from AssertVtysh.make(
r2,
"bgpd",
f"show bgp ipv4 unicast 0.0.0.0/0 json",
maxwait=10.0,
compare=expected,
)

0 comments on commit 6138071

Please sign in to comment.