Coverage for birdplan/bird_config/sections/protocols/bgp/bgp_attributes.py: 100%
106 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-23 03:27 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-23 03:27 +0000
1#
2# SPDX-License-Identifier: GPL-3.0-or-later
3#
4# Copyright (c) 2019-2024, AllWorldIT
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
19"""BIRD BGP protocol attributes."""
21from typing import Dict, List, Optional, Union
23__all__ = ["BGPRoutePolicyAccept", "BGPRoutePolicyImport", "BGPPeertypeConstraints", "BGPAttributes"]
26class BGPRoutePolicyAccept: # pylint: disable=too-few-public-methods
27 """
28 BGP route policy for acceptance of routes from the main BGP table into the master table.
30 Attributes
31 ----------
32 bgp_customer_blackhole : bool
33 Accept blackhole routes. Defaults to `True`.
34 bgp_own_blackhole : bool
35 Accept blackhole routes. Defaults to `True`.
36 bgp_own_default : bool
37 Accept default routes originated from within our federation. Defaults to `False`.
38 bgp_transit_default : bool
39 Accept default routes originated from transit peers. Defaults to `False`.
40 originated : bool
41 Accept originated routes. Defaults to `True`.
42 originated_default : bool
43 Accept originated routes. Defaults to `False`.
45 """
47 bgp_customer_blackhole: bool
48 bgp_own_blackhole: bool
49 bgp_own_default: bool
50 bgp_transit_default: bool
51 originated: bool
52 originated_default: bool
54 def __init__(self) -> None:
55 """Initialize object."""
56 self.bgp_customer_blackhole = True
57 self.bgp_own_blackhole = True
58 self.bgp_own_default = False
59 self.bgp_transit_default = False
60 self.originated = True
61 self.originated_default = False
64class BGPRoutePolicyImport: # pylint: disable=too-few-public-methods
65 r"""
66 BGP route policy for importing of routes internally.
68 Attributes
69 ----------
70 connected : Union[bool, List[str]]
71 Import connected routes into the main BGP table. This attribute is indexed by interface name with a boolean option.
72 The interface name can be an exact interface match, or a wildcard with a \*.
73 kernel : bool
74 Import kernel routes into the main BGP table. Defaults to `False`.
75 kernel_blackhole : bool
76 Import kernel blackhole routes into the main BGP table. Defaults to `False`.
77 kernel_default : bool
78 Import kernel default routes into the main BGP table. Defaults to `False`.
79 static : bool
80 Import static routes into the main BGP table. Defaults to `False`.
81 static_default : bool
82 Import static default routes into the main BGP table. Defaults to `False`.
83 static_blackhole : bool
84 Import static blackhole routes into the main BGP table. Defaults to `False`.
86 """
88 connected: Union[bool, List[str]]
89 kernel: bool
90 kernel_blackhole: bool
91 kernel_default: bool
92 static: bool
93 static_blackhole: bool
94 static_default: bool
96 def __init__(self) -> None:
97 """Initialize object."""
98 self.connected = False
99 self.kernel = False
100 self.kernel_blackhole = False
101 self.kernel_default = False
102 self.static = False
103 self.static_blackhole = False
104 self.static_default = False
107class BGPPeertypeConstraints: # pylint: disable=too-few-public-methods,too-many-instance-attributes
108 """
109 BGP constraints for a specific peer type.
111 Attributes
112 ----------
113 import_maxlen4 : int
114 Prefix maximum length for IPv4 to import.
115 import_minlen4 : int
116 Prefix minimum length for IPv4 to import.
117 export_maxlen4 : int
118 Prefix maximum length for IPv4 to export.
119 export_minlen4 : int
120 Prefix minimum length for IPv4 to export.
121 import_maxlen6 : int
122 Prefix maximum length for IPv6 to import.
123 import_minlen6 : int
124 Prefix minimum length for IPv6 to import.
125 export_maxlen6 : int
126 Prefix maximum length for IPv6 to export.
127 export_minlen6 : int
128 Prefix minimum length for IPv6 to export.
129 blackhole_import_maxlen4 : int
130 Blackhole maximum length for IPv4 to import.
131 blackhole_import_minlen4 : int
132 Blackhole minimum length for IPv4 to import.
133 blackhole_export_maxlen4 : int
134 Blackhole maximum length for IPv4 to export.
135 blackhole_export_minlen4 : int
136 Blackhole minimum length for IPv4 to export.
137 blackhole_import_maxlen6 : int
138 Blackhole maximum length for IPv6 to import.
139 blackhole_import_minlen6 : int
140 Blackhole minimum length for IPv6 to import.
141 blackhole_export_maxlen6 : int
142 Blackhole maximum length for IPv6 to export.
143 blackhole_export_minlen6 : int
144 Blackhole minimum length for IPv6 to export.
145 aspath_import_maxlen : int
146 AS-PATH maximum length.
147 aspath_import_minlen : int
148 AS-PATH minimum length.
149 community_import_maxlen : int
150 Community maximum length.
151 extended_community_import_maxlen : int
152 Extended community maximum length.
153 large_community_import_maxlen : int
154 Large community maximum length.
156 """
158 import_maxlen4: int
159 import_minlen4: int
161 export_maxlen4: int
162 export_minlen4: int
164 import_maxlen6: int
165 import_minlen6: int
167 export_maxlen6: int
168 export_minlen6: int
170 blackhole_import_maxlen4: int
171 blackhole_import_minlen4: int
173 blackhole_export_maxlen4: int
174 blackhole_export_minlen4: int
176 blackhole_import_maxlen6: int
177 blackhole_import_minlen6: int
179 blackhole_export_maxlen6: int
180 blackhole_export_minlen6: int
182 aspath_import_maxlen: int
183 aspath_import_minlen: int
185 community_import_maxlen: int
186 extended_community_import_maxlen: int
187 large_community_import_maxlen: int
189 def __init__(self, peer_type: Optional[str]) -> None:
190 """Initialize object."""
192 # Set defaults
194 self.import_maxlen4 = 24
195 self.import_minlen4 = 8
197 self.export_maxlen4 = 24
198 self.export_minlen4 = 8
200 self.import_maxlen6 = 48
201 self.import_minlen6 = 16
203 self.export_maxlen6 = 48
204 self.export_minlen6 = 16
206 self.blackhole_import_maxlen4 = 32
207 self.blackhole_import_minlen4 = 24
209 self.blackhole_export_maxlen4 = 32
210 self.blackhole_export_minlen4 = 24
212 self.blackhole_import_maxlen6 = 128
213 self.blackhole_import_minlen6 = 64
215 self.blackhole_export_maxlen6 = 128
216 self.blackhole_export_minlen6 = 64
218 self.aspath_import_maxlen = 100
219 self.aspath_import_minlen = 1
221 self.community_import_maxlen = 100
222 self.extended_community_import_maxlen = 100
223 self.large_community_import_maxlen = 100
225 # Override defaults for internal peer types
226 if peer_type in ("internal", "rrclient", "rrserver", "rrserver-rrserver"):
227 self.import_maxlen4 = 32
228 self.export_maxlen4 = 32
229 self.import_maxlen6 = 128
230 self.export_maxlen6 = 128
231 self.aspath_import_minlen = 0
233 # Override defaults for customers with private ASN's
234 elif peer_type == "customer.private":
235 self.import_maxlen4 = 29
236 self.import_minlen4 = 16
237 self.import_maxlen6 = 64
238 self.import_minlen6 = 32
241class BGPAttributes: # pylint: disable=too-few-public-methods
242 """
243 BGP attributes.
245 Attributes
246 ----------
247 asn : int
248 BGP ASN.
249 graceful_shutdown : boolean
250 Set graceful_shutdown mode for all peers.
251 quarantine : boolean
252 Set quarantine mode for all peers.
253 rr_cluster_id : Optional[str]
254 Route relfector cluster ID in the case of us being a route reflector.
255 route_policy_accept : BGPRoutePolicyAccept
256 Route policy for acceptance of routes from the main BGP table into the master table.
257 route_policy_import : BGPRoutePolicyImport
258 Route policy for importing of routes from internal tables into our main BGP table.
259 peertype_constraints : BGPPeertypeConstraints
260 Prefix limits for each peer type we support.
262 """
264 asn: Optional[int]
265 graceful_shutdown: bool
266 quarantine: bool
267 rr_cluster_id: Optional[str]
268 route_policy_accept: BGPRoutePolicyAccept
269 route_policy_import: BGPRoutePolicyImport
271 peertype_constraints: Dict[str, BGPPeertypeConstraints]
273 def __init__(self) -> None:
274 """Initialize object."""
276 self.asn = None
278 self.graceful_shutdown = False
280 self.quarantine = False
282 self.rr_cluster_id = None
284 self.route_policy_accept = BGPRoutePolicyAccept()
285 self.route_policy_import = BGPRoutePolicyImport()
287 self.peertype_constraints = {}
288 for peer_type in (
289 "customer",
290 "customer.private",
291 "internal",
292 "peer",
293 "routecollector",
294 "routeserver",
295 "rrclient",
296 "rrserver",
297 "rrserver-rrserver",
298 "transit",
299 ):
300 self.peertype_constraints[peer_type] = BGPPeertypeConstraints(peer_type)