Coverage for birdplan/bird_config/sections/protocols/__init__.py: 100%
68 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 protocols section."""
21from ...globals import BirdConfigGlobals
22from ..base import SectionBase
23from ..constants import SectionConstants
24from ..functions import SectionFunctions
25from ..tables import SectionTables
26from .bgp import ProtocolBGP
27from .device import ProtocolDevice
28from .direct import ProtocolDirect
29from .kernel import ProtocolKernel
30from .ospf import ProtocolOSPF
31from .pipe import ProtocolPipe
32from .rip import ProtocolRIP
33from .static import ProtocolStatic
35__all__ = ["SectionProtocols"]
38class SectionProtocols(SectionBase):
39 """BIRD protocols section."""
41 _device: ProtocolDevice
42 _direct: ProtocolDirect
43 _kernel: ProtocolKernel
44 _static: ProtocolStatic
45 _rip: ProtocolRIP
46 _ospf: ProtocolOSPF
47 _bgp: ProtocolBGP
49 def __init__(
50 self, birdconfig_globals: BirdConfigGlobals, constants: SectionConstants, functions: SectionFunctions, tables: SectionTables
51 ):
52 """Initialize object."""
53 super().__init__(birdconfig_globals)
55 self._device = ProtocolDevice(birdconfig_globals, constants, functions, tables)
56 self._direct = ProtocolDirect(birdconfig_globals, constants, functions, tables)
57 self._kernel = ProtocolKernel(birdconfig_globals, constants, functions, tables)
58 self._static = ProtocolStatic(birdconfig_globals, constants, functions, tables)
59 self._rip = ProtocolRIP(birdconfig_globals, constants, functions, tables)
60 self._ospf = ProtocolOSPF(birdconfig_globals, constants, functions, tables)
61 self._bgp = ProtocolBGP(birdconfig_globals, constants, functions, tables)
63 def configure(self) -> None:
64 """Configure all protocols."""
65 super().configure()
67 # Add device protocol
68 self.conf.add(self.device)
70 # Add direct protocol
71 self.conf.add(self.direct)
72 # Add pipe between direct and master tables
73 bgp_direct_pipe = ProtocolPipe(
74 self.birdconfig_globals,
75 table_from="master",
76 table_to="direct",
77 table_import="all",
78 )
79 self.conf.add(bgp_direct_pipe)
81 # Add kernel protocol
82 self.conf.add(self.kernel)
84 # If we have static routes, pull in the static configuration
85 if self.static.routes:
86 self.conf.add(self.static)
88 # If we have RIP interfaces, pull in the RIP configuration
89 if self.rip.interfaces:
90 self.conf.add(self.rip)
92 # If we have OSPF interfaces, pull the OSPF configuration
93 if self.ospf.areas:
94 self.conf.add(self.ospf)
96 # If we have BGP peers, pull in the BGP configuration
97 if self.bgp.peers:
98 self.conf.add(self.bgp)
100 @property
101 def device(self) -> ProtocolDevice:
102 """Return the device protocol."""
103 return self._device
105 @property
106 def direct(self) -> ProtocolDirect:
107 """Return the direct protocol."""
108 return self._direct
110 @property
111 def kernel(self) -> ProtocolKernel:
112 """Return the kernel protocol."""
113 return self._kernel
115 @property
116 def static(self) -> ProtocolStatic:
117 """Return the static protocol."""
118 return self._static
120 @property
121 def rip(self) -> ProtocolRIP:
122 """Return the RIP protocol."""
123 return self._rip
125 @property
126 def ospf(self) -> ProtocolOSPF:
127 """Return the OSPF protocol."""
128 return self._ospf
130 @property
131 def bgp(self) -> ProtocolBGP:
132 """Return the BGP protocol."""
133 return self._bgp