-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Rewrote `app.lua` and created `config.lua`.) Added a new 'config' data structure that describes an app network and the function `app.configure(config)` to instantiate it. You can call `app.configure()` several times and each call will compute the changes needed to switch from the old app network to the new one, creating/deleting/updating apps and links as needed. This requires minor changes to all apps: 1. The functions `receive`, `transmit`, `nreadable`, etc, have moved from the `app` module to the `link` module. (Calls must be updated.) 2. The port arrays `outputi` and `inputi` aren't automatically created anymore. This is an issue if you want to iterate through all ports. (You can look at how `basic_apps` dealt with this.) and minor changes to all app-networks: 1. Use the `config` module functions `new()`, `app()`, and `link()` to define which apps and links you need. 2. Call `app.configure(myconfig)` instead of `app.relink()`. 2. (Optional) call `app.main({duration = numseconds})` instead of writing a `breathe()` loop.
- Loading branch information
Showing
6 changed files
with
245 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
-- 'config' is a data structure that describes an app network. | ||
|
||
module(..., package.seeall) | ||
|
||
-- API: Create a new configuration. | ||
-- Initially there are no apps or links. | ||
function new () | ||
return { | ||
apps = {}, -- list of {name, class, args} | ||
links = {} -- table with keys like "a.out -> b.in" | ||
} | ||
end | ||
|
||
-- API: Add an app to the configuration. | ||
-- | ||
-- config.app(c, name, class, arg): | ||
-- c is a config object. | ||
-- name is the name of this app in the network (a string). | ||
-- class is the Lua object with a class:new(arg) method to create the app. | ||
-- arg is the app's configuration (as a string to be passed to new()). | ||
-- | ||
-- Example: config.app(c, "nic", Intel82599, [[{pciaddr = "0000:00:01.00"}]]) | ||
function app (config, name, class, arg) | ||
arg = arg or "nil" | ||
assert(type(name) == "string", "name must be a string") | ||
assert(type(class) == "table", "class must be a table") | ||
assert(type(arg) == "string", "arg must be a string") | ||
config.apps[name] = { class = class, arg = arg} | ||
end | ||
|
||
-- API: Add a link to the configuration. | ||
-- | ||
-- Example: config.link(c, "nic.tx -> vm.rx") | ||
function link (config, spec) | ||
config.links[canonical_link(spec)] = true | ||
end | ||
|
||
-- Given "a.out -> b.in" return "a", "out", "b", "in". | ||
function parse_link (spec) | ||
local fa, fl, ta, tl = spec:gmatch(link_syntax)() | ||
if fa and fl and ta and tl then | ||
return fa, fl, ta, tl | ||
else | ||
error("link parse error: " .. spec) | ||
end | ||
end | ||
|
||
link_syntax = [[ *(%w+).(%w+) *-> *(%w+).(%w+) *]] | ||
|
||
function format_link (fa, fl, ta, tl) | ||
return ("%s.%s -> %s.%s"):format(fa, fl, ta, tl) | ||
end | ||
|
||
function canonical_link (spec) | ||
return format_link(parse_link(spec)) | ||
end | ||
|
||
-- Return a Lua object for the arg to an app. | ||
-- Example: | ||
-- parse_app_arg("{ timeout = 5 * 10 }") => { timeout = 50 } | ||
function parse_app_arg (s) | ||
print("s", type(s), s) | ||
assert(type(s) == 'string') | ||
return loadstring("return " .. s)() | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
enum { LINK_RING_SIZE = 8192, | ||
LINK_MAX_PACKETS = 8191 | ||
}; | ||
|
||
struct link { | ||
// this is a circular ring buffer, as described at: | ||
// http://en.wikipedia.org/wiki/Circular_buffer | ||
// Two cursors: | ||
// read: the next element to be read | ||
// write: the next element to be written | ||
int read, write; | ||
// Index (into the Lua app.active_apps array) of the app that | ||
// receives from this link. | ||
int receiving_app; | ||
// True when there are new packets to process. | ||
// Set when a new packet is added to the ring and cleared after | ||
// 'receiving_app' runs. | ||
bool has_new_data; | ||
struct packet* packets[LINK_RING_SIZE]; | ||
struct { | ||
double txbytes, rxbytes, txpackets, rxpackets, txdrop; | ||
} stats; | ||
}; | ||
|
Oops, something went wrong.
this (line 132 of src/core/app.lua) still worries me, as it seems to assume that the subsequent
receiver:push()
always empies the link. instead, it's just as efficient to usenot link_ling.is_empty(link)
on the line above this one.