Network Programming and Acceleration
Modern networking relies on high-performance NICs, which typically range from 10 Gbps to 100 Gbps or even more. Traditional Linux drivers, which operate in kernel space, copy packet data from kernel space to user space, thus significantly reducing system performance. To overcome this limitation, academia and industry have proposed a plethora of accelerated drivers which address this issue, eliminating packet copying by directly sharing the DMA NIC descriptor to user-space applications. However, the applications must be rewritten in large part as their code needs to be adapted to work with these frameworks (e.g., DPDK), causing kernel compatibility issues and making portability to other operating systems impossible.
Modifying legacy applications to integrate accelerated drivers to improve performance has a significant cost. Since the PCAP library was found to be both incompatible with multi-threading semantics and too slow to capture and transmit packets at line rate in high-speed networks, the is currently no easy-to-use substitute. In recent years, Linux kernel developers introduced AF_XDP, an accelerated socket, in an attempt to ease the development of fast network applications.
The performance of AF_XDP is excellent. However, its semantics is messy and boilerplate. As a consequence, the integration of such a socket is non-trivial and requires extensive low-level programming experience. Moreover, AF_XDP is available with the most recent kernels only. Programmers dealing with older Linux kernels (<5.x) must rely on pre-existing accelerated Linux drivers developed for other projects.
To reduce the amount of effort required to make legacy applications compatible with accelerated sockets, Larthia comes to programmers' aid by presenting Nethuns!
Nethuns is an open-source software library that implements a zero-cost socket-like semantics, thus simplifying the use of accelerated sockets in legacy applications. Currently, the library supports multiple accelerated sockets and makes it trivial to swap from one to another effortlessly.
To not impinge on the performance, the switch between sockets is enabled by recompiling the applications and linking different library versions.
This procedure is automagically implemented via CMAKE scripts.
No further effort is required on the programmer's side, significantly easing the development and eliminating the time and pain required to manage complex frameworks to achieve zero-copy semantics.
Nethuns is a software library written in C that provides a unified API to access and manage low-level network operations relying over underlying network I/O frameworks, and consequently operating systems. The design of Nethuns originates from the practical requirement of developing portable network applications with extremely high data rate targets. Nethuns provides a unified abstraction layer that enables programmers to implement their applications regardless of the underlying technology, as opposed to rewriting them to match the semantics of network I/O engines over various operating systems. Therefore, network applications that use the Nethuns library only need to be re-compiled to run on top of a different engine (chosen in the set of the ones available for the OS), with no need for code adaptation.
Nethuns fills the lack of a unified network abstraction in the software domain, which is instead present in the hardware domain thanks to P4. Nethuns plays a similar role to that entrusted to the PCAP library in the past. Besides, it adds support for recent technologies such as AF_XDP and concurrency. Nethuns introduces the least amount of overhead possible. This preserves the functionality and performance of the underlying native network I/O frameworks. The API exposed by Nethuns recalls the interface of traditional sockets to make its adoption immediate for network programmers.
Nethuns fully supports:
- AF_PACKET and AF_XDP sockets for fast packet handling on Linux
- the Netmap framework for fast packet I/O on Linux and FreeBSD operating systems
- the PCAP library for use in BSD, MacOS and Windows operating systems
- lock-free, cache friendly Single Producer - Single Consumer (SPSC) queues
- compile-time polymorphic ring buffers for packets
- packet capture and transmission
- VLAN support
Nethuns is freely available for download at https://github.com/larthia/nethuns