S
Sheba ISP ERPDOCS
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 NamePurposeKey Fields
POPBranchPoint of Presence (POP) distribution branchname, code, location, contact_person, is_active
RouterMikroTik Core Router registrationname, ip_address, api_port, username, encrypted_password, status
OLTOptical Line Terminal chassisname, ip_address, brand, snmp_community, pon_ports_count
ONUOptical Network Unit at subscriber premisesolt, pon_port, mac_address, rx_power, tx_power, status
UserSessionLive active PPPoE session cacheusername, ip_address, mac_address, uptime, bytes_in, bytes_out
NetworkSyncJobDurable hardware synchronization queuecustomer, 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 task sync_router_telemetry retries 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_job gracefully executes inline fallback after transaction commit.

On this page