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:
- Compile snabbswitch to get
snabb
executable. - Compile a C callback function to a shared library e.g.
capturecallback.c
below. - Run:
sudo ./snabb snsh capture2c <pciaddress> <filename.so>
The output should look something like this:
sudo ./snabb snsh capture2c.lua 0000:01:00.0 capturecallback.so
Loading shared object: program/capture2c/capturecallback.so
Initializing NIC: 0000:01:00.0
Processing traffic...
Got packet with 64 bytes.
Got packet with 64 bytes.
Got packet with 64 bytes.
Got packet with 64 bytes.
Got packet with 64 bytes.
The program takes advantage of Lua letting Snabb Switch be scripted after it has been compiled and of the LuaJIT FFI that makes it easy for Snabb Switch to call C.
The 10G device driver is itself implemented purely in Lua by the module intel10g.lua.