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 proto = luci.util.class(netmod.proto.generic)
22 local device = luci.util.class(netmod.interface)
24 netmod.IFACE_PATTERNS_VIRTUAL[#netmod.IFACE_PATTERNS_VIRTUAL+1] = "^relay-%w"
26 function proto.__init__(self, name)
30 function proto.ifname(self)
31 return "relay-" .. self.sid
34 function proto.is_floating(self)
38 function proto.is_virtual(self)
42 function proto.get_interface(self)
43 return device(self.sid, self)
46 function proto.get_interfaces(self)
47 if not self.ifaces then
51 for net in luci.util.imatch(self:_get("network")) do
52 net = netmod:get_network(net)
54 dev = net:get_interface()
61 for dev in luci.util.imatch(self:_get("ifname")) do
62 dev = netmod:get_interface(dev)
70 for _, dev in luci.util.kspairs(ifs) do
71 self.ifaces[#self.ifaces+1] = dev
78 function proto.uptime(self)
81 for net in luci.util.imatch(self:_get("network")) do
82 net = netmod:get_network(net)
84 upt = math.max(upt, net:uptime())
91 function device.__init__(self, ifname, network)
93 self.network = network
96 function device.type(self)
100 function device.is_up(self)
103 for _, dev in ipairs(self.network:get_interfaces()) do
104 if not dev:is_up() then
113 function device._stat(self, what)
117 for _, dev in ipairs(self.network:get_interfaces()) do
118 v = v + dev[what](dev)
124 function device.rx_bytes(self) return self:_stat("rx_bytes") end
125 function device.tx_bytes(self) return self:_stat("tx_bytes") end
126 function device.rx_packets(self) return self:_stat("rx_packets") end
127 function device.tx_packets(self) return self:_stat("tx_packets") end
129 function device.mac(self)
132 for _, dev in ipairs(self.network:get_interfaces()) do
138 function device.ipaddrs(self)
141 addrs[1] = luci.ip.IPv4(self.network:_get("ipaddr"))
146 function device.ip6addrs(self)
150 function device.shortname(self)
151 return "%s %q" % { luci.i18n.translate("Relay"), self.ifname }
154 function device.get_type_i18n(self)
155 return luci.i18n.translate("Relay Bridge")
159 netmod.proto.relay = proto