Skip to content
---- TRACE 3 start counter.lua:32
0001 TGETS 2 0 0 ; "c"
0000 . . FUNCC ; ffi.meta.__index
0002 ADDVV 2 2 1
0000 . . FUNCC ; ffi.meta.__add
0003 TSETS 2 0 0 ; "c"
0000 . . FUNCC ; ffi.meta.__newindex
0004 RET0 0 1
---- TRACE 3 IR
0001 > cdt SLOAD #1 T

This is a simple example of a low-level script that uses the Snabb Switch 82599 10G ethernet device driver directly to feed packets into a C function provided as a shared library. Written for a discussion with Pavel Odintsov.

Here is now to run it:

  1. Compile snabbswitch to get snabb executable.
  2. Compile a C callback function to a shared library e.g. capturecallback.c below.
  3. Run: sudo ./snabb snsh capture2c <pciaddress> <filename.so>

The output should look something like this:

-- tap-test.lua -- test program based on ljsyscall test code
-- Reference example code for ljsyscall here:
-- https://github.com/justincormack/ljsyscall/blob/master/test/linux.lua
-- Run via Snabb Switch like this:
-- sudo snabb snsh tap-test.lua
local syscall = require("syscall") -- ljsyscall
-- Create a new tap device
linux$ git log --graph --merges --format='%h %cn %s' | head -500
* 1113cdf Linus Torvalds: Merge tag 'nfs-for-4.1-2' of git://git.linux-nfs.org/projects/trondmy/linux-nfs
* 416716e Linus Torvalds: Merge tag 'powerpc-4.1-4' of git://git.kernel.org/pub/scm/linux/kernel/git/mpe/linux
* 68465bb Linus Torvalds: Merge tag 'pwm/for-4.1-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/thierry.reding/linux-pwm
* 7cf7d42 Linus Torvalds: Merge tag 'for-linus-20150516' of git://git.infradead.org/linux-mtd
* c0655fe Linus Torvalds: Merge tag 'usb-4.1-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
|\
| * 5691926 Greg Kroah-Hartman: Merge tag 'usb-serial-4.1-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial into usb-linus
| * 17aeca1 Greg Kroah-Hartman: Merge tag 'usb-ci-v4.1-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb into usb-linus
| * 99c605a Greg Kroah-Hartman: Merge tag 'fixes-for-v4.1-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi/us
-- Return three values:
-- valid - is the header checksum valid (always true for IPv6)
-- offset - where the inner checksum starts, or nil if no more to checksum
-- initial - initial value for inner checksum ("pseudo header checksum")
function check_header (p)
if is_ipv4(p) then
-- check header checksum;
-- find start of tcp/udp header;
-- calculate pseudo header checksum
elseif is_ipv6(p) then
diff --git a/src/apps/solarflare/solarflare.lua b/src/apps/solarflare/solarflare.lua
index 5aeddde..7944815 100644
--- a/src/apps/solarflare/solarflare.lua
+++ b/src/apps/solarflare/solarflare.lua
@@ -82,7 +82,7 @@ function SolarFlareNic:flush_receives(id)
end
function SolarFlareNic:enqueue_transmit(p)
- assert(not self.tx_packets[self.tx_id], "tx buffer overrun")
+-- assert(self.tx_packets[self.tx_id] ~= nil, "tx buffer overrun")
LINK snabb
Firmware: 936K snabb
selftest: intel_app
Running iterated VMDq test...
never got link up: 0000:01:00.0
test # 1: VMDq VLAN=101; 100ms burst. packet sent: 206,040
test # 2: VMDq VLAN=102; 100ms burst. packet sent: 229,755
test # 3: VMDq VLAN=103; 100ms burst. packet sent: 226,950
test # 4: VMDq VLAN=104; 100ms burst. packet sent: 225,420

This error:

Invalid DMA address: 0x5002e0925a00
core/memory.lua:95: DMA address tag check failed

is reported by this function:

/*-
* BSD LICENSE
*
* Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
00000000004026e1 <rte_memcpy_wrapped_in_function>:
4026e1: 55 push %rbp
4026e2: 48 89 e5 mov %rsp,%rbp
4026e5: 48 81 ec d0 14 00 00 sub $0x14d0,%rsp
4026ec: 48 89 bd 48 eb ff ff mov %rdi,-0x14b8(%rbp)
4026f3: 48 89 b5 40 eb ff ff mov %rsi,-0x14c0(%rbp)
4026fa: 89 95 3c eb ff ff mov %edx,-0x14c4(%rbp)
402700: 8b 85 3c eb ff ff mov -0x14c4(%rbp),%eax
402706: 48 98 cltq
402708: 48 8b 95 48 eb ff ff mov -0x14b8(%rbp),%rdx
Something went wrong with that request. Please try again.