Backend Modules
apps.network — MikroTik RouterOS & OLT Chassis
Core network operations, POP branches, MikroTik RouterOS v7 integration, OLT optical diagnostics, and online sessions.
apps.network — MikroTik RouterOS & OLT Chassis
IMPLEMENTED
- Location:
backend/apps/network/ - Responsibilities: MikroTik RouterOS v7 synchronization, PPPoE credentials and queue management, EPON/GPON OLT chassis management, optical RX power diagnostics, and active online subscriber sessions.
1. Database Models (6 Models)
| Model Name | Purpose | Key Fields |
|---|---|---|
POPBranch | Point of Presence (POP) distribution branch | name, code, location, contact_person, is_active |
Router | MikroTik Core Router registration | name, ip_address, api_port, username, encrypted_password, status |
OLT | Optical Line Terminal chassis | name, ip_address, brand, snmp_community, pon_ports_count |
ONU | Optical Network Unit at subscriber premises | olt, pon_port, mac_address, rx_power, tx_power, status |
UserSession | Live active PPPoE session cache | username, ip_address, mac_address, uptime, bytes_in, bytes_out |
NetworkSyncJob | Durable hardware synchronization queue | customer, router, olt, action, status, payload, retry_count |
2. MikroTik Client Architecture (apps.network.services.mikrotik)
RouterViewSet / Background Task
│
▼
MikroTikService (Business Logic)
│
▼
MikroTikClient (Adapter & Connection Pooling)
│
▼
RouterOS v7 REST API / Binary API Socket- Credential Security: Passwords stored symmetrically encrypted via
cryptography.fernet. - SSRF Prevention: Strict server-side IP validation prevents arbitrary internal network probing.
- Failover / Offline Handling: Routers unreachable during operations are flagged
OFFLINE; background tasksync_router_telemetryretries connectivity and reports circuit restoration.
3. The Critical Network Rule & Post-Commit Synchronization
Network hardware communication (MikroTik RouterOS REST/sockets, OLT telnet/SNMP) entails non-deterministic latencies, socket timeouts, and potential device unresponsiveness.
Architectural Invariant
CRITICAL NETWORK RULE: Physical hardware operations must NEVER be executed inside an open PostgreSQL database transaction. Database changes must commit first. Hardware synchronization must occur post-commit via durable background jobs.
Durable Sync Workflow (NetworkSyncJob)
Rendering diagram...
- Job Actions:
ENABLE_USER: Re-enables disabled PPPoE secret on router upon recharge or grace period.DISABLE_USER: Disables PPPoE secret on router upon expiry or manual suspension.UPDATE_PACKAGE: Updates profile and rate limit queues when a customer switches speed tiers.DISCONNECT_SESSION: Kicks active PPPoE session forcing immediate reconnect with new profile.
- Durable Safety: If Celery is temporarily unavailable or in synchronous mode,
dispatch_network_sync_jobgracefully executes inline fallback after transaction commit.