How filipholik/smartgridsim works
Project Type and Purpose
• SGSim is a full-stack simulation tool for smart-grid communications and cyber-attack emulation.
• Key runtime modes:
– Network emulation via Mininet (Python scripts)
– Desktop GUI app (C)
– Browser-based SCADA GUI (PHP + JavaScript)
– Data persistence (SQLite)
File Structure
Top-level items:
• Start scripts:
– StartSGTopology.sh / StartDSSTopology.sh → bootstraps Mininet topologies
– StartGUI.sh → compiles & runs the C desktop GUI
– initDatabase.sh → initializes the SQLite schema
• topologies/
– SmartGridTopology.py, DSSTopology.py → define Mininet graphs and attach device emulators
• comlib_dps.zip, comlib_dss.zip
– Device-simulation libraries for primary/secondary substations, unpacked by the topology scripts
• GUI/
– Application/ → C source (GUI.c), CMakeLists.txt, styling (style.css)
– PHPserver/ → SCADA web server (PHP pages, CSS, JS, SQLite DB file, dbHandler modules)
– DDOSDetection.sh → shell script to detect flood attacks in the emulated network
• GUI/PHPserver/dbHandler/
– PHP modules that connect to SGData.db and expose sensor values, timestamps, DDOS flags, GOOSE states, etc.
README for Stack Details
• Dependencies: mininet, sqlite3, PHP
• Workflow:
1. Unzip comlib packages
2. Run “StartSGTopology.sh” (mininet + Python)
3. Run “GUI/StartGUI.sh” (desktop GUI)
4. Browse to localhost:8000 for web SCADA
• Two GUIs operate in parallel: desktop C app and browser SCADA
Main Components & Their Interactions
A. Host Environment
– Shell scripts orchestrate startup (topology, GUI, DB init)
B. Network Emulator (Mininet + Python)
– Python topologies spawn hosts representing IEDs, sensors, IED1…IED4, DSS1…DSS2
– Each host loads comlib_dps or comlib_dss to simulate IEC 61850 traffic (GOOSE, SV, MMS)
– A DDOSDetection.sh script runs on one host (or controller) to monitor flood attacks
C. Data Storage (SQLite)
– initDatabase.sh creates SGData.db
– Device-simulation code writes measurement and state data via HTTP calls to PHPserver/dbHandler/*.php
– DDOSDetection.sh writes anomaly flags to SGData.db
D. Web SCADA Server (PHP + JavaScript)
– index.php + client.js + topology.js render real-time substation topology and values in a browser
– dbHandler modules serve JSON endpoints for sensor data, timestamps, GOOSE states
E. Desktop GUI (C app)
– Compiled under GUI/Application via CMake / Makefile
– Polls SGData.db directly or via HTTP endpoints to display network & data in a native window
Architectural Patterns & Principles
• Separation of concerns:
– Network emulation, data capture, data storage, web UI, desktop UI are decoupled
• MVC in Web SCADA:
– Model: SGData.db + dbHandler PHP scripts
– View: HTML/CSS/JavaScript (topology.js, client.js)
– Controller: PHP pages
• Micro-process style: each shell script, Python script, PHP module performs a single role