Just for fun, here is some simple Snabb Switch example code to retransmit
every packet that is received on a set of Ethernet ports. It’s part of
the basic selftest code in
The coding style is starting to settle down lately and so it’s more
tempting for me to share little snippets of code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Reasonably easy to understand, I hope?
The features of this program that I would like to draw attention to are:
- It is written in a high-level language, LuaJIT.
- On one Xeon core it handles 12 million packets per second spread across 20 x 10GbE network ports. This loop runs in about 85 nanoseconds per packet. And there is heaps of room for optimization left, both in the single-core and multi-core contexts.
- It uses device drivers directly. The
outputobjects are each one of our drivers for Intel 1G, Intel 10G, or Virtio ethernet devices. The “buffers” are blocks of physical memory that are directly used for hardware DMA.
- It’s written in a pretty natural style and yet doesn’t need to garbage collect. The only objects being frequently allocated and freed are the packet buffers, and those are straightforwardly reference counted with
This my friends is an idea for how we could write high-speed packet networking code over the next decade or so. I hope to win you over to this way of thinking :-)