# iqiyi/dpvs architecture

> Architecture diagram of the GitHub repository iqiyi/dpvs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/iqiyi/dpvs
- Repository: https://github.com/iqiyi/dpvs

## Overview

##### Main Components
- Data Plane (DPVS Core): This is where high-speed packet processing occurs. It makes use of DPDK, and its integration is clearly visible in the “src” and “include” directories (e.g. core files for handling DPDK memory, mbuf management, RX/TX batching, etc.). Also, modules under “ipvs”, “ipset”, “ipv6”, “tc” show the implementation of load balancing algorithms (RR, WLC, WRR, MH, Conhash), connection tracking, and traffic control.
- DPDK Integration & Environment Setup: DPDK is fundamental. A distinct process for binding NIC devices using tools like dpdk-devbind.py exists, along with patch directories (patch/dpdk-24.11) where DPDK-specific modifications are applied. Hugepages and driver configurations (e.g. in the README’s “DPDK setup” section) belong here.
- Control & Management: This includes administration and runtime configuration through tools like dpip and ipvsadm. The configuration files in “conf” (with different dpvs.conf samples) and the header “conf/dpvs.conf.items” define the supported options. Also, dpvs-agent (in both “src” and “tools/dpvs-agent”) and the healthcheck components provide RESTful management and monitoring.
- Auxiliary Kernel/Interface Components: Although the DPVS engine bypasses the kernel for data path, there remain kernel modules (e.g., under “kmod”) for handling legacy KNI (or for the optional virtio-user replacement) and sample code for special modes (such as UOA).
- Testing & Documentation: The “test”, “doc”, and “tools” directories contain performance tests, sample scripts, and extensive documentation that are relevant for operational topology and system verification.

##### Relationships and Interactions
- Incoming traffic from physical NICs is bound and managed by DPDK. Packets enter the data plane of DPVS, where the core load-balancing engine (in “src”) processes the packets using various algorithms (with modules under “ipvs”, “ipset”, etc.).
- The engine interacts with its configuration (read from dpvs.conf and associated items) and receives runtime control commands via the management tools (dpip, ipvsadm, and dpvs-agent).
- The control plane (or management interfaces) provides an admin layer, enabling adjustments to the forwarding decisions (e.g., setting up VIPs, local IPs for FNAT, and adjusting algorithm parameters).
- Debugging and performance tools (found in “tools” and “test”) interface with the core to monitor and fine-tune performance.

##### Architectural Patterns
- Layer separation: There is a clear separation between the data plane (packet processing, forwarding) and the control/management plane (configuration, monitoring via REST API, command line utilities).
- Lockless / per-CPU architecture: The share‑nothing design (demonstrated by the modular, per‑CPU data structures found in “global_data”, “scheduler”, etc.) could be highlighted.
- Extensibility: The modular design (see distinct directories for ipset, ipvs, parser, etc.) illustrates a plug‑in approach for different forwarding modes and health-check mechanisms.

##### Relevant Technologies
- DPDK – basis for high-speed packet I/O and NIC binding.
- Linux networking (for hugepages, NIC configuration and kernel bypass).
- C Programming (core engine, config file parsing, and low-level packet processing)
- REST API and Golang components – in dpvs-agent for modern management.
- Tools and scripts (Makefiles, shell scripts in “scripts” and “tools”) which automate builds, dpdk patching, and configuration management.

– DPDK Libraries & Drivers (include mention of hugepages, NIC binding)
– DPVS Data Plane Engine (with sub-modules like IPVS, Traffic Control, IPset, Connection Management)
– Control & Management Plane (dpip, ipvsadm, dpvs-agent, healthcheck)
– Configuration Management (dpvs.conf and associated items)
– Auxiliary Kernel Modules (legacy KNI, kmod components)
- Labels that specify major design patterns (e.g., “Lockless per-CPU,” “Kernel bypass”) and note external dependencies (DPDK, hugepages, etc.).

##### Essential Architectural Elements
- Be as detailed as possible by drawing out each module as a distinct component where appropriate (for instance, representing the IPVS algorithm module separately from the IPset module).
- Dependencies on other systems (e.g., external REST calls via dpvs-agent, DPDK patches, build environment scripts).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware Layer
    subgraph "Hardware Layer"
        NICs("Hardware NICs"):::hardware
    end

    %% DPDK Integration & Environment Setup
    subgraph "DPDK Integration & Environment Setup"
        DPDK_Patches("DPDK Patches"):::dpdk
        DPDK_Make("DPDK Build Makefile"):::dpdk
        DPDK_Build("DPDK Build Script"):::dpdk
    end

    %% DPVS Data Plane Engine
    subgraph "DPVS Data Plane Engine"
        Core_src("DPVS Core - Source Code (uses modules: IPVS, IPset, IPv6, TC)"):::core
        Core_hdr("DPVS Core - Headers & Modules"):::core
    end

    %% Control & Management
    subgraph "Control & Management"
        Dpip("dpip Tool"):::control
        Agent("dpvs-agent"):::control
        Conf("Configuration Files"):::control
    end

    %% Auxiliary Kernel/Interface Components
    subgraph "Auxiliary Kernel Components"
        KernelModules("Kernel Modules"):::aux
        KNI("KNI Management"):::aux
    end

    %% Testing & Documentation
    subgraph "Testing & Documentation"
        Testing("Testing Tools"):::testdoc
        Docs("Documentation"):::testdoc
    end

    %% Relationships and Data Flow
    NICs --> DPDK_Patches
    DPDK_Patches --> DPDK_Make
    DPDK_Make --> DPDK_Build
    DPDK_Build --> Core_src
    Core_src --> Core_hdr
    Conf --> Core_src
    Dpip --> Core_src
    Agent --> Core_src
    Core_src --> KernelModules
    Core_hdr --> KNI
    Testing --> Core_src
    Docs --> Core_src

    %% Additional control message flow
    Dpip -->|"control"| Core_src
    Agent -->|"control"| Core_src

    %% Click Events
    click Core_src "https://github.com/iqiyi/dpvs/tree/master/src"
    click Core_hdr "https://github.com/iqiyi/dpvs/tree/master/include"
    click DPDK_Patches "https://github.com/iqiyi/dpvs/blob/master/patch/dpdk-24.11"
    click DPDK_Make "https://github.com/iqiyi/dpvs/blob/master/src/dpdk.mk"
    click DPDK_Build "https://github.com/iqiyi/dpvs/blob/master/scripts/dpdk-build.sh"
    click Dpip "https://github.com/iqiyi/dpvs/tree/master/tools/dpip"
    click Agent "https://github.com/iqiyi/dpvs/tree/master/tools/dpvs-agent"
    click Conf "https://github.com/iqiyi/dpvs/tree/master/conf"
    click KernelModules "https://github.com/iqiyi/dpvs/tree/master/kmod"
    click KNI "https://github.com/iqiyi/dpvs/blob/master/include/kni.h"
    click KNI "https://github.com/iqiyi/dpvs/blob/master/src/kni.c"
    click Testing "https://github.com/iqiyi/dpvs/tree/master/test"
    click Docs "https://github.com/iqiyi/dpvs/tree/master/doc"

    %% Styles
    classDef hardware fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef dpdk fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef core fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef control fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef aux fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef testdoc fill:#87CEEB,stroke:#000,stroke-width:2px;
```
