Skip to content

David-A-T-M/RouterSimulator_cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

72 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Router Topology Simulator (C++) 🌐

RouterSimulator_cpp is a C++20 discrete-event network simulator that models packet-switched networking. It simulates a multi-router topology in which terminals generate traffic, routers forward packets hop-by-hop, and destination terminals reassemble the original data.

The simulation advances in discrete time units called ticks. On each tick, every router and every terminal executes a fixed pipeline of operations: draining output buffers, delivering locally-destined packets, ticking attached terminals, and processing newly arrived packets from the input buffer. Routing tables are recomputed periodically using Dijkstra's algorithm, with neighbor buffer occupancy used as edge cost. Includes automated testing, static analysis, and documentation generation.

What It Models

Concept Model
Data unit sent by a terminal Page β€” a logical message
Transmission unit on the wire Packet β€” a fragment of a Page
Addressing 16-bit IPAddress (upper 8 bits = router ID, lower 8 bits = terminal ID)
Node types Router (forwarding) and Terminal (end-host)
Buffering PacketBuffer β€” FIFO queue, optionally capacity-bounded
Path selection DijkstraAlgorithm β†’ RoutingTable
Reassembly at destination PageReassembler β€” collects fragments, detects completion
Topology Network β€” randomly generated, configurable
Simulation control Admin β€” runs ticks, collects NetworkStats

πŸš€ Key Features

  • CMake-based build system with library/executable separation and GoogleTest integration
  • Automated CI pipeline (GitHub Actions) with style checks, static analysis, builds, tests, and documentation validation
  • Static analysis via cppcheck with exhaustive checks and HTML report generation
  • Code style enforcement using clang-format with a Google-based profile
  • Doxygen documentation with strict warning policies

πŸ› οΈ Technical Overview

The project follows a solid Object-Oriented Programming (OOP) approach to ensure data integrity:

  • Router Class: Represents an individual network node. It manages its own identification and a local routing table containing its neighbors. Each router maintains separate buffers for input, output, and local delivery with configurable capacities and bandwidth constraints.

  • Admin Logic: The core orchestrator that handles the global graph structure. It ensures that when a router is deleted, all incoming and outgoing links from other routers are also wiped to prevent data inconsistency. Admin also controls simulation timing and generates periodic reports.

  • Network Class: Central coordinator managing the entire topology, traffic generation, and packet flow simulation. It maintains network statistics, recalculates routing tables periodically using Dijkstra's algorithm, and orchestrates the tick-by-tick simulation.

  • Terminal Class: End-host devices that generate traffic, fragment pages into packets, and reassemble received packets. Terminals are the source and destination of all network traffic.

  • Dijkstra Algorithm: Implements shortest path computation with a dynamic cost metric based on buffer occupancy, enabling load-aware routing that naturally avoids congested routers.

Component Overview

The simulator is organized around five primary classes with supporting types and utilities.

Component Header Role
Network include/core/Network.h Top-level orchestrator; owns all routers, runs the simulation loop, triggers route recalculation
Router include/core/Router.h Packet forwarding node; manages terminals, neighbor connections, and per-direction buffers
Terminal include/core/Terminal.h End device; generates traffic, queues outgoing packets, reassembles incoming pages
PacketBuffer include/core/PacketBuffer.h FIFO queue used by both Router and Terminal for all packet buffering
PageReassembler include/core/PageReassembler.h Collects packet fragments at a Terminal and detects page completion
DijkstraAlgorithm include/algorithms/Dijkstra.h Computes shortest-path routing tables for all routers using neighbor buffer usage as edge cost
Admin include/core/Admin.h Monitoring interface; calls Network::simulate() and prints NetworkStats reports

Supporting value types β€” IPAddress, Packet, Page, and RoutingTable

Sequence Diagram

Screenshot From 2026-02-28 09-38-00

πŸ“ Architecture Overview

Layered Architecture

   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚                    APPLICATION LAYER                    β”‚
   β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
   β”‚  β”‚                      main.cpp                     β”‚  β”‚
   β”‚  β”‚             Admin (Simulation Control)            β”‚  β”‚
   β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚              ORCHESTRATION LAYER              β”‚
        β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
        β”‚  β”‚        Network (Topology Manager)       β”‚  β”‚
        β”‚  β”‚        β€’ Initializes topology           β”‚  β”‚
        β”‚  β”‚        β€’ Coordinates tick execution     β”‚  β”‚
        β”‚  β”‚        β€’ Collects statistics            β”‚  β”‚
        β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
           β”‚                    β”‚                    β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”
    β”‚   ROUTERS    β”‚  β”‚     TERMINALS     β”‚  β”‚  ALGORITHMS   β”‚
    β”‚              β”‚  β”‚                   β”‚  β”‚               β”‚
    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
    β”‚  β”‚ Input  β”‚  β”‚  β”‚  β”‚ Page Buffer β”‚  β”‚  β”‚ β”‚ Dijkstra  β”‚ β”‚
    β”‚  β”‚ Buffer β”‚  β”‚  β”‚  β”‚             β”‚  β”‚  β”‚ β”‚           β”‚ β”‚
    β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€  β”‚  β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€  β”‚  β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
    β”‚  β”‚Routing β”‚  β”‚  β”‚  β”‚  Generates  β”‚  β”‚  β”‚               β”‚
    β”‚  β”‚ Table  β”‚  β”‚  β”‚  β”‚  Traffic    β”‚  β”‚  β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
    β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€  β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚ β”‚Reassemblerβ”‚ β”‚
    β”‚  β”‚ Output β”‚  β”‚  β”‚                   β”‚  β”‚ β”‚           β”‚ β”‚
    β”‚  β”‚ Buffer β”‚  β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
    β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€  β”‚  β”‚  β”‚Reassembler  β”‚  β”‚  β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
    β”‚  β”‚ Local  β”‚  β”‚  β”‚  β”‚ (per page)  β”‚  β”‚  β”‚ β”‚ Routing   β”‚ β”‚
    β”‚  β”‚ Buffer β”‚  β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚ β”‚ Tables    β”‚ β”‚
    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚                   β”‚  β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

                            CORE LAYER

   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚                    DATA STRUCTURE LAYER                     β”‚
   β”‚                                                             β”‚
   β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
   β”‚  β”‚ List<T>    β”‚  β”‚ Packet       β”‚  β”‚ IPAddress           β”‚  β”‚
   β”‚  β”‚ (Generic   β”‚  β”‚              β”‚  β”‚ (16-bit address)    β”‚  β”‚
   β”‚  β”‚  linked    β”‚  β”‚ Transmission β”‚  β”‚ Router ID | Term ID β”‚  β”‚
   β”‚  β”‚  list)     β”‚  β”‚ unit         β”‚  β”‚                     β”‚  β”‚
   β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
   β”‚                                                             β”‚
   β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                        β”‚
   β”‚  β”‚ Page          β”‚  β”‚ RoutingTable β”‚                        β”‚
   │  │ Logical       │  │ Destination→ │                        │
   β”‚  β”‚ message       β”‚  β”‚ NextHop Map  β”‚                        β”‚
   β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                        β”‚
   β”‚                                                             β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🚧 Planned Enhancements

  • Dynamic Topology Management: Add or remove routers and establish connections (links) in real-time.
  • File Persistence: Load pre-configured network topologies and export simulation results.
  • Network Analysis: Analyze connectivity, path costs, and bottlenecks.
  • Advanced Routing: Multiple routing strategies and multicast support.
  • Performance Optimizations: Improved algorithms and parallel processing.

πŸ“‹ Prerequisites

  • CMake 3.10+
  • C++20 compiler
  • GoogleTest (fetched automatically by CMake)
  • Doxygen (optional, for documentation target)
  • clang-format, cppcheck (optional, for local checks)

Quick Start

Build

cmake -B build
cmake --build build

Run

./build/RouterSimulator_cpp

Run Tests

ctest --test-dir build

Static Analysis

cmake --build build --target check

Documentation

cmake --build build --target doc

Project Structure

RouterSimulator_cpp/
β”œβ”€β”€ include/
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”œβ”€β”€ IPAddress.h          # IPAddress type
β”‚   β”‚   β”œβ”€β”€ Packet.h             # Packet type
β”‚   β”‚   β”œβ”€β”€ Page.h               # Page type
β”‚   β”‚   β”œβ”€β”€ PacketBuffer.h       # FIFO packet queue
β”‚   β”‚   β”œβ”€β”€ RoutingTable.h       # Next-hop table
β”‚   β”‚   β”œβ”€β”€ Router.h             # Router node
β”‚   β”‚   β”œβ”€β”€ Terminal.h           # End-host node
β”‚   β”‚   β”œβ”€β”€ Network.h            # Topology + simulation loop
β”‚   β”‚   └── Admin.h              # Simulation runner + reporter
β”‚   β”œβ”€β”€ algorithms/
β”‚   β”‚   └── Dijkstra.h           # Routing table computation
β”‚   └── structures/
β”‚       └── list.h               # Generic singly-linked list
β”œβ”€β”€ src/
β”‚   └── core/                    # Implementations of the above
β”œβ”€β”€ tests/
β”‚   └── test_*.cpp               # Google Test suites per component
β”œβ”€β”€ main.cpp                     # Entry point
└── CMakeLists.txt               # Build definition

Build Targets

Target Description
RouterLib Static library from src/*.cpp
RouterSimulator_cpp Main executable linked with RouterLib
test_* Test executables (one per tests/test_*.cpp)
check Run cppcheck static analysis
doc Generate Doxygen HTML docs (if Doxygen is available)

CI Pipeline

Three parallel jobs run on pushes/PRs to main, dev, and feat/** branches:

  1. style-and-static-analysis: clang-format check and cppcheck with HTML report upload
  2. build-and-test: CMake configure, build, and CTest execution
  3. documentation: Doxygen generation with warning enforcement and artifact upload on failure

Code Style

  • Based on Google style with customizations
  • Column limit: 100
  • Indent with four spaces, no tabs
  • Pointer alignment: left (int* p)
  • Access modifier offset: -4

Notes

  • GoogleTest is fetched automatically via FetchContent during CMake configuration
  • The check target runs cppcheck with exhaustive settings and will fail the build on findings
  • Doxygen warnings are treated strictly; undocumented entities and missing parameter docs cause failures
  • CI installs tools via apt-get and uses reusable actions for style, build, and documentation steps

Wiki pages you might want to explore:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors