# voipmonitor/sniffer architecture

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

- Interactive diagram: https://gitdiagram.com/voipmonitor/sniffer
- Repository: https://github.com/voipmonitor/sniffer

## Overview

##### Main Components

a) Packet Capture Layer
- PCAP handling components (pcap_queue.cpp, pcap_queue_block.h)
- Both live capture and file reading capabilities

b) Protocol Analysis Layer
- SIP Processing (multiple SIP-related files)
- RTP Processing (rtp.cpp, rtcp.cpp)
- Other protocols (MGCP, Skinny, WebRTC, WebSocket)
- SSL/TLS handling (ssl directory, dssl directory)

c) Call Processing Engine
- Call Table Management (calltable.cpp)
- Jitter Buffer Simulation (jitterbuffer directory)
- Audio Processing (audio_convert.cpp, codec files)
- Quality Metrics Calculator (MOS calculation)

d) Storage Layer
- MySQL Database Interface (sql_db.cpp)
- PCAP File Storage
- RRD Integration (rrd.cpp)

e) System Management
- Configuration Management (config_param.cpp)
- Manager Interface (manager.cpp)
- Fraud Detection (fraud.cpp)

**[Network Traffic] → [Packet Capture Layer] → [Protocol Analysis Layer] → [Call Processing Engine] → [Storage Layer]**
- ↓
- [System Management Layer]

##### Detailed Component Relationships

- Packet flow from capture to analysis
- Call data flow to storage
- Management commands flow
- Quality metrics calculation path

- Blue: Core packet processing components
- Green: Analysis and metrics components
- Orange: Storage components
- Gray: Management and configuration components

##### Technical Details

- Protocol support (SIP, RTP, RTCP, MGCP, WebRTC)
- Codec support (show audio processing pipeline)
- Quality metric calculations (loss, latency, MOS)
- Storage formats (PCAP, MySQL, RRD)

##### Implementation Notes

- Packet capture pipeline (pcap_queue.cpp)
- Call processing workflow (calltable.cpp)
- Audio processing chain (audio_convert.cpp)
- Storage mechanisms (sql_db.cpp)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Network
        NT[Network Traffic]
    end

    subgraph "Packet Capture"
        PCQ["Packet Queue"]:::capture
        PCB["Packet Queue Block"]:::capture
    end

    subgraph "Protocol Analysis"
        SIP["SIP Processing"]:::protocol
        RTP["RTP Processing"]:::protocol
        RTCP["RTCP Processing"]:::protocol
        MGCP["MGCP Processing"]:::protocol
        WRTC["WebRTC Processing"]:::protocol
        SKN["Skinny Processing"]:::protocol
        SSL["SSL/TLS Handler"]:::protocol
    end

    subgraph "Call Processing"
        CT["Call Table"]:::processing
        JB["Jitter Buffer"]:::processing
        AP["Audio Processing"]:::processing
        QM["Quality Metrics"]:::processing
    end

    subgraph "Storage"
        DB["MySQL Database"]:::storage
        PCAP["PCAP Storage"]:::storage
        RRD["RRD System"]:::storage
    end

    subgraph "System Management"
        CFG["Configuration Manager"]:::management
        MGR["System Manager"]:::management
        FD["Fraud Detection"]:::management
    end

    %% Main Flow
    NT --> PCQ
    PCQ --> PCB
    PCB --> SIP & RTP & RTCP & MGCP & WRTC & SKN & SSL

    %% Protocol to Call Processing
    SIP & RTP & RTCP & MGCP & WRTC & SKN --> CT
    CT --> JB
    JB --> AP
    AP --> QM

    %% Storage Flow
    QM --> DB
    QM --> PCAP
    QM --> RRD

    %% Management Integration
    CFG --> PCQ
    CFG --> CT
    MGR --> CT
    FD --> CT

    %% Click Events
    click PCQ "https://github.com/voipmonitor/sniffer/blob/master/pcap_queue.cpp"
    click PCB "https://github.com/voipmonitor/sniffer/blob/master/pcap_queue_block.h"
    click SIP "https://github.com/voipmonitor/sniffer/blob/master/sip_tcp_data.cpp"
    click RTP "https://github.com/voipmonitor/sniffer/blob/master/rtp.cpp"
    click RTCP "https://github.com/voipmonitor/sniffer/blob/master/rtcp.cpp"
    click MGCP "https://github.com/voipmonitor/sniffer/blob/master/mgcp.cpp"
    click WRTC "https://github.com/voipmonitor/sniffer/blob/master/webrtc.cpp"
    click SKN "https://github.com/voipmonitor/sniffer/blob/master/skinny.cpp"
    click SSL "https://github.com/voipmonitor/sniffer/tree/master/ssl"
    click CT "https://github.com/voipmonitor/sniffer/blob/master/calltable.cpp"
    click JB "https://github.com/voipmonitor/sniffer/tree/master/jitterbuffer"
    click AP "https://github.com/voipmonitor/sniffer/blob/master/audio_convert.cpp"
    click QM "https://github.com/voipmonitor/sniffer/blob/master/mos_g729.cpp"
    click DB "https://github.com/voipmonitor/sniffer/blob/master/sql_db.cpp"
    click RRD "https://github.com/voipmonitor/sniffer/blob/master/rrd.cpp"
    click CFG "https://github.com/voipmonitor/sniffer/blob/master/config_param.cpp"
    click MGR "https://github.com/voipmonitor/sniffer/blob/master/manager.cpp"
    click FD "https://github.com/voipmonitor/sniffer/blob/master/fraud.cpp"

    %% Styling
    classDef capture fill:#1E88E5,color:white
    classDef protocol fill:#43A047,color:white
    classDef processing fill:#FDD835,color:black
    classDef storage fill:#FB8C00,color:white
    classDef management fill:#757575,color:white

    %% Legend
    subgraph Legend
        L1["Packet Capture"]:::capture
        L2["Protocol Handler"]:::protocol
        L3["Call Processing"]:::processing
        L4["Storage System"]:::storage
        L5["Management"]:::management
    end
```
