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