# smartbgp/yabmp architecture

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

- Interactive diagram: https://gitdiagram.com/smartbgp/yabmp
- Repository: https://github.com/smartbgp/yabmp

## Overview

##### Project type and purpose
- This is a Python‑based network daemon/library implementing the BGP Monitoring Protocol (BMP) receiver (RFC 7854 v3).
- It listens on a socket for BMP messages, parses them, and writes message contents to files (or publishes them via hooks).

##### File structure
- Top‑level:
- bin/yabmpd         – CLI wrapper that starts the daemon
- etc/yabmp/*.ini.sample – Configuration template
- Dockerfile, start.sh – containerization and startup scripts
- setup.py, requirements.txt – packaging/dependencies
- Core package (yabmp/):
- channel/           – abstractions for network channels (config, factory, consumer, publisher, protocol)
- message/bmp.py     – BMP message definitions and parsers
- core/              – low‑level BMP protocol factory and wire‐level handling
- handler/default.py – default “write to file” handler
- service.py         – orchestrates startup, instantiates channel(s), dispatches messages
- common/            – shared constants and exception definitions
- hooks.py, log.py   – extension points and logging utilities
- cmd/               – command‑line interface module
- tests/             – unit tests

##### README for additional insights
- Confirms it’s a receiver‑side reference implementation for stepping through BMP messages and dumping them.
- Quick‑start instructions show running `python yabmpd` spawns a BMP listener on port 20000.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Network layer
    subgraph "Network I/O"
        direction TB
        ExtRouter["External BGP Router"]:::network
        ChannelConsumer["Channel Consumer"]:::network
    end

    %% Parsing layer
    subgraph "Parsing / Protocol"
        direction TB
        ProtocolParser["Channel Protocol Parser"]:::parse
        CoreFactory["Core Protocol Factory"]:::parse
        CoreProtocol["Core Protocol Handler"]:::parse
        MessageLayer["BMP Message Definitions & Parsers"]:::parse
    end

    %% Handler / Persistence layer
    subgraph "Handlers / Persistence"
        direction TB
        DefaultHandler["Default File Handler"]:::handler
        Hooks["Hooks / Extension Points"]:::handler
    end

    %% Infrastructure layer
    subgraph "Infrastructure / Orchestration"
        direction TB
        CLI["CLI Entrypoint"]:::infra
        Service["Service Orchestrator"]:::infra
        ConfigLoader["Config Subsystem"]:::infra
        Logger["Logging Subsystem"]:::infra
    end

    %% Data flows
    ExtRouter -->|"raw BMP bytes"| ChannelConsumer
    ChannelConsumer -->|"framed bytes"| ProtocolParser
    ProtocolParser -->|"wire-level frames"| CoreFactory
    CoreFactory -->|"protocol instance"| CoreProtocol
    CoreProtocol -->|"raw message"| MessageLayer
    MessageLayer -->|"Parsed BMPMessage object"| DefaultHandler
    MessageLayer -->|"Parsed BMPMessage object"| Hooks

    %% Startup flow
    CLI -->|"reads config & args"| ConfigLoader
    CLI -->|"initializes"| Logger
    CLI -->|"starts service"| Service
    Service -->|"instantiates"| ChannelConsumer
    Service -->|"instantiates"| ProtocolParser
    Service -->|"instantiates"| CoreFactory
    Service -->|"registers handlers"| DefaultHandler
    Service -->|"registers hooks"| Hooks

    %% Styling
    classDef network fill:#e5f5e0,stroke:#333,stroke-width:1px
    classDef parse fill:#e0ecf4,stroke:#333,stroke-width:1px
    classDef handler fill:#fee6ce,stroke:#333,stroke-width:1px
    classDef infra fill:#f0f0f0,stroke:#333,stroke-width:1px

    %% Click events
    click CLI "https://github.com/smartbgp/yabmp/tree/master/bin/yabmpd"
    click Service "https://github.com/smartbgp/yabmp/blob/master/yabmp/service.py"
    click ConfigLoader "https://github.com/smartbgp/yabmp/blob/master/yabmp/config.py"
    click Logger "https://github.com/smartbgp/yabmp/blob/master/yabmp/log.py"
    click Hooks "https://github.com/smartbgp/yabmp/blob/master/yabmp/hooks.py"
    click ChannelConsumer "https://github.com/smartbgp/yabmp/blob/master/yabmp/channel/consumer.py"
    click ProtocolParser "https://github.com/smartbgp/yabmp/blob/master/yabmp/channel/protocol.py"
    click CoreFactory "https://github.com/smartbgp/yabmp/blob/master/yabmp/core/factory.py"
    click CoreProtocol "https://github.com/smartbgp/yabmp/blob/master/yabmp/core/protocol.py"
    click MessageLayer "https://github.com/smartbgp/yabmp/blob/master/yabmp/message/bmp.py"
    click DefaultHandler "https://github.com/smartbgp/yabmp/blob/master/yabmp/handler/default.py"
    click ConfigLoader "https://github.com/smartbgp/yabmp/blob/master/etc/yabmp/yabmp.ini.sample"
    click FactoryModule "https://github.com/smartbgp/yabmp/blob/master/yabmp/channel/factory.py"
    click Publisher "https://github.com/smartbgp/yabmp/blob/master/yabmp/channel/publisher.py"
    click CMDModule "https://github.com/smartbgp/yabmp/blob/master/yabmp/cmd/__init__.py"
    click Constants "https://github.com/smartbgp/yabmp/blob/master/yabmp/common/constants.py"
    click Exceptions "https://github.com/smartbgp/yabmp/blob/master/yabmp/common/exception.py"
    click Tests "https://github.com/smartbgp/yabmp/tree/master/yabmp/tests/"
    class FactoryModule,yabmp/channel/factory.py infra
    class Publisher,yabmp/channel/publisher.py parse
    class CMDModule,yabmp/cmd/__init__.py infra
    class Constants,Exceptions infra
    class Tests infra
```
