Update my email addresses in the license headers
[project/luci.git] / applications / luci-app-olsr / luasrc / model / cbi / olsr / olsrdiface.lua
1 -- Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 local util = require "luci.util"
5 local ip = require "luci.ip"
6
7 function write_float(self, section, value)
8     local n = tonumber(value)
9     if n ~= nil then
10         return Value.write(self, section, "%.1f" % n)
11     end
12 end
13
14 m = Map("olsrd", translate("OLSR Daemon - Interface"),
15         translate("The OLSR daemon is an implementation of the Optimized Link State Routing protocol. "..
16         "As such it allows mesh routing for any network equipment. "..
17         "It runs on any wifi card that supports ad-hoc mode and of course on any ethernet device. "..
18         "Visit <a href='http://www.olsr.org'>olsrd.org</a> for help and documentation."))
19
20 m.redirect = luci.dispatcher.build_url("admin/services/olsrd")
21
22 if not arg[1] or m.uci:get("olsrd", arg[1]) ~= "Interface" then
23         luci.http.redirect(m.redirect)
24         return
25 end
26
27 i = m:section(NamedSection, arg[1], "Interface", translate("Interface"))
28 i.anonymous = true
29 i.addremove = false
30
31 i:tab("general", translate("General Settings"))
32 i:tab("addrs",   translate("IP Addresses"))
33 i:tab("timing",  translate("Timing and Validity"))
34
35 ign = i:taboption("general", Flag, "ignore", translate("Enable"),
36         translate("Enable this interface."))
37 ign.enabled  = "0"
38 ign.disabled = "1"
39 ign.rmempty = false
40 function ign.cfgvalue(self, section)
41         return Flag.cfgvalue(self, section) or "0"
42 end
43
44 network = i:taboption("general", Value, "interface", translate("Network"),
45         translate("The interface OLSRd should serve."))
46
47 network.template = "cbi/network_netlist"
48 network.widget   = "radio"
49 network.nocreate = true
50
51 mode = i:taboption("general", ListValue, "Mode", translate("Mode"),
52         translate("Interface Mode is used to prevent unnecessary packet forwarding on switched ethernet interfaces. "..
53         "valid Modes are \"mesh\" and \"ether\". Default is \"mesh\"."))
54 mode:value("mesh")
55 mode:value("ether")
56 mode.optional = true
57 mode.rmempty = true
58
59
60 weight = i:taboption("general", Value, "Weight", translate("Weight"),
61         translate("When multiple links exist between hosts the weight of interface is used to determine the link to use. "..
62         "Normally the weight is automatically calculated by olsrd based on the characteristics of the interface, "..
63         "but here you can specify a fixed value. Olsrd will choose links with the lowest value.<br />"..
64         "<b>Note:</b> Interface weight is used only when LinkQualityLevel is set to 0. "..
65         "For any other value of LinkQualityLevel, the interface ETX value is used instead."))
66 weight.optional = true
67 weight.datatype = "uinteger"
68 weight.placeholder = "0"
69
70 lqmult = i:taboption("general", DynamicList, "LinkQualityMult", translate("LinkQuality Multiplicator"),
71         translate("Multiply routes with the factor given here. Allowed values are between 0.01 and 1.0. "..
72         "It is only used when LQ-Level is greater than 0. Examples:<br />"..
73         "reduce LQ to 192.168.0.1 by half: 192.168.0.1 0.5<br />"..
74         "reduce LQ to all nodes on this interface by 20%: default 0.8"))
75 lqmult.optional = true
76 lqmult.rmempty = true
77 lqmult.cast = "table"
78 lqmult.placeholder = "default 1.0"
79
80 function lqmult.validate(self, value)
81         for _, v in pairs(value) do
82                 if v ~= "" then
83                         local val = util.split(v, " ")
84                         local host = val[1]
85                         local mult = val[2]
86                         if not host or not mult then
87                                 return nil, translate("LQMult requires two values (IP address or 'default' and multiplicator) seperated by space.")
88                         end
89                         if not (host == "default" or ip.IPv4(host) or ip.IPv6(host)) then
90                                 return nil, translate("Can only be a valid IPv4 or IPv6 address or 'default'")
91                         end
92                         if not tonumber(mult) or tonumber(mult) > 1 or tonumber(mult) < 0.01 then
93                                 return nil, translate("Invalid Value for LQMult-Value. Must be between 0.01 and 1.0.")
94                         end
95                         if not mult:match("[0-1]%.[0-9]+") then
96                                 return nil, translate("Invalid Value for LQMult-Value. You must use a decimal number between 0.01 and 1.0 here.")
97                         end
98                 end
99         end
100         return value
101 end
102
103 ip4b = i:taboption("addrs", Value, "Ip4Broadcast", translate("IPv4 broadcast"),
104         translate("IPv4 broadcast address for outgoing OLSR packets. One useful example would be 255.255.255.255. "..
105         "Default is \"0.0.0.0\", which triggers the usage of the interface broadcast IP."))
106 ip4b.optional = true
107 ip4b.datatype = "ip4addr"
108 ip4b.placeholder = "0.0.0.0"
109
110 ip6m = i:taboption("addrs", Value, "IPv6Multicast", translate("IPv6 multicast"),
111         translate("IPv6 multicast address. Default is \"FF02::6D\", the manet-router linklocal multicast."))
112 ip6m.optional = true
113 ip6m.datatype = "ip6addr"
114 ip6m.placeholder = "FF02::6D"
115
116 ip4s = i:taboption("addrs", Value, "IPv4Src", translate("IPv4 source"),
117         translate("IPv4 src address for outgoing OLSR packages. Default is \"0.0.0.0\", which triggers usage of the interface IP."))
118 ip4s.optional = true
119 ip4s.datatype = "ip4addr"
120 ip4s.placeholder = "0.0.0.0"
121
122 ip6s = i:taboption("addrs", Value, "IPv6Src", translate("IPv6 source"),
123         translate("IPv6 src prefix. OLSRd will choose one of the interface IPs which matches the prefix of this parameter. "..
124         "Default is \"0::/0\", which triggers the usage of a not-linklocal interface IP."))
125 ip6s.optional = true
126 ip6s.datatype = "ip6addr"
127 ip6s.placeholder = "0::/0"
128
129 hi = i:taboption("timing", Value, "HelloInterval", translate("Hello interval"))
130 hi.optional = true
131 hi.datatype = "ufloat"
132 hi.placeholder = "5.0"
133 hi.write = write_float
134
135 hv = i:taboption("timing", Value, "HelloValidityTime", translate("Hello validity time"))
136 hv.optional = true
137 hv.datatype = "ufloat"
138 hv.placeholder = "40.0"
139 hv.write = write_float
140
141 ti = i:taboption("timing", Value, "TcInterval", translate("TC interval"))
142 ti.optional = true
143 ti.datatype = "ufloat"
144 ti.placeholder = "2.0"
145 ti.write = write_float
146
147 tv = i:taboption("timing", Value, "TcValidityTime", translate("TC validity time"))
148 tv.optional = true
149 tv.datatype = "ufloat"
150 tv.placeholder = "256.0"
151 tv.write = write_float
152
153 mi = i:taboption("timing", Value, "MidInterval", translate("MID interval"))
154 mi.optional = true
155 mi.datatype = "ufloat"
156 mi.placeholder = "18.0"
157 mi.write = write_float
158
159 mv = i:taboption("timing", Value, "MidValidityTime", translate("MID validity time"))
160 mv.optional = true
161 mv.datatype = "ufloat"
162 mv.placeholder = "324.0"
163 mv.write = write_float
164
165 ai = i:taboption("timing", Value, "HnaInterval", translate("HNA interval"))
166 ai.optional = true
167 ai.datatype = "ufloat"
168 ai.placeholder = "18.0"
169 ai.write = write_float
170
171 av = i:taboption("timing", Value, "HnaValidityTime", translate("HNA validity time"))
172 av.optional = true
173 av.datatype = "ufloat"
174 av.placeholder = "108.0"
175 av.write = write_float
176
177 return m