Skip to content

Commit

Permalink
Merge branch 'master' into statistics-superset
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/apps/intel/intel10g.lua
#	src/core/app.lua
  • Loading branch information
eugeneia committed Jun 9, 2016
2 parents 327804f + 8fb3759 commit 30fcbcb
Show file tree
Hide file tree
Showing 129 changed files with 4,409 additions and 147 deletions.
4 changes: 2 additions & 2 deletions lib/ljsyscall/syscall/linux/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

local require, error, assert, tonumber, tostring,
setmetatable, pairs, ipairs, unpack, rawget, rawset,
pcall, type, table, string =
pcall, type, table, string =
require, error, assert, tonumber, tostring,
setmetatable, pairs, ipairs, unpack, rawget, rawset,
pcall, type, table, string
Expand Down Expand Up @@ -47,7 +47,7 @@ function util.if_nametoindex(name) -- standard function in some libc versions
if not s then return nil, err end
local i, err = if_nametoindex(name, s)
if not i then return nil, err end
local ok, err = S.close(s)
local ok, err = s:close()
if not ok then return nil, err end
return i
end
Expand Down
6 changes: 6 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,12 @@ Returns the payload length of *packet*.

Returns an exact copy of *packet*.

— Function **packet.resize** *packet*, *length*

Sets the payload length of *packet*, truncating or extending its payload. In
the latter case the contents of the extended area at the end of the payload are
filled with zeros.

— Function **packet.append** *packet*, *pointer*, *length*

Appends *length* bytes starting at *pointer* to the end of *packet*. An
Expand Down
26 changes: 26 additions & 0 deletions src/apps/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,29 @@ link. The packets are transmitted in the order they were received.
| |
+----------+

## Truncate

The `Truncate` app sends all packets received from the `input` to the `output`
link and truncates or zero pads each packet to a given length. It accepts a
number as its configuration argument which is the length of the truncated or
padded packets.

DIAGRAM: Truncate
+----------+
| |
input ----* Truncate *---- output
| |
+----------+

## Sample

The `Sample` app forwards packets every *n*th packet from the `input` link to
the `output` link, and drops all others packets. It accepts a number as its
configuration argument which is *n*.

DIAGRAM: Sample
+--------+
| |
input ----* Sample *---- output
| |
+--------+
42 changes: 38 additions & 4 deletions src/apps/basic/basic_apps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ module(...,package.seeall)
local app = require("core.app")
local packet = require("core.packet")
local link = require("core.link")
local transmit, receive = link.transmit, link.receive


local ffi = require("ffi")
local C = ffi.C
local transmit, receive = link.transmit, link.receive

--- # `Source` app: generate synthetic packets

Expand Down Expand Up @@ -147,3 +144,40 @@ function Repeater:stop ()
end
end

--- # `Truncate` app: truncate or zero pad packet to length n

Truncate = {}

function Truncate:new (n)
return setmetatable({n = n}, {__index=Truncate})
end

function Truncate:push ()
for _ = 1, link.nreadable(self.input.input) do
local p = receive(self.input.input)
ffi.fill(p.data, math.min(0, self.n - p.length))
p.length = self.n
transmit(self.output.output,p)
end
end

--- # `Sample` app: let through every nth packet

Sample = {}

function Sample:new (n)
return setmetatable({n = n, seen = 1}, {__index=Sample})
end

function Sample:push ()
for _ = 1, link.nreadable(self.input.input) do
local p = receive(self.input.input)
if self.n == self.seen then
transmit(self.output.output, p)
self.seen = 1
else
self.seen = self.seen + 1
packet.free(p)
end
end
end
21 changes: 13 additions & 8 deletions src/apps/intel/intel10g.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ end
function M_sf:open ()
pci.unbind_device_from_linux(self.pciaddress)
pci.set_bus_master(self.pciaddress, true)
self.base, self.fd = pci.map_pci_memory(self.pciaddress, 0)
self.base, self.fd = pci.map_pci_memory_locked(self.pciaddress, 0)
register.define(config_registers_desc, self.r, self.base)
register.define(transmit_registers_desc, self.r, self.base)
register.define(receive_registers_desc, self.r, self.base)
Expand Down Expand Up @@ -178,6 +178,10 @@ do
end
end

function M_sf:ingress_packet_drops ()
return self.qs.QPRDC[0]()
end

function M_sf:global_reset ()
local reset = bits{LinkReset=3, DeviceReset=26}
self.r.CTRL(reset)
Expand Down Expand Up @@ -486,7 +490,7 @@ end
function M_pf:open ()
pci.unbind_device_from_linux(self.pciaddress)
pci.set_bus_master(self.pciaddress, true)
self.base, self.fd = pci.map_pci_memory(self.pciaddress, 0)
self.base, self.fd = pci.map_pci_memory_locked(self.pciaddress, 0)
register.define(config_registers_desc, self.r, self.base)
register.define_array(switch_config_registers_desc, self.r, self.base)
register.define_array(packet_filter_desc, self.r, self.base)
Expand Down Expand Up @@ -688,8 +692,8 @@ function M_vf:reconfig(opts)
:set_MAC(opts.macaddr)
:set_mirror(opts.mirror)
:set_VLAN(opts.vlan)
:set_rx_stats(opts.rxcounter)
:set_tx_stats(opts.txcounter)
:set_rx_stats(opts.rxcounter or 0)
:set_tx_stats(opts.txcounter or 0)
:set_tx_rate(opts.rate_limit, opts.priority)
:enable_receive()
:enable_transmit()
Expand All @@ -703,8 +707,8 @@ function M_vf:init (opts)
:set_MAC(opts.macaddr)
:set_mirror(opts.mirror)
:set_VLAN(opts.vlan)
:set_rx_stats(opts.rxcounter)
:set_tx_stats(opts.txcounter)
:set_rx_stats(opts.rxcounter or 0)
:set_tx_stats(opts.txcounter or 0)
:set_tx_rate(opts.rate_limit, opts.priority)
:enable_receive()
:enable_transmit()
Expand Down Expand Up @@ -958,7 +962,6 @@ function M_vf:set_tx_stats (counter)
end

function M_vf:get_rxstats ()
if not self.rxstats then return nil end
return {
counter_id = self.rxstats,
packets = tonumber(self.pf.qs.QPRC[self.rxstats]()),
Expand All @@ -969,7 +972,6 @@ function M_vf:get_rxstats ()
end

function M_vf:get_txstats ()
if not self.txstats then return nil end
return {
counter_id = self.txstats,
packets = tonumber(self.pf.qs.QPTC[self.txstats]()),
Expand All @@ -994,6 +996,9 @@ function M_vf:set_tx_rate (limit, priority)
return self
end

function M_vf:ingress_packet_drops ()
return self.pf.qs.QPRDC[self.rxstats]()
end

rxdesc_t = ffi.typeof [[
union {
Expand Down
4 changes: 4 additions & 0 deletions src/apps/intel/intel_app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ function Intel82599:pull ()
end
end

function Intel82599:ingress_packet_drops ()
return self.dev:ingress_packet_drops()
end

function Intel82599:add_receive_buffers ()
-- Generic buffers
while self.dev:can_add_receive_buffer() do
Expand Down
5 changes: 5 additions & 0 deletions src/apps/intel/loadgen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ function LoadGen:report ()
print(self.pciaddress,
"TXDGPC (TX packets)", lib.comma_value(tonumber(self.dev.s.TXDGPC())),
"GOTCL (TX octets)", lib.comma_value(tonumber(self.dev.s.GOTCL())))
print(self.pciaddress,
"RXDGPC (RX packets)", lib.comma_value(tonumber(self.dev.s.RXDGPC())),
"GORCL (RX octets)", lib.comma_value(tonumber(self.dev.s.GORCL())))
self.dev.s.TXDGPC:reset()
self.dev.s.GOTCL:reset()
self.dev.s.RXDGPC:reset()
self.dev.s.GORCL:reset()
end

8 changes: 6 additions & 2 deletions src/apps/ipv6/nd_light.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,14 @@ local function check_ip_address(ip, desc)
end

function nd_light:new (arg)
local conf = arg and config.parse_app_arg(arg) or {}
local arg = arg and config.parse_app_arg(arg) or {}
--copy the args to avoid changing the arg table so that it stays reusable.
local conf = {}
for k,v in pairs(arg) do
conf[k] = v
end
local o = nd_light:superClass().new(self)
conf.delay = conf.delay or 1000
conf.retrans = conf.retrans
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)
Expand Down
Binary file added src/apps/socket/.images/UnixSocket.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions src/apps/socket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,25 @@ interface are put on the `tx` port.

The `RawSocket` app accepts a string as its configuration argument. The
string denotes the interface to bridge to.

# UnixSocket App (apps.socket.unix)

The `UnixSocket` app provides I/O for a named Unix socket.

![UnixSocket](.images/UnixSocket.png)

## Configuration

The `UnixSocket` app takes a string argument which denotes the Unix socket
file name to open, or a table with the fields:

* `filename` - the Unix socket file name to open.
* `listen` - if `true`, listen for incoming connections on the socket
rather than connecting to the socket in client mode.
* `mode` - can be "stream" or "packet" (the default is "stream"):
the difference is that in packet mode, the packets are not split
or merged (in both modes packets arrive in order).

__NOTE__: The socket is not opened until the first call to push() or pull().
If connection is lost, the socket will be re-opened on the next call
to push() or pull().
43 changes: 31 additions & 12 deletions src/apps/socket/raw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ local packet = require("core.packet")
local ffi = require("ffi")
local C = ffi.C

--ljsyscall returns error as a a cdata instead of a string,
--and the standard assert() doesn't use tostring() on it.
local function assert(v, ...)
if not v then error(tostring(... or 'assertion failed'), 2) end
return v, ...
end

local c, t = S.c, S.types.t

RawSocket = {}
Expand All @@ -20,13 +27,17 @@ function RawSocket:new (ifname)
if not index then error(err) end

local tp = h.htons(c.ETH_P["ALL"])
local sock, err = S.socket(c.AF.PACKET, bit.bor(c.SOCK.RAW, c.SOCK.NONBLOCK), tp)
if not sock then error(err) end
local sock = assert(S.socket(c.AF.PACKET, bit.bor(c.SOCK.RAW, c.SOCK.NONBLOCK), tp))
local index, err = S.util.if_nametoindex(ifname)
if not index then
sock:close()
error(err)
end

local addr = t.sockaddr_ll{sll_family = c.AF.PACKET, sll_ifindex = index, sll_protocol = tp}
local ok, err = S.bind(sock, addr)
if not ok then
S.close(sock)
sock:close()
error(err)
end
return setmetatable({sock = sock}, {__index = RawSocket})
Expand All @@ -41,14 +52,18 @@ function RawSocket:pull ()
end

function RawSocket:can_receive ()
local ok, err = S.select({readfds = {self.sock}}, 0)
return not (err or ok.count == 0)
local t, err = S.select({readfds = {self.sock}}, 0)
while not t and (err.AGAIN or err.INTR) do
t, err = S.select({readfds = {self.sock}}, 0)
end
assert(t, err)
return t.count == 1
end

function RawSocket:receive ()
local buffer = ffi.new("uint8_t[?]", C.PACKET_PAYLOAD_SIZE)
local sz, err = S.read(self.sock, buffer, C.PACKET_PAYLOAD_SIZE)
if not sz then return err end
assert(sz, err)
return packet.from_pointer(buffer, sz)
end

Expand All @@ -63,18 +78,22 @@ function RawSocket:push ()
end

function RawSocket:can_transmit ()
local ok, err = S.select({writefds = {self.sock}}, 0)
return not (err or ok.count == 0)
local t, err = S.select({writefds = {self.sock}}, 0)
while not t and (err.AGAIN or err.INTR) do
t, err = S.select({writefds = {self.sock}}, 0)
end
assert(t, err)
return t.count == 1
end

function RawSocket:transmit (p)
local sz, err = S.write(self.sock, packet.data(p), packet.length(p))
if not sz then return err end
return sz
local sz, err = S.write(self.sock, p.data, p.length)
assert(sz, err)
assert(sz == p.length)
end

function RawSocket:stop()
S.close(self.sock)
self.sock:close()
end

function selftest ()
Expand Down
Loading

0 comments on commit 30fcbcb

Please sign in to comment.