Coverage for birdplan/bird_config/sections/protocols/ospf/ospf_functions.py: 100%

25 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"""OSPF 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__ = ["OSPFFunctions"] 

28 

29 

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

31 """OSPF 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 = "OSPF Functions" 

38 

39 @BirdFunction("ospf_accept_connected") 

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

41 """BIRD ospf_accept_connected function.""" 

42 

43 return f"""\ 

44 # Accept OSPF connected routes 

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

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

47 if DEBUG then print filter_name, 

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

49 " due to connected route match"; 

50 accept; 

51 }}""" 

52 

53 @BirdFunction("ospf_accept_ospf") 

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

55 """BIRD ospf_accept_ospf function.""" 

56 

57 return f"""\ 

58 # Accept OSPF route 

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

60 if (source !~ [RTS_OSPF, RTS_OSPF_IA, RTS_OSPF_EXT1, RTS_OSPF_EXT2] || {self.functions.is_default()}) then 

61 return false; 

62 if DEBUG then print filter_name, 

63 " [ospf_accept_ospf] Accepting OSPF route ", {self.functions.route_info()}, " due to OSPF route match"; 

64 accept; 

65 }}""" 

66 

67 @BirdFunction("ospf_accept_ospf_default") 

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

69 """BIRD ospf_accept_ospf_default function.""" 

70 

71 return f"""\ 

72 # Accept OSPF route 

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

74 if (source !~ [RTS_OSPF, RTS_OSPF_IA, RTS_OSPF_EXT1, RTS_OSPF_EXT2] || !{self.functions.is_default()}) then 

75 return false; 

76 if DEBUG then print filter_name, 

77 " [accept_ospf] Accepting OSPF default route ", {self.functions.route_info()}, 

78 " due to OSPF default route match"; 

79 accept; 

80 }}""" 

81 

82 @BirdFunction("ospf_is_connected") 

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

84 """BIRD ospf_is_connected function.""" 

85 

86 return """\ 

87 # Check if this is an connected route 

88 function ospf_is_connected(string filter_name) -> bool { 

89 if (proto = "direct4_ospf" || proto = "direct6_ospf") then return true; 

90 return false; 

91 }""" 

92 

93 @BirdFunction("ospf_redistribute_connected") 

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

95 """BIRD ospf_redistribute_connected function.""" 

96 

97 return f"""\ 

98 # Accept OSPF connected routes 

99 function ospf_redistribute_connected(string filter_name) -> bool {{ 

100 if (!{self.is_connected()} || {self.functions.is_default()}) then return false; 

101 if DEBUG then print filter_name, 

102 " [ospf_redistribute_connected] Redistributing OSPF connected route ", {self.functions.route_info()}, 

103 " due to connected route match"; 

104 accept; 

105 }}"""