-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrx-pkts-distribution.lua
More file actions
54 lines (49 loc) · 1.47 KB
/
rx-pkts-distribution.lua
File metadata and controls
54 lines (49 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
local mg = require "dpdk"
local memory = require "memory"
local device = require "device"
local stats = require "stats"
local histogram = require "histogram"
local log = require "log"
local timer = require "timer"
function master(rxPort, saveInterval)
if not rxPort then
return log:info("usage: rxPort [saveInterval]")
end
-- TODO: RSS?
local saveInterval = saveInterval or 60
local rxDev = device.config{ port = rxPort, dropEnable = false }
device.waitForLinks()
mg.launchLua("counterSlave", rxDev:getRxQueue(0), saveInterval)
mg.waitForSlaves()
end
function counterSlave(queue, saveInterval)
local bufs = memory.bufArray()
local ctrs = {}
local rxCtr = stats:newDevRxCounter(queue.dev)
-- to track if we lose packets on the NIC
local pktCtr = stats:newPktRxCounter("Packets counted", "plain")
local hist = histogram:create()
local timer = timer:new(saveInterval)
while mg.running() do
local rx = queue:tryRecv(bufs, 100)
for i = 1, rx do
local buf = bufs[i]
local size = buf:getSize()
hist:update(size)
pktCtr:countPacket(buf)
end
bufs:free(rx)
rxCtr:update()
pktCtr:update()
if timer:expired() then
-- FIXME: this is really slow and might lose packets
-- however, the histogram sucks and moving this to another thread would require a rewrite
timer:reset()
hist:print()
hist:save("hist" .. time() .. ".csv")
end
end
rxCtr:finalize()
pktCtr:finalize()
-- TODO: check the queue's overflow counter to detect lost packets
end