diff --git a/src/apps/vhost/vhost_user.lua b/src/apps/vhost/vhost_user.lua index 98d4f66d5f..63e972b141 100644 --- a/src/apps/vhost/vhost_user.lua +++ b/src/apps/vhost/vhost_user.lua @@ -15,7 +15,6 @@ local main = require("core.main") local memory = require("core.memory") local counter = require("core.counter") local pci = require("lib.hardware.pci") -local ethernet = require("lib.protocol.ethernet") local net_device= require("lib.virtio.net_device") local timer = require("core.timer") local ffi = require("ffi") @@ -104,32 +103,6 @@ function VhostUser:push () end end -function VhostUser:tx_callback (p) - counter.add(self.counters.txbytes, packet.length(p)) - counter.add(self.counters.txpackets) - if ethernet:is_mcast(packet.data(p)) then - counter.add(self.counters.txmcast) - end - if ethernet:is_bcast(packet.data(p)) then - counter.add(self.counters.txbcast) - end -end - -function VhostUser:rx_callback (p) - counter.add(self.counters.rxbytes, packet.length(p)) - counter.add(self.counters.rxpackets) - if ethernet:is_mcast(packet.data(p)) then - counter.add(self.counters.rxmcast) - end - if ethernet:is_bcast(packet.data(p)) then - counter.add(self.counters.rxbcast) - end -end - -function VhostUser:rxdrop_callback (p) - counter.add(self.counters.rxdrop) -end - -- Try to connect to QEMU. function VhostUser:client_connect () return C.vhost_user_connect(self.socket_path) diff --git a/src/lib/ipc/shmem/iftable_mib.lua b/src/lib/ipc/shmem/iftable_mib.lua index 8d96d29e67..c03f98c29a 100644 --- a/src/lib/ipc/shmem/iftable_mib.lua +++ b/src/lib/ipc/shmem/iftable_mib.lua @@ -30,8 +30,13 @@ function init_snmp (name, counters, directory, interval) ifTable:register('ifSpeed', 'Gauge32') ifTable:register('ifHighSpeed', 'Gauge32') if counters.speed then - ifTable:set('ifSpeed', counter.read(counters.speed)) - ifTable:set('ifHighSpeed', counter.read(counters.speed) / 1000) + speed = counters.read(counters.speed) + if speed > 1000000000 then + ifTable:set('ifSpeed', 4294967295) -- RFC3635 sec. 3.2.8 + else + ifTable:set('ifSpeed', speed) + end + ifTable:set('ifHighSpeed', speed / 1000000) end ifTable:register('ifPhysAddress', { type = 'OctetStr', length = 6 }) if counters.macaddr then diff --git a/src/lib/virtio/net_device.lua b/src/lib/virtio/net_device.lua index 14fa5c9b1e..14883b1e1a 100644 --- a/src/lib/virtio/net_device.lua +++ b/src/lib/virtio/net_device.lua @@ -10,6 +10,8 @@ local link = require("core.link") local memory = require("core.memory") local packet = require("core.packet") local timer = require("core.timer") +local counter = require("core.counter") +local ethernet = require("lib.protocol.ethernet") local vq = require("lib.virtio.virtq_device") local checksum = require("lib.checksum") local ffi = require("ffi") @@ -151,6 +153,7 @@ end function VirtioNetDevice:rx_packet_end(header_id, total_size, rx_p) local l = self.owner.output.tx + local counters = self.owner.counters if l then if band(self.rx_hdr_flags, C.VIO_NET_HDR_F_NEEDS_CSUM) ~= 0 and -- Bounds-check the checksum area @@ -162,11 +165,18 @@ function VirtioNetDevice:rx_packet_end(header_id, total_size, rx_p) rx_p.length - self.rx_hdr_csum_start, self.rx_hdr_csum_offset) end - self.owner:rx_callback(rx_p) + counter.add(counters.rxbytes, rx_p.length) + counter.add(counters.rxpackets) + if ethernet:is_mcast(rx_p.data) then + counter.add(counters.rxmcast) + end + if ethernet:is_bcast(rx_p.data) then + counter.add(counters.rxbcast) + end link.transmit(l, rx_p) else debug("droprx", "len", rx_p.length) - self.owner:rxdrop_callback(rx_p) + counter.add(counters.rxdrop) packet.free(rx_p) end self.virtq[self.ring_id]:put_buffer(header_id, total_size) @@ -254,7 +264,15 @@ function VirtioNetDevice:tx_buffer_add(tx_p, addr, len) end function VirtioNetDevice:tx_packet_end(header_id, total_size, tx_p) - self.owner:tx_callback(tx_p) + local counters = self.owner.counters + counter.add(counters.txbytes, tx_p.length) + counter.add(counters.txpackets) + if ethernet:is_mcast(tx_p.data) then + counter.add(counters.txmcast) + end + if ethernet:is_bcast(tx_p.data) then + counter.add(counters.txbcast) + end packet.free(tx_p) self.virtq[self.ring_id]:put_buffer(header_id, total_size) end @@ -322,9 +340,17 @@ function VirtioNetDevice:tx_buffer_add_mrg_rxbuf(tx_p, addr, len) end function VirtioNetDevice:tx_packet_end_mrg_rxbuf(header_id, total_size, tx_p) + local counters = self.owner.counters -- free the packet only when all its data is processed if self.tx.finished then - self.owner:tx_callback(tx_p) + counter.add(counters.txbytes, tx_p.length) + counter.add(counters.txpackets) + if ethernet:is_mcast(tx_p.data) then + counter.add(counters.txmcast) + end + if ethernet:is_bcast(tx_p.data) then + counter.add(counters.txbcast) + end packet.free(tx_p) self.tx.p = nil self.tx.data_sent = nil