Skip to content

laxman-gupta1006/WiFi_Communication_Simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WiFi Communication Technology Simulator

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.

Project Overview

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.

Architecture

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.

File Structure

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

Prerequisites

  • C++17 or later compiler (e.g., g++)
  • make

Building the Project

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.

Usage

Run the simulator from the project root:

make run

Or run the executable directly:

./build/wifi_simulator

Menu Options

  1. Run Simulation: Executes performance simulation for all WiFi standards and user scenarios
  2. View Simulation Results: Displays results from the last run
  3. Exit: Quit the program

Simulation Parameters

  • User Scenarios: 1, 10, 100 users
  • Metrics: Throughput, Average Latency, Maximum Latency
  • Iterations: 100 per scenario (configurable in code)

How It Works

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

Extending the Simulation

To add a new WiFi technology:

  1. Create a new header/source (e.g., wifi7.h, wifi7.cpp)
  2. Implement new User and Access Point classes
  3. Register the new technology in main.cpp
  4. Add to the build system if needed

Key Wireless Technologies

CSMA/CA (Carrier Sense Multiple Access with Collision Avoidance)

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 in include/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 (Multiple Input, Multiple Output)

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 (Orthogonal Frequency Division Multiple Access)

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.

License

This project is open source and available under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published