How pktgen/pktgen-dpdk works
Project Type and Purpose
• This is a high-performance, DPDK-powered traffic generator (“Pktgen”) written in C with an embedded Lua shell and a Python helper script (tools/run.py).
• It is not a web app but a CLI/networking tool comprising:
• Core packet-generation engine (app)
• Modular C libraries (lib/cli, lib/common, lib/lua, etc.)
• Scripting control (Lua + Python)
• Configuration files (in cfg/)
Key Top-Level Components
• app/ → main DPDK application (pktgen)
• lib/ → shared modules (CLI frontend, common utilities, Lua bindings, plugins)
• cfg/ → user configurations for interfaces, cores, themes
• tools/run.py → Python wrapper to set up and launch pktgen with configs
• test/, examples/ → test scripts and sample code
• doc/ → documentation and Doxygen sources
Main Architectural Blocks
A. Packet Generator Engine (app/pktgen-*.c)
• Initializes DPDK EAL, allocates hugepages, binds PMDs
• Spawns per-port threads to generate/receive packets
• Implements multiple protocols (ARP, IPv4, TCP, UDP, etc.) via pktgen-*.c modules
B. CLI & Display Layer
• lib/cli provides line-editing, commands, autocomplete, history
• pktgen-display.c drives the terminal UI
C. Lua Scripting Layer
• Embedded Lua interpreter (lib/lua) exposes C API (lua_dapi, lua_dpdk, lua_pktmbuf, etc.)
• TCP control socket on port 22022 for remote scripting
D. Configuration Loader
• Python script tools/run.py reads cfg/*.cfg, sets up DPDK ports/cores, invokes app/pktgen with arguments
• In-app loader parses .cfg variables or external Lua scripts
E. Supporting Libraries
• lib/common – checksum, core info, port config, string utilities
• lib/utils – JSON, port lists, heap, IP parsing
• lib/hmap, lib/vec – data structures
• lib/plugin – plugin interface
F. External Interfaces
• Ethernet NICs via DPDK Poll Mode Drivers (PMDs)
• Remote TCP socket (Lua shell)
• Local terminal (CLI UI)
G. Documentation / Build / CI
• Meson build scripts (root meson.build, app/meson.build, etc.)
• GitHub Actions for lint/docs
Relationships and Data Flows
• Tools/run.py → (executes) → app/pktgen with CLI arguments & cfg files
• app/pktgen ↔ DPDK EAL ↔ NIC PMDs (data plane traffic)
• app/pktgen → lib/common, lib/utils, lib/cli for helper functions
• app/pktgen ↔ lib/lua for scripting commands
• External user → TCP socket → Lua shell → C API → packet engine
• CLI UI input → lib/cli → pktgen commands → modify generator state
Architectural Patterns & Design Principles
• Modular layering: core engine, CLI front-end, scripting API
• Plugin/extension points via lib/plugin and Lua hooks
• Separation of control plane (CLI/Lua/config) from data plane (DPDK packet loops)
• Build-time configuration using Meson