Skip to content

Repository for the project of the Softwarized and Virtualized Mobile Networks course of the a.y. 2025-2026

Notifications You must be signed in to change notification settings

najirod02/TrafficPredictionSDN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Traffic Prediction on SDN

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.

Table of contents

Requirements

ComNetsEmu

The main requirement is to install ComNetsEmu. At the following link you can find all the steps to install it.

Pip

Some python modules need to be installed using:

pip install -r requirements.txt

The 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.

Project Structure

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.

Traffic Extractor - Networks module

This module is responsable for the creation of networks and the extraction of their traffic.

Features

  • Random network topologies generation
  • Random background traffic production
  • SDN controllers management
  • Switches statistics logging to CSV files

Usage

To run such module, execute the following command:

sudo python3 traffic_extractor/nets_controller.py

The 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.

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.

Traffic Predictor - Machine Learning Module

This module processes generated runs' CSV logs and starts a full machine learning pipeline for traffic prediction.

Features

  • Data preprocessing
  • Feature engineering
  • Model training and validation
  • Predictions and evaluation

Usage

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.

Training mode

To use the code in training mode, run:

python3 -m traffic_predictor.main

Note

By ensuring the "TRAINING" flag at the beginning of "traffic_predictor/main.py" is set to "True".

Testing mode

To use the code in testing mode, run:

python3 -m traffic_predictor.main

Note

By ensuring the "TRAINING" flag at the beginning of "traffic_predictor/main.py" is set to "False".

Plotter module

This module serves as a tool to eventually visualize the generated networks and their traffic.

Usage

To run such module, execute the following command:

python3 traffic_plotter/dataset_visualizer.py

Pipeline testing - Demo

In order to test the whole pipeline, run the following command:

sudo python3 -m demo.demo

After 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.

Additional Notes

Mininet

If Mininet and/or ComNetsEmu becomes stuck or fails to terminate correctly, run:

sudo mn -c

This 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.

GPU Cuda

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.


Paths correctness

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.

Authors

Name Email
Dorijan Di Zepp [email protected]
Stefano Camposilvan [email protected]

About

Repository for the project of the Softwarized and Virtualized Mobile Networks course of the a.y. 2025-2026

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages