Skip to content

Commit

Permalink
Merge pull request #971 from Igalia/rss
Browse files Browse the repository at this point in the history
Enable RSS on the lwAFTR
  • Loading branch information
wingo authored Sep 26, 2017
2 parents b683e86 + d6974ca commit d036fd0
Show file tree
Hide file tree
Showing 50 changed files with 230 additions and 154 deletions.
16 changes: 2 additions & 14 deletions src/apps/config/action_codec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,9 @@ local function find_public_name(obj)
error('could not determine public name for object: '..tostring(obj))
end

local lower_case = "abcdefghijklmnopqrstuvwxyz"
local upper_case = lower_case:upper()
local extra = "0123456789_-"
local alphabet = table.concat({lower_case, upper_case, extra})
assert(#alphabet == 64)
local function random_file_name()
-- 22 bytes, but we only use 2^6=64 bits from each byte, so total of
-- 132 bits of entropy.
local bytes = lib.random_data(22)
local out = {}
for i=1,#bytes do
table.insert(out, alphabet:byte(bytes:byte(i) % 64 + 1))
end
local basename = string.char(unpack(out))
return shm.root..'/'..tostring(S.getpid())..'/app-conf-'..basename
local basename = 'app-conf-'..lib.random_printable_string(160)
return shm.root..'/'..shm.resolve(basename)
end

local function encoder()
Expand Down
13 changes: 0 additions & 13 deletions src/apps/lwaftr/lwutil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ local ehs = constants.ethernet_header_size
local o_ipv4_flags = constants.o_ipv4_flags
local ntohs = lib.ntohs

-- Produces configuration for each instance.
-- Provided a multi-process configuration it will iterate over each instance
-- and produce a configuration for each device with a single instance in. This
-- is then able to be provided to the lwaftr app.
function produce_instance_configs(conf)
local ret = {}
for device, queues in pairs(conf.softwire_config.instance) do
ret[device] = lib.deepcopy(conf)
ret[device].softwire_config.instance = {[device]=queues}
end
return ret
end

function get_ihl_from_offset(pkt, offset)
local ver_and_ihl = pkt.data[offset]
return band(ver_and_ihl, 0xf) * 4
Expand Down
17 changes: 17 additions & 0 deletions src/core/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,23 @@ function random_data (length)
return ffi.string(random_bytes(length), length)
end

local lower_case = "abcdefghijklmnopqrstuvwxyz"
local upper_case = lower_case:upper()
local extra = "0123456789_-"
local alphabet = table.concat({lower_case, upper_case, extra})
assert(#alphabet == 64)
function random_printable_string (entropy)
-- 64 choices in our alphabet, so 6 bits of entropy per byte.
entropy = entropy or 160
local length = math.floor((entropy - 1) / 6) + 1
local bytes = random_data(length)
local out = {}
for i=1,length do
out[i] = alphabet:byte(bytes:byte(i) % 64 + 1)
end
return string.char(unpack(out))
end

-- Compiler barrier.
-- Prevents LuaJIT from moving load/store operations over this call.
-- Any FFI call is sufficient to achieve this, see:
Expand Down
40 changes: 38 additions & 2 deletions src/lib/yang/binary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
module(..., package.seeall)

local ffi = require("ffi")
local lib = require("core.lib")
local shm = require("core.shm")
local schema = require("lib.yang.schema")
local util = require("lib.yang.util")
local value = require("lib.yang.value")
local stream = require("lib.yang.stream")
local data = require('lib.yang.data')
local ctable = require('lib.ctable')
local cltable = require('lib.cltable')
local lib = require("core.lib")

local MAGIC = "yangconf"
local VERSION = 0x00005000
Expand Down Expand Up @@ -467,6 +468,41 @@ function load_compiled_data_file(filename)
return load_compiled_data(stream.open_input_byte_stream(filename))
end

function data_copier_from_grammar(production)
local compile = data_compiler_from_grammar(data_emitter(production), '')
return function(data)
local basename = 'copy-'..lib.random_printable_string(160)
local tmp = shm.root..'/'..shm.resolve(basename)
compile(data, tmp)
return function() return load_compiled_data_file(tmp).data end
end
end

function data_copier_for_schema(schema, is_config)
local grammar = data.data_grammar_from_schema(schema, is_config)
return data_copier_from_grammar(grammar)
end

function config_copier_for_schema(schema)
return data_copier_for_schema(schema, true)
end

function state_copier_for_schema(schema)
return data_copier_for_schema(schema, false)
end

function config_copier_for_schema_by_name(schema_name)
return config_copier_for_schema(schema.load_schema_by_name(schema_name))
end

function copy_config_for_schema(schema, data)
return config_copier_for_schema(schema)(data)()
end

function copy_config_for_schema_by_name(schema_name, data)
return config_copier_for_schema_by_name(schema_name)(data)()
end

function selftest()
print('selfcheck: lib.yang.binary')
local test_schema = schema.load_schema([[module snabb-simple-router {
Expand Down Expand Up @@ -574,7 +610,7 @@ function selftest()
local data2 = load_compiled_data_file(tmp)
assert(data2.schema_name == 'snabb-simple-router')
assert(data2.revision_date == '')
data = data2.data
data = copy_config_for_schema(test_schema, data2.data)
os.remove(tmp)
end
print('selfcheck: ok')
Expand Down
15 changes: 14 additions & 1 deletion src/lib/yang/snabb-softwire-v2.yang
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,20 @@ module snabb-softwire-v2 {
key "id";

leaf id {
type uint8;
type uint8 { range 0..1; }
description
"RSS queue on which to attach. Traffic will be partitioned
evenly between instances servicing queues on the same
interface. The queue to which an incoming packet is assigned
is a function of the TCP or UDP source and destination ports
(if any) and the source and destination IPv4 or IPv6
addresses. Fragmented packets will be delivered to the
lowest-numbered queue.
Note that currently the lwAFTR is restricted to running at
most 2 RSS workers per device. This limitation may be lifted
to 4 soon. Raising it farther is possible but needs changes
to how the lwAFTR uses its PCI devices.";
}

container external-interface {
Expand Down
2 changes: 1 addition & 1 deletion src/program/lwaftr/doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ softwire-config {
instances {
device "00:05.0"
queue {
id 1;
id 0;
external-interface {
ip 10.10.10.10;
mac 12:12:12:12:12:12;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ local function multiprocess_migration(src, conf_file)
local instance = {
[device] = {queue = cltable.new({ key_type = queue_key }),},
}
local key = ffi.new(queue_key, 1)
local key = ffi.new(queue_key, 0)
local value = {
external_interface = {
device = ex_device,
Expand Down
43 changes: 18 additions & 25 deletions src/program/lwaftr/run/run.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local cpuset = require("lib.cpuset")
local csv_stats = require("program.lwaftr.csv_stats")
local lib = require("core.lib")
local setup = require("program.lwaftr.setup")
local cltable = require("lib.cltable")
local ingress_drop_monitor = require("lib.timers.ingress_drop_monitor")
local lwutil = require("apps.lwaftr.lwutil")
local engine = require("core.app")
Expand All @@ -20,30 +21,27 @@ end
local function migrate_device_on_config(config, v4, v6)
-- Validate there is only one instance, otherwise the option is ambiguous.
local device, instance
for pci_addr, inst in pairs(config.softwire_config.instance) do
assert(device == nil, "Unable to migrate config to '"..pci_addr.."' as"..
"there are multiple instances configured.")
device, instance = pci_addr, inst
for k, v in pairs(config.softwire_config.instance) do
assert(device == nil,
"Unable to specialize config for specified NIC(s) as"..
"there are multiple instances configured.")
device, instance = k, v
end

local migrated = config
migrated.softwire_config.instance = lib.deepcopy(
migrated.softwire_config.instance
)
local instances = migrated.softwire_config.instance
assert(device ~= nil,
"Unable to specialize config for specified NIC(s) as"..
"there are no instances configured.")

if v4 and v4 ~= device then
print("Migrating instance '"..device.."' to '"..v4.."'")
instances[v4] = instances[device]
instances[device] = nil
config.softwire_config.instance[v4] = instance
config.softwire_config.instance[device] = nil
end

if v6 then
local device, instance = next(instances)
instance.queue.values[1].external_interface.device = v6
for id, queue in cltable.pairs(instance.queue) do
queue.external_interface.device = v6
end
end

return migrated
end

function parse_args(args)
Expand Down Expand Up @@ -147,18 +145,13 @@ function run(args)
local opts, scheduling, conf_file, v4, v6 = parse_args(args)
local conf = setup.read_config(conf_file)

-- If there are v4 or v6 options we need to migrate the configuration in
-- memory from the PCI device specified, later we'll want to support
-- selecting multiple devices, this is where you will do it.
if v4 or v6 then
conf = migrate_device_on_config(conf, v4, v6)
end
-- If the user passed --v4, --v6, or --on-a-stick, migrate the
-- configuration's device.
if v4 or v6 then migrate_device_on_config(conf, v4, v6) end

-- If there is a name defined on the command line, it should override
-- anything defined in the config.
if opts.name then
conf.softwire_config.name = opts.name
end
if opts.name then conf.softwire_config.name = opts.name end

local function setup_fn(graph, lwconfig)
-- If --virtio has been specified, always use this.
Expand Down
Loading

0 comments on commit d036fd0

Please sign in to comment.