Project for the Softwarized and Virtualized Mobile Networks course (a.y. 2025–2026).
This project uses ComNetsEmu as a network emulator and RYU as the SDN controller to build a virtualized environment for traffic generation and traffic prediction using machine learning.
The main requirement is to install ComNetsEmu. At the following link you can find all the steps to install it.
Some python modules need to be installed using:
pip install -r requirements.txtThe requirements.txt file is already provided to simplify the installation of the different modules.
Note
A virtual environment is suggested to be used to install the modules to avoid conflicts with different versions.
The project consists of two main modules:
- Traffic Extractor
- Traffic Predictor
Which can be run separately by following the instructions in the dedicated sections below.
To these blocks, an additional module for plotting generated networks' topologies and traffic data is added.
Lastly, a "demo.py" is given to test out the whole pipeline.
This module is responsable for the creation of networks and the extraction of their traffic.
- Random network topologies generation
- Random background traffic production
- SDN controllers management
- Switches statistics logging to CSV files
To run such module, execute the following command:
sudo python3 traffic_extractor/nets_controller.pyThe following variables can be configured:
-
logger_controller.py
REQUEST_DELAY_S: indicate the logging frequency. As it is tighlty related to the model training, we suggest to NOT modify it.
-
nets_controller.py
BASE_OUTPUT_DIR: the output directory of the logs generated.NUM_RUNS: how many different networks need to be run.RUNTIME: how many seconds each run need to be executed.
-
nets_generator.py
- In
__init__function you can define the interval of switches and hosts that can be generated for each network.
- In
The script will automatically start and stop the required controllers:
-
Traffic Controller
Custom RYU application that monitors all OpenFlow switches and periodically writes statistics to a CSV log. -
Simple Switch Controller
Standard RYU L2 learning switch used to populate basic forwarding rules.
Important
Do not change the controllers port numbers.
The network controller expects these controllers to be reachable on fixed ports.
This module processes generated runs' CSV logs and starts a full machine learning pipeline for traffic prediction.
- Data preprocessing
- Feature engineering
- Model training and validation
- Predictions and evaluation
The module provides both a training and a testing mode:
-
Training mode is used to train the model from scratch.
The trained model is then saved in an apposite folder, "model". -
Testing mode is used to evaluate the saved model on the test set.
The following flags and variables can be configured:
- main.py
TRAINING: flag to indicate if a new model has to be trained or just a testing is required.RAW_DATA_PATH: the folder where the logs are stored.PROCESSED_DATA_PATH: the output folder to store the preprocessed data.MODEL_PATH: the output folder where to store the trained model.
To correctly use the code for both modes, please refer to the sections below.
To use the code in training mode, run:
python3 -m traffic_predictor.mainNote
By ensuring the "TRAINING" flag at the beginning of "traffic_predictor/main.py" is set to "True".
To use the code in testing mode, run:
python3 -m traffic_predictor.mainNote
By ensuring the "TRAINING" flag at the beginning of "traffic_predictor/main.py" is set to "False".
This module serves as a tool to eventually visualize the generated networks and their traffic.
To run such module, execute the following command:
python3 traffic_plotter/dataset_visualizer.pyIn order to test the whole pipeline, run the following command:
sudo python3 -m demo.demoAfter running such command, results in terms of accuracy of prediction will be displayed in the terminal.
Additionally, plots showing a comparison between real and predicted values, for each run and each target traffic feature, will be added to the "demo/results" folder.
If Mininet and/or ComNetsEmu becomes stuck or fails to terminate correctly, run:
sudo mn -cThis clears all leftover network namespaces and virtual interfaces.
This can happen only when executing the networks module as it is the one to use the functionalities of ComNetsEmmu.
The Machine Learning module automatically detects if the host has a GPU available otherwise, the CPU will be used.
As both training and testing phase require a certain amount of resources, there can be the case were, even if the GPU is available, the script execution will be terminated because of insufficient resources.
A possible output error:
torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 1.26 GiB. GPU 0 has a total capacity of <your_gpu_capacity>Note
In case the host's GPU doesn't have enough resources, force the CPU usage by explicitly define DEVICE = "cpu" in the following python scripts:
utils.py, functions.py.
Be sure to run all commands from the project root directory (i.e., the folder containing this README) to ensure all relative paths resolve correctly.
| Name | |
|---|---|
| Dorijan Di Zepp | [email protected] |
| Stefano Camposilvan | [email protected] |