Skip to content

Commit

Permalink
Merge pull request #432 from lukego/integrate-march2015-3
Browse files Browse the repository at this point in the history
Collection of PRs to master
  • Loading branch information
lukego committed Mar 27, 2015
2 parents c82edb6 + 4265fc6 commit 08728d5
Show file tree
Hide file tree
Showing 23 changed files with 381 additions and 163 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -106,4 +106,4 @@ Github pull requests. Report bugs with Github issues.

### Benchmark Results

[![Benchmark Results](http://lab1.snabb.co:2008/~max/benchmarks.png)](https://travis-ci.org/SnabbCo/snabbswitch.svg?branch=master)
[![Benchmark Results](http://lab1.snabb.co:2008/~max/benchmarks.png)](http://lab1.snabb.co:2008/~max/benchmarks.png)
2 changes: 1 addition & 1 deletion src/README.md
Expand Up @@ -67,7 +67,7 @@ to parse *arg*.

— Field **myapp.input**

— Field **app.output**
— Field **myapp.output**

Tables of named input and output links. These tables are initialized by
the engine for use in processing and are *read-only*.
Expand Down
2 changes: 1 addition & 1 deletion src/README.md.src
Expand Up @@ -83,7 +83,7 @@ to parse *arg*.

— Field **myapp.input**

— Field **app.output**
— Field **myapp.output**

Tables of named input and output links. These tables are initialized by
the engine for use in processing and are *read-only*.
Expand Down
56 changes: 54 additions & 2 deletions src/apps/intel/intel10g.lua
Expand Up @@ -15,13 +15,20 @@ local pci = require("lib.hardware.pci")
local register = require("lib.hardware.register")
local index_set = require("lib.index_set")
local macaddress = require("lib.macaddress")
local mib = require("lib.ipc.shmem.mib")
local timer = require("core.timer")

local bits, bitset = lib.bits, lib.bitset
local band, bor, lshift = bit.band, bit.bor, bit.lshift

num_descriptors = 512
--num_descriptors = 32

-- Set to true to enable IF-MIB support via the ipc/shmem mechanism
enable_snmp = false
-- Timer for interface status check in seconds (only active when
-- enable_snmp=true)
status_timer = 5

local function pass (...) return ... end

Expand Down Expand Up @@ -49,7 +56,6 @@ function new_sf (pciaddress)
return setmetatable(dev, M_sf)
end


function M_sf:open ()
pci.unbind_device_from_linux(self.pciaddress)
pci.set_bus_master(self.pciaddress, true)
Expand Down Expand Up @@ -82,7 +88,10 @@ end
--- See data sheet section 4.6.3 "Initialization Sequence."

function M_sf:init ()
self :init_dma_memory()
if enable_snmp then
self:init_snmp()
end
self:init_dma_memory()

self.redos = 0
local mask = bits{Link_up=30}
Expand Down Expand Up @@ -145,6 +154,45 @@ do
end
end

function M_sf:init_snmp ()
-- Rudimentary population of a row in the ifTable MIB. Allocation
-- of the ifIndex is delegated to the SNMP agent via the name of
-- the interface in ifDescr (currently the PCI address).
local ifTable = mib:new({ filename = self.pciaddress })
ifTable:register('ifDescr', 'OctetStr', self.pciaddress)
ifTable:register('ifAdminStatus', 'Integer32', 1) -- up
ifTable:register('ifOperStatus', 'Integer32', 2) -- down
ifTable:register('ifLastChange', 'TimeTicks', 0)
ifTable:register('_X_ifLastChange_TicksBase', 'Counter64', C.get_unix_time())
ifTable:register('ifType', 'Integer32', 6) -- ethernetCsmacd
ifTable:register('ifSpeed', 'Gauge32', 10000000)

-- Create a timer to periodically check the interface status. The
-- default interval is 5 seconds, defined by the status_timer
-- variable.
local status = { [1] = 'up', [2] = 'down' }
local mask = bits{Link_up=30}
local t = timer.new("Interface "..self.pciaddress.." status checker",
function(t)
local old = ifTable:get('ifOperStatus')
local new = 1
if band(self.r.LINKS(), mask) ~= mask then
new = 2
end
if old ~= new then
print("Interface "..self.pciaddress..
" status change: "..status[old]..
" => "..status[new])
ifTable:set('ifOperStatus', new)
ifTable:set('ifLastChange', 0)
ifTable:set('_X_ifLastChange_TicksBase',
C.get_unix_time())
end
end, 1e9 * status_timer, 'repeating')
timer.activate(t)
return self
end

function M_sf:global_reset ()
local reset = bits{LinkReset=3, DeviceReset=26}
self.r.CTRL(reset)
Expand Down Expand Up @@ -447,6 +495,9 @@ function M_pf:close()
end

function M_pf:init ()
if enable_snmp then
self:init_snmp()
end
self.redos = 0
local mask = bits{Link_up=30}
for i = 1, 100 do
Expand All @@ -472,6 +523,7 @@ function M_pf:init ()
return self
end

M_pf.init_snmp = M_sf.init_snmp
M_pf.global_reset = M_sf.global_reset
M_pf.disable_interrupts = M_sf.disable_interrupts
M_pf.set_receive_descriptors = pass
Expand Down
41 changes: 26 additions & 15 deletions src/apps/ipv6/nd_light.lua
Expand Up @@ -183,13 +183,21 @@ function nd_light:new (arg)
sna.eth, sna.ipv6, sna.icmp = unpack(dgram:stack())
sna.dgram = dgram
o._sna = sna

-- Caches for for various cdata pointer objects to avoid boxing in
-- the push() loop
o._cache = {
p = ffi.new("struct packet *[1]"),
mem = ffi.new("uint8_t *[1]")
}
return o
end

-- Process neighbor solicitation
local function ns (self, dgram, eth, ipv6, icmp)
local payload, length = dgram:payload()
if not icmp:checksum_check(payload, length, ipv6) then
local mem, length = self._cache.mem
mem[0], length = dgram:payload()
if not icmp:checksum_check(mem[0], length, ipv6) then
print(self:name()..": bad icmp checksum")
return nil
end
Expand All @@ -209,8 +217,8 @@ local function ns (self, dgram, eth, ipv6, icmp)
sna.ipv6:dst(ipv6:src())
-- The payload of the pre-fabricated packet consists of the NA and
-- target ll-option
local mem, length = sna.dgram:payload()
sna.icmp:checksum(mem, length, sna.ipv6)
mem[0], length = sna.dgram:payload()
sna.icmp:checksum(mem[0], length, sna.ipv6)
return true
end

Expand All @@ -237,10 +245,10 @@ local function na (self, dgram, eth, ipv6, icmp)
end

local function from_south (self, p)
if not self._filter:match(packet.data(p), packet.length(p)) then
if not self._filter:match(packet.data(p[0]), packet.length(p[0])) then
return false
end
local dgram = datagram:new(p, ethernet)
local dgram = datagram:new(p[0], ethernet)
-- Parse the ethernet, ipv6 amd icmp headers
dgram:parse_n(3)
local eth, ipv6, icmp = unpack(dgram:stack())
Expand All @@ -264,22 +272,24 @@ function nd_light:push ()
self._next_hop.timer_cb()
end

local cache = self._cache
local l_in = self.input.south
local l_out = self.output.north
local l_reply = self.output.south
while not link.empty(l_in) and not link.full(l_out) do
local p = link.receive(l_in)
local p = cache.p
p[0] = link.receive(l_in)
local status = from_south(self, p)
if status == nil then
-- Discard
packet.free(p)
packet.free(p[0])
elseif status == true then
-- Send NA back south
packet.free(p)
packet.free(p[0])
link.transmit(l_reply, packet.clone(self._sna.packet))
else
-- Send transit traffic up north
link.transmit(l_out, p)
link.transmit(l_out, p[0])
end
end

Expand All @@ -291,11 +301,12 @@ function nd_light:push ()
-- has completed.
packet.free(link.receive(l_in))
else
local p = link.receive(l_in)
if packet.length(p) >= self._eth_header:sizeof() then
self._eth_header:copy(packet.data(p))
link.transmit(l_out, p)
else packet.free(p) end
local p = cache.p
p[0] = link.receive(l_in)
if packet.length(p[0]) >= self._eth_header:sizeof() then
self._eth_header:copy(packet.data(p[0]))
link.transmit(l_out, p[0])
else packet.free(p[0]) end
end
end
end
Expand Down
11 changes: 8 additions & 3 deletions src/apps/packet_filter/README.md
Expand Up @@ -3,7 +3,12 @@
The `PacketFilter` app receives packets on the `input` port and transmits
conforming packets to the `output` port. In order to conform, a packet
must match at least one of the *filter rules* of the `PacketFilter`
instance and/or belong to a sanctioned connection.
instance and/or belong to a *sanctioned connection*. For a connection to
be sanctioned it must be tracked in a *connection table* by a
`PacketFilter` app using the `state_track` operators. All `PacketFilter`
apps share a global namespace of *connection table identifiers*. Multiple
`PacketFilter` apps—e.g. for inbound and outbound traffic—can refer to
the same connection by sharing a connection table identifer.

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

Expand All @@ -14,13 +19,13 @@ following keys are available:

— Key **rules**

*Required*. A list of filter rules as described in the *Filter Rules*
*Required*. An array of filter rules as described in the *Filter Rules*
section below.

— Key **state_track**

*Optional*. A string naming a connection table. If set, packets passing
_any_ rule will be tracked in the specified connection table.
*any* rule will be tracked in the specified connection table.

— Key **state_check**

Expand Down
11 changes: 8 additions & 3 deletions src/apps/packet_filter/README.md.src
Expand Up @@ -3,7 +3,12 @@
The `PacketFilter` app receives packets on the `input` port and transmits
conforming packets to the `output` port. In order to conform, a packet
must match at least one of the *filter rules* of the `PacketFilter`
instance and/or belong to a sanctioned connection.
instance and/or belong to a *sanctioned connection*. For a connection to
be sanctioned it must be tracked in a *connection table* by a
`PacketFilter` app using the `state_track` operators. All `PacketFilter`
apps share a global namespace of *connection table identifiers*. Multiple
`PacketFilter` apps—e.g. for inbound and outbound traffic—can refer to
the same connection by sharing a connection table identifer.

DIAGRAM: PacketFilter
+--------------+
Expand All @@ -19,13 +24,13 @@ following keys are available:

— Key **rules**

*Required*. A list of filter rules as described in the *Filter Rules*
*Required*. An array of filter rules as described in the *Filter Rules*
section below.

— Key **state_track**

*Optional*. A string naming a connection table. If set, packets passing
_any_ rule will be tracked in the specified connection table.
*any* rule will be tracked in the specified connection table.

— Key **state_check**

Expand Down
Binary file added src/apps/solarflare/.images/Solarflare.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions src/apps/solarflare/README.md
@@ -0,0 +1,29 @@
# Solarflare Ethernet Controller Apps

## Solarflare (apps.solarflare.solarflare)

The `Solarflare` app drives one port of a Solarflare SFN7 Ethernet
controller. Packets taken from the `rx` port are transmitted onto the
network. Packets received from the network are put on the `tx` port.

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

### Configuration

The `Solarflare` app accepts a table as its configuration argument. The
following keys are defined:

— Key **pciaddr**

*Required*. The PCI address of the NIC as a string.

— Key **macaddr**

*Optional*. The MAC address to use as a string. The default is a
wild-card (e.g. accept all packets).

— Key **vlan**

*Optional*. A twelve bit integer (0-4095). If set, incoming packets from
other VLANs are dropped and outgoing packets are tagged with a VLAN
header.
34 changes: 34 additions & 0 deletions src/apps/solarflare/README.md.src
@@ -0,0 +1,34 @@
# Solarflare Ethernet Controller Apps

## Solarflare (apps.solarflare.solarflare)

The `Solarflare` app drives one port of a Solarflare SFN7 Ethernet
controller. Packets taken from the `rx` port are transmitted onto the
network. Packets received from the network are put on the `tx` port.

DIAGRAM: Solarflare
+------------+
| |
rx ---->* Solarflare *----> tx
| |
+------------+

### Configuration

The `Solarflare` app accepts a table as its configuration argument. The
following keys are defined:

— Key **pciaddr**

*Required*. The PCI address of the NIC as a string.

— Key **macaddr**

*Optional*. The MAC address to use as a string. The default is a
wild-card (e.g. accept all packets).

— Key **vlan**

*Optional*. A twelve bit integer (0-4095). If set, incoming packets from
other VLANs are dropped and outgoing packets are tagged with a VLAN
header.
1 change: 1 addition & 0 deletions src/core/app.lua
Expand Up @@ -52,6 +52,7 @@ end

-- Restart dead apps.
function restart_dead_apps ()
if not use_restart then return end
local restart_delay = 2 -- seconds
local actions = { start={}, restart={}, reconfig={}, keep={}, stop={} }
local restart = false
Expand Down
2 changes: 2 additions & 0 deletions src/doc/genbook.sh
Expand Up @@ -35,6 +35,8 @@ $(cat ../apps/README.md)
$(cat ../apps/intel/README.md)
$(cat ../apps/solarflare/README.md)
$(cat ../apps/rate_limiter/README.md)
$(cat ../apps/packet_filter/README.md)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ipc/shmem/shmem.lua
Expand Up @@ -120,7 +120,7 @@ shmem._namespace = "default:1"
shmem._fs = ':'

local defaults = {
directory = '/tmp/snabb-shmem',
directory = '/tmp',
}

---- Class methods
Expand Down
Binary file modified src/lib/protocol/.images/Datagram.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 08728d5

Please sign in to comment.