Coverage for birdplan/bird_config/sections/protocols/rip/rip_functions.py: 100%

28 statements  

« 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/>. 

18 

19"""RIP protocol specific functions class.""" 

20 

21from typing import Any 

22 

23from ....globals import BirdConfigGlobals 

24from ...functions import BirdFunction, SectionFunctions 

25from ..base_protocol_functions import ProtocolFunctionsBase 

26 

27__all__ = ["RIPFunctions"] 

28 

29 

30class RIPFunctions(ProtocolFunctionsBase): # pylint: disable=too-many-public-methods 

31 """RIP protocol specific functions class.""" 

32 

33 def __init__(self, birdconfig_globals: BirdConfigGlobals, functions: SectionFunctions): 

34 """Initialize the object.""" 

35 super().__init__(birdconfig_globals, functions) 

36 

37 self._section = "RIP Functions" 

38 

39 @BirdFunction("rip_accept_connected") 

40 def accept_connected(self, *args: Any) -> str: # pylint: disable=unused-argument 

41 """BIRD rip_accept_connected function.""" 

42 

43 return f"""\ 

44 # Accept RIP connected routes 

45 function rip_accept_connected(string filter_name) -> bool {{ 

46 if ((proto != "direct4_rip" && proto != "direct6_rip") || {self.functions.is_default()}) then return false; 

47 if DEBUG then print filter_name, 

48 " [rip_accept_connected] Accepting RIP connected route ", {self.functions.route_info()}, 

49 " due to connected route match"; 

50 accept; 

51 }}""" 

52 

53 @BirdFunction("rip_accept_rip_default") 

54 def accept_rip_default(self, *args: Any) -> str: # pylint: disable=unused-argument 

55 """BIRD rip_accept_rip_default function.""" 

56 

57 return f"""\ 

58 # Accept RIP route 

59 function rip_accept_rip_default(string filter_name) -> bool {{ 

60 if (source != RTS_RIP || !{self.functions.is_default()}) then return false; 

61 if DEBUG then print filter_name, 

62 " [rip_accept_rip_default] Accepting RIP default route ", {self.functions.route_info()}, 

63 " due to default route match"; 

64 accept; 

65 }}""" 

66 

67 @BirdFunction("rip_accept_rip") 

68 def accept_rip(self, *args: Any) -> str: # pylint: disable=unused-argument 

69 """BIRD rip_accept_rip function.""" 

70 

71 return f"""\ 

72 # Accept RIP route 

73 function rip_accept_rip(string filter_name) -> bool {{ 

74 if (source != RTS_RIP || {self.functions.is_default()}) then return false; 

75 if DEBUG then print filter_name, 

76 " [rip_accept_rip] Accepting RIP route ", {self.functions.route_info()}, " due to RIP route match"; 

77 accept; 

78 }}""" 

79 

80 @BirdFunction("rip_redistribute_connected") 

81 def redistribute_connected(self, *args: Any) -> str: # pylint: disable=unused-argument 

82 """BIRD rip_redistribute_connected function.""" 

83 

84 return f"""\ 

85 # Accept RIP connected routes 

86 function rip_redistribute_connected(string filter_name) -> bool {{ 

87 if ((proto != "direct4_rip" && proto != "direct6_rip") || {self.functions.is_default()}) then return false; 

88 if DEBUG then print filter_name, 

89 " [rip_redistribute_connected] Redistributing RIP connected route ", {self.functions.route_info()}, 

90 " due to connected route match"; 

91 accept; 

92 }}""" 

93 

94 @BirdFunction("rip_redistribute_rip_default") 

95 def redistribute_rip_default(self, *args: Any) -> str: # pylint: disable=unused-argument 

96 """BIRD rip_redistribute_rip_default function.""" 

97 

98 return f"""\ 

99 # Accept RIP route 

100 function rip_redistribute_rip_default(string filter_name) -> bool {{ 

101 if (source != RTS_RIP || !{self.functions.is_default()}) then return false; 

102 if DEBUG then print filter_name, 

103 " [rip_redistribute_rip_default] Redistributing RIP default route ", {self.functions.route_info()}, 

104 " due to RIP default route match"; 

105 accept; 

106 }}""" 

107 

108 @BirdFunction("rip_redistribute_rip") 

109 def redistribute_rip(self, *args: Any) -> str: # pylint: disable=unused-argument 

110 """BIRD rip_redistribute_rip function.""" 

111 

112 return f"""\ 

113 # Accept RIP route 

114 function rip_redistribute_rip(string filter_name) -> bool {{ 

115 if (source != RTS_RIP || {self.functions.is_default()}) then return false; 

116 if DEBUG then print filter_name, 

117 " [rip_redistribute_rip] Redistributing RIP route ", {self.functions.route_info()}, 

118 " due to RIP route match"; 

119 accept; 

120 }}"""