bird-openwrt: BIRD daemon integration with UCI and LuCI configuration
[feed/routing.git] / bird-openwrt / bird4-openwrt / src / model / bgp_proto.lua
1 --[[
2 Copyright (C) 2014 - Eloi Carbó Solé (GSoC2014)
3 BGP/Bird integration with OpenWRT and QMP
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 --]]
18
19 require("luci.sys")
20 local http = require "luci.http"
21 local uci = require "luci.model.uci"
22 local uciout = uci.cursor()
23
24 m=Map("bird4", "Bird4 BGP protocol's configuration")
25
26 tab_templates = {}
27 uciout:foreach('bird4', 'bgp_template', function (s)
28 local name = s[".name"]
29 if (name ~= nil) then
30 table.insert(tab_templates, name)
31 end
32 end)
33
34 -- Section BGP Templates
35
36 sect_templates = m:section(TypedSection, "bgp_template", "BGP Templates", "Configuration of the templates used in BGP instances.")
37 sect_templates.addremove = true
38 sect_templates.anonymous = false
39
40 disabled = sect_templates:option(Flag, "disabled", "Disabled", "Enable/Disable BGP Protocol")
41 disabled.optional=true
42 table = sect_templates:option(ListValue, "table", "Table", "Set the table used for BGP Routing")
43 table.optional=true
44 uciout:foreach("bird4", "table",
45 function (s)
46 table:value(s.name)
47 end)
48 table:value("")
49
50 import = sect_templates:option(Value, "import", "Import","")
51 import.optional=true
52 export = sect_templates:option(Value, "export", "Export", "")
53 export.optional=true
54
55 source_addr = sect_templates:option(Value, "source_address", "Source Address", "Source address for BGP routing. By default uses Router ID")
56 source_addr.optional = true
57
58 description = sect_templates:option(TextValue, "description", "Description", "Description of the current BGP instance")
59 description.optional = true
60
61 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")
62 next_hop_self.default = nil
63 next_hop_self.optional = true
64
65 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")
66 next_hop_keep.default = nil
67 next_hop_keep.optional = true
68
69 rr_client = sect_templates:option(Flag, "rr_client", "Route Reflector server", "This router serves as a Route Reflector server and treats neighbors as clients")
70 rr_client.default = nil
71 rr_client.optional = true
72
73 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")
74 rr_cluster_id.optional = true
75
76 import_limit = sect_templates:option(Value, "import_limit", "Routes import limit", "Specify an import route limit. By default is disabled '0'")
77 import_limit.default= "0"
78 import_limit.optional = true
79
80 import_limit_action = sect_templates:option(ListValue, "import_limit_action", "Routes import limit action", "Action to take when import routes limit ir reached")
81 import_limit_action:value("warn")
82 import_limit_action:value("block")
83 import_limit_action:value("disable")
84 import_limit_action:value("restart")
85 import_limit_action.default = "warn"
86 import_limit_action.optional = true
87
88 export_limit = sect_templates:option(Value, "export_limit", "Routes export limit", "Specify an export route limit. By default is disabled '0'")
89 export_limit.default="0"
90 export_limit.optional = true
91
92 export_limit_action = sect_templates:option(ListValue, "export_limit_action", "Routes export limit action", "Action to take when export routes limit is reached")
93 export_limit_action:value("warn")
94 export_limit_action:value("block")
95 export_limit_action:value("disable")
96 export_limit_action:value("restart")
97 export_limit_action.default = "warn"
98 export_limit_action.optional = true
99
100 receive_limit = sect_templates:option(Value, "receive_limit", "Routes received limit", "Specify a received route limit. By default is disabled '0'")
101 receive_limit.default="0"
102 receive_limit.optional = true
103
104 receive_limit_action = sect_templates:option(ListValue, "receive_limit_action", "Routes received limit action", "Action to take when received routes limit is reached")
105 receive_limit_action:value("warn")
106 receive_limit_action:value("block")
107 receive_limit_action:value("disable")
108 receive_limit_action:value("restart")
109 receive_limit_action.default = "warn"
110 receive_limit_action.optional = true
111
112
113 local_address = sect_templates:option(Value, "local_address", "Local BGP address", "")
114 local_address.optional=true
115 local_as = sect_templates:option(Value, "local_as", "Local AS", "")
116 local_as.optional=true
117
118 -- Section BGP Instances:
119
120 sect_instances = m:section(TypedSection, "bgp", "BGP Instances", "Configuration of the BGP protocol instances")
121 sect_instances.addremove = true
122 sect_instances.anonymous = false
123
124 templates = sect_instances:option(ListValue, "template", "Templates", "Available BGP templates")
125
126 uciout:foreach("bird4", "bgp_template",
127 function(s)
128 templates:value(s[".name"])
129 end)
130 templates:value("")
131
132 source_addr = sect_instances:option(Value, "source_address", "Source Address", "Source address for BGP routing. By default uses Router ID")
133 source_addr.optional = true
134
135 description = sect_instances:option(TextValue, "description", "Description", "Description of the current BGP instance")
136 description.optional = true
137
138 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")
139 next_hop_self.default = nil
140 next_hop_self.optional = true
141
142 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")
143 next_hop_keep.default = nil
144 next_hop_keep.optional = true
145
146 rr_client = sect_instances:option(Flag, "rr_client", "Route Reflector server", "This router serves as a Route Reflector server and treats neighbors as clients")
147 rr_client.default = nil
148 rr_client.optional = true
149
150 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")
151 rr_cluster_id.optional = true
152
153 import_limit = sect_instances:option(Value, "import_limit", "Routes import limit", "Specify an import route limit. By default is disabled '0'")
154 import_limit.default="0"
155 import_limit.optional = true
156
157 import_limit_action = sect_instances:option(ListValue, "import_limit_action", "Routes import limit action", "Action to take when import routes limit ir reached")
158 import_limit_action:value("warn")
159 import_limit_action:value("block")
160 import_limit_action:value("disable")
161 import_limit_action:value("restart")
162 import_limit_action.default = "warn"
163 import_limit_action.optional = true
164
165 export_limit = sect_instances:option(Value, "export_limit", "Routes export limit", "Specify an export route limit. By default is disabled '0'")
166 export_limit.default="0"
167 export_limit.optional = true
168
169 export_limit_action = sect_instances:option(ListValue, "export_limit_action", "Routes export limit action", "Action to take when export routes limit is reached")
170 export_limit_action:value("warn")
171 export_limit_action:value("block")
172 export_limit_action:value("disable")
173 export_limit_action:value("restart")
174 export_limit_action.default = "warn"
175 export_limit_action.optional = true
176
177 receive_limit = sect_instances:option(Value, "receive_limit", "Routes received limit", "Specify a received route limit. By default is disabled '0'")
178 receive_limit.default="0"
179 receive_limit.optional = true
180
181 receive_limit_action = sect_instances:option(ListValue, "receive_limit_action", "Routes received limit action", "Action to take when received routes limit is reached")
182 receive_limit_action:value("warn")
183 receive_limit_action:value("block")
184 receive_limit_action:value("disable")
185 receive_limit_action:value("restart")
186 receive_limit_action.default = "warn"
187 receive_limit_action.optional = true
188
189
190 neighbor_address = sect_instances:option(Value, "neighbor_address", "Neighbor IP Address", "")
191 neighbor_as = sect_instances:option(Value, "neighbor_as", "Neighbor AS", "")
192
193 disabled = sect_instances:option(Flag, "disabled", "Disabled", "Enable/Disable BGP Protocol")
194 disabled.optional=true
195 disabled.default=nil
196 table = sect_instances:option(ListValue, "table", "Table", "Set the table used for BGP Routing")
197 table.optional=true
198 uciout:foreach("bird4", "table",
199 function (s)
200 table:value(s.name)
201 end)
202 table:value("")
203
204 import = sect_instances:option(Value, "import", "Import","")
205 import.optional=true
206 export = sect_instances:option(Value, "export", "Export", "")
207 export.optional=true
208 local_address = sect_instances:option(Value, "local_address", "Local BGP address", "")
209 local_address.optional=true
210 local_as = sect_instances:option(Value, "local_as", "Local AS", "")
211 local_as.optional=true
212
213 -- Section BGP Filters
214
215 sect_filters = m:section(TypedSection, "filter", "BGP Filters", "Filters of the BGP instances")
216 sect_filters.addremove = true
217 sect_filters.anonymous = false
218 sect_filters:depends("type", "bgp")
219
220 instance = sect_filters:option(ListValue, "instance", "BGP instance", "Filter's BGP instance")
221 instance:depends("type", "bgp")
222
223 uciout:foreach("bird4", "bgp",
224 function (s)
225 instance:value(s[".name"])
226 end)
227
228 type = sect_filters:option(Value, "type", "Filter type", "")
229 type.default = "bgp"
230
231 path = sect_filters:option(Value, "file_path", "Filter's file path", "Path to the Filter's file")
232 path:depends("type", "bgp")
233
234 function m.on_commit(self,map)
235 luci.sys.call('/etc/init.d/bird4 stop; /etc/init.d/bird4 start')
236 end
237
238 return m
239