Skip to content

mjmaher987/Packet-Host-Router-Simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📡 Packet–Host–Router Simulation

A discrete-event simulation of a computer network, comparing how three packet-scheduling policies — FIFO, NPPS, and WRR — affect delay, utilization, and packet loss.

At the intersection of Computer Simulation and Computer Networks.


📋 Overview

💡 In plain English — what is this? Imagine packets (small chunks of data) arriving at a router faster than it can forward them. They pile up in a queue, and the router must decide which packet to send next. This project simulates that scenario on a computer and measures how different "who-goes-next" rules perform.

💡 What is a discrete-event simulation? Instead of running in real time, the program jumps from one event to the next (a packet arrives, a packet finishes service, …), updating the system state at each event. This lets us model hours of network traffic in a fraction of a second and experiment safely.

The simulated system:

flowchart LR
    H[Host<br/>generates packets] -->|Poisson arrivals| Q[Router queue<br/>limited size → overflow = dropped]
    Q -->|scheduling policy<br/>FIFO · NPPS · WRR| P1[Processor 1]
    Q --> P2[Processor 2]
    P1 --> D[Done]
    P2 --> D
    Q -.->|queue full| X[❌ Dropped]
Loading
  • Packets arrive with Poisson-distributed inter-arrival times and have Exponential service times (classic queueing-theory assumptions).
  • Each packet has one of 3 priority levels.
  • The router has a limited-size queue — if it's full, new packets are dropped (packet loss).

⚙️ The Three Scheduling Policies

💡 The whole point of the project is to compare how the router picks the next packet.

Policy What it does In plain English
FIFO (First-In-First-Out) Serves packets in arrival order A single fair line at the bank — first come, first served
NPPS (Non-Preemptive Priority) Always serves the highest-priority waiting packet next, but never interrupts a packet already in service VIPs jump the queue, but you don't yank someone off the counter mid-transaction
WRR (Weighted Round-Robin) Keeps a separate queue per priority and cycles through them, giving more "turns" to higher priorities Three lines served in rotation, with the important line getting more turns

📊 Metrics Measured

The simulation tracks, for each policy:

  • Average queue length over time (how congested the router gets)
  • Average time wasted in queues (total and per priority) — i.e. delay
  • Processor utilization (how busy the servers are)
  • Number of dropped packets (packet loss)
  • CDF of high-priority packet delay — a proxy for CDV (Cell Delay Variation / jitter)


Left: the queue grows over time as traffic exceeds capacity. Right: processor utilization quickly saturates near 100%.


CDF of high-priority packet delay — how long important packets wait.


🏆 Results — which policy wins?

Across this run of 505 packets, WRR dropped the fewest packets:

Policy Packets dropped Drop rate
FIFO 301 59.6%
NPPS 304 60.2%
WRR 291 57.6%

Conclusion: WRR is the best of the three for this setup, giving the lowest packet loss while still respecting priorities. (The system is intentionally overloaded — hence high drop rates across the board — to stress-test the policies.)

💡 Want higher utilization / fewer drops? Add more processors, increase the queue size, or speed up service — the report discusses these trade-offs in detail.


🗂️ Repository Structure

Packet-Host-Router-Simulation/
├── Source Codes/
│   ├── main.py                       # the discrete-event simulator
│   ├── Router_Host_Network_Simulation - 020407 - 2113.ipynb  # run + visualizations
│   ├── fifo.csv / npps.csv / wrr.csv # per-packet results for each policy
├── Report/                           # full write-up (PDF + DOCX)
├── Network_CS_Project.pdf            # original project specification
└── README.md

🚀 Running the Simulation

git clone https://github.com/mjmaher987/Packet-Host-Router-Simulation.git
cd Packet-Host-Router-Simulation/"Source Codes"

pip install numpy matplotlib pandas

# run the simulator
python main.py

To switch policies, change the SERVICE_POLICY line in main.py:

SERVICE_POLICY = [FIFO, WRR, NPPS][2]   # index 0=FIFO, 1=WRR, 2=NPPS

For the full run with all the comparison plots, open the notebook Router_Host_Network_Simulation - 020407 - 2113.ipynb.


🛠️ Tech Stack

  • Language: Python
  • Modeling: custom discrete-event simulation; Poisson arrivals & Exponential service times
  • Analysis/Plots: NumPy, Matplotlib, pandas (CSV outputs)

About

Intersection of Computer Simulation and Computer Networks

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors