Skip to content

Commit

Permalink
Producer
Browse files Browse the repository at this point in the history
- `examples/test_pcap_read.lua`: Add `-p` to test using producer interface
- `filter.layer` Issue DNS-OARC#41: Add producer interface
- `output.null`: Change `run()` so it can consume all objects
  • Loading branch information
jelu committed Apr 26, 2018
1 parent 4d65740 commit 636774b
Show file tree
Hide file tree
Showing 7 changed files with 452 additions and 216 deletions.
226 changes: 157 additions & 69 deletions examples/test_pcap_read.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local clock = require("dnsjit.lib.clock")
local getopt = require("dnsjit.lib.getopt").new({
{ "t", "thread", 0, "Test also with dnsjit.filter.thread, give number of threads to run", "?" },
{ "l", "layer", false, "Test also with dnsjit.filter.layer", "?" },
{ "p", "producer", false, "Test with the producer interface rather then receiver interface", "?" },
})
local pcap, runs = unpack(getopt:parse())
if getopt:val("help") then
Expand All @@ -15,7 +16,11 @@ if pcap == nil then
return
end

inputs = { "fpcap", "mmpcap", "pcap", "pcapthread" }
if getopt:val("p") then
inputs = { "fpcap", "mmpcap", "pcap" }
else
inputs = { "fpcap", "mmpcap", "pcap", "pcapthread" }
end
result = {}
results = {}
highest = nil
Expand All @@ -26,74 +31,69 @@ else
runs = tonumber(runs)
end

for _, name in pairs(inputs) do
rt = 0.0
p = 0
if getopt:val("p") then
for _, name in pairs(inputs) do
rt = 0.0
p = 0

print("run", name)
for n = 1, runs do
t = nil
tos = nil
if getopt:val("t") > 1 then
local nn
tos = {}
o = require("dnsjit.filter.thread").new()
for nn = 1, getopt:val("t") do
local oo = require("dnsjit.output.null").new()
o:receiver(oo)
table.insert(tos, oo)
end
o:start()
t = o
else
o = require("dnsjit.output.null").new()
end
i = require("dnsjit.input."..name).new()
if name == "pcap" then
i:open_offline(pcap)
if getopt:val("l") then
f = require("dnsjit.filter.layer").new()
f:receiver(o)
i:receiver(f)
print("run", name)
for n = 1, runs do
t = nil
tos = nil
-- if getopt:val("t") > 1 then
-- local nn
-- tos = {}
-- o = require("dnsjit.filter.thread").new()
-- for nn = 1, getopt:val("t") do
-- local oo = require("dnsjit.output.null").new()
-- o:receiver(oo)
-- table.insert(tos, oo)
-- end
-- o:start()
-- t = o
-- else
o = require("dnsjit.output.null").new()
-- end
i = require("dnsjit.input."..name).new()
if name == "pcap" then
i:open_offline(pcap)
if getopt:val("l") then
f = require("dnsjit.filter.layer").new()
f:producer(i)
o:producer(f)
else
o:producer(i)
end
ss, sns = clock:monotonic()
-- i:dispatch()
o:run(0)
else
i:receiver(o)
-- if t then
-- i:use_shared(true)
-- end
i:open(pcap)
if getopt:val("l") then
f = require("dnsjit.filter.layer").new()
f:producer(i)
o:producer(f)
else
o:producer(i)
end
ss, sns = clock:monotonic()
-- i:run()
o:run(0)
end
ss, sns = clock:monotonic()
i:dispatch()
elseif name == "pcapthread" then
i:open_offline(pcap)
i:receiver(o)
ss, sns = clock:monotonic()
i:run()
else
if t then
i:use_shared(true)
end
i:open(pcap)
if getopt:val("l") then
f = require("dnsjit.filter.layer").new()
f:receiver(o)
i:receiver(f)
else
i:receiver(o)
t:stop()
end
ss, sns = clock:monotonic()
i:run()
end
if t then
t:stop()
end
es, ens = clock:monotonic()
es, ens = clock:monotonic()

if es > ss then
rt = rt + ((es - ss) - 1) + ((1000000000 - sns + ens)/1000000000)
elseif es == ss and ens > sns then
rt = rt + (ens - sns) / 1000000000
end
if es > ss then
rt = rt + ((es - ss) - 1) + ((1000000000 - sns + ens)/1000000000)
elseif es == ss and ens > sns then
rt = rt + (ens - sns) / 1000000000
end

if name == "pcapthread" then
p = p + i:packets()
else
if tos then
for _, oo in pairs(tos) do
p = p + oo:packets()
Expand All @@ -102,16 +102,104 @@ for _, name in pairs(inputs) do
p = p + o:packets()
end
end

result[name] = {
rt = rt,
p = p
}
if highest == nil or rt > result[highest].rt then
highest = name
end
table.insert(results, name)
end
else
for _, name in pairs(inputs) do
rt = 0.0
p = 0

result[name] = {
rt = rt,
p = p
}
if highest == nil or rt > result[highest].rt then
highest = name
print("run", name)
for n = 1, runs do
t = nil
tos = nil
if getopt:val("t") > 1 then
local nn
tos = {}
o = require("dnsjit.filter.thread").new()
for nn = 1, getopt:val("t") do
local oo = require("dnsjit.output.null").new()
o:receiver(oo)
table.insert(tos, oo)
end
o:start()
t = o
else
o = require("dnsjit.output.null").new()
end
i = require("dnsjit.input."..name).new()
if name == "pcap" then
i:open_offline(pcap)
if getopt:val("l") then
f = require("dnsjit.filter.layer").new()
f:receiver(o)
i:receiver(f)
else
i:receiver(o)
end
ss, sns = clock:monotonic()
i:dispatch()
elseif name == "pcapthread" then
i:open_offline(pcap)
i:receiver(o)
ss, sns = clock:monotonic()
i:run()
else
if t then
i:use_shared(true)
end
i:open(pcap)
if getopt:val("l") then
f = require("dnsjit.filter.layer").new()
f:receiver(o)
i:receiver(f)
else
i:receiver(o)
end
ss, sns = clock:monotonic()
i:run()
end
if t then
t:stop()
end
es, ens = clock:monotonic()

if es > ss then
rt = rt + ((es - ss) - 1) + ((1000000000 - sns + ens)/1000000000)
elseif es == ss and ens > sns then
rt = rt + (ens - sns) / 1000000000
end

if name == "pcapthread" then
p = p + i:packets()
else
if tos then
for _, oo in pairs(tos) do
p = p + oo:packets()
end
else
p = p + o:packets()
end
end
end

result[name] = {
rt = rt,
p = p
}
if highest == nil or rt > result[highest].rt then
highest = name
end
table.insert(results, name)
end
table.insert(results, name)
end

print("name", "runtime", "pps", "x", "pkts")
Expand Down
Loading

0 comments on commit 636774b

Please sign in to comment.