Skip to content

Commit

Permalink
Merge #964 branch 'eugeneia/statistics-superset' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
lukego committed Jul 13, 2016
2 parents cf1810e + f891072 commit 3e1f4dc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
27 changes: 0 additions & 27 deletions src/apps/vhost/vhost_user.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions src/lib/ipc/shmem/iftable_mib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 30 additions & 4 deletions src/lib/virtio/net_device.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3e1f4dc

Please sign in to comment.