Skip to content

Timeout #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/dumpdns-qr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ while true do
local pl = obj:cast()
if obj:type() == "payload" and pl.len > 0 then
local transport = obj.obj_prev
while transport do
while transport ~= nil do
if transport.obj_type == object.IP or transport.obj_type == object.IP6 then
break
end
transport = transport.obj_prev
end
local protocol = obj.obj_prev
while protocol do
while protocol ~= nil do
if protocol.obj_type == object.UDP or protocol.obj_type == object.TCP then
break
end
Expand Down
4 changes: 2 additions & 2 deletions examples/dumpdns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ while true do
local pl = obj:cast()
if obj:type() == "payload" and pl.len > 0 then
local transport = obj.obj_prev
while transport do
while transport ~= nil do
if transport.obj_type == object.IP or transport.obj_type == object.IP6 then
break
end
transport = transport.obj_prev
end
local protocol = obj.obj_prev
while protocol do
while protocol ~= nil do
if protocol.obj_type == object.UDP or protocol.obj_type == object.TCP then
break
end
Expand Down
2 changes: 1 addition & 1 deletion examples/filter_rcode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ while true do
local pl = obj:cast()
if obj:type() == "payload" and pl.len > 0 then
local transport = obj.obj_prev
while transport do
while transport ~= nil do
if transport.obj_type == object.IP or transport.obj_type == object.IP6 then
break
end
Expand Down
12 changes: 7 additions & 5 deletions examples/replay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@ if printdns then

recv(rctx, obj)

local resp = nil
while resp == nil do
resp = oprod(opctx)
local response = oprod(opctx)
if response == nil then
log.fatal("producer error")
end
while resp ~= nil do
local payload = response:cast()
if payload.len == 0 then
print("timed out")
else
dns.obj_prev = resp
print("response:")
dns:print()
resp = oprod(opctx)
end
end
end
Expand Down
56 changes: 28 additions & 28 deletions examples/respdiff.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ while true do
dns.obj_prev = obj
if dns:parse_header() == 0 then
local transport = obj.obj_prev
while transport do
while transport ~= nil do
if transport.obj_type == object.IP or transport.obj_type == object.IP6 then
break
end
transport = transport.obj_prev
end
local protocol = obj.obj_prev
while protocol do
while protocol ~= nil do
if protocol.obj_type == object.UDP or protocol.obj_type == object.TCP then
break
end
Expand Down Expand Up @@ -102,7 +102,8 @@ while true do
clipayload.payload = q.payload
clipayload.len = q.len

local responses, response = {}, nil
local prod, pctx

if q.proto == "udp" then
if not udpcli then
udpcli = require("dnsjit.output.udpcli").new()
Expand All @@ -111,13 +112,8 @@ while true do
udpprod, _ = udpcli:produce()
end
udprecv(udpctx, cliobject)
while response == nil do
response = udpprod(udpctx)
end
while response ~= nil do
table.insert(responses, response)
response = udpprod(udpctx)
end
prod = udpprod
pctx = udpctx
elseif q.proto == "tcp" then
if not tcpcli then
tcpcli = require("dnsjit.output.tcpcli").new()
Expand All @@ -126,27 +122,31 @@ while true do
tcpprod, _ = tcpcli:produce()
end
tcprecv(tcpctx, cliobject)
while response == nil do
response = tcpprod(tcpctx)
end
while response ~= nil do
table.insert(responses, response)
response = tcpprod(tcpctx)
end
prod = tcpprod
pctx = tcpctx
end

for _, response in pairs(responses) do
dns.obj_prev = response
if dns:parse_header() == 0 and dns.id == q.id then
query_payload.payload = q.payload
query_payload.len = q.len
original_payload.payload = payload.payload
original_payload.len = payload.len
response = response:cast()
response_payload.payload = response.payload
response_payload.len = response.len
while true do
local response = prod(pctx)
if response == nil then
log.fatal("producer error")
end
local rpl = response:cast()
if rpl.len == 0 then
log.info("timed out")
else
dns.obj_prev = response
if dns:parse_header() == 0 and dns.id == q.id then
query_payload.payload = q.payload
query_payload.len = q.len
original_payload.payload = payload.payload
original_payload.len = payload.len
response_payload.payload = rpl.payload
response_payload.len = rpl.len

resprecv(respctx, query_payload_obj)
resprecv(respctx, query_payload_obj)
break
end
end
end
end
Expand Down
90 changes: 90 additions & 0 deletions examples/test_throughput.lua
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,96 @@ if getopt:val("s") then

print(run, "runtime", runtime, num/runtime, "/sec", o1:packets() + o2:packets() + o3:packets() + o4:packets(), o1:packets(), o2:packets(), o3:packets(), o4:packets())
end

print("zero:receiver() -> lua split table -> null:receive() x4")
local run
for run = 1, runs do
local i = require("dnsjit.input.zero").new()
local o1 = require("dnsjit.output.null").new()
local o2 = require("dnsjit.output.null").new()
local o3 = require("dnsjit.output.null").new()
local o4 = require("dnsjit.output.null").new()

local prod, pctx = i:produce()
local recv, rctx = {}, {}

local f, c = o1:receive()
table.insert(recv, f)
table.insert(rctx, c)
f, c = o2:receive()
table.insert(recv, f)
table.insert(rctx, c)
f, c = o3:receive()
table.insert(recv, f)
table.insert(rctx, c)
f, c = o4:receive()
table.insert(recv, f)
table.insert(rctx, c)

local start_sec, start_nsec = clock:monotonic()
local idx = 1
for n = 1, num do
local f, c = recv[idx], rctx[idx]
if not f then
idx = 1
f, c = recv[1], rctx[1]
end
f(c, prod(pctx))
idx = idx + 1
end
local end_sec, end_nsec = clock:monotonic()

local runtime = 0
if end_sec > start_sec then
runtime = ((end_sec - start_sec) - 1) + ((1000000000 - start_nsec + end_nsec)/1000000000)
elseif end_sec == start_sec and end_nsec > start_nsec then
runtime = (end_nsec - start_nsec) / 1000000000
end

print(run, "runtime", runtime, num/runtime, "/sec", o1:packets() + o2:packets() + o3:packets() + o4:packets(), o1:packets(), o2:packets(), o3:packets(), o4:packets())
end

print("zero:receiver() -> lua split gen code -> null:receive() x4")
local run
for run = 1, runs do
local i = require("dnsjit.input.zero").new()
local o1 = require("dnsjit.output.null").new()
local o2 = require("dnsjit.output.null").new()
local o3 = require("dnsjit.output.null").new()
local o4 = require("dnsjit.output.null").new()

local prod, pctx = i:produce()
local f1, c1 = o1:receive()
local f2, c2 = o2:receive()
local f3, c3 = o3:receive()
local f4, c4 = o4:receive()

local code = "return function (num, prod, pctx, f1, c1, f2, c2, f3, c3, f4, c4)\nlocal n = 0\nwhile n < num do\n"
code = code .. "f1(c1,prod(pctx))\n"
code = code .. "n = n + 1\n"
code = code .. "f2(c2,prod(pctx))\n"
code = code .. "n = n + 1\n"
code = code .. "f3(c3,prod(pctx))\n"
code = code .. "n = n + 1\n"
code = code .. "f4(c4,prod(pctx))\n"
code = code .. "n = n + 1\n"
code = code .. "end\n"
code = code .. "end"
local f = assert(loadstring(code))()

local start_sec, start_nsec = clock:monotonic()
f(num, prod, pctx, f1, c1, f2, c2, f3, c3, f4, c4)
local end_sec, end_nsec = clock:monotonic()

local runtime = 0
if end_sec > start_sec then
runtime = ((end_sec - start_sec) - 1) + ((1000000000 - start_nsec + end_nsec)/1000000000)
elseif end_sec == start_sec and end_nsec > start_nsec then
runtime = (end_nsec - start_nsec) / 1000000000
end

print(run, "runtime", runtime, num/runtime, "/sec", o1:packets() + o2:packets() + o3:packets() + o4:packets(), o1:packets(), o2:packets(), o3:packets(), o4:packets())
end
end

if getopt:val("t") then
Expand Down
72 changes: 40 additions & 32 deletions src/core/object/dns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -671,44 +671,52 @@ function Dns:print(num_labels)
print("", "nscount:", self.nscount)
print("", "arcount:", self.arcount)

print("", "questions:")
for n = 1, self.qdcount do
if C.core_object_dns_parse_q(self, q, labels, num_labels) ~= 0 then
return
if self.qdcount > 0 then
print("questions:", "class", "type", "labels")
for n = 1, self.qdcount do
if C.core_object_dns_parse_q(self, q, labels, num_labels) ~= 0 then
return
end
print("", Dns.class_tostring(q.class), Dns.type_tostring(q.type), label.tooffstr(self, labels, num_labels))
end
print("", "", Dns.class_tostring(q.class), Dns.type_tostring(q.type), label.tooffstr(self, labels, num_labels))
end
print("", "answers:")
for n = 1, self.ancount do
if C.core_object_dns_parse_rr(self, rr, labels, num_labels) ~= 0 then
return
end
if rr.rdata_labels == 0 then
print("", "", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels))
else
print("", "", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels), label.tooffstr(self, labels, rr.rdata_labels, rr.labels))
if self.ancount > 0 then
print("answers:", "class", "type", "ttl", "labels", "RR labels")
for n = 1, self.ancount do
if C.core_object_dns_parse_rr(self, rr, labels, num_labels) ~= 0 then
return
end
if rr.rdata_labels == 0 then
print("", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels))
else
print("", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels), label.tooffstr(self, labels, rr.rdata_labels, rr.labels))
end
end
end
print("", "authorities:")
for n = 1, self.nscount do
if C.core_object_dns_parse_rr(self, rr, labels, num_labels) ~= 0 then
return
end
if rr.rdata_labels == 0 then
print("", "", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels))
else
print("", "", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels), label.tooffstr(self, labels, rr.rdata_labels, rr.labels))
if self.nscount > 0 then
print("authorities:", "class", "type", "ttl", "labels", "RR labels")
for n = 1, self.nscount do
if C.core_object_dns_parse_rr(self, rr, labels, num_labels) ~= 0 then
return
end
if rr.rdata_labels == 0 then
print("", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels))
else
print("", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels), label.tooffstr(self, labels, rr.rdata_labels, rr.labels))
end
end
end
print("", "additionals:")
for n = 1, self.arcount do
if C.core_object_dns_parse_rr(self, rr, labels, num_labels) ~= 0 then
return
end
if rr.rdata_labels == 0 then
print("", "", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels))
else
print("", "", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels), label.tooffstr(self, labels, rr.rdata_labels, rr.labels))
if self.arcount > 0 then
print("additionals:", "class", "type", "ttl", "labels", "RR labels")
for n = 1, self.arcount do
if C.core_object_dns_parse_rr(self, rr, labels, num_labels) ~= 0 then
return
end
if rr.rdata_labels == 0 then
print("", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels))
else
print("", Dns.class_tostring(rr.class), Dns.type_tostring(rr.type), rr.ttl, label.tooffstr(self, labels, rr.labels), label.tooffstr(self, labels, rr.rdata_labels, rr.labels))
end
end
end
end
Expand Down
Loading