-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_bgp_orf.py
175 lines (155 loc) Β· 4.97 KB
/
test_bgp_orf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2023 Nathan Mangar
"""
Test if BGP ORF filtering is working correctly when modifying prefix-list.
Initially advertise "ini_permit" from R1 to R2. Then add "ini_deny", check
ORF updated, remove "ini_permit", check ORF updated.
"""
__topotests_replaces__ = {
"bgp_orf/": "acddc0ed3ce0833490b7ef38ed000d54388ebea4",
}
# pylint: disable=wildcard-import, unused-wildcard-import, trailing-whitespace
from topotato.v1 import *
@topology_fixture()
def topology(topo):
"""
[ r1 ]--{ ini_permit }
[ ]
[ ]--{ ini_deny }
|
[ r2 ]
"""
class Configs(FRRConfigs):
zebra = """
#% extends "boilerplate.conf"
## nothing needed
"""
bgpd = """
#% block main
#% if router.name == 'r1'
router bgp 65001
no bgp ebgp-requires-policy
neighbor {{ router.iface_to('r2').other.ip4[0].ip }} remote-as external
address-family ipv4 unicast
redistribute connected
neighbor {{ router.iface_to('r2').other.ip4[0].ip }} capability orf prefix-list both
!
#% elif router.name == 'r2'
router bgp 65002
no bgp ebgp-requires-policy
neighbor {{ router.iface_to('r1').other.ip4[0].ip }} remote-as external
address-family ipv4 unicast
neighbor {{ router.iface_to('r1').other.ip4[0].ip }} capability orf prefix-list both
neighbor {{ router.iface_to('r1').other.ip4[0].ip }} prefix-list r1 in
!
ip prefix-list r1 seq 5 permit {{ topo.lans["ini_permit"].ip4[0] }}
#% endif
#% endblock
"""
class TestBGPORF(TestBase, AutoFixture, topo=topology, configs=Configs):
@topotatofunc
def bgp_converge(self, topo, r1, r2):
"""
Wait for initial BGP convergence
- ``ini_permit`` LAN should be seen on r2
- ``ini_deny`` LAN should NOT be seen on r2
"""
expected = {
"advertisedRoutes": {
str(topo.lans["ini_permit"].ip4[0]): JSONCompareIgnoreContent(),
str(topo.lans["ini_deny"].ip4[0]): None,
}
}
yield from AssertVtysh.make(
r1,
"bgpd",
f"show bgp ipv4 unicast neighbor {r2.iface_to('r1').ip4[0].ip} advertised-routes json",
maxwait=5.0,
compare=expected,
)
expected = {
"peers": {
str(r1.iface_to("r2").ip4[0].ip): {
"pfxRcd": 1,
"pfxSnt": 1,
"state": "Established",
"peerState": "OK",
}
}
}
yield from AssertVtysh.make(
r2,
"bgpd",
f"show bgp ipv4 unicast summary json",
maxwait=5.0,
compare=expected,
)
@topotatofunc
def bgp_orf_change_permit(self, topo, r1, r2):
"""
Change config on r2 to permit ``ini_deny`` prefix
"""
yield from ReconfigureFRR.make(
r2,
"bgpd",
f"ip prefix-list r1 seq 10 permit {topo.lans['ini_deny'].ip4[0]}",
)
expected = {
"advertisedRoutes": {
str(topo.lans["ini_permit"].ip4[0]): JSONCompareIgnoreContent(),
str(topo.lans["ini_deny"].ip4[0]): JSONCompareIgnoreContent(),
}
}
yield from AssertVtysh.make(
r1,
"bgpd",
f"show bgp ipv4 unicast neighbor {r2.iface_to('r1').ip4[0].ip} advertised-routes json",
maxwait=5.0,
compare=expected,
)
expected = {
"routes": {
str(topo.lans["ini_permit"].ip4[0]): [{"valid": True}],
str(topo.lans["ini_deny"].ip4[0]): [{"valid": True}],
}
}
yield from AssertVtysh.make(
r2,
"bgpd",
f"show bgp ipv4 unicast json",
maxwait=5.0,
compare=expected,
)
@topotatofunc
def bgp_orf_change_deny(self, topo, r1, r2):
"""
Change config on r2 to deny ``ini_permit`` prefix
"""
yield from ReconfigureFRR.make(r2, "bgpd", "no ip prefix-list r1 seq 5")
expected = {
"advertisedRoutes": {
str(topo.lans["ini_permit"].ip4[0]): None,
str(topo.lans["ini_deny"].ip4[0]): JSONCompareIgnoreContent(),
}
}
yield from AssertVtysh.make(
r1,
"bgpd",
f"show bgp ipv4 unicast neighbor {r2.iface_to('r1').ip4[0].ip} advertised-routes json",
maxwait=5.0,
compare=expected,
)
expected = {
"routes": {
str(topo.lans["ini_permit"].ip4[0]): None,
str(topo.lans["ini_deny"].ip4[0]): [{"valid": True}],
}
}
yield from AssertVtysh.make(
r2,
"bgpd",
f"show bgp ipv4 unicast json",
maxwait=5.0,
compare=expected,
)