This project simulates a federated learning environment over a mobile network using the NS-3 simulator. The simulation involves several key elements such as mobile user devices (UEs), eNodeBs (base stations), and a remote server. Federated learning clients (UEs) train local models and periodically send their updates to the server over a 4G LTE or 5G MmWave network.
The simulation is designed to handle parallel client training, transmission of trained models, and server aggregation in a federated learning round.
- UE Nodes: User equipment (e.g., mobile devices) participating in the federated learning process.
- eNB Nodes: The base stations that handle communication between UEs and the server.
- Remote Host: The server that receives the locally trained models and performs aggregation.
- NS-3: This simulation uses NS-3 and its LTE/MmWave modules.
- Python 3: For running the local training tasks via scripts.
- NetAnim: Optionally used for visualizing the network simulation.
- Dependencies: Make sure NS-3 modules like
lte,internet,mobility, andapplicationsare installed and available.
ns3/applications-module.hns3/internet-module.hns3/lte-helper.hns3/flow-monitor-module.hjson.hpp: For handling JSON files.random,future: For generating randomness and handling parallel execution.
- Clone this repository.
- Compile the NS-3 simulation:
./ns3 configure ./ns3
- Run the simulation:
./ns3 --run "simulation"
-
Federated Learning Process:
- Each UE trains a local model using a Python script.
- Models are sent over the network to the remote server.
- The server aggregates the models.
-
LTE/MmWave Network Simulation:
- The UEs communicate with the server via base stations using LTE or MmWave networks.
- Mobility and handovers are supported between eNBs.
-
Parallel Execution:
- Client training is run in parallel using C++ futures for efficiency.
-
Network Monitoring:
- Instantaneous throughput and connection details are logged during the simulation.
-
MyApp: Simulates application layer traffic generation for UEs. This class handles the sending of data packets from UEs to the server.
-
Clients_Models: Represents each federated learning client, including its associated node, training time, and bytes transferred.
- sendstream(): Sends the trained model from the UE to the server.
- train_clients(): Triggers the training process for all clients, each running a Python script to train a model.
- manager(): Manages the federated learning rounds, selects clients, and coordinates the sending of models to the server.
- NotifyConnectionEstablishedUe/NotifyConnectionEstablishedEnb: Logs the connection establishment between UEs and eNBs.
- NotifyHandoverStartUe/NotifyHandoverEndOkUe: Logs UE handover events during the simulation.
The simulation involves:
- Network Configuration:
- UEs and eNBs are initialized with random positions.
- LTE or MmWave channels are set up.
- Mobility Models: UEs are assigned a constant position, but this can be changed to a dynamic model if required.
- Data Transfer: Each UE sends its trained model to the server, and throughput is monitored using the
FlowMonitorclass.
-
Configure the number of UEs and eNBs: These are set via global variables:
int number_of_ues = 10; int number_of_enbs = 1; int n_participaping_clients = 5;
-
Training and Model Transmission: The UEs perform local training, and the trained model is sent to the server over the network. The server then aggregates the models.
-
Timeout Mechanism: If a round of transmission does not finish in a specified time (
timeout = Seconds(60)), the round is considered timed out. -
Output: The simulation logs network events and the time taken by each UE to send its model.
- Logs: Simulation progress and network events are logged to the console.
- Throughput Measurement: Instantaneous throughput in Mbps is calculated and displayed.
- Client Selection: Each round, a subset of clients is randomly selected to participate in federated learning.
This project is licensed under the MIT License.