Skip to content

Commit 6138071

Browse files
committed
topotato: wip test_bgp_default_originate_timer.py
Signed-off-by: Nathan Mangar <[email protected]>
1 parent 59d16e7 commit 6138071

File tree

1 file changed

+166
-0
lines changed

1 file changed

+166
-0
lines changed

test_bgp_default_originate_timer.py

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# SPDX-License-Identifier: GPL-2.0-or-later
2+
# Copyright (C) 2023 Nathan Mangar
3+
4+
"""
5+
Check if `bgp default-originate timer` commands takes an effect:
6+
1. Set bgp default-originate timer 3600
7+
2. No default route is advertised because the timer is running for 3600 seconds
8+
3. We reduce it to 10 seconds
9+
4. Default route is advertised
10+
"""
11+
12+
13+
__topotests_file__ = "bgp_default_originate_timer/test_bgp_default_originate_timer.py"
14+
__topotests_gitrev__ = "1bfbdc17f20fe4e9d66c9adcbfa48b7a7adfdc29"
15+
16+
# 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
17+
18+
from topotato import *
19+
20+
21+
@topology_fixture()
22+
def topology(topo):
23+
"""
24+
[ r1 ]--{ s2 }
25+
| |
26+
{ s1 }--[ r3 ]
27+
|
28+
[ r2 ]
29+
"""
30+
31+
topo.router("r1").lo_ip4.append("172.16.255.1/32")
32+
topo.router("r1").iface_to("s1").ip4.append("192.168.1.1/24")
33+
topo.router("r2").iface_to("s1").ip4.append("192.168.1.2/24")
34+
topo.router("r1").iface_to("s2").ip4.append("192.168.2.1/24")
35+
topo.router("r3").iface_to("s1").ip4.append("192.168.2.2/24")
36+
37+
38+
class Configs(FRRConfigs):
39+
routers = ["r1", "r2", "r3"]
40+
41+
zebra = """
42+
#% extends "boilerplate.conf"
43+
#% block main
44+
#% for iface in router.ifaces
45+
interface {{ iface.ifname }}
46+
ip address {{ iface.ip4[0] }}
47+
!
48+
#% endfor
49+
#% endblock
50+
"""
51+
52+
bgpd = """
53+
#% extends "boilerplate.conf"
54+
#% block main
55+
#% if router.name == 'r1'
56+
router bgp 65001
57+
no bgp ebgp-requires-policy
58+
bgp default-originate timer 3600
59+
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} remote-as external
60+
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} timers 1 3
61+
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} timers connect 1
62+
neighbor {{ routers.r3.iface_to('s1').ip4[0].ip }} remote-as external
63+
neighbor {{ routers.r3.iface_to('s1').ip4[0].ip }} timers 1 3
64+
neighbor {{ routers.r3.iface_to('s1').ip4[0].ip }} timers connect 1
65+
address-family ipv4
66+
neighbor {{ routers.r2.iface_to('s1').ip4[0].ip }} default-originate route-map default
67+
exit-address-family
68+
!
69+
bgp community-list standard r3 seq 5 permit 65003:1
70+
!
71+
route-map default permit 10
72+
match community r3
73+
exit
74+
#% elif router.name == 'r2'
75+
router bgp 65002
76+
no bgp ebgp-requires-policy
77+
neighbor {{ routers.r1.iface_to('s1').ip4[0].ip }} remote-as external
78+
neighbor {{ routers.r1.iface_to('s1').ip4[0].ip }} timers 1 3
79+
neighbor {{ routers.r1.iface_to('s1').ip4[0].ip }} timers connect 1
80+
!
81+
#% elif router.name == 'r3'
82+
router bgp 65003
83+
no bgp ebgp-requires-policy
84+
neighbor {{ routers.r1.iface_to('s2').ip4[0].ip }} remote-as external
85+
neighbor {{ routers.r1.iface_to('s2').ip4[0].ip }} timers 1 3
86+
neighbor {{ routers.r1.iface_to('s2').ip4[0].ip }} timers connect 1
87+
address-family ipv4 unicast
88+
redistribute connected route-map r1
89+
exit-address-family
90+
!
91+
route-map r1 permit 10
92+
set community 65003:1
93+
exit
94+
#% endif
95+
#% endblock
96+
"""
97+
98+
99+
class BGPDefaultOriginateTimer(TestBase, AutoFixture, topo=topology, configs=Configs):
100+
@topotatofunc
101+
def bgp_default_received_from_r1(self, _, r1, r2):
102+
expected = {
103+
"paths": [
104+
{
105+
"nexthops": [
106+
{
107+
"hostname": "r1",
108+
"ip": str(r1.iface_to("s1").ip4[0].ip),
109+
}
110+
],
111+
}
112+
],
113+
}
114+
115+
yield from AssertVtysh.make(
116+
r2,
117+
"bgpd",
118+
f"show bgp ipv4 unicast 0.0.0.0/0 json",
119+
maxwait=10.0,
120+
compare=expected,
121+
)
122+
123+
@topotatofunc
124+
def bgp_default_received_from_r1_2(self, _, r1, r2, r3):
125+
expected = {
126+
"paths": [
127+
{
128+
"nexthops": [
129+
{
130+
"hostname": "r1",
131+
"ip": str(r1.iface_to("s1").ip4[0].ip),
132+
}
133+
],
134+
}
135+
],
136+
}
137+
138+
yield from AssertVtysh.make(
139+
r1,
140+
"vtysh",
141+
"""
142+
configure terminal
143+
router bgp
144+
bgp default-originate timer 10
145+
""",
146+
compare="",
147+
)
148+
149+
yield from AssertVtysh.make(
150+
r3,
151+
"vtysh",
152+
"""
153+
configure terminal
154+
route-map r1 permit 10
155+
set metric 1
156+
""",
157+
compare="",
158+
)
159+
160+
yield from AssertVtysh.make(
161+
r2,
162+
"bgpd",
163+
f"show bgp ipv4 unicast 0.0.0.0/0 json",
164+
maxwait=10.0,
165+
compare=expected,
166+
)

0 commit comments

Comments
 (0)