Skip to content

Commit

Permalink
lwaftr --xdp sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeneia committed Jul 13, 2021
1 parent 8d4ee13 commit 2bcc644
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/program/lwaftr/run/README
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Optional arguments:
-i, --virtio Interpret PCI addresses as referring to
virtio-net interfaces instead of
auto-detecting the appropriate driver.
--xdp Use Linux interfaces via XDP.
(Incompatible with --on-a-stick.)
-r SIZE, --ring-buffer-size SIZE
Set NIC receive buffer size. The
default is driver-dependent. See
Expand Down
11 changes: 11 additions & 0 deletions src/program/lwaftr/run/run.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ function parse_args(args)
function handlers.v () opts.verbosity = opts.verbosity + 1 end
function handlers.t (arg) opts.trace = assert(arg) end
function handlers.i () opts.virtio_net = true end
handlers['xdp'] = function(arg)
opts['xdp'] = true
scheduling.enable_xdp = {} -- XXX - maybe configure num_chunks here?
end
function handlers.D (arg)
opts.duration = assert(tonumber(arg), "duration must be a number")
assert(opts.duration >= 0, "duration can't be negative")
Expand Down Expand Up @@ -105,6 +109,7 @@ function parse_args(args)
lib.dogetopt(args, handlers, "b:c:vD:yhir:n:t:",
{ conf = "c", name = "n", cpu = 1, v4 = 1, v6 = 1,
["on-a-stick"] = 1, virtio = "i", ["ring-buffer-size"] = "r",
["xdp"] = 0,
["real-time"] = 0, mirror = 1, ["ingress-drop-monitor"] = 1,
verbose = "v", trace = "t", ["bench-file"] = "b", ["profile"] = 0,
duration = "D", hydra = "y", help = "h" })
Expand Down Expand Up @@ -153,6 +158,12 @@ function run(args)
return setup_fn(graph, lwconfig, 'inetNic', 'b4sideNic')
end

-- If --xdp has been specified, always use this.
if opts.xdp then
return setup.load_xdp(graph, lwconfig, 'inetNic', 'b4sideNic',
opts.ring_buffer_size)
end

-- If instance has external-interface.device configure as bump-in-the-wire
-- otherwise configure it in on-a-stick mode.
local device, id, queue = lwutil.parse_instance(lwconfig)
Expand Down
21 changes: 21 additions & 0 deletions src/program/lwaftr/setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,27 @@ function load_phy(c, conf, v4_nic_name, v6_nic_name, ring_buffer_size)
link_sink(c, v4_nic_name..'.'..v4_info.rx, v6_nic_name..'.'..v6_info.rx)
end

function load_xdp(c, conf, v4_nic_name, v6_nic_name, ring_buffer_size)
local v4_device, id, queue = lwutil.parse_instance(conf)
local v6_device = queue.external_interface.device
assert(lib.is_iface(v4_device), v4_nic_name..": "..v4_device.." is not a Linux interface")
assert(lib.is_iface(v6_device), v6_nic_name..": "..v6_device.." is not a Linux interface")
assert(not lwutil.is_on_a_stick(v4_device, queue),
"--xdp does not support on-a-stick configuration")

lwaftr_app(c, conf)

config.app(c, v4_nic_name, require("apps.xdp.xdp").driver, {
ifname=v4_device,
queue=id})
config.app(c, v6_nic_name, require("apps.xdp.xdp").driver, {
ifname=v6_device,
queue=id})

link_source(c, v4_nic_name..'.output', v6_nic_name..'.output')
link_sink(c, v4_nic_name..'.input', v6_nic_name..'.input')
end

function load_on_a_stick_kernel_iface (c, conf, args)
local RawSocket = require("apps.socket.raw").RawSocket
local iface, id, queue = lwutil.parse_instance(conf)
Expand Down

0 comments on commit 2bcc644

Please sign in to comment.