Skip to content

Commit

Permalink
core.app: assert that links are connected only once
Browse files Browse the repository at this point in the history
This reveals bugs in some test cases:

In apps.lwaft.V4V6, the same source is connected to different apps,
which does not work as intended.

In apps.test.match, fix bug in config reuse the code re-uses the same
app config object for each test. In the penultimate case, the config
contains the linkspec "src.output -> sink.rx". The last case adds the
specs "src.output -> join.src" and "join.output -> sink.rx",
i.e. there are now two links connected to sink.rx.  The hash-part of
the app's input table only contains the second of these links while
the array part contains both.

Re-use of an app config object only works in an additive fashion as
there is no method to remove apps or links from it.  The bug is fixed
by creating a new config object and adding all elements from scratch.

program.snabbvmx.tests.end-to-end.selftest.sh also fails.  This
appears to be a bug in program.snabbvmx.lwaftr.setup, which creates
the link specs

vm_v4v6.v6 -> nh_fwd6.vm
vm_v4v6.v4 -> nh_fwd6.vm

The latter should probably be

vm_v4v6.v4 -> nh_fwd4.vm
  • Loading branch information
alexandergall committed Jan 11, 2019
1 parent a2097f3 commit 395a4f8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/apps/lwaftr/V4V6.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,19 @@ local function test_join ()
engine.configure(config.new()) -- Clean up engine.

local c = config.new()
config.app(c, 'source', basic_apps.Join)
config.app(c, 'source4', basic_apps.Join)
config.app(c, 'source6', basic_apps.Join)
config.app(c, 'v4v6', V4V6)
config.app(c, 'sink', basic_apps.Sink)

config.link(c, 'source.output -> v4v6.v4')
config.link(c, 'source.output -> v4v6.v6')
config.link(c, 'source4.output -> v4v6.v4')
config.link(c, 'source6.output -> v4v6.v6')
config.link(c, 'v4v6.output -> sink.input')

engine.configure(c)
link.transmit(engine.app_table.source.output.output, arp_pkt())
link.transmit(engine.app_table.source.output.output, ipv4_pkt())
link.transmit(engine.app_table.source.output.output, ipv6_pkt())
link.transmit(engine.app_table.source4.output.output, arp_pkt())
link.transmit(engine.app_table.source4.output.output, ipv4_pkt())
link.transmit(engine.app_table.source6.output.output, ipv6_pkt())
engine.main({duration = 0.1, noreport = true})

assert(link.stats(engine.app_table.sink.input.input).rxpackets == 3)
Expand Down
4 changes: 3 additions & 1 deletion src/apps/test/match.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,16 @@ function selftest()
engine.main({duration=0.0001})
assert(#engine.app_table.sink:errors() > 0)

engine.configure(config.new())
c = config.new()
config.app(c, "sink", Match, {fuzzy=true})
config.app(c, "src", basic_apps.Source, 8)
config.app(c, "comparator", basic_apps.Source, 8)
config.app(c, "garbage", basic_apps.Source, 12)
config.app(c, "join", basic_apps.Join)
config.link(c, "src.output -> join.src")
config.link(c, "garbage.output -> join.garbage")
config.link(c, "join.output -> sink.rx")
config.link(c, "comparator.output -> sink.comparator")
engine.configure(c)
engine.main({duration=0.0001})
assert(#engine.app_table.sink:errors() == 0)
Expand Down
4 changes: 4 additions & 0 deletions src/core/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,17 @@ function apply_config_actions (actions)
function ops.link_output (appname, linkname, linkspec)
local app = app_table[appname]
local link = assert(link_table[linkspec])
assert(not app.output[linkname],
appname..": duplicate output link "..linkname)
app.output[linkname] = link
table.insert(app.output, link)
if app.link then app:link() end
end
function ops.link_input (appname, linkname, linkspec)
local app = app_table[appname]
local link = assert(link_table[linkspec])
assert(not app.input[linkname],
appname..": duplicate input link "..linkname)
app.input[linkname] = link
table.insert(app.input, link)
if app.link then app:link() end
Expand Down

0 comments on commit 395a4f8

Please sign in to comment.