Coverage for src/birdplan/bird_config/sections/protocols/__init__.py: 100%

61 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-25 07:38 +0000

1# 

2# SPDX-License-Identifier: GPL-3.0-or-later 

3# 

4# Copyright (c) 2019-2025, 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/>. 

18 

19"""BIRD protocols section.""" 

20 

21from ...globals import BirdConfigGlobals 

22from ..base import SectionBase 

23from ..bird_attributes import SectionBirdAttributes 

24from ..constants import SectionConstants 

25from ..functions import SectionFunctions 

26from ..tables import SectionTables 

27from .bgp import ProtocolBGP 

28from .device import ProtocolDevice 

29from .direct import ProtocolDirect 

30from .kernel import ProtocolKernel 

31from .ospf import ProtocolOSPF 

32from .pipe import ProtocolPipe 

33from .rip import ProtocolRIP 

34from .static import ProtocolStatic 

35 

36__all__ = ["SectionProtocols"] 

37 

38 

39class SectionProtocols(SectionBase): 

40 """BIRD protocols section.""" 

41 

42 _device: ProtocolDevice 

43 _direct: ProtocolDirect 

44 _kernel: ProtocolKernel 

45 _static: ProtocolStatic 

46 _rip: ProtocolRIP 

47 _ospf: ProtocolOSPF 

48 _bgp: ProtocolBGP 

49 

50 def __init__( # pylint: disable=too-many-arguments,too-many-positional-arguments 

51 self, 

52 birdconfig_globals: BirdConfigGlobals, 

53 birdattributes: SectionBirdAttributes, 

54 constants: SectionConstants, 

55 functions: SectionFunctions, 

56 tables: SectionTables, 

57 ) -> None: 

58 """Initialize object.""" 

59 super().__init__(birdconfig_globals) 

60 

61 self._device = ProtocolDevice(birdconfig_globals, birdattributes, constants, functions, tables) 

62 self._direct = ProtocolDirect(birdconfig_globals, birdattributes, constants, functions, tables) 

63 self._kernel = ProtocolKernel(birdconfig_globals, birdattributes, constants, functions, tables) 

64 self._static = ProtocolStatic(birdconfig_globals, birdattributes, constants, functions, tables) 

65 self._rip = ProtocolRIP(birdconfig_globals, birdattributes, constants, functions, tables) 

66 self._ospf = ProtocolOSPF(birdconfig_globals, birdattributes, constants, functions, tables) 

67 self._bgp = ProtocolBGP(birdconfig_globals, birdattributes, constants, functions, tables) 

68 

69 def configure(self) -> None: 

70 """Configure all protocols.""" 

71 super().configure() 

72 

73 # Add device protocol 

74 self.conf.add(self.device) 

75 

76 # Add direct protocol 

77 self.conf.add(self.direct) 

78 # Add pipe between direct and master tables 

79 bgp_direct_pipe = ProtocolPipe( 

80 self.birdconfig_globals, 

81 table_from="master", 

82 table_to="direct", 

83 table_import="all", 

84 ) 

85 self.conf.add(bgp_direct_pipe) 

86 

87 # Add kernel protocol 

88 self.conf.add(self.kernel) 

89 

90 # If we have static routes, pull in the static configuration 

91 if self.static.routes: 

92 self.conf.add(self.static) 

93 

94 # If we have RIP interfaces, pull in the RIP configuration 

95 if self.rip.interfaces: 

96 self.conf.add(self.rip) 

97 

98 # If we have OSPF interfaces, pull the OSPF configuration 

99 if self.ospf.areas: 

100 self.conf.add(self.ospf) 

101 

102 # If we have BGP peers, pull in the BGP configuration 

103 if self.bgp.peers: 

104 self.conf.add(self.bgp) 

105 

106 @property 

107 def device(self) -> ProtocolDevice: 

108 """Return the device protocol.""" 

109 return self._device 

110 

111 @property 

112 def direct(self) -> ProtocolDirect: 

113 """Return the direct protocol.""" 

114 return self._direct 

115 

116 @property 

117 def kernel(self) -> ProtocolKernel: 

118 """Return the kernel protocol.""" 

119 return self._kernel 

120 

121 @property 

122 def static(self) -> ProtocolStatic: 

123 """Return the static protocol.""" 

124 return self._static 

125 

126 @property 

127 def rip(self) -> ProtocolRIP: 

128 """Return the RIP protocol.""" 

129 return self._rip 

130 

131 @property 

132 def ospf(self) -> ProtocolOSPF: 

133 """Return the OSPF protocol.""" 

134 return self._ospf 

135 

136 @property 

137 def bgp(self) -> ProtocolBGP: 

138 """Return the BGP protocol.""" 

139 return self._bgp