# olsr/oonf architecture

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

- Interactive diagram: https://gitdiagram.com/olsr/oonf
- Repository: https://github.com/olsr/oonf

## Overview

##### Project type and purpose
- This is a C-based network routing framework and toolset (“OONF”: OLSR.org Network Framework).
- It builds several CLI network daemons (olsrd2, dlep-radio, dlep-router, etc.) plus a core library and many protocol/plugin modules (NHDP, OLSRv2, DLEP, RFC5444, etc.).
- It is not a web-app but a modular, plugin-based network protocol engine.

##### File structure
- Top-level “apps” folder: each subfolder is one executable (dlep-radio, dlep-router, olsrd2, etc.) with its own CMakeLists.
- “src” tree: broken into directories per layer:
- base (network sockets, timers, HTTP, telnet, packet sockets)
- crypto (hash/signature providers)
- generic plugins (configuration loaders, DLEP, eth-listener, remotecontrol, systeminfo, etc.)
- libcommon, libconfig, libcore, librfc5444 (core libraries)
- protocol stacks: nhdp, olsrv2 (each with sub-modules)
- main (entry point)
- tests (CUnit tests)
- “include” mirrors “src” with public headers for each lib and module.
- build infrastructure: CMakeLists.txt at root, cmake/ folder, build/ folder.
- packaging: Debian under apps/olsrd2/debian, OpenWrt under openwrt/.
- configuration templates under “configuration/”.

##### README
- Confirms it is a network daemon framework, built with CMake and plugins, producing static binaries like olsrd2_static.
- Usage instructions show: selecting interfaces, logging subsystems, enabling protocols (NHDP, DLEP).

##### Main components
a. Executable layer (apps):
– olsrd2_static, dlep-radio, dlep-router, oonf (generic app)
b. Core Framework libraries:
– libcore (application lifecycle, subsystem registry)
– libconfig (configuration parsing/validation)
– libcommon (data structures, JSON, netaddr, lists)
– librfc5444 (message parser/writer)
c. Plugin Controller (loads runtime modules)
d. Protocol/feature modules (plugins):
– NHDP (neighborhood discovery)
– OLSRv2 (routing)
– DLEP (link-status exchange; radio/router roles)
– Generic services: cfg_compact, cfg_uciloader, eth_listener, remotecontrol, systeminfo, plugin_controller
– Crypto providers (hash, signature) used by some modules
e. OS integration layer (base):
– Packet sockets, Netlink (nl80211), timers, threading primitives, HTTP/telnet interfaces
f. External interfaces:
– Network interfaces (eth0, wlan0, lo)
– Telnet/HTTP management ports (viewer)
g. Configuration subsystem: reads configuration files, provides settings to modules

##### Relationships and interactions
- Apps link statically against core libs; they call main() in libcore.
- libcore registers a “plugin controller” which loads each enabled plugin module at startup.
- Plugin modules register themselves as subsystems (protocol handlers) with libcore.
- The framework’s I/O loop (in libcore) dispatches received raw packets (via packet sockets or netlink) into librfc5444 parser. Parsed messages are routed to appropriate protocol plugin (NHDP, DLEP, OLSRv2).
- Protocol modules may invoke crypto providers or generic services (eth_listener, link_config) as needed.
- Outgoing messages are composed via librfc5444 writer and sent back out the appropriate socket.
- libconfig provides the configuration data to each plugin during initialization.
- Generic modules (remotecontrol, viewer) provide management interfaces (HTTP, telnet).
- Test suites verify each library and module in isolation.

##### Architectural patterns & design principles
- Plugin-based modular architecture: core framework + dynamically linked (or statically registered) subsystems.
- Layered design:
- Transport/OS integration layer (base)
- Message framing layer (librfc5444)
- Protocol logic layer (NHDP, OLSRv2, DLEP)
- Management layer (remotecontrol, systeminfo)
- Separation of concerns: each library (libcommon, libconfig, etc.) focuses on one domain.
- Dependency inversion: core framework depends on abstract plugin interfaces; concrete modules implement those interfaces.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Executable Layer
    subgraph "Executable Layer"
        direction TB
        dlep_radio["dlep-radio"]:::apps
        dlep_router["dlep-router"]:::apps
        olsrd2["olsrd2"]:::apps
        olsrd2_dlep["olsrd2-dlep"]:::apps
        oonf_cli["oonf CLI"]:::apps
    end

    %% Core Framework Libraries
    subgraph "Core Framework Libraries"
        direction TB
        libcore["libcore"]:::core
        libconfig["libconfig"]:::core
        libcommon["libcommon"]:::core
        librfc5444["librfc5444"]:::core
    end

    plugin_controller["Plugin Controller"]:::plugin

    %% Plugin Modules
    subgraph "Protocol & Feature Modules"
        direction TB
        subgraph "Protocol Modules"
            NHDP["NHDP"]:::plugin
            OLSRv2["OLSRv2"]:::plugin
            DLEP["DLEP"]:::plugin
        end
        subgraph "Generic Services"
            cfg_compact["cfg_compact"]:::plugin
            cfg_uciloader["cfg_uciloader"]:::plugin
            eth_listener["eth_listener"]:::plugin
            remotecontrol["remotecontrol"]:::plugin
            systeminfo["systeminfo"]:::plugin
            link_config["link_config"]:::plugin
            nl80211_listener["nl80211_listener"]:::plugin
        end
        subgraph "Crypto Providers"
            crypto["Crypto Providers"]:::plugin
        end
    end

    %% OS Integration Layer
    subgraph "OS Integration Layer (Base)"
        direction TB
        packet_socket["Packet Sockets"]:::base
        netlink["Netlink"]:::base
        timers["Timers/Threads"]:::base
        http_telnet["HTTP/Telnet"]:::base
    end

    %% External Interfaces
    subgraph "External Interfaces"
        direction TB
        net_if["Network IFs (eth0,wlan0)"]:::external
        mgmt_ports["Telnet/HTTP Ports"]:::external
    end

    %% Connections
    dlep_radio -->|links & calls API| libcore
    dlep_router -->|links & calls API| libcore
    olsrd2 -->|links & calls API| libcore
    olsrd2_dlep -->|links & calls API| libcore
    oonf_cli -->|links & calls API| libcore

    libcore -->|initializes| plugin_controller
    libconfig -->|provides config| plugin_controller
    plugin_controller -->|loads| NHDP
    plugin_controller -->|loads| OLSRv2
    plugin_controller -->|loads| DLEP
    plugin_controller -->|loads| cfg_compact
    plugin_controller -->|loads| cfg_uciloader
    plugin_controller -->|loads| eth_listener
    plugin_controller -->|loads| remotecontrol
    plugin_controller -->|loads| systeminfo
    plugin_controller -->|loads| link_config
    plugin_controller -->|loads| nl80211_listener

    NHDP -->|uses| librfc5444
    OLSRv2 -->|uses| librfc5444
    DLEP -->|uses| librfc5444
    cfg_compact -->|optional uses| crypto
    cfg_uciloader -->|optional uses| crypto

    librfc5444 -->|recv/send packets| packet_socket
    librfc5444 -->|recv/send packets| netlink
    packet_socket -->|packets| net_if
    netlink -->|events| net_if
    http_telnet -->|management| mgmt_ports
    eth_listener -->|link events| net_if

    %% Click Events
    click dlep_radio "https://github.com/olsr/oonf/blob/master/apps/dlep-radio/CMakeLists.txt"
    click dlep_router "https://github.com/olsr/oonf/blob/master/apps/dlep-router/CMakeLists.txt"
    click olsrd2 "https://github.com/olsr/oonf/blob/master/apps/olsrd2/CMakeLists.txt"
    click olsrd2_dlep "https://github.com/olsr/oonf/blob/master/apps/olsrd2-dlep/CMakeLists.txt"
    click oonf_cli "https://github.com/olsr/oonf/blob/master/apps/oonf/CMakeLists.txt"
    click libcore "https://github.com/olsr/oonf/blob/master/src/libcore/oonf_main.c"
    click libconfig "https://github.com/olsr/oonf/tree/master/src/libconfig/"
    click libcommon "https://github.com/olsr/oonf/tree/master/src/libcommon/"
    click librfc5444 "https://github.com/olsr/oonf/tree/master/src/librfc5444/"
    click plugin_controller "https://github.com/olsr/oonf/blob/master/src/generic/plugin_controller/plugin_controller.c"

    %% Styles
    classDef apps fill:#FFA500,stroke:#333,stroke-width:1px
    classDef core fill:#1E90FF,stroke:#333,stroke-width:1px
    classDef plugin fill:#32CD32,stroke:#333,stroke-width:1px
    classDef base fill:#A9A9A9,stroke:#333,stroke-width:1px
    classDef external fill:#FF4500,stroke:#333,stroke-width:1px
```
