Skip to content

Instantly share code, notes, and snippets.

@djkonro
Created October 16, 2018 07:57
Show Gist options
  • Save djkonro/0f8da0066894034fbb2e137c19238e1c to your computer and use it in GitHub Desktop.
Save djkonro/0f8da0066894034fbb2e137c19238e1c to your computer and use it in GitHub Desktop.
local basic_apps = require("apps.basic.basic_apps")
local xdpsock = require("apps.socket.af_xdp.xdpsock")
local raw = require("apps.socket.raw")
local ffi = require("ffi")
local C = ffi.C
function run ()
npackets = 100e6
npackets = tonumber(npackets) or error("Invalid number of packets: " .. npackets)
local c = config.new()
-- Simple topology:
-- .------.
-- Source ---> Tee Sink
-- `------'
-- Source generates packets, Tee duplicates them, Sink receives
-- both duplicates.
config.app(c, "Source", basic_apps.Source)
config.app(c, "Tee", basic_apps.Tee)
config.app(c, "Sink", xdpsock.AfxdpSocket, "lo")
-- config.app(c, "Sink", raw.RawSocket, "lo")
config.link(c, "Source.tx -> Tee.rx")
config.link(c, "Tee.tx1 -> Sink.rx1")
config.link(c, "Tee.tx2 -> Sink.rx2")
engine.configure(c)
local start = C.get_monotonic_time()
timer.activate(timer.new("null", function () end, 1e6, 'repeating'))
while link.stats(engine.app_table.Source.output.tx).txpackets < npackets do
engine.main({duration = 0.01, no_report = true})
end
local finish = C.get_monotonic_time()
local runtime = finish - start
local packets = link.stats(engine.app_table.Source.output.tx).txpackets
engine.report()
print()
print(("Processed %.1f million packets in %.2f seconds (rate: %.1f Mpps)."):format(packets / 1e6, runtime, packets / runtime / 1e6))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment