Skip to content

Commit

Permalink
apps.test.synth: Added support for sequences of packet sizes.
Browse files Browse the repository at this point in the history
packetblaster: Modified the -S parameter to get multiple packet sizes
separated by commas. Updated documentation.
  • Loading branch information
aequabit committed Jan 21, 2016
1 parent 5eede86 commit d0ad471
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ is the master line of development.

[packetblaster](src/program/packetblaster/) generates load by
replaying a [pcap format](http://en.wikipedia.org/wiki/Pcap) trace
file onto any number of Intel 82599 10-Gigabit network
file or synthesizing customizable packets onto any number of Intel 82599 10-Gigabit network
interfaces. This is very efficient: only a small % of one core per CPU
is required even for hundreds of Gbps of traffic. Because so little
CPU resources are required you can run packetblaster on a small server
Expand Down
35 changes: 22 additions & 13 deletions src/apps/test/synth.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,50 @@ Synth = {}

function Synth:new (arg)
local conf = arg and config.parse_app_arg(arg) or {}
conf.size = conf.size or 64
conf.sizes = conf.sizes or {64}
assert(#conf.sizes >= 1, "Needs at least one size.")
conf.src = conf.src or '00:00:00:00:00:00'
conf.dst = conf.dst or '00:00:00:00:00:00'
local ether = ethernet:new({ src = ethernet:pton(conf.src),
dst = ethernet:pton(conf.dst) })
local payload_size = conf.size - ethernet:sizeof()
local data = ffi.new("char[?]", payload_size)
local dgram = datagram:new(packet.from_pointer(data, payload_size))
dgram:push(ether)
return setmetatable({packet=dgram:packet()}, {__index=Synth})
local packets = {}
for i, size in ipairs(conf.sizes) do
local ether = ethernet:new({ src = ethernet:pton(conf.src),
dst = ethernet:pton(conf.dst) })
local payload_size = size - ethernet:sizeof()
local data = ffi.new("char[?]", payload_size)
local dgram = datagram:new(packet.from_pointer(data, payload_size))
dgram:push(ether)
packets[i] = dgram:packet()
end
return setmetatable({packets=packets}, {__index=Synth})
end

function Synth:pull ()
for _, o in ipairs(self.output) do
for i = 1, link.nwritable(o) do
transmit(o, packet.clone(self.packet))
for _, p in ipairs(self.packets) do
transmit(o, packet.clone(p))
end
end
end
end

function Synth:stop ()
packet.free(self.packet)
for _, p in ipairs(self.packets) do
packet.free(p)
end
end

function selftest ()
local pcap = require("apps.pcap.pcap")
local c = config.new()
config.app(c, "synth", Synth, { size = 128,
config.app(c, "synth", Synth, { sizes = {32, 64, 128},
src = "11:11:11:11:11:11",
dst = "22:22:22:22:22:22" })
config.app(c, "writer", pcap.PcapWriter, "apps/test/synth.pcap.output")
config.link(c, "synth.output->writer.input")
engine.configure(c)
engine.main( {duration = 0.00000001, -- hack: one breath.
report = { showlinks = true } } )
engine.main({ duration = 0.00000001, -- hack: one breath.
report = { showlinks = true } })

if io.open("apps/test/synth.pcap"):read('*a') ~=
io.open("apps/test/synth.pcap.output"):read('*a')
Expand Down
Binary file modified src/apps/test/synth.pcap
Binary file not shown.
13 changes: 8 additions & 5 deletions src/program/packetblaster/packetblaster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ local long_opts = {
help = "h",
source = "s",
destination = "d",
size = "S"
sizes = "S"
}

function run (args)
Expand Down Expand Up @@ -52,15 +52,18 @@ function run (args)
elseif mode == 'synth' and #args >= 1 then
local source
local destination
local size
local sizes
function opt.s (arg) source = arg end
function opt.d (arg) destination = arg end
function opt.S (arg)
size = assert(tonumber(arg), "size is not a number!")
function opt.S (arg)
sizes = {}
for size in string.gmatch(arg, "%d+") do
sizes[#sizes+1] = tonumber(size)
end
end

args = lib.dogetopt(args, opt, "hD:s:d:S:", long_opts)
config.app(c, "source", Synth, { size = size,
config.app(c, "source", Synth, { sizes = sizes,
src = source,
dst = destination })
else
Expand Down
9 changes: 5 additions & 4 deletions src/program/packetblaster/synth/README
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ Usage: packetblaster synth [OPTIONS] <PCI>...
-d DESTINATION, --dst DESTINATION
Destination MAC-Address.
Default: 00:00:00:00:00:00
-S SIZE, --size SIZE
Set packetsize to SIZE bytes.
-S SIZES, --sizes SIZES
A comma separated list of numbers. Send packets of
SIZES bytes.
Default: 64
-D DURATION, --duration DURATION
Run for DURATION seconds.
Expand All @@ -18,7 +19,7 @@ Usage: packetblaster synth [OPTIONS] <PCI>...
packetblaster transmits packets continuously to one or more network adapters.
The PCI arguments are Lua pattern strings that are used to match the network
adapters to use. The packets are synthetisized according to SOURCE,
DESTINATION, SIZE.
DESTINATION and SIZES.

Examples:
packetblaster synth -s 11:11:11:11:11:11 -d 22:22:22:22:22:22 -S 256 01:00.0
packetblaster synth -d 22:22:22:22:22:22 -S 32,64,128 01:00.0

0 comments on commit d0ad471

Please sign in to comment.