Skip to content

Instantly share code, notes, and snippets.

@upa
Created December 26, 2017 15:01
Show Gist options
  • Save upa/fa614018f8abc925fa6496a582744187 to your computer and use it in GitHub Desktop.
Save upa/fa614018f8abc925fa6496a582744187 to your computer and use it in GitHub Desktop.
A MoonGen script: count rxed packets on each queue
local mg = require "moongen"
local memory = require "memory"
local device = require "device"
local stats = require "stats"
local log = require "log"
local timer = require "timer"
local pktctrs = {}
function configure(parser)
parser:argument("rxDev", "The device to receive from"):convert(tonumber)
parser:option("-q --queuenum", "Num of queues"):default(1):convert(tonumber)
parser:option("-t --timeout", "timeout"):default(0):convert(tonumber)
end
function master(args)
local rxDev = device.config{port = args.rxDev, rxQueues = args.queuenum, dropEnable = false}
device.waitForLinks()
for n = 0, args.queuenum - 1 do
mg.startTask("dumpSlave", rxDev:getRxQueue(n), n, args.timeout)
end
mg.waitForTasks()
end
function dumpSlave(queue, qnum, timeout)
local bufs = memory.bufArray()
local pktCtr = stats:newPktRxCounter(string.format("Pkt Count:Queue:%d", qnum), "plain")
pktctrs[qnum] = pktCtr
local timer = timer:new(timeout)
while mg.running() do
local rx = queue:tryRecv(bufs, 128)
for i = 1, rx do
local buf = bufs[i]
-- buf:dump()
pktCtr:countPacket(buf)
end
bufs:free(rx)
pktCtr:update()
if timeout > 0 and timer:expired() then
break
end
end
pktCtr:finalize()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment