applications/luci-olsr: rework ui
[project/luci.git] / applications / luci-olsr / luasrc / model / cbi / olsr / olsrd.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11         http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15
16 require("luci.tools.webadmin")
17
18 m = Map("olsrd", translate("OLSR Daemon"),
19         translate("The OLSR daemon is an implementation of the Optimized Link State Routing protocol. "..
20         "As such it allows mesh routing for any network equipment. "..
21         "It runs on any wifi card that supports ad-hoc mode and of course on any ethernet device. "..
22         "Visit <a href='http://www.olsr.org'>olsrd.org</a> for help and documentation."))
23
24 function m.on_parse()
25         local has_defaults = false
26
27         m.uci:foreach("olsrd", "InterfaceDefaults",
28                 function(s)
29                         has_defaults = true
30                         return false
31                 end)
32
33         if not has_defaults then
34                 m.uci:section("olsrd", "InterfaceDefaults")
35         end
36 end
37
38 s = m:section(TypedSection, "olsrd", translate("General settings"))
39 --s.dynamic = true
40 s.anonymous = true
41
42 s:tab("general",  translate("General Settings"))
43 s:tab("lquality", translate("Link Quality Settings"))
44 s:tab("advanced", translate("Advanced Settings"))
45
46
47 ipv = s:taboption("general", ListValue, "IpVersion", translate("Internet protocol"),
48         translate("IP-version to use. If 6and4 is selected then one olsrd instance is started for each protocol."))
49 ipv:value("4", "IPv4")
50 ipv:value("6", "IPv6")
51 ipv:value("6and4", "6and4")
52
53
54 poll = s:taboption("advanced", Value, "Pollrate", translate("Pollrate"),
55         translate("Polling rate for OLSR sockets in seconds. Default is 0.05."))
56 poll.optional = true
57 poll.datatype = "ufloat"
58 poll.placeholder = "0.05"
59
60 nicc = s:taboption("advanced", Value, "NicChgsPollInt", translate("Nic changes poll interval"),
61         translate("Interval to poll network interfaces for configuration changes (in seconds). Default is \"2.5\"."))
62 nicc.optional = true
63 nicc.datatype = "ufloat"
64 nicc.placeholder = "2.5"
65
66 tos = s:taboption("advanced", Value, "TosValue", translate("TOS value"),
67         translate("Type of service value for the IP header of control traffic. Default is \"16\"."))
68 tos.optional = true
69 tos.datatype = "uinteger"
70 tos.placeholder = "16"
71
72 fib = s:taboption("general", ListValue, "FIBMetric", translate("FIB metric"),
73         translate ("FIBMetric controls the metric value of the host-routes OLSRd sets. "..
74         "\"flat\" means that the metric value is always 2. This is the preferred value "..
75         "because it helps the linux kernel routing to clean up older routes. "..
76         "\"correct\" uses the hopcount as the metric value. "..
77         "\"approx\" use the hopcount as the metric value too, but does only update the hopcount if the nexthop changes too. "..
78         "Default is \"flat\"."))
79 fib:value("flat")
80 fib:value("correct")
81 fib:value("approx")
82
83 lql = s:taboption("lquality", ListValue, "LinkQualityLevel", translate("LQ level"),
84         translate("Link quality level switch between hopcount and cost-based (mostly ETX) routing.<br />"..
85         "<b>0</b> = do not use link quality<br />"..
86         "<b>2</b> = use link quality for MPR selection and routing<br />"..
87         "Default is \"2\""))
88 lql:value("2")
89 lql:value("0")
90
91 lqage = s:taboption("lquality", Value, "LinkQualityAging", translate("LQ aging"),
92         translate("Link quality aging factor (only for lq level 2). Tuning parameter for etx_float and etx_fpm, smaller values "..
93         "mean slower changes of ETX value. (allowed values are between 0.01 and 1.0)"))
94 lqage.optional = true
95 lqage:depends("LinkQualityLevel", "2")
96
97 lqa = s:taboption("lquality", ListValue, "LinkQualityAlgorithm", translate("LQ algorithm"),
98         translate("Link quality algorithm (only for lq level 2).<br />"..
99         "<b>etx_float</b>: floating point ETX with exponential aging<br />"..
100         "<b>etx_fpm</b>  : same as ext_float, but with integer arithmetic<br />"..
101         "<b>etx_ff</b>   : ETX freifunk, an etx variant which use all OLSR traffic (instead of only hellos) for ETX calculation<br />"..
102         "<b>etx_ffeth</b>: incompatible variant of etx_ff that allows ethernet links with ETX 0.1.<br />"..
103         "Defaults to \"etx_ff\""))
104 lqa.optional = true
105 lqa:value("etx_ff")
106 lqa:value("etx_fpm")
107 lqa:value("etx_float")
108 lqa:value("etx_ffeth")
109 lqa:depends("LinkQualityLevel", "2")
110 lqa.optional = true
111
112 lqfish = s:taboption("lquality", Flag, "LinkQualityFishEye", translate("LQ fisheye"),
113         translate("Fisheye mechanism for TCs (checked means on). Default is \"on\""))
114 lqfish.default = "1"
115 lqfish.optional = true
116
117 hyst = s:taboption("lquality", Flag, "UseHysteresis", translate("Use hysteresis"),
118         translate("Hysteresis for link sensing (only for hopcount metric). Hysteresis adds more robustness to the link sensing "..
119         "but delays neighbor registration. Defaults is \"yes\""))
120 hyst.default = "yes"
121 hyst.enabled = "yes"
122 hyst.disabled = "no"
123 hyst:depends("LinkQualityLevel", "0")
124 hyst.optional = true
125
126 port = s:taboption("general", Value, "OlsrPort", translate("Port"),
127         translate("The port OLSR uses. This should usually stay at the IANA assigned port 698. It can have a value between 1 and 65535."))
128 port.optional = true
129 port.default = "698"
130 port.rmempty = true
131
132 mainip = s:taboption("general", Value, "MainIp", translate("Main IP"),
133         translate("Sets the main IP (originator ip) of the router. This IP will NEVER change during the uptime of olsrd. "..
134         "Default is 0.0.0.0, which triggers usage of the IP of the first interface."))
135 mainip.optional = true
136 mainip.rmempty = true
137 mainip.datatype = "ipaddr"
138 mainip.placeholder = "0.0.0.0"
139
140 willingness = s:taboption("advanced", ListValue, "Willingness", translate("Willingness"),
141                 translate("The fixed willingness to use. If not set willingness will be calculated dynamically based on battery/power status. Default is \"3\"."))
142 for i=0,7 do
143         willingness:value(i)
144 end
145 willingness.optional = true
146 willingness.default = "3"
147
148 natthr = s:taboption("advanced", Value, "NatThreshold", translate("NAT threshold"),
149         translate("If the route to the current gateway is to be changed, the ETX value of this gateway is "..
150         "multiplied with this value before it is compared to the new one. "..
151         "The parameter can be a value between 0.1 and 1.0, but should be close to 1.0 if changed.<br />"..
152         "<b>WARNING:</b> This parameter should not be used together with the etx_ffeth metric!<br />"..
153         "Defaults to \"1.0\"."))
154 for i=1,0.1,-0.1 do
155         natthr:value(i)
156 end
157 natthr:depends("LinkQualityAlgorithm", "etx_ff")
158 natthr:depends("LinkQualityAlgorithm", "etx_float")
159 natthr:depends("LinkQualityAlgorithm", "etx_fpm")
160 natthr.default = 1
161 natthr.optional = true
162
163
164 i = m:section(TypedSection, "InterfaceDefaults", translate("Interfaces Defaults"))
165 i.anonymous = true
166 i.addremove = false
167
168 i:tab("general", translate("General Settings"))
169 i:tab("addrs",   translate("IP Addresses"))
170 i:tab("timing",  translate("Timing and Validity"))
171
172 mode = i:taboption("general", ListValue, "Mode", translate("Mode"),
173         translate("Interface Mode is used to prevent unnecessary packet forwarding on switched ethernet interfaces. "..
174         "valid Modes are \"mesh\" and \"ether\". Default is \"mesh\"."))
175 mode:value("mesh")
176 mode:value("ether")
177 mode.optional = true
178 mode.rmempty = true
179
180
181 weight = i:taboption("general", Value, "Weight", translate("Weight"),
182         translate("When multiple links exist between hosts the weight of interface is used to determine the link to use. "..
183         "Normally the weight is automatically calculated by olsrd based on the characteristics of the interface, "..
184         "but here you can specify a fixed value. Olsrd will choose links with the lowest value.<br />"..
185         "<b>Note:</b> Interface weight is used only when LinkQualityLevel is set to 0. "..
186         "For any other value of LinkQualityLevel, the interface ETX value is used instead."))
187 weight.optional = true
188 weight.datatype = "uinteger"
189 weight.placeholder = "0"
190
191 lqmult = i:taboption("general", DynamicList, "LinkQualityMult", translate("LinkQuality Multiplicator"),
192         translate("Multiply routes with the factor given here. Allowed values are between 0.01 and 1. "..
193         "It is only used when LQ-Level is greater than 0. Examples:<br />"..
194         "reduce LQ to 192.168.0.1 by half: 192.168.0.1 0.5<br />"..
195         "reduce LQ to all nodes on this interface by 20%: default 0.8"))
196 lqmult.optional = true
197 lqmult.rmempty = true
198 lqmult.cast = "table"
199 lqmult.placeholder = "default 1.0"
200
201
202 ip4b = i:taboption("addrs", Value, "Ip4Broadcast", translate("IPv4 broadcast"),
203         translate("IPv4 broadcast address for outgoing OLSR packets. One useful example would be 255.255.255.255. "..
204         "Default is \"0.0.0.0\", which triggers the usage of the interface broadcast IP."))
205 ip4b.optional = true
206 ip4b.datatype = "ip4addr"
207 ip4b.placeholder = "0.0.0.0"
208
209 ip6m = i:taboption("addrs", Value, "IPv6Multicast", translate("IPv6 multicast"),
210         translate("IPv6 multicast address. Default is \"FF02::6D\", the manet-router linklocal multicast."))
211 ip6m.optional = true
212 ip6m.datatype = "ip6addr"
213 ip6m.placeholder = "FF02::6D"
214
215 ip4s = i:taboption("addrs", Value, "IPv4Src", translate("IPv4 source"),
216         translate("IPv4 src address for outgoing OLSR packages. Default is \"0.0.0.0\", which triggers usage of the interface IP."))
217 ip4s.optional = true
218 ip4s.datatype = "ip4addr"
219 ip4s.placeholder = "0.0.0.0"
220
221 ip6s = i:taboption("addrs", Value, "IPv6Src", translate("IPv6 source"),
222         translate("IPv6 src prefix. OLSRd will choose one of the interface IPs which matches the prefix of this parameter. "..
223         "Default is \"0::/0\", which triggers the usage of a not-linklocal interface IP."))
224 ip6s.optional = true
225 ip6s.datatype = "ip6addr"
226 ip6s.placeholder = "0::/0"
227
228
229 hi = i:taboption("timing", Value, "HelloInterval", translate("Hello interval"))
230 hi.optional = true
231 hi.datatype = "ufloat"
232 hi.placeholder = "5.0"
233
234 hv = i:taboption("timing", Value, "HelloValidityTime", translate("Hello validity time"))
235 hv.optional = true
236 hv.datatype = "ufloat"
237 hv.placeholder = "40.0"
238
239 ti = i:taboption("timing", Value, "TcInterval", translate("TC interval"))
240 ti.optional = true
241 ti.datatype = "ufloat"
242 ti.placeholder = "2.0"
243
244 tv = i:taboption("timing", Value, "TcValidityTime", translate("TC validity time"))
245 tv.optional = true
246 tv.datatype = "ufloat"
247 tv.placeholder = "256.0"
248
249 mi = i:taboption("timing", Value, "MidInterval", translate("MID interval"))
250 mi.optional = true
251 mi.datatype = "ufloat"
252 mi.placeholder = "18.0"
253
254 mv = i:taboption("timing", Value, "MidValidityTime", translate("MID validity time"))
255 mv.optional = true
256 mv.datatype = "ufloat"
257 mv.placeholder = "324.0"
258
259 ai = i:taboption("timing", Value, "HnaInterval", translate("HNA interval"))
260 ai.optional = true
261 ai.datatype = "ufloat"
262 ai.placeholder = "18.0"
263
264 av = i:taboption("timing", Value, "HnaValidityTime", translate("HNA validity time"))
265 av.optional = true
266 av.datatype = "ufloat"
267 av.placeholder = "108.0"
268
269
270 ifs = m:section(TypedSection, "Interface", translate("Interfaces"))
271 ifs.addremove = true
272 ifs.anonymous = true
273 ifs.extedit   = luci.dispatcher.build_url("admin/services/olsrd/iface/%s")
274 ifs.template  = "cbi/tblsection"
275
276 ign = ifs:option(Flag, "ignore", translate("Enable"))
277 ign.enabled  = "0"
278 ign.disabled = "1"
279 ign.rmempty = false
280 function ign.cfgvalue(self, section)
281         return Flag.cfgvalue(self, section) or "0"
282 end
283
284 network = ifs:option(DummyValue, "interface", translate("Network"))
285 network.template = "cbi/network_netinfo"
286
287 mode = ifs:option(DummyValue, "Mode", translate("Mode"))
288 function mode.cfgvalue(...)
289         return Value.cfgvalue(...) or "mesh"
290 end
291
292 hello = ifs:option(DummyValue, "_hello", translate("Hello"))
293 function hello.cfgvalue(self, section)
294         local i = tonumber(m.uci:get("olsrd", section, "HelloInterval"))     or 5
295         local v = tonumber(m.uci:get("olsrd", section, "HelloValidityTime")) or 40
296         return "%.01fs / %.01fs" %{ i, v }
297 end
298
299 tc = ifs:option(DummyValue, "_tc", translate("TC"))
300 function tc.cfgvalue(self, section)
301         local i = tonumber(m.uci:get("olsrd", section, "TcInterval"))     or 2
302         local v = tonumber(m.uci:get("olsrd", section, "TcValidityTime")) or 256
303         return "%.01fs / %.01fs" %{ i, v }
304 end
305
306 mid = ifs:option(DummyValue, "_mid", translate("MID"))
307 function mid.cfgvalue(self, section)
308         local i = tonumber(m.uci:get("olsrd", section, "MidInterval"))     or 18
309         local v = tonumber(m.uci:get("olsrd", section, "MidValidityTime")) or 324
310         return "%.01fs / %.01fs" %{ i, v }
311 end
312
313 hna = ifs:option(DummyValue, "_hna", translate("HNA"))
314 function hna.cfgvalue(self, section)
315         local i = tonumber(m.uci:get("olsrd", section, "HnaInterval"))     or 18
316         local v = tonumber(m.uci:get("olsrd", section, "HnaValidityTime")) or 108
317         return "%.01fs / %.01fs" %{ i, v }
318 end
319
320 return m