e243fa6b96a744fe573792481c0ca8fe3d35499c
[feed/routing.git] / bird-openwrt / bird6-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("bird6", "Bird6 BGP protocol's configuration")
25
26 tab_templates = {}
27 uciout:foreach('bird6', '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("bird6", "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 local_address = sect_templates:option(Value, "local_address", "Local BGP address", "")
113 local_address.optional=true
114 local_as = sect_templates:option(Value, "local_as", "Local AS", "")
115 local_as.optional=true
116
117 -- Section BGP Instances:
118
119 sect_instances = m:section(TypedSection, "bgp", "BGP Instances", "Configuration of the BGP protocol instances")
120 sect_instances.addremove = true
121 sect_instances.anonymous = false
122
123 templates = sect_instances:option(ListValue, "template", "Templates", "Available BGP templates")
124
125 uciout:foreach("bird6", "bgp_template",
126 function(s)
127 templates:value(s[".name"])
128 end)
129 templates:value("")
130 neighbor_address = sect_instances:option(Value, "neighbor_address", "Neighbor IP Address", "")
131 neighbor_as = sect_instances:option(Value, "neighbor_as", "Neighbor AS", "")
132
133 disabled = sect_instances:option(Flag, "disabled", "Disabled", "Enable/Disable BGP Protocol")
134 disabled.optional=true
135 disabled.default=nil
136 table = sect_instances:option(ListValue, "table", "Table", "Set the table used for BGP Routing")
137 table.optional=true
138 uciout:foreach("bird6", "table",
139 function (s)
140 table:value(s.name)
141 end)
142 table:value("")
143
144 description = sect_instances:option(TextValue, "description", "Description", "Description of the current BGP instance")
145 description.optional = true
146
147 import = sect_instances:option(Value, "import", "Import","")
148 import.optional=true
149 export = sect_instances:option(Value, "export", "Export", "")
150 export.optional=true
151
152 source_addr = sect_instances:option(Value, "source_address", "Source Address", "Source address for BGP routing. By default uses Router ID")
153 source_addr.optional = true
154
155 local_address = sect_instances:option(Value, "local_address", "Local BGP address", "")
156 local_address.optional=true
157 local_as = sect_instances:option(Value, "local_as", "Local AS", "")
158 local_as.optional=true
159
160 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")
161 next_hop_self.default = nil
162 next_hop_self.optional = true
163
164 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")
165 next_hop_keep.default = nil
166 next_hop_keep.optional = true
167
168 rr_client = sect_instances:option(Flag, "rr_client", "Route Reflector server", "This router serves as a Route Reflector server and treats neighbors as clients")
169 rr_client.default = nil
170 rr_client.optional = true
171
172 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")
173 rr_cluster_id.optional = true
174
175 import_limit = sect_instances:option(Value, "import_limit", "Routes import limit", "Specify an import route limit. By default is disabled '0'")
176 import_limit.default="0"
177 import_limit.optional = true
178
179 import_limit_action = sect_instances:option(ListValue, "import_limit_action", "Routes import limit action", "Action to take when import routes limit ir reached")
180 import_limit_action:value("warn")
181 import_limit_action:value("block")
182 import_limit_action:value("disable")
183 import_limit_action:value("restart")
184 import_limit_action.default = "warn"
185 import_limit_action.optional = true
186
187 export_limit = sect_instances:option(Value, "export_limit", "Routes export limit", "Specify an export route limit. By default is disabled '0'")
188 export_limit.default="0"
189 export_limit.optional = true
190
191 export_limit_action = sect_instances:option(ListValue, "export_limit_action", "Routes export limit action", "Action to take when export routes limit is reached")
192 export_limit_action:value("warn")
193 export_limit_action:value("block")
194 export_limit_action:value("disable")
195 export_limit_action:value("restart")
196 export_limit_action.default = "warn"
197 export_limit_action.optional = true
198
199 receive_limit = sect_instances:option(Value, "receive_limit", "Routes received limit", "Specify a received route limit. By default is disabled '0'")
200 receive_limit.default="0"
201 receive_limit.optional = true
202
203 receive_limit_action = sect_instances:option(ListValue, "receive_limit_action", "Routes received limit action", "Action to take when received routes limit is reached")
204 receive_limit_action:value("warn")
205 receive_limit_action:value("block")
206 receive_limit_action:value("disable")
207 receive_limit_action:value("restart")
208 receive_limit_action.default = "warn"
209 receive_limit_action.optional = true
210
211 -- Section BGP Filters
212
213 sect_filters = m:section(TypedSection, "filter", "BGP Filters", "Filters of the BGP instances")
214 sect_filters.addremove = true
215 sect_filters.anonymous = false
216 sect_filters:depends("type", "bgp")
217
218 instance = sect_filters:option(ListValue, "instance", "BGP instance", "Filter's BGP instance")
219 instance:depends("type", "bgp")
220
221 uciout:foreach("bird6", "bgp",
222 function (s)
223 instance:value(s[".name"])
224 end)
225
226 type = sect_filters:option(Value, "type", "Filter type", "")
227 type.default = "bgp"
228
229 path = sect_filters:option(Value, "file_path", "Filter's file path", "Path to the Filter's file")
230 path:depends("type", "bgp")
231
232 function m.on_commit(self,map)
233 luci.sys.call('/etc/init.d/bird6 stop; /etc/init.d/bird6 start')
234 end
235
236 return m
237