# nvidia/nsmd architecture

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

- Interactive diagram: https://gitdiagram.com/nvidia/nsmd
- Repository: https://github.com/nvidia/nsmd

## Overview

##### Project type and purpose
- This is a system-level management suite for Nvidia hardware on a BMC (Baseboard Management Controller).
- It consists of three main binaries:
– nsmd: the long-running daemon that discovers NSM endpoints over MCTP, gathers telemetry, and publishes via D-Bus.
– nsmtool: a CLI requester that sends NSM commands, receives responses, and formats them for human consumption.
– nsmMockupResponder: a mock endpoint for development/testing that simulates NSM hardware over a UNIX socket.

##### File structure
- Top-level directories:
– common: shared C++ utilities (coroutines, logging, timers, DBus helpers).
– libnsm: a C library implementing PLDM-over-MCTP commands (device discovery, configuration, diagnostics, firmware utils).
– requester: helpers for building and managing MCTP requests/timeouts.
– nsmd: the main daemon broken into many modules (deviceManager, eventManager, sensorManager, plus per-feature subdirectories like nsmChassis, nsmNumericSensor, etc.).
– nsmtool: the command-line client.
– mockupResponder: a test daemon that implements/responds to NSM requests for emulated endpoints.
– services: D-Bus service files.
– subprojects: vendored dependencies (sdbusplus, phosphor-logging, etc.).
– tools: offline JSON/XLSX processors for sensor/port topology and correlation.
– tracepoints: eBPF/tracing instrumentation.

##### README for additional insights
- Describes build via Meson/Ninja.
- Emphasizes the three artifacts and their role.
- Mentions D-Bus interfaces (sdbusplus) for publishing telemetry.
- Highlights MCTP-PLDM as underlying transport.

##### Main components & relationships
a. Components
1. CLI Client (nsmtool)
2. Daemon (nsmd), which itself contains:
– Core managers (deviceManager, eventManager, sensorManager, asyncOperationManager)
– Feature plugins (nsmChassis, nsmNumericSensor, nsmEvent, nsmFirmwareUtils, etc.)
– IPC handlers (socket_handler for MCTP demux, responder_handler for DBus introspection)
– Shared libraries: common (C++ utilities), libnsm (PLDM-over-MCTP logic), requester (MCTP endpoint)
– Systemd service file (services/nsmd.service)
3. Mockup Responder (nsmMockupResponder)
4. Underlying transports:
– MCTP control daemon & demux over UNIX socket
– sdbusplus-based D-Bus for publishing telemetry & control
5. Consumers
– bmcweb or other D-Bus subscribers

b. Interactions
– nsmtool sends a request over the MCTP socket → nsmd’s socket_handler demuxes it → it goes through requester/libnsm → feature modules handle it → nsmd writes back via socket → nsmtool prints it.
– nsmd periodically polls endpoints (via libnsm PLDM commands) → sensorManager aggregates results → publishes properties over D-Bus → external consumers (bmcweb) read them.
– mockupResponder binds to the same MCTP socket for development → responds to PLDM commands with prerecorded JSON chassis definitions.

c. Architectural patterns / design principles
– Modular plugin architecture: each NSM feature lives in its own directory with its own Meson target and tests.
– Layered IPC: transport (MCTP), protocol (PLDM in libnsm), business logic (nsmd modules), presentation (D-Bus interfaces).
– Test-driven: nearly every module has a corresponding test directory.
– Shared utilities for concurrency (common/coroutineSemaphore.hpp), timing, and logging.

d. Key technologies / frameworks
– Meson + Ninja for builds
– CMake-style module separation by Meson subdirectories
– sdbusplus (D-Bus binding)
– MCTP over UNIX domain sockets
– PLDM command library (libnsm)
– C++17 concurrency primitives
– Systemd service file for daemon management

##### Detailed capture
- Drill into one feature module (e.g., nsmNumericSensor):
– Show how sensorManager invokes the factory (nsmNumericSensorFactory) → individual sensors → aggregator → D-Bus.
- Build dependencies:
– subprojects → common/libnsm → nsmd/nsmtool/mockupResponder.
- Call out test harnesses:

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Clients"
        nsmtool["nsmtool CLI"]:::binary
    end

    subgraph "Daemons"
        nsmd["nsmd Daemon"]:::binary
        mockupResponder["nsmMockupResponder"]:::binary
    end

    subgraph "Shared Libraries"
        common["common"]:::lib
        libnsm["libnsm"]:::lib
        requester["requester"]:::lib
    end

    subgraph "nsmd Daemon Layers"
        subgraph "Transport & IPC"
            socketHandler["socket_handler"]:::transport
            responderHandler["responder_handler"]:::transport
        end
        subgraph "Protocol & Request Router"
            requesterProto["requester"]:::protocol
            libnsmProto["libnsm"]:::protocol
        end
        subgraph "Managers"
            deviceManager["deviceManager"]:::logic
            eventManager["eventManager"]:::logic
            sensorManager["sensorManager"]:::logic
            asyncOpManager["asyncOperationManager"]:::logic
        end
        subgraph "Feature Plugins"
            nsmChassisPlugin["nsmChassis Plugin"]:::logic
            nsmNumericPlugin["nsmNumericSensor Plugin"]:::logic
            nsmFirmwarePlugin["nsmFirmwareUtils Plugin"]:::logic
        end
        subgraph "Presentation"
            dbusPublisher["D-Bus Publisher"]:::logic
        end
    end

    subgraph "External Systems"
        hardwareEndpoints(("NSM Hardware Endpoints")):::external
        dbusBus(("D-Bus Bus")):::external
        bmcweb(("bmcweb D-Bus Subscriber")):::external
    end

    nsmtool -->|"PLDM command"| socketHandler
    mockupResponder -.->|"PLDM command"| socketHandler
    socketHandler --> requester
    requester --> libnsm
    libnsm --> nsmChassisPlugin
    libnsm --> nsmNumericPlugin
    libnsm --> nsmFirmwarePlugin
    nsmChassisPlugin --> sensorManager
    nsmNumericPlugin --> sensorManager
    nsmFirmwarePlugin --> sensorManager
    sensorManager --> dbusPublisher
    dbusPublisher -.->|"D-Bus property update"| dbusBus
    dbusBus --> bmcweb
    libnsm -->|"PLDM over MCTP"| hardwareEndpoints

    click nsmd "https://github.com/nvidia/nsmd/blob/develop/nsmd/nsmd.cpp"
    click deviceManager "https://github.com/nvidia/nsmd/blob/develop/nsmd/deviceManager.cpp"
    click deviceManager "https://github.com/nvidia/nsmd/blob/develop/nsmd/deviceManager.hpp"
    click eventManager "https://github.com/nvidia/nsmd/blob/develop/nsmd/eventManager.hpp"
    click eventManager "https://github.com/nvidia/nsmd/blob/develop/nsmd/eventTypeHandlers.cpp"
    click sensorManager "https://github.com/nvidia/nsmd/blob/develop/nsmd/sensorManager.cpp"
    click sensorManager "https://github.com/nvidia/nsmd/blob/develop/nsmd/sensorManager.hpp"
    click asyncOpManager "https://github.com/nvidia/nsmd/blob/develop/nsmd/nsmSetAsync/asyncOperationManager.cpp"
    click asyncOpManager "https://github.com/nvidia/nsmd/blob/develop/nsmd/nsmSetAsync/asyncOperationManager.hpp"
    click nsmChassisPlugin "https://github.com/nvidia/nsmd/blob/develop/nsmd/nsmChassis/meson.build"
    click nsmChassisPlugin "https://github.com/nvidia/nsmd/blob/develop/nsmd/nsmChassis/nsmChassis.cpp"
    click nsmChassisPlugin "https://github.com/nvidia/nsmd/blob/develop/nsmd/nsmChassis/nsmChassis.hpp"
    click nsmNumericPlugin "https://github.com/nvidia/nsmd/blob/develop/nsmd/nsmNumericSensor/meson.build"
    click nsmNumericPlugin "https://github.com/nvidia/nsmd/blob/develop/nsmd/nsmNumericSensor/nsmNumericSensor.cpp"
    click nsmNumericPlugin "https://github.com/nvidia/nsmd/blob/develop/nsmd/nsmNumericSensor/nsmNumericSensor.hpp"
    click nsmFirmwarePlugin "https://github.com/nvidia/nsmd/blob/develop/nsmd/nsmFirmwareUtils/meson.build"
    click nsmFirmwarePlugin "https://github.com/nvidia/nsmd/blob/develop/nsmd/nsmFirmwareUtils/nsmFirmwareSlot.cpp"
    click nsmFirmwarePlugin "https://github.com/nvidia/nsmd/blob/develop/nsmd/nsmFirmwareUtils/nsmKeyMgmt.cpp"
    click socketHandler "https://github.com/nvidia/nsmd/blob/develop/nsmd/socket_handler.cpp"
    click socketHandler "https://github.com/nvidia/nsmd/blob/develop/nsmd/socket_handler.hpp"
    click responderHandler "https://github.com/nvidia/nsmd/blob/develop/nsmd/responder_handler.hpp"
    click common "https://github.com/nvidia/nsmd/blob/develop/common/coroutine.hpp"
    click common "https://github.com/nvidia/nsmd/blob/develop/common/log.hpp"
    click common "https://github.com/nvidia/nsmd/blob/develop/common/dBusAsyncUtils.hpp"
    click libnsm "https://github.com/nvidia/nsmd/blob/develop/libnsm/base.c"
    click libnsm "https://github.com/nvidia/nsmd/blob/develop/libnsm/device-configuration.c"
    click libnsm "https://github.com/nvidia/nsmd/blob/develop/libnsm/firmware-utils.c"
    click requester "https://github.com/nvidia/nsmd/blob/develop/requester/mctp_endpoint_discovery.cpp"
    click requester "https://github.com/nvidia/nsmd/blob/develop/requester/request_timeout_tracker.cpp"
    click nsmtool "https://github.com/nvidia/nsmd/blob/develop/nsmtool/meson.build"
    click nsmtool "https://github.com/nvidia/nsmd/blob/develop/nsmtool/nsmtool.cpp"
    click nsmtool "https://github.com/nvidia/nsmd/blob/develop/nsmtool/cmd_helper.cpp"
    click nsmtool "https://github.com/nvidia/nsmd/blob/develop/nsmtool/nsm_telemetry_cmd.cpp"
    click mockupResponder "https://github.com/nvidia/nsmd/blob/develop/mockupResponder/meson.build"
    click mockupResponder "https://github.com/nvidia/nsmd/blob/develop/mockupResponder/mockupResponder.cpp"
    click mockupResponder "https://github.com/nvidia/nsmd/blob/develop/mockupResponder/nsmMockupResponder.cpp"
    click nsmd "https://github.com/nvidia/nsmd/blob/develop/services/nsmd.service"

    classDef binary fill:#ADD8E6,stroke:#333;
    classDef lib fill:#90EE90,stroke:#333;
    classDef transport fill:#87CEEB,stroke:#333;
    classDef protocol fill:#98FB98,stroke:#333;
    classDef logic fill:#FFA07A,stroke:#333;
    classDef external fill:#FFD700,stroke:#333,stroke-dasharray: 2 2;
```
