Update my email addresses in the license headers
[project/luci.git] / applications / luci-app-olsr / luasrc / model / cbi / olsr / olsrd6.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
3 -- Licensed to the public under the Apache License 2.0.
4
5 require("luci.tools.webadmin")
6 local fs  = require "nixio.fs"
7 local util = require "luci.util"
8 local ip = require "luci.ip"
9
10 local has_ipip  = fs.glob("/etc/modules.d/[0-9]*-ipip")()
11
12 m = Map("olsrd6", translate("OLSR Daemon"),
13         translate("The OLSR daemon is an implementation of the Optimized Link State Routing protocol. "..
14         "As such it allows mesh routing for any network equipment. "..
15         "It runs on any wifi card that supports ad-hoc mode and of course on any ethernet device. "..
16         "Visit <a href='http://www.olsr.org'>olsrd.org</a> for help and documentation."))
17
18 function m.on_parse()
19         local has_defaults = false
20
21         m.uci:foreach("olsrd6", "InterfaceDefaults",
22                 function(s)
23                         has_defaults = true
24                         return false
25                 end)
26
27         if not has_defaults then
28                 m.uci:section("olsrd6", "InterfaceDefaults")
29         end
30 end
31
32 function write_float(self, section, value)
33     local n = tonumber(value)
34     if n ~= nil then
35         return Value.write(self, section, "%.1f" % n) 
36     end
37 end
38
39 s = m:section(TypedSection, "olsrd6", translate("General settings"))
40 s.anonymous = true
41
42 s:tab("general",  translate("General Settings"))
43 s:tab("lquality", translate("Link Quality Settings"))
44 s:tab("smartgw", translate("SmartGW"), not has_ipip and translate("Warning: kmod-ipip is not installed. Without kmod-ipip SmartGateway will not work, please install it."))
45 s:tab("advanced", translate("Advanced Settings"))
46
47 poll = s:taboption("advanced", Value, "Pollrate", translate("Pollrate"),
48         translate("Polling rate for OLSR sockets in seconds. Default is 0.05."))
49 poll.optional = true
50 poll.datatype = "ufloat"
51 poll.placeholder = "0.05"
52
53 nicc = s:taboption("advanced", Value, "NicChgsPollInt", translate("Nic changes poll interval"),
54         translate("Interval to poll network interfaces for configuration changes (in seconds). Default is \"2.5\"."))
55 nicc.optional = true
56 nicc.datatype = "ufloat"
57 nicc.placeholder = "2.5"
58
59 tos = s:taboption("advanced", Value, "TosValue", translate("TOS value"),
60         translate("Type of service value for the IP header of control traffic. Default is \"16\"."))
61 tos.optional = true
62 tos.datatype = "uinteger"
63 tos.placeholder = "16"
64
65 fib = s:taboption("general", ListValue, "FIBMetric", translate("FIB metric"),
66         translate ("FIBMetric controls the metric value of the host-routes OLSRd sets. "..
67         "\"flat\" means that the metric value is always 2. This is the preferred value "..
68         "because it helps the linux kernel routing to clean up older routes. "..
69         "\"correct\" uses the hopcount as the metric value. "..
70         "\"approx\" use the hopcount as the metric value too, but does only update the hopcount if the nexthop changes too. "..
71         "Default is \"flat\"."))
72 fib:value("flat")
73 fib:value("correct")
74 fib:value("approx")
75
76 lql = s:taboption("lquality", ListValue, "LinkQualityLevel", translate("LQ level"),
77         translate("Link quality level switch between hopcount and cost-based (mostly ETX) routing.<br />"..
78         "<b>0</b> = do not use link quality<br />"..
79         "<b>2</b> = use link quality for MPR selection and routing<br />"..
80         "Default is \"2\""))
81 lql:value("2")
82 lql:value("0")
83
84 lqage = s:taboption("lquality", Value, "LinkQualityAging", translate("LQ aging"),
85         translate("Link quality aging factor (only for lq level 2). Tuning parameter for etx_float and etx_fpm, smaller values "..
86         "mean slower changes of ETX value. (allowed values are between 0.01 and 1.0)"))
87 lqage.optional = true
88 lqage:depends("LinkQualityLevel", "2")
89
90 lqa = s:taboption("lquality", ListValue, "LinkQualityAlgorithm", translate("LQ algorithm"),
91         translate("Link quality algorithm (only for lq level 2).<br />"..
92         "<b>etx_float</b>: floating point ETX with exponential aging<br />"..
93         "<b>etx_fpm</b>  : same as etx_float, but with integer arithmetic<br />"..
94         "<b>etx_ff</b>   : ETX freifunk, an etx variant which use all OLSR traffic (instead of only hellos) for ETX calculation<br />"..
95         "<b>etx_ffeth</b>: incompatible variant of etx_ff that allows ethernet links with ETX 0.1.<br />"..
96         "Defaults to \"etx_ff\""))
97 lqa.optional = true
98 lqa:value("etx_ff")
99 lqa:value("etx_fpm")
100 lqa:value("etx_float")
101 lqa:value("etx_ffeth")
102 lqa:depends("LinkQualityLevel", "2")
103 lqa.optional = true
104
105 lqfish = s:taboption("lquality", Flag, "LinkQualityFishEye", translate("LQ fisheye"),
106         translate("Fisheye mechanism for TCs (checked means on). Default is \"on\""))
107 lqfish.default = "1"
108 lqfish.optional = true
109
110 hyst = s:taboption("lquality", Flag, "UseHysteresis", translate("Use hysteresis"),
111         translate("Hysteresis for link sensing (only for hopcount metric). Hysteresis adds more robustness to the link sensing "..
112         "but delays neighbor registration. Defaults is \"yes\""))
113 hyst.default = "yes"
114 hyst.enabled = "yes"
115 hyst.disabled = "no"
116 hyst:depends("LinkQualityLevel", "0")
117 hyst.optional = true
118 hyst.rmempty = true
119
120 port = s:taboption("general", Value, "OlsrPort", translate("Port"),
121         translate("The port OLSR uses. This should usually stay at the IANA assigned port 698. It can have a value between 1 and 65535."))
122 port.optional = true
123 port.default = "698"
124 port.rmempty = true
125
126 mainip = s:taboption("general", Value, "MainIp", translate("Main IP"),
127         translate("Sets the main IP (originator ip) of the router. This IP will NEVER change during the uptime of olsrd. "..
128         "Default is ::, which triggers usage of the IP of the first interface."))
129 mainip.optional = true
130 mainip.rmempty = true
131 mainip.datatype = "ipaddr"
132 mainip.placeholder = "::"
133
134 sgw = s:taboption("smartgw", Flag, "SmartGateway", translate("Enable"), translate("Enable SmartGateway. If it is disabled, then " ..
135         "all other SmartGateway parameters are ignored. Default is \"no\"."))
136 sgw.default="no"
137 sgw.enabled="yes"
138 sgw.disabled="no"
139 sgw.rmempty = true
140
141 sgwnat = s:taboption("smartgw", Flag, "SmartGatewayAllowNAT", translate("Allow gateways with NAT"), translate("Allow the selection of an outgoing ipv4 gateway with NAT"))
142 sgwnat:depends("SmartGateway", "yes")
143 sgwnat.default="yes"
144 sgwnat.enabled="yes"
145 sgwnat.disabled="no"
146 sgwnat.optional = true
147 sgwnat.rmempty = true
148
149 sgwuplink = s:taboption("smartgw", ListValue, "SmartGatewayUplink", translate("Announce uplink"), translate("Which kind of uplink is exported to the other mesh nodes. " ..
150         "An uplink is detected by looking for a local HNA6 ::ffff:0:0/96 or 2000::/3. Default setting is \"both\"."))
151 sgwuplink:value("none")
152 sgwuplink:value("ipv4")
153 sgwuplink:value("ipv6")
154 sgwuplink:value("both")
155 sgwuplink:depends("SmartGateway", "yes")
156 sgwuplink.default="both"
157 sgwuplink.optional = true
158 sgwuplink.rmempty = true
159
160 sgwulnat = s:taboption("smartgw", Flag, "SmartGatewayUplinkNAT", translate("Uplink uses NAT"), translate("If this Node uses NAT for connections to the internet. " ..
161         "Default is \"yes\"."))
162 sgwulnat:depends("SmartGatewayUplink", "ipv4")
163 sgwulnat:depends("SmartGatewayUplink", "both")
164 sgwulnat.default="yes"
165 sgwulnat.enabled="yes"
166 sgwulnat.disabled="no"
167 sgwnat.optional = true
168 sgwnat.rmempty = true
169
170 sgwspeed = s:taboption("smartgw", Value, "SmartGatewaySpeed", translate("Speed of the uplink"), translate("Specifies the speed of "..
171         "the uplink in kilobits/s. First parameter is upstream, second parameter is downstream. Default is \"128 1024\"."))
172 sgwspeed:depends("SmartGatewayUplink", "ipv4")
173 sgwspeed:depends("SmartGatewayUplink", "ipv6")
174 sgwspeed:depends("SmartGatewayUplink", "both")
175 sgwspeed.optional = true
176 sgwspeed.rmempty = true
177
178 sgwprefix = s:taboption("smartgw", Value, "SmartGatewayPrefix", translate("IPv6-Prefix of the uplink"), translate("This can be used " ..
179         "to signal the external IPv6 prefix of the uplink to the clients. This might allow a client to change it's local IPv6 address to " ..
180         "use the IPv6 gateway without any kind of address translation. The maximum prefix length is 64 bits. " ..
181         "Default is \"::/0\" (no prefix)."))
182 sgwprefix:depends("SmartGatewayUplink", "ipv6")
183 sgwprefix:depends("SmartGatewayUplink", "both")
184 sgwprefix.optional = true
185 sgwprefix.rmempty = true
186
187 willingness = s:taboption("advanced", ListValue, "Willingness", translate("Willingness"),
188                 translate("The fixed willingness to use. If not set willingness will be calculated dynamically based on battery/power status. Default is \"3\"."))
189 for i=0,7 do
190         willingness:value(i)
191 end
192 willingness.optional = true
193 willingness.default = "3"
194
195 natthr = s:taboption("advanced", Value, "NatThreshold", translate("NAT threshold"),
196         translate("If the route to the current gateway is to be changed, the ETX value of this gateway is "..
197         "multiplied with this value before it is compared to the new one. "..
198         "The parameter can be a value between 0.1 and 1.0, but should be close to 1.0 if changed.<br />"..
199         "<b>WARNING:</b> This parameter should not be used together with the etx_ffeth metric!<br />"..
200         "Defaults to \"1.0\"."))
201 for i=1,0.1,-0.1 do
202         natthr:value(i)
203 end
204 natthr:depends("LinkQualityAlgorithm", "etx_ff")
205 natthr:depends("LinkQualityAlgorithm", "etx_float")
206 natthr:depends("LinkQualityAlgorithm", "etx_fpm")
207 natthr.default = "1.0"
208 natthr.optional = true
209 natthr.write = write_float
210
211
212 i = m:section(TypedSection, "InterfaceDefaults", translate("Interfaces Defaults"))
213 i.anonymous = true
214 i.addremove = false
215
216 i:tab("general", translate("General Settings"))
217 i:tab("addrs",   translate("IP Addresses"))
218 i:tab("timing",  translate("Timing and Validity"))
219
220 mode = i:taboption("general", ListValue, "Mode", translate("Mode"),
221         translate("Interface Mode is used to prevent unnecessary packet forwarding on switched ethernet interfaces. "..
222         "valid Modes are \"mesh\" and \"ether\". Default is \"mesh\"."))
223 mode:value("mesh")
224 mode:value("ether")
225 mode.optional = true
226 mode.rmempty = true
227
228
229 weight = i:taboption("general", Value, "Weight", translate("Weight"),
230         translate("When multiple links exist between hosts the weight of interface is used to determine the link to use. "..
231         "Normally the weight is automatically calculated by olsrd based on the characteristics of the interface, "..
232         "but here you can specify a fixed value. Olsrd will choose links with the lowest value.<br />"..
233         "<b>Note:</b> Interface weight is used only when LinkQualityLevel is set to 0. "..
234         "For any other value of LinkQualityLevel, the interface ETX value is used instead."))
235 weight.optional = true
236 weight.datatype = "uinteger"
237 weight.placeholder = "0"
238
239 lqmult = i:taboption("general", DynamicList, "LinkQualityMult", translate("LinkQuality Multiplicator"),
240         translate("Multiply routes with the factor given here. Allowed values are between 0.01 and 1.0. "..
241         "It is only used when LQ-Level is greater than 0. Examples:<br />"..
242         "reduce LQ to fd91:662e:3c58::1 by half: fd91:662e:3c58::1 0.5<br />"..
243         "reduce LQ to all nodes on this interface by 20%: default 0.8"))
244 lqmult.optional = true
245 lqmult.rmempty = true
246 lqmult.cast = "table"
247 lqmult.placeholder = "default 1.0"
248
249 function lqmult.validate(self, value)
250         for _, v in pairs(value) do
251                 if v ~= "" then
252                         local val = util.split(v, " ")
253                         local host = val[1]
254                         local mult = val[2]
255                         if not host or not mult then
256                                 return nil, translate("LQMult requires two values (IP address or 'default' and multiplicator) seperated by space.")
257                         end
258                         if not (host == "default" or ip.IPv6(host)) then
259                                 return nil, translate("Can only be a valid IPv6 address or 'default'")
260                         end
261                         if not tonumber(mult) or tonumber(mult) > 1 or tonumber(mult) < 0.01 then
262                                 return nil, translate("Invalid Value for LQMult-Value. Must be between 0.01 and 1.0.")
263                         end
264                         if not mult:match("[0-1]%.[0-9]+") then
265                                 return nil, translate("Invalid Value for LQMult-Value. You must use a decimal number between 0.01 and 1.0 here.")
266                         end
267                 end
268         end
269         return value
270 end
271
272 ip6m = i:taboption("addrs", Value, "IPv6Multicast", translate("IPv6 multicast"),
273         translate("IPv6 multicast address. Default is \"FF02::6D\", the manet-router linklocal multicast."))
274 ip6m.optional = true
275 ip6m.datatype = "ip6addr"
276 ip6m.placeholder = "FF02::6D"
277
278 ip6s = i:taboption("addrs", Value, "IPv6Src", translate("IPv6 source"),
279         translate("IPv6 src prefix. OLSRd will choose one of the interface IPs which matches the prefix of this parameter. "..
280         "Default is \"0::/0\", which triggers the usage of a not-linklocal interface IP."))
281 ip6s.optional = true
282 ip6s.datatype = "ip6addr"
283 ip6s.placeholder = "0::/0"
284
285
286 hi = i:taboption("timing", Value, "HelloInterval", translate("Hello interval"))
287 hi.optional = true
288 hi.datatype = "ufloat"
289 hi.placeholder = "5.0"
290 hi.write = write_float
291
292 hv = i:taboption("timing", Value, "HelloValidityTime", translate("Hello validity time"))
293 hv.optional = true
294 hv.datatype = "ufloat"
295 hv.placeholder = "40.0"
296 hv.write = write_float
297
298 ti = i:taboption("timing", Value, "TcInterval", translate("TC interval"))
299 ti.optional = true
300 ti.datatype = "ufloat"
301 ti.placeholder = "2.0"
302 ti.write = write_float
303
304 tv = i:taboption("timing", Value, "TcValidityTime", translate("TC validity time"))
305 tv.optional = true
306 tv.datatype = "ufloat"
307 tv.placeholder = "256.0"
308 tv.write = write_float
309
310 mi = i:taboption("timing", Value, "MidInterval", translate("MID interval"))
311 mi.optional = true
312 mi.datatype = "ufloat"
313 mi.placeholder = "18.0"
314 mi.write = write_float
315
316 mv = i:taboption("timing", Value, "MidValidityTime", translate("MID validity time"))
317 mv.optional = true
318 mv.datatype = "ufloat"
319 mv.placeholder = "324.0"
320 mv.write = write_float
321
322 ai = i:taboption("timing", Value, "HnaInterval", translate("HNA interval"))
323 ai.optional = true
324 ai.datatype = "ufloat"
325 ai.placeholder = "18.0"
326 ai.write = write_float
327
328 av = i:taboption("timing", Value, "HnaValidityTime", translate("HNA validity time"))
329 av.optional = true
330 av.datatype = "ufloat"
331 av.placeholder = "108.0"
332 av.write = write_float
333
334
335 ifs = m:section(TypedSection, "Interface", translate("Interfaces"))
336 ifs.addremove = true
337 ifs.anonymous = true
338 ifs.extedit   = luci.dispatcher.build_url("admin/services/olsrd6/iface/%s")
339 ifs.template  = "cbi/tblsection"
340
341 function ifs.create(...)
342         local sid = TypedSection.create(...)
343         luci.http.redirect(ifs.extedit % sid)
344 end
345
346 ign = ifs:option(Flag, "ignore", translate("Enable"))
347 ign.enabled  = "0"
348 ign.disabled = "1"
349 ign.rmempty = false
350 function ign.cfgvalue(self, section)
351         return Flag.cfgvalue(self, section) or "0"
352 end
353
354 network = ifs:option(DummyValue, "interface", translate("Network"))
355 network.template = "cbi/network_netinfo"
356
357 mode = ifs:option(DummyValue, "Mode", translate("Mode"))
358 function mode.cfgvalue(...)
359         return Value.cfgvalue(...) or m.uci:get_first("olsrd6", "InterfaceDefaults", "Mode", "mesh")
360 end
361
362 hello = ifs:option(DummyValue, "_hello", translate("Hello"))
363 function hello.cfgvalue(self, section)
364         local i = tonumber(m.uci:get("olsrd6", section, "HelloInterval"))     or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "HelloInterval", 5))
365         local v = tonumber(m.uci:get("olsrd6", section, "HelloValidityTime")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "HelloValidityTime", 40))
366         return "%.01fs / %.01fs" %{ i, v }
367 end
368
369 tc = ifs:option(DummyValue, "_tc", translate("TC"))
370 function tc.cfgvalue(self, section)
371         local i = tonumber(m.uci:get("olsrd6", section, "TcInterval"))     or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "TcInterval", 2))
372         local v = tonumber(m.uci:get("olsrd6", section, "TcValidityTime")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "TcValidityTime", 256))
373         return "%.01fs / %.01fs" %{ i, v }
374 end
375
376 mid = ifs:option(DummyValue, "_mid", translate("MID"))
377 function mid.cfgvalue(self, section)
378         local i = tonumber(m.uci:get("olsrd6", section, "MidInterval"))     or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "MidInterval", 18))
379         local v = tonumber(m.uci:get("olsrd6", section, "MidValidityTime")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "MidValidityTime", 324))
380         return "%.01fs / %.01fs" %{ i, v }
381 end
382
383 hna = ifs:option(DummyValue, "_hna", translate("HNA"))
384 function hna.cfgvalue(self, section)
385         local i = tonumber(m.uci:get("olsrd6", section, "HnaInterval"))     or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "HnaInterval", 18))
386         local v = tonumber(m.uci:get("olsrd6", section, "HnaValidityTime")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "HnaValidityTime", 108))
387         return "%.01fs / %.01fs" %{ i, v }
388 end
389
390 return m