de2c4a7c1a899dc4e7523781a237e0f52a751bfa
[feed/routing.git] / bird-openwrt / bird6-openwrt / src / model / bgp_proto.lua
1 --[[
2 Copyright (C) 2014-2017 - Eloi Carbo
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 --]]
17
18 require("luci.sys")
19 local http = require "luci.http"
20 local uci = luci.model.uci.cursor()
21
22 -- Repeated Strings
23 local common_string = "Valid options are:<br />" .. "1. all (All the routes)<br />" .. "2. none (No routes)<br />" .. "3. filter <b>Your_Filter_Name</b> (Call a specific filter from any of the available in the filters files)"
24 local imp_string = "Set if the protocol must import routes.<br />" .. common_string
25 local exp_string = "Set if the protocol must export routes.<br />" .. common_string
26
27 m=Map("bird6", "Bird6 BGP protocol's configuration")
28
29 tab_templates = {}
30 uci:foreach('bird6', 'bgp_template', function (s)
31 local name = s[".name"]
32 if (name ~= nil) then
33 table.insert(tab_templates, name)
34 end
35 end)
36
37 --
38 -- BGP TEMPLATES
39 --
40 sect_templates = m:section(TypedSection, "bgp_template", "BGP Templates", "Configuration of the templates used in BGP instances.")
41 sect_templates.addremove = true
42 sect_templates.anonymous = false
43
44 disabled = sect_templates:option(Flag, "disabled", "Disabled", "Enable/Disable BGP Protocol")
45 disabled.optional=true
46
47 description = sect_templates:option(TextValue, "description", "Description", "Description of the current BGP instance")
48 description.optional = true
49
50 table = sect_templates:option(ListValue, "table", "Table", "Set the table used for BGP Routing")
51 table.optional=true
52 uci:foreach("bird6", "table",
53 function (s)
54 table:value(s.name)
55 end)
56 table:value("")
57 table.default = ""
58
59 igp_table = sect_templates:option(ListValue, "igp_table", "IGP Table", "Select the IGP Routing Table to use. Hint: usually the same table as BGP.")
60 igp_table.optional = true
61 uci:foreach("bird6", "table",
62 function(s)
63 igp_table:value(s.name)
64 end)
65 igp_table:value("")
66 igp_table.default = ""
67
68 import = sect_templates:option(Value, "import", "Import", imp_string)
69 import.optional=true
70
71 export = sect_templates:option(Value, "export", "Export", exp_string)
72 export.optional=true
73
74 source_addr = sect_templates:option(Value, "source_address", "Source Address", "Source address for BGP routing. By default uses Router ID")
75 source_addr.optional = true
76
77 local_address = sect_templates:option(Value, "local_address", "Local BGP address", "")
78 local_address.optional = false
79
80 local_as = sect_templates:option(Value, "local_as", "Local AS", "")
81 local_as.optional = false
82
83 next_hop_self = sect_templates:option(Flag, "next_hop_self", "Next hop self", "Avoid next hop calculation and advertise own source address as next hop")
84 next_hop_self.default = nil
85 next_hop_self.optional = true
86
87 next_hop_keep = sect_templates:option(Flag, "next_hop_keep", "Next hop keep", "Forward the received Next Hop attribute event in situations where the local address should be used instead, like subneting")
88 next_hop_keep.default = nil
89 next_hop_keep.optional = true
90
91 rr_client = sect_templates:option(Flag, "rr_client", "Route Reflector server", "This router serves as a Route Reflector server and treats neighbors as clients")
92 rr_client.default = nil
93 rr_client.optional = true
94
95 rr_cluster_id = sect_templates:option(Value, "rr_cluster_id", "Route Reflector Cluster ID", "Identificator of the RR cluster. By default uses the Router ID")
96 rr_cluster_id.optional = true
97
98 import_trigger = sect_templates:option(Flag, "import_trigger", "Import Limit", "Enable Routes Import limit settings")
99 import_trigger.default = 0
100 import_trigger.rmempty = false
101 import_trigger.optional = false
102
103 import_limit = sect_templates:option(Value, "import_limit", "Routes import limit", "Specify an import route limit.")
104 import_limit:depends({import_trigger = "1"})
105 import_limit.rmempty = true
106
107 import_limit_action = sect_templates:option(ListValue, "import_limit_action", "Routes import limit action", "Action to take when import routes limit ir reached")
108 import_limit_action:depends({import_trigger = "1"})
109 import_limit_action:value("warn")
110 import_limit_action:value("block")
111 import_limit_action:value("disable")
112 import_limit_action:value("restart")
113 import_limit_action.default = "warn"
114 import_limit_action.rmempty = true
115
116 export_trigger = sect_templates:option(Flag, "export_trigger", "Export Limit", "Enable Routes Export limit settings")
117 export_trigger.default = 0
118 export_trigger.rmempty = false
119 export_trigger.optional = false
120
121 export_limit = sect_templates:option(Value, "export_limit", "Routes export limit", "Specify an export route limit.")
122 export_limit:depends({export_trigger = "1"})
123 export_limit.rmempty = true
124
125 export_limit_action = sect_templates:option(ListValue, "export_limit_action", "Routes export limit action", "Action to take when export routes limit is reached")
126 export_limit_action:depends({export_trigger = "1"})
127 export_limit_action.rmempty = true
128 export_limit_action:value("warn")
129 export_limit_action:value("block")
130 export_limit_action:value("disable")
131 export_limit_action:value("restart")
132 export_limit_action.default = "warn"
133
134 receive_trigger = sect_templates:option(Flag, "receive_trigger", "Received Limit", "Enable Routes Received Limit settings")
135 receive_trigger.default = 0
136 receive_trigger.rmempty = false
137 receive_trigger.optional = false
138
139 receive_limit = sect_templates:option(Value, "receive_limit", "Routes received limit", "Specify a received route limit.")
140 receive_limit:depends({receive_trigger = "1"})
141 receive_limit.rmempty = true
142
143 receive_limit_action = sect_templates:option(ListValue, "receive_limit_action", "Routes received limit action", "Action to take when received routes limit is reached")
144 receive_limit_action:depends({receive_trigger = "1"})
145 receive_limit_action:value("warn")
146 receive_limit_action:value("block")
147 receive_limit_action:value("disable")
148 receive_limit_action:value("restart")
149 receive_limit_action.default = "warn"
150 receive_limit_action.rmempty= true
151
152 --
153 -- BGP INSTANCES
154 --
155 sect_instances = m:section(TypedSection, "bgp", "BGP Instances", "Configuration of the BGP protocol instances")
156 sect_instances.addremove = true
157 sect_instances.anonymous = false
158
159 templates = sect_instances:option(ListValue, "template", "Templates", "Available BGP templates")
160 uci:foreach("bird6", "bgp_template",
161 function(s)
162 templates:value(s[".name"])
163 end)
164 templates:value("")
165
166 disabled = sect_instances:option(Flag, "disabled", "Disabled", "Enable/Disable BGP Protocol")
167 disabled.optional = false
168 disabled.rmempty = false
169 disabled.default = nil
170
171 description = sect_instances:option(TextValue, "description", "Description", "Description of the current BGP instance")
172 description.optional = true
173
174 table = sect_instances:option(ListValue, "table", "Table", "Set the table used for BGP Routing")
175 table.optional=true
176 uci:foreach("bird6", "table",
177 function (s)
178 table:value(s.name)
179 end)
180 table:value("")
181 table.default = ""
182
183 igp_table = sect_instances:option(ListValue, "igp_table", "IGP Table", "Select the IGP Routing Table to use. Hint: usually the same table as BGP.")
184 igp_table.optional = true
185 uci:foreach("bird6", "table",
186 function(s)
187 igp_table:value(s.name)
188 end)
189 igp_table:value("")
190 igp_table.default = ""
191
192 import = sect_instances:option(Value, "import", "Import", imp_string)
193 import.optional=true
194
195 export = sect_instances:option(Value, "export", "Export", exp_string)
196 export.optional=true
197
198 source_address = sect_instances:option(Value, "source_address", "Source Address", "Source address for BGP routing. By default uses Router ID")
199 source_address.optional = true
200
201 local_address = sect_instances:option(Value, "local_address", "Local BGP address", "")
202 local_address.optional=true
203
204 local_as = sect_instances:option(Value, "local_as", "Local AS", "")
205 local_as.optional=true
206
207 neighbor_address = sect_instances:option(Value, "neighbor_address", "Neighbor IP Address", "")
208 neighbor_address.optional = false
209
210 neighbor_as = sect_instances:option(Value, "neighbor_as", "Neighbor AS", "")
211 neighbor_as.optional = false
212
213 next_hop_self = sect_instances:option(Flag, "next_hop_self", "Next hop self", "Avoid next hop calculation and advertise own source address as next hop")
214 next_hop_self.default = nil
215 next_hop_self.optional = true
216
217 next_hop_keep = sect_instances:option(Flag, "next_hop_keep", "Next hop keep", "Forward the received Next Hop attribute event in situations where the local address should be used instead, like subneting")
218 next_hop_keep.default = nil
219 next_hop_keep.optional = true
220
221 rr_client = sect_instances:option(Flag, "rr_client", "Route Reflector server", "This router serves as a Route Reflector server and treats neighbors as clients")
222 rr_client.default = nil
223 rr_client.optional = true
224
225 rr_cluster_id = sect_instances:option(Value, "rr_cluster_id", "Route Reflector Cluster ID", "Identificator of the RR cluster. By default uses the Router ID")
226 rr_cluster_id.optional = true
227
228 import_trigger = sect_instances:option(Flag, "import_trigger", "Import Limit", "Enable Routes Import limit settings")
229 import_trigger.default = 0
230 import_trigger.rmempty = false
231 import_trigger.optional = false
232
233 import_limit = sect_instances:option(Value, "import_limit", "Routes import limit", "Specify an import route limit.")
234 import_limit:depends({import_trigger = "1"})
235 import_limit.rmempty = true
236
237 import_limit_action = sect_instances:option(ListValue, "import_limit_action", "Routes import limit action", "Action to take when import routes limit ir reached")
238 import_limit_action:depends({import_trigger = "1"})
239 import_limit_action:value("warn")
240 import_limit_action:value("block")
241 import_limit_action:value("disable")
242 import_limit_action:value("restart")
243 import_limit_action.default = "warn"
244 import_limit_action.rmempty = true
245
246 export_trigger = sect_instances:option(Flag, "export_trigger", "Export Limit", "Enable Routes Export limit settings")
247 export_trigger.default = 0
248 export_trigger.rmempty = false
249 export_trigger.optional = false
250
251 export_limit = sect_instances:option(Value, "export_limit", "Routes export limit", "Specify an export route limit.")
252 export_limit:depends({export_trigger = "1"})
253 export_limit.rmempty = true
254
255 export_limit_action = sect_instances:option(ListValue, "export_limit_action", "Routes export limit action", "Action to take when export routes limit is reached")
256 export_limit_action:depends({export_trigger = "1"})
257 export_limit_action.rmempty = true
258 export_limit_action:value("warn")
259 export_limit_action:value("block")
260 export_limit_action:value("disable")
261 export_limit_action:value("restart")
262 export_limit_action.default = "warn"
263
264 receive_trigger = sect_instances:option(Flag, "receive_trigger", "Received Limit", "Enable Routes Received Limit settings")
265 receive_trigger.default = 0
266 receive_trigger.rmempty = false
267 receive_trigger.optional = false
268
269 receive_limit = sect_instances:option(Value, "receive_limit", "Routes received limit", "Specify a received route limit.")
270 receive_limit:depends({receive_trigger = "1"})
271 receive_limit.rmempty = true
272
273 receive_limit_action = sect_instances:option(ListValue, "receive_limit_action", "Routes received limit action", "Action to take when received routes limit is reached")
274 receive_limit_action:depends({receive_trigger = "1"})
275 receive_limit_action:value("warn")
276 receive_limit_action:value("block")
277 receive_limit_action:value("disable")
278 receive_limit_action:value("restart")
279 receive_limit_action.default = "warn"
280 receive_limit_action.rmempty= true
281
282 function m.on_commit(self,map)
283 luci.sys.exec('/etc/init.d/bird6 restart')
284 end
285
286 return m