Skip to content

Commit

Permalink
Merge PR #1028 (v2016.10 release) into master
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeneia committed Oct 7, 2016
2 parents b7d6d77 + 89a1f26 commit eb9d141
Show file tree
Hide file tree
Showing 42 changed files with 457 additions and 487 deletions.
38 changes: 33 additions & 5 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,15 @@ Name of the app. *Read-only*.

— Field **myapp.shm**

Can be set to a specification for `core.shm.create_frame` during `new`. When
set, this field will be initialized to a frame of shared memory objects by the
engine.
Can be set to a specification for `core.shm.create_frame`. When set, this field
will be initialized to a frame of shared memory objects by the engine.


— Field **myapp.config**

Can be set to a specification for `core.lib.parse`. When set, the specification
will be used to validate the app’s arg when it is configured using
`config.app`.


— Method **myapp:link**
Expand Down Expand Up @@ -871,15 +877,37 @@ Returns a copy of *array*. *Array* must not be a "sparse array".
— Function **lib.htons** *n*

Host to network byte order conversion functions for 32 and 16 bit
integers *n* respectively.
integers *n* respectively. Unsigned.

— Function **lib.ntohl** *n*

— Function **lib.ntohs** *n*

Network to host byte order conversion functions for 32 and 16 bit
integers *n* respectively.
integers *n* respectively. Unsigned.

— Function **lib.parse** *arg*, *config*

Validates *arg* against the specification in *config*, and returns a fresh
table containing the parameters in *arg* and any omitted optional parameters
with their default values. Given *arg*, a table of parameters or `nil`, assert
that from *config* all of the required keys are present, fill in any missing
values for optional keys, and error if any unknown keys are found. *Config* has
the following format:

```
config := { key = {[required=boolean], [default=value]}, ... }
```

Each key is optional unless `required` is set to a true value, and its default
value defaults to `nil`.

Example:

```
lib.parse({foo=42, bar=43}, {foo={required=true}, bar={}, baz={default=44}})
=> {foo=42, bar=43, baz=44}
```


## Main
Expand Down
2 changes: 1 addition & 1 deletion src/apps/basic/basic_apps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ end
function Join:push ()
for _, inport in ipairs(self.input) do
while not link.empty(inport) do
transmit(self.output.out, receive(inport))
transmit(self.output.output, receive(inport))
end
end
end
Expand Down
13 changes: 6 additions & 7 deletions src/apps/bridge/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,19 @@
-- ports to limit the scope of flooding.

module(..., package.seeall)
local config = require("core.config")

bridge = subClass(nil)
bridge._name = "base bridge"
bridge.config = {
ports = {required=true},
split_horizon_groups = {},
config = {default={}}
}

function bridge:new (arg)
function bridge:new (conf)
assert(self ~= bridge, "Can't instantiate abstract class "..self:name())
local o = bridge:superClass().new(self)
local conf = arg and config.parse_app_arg(arg) or {}
assert(conf.ports, self._name..": invalid configuration")
o._conf = conf
if not o._conf.config then
o._conf.config = {}
end

-- Create a list of forwarding ports for all ports connected to the
-- bridge, taking split horizon groups into account
Expand Down
24 changes: 16 additions & 8 deletions src/apps/intel/intel10g.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@ local timer = require("core.timer")
local bits, bitset = lib.bits, lib.bitset
local band, bor, lshift = bit.band, bit.bor, bit.lshift

num_descriptors = 1024
local num_descriptors = 1024
function ring_buffer_size (arg)
if not arg then return num_descriptors end
local ring_size = assert(tonumber(arg), "bad ring size: " .. arg)
if ring_size > 32*1024 then
error("ring size too large for hardware: " .. ring_size)
end
if math.log(ring_size)/math.log(2) % 1 ~= 0 then
error("ring size is not a power of two: " .. arg)
end
num_descriptors = assert(tonumber(arg))
end

-- Defaults for configurable items
local default = {
Expand Down Expand Up @@ -692,8 +703,8 @@ function M_vf:reconfig(opts)
:set_MAC(opts.macaddr)
:set_mirror(opts.mirror)
:set_VLAN(opts.vlan)
:set_rx_stats(opts.rxcounter or 0)
:set_tx_stats(opts.txcounter or 0)
:set_rx_stats(opts.rxcounter)
:set_tx_stats(opts.txcounter)
:set_tx_rate(opts.rate_limit, opts.priority)
:enable_receive()
:enable_transmit()
Expand All @@ -707,8 +718,8 @@ function M_vf:init (opts)
:set_MAC(opts.macaddr)
:set_mirror(opts.mirror)
:set_VLAN(opts.vlan)
:set_rx_stats(opts.rxcounter or 0)
:set_tx_stats(opts.txcounter or 0)
:set_rx_stats(opts.rxcounter)
:set_tx_stats(opts.txcounter)
:set_tx_rate(opts.rate_limit, opts.priority)
:enable_receive()
:enable_transmit()
Expand Down Expand Up @@ -981,7 +992,6 @@ function M_vf:get_txstats ()
end

function M_vf:set_tx_rate (limit, priority)
limit = tonumber(limit) or 0
self.pf.r.RTTDQSEL(self.poolnum)
if limit >= 10 then
local factor = 10000 / tonumber(limit) -- line rate = 10,000 Mb/s
Expand All @@ -990,8 +1000,6 @@ function M_vf:set_tx_rate (limit, priority)
else
self.pf.r.RTTBCNRC(0x00)
end

priority = tonumber(priority) or 1.0
self.pf.r.RTTDT1C(bit.band(math.floor(priority * 0x80), 0x3FF))
return self
end
Expand Down
40 changes: 26 additions & 14 deletions src/apps/intel/intel_app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,21 @@ local register = require("lib.hardware.register")
local macaddress = require("lib.macaddress")
local intel10g = require("apps.intel.intel10g")
local receive, transmit, empty = link.receive, link.transmit, link.empty
Intel82599 = {}

Intel82599 = {
config = {
pciaddr = {required=true},
mtu = {},
macaddr = {},
vlan = {},
vmdq = {},
mirror = {},
rxcounter = {default=0},
txcounter = {default=0},
rate_limit = {default=0},
priority = {default=1.0}
}
}
Intel82599.__index = Intel82599

local C = ffi.C
Expand All @@ -35,8 +49,7 @@ local function firsthole(t)
end

-- Create an Intel82599 App for the device with 'pciaddress'.
function Intel82599:new (arg)
local conf = config.parse_app_arg(arg)
function Intel82599:new (conf)
local self = {}

if conf.vmdq then
Expand Down Expand Up @@ -111,8 +124,7 @@ function Intel82599:stop()
end


function Intel82599:reconfig(arg)
local conf = config.parse_app_arg(arg)
function Intel82599:reconfig (conf)
assert((not not self.dev.pf) == (not not conf.vmdq), "Can't reconfig from VMDQ to single-port or viceversa")

self.dev:reconfig(conf)
Expand Down Expand Up @@ -376,14 +388,14 @@ function mq_sq(pcidevA, pcidevB)
print("Send traffic from a nicA (SF) to nicB (two VFs)")
print("The packets should arrive evenly split between the VFs")
config.app(c, 'sink_ms', basic_apps.Sink)
config.link(c, 'source_ms.out -> repeater_ms.input')
config.link(c, 'source_ms.output -> repeater_ms.input')
config.link(c, 'repeater_ms.output -> nicAs.rx')
config.link(c, 'nicAs.tx -> sink_ms.in1')
config.link(c, 'nicBm0.tx -> sink_ms.in2')
config.link(c, 'nicBm1.tx -> sink_ms.in3')
engine.configure(c)
link.transmit(engine.app_table.source_ms.output.out, packet.from_string(d1))
link.transmit(engine.app_table.source_ms.output.out, packet.from_string(d2))
link.transmit(engine.app_table.source_ms.output.output, packet.from_string(d1))
link.transmit(engine.app_table.source_ms.output.output, packet.from_string(d2))
end

-- one multiqueue driver with two apps and do switch stuff
Expand Down Expand Up @@ -424,13 +436,13 @@ function mq_sw(pcidevA)
print ("Send a bunch of packets from Am0")
print ("half of them go to nicAm1 and half go nowhere")
config.app(c, 'sink_ms', basic_apps.Sink)
config.link(c, 'source_ms.out -> repeater_ms.input')
config.link(c, 'source_ms.output -> repeater_ms.input')
config.link(c, 'repeater_ms.output -> nicAm0.rx')
config.link(c, 'nicAm0.tx -> sink_ms.in1')
config.link(c, 'nicAm1.tx -> sink_ms.in2')
engine.configure(c)
link.transmit(engine.app_table.source_ms.output.out, packet.from_string(d1))
link.transmit(engine.app_table.source_ms.output.out, packet.from_string(d2))
link.transmit(engine.app_table.source_ms.output.output, packet.from_string(d1))
link.transmit(engine.app_table.source_ms.output.output, packet.from_string(d2))
end

function manyreconf(pcidevA, pcidevB, n, do_pf)
Expand Down Expand Up @@ -476,14 +488,14 @@ function manyreconf(pcidevA, pcidevB, n, do_pf)
vlan = 100+i,
})
config.app(c, 'sink_ms', basic_apps.Sink)
config.link(c, 'source_ms.out -> repeater_ms.input')
config.link(c, 'source_ms.output -> repeater_ms.input')
config.link(c, 'repeater_ms.output -> nicAm0.rx')
config.link(c, 'nicAm0.tx -> sink_ms.in1')
config.link(c, 'nicAm1.tx -> sink_ms.in2')
if do_pf then engine.configure(config.new()) end
engine.configure(c)
link.transmit(engine.app_table.source_ms.output.out, packet.from_string(d1))
link.transmit(engine.app_table.source_ms.output.out, packet.from_string(d2))
link.transmit(engine.app_table.source_ms.output.output, packet.from_string(d1))
link.transmit(engine.app_table.source_ms.output.output, packet.from_string(d2))
engine.main({duration = 0.1, no_report=true})
cycles = cycles + 1
redos = redos + engine.app_table.nicAm1.dev.pf.redos
Expand Down
6 changes: 3 additions & 3 deletions src/apps/intel/loadgen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function disable_tx_descriptor_writeback (dev)
-- Disable writeback of transmit descriptors.
-- That way our transmit descriptors stay fresh and reusable.
-- Tell hardware write them to this other memory instead.
local bytes = intel10g.num_descriptors * ffi.sizeof(intel10g.rxdesc_t)
local bytes = intel10g.ring_buffer_size() * ffi.sizeof(intel10g.rxdesc_t)
local ptr, phy = memory.dma_alloc(bytes)
dev.r.TDWBAL(phy % 2^32)
dev.r.TDWBAH(phy / 2^32)
Expand All @@ -40,7 +40,7 @@ end
function zero_descriptors (dev)
-- Clear unused descriptors
local b = memory.dma_alloc(4096)
for i = 0, intel10g.num_descriptors-1 do
for i = 0, intel10g.ring_buffer_size()-1 do
-- Make each descriptors point to valid DMA memory but be 0 bytes long.
dev.txdesc[i].address = memory.virtual_to_physical(b)
dev.txdesc[i].options = bit.lshift(1, 24) -- End of Packet flag
Expand All @@ -64,7 +64,7 @@ function LoadGen:pull ()
if dev.tdt == 0 then return end
C.full_memory_barrier()
if tdh == 0 then
dev.r.TDT(intel10g.num_descriptors)
dev.r.TDT(intel10g.ring_buffer_size())
else
dev.r.TDT(tdh - 1)
end
Expand Down
15 changes: 8 additions & 7 deletions src/apps/ipsec/esp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ local esp = require("lib.ipsec.esp")
local counter = require("core.counter")
local C = require("ffi").C

AES128gcm = {}

local provided_counters = {
'type', 'dtime', 'txerrors', 'rxerrors'
AES128gcm = {
config = {
spi = {required=true}, key = {required=true}, window_size = {}
},
shm = {
txerrors = {counter}, rxerrors = {counter}
}
}

function AES128gcm:new (arg)
local conf = arg and config.parse_app_arg(arg) or {}
function AES128gcm:new (conf)
local self = {}
self.encrypt = esp.esp_v6_encrypt:new{
mode = "aes-128-gcm",
Expand All @@ -28,7 +30,6 @@ function AES128gcm:new (arg)
keymat = conf.key:sub(1, 32),
salt = conf.key:sub(33, 40),
window_size = conf.replay_window}
self.shm = { txerrors = {counter}, rxerrors = {counter} }
return setmetatable(self, {__index = AES128gcm})
end

Expand Down
35 changes: 19 additions & 16 deletions src/apps/ipv6/nd_light.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ local lib = require("core.lib")

nd_light = subClass(nil)
nd_light._name = "Partial IPv6 neighbor discovery"
nd_light.config = {
local_mac = {required=true},
local_ip = {required=true},
next_hop = {required=true},
delay = {default=1000},
retrans = {}
}
nd_light.shm = {
status = {counter, 2}, -- Link down
rxerrors = {counter},
txerrors = {counter},
txdrop = {counter},
ns_checksum_errors = {counter},
ns_target_address_errors = {counter},
na_duplicate_errors = {counter},
na_target_address_errors = {counter},
nd_protocol_errors = {counter}
}

-- config:
-- local_mac MAC address of the interface attached to "south".
Expand Down Expand Up @@ -79,12 +97,8 @@ local function check_ip_address(ip, desc)
return ip
end

function nd_light:new (arg)
--copy the args to avoid changing the arg table so that it stays reusable.
local conf = arg and lib.deepcopy(config.parse_app_arg(arg)) or {}
function nd_light:new (conf)
local o = nd_light:superClass().new(self)
conf.delay = conf.delay or 1000
assert(conf.local_mac, "nd_light: missing local MAC address")
if type(conf.local_mac) == "string" and string.len(conf.local_mac) ~= 6 then
conf.local_mac = ethernet:pton(conf.local_mac)
else
Expand Down Expand Up @@ -199,17 +213,6 @@ function nd_light:new (arg)
}
o._logger = lib.logger_new({ module = 'nd_light' })

-- Create counters
o.shm = { status = {counter, 2}, -- Link down
rxerrors = {counter},
txerrors = {counter},
txdrop = {counter},
ns_checksum_errors = {counter},
ns_target_address_errors = {counter},
na_duplicate_errors = {counter},
na_target_address_errors = {counter},
nd_protocol_errors = {counter} }

return o
end

Expand Down
Loading

0 comments on commit eb9d141

Please sign in to comment.