---
Prof. Granelli Fabrizio
Group: De Marco Matthew, Lo Iacono Andrea, Revrenna Jago
This project implements a Digital Twin for monitoring and predicting traffic behavior in Software Defined Networks (SDN). The system consists of:
- Physical Twin (PT): A Mininet network with OpenFlow switches controlled by a Ryu controller
- Digital Twin (DT): A real-time monitoring dashboard with ML-based traffic prediction
The Digital Twin continuously polls the Physical Twin for traffic statistics, stores them in a SQLite database, and uses trained Seq2Seq LSTM models to predict future traffic patterns 60 seconds ahead.
Key Features:
- Real-time traffic monitoring via web dashboard
- ML-based traffic state classification (NORMAL, ELEVATED, HIGH, CRITICAL)
- Multi-scenario model support (Normal, Burst, Congestion, DDoS, Mixed)
- Live prediction graph visualization
- Scenario-based model switching from UI
+---------------------------+ REST API +---------------------------+
| PHYSICAL TWIN | <---------------------> | DIGITAL TWIN |
|---------------------------| |---------------------------|
| Mininet Network | | Orchestrator |
| OpenFlow Switches | | Flask Web Dashboard |
| Ryu Controller | | SQLite Database |
| | | PyTorch ML Models |
+---------------------------+ +---------------------------+
192.168.56.101 192.168.56.102
- Host Machine: Windows 10/11 or macOS
- RAM: Minimum 8GB (16GB recommended)
- CPU: Multi-core processor with virtualization support
- Disk: 30GB free space
Windows:
- VirtualBox 6.1+
- Vagrant 2.3+
macOS:
- Multipass 1.10+
Both VMs require:
- Ubuntu 20.04
- ComNetsEmu framework (official repo)
- Python 3.8+
- PyTorch, Flask, NumPy, Scikit-learn
Important
For ComNetsEmu installation, refer to the official repository: https://git.comnets.net/public-repo/comnetsemu . ComNetsEmu installation is a fundamental and mandatory step to replicate our work in your machine. ComNetsEmu must be installed in both the VMs (the one used for the Physical Twin and the one used for the Digital Twin)
-
Install Prerequisites
- Install VirtualBox
- Install Vagrant
-
Clone the Repository
git clone https://github.com/MattDema/Networking_DT4SDN.git cd Networking_DT4SDN -
Start the Digital Twin VM
vagrant up comnetsemu_dt
-
SSH into the VM
vagrant ssh comnetsemu_dt
-
Set up Python environment (inside VM)
cd ~/Networking_DT4SDN/setups chmod +x setup_vm.sh ./setup_vm.sh
Tip
The Vagrantfile automatically installs ComNetsEmu from the official repo, clones this repository, and sets up dependencies.
Creating the VMs:
# Physical Twin VM
multipass launch 20.04 --name comnetsemu-vm --cpus 1 --mem 1G --disk 5G
# Digital Twin VM
multipass launch 20.04 --name digital-twin --cpus 2 --mem 4G --disk 20GSetting up the Physical Twin:
multipass shell comnetsemu-vm- Install ComNetsEmu from the official repository
- Install dependencies:
pip3 install requests
- Clone the repository:
git clone https://github.com/MattDema/Networking_DT4SDN.git
Setting up the Digital Twin:
multipass shell digital-twin- Install ComNetsEmu from the official repository
- Install dependencies:
sudo apt update sudo apt install python3-pip -y sudo pip3 install flask requests numpy scipy joblib torch scikit-learn pandas
- Clone the repository:
git clone https://github.com/MattDema/Networking_DT4SDN.git
Open two terminals in the Physical Twin VM:
Terminal 1 - Ryu Controller:
cd ~/Networking_DT4SDN/setups
chmod +x start_ryu.sh
./setups/start_ryu.shTerminal 2 - Mininet Topology:
cd ~/Networking_DT4SDN/src/utils
python3 topology_generator.py
# Follow prompts to create network (e.g., 3 switches, 6 hosts, tree topology)-
First, get the Physical Twin IP:
# On host machine multipass list # or check Vagrant network config
-
Update the PT_IP in the orchestrator:
cd ~/Networking_DT4SDN/src/controllers nano orchestrator.py # Change: PT_IP = os.getenv('PT_IP', 'YOUR_PT_IP_HERE')
-
Also update in
src/web_interface/app.py -
Start the Orchestrator:
cd ~/Networking_DT4SDN python3 src/controllers/orchestrator.py
-
Access the Dashboard at:
http://DT_IP:5000
In the Mininet terminal, use iperf to simulate different traffic patterns:
Normal Traffic:
h1 iperf -c 10.0.0.2 -u -b 500K -t 60Burst Traffic:
h1 iperf -c 10.0.0.2 -u -b 25M -t 15 &Congestion Simulation:
h1 iperf -c 10.0.0.2 -u -b 8M -t 90 &
# Wait 20 seconds, then:
h2 iperf -c 10.0.0.3 -u -b 8M -t 70 &DDoS Simulation:
h1 iperf -c 10.0.0.2 -u -b 29M -t 400Warning
Press Ctrl+C to stop traffic and observe the model returning to NORMAL state.
The system uses two types of ML models:
| Model Type | Purpose | Architecture |
|---|---|---|
| Classifier | Predict traffic state | BiLSTM |
| Seq2Seq | Predict 60s future values | CNN + BiLSTM |
Available Scenarios:
normal- Trained on normal traffic patternsburst- Trained on burst trafficcongestion- Trained on network congestionddos- Trained on DDoS attack patternsmixed- Trained on all scenarios (default)
Switching Models via UI: Use the dropdown in the dashboard header to switch between scenario models in real-time.
Switching Models via API:
curl -X POST http://DT_IP:5000/api/models/switch \
-H "Content-Type: application/json" \
-d '{"scenario": "ddos"}'Networking_DT4SDN/
├── src/
│ ├── controllers/
│ │ └── orchestrator.py # Main entry point
│ ├── web_interface/
│ │ └── app.py # Flask dashboard + API
│ ├── database/
│ │ ├── db_manager.py # SQLite operations
│ │ └── schema.sql # Database schema
│ ├── ml_models/
│ │ ├── state_predictor.py # Classifier model
│ │ ├── seq2seq_predictor.py # Seq2Seq model
│ │ └── training/ # Training scripts
│ └── utils/
│ └── topology_generator.py # Mininet topology creator
├── models/ # Trained model files (.pt)
├── setups/
│ ├── start_ryu.sh # Ryu controller startup
│ └── setup_vm.sh # VM setup script
├── Vagrantfile # Windows VM configuration
└── requirements.txt # Python dependencies
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Dashboard HTML page |
/api/prediction |
GET | Current traffic prediction |
/api/models |
GET | List available models |
/api/models/switch |
POST | Switch to different scenario model |
/stats |
GET | Database statistics |
Networking Module 2 Course - Professor: Fabrizio Granelli
This project is licensed under the MIT License - see the LICENSE file for details.
