# hpcn-uam/dpdk2disk architecture

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

- Interactive diagram: https://gitdiagram.com/hpcn-uam/dpdk2disk
- Repository: https://github.com/hpcn-uam/dpdk2disk

## Overview

##### Project Type and Purpose
- This is an open‑source, command‑line packet‑capture tool built in C, using DPDK for zero‑copy high‑speed packet I/O.
- Its sole purpose is to receive network packets at line rate (tested up to 40 Gbps) and dump them in PCAP format to a disk array.

##### File Structure
Top‑level items:
- dpdk/          ← DPDK submodule (Environment Abstraction Layer, PMDs, EAL)
- scripts/       ← Example shell scripts to kick off capture
- src/           ← Application source code
– Makefile
– main.c, init.c, runtime.c, config.c, external.c, hdd.c, …
– hptimelib/ (high‑precision timestamp library)
– pcap_wrap.h (wrapper for PCAP file format)
– test/ (unit or integration tests)

Key observations:
- All logic resides in src/, following a roughly modular structure: initialization, runtime core loop, disk writer, external modules, timestamp library.
- No GUI or web frontend—pure CLI tool.
- Scripts orchestrate build and run: capture0.sh sets up DPDK environment variables and starts the binary.

##### README for Further Insights
- Confirms DPDK version is vendored in dpdk/ (or can be pointed to externally via RTE_SDK).
- Build steps: dpdk-setup.sh for DPDK, Makefile in src/ for the app.
- Execution: capture0.sh <outputFolder> [MaxFileSize]

##### Main Components
a. DPDK Environment (dpdk/)
– EAL initialization
– PMD drivers for NIC ports
– Memory pools for packet buffers
b. Application Core (src/)
– Configuration Loader (config.c)
– Initialization Module (init.c)
– Runtime Packet Loop (runtime.c)
– External Interface (external.c / external.h)
– High‑Precision Timestamp Library (hptimelib / hptl.c)
– HDD/PCAP Writer (hdd.c / pcap_wrap.h)
c. Host OS and Disk Array
d. Control Scripts (scripts/capture0.sh)

##### Architectural Patterns & Principles
- Modular C code with clear separation of concerns: init, runtime, I/O, external modules.
- Zero‑copy packet processing via DPDK EAL and mbuf pools.
- Pluggable timestamp library (hptl), external interface for future extensions.

##### Relevant Technologies / Frameworks
- DPDK (Data Plane Development Kit) for user‑space packet I/O
- POSIX Shell for scripts
- Standard C and Makefile for build

##### Essential Elements Checklist
– Clear component labels
– Layered grouping: Scripts → Application → DPDK → Hardware

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Control Scripts
    subgraph "Control Scripts"
        direction TB
        Scripts["capture0.sh"]:::scripts
    end

    %% Application Layer
    subgraph "Application (src/)"
        direction TB

        %% Build System
        Makefile["Makefile"]:::core

        %% Entry Point
        MainC["main.c"]:::core
        MainH["main.h"]:::core

        %% Modules
        Config["config.c"]:::core
        Init["init.c"]:::core
        Runtime["runtime.c"]:::core
        ExternalC["external.c"]:::core
        ExternalH["external.h"]:::core

        %% Timestamp Library
        subgraph "High-Precision Timestamp Library"
            direction TB
            HPTELib["hptimelib/"]:::externalDep
            HPTLcoreC["hptl.c"]:::externalDep
            HPTLcoreH["hptl.h"]:::externalDep
            HPTLcfg["hptl_config.h"]:::externalDep
            HPTLdepC["hptl_deprecated.c"]:::externalDep
            HPTLdepH["hptl_deprecated.h"]:::externalDep
        end

        %% Disk/PCAP Writer
        subgraph "HDD/PCAP Writer"
            direction TB
            HDD["hdd.c"]:::core
            PCAP["pcap_wrap.h"]:::core
        end

        %% Tests
        Test["test/"]:::core
    end

    %% DPDK Environment
    subgraph "DPDK Environment"
        direction TB
        DPDK["dpdk/"]:::externalDep
    end

    %% Hardware / OS
    subgraph "Hardware / OS"
        direction TB
        NIC["NIC"]:::hw
        MemPools["Memory Pools"]:::hw
        Disk["Disk Array"]:::hw
    end

    %% Data & Control Flows
    Scripts -->|"launches EAL + binary"| MainC
    MainC -->|loads| Config
    MainC -->|calls| Init
    Init -->|initializes EAL| DPDK
    DPDK -->|allocates mbufs| MemPools
    MemPools -->|provides packets| Runtime
    Runtime -->|injects timestamps| HPTLcoreC
    Runtime -->|writes frames| HDD
    HDD -->|pcap frames| Disk
    Runtime -->|uses| ExternalC
    Config -->|provides parameters| Init
    Config -->|provides parameters| Runtime
    Config -->|provides parameters| ExternalC
    Config -->|provides parameters| HDD
    Test -->|executes| MainC

    %% Click Events
    click DPDK "https://github.com/hpcn-uam/dpdk2disk/tree/master/dpdk/"
    click Scripts "https://github.com/hpcn-uam/dpdk2disk/blob/master/scripts/capture0.sh"
    click Makefile "https://github.com/hpcn-uam/dpdk2disk/tree/master/src/Makefile"
    click MainC "https://github.com/hpcn-uam/dpdk2disk/blob/master/src/main.c"
    click MainH "https://github.com/hpcn-uam/dpdk2disk/blob/master/src/main.h"
    click Config "https://github.com/hpcn-uam/dpdk2disk/blob/master/src/config.c"
    click Init "https://github.com/hpcn-uam/dpdk2disk/blob/master/src/init.c"
    click Runtime "https://github.com/hpcn-uam/dpdk2disk/blob/master/src/runtime.c"
    click ExternalC "https://github.com/hpcn-uam/dpdk2disk/blob/master/src/external.c"
    click ExternalH "https://github.com/hpcn-uam/dpdk2disk/blob/master/src/external.h"
    click HPTELib "https://github.com/hpcn-uam/dpdk2disk/tree/master/src/hptimelib/"
    click HPTLcoreC "https://github.com/hpcn-uam/dpdk2disk/blob/master/src/hptl.c"
    click HPTLcoreH "https://github.com/hpcn-uam/dpdk2disk/blob/master/src/hptl.h"
    click HPTLcfg "https://github.com/hpcn-uam/dpdk2disk/blob/master/src/hptl_config.h"
    click HPTLdepC "https://github.com/hpcn-uam/dpdk2disk/blob/master/src/hptl_deprecated.c"
    click HPTLdepH "https://github.com/hpcn-uam/dpdk2disk/blob/master/src/hptl_deprecated.h"
    click HDD "https://github.com/hpcn-uam/dpdk2disk/blob/master/src/hdd.c"
    click PCAP "https://github.com/hpcn-uam/dpdk2disk/blob/master/src/pcap_wrap.h"
    click Test "https://github.com/hpcn-uam/dpdk2disk/tree/master/src/test/"

    %% Styles
    classDef core fill:#cce5ff,stroke:#004085,color:#004085
    classDef externalDep fill:#d4edda,stroke:#155724,color:#155724
    classDef scripts fill:#ffe5b4,stroke:#cc8400,color:#cc8400
    classDef hw fill:#e2e3e5,stroke:#6c757d,color:#6c757d
```
