A C++ simulation framework for analyzing and comparing the performance of WiFi 4, WiFi 5, and WiFi 6 under various network loads. This project is open source and public.
This simulator models the MAC layer of WiFi networks, focusing on CSMA/CA and collision handling, to provide insights into throughput and latency as user load increases.
The project is organized into modular components:
- User: Represents a network station. Each WiFi version (4/5/6) has its own user class inheriting from a common base.
- Access Point (AP): Manages the channel and coordinates transmissions. Each WiFi version has its own AP class.
- Packet: Encapsulates data sent between users and the AP.
- Channel: Simulates the shared wireless medium.
- Simulation Loop: Advances time in discrete steps, handling user backoff, channel access, and collision detection.
- Main Menu: Command-line interface for running and viewing simulations.
WiFi_Communication_Simulator/
│
├── Makefile # Build system
├── README.md # Project documentation
│
├── include/ # Header files
│ ├── ap.h # Access Point base class
│ ├── channel.h # Channel simulation
│ ├── packet.h # Packet structure
│ ├── user.h # User base class
│ ├── wifi4.h # WiFi 4 implementation
│ ├── wifi5.h # WiFi 5 implementation
│ └── wifi6.h # WiFi 6 implementation
│
├── src/ # Source files
│ ├── main.cpp # Main application and menu
│ ├── ap.cpp
│ ├── channel.cpp
│ ├── packet.cpp
│ ├── user.cpp
│ ├── wifi4.cpp
│ ├── wifi5.cpp
│ └── wifi6.cpp
│
└── build/ # Compiled objects and executable
- C++17 or later compiler (e.g., g++)
- make
Clone the repository and build using the Makefile:
git clone https://github.com/laxman-gupta1006/WiFi_Communication_Simulator.git
cd WiFi_Communication_Simulator
make
This will produce the executable wifi_simulator
in the build/
directory.
Run the simulator from the project root:
make run
Or run the executable directly:
./build/wifi_simulator
- Run Simulation: Executes performance simulation for all WiFi standards and user scenarios
- View Simulation Results: Displays results from the last run
- Exit: Quit the program
- User Scenarios: 1, 10, 100 users
- Metrics: Throughput, Average Latency, Maximum Latency
- Iterations: 100 per scenario (configurable in code)
- CSMA/CA: Each user senses the channel and uses a random backoff before transmitting. Collisions are detected and handled with binary exponential backoff.
- Performance Metrics: After each simulation, throughput and latency statistics are computed and displayed.
To add a new WiFi technology:
- Create a new header/source (e.g.,
wifi7.h
,wifi7.cpp
) - Implement new User and Access Point classes
- Register the new technology in
main.cpp
- Add to the build system if needed
CSMA/CA is the fundamental channel access method used in WiFi networks. Before transmitting, a device listens to the channel to check if it is free. If the channel is busy, the device waits for a random backoff period before trying again. This reduces the likelihood of collisions when multiple devices attempt to transmit simultaneously. If a collision does occur, the backoff window is increased (binary exponential backoff), further reducing the chance of repeated collisions.
How it's simulated in code:
- The main logic is in each WiFi version's access point, e.g.
src/wifi4.cpp
:// WiFi4AccessPoint::simulateTransmission() while (currentTime < SIMULATION_TIME) { for (auto user : wifi4Users) { if (user->canTransmit()) { if (isChannelFree()) { // Transmit packet } else { // Channel busy - backoff user->incrementBackoff(); } } } }
- Each user has a backoff counter and contention window (see
WiFi4User
ininclude/wifi4.h
). - If multiple users transmit in the same slot, a collision is detected and their contention windows are doubled:
// In simulateTransmission() if (transmittingUsers.size() > 1) { for (auto* user : transmittingUsers) { user->doubleContentionWindow(); user->setBackoff(); } }
MIMO uses multiple antennas at both the transmitter and receiver to improve throughput and reliability. WiFi 4 introduced MIMO, and later standards expanded its capabilities.
How it's simulated in code:
- The number of spatial streams is a parameter in the transmission time calculation:
// In Packet::calculateTransmissionTime() and WiFi4/5/6AccessPoint::simulateTransmission() double txTime = packet->calculateTransmissionTime(/* bandwidth, streams, coding rate */); // Example for WiFi 4: double txTime = packet->calculateTransmissionTime(20.0, 2, 5.0/6.0); // 2 spatial streams
- Higher WiFi versions use more streams (see
wifi5.cpp
,wifi6.cpp
), increasing throughput.
OFDMA divides the channel into sub-channels, allowing multiple users to transmit simultaneously. This is a key feature of WiFi 6.
How it's simulated in code:
- In
src/wifi6.cpp
, the access point allocates resource units to multiple users in the same time slot:// WiFi6AccessPoint::simulateTransmission() std::vector<WiFi6User*> scheduledUsers = scheduleUsersForOFDMA(); for (auto* user : scheduledUsers) { // Each user transmits in parallel on a different resource unit auto packet = user->createPacket(); // ... }
- This allows several users to transmit in parallel, reducing latency and increasing efficiency compared to WiFi 4/5.
This project is open source and available under the MIT License.