2 LuCI - Network model - relay protocol extension
4 Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
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
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
20 local netmod = luci.model.network
21 local device = luci.util.class(netmod.interface)
23 netmod:register_pattern_virtual("^relay-%w")
25 local proto = netmod:register_protocol("relay")
27 function proto.get_i18n(self)
28 return luci.i18n.translate("Relay bridge")
31 function proto.ifname(self)
32 return "relay-" .. self.sid
35 function proto.opkg_package(self)
39 function proto.is_installed(self)
40 return nixio.fs.access("/etc/init.d/relayd")
43 function proto.is_floating(self)
47 function proto.is_virtual(self)
51 function proto.get_interface(self)
52 return device(self.sid, self)
55 function proto.get_interfaces(self)
56 if not self.ifaces then
60 for net in luci.util.imatch(self:_get("network")) do
61 net = netmod:get_network(net)
63 dev = net:get_interface()
70 for dev in luci.util.imatch(self:_get("ifname")) do
71 dev = netmod:get_interface(dev)
79 for _, dev in luci.util.kspairs(ifs) do
80 self.ifaces[#self.ifaces+1] = dev
87 function proto.uptime(self)
90 for net in luci.util.imatch(self:_get("network")) do
91 net = netmod:get_network(net)
93 upt = math.max(upt, net:uptime())
100 function device.__init__(self, ifname, network)
102 self.network = network
105 function device.type(self)
109 function device.is_up(self)
112 for _, dev in ipairs(self.network:get_interfaces()) do
113 if not dev:is_up() then
122 function device._stat(self, what)
126 for _, dev in ipairs(self.network:get_interfaces()) do
127 v = v + dev[what](dev)
133 function device.rx_bytes(self) return self:_stat("rx_bytes") end
134 function device.tx_bytes(self) return self:_stat("tx_bytes") end
135 function device.rx_packets(self) return self:_stat("rx_packets") end
136 function device.tx_packets(self) return self:_stat("tx_packets") end
138 function device.mac(self)
141 for _, dev in ipairs(self.network:get_interfaces()) do
147 function device.ipaddrs(self)
150 addrs[1] = luci.ip.IPv4(self.network:_get("ipaddr"))
155 function device.ip6addrs(self)
159 function device.shortname(self)
160 return "%s %q" % { luci.i18n.translate("Relay"), self.ifname }
163 function device.get_type_i18n(self)
164 return luci.i18n.translate("Relay Bridge")