Skip to content

Network Layer

Overview

The network layer provides high-performance, low-latency access to the Linux networking stack from raw Layer-2 frame injection to kernel-bypass DPDK drivers. All modules target sub-microsecond critical paths with zero dynamic allocation after initialization.

┌─────────────────────────────────────────────────────────────────────┐
│                        Application Layer                             │
├─────────────────────────────────────────────────────────────────────┤
│  raw_socket  │  epoll_reactor  │  zero_copy  │      dpdk           │
│  (AF_PACKET) │  (Event Loop)   │  (io_uring) │  (Userspace NIC)    │
├─────────────────────────────────────────────────────────────────────┤
│                     Linux Kernel / DPDK                              │
├─────────────────────────────────────────────────────────────────────┤
│                        NIC Hardware                                  │
└─────────────────────────────────────────────────────────────────────┘

Modules

Module Status Description Latency Target
raw_socket ✅ Implemented AF_PACKET Layer-2 frame TX/RX with PACKET_MMAP < 5 µs
epoll_reactor ✅ Implemented Single-threaded event loop with timer FD integration < 1 µs dispatch
zero_copy 🔲 Planned mmap, splice, io_uring, MSG_ZEROCOPY < 1 µs
dpdk 🔲 Planned DPDK userspace NIC poll-mode drivers < 500 ns

Architecture

graph TD
    A[Application] --> B[epoll_reactor]
    B --> C[raw_socket]
    B --> D[zero_copy]
    C --> E[AF_PACKET / PACKET_MMAP]
    D --> F[io_uring / splice]
    E --> G[NIC]
    F --> G
    H[dpdk] --> G
    style H fill:#f9f,stroke:#333,stroke-width:2px
    style D fill:#f9f,stroke:#333,stroke-width:2px

Design Principles

  1. Zero allocation after init All buffers pre-allocated at startup
  2. Single-threaded ownership No locks in the hot path; use CPU pinning + SPSC queues for cross-core transfer
  3. Batch processing Drain all ready events per syscall to amortize kernel transitions
  4. Cache-line awareness Data structures aligned to prevent false sharing
  5. Kernel bypass where possible PACKET_MMAP for Layer-2, DPDK for full bypass

Build

# Build all network modules
make -C src/network/raw_socket
make -C src/network/epoll_reactor

# Run with required capabilities
sudo setcap cap_net_raw+ep ./build/raw_socket_demo
./build/raw_socket_demo

Dependencies

Dependency Version Purpose
Linux kernel ≥ 2.6.27 epoll, timerfd, PACKET_MMAP
Linux kernel ≥ 5.1 io_uring (zero_copy module)
DPDK ≥ 22.11 Userspace NIC drivers (planned)
libcap any CAP_NET_RAW capability setting