Skip to content

Commit

Permalink
Added the possibility to synthetisize packets in packetblaster by usi…
Browse files Browse the repository at this point in the history
…ng apps.test.synth.
  • Loading branch information
aequabit committed Jan 19, 2016
1 parent c603530 commit 3ee37c1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 17 deletions.
27 changes: 21 additions & 6 deletions src/program/packetblaster/README
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
Usage: packetblaster replay [OPTIONS] <PCAP-FILE> <PCI>...
Usage: packetblaster replay [OPTIONS] <PCI>...

-p PCAPFILE, --pcap PCAPFILE
PCAPFILE to replay.
-s SOURCE, --src SOURCE
Source MAC-Address.
Default: 00:00:00:00:00:00
-d DESTINATION, --dst DESTINATION
Destination MAC-Address.
Default: 00:00:00:00:00:00
-S SIZE, --size SIZE
Set packetsize to SIZE bytes.
Default: 64
-D DURATION, --duration DURATION
Run for DURATION seconds.
Default: unlimited
-h, --help
Print usage information.

Transmit packets from PCAP-FILE continuously to one or more network
adapters. The PCI arguments are Lua pattern strings that are used to
match the network adapters to use.
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. If a PCAPFILE is supplied then the packets from that file are
transmitted, otherwise the packets are synthetisized according to SOURCE,
DESTINATION, SIZE.


Examples:
packetblaster replay myfile.cap 0000:01:00.0
packetblaster replay myfile.cap 01:00
packetblaster replay -p myfile.cap 0000:01:00.0
packetblaster replay -s 11:11:11:11:11:11 -d 22:22:22:22:22:22 -S 256 0000:01:00.0
41 changes: 30 additions & 11 deletions src/program/packetblaster/packetblaster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local intel_app = require("apps.intel.intel_app")
local basic_apps = require("apps.basic.basic_apps")
local main = require("core.main")
local PcapReader= require("apps.pcap.pcap").PcapReader
local Synth = require("apps.test.synth").Synth
local LoadGen = require("apps.intel.loadgen").LoadGen
local lib = require("core.lib")
local ffi = require("ffi")
Expand All @@ -18,32 +19,51 @@ local usage = require("program.packetblaster.README_inc")

local long_opts = {
duration = "D",
help = "h"
help = "h",
pcapfile = "p",
source = "s",
destination = "d",
size = "S",

}

function run (args)
local opt = {}
local duration
local filename
local source
local destination
local size
function opt.D (arg) duration = tonumber(arg) end
function opt.h (arg) print(usage) main.exit(1) end
if #args < 3 or table.remove(args, 1) ~= 'replay' then opt.h() end
args = lib.dogetopt(args, opt, "hD:", long_opts)
local filename = table.remove(args, 1)
function opt.p (arg) filename = arg end
function opt.s (arg) source = arg end
function opt.d (arg) destination = arg end
function opt.S (arg) size = arg end
if #args < 2 or table.remove(args, 1) ~= 'replay' then opt.h() end
args = lib.dogetopt(args, opt, "hD:p:s:d:S:", long_opts)

local patterns = args
local c = config.new()
config.app(c, "pcap", PcapReader, filename)
config.app(c, "loop", basic_apps.Repeater)
config.app(c, "tee", basic_apps.Tee)
config.link(c, "pcap.output -> loop.input")
config.link(c, "loop.output -> tee.input")
if filename ~= nil then
config.app(c, "pcap", PcapReader, filename)
config.app(c, "loop", basic_apps.Repeater)
config.app(c, "source", apps.test.synth)
config.link(c, "pcap.output -> loop.input")
config.link(c, "loop.output -> source.input")
else
config.app(c, "source", Synth, { size = size,
src = source,
dst = destination })
end
local nics = 0
pci.scan_devices()
for _,device in ipairs(pci.devices) do
if is_device_suitable(device, patterns) then
nics = nics + 1
local name = "nic"..nics
config.app(c, name, LoadGen, device.pciaddress)
config.link(c, "tee."..tostring(nics).."->"..name..".input")
config.link(c, "source."..tostring(nics).."->"..name..".input")
end
end
assert(nics > 0, "<PCI> matches no suitable devices.")
Expand Down Expand Up @@ -74,4 +94,3 @@ function is_device_suitable (pcidev, patterns)
end
end


0 comments on commit 3ee37c1

Please sign in to comment.