Skip to content

Commit

Permalink
Revert "lwaftr: keep full config in worker setup"
Browse files Browse the repository at this point in the history
This reverts commit d4a1083.

Instead we attach instance device/queue_id meta-data to the
worker configs using a setmetatable, and ensure that all
config manipulation based on the worker queue id is performed
within the manager process.

Specifically, this means moving select_instance() from
apps.lwaftr.lwaftr to apps.lwaftr.lwutil and calling it from
program.lwaftr.setup. (I also took the liberty to make this
function pure to avoid future confusion on my end.)
  • Loading branch information
eugeneia committed Oct 1, 2021
1 parent 98e97b4 commit 75a3373
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 33 deletions.
18 changes: 1 addition & 17 deletions src/apps/lwaftr/lwaftr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -339,21 +339,6 @@ local function drop(pkt)
packet.free(pkt)
end

local function select_instance(conf)
local function table_merge(t1, t2)
local ret = {}
for k,v in pairs(t1) do ret[k] = v end
for k,v in pairs(t2) do ret[k] = v end
return ret
end
local device, id, queue = lwutil.parse_instance(conf)
conf.softwire_config.external_interface = table_merge(
conf.softwire_config.external_interface, queue.external_interface)
conf.softwire_config.internal_interface = table_merge(
conf.softwire_config.internal_interface, queue.internal_interface)
return conf
end

LwAftr = { yang_schema = 'snabb-softwire-v2' }
-- Fields:
-- - direction: "in", "out", "hairpin", "drop";
Expand Down Expand Up @@ -420,9 +405,8 @@ LwAftr.shm = {
function LwAftr:new(conf)
if conf.debug then debug = true end
local o = setmetatable({}, {__index=LwAftr})
conf = select_instance(conf).softwire_config
conf = conf.softwire_config
o.conf = conf

o.binding_table = bt.load(conf.binding_table)
o.inet_lookup_queue = bt.BTLookupQueue.new(o.binding_table)
o.hairpin_lookup_queue = bt.BTLookupQueue.new(o.binding_table)
Expand Down
20 changes: 20 additions & 0 deletions src/apps/lwaftr/lwutil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ local ntohs = lib.ntohs

-- Return device PCI address, queue ID, and queue configuration.
function parse_instance(conf)
assert(conf.worker_config, "conf missing instance/queue metadata.")
local device = conf.worker_config.device
local id = conf.worker_config.queue_id
local queue = conf.softwire_config.instance[device].queue[id]
Expand Down Expand Up @@ -49,6 +50,25 @@ function num_queues(conf)
return n
end

function select_instance(conf)
local function table_merge(t1, t2)
local ret = {}
for k,v in pairs(t1) do ret[k] = v end
for k,v in pairs(t2) do ret[k] = v end
return ret
end
local device, id, queue = parse_instance(conf)
local copy = {softwire_config={}}
for k,v in pairs(conf.softwire_config) do
copy.softwire_config[k] = v
end
copy.softwire_config.external_interface = table_merge(
conf.softwire_config.external_interface, queue.external_interface)
copy.softwire_config.internal_interface = table_merge(
conf.softwire_config.internal_interface, queue.internal_interface)
return copy
end

function get_ihl_from_offset(pkt, offset)
local ver_and_ihl = pkt.data[offset]
return band(ver_and_ihl, 0xf) * 4
Expand Down
13 changes: 0 additions & 13 deletions src/lib/yang/snabb-softwire-v2.yang
Original file line number Diff line number Diff line change
Expand Up @@ -886,18 +886,5 @@ module snabb-softwire-v2 {
}
}

container worker-config {
description
"Worker process configuration state. The contained leaves are used only
internally. Setting them has no effect.";

leaf device {
type string;
}
leaf queue-id {
type uint8;
}
}

uses state-counters;
}
6 changes: 3 additions & 3 deletions src/program/lwaftr/setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function lwaftr_app(c, conf)
{ address = convert_ipv4(iexternal_interface.ip) })
config.app(c, "icmpechov6", ipv6_echo.ICMPEcho,
{ address = iinternal_interface.ip })
config.app(c, "lwaftr", lwaftr.LwAftr, conf)
config.app(c, "lwaftr", lwaftr.LwAftr, lwutil.select_instance(conf))
config.app(c, "fragmenterv4", ipv4_fragment.Fragmenter,
{ mtu=gexternal_interface.mtu })
config.app(c, "fragmenterv6", ipv6_fragment.Fragmenter,
Expand Down Expand Up @@ -827,8 +827,8 @@ local function compute_worker_configs(conf)
for id, _ in pairs(queues.queue) do
local worker_id = string.format('%s/%s', device, id)
local worker_config = make_copy()
worker_config.worker_config = {device=device, queue_id=id}
ret[worker_id] = worker_config
local meta = {worker_config = {device=device, queue_id=id}}
ret[worker_id] = setmetatable(worker_config, {__index=meta})
end
end
return ret
Expand Down

0 comments on commit 75a3373

Please sign in to comment.