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.
| 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 |
- 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
cppcheckwith exhaustive checks and HTML report generation - Code style enforcement using
clang-formatwith a Google-based profile - Doxygen documentation with strict warning policies
The project follows a solid Object-Oriented Programming (OOP) approach to ensure data integrity:
-
RouterClass: 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. -
AdminLogic: 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. -
NetworkClass: 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. -
TerminalClass: 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.
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
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 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 β β
β βββββββββββββββββ ββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- 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.
- CMake 3.10+
- C++20 compiler
- GoogleTest (fetched automatically by CMake)
- Doxygen (optional, for documentation target)
- clang-format, cppcheck (optional, for local checks)
cmake -B build
cmake --build build./build/RouterSimulator_cppctest --test-dir buildcmake --build build --target checkcmake --build build --target docRouterSimulator_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
| 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) |
Three parallel jobs run on pushes/PRs to main, dev, and feat/** branches:
- style-and-static-analysis:
clang-formatcheck andcppcheckwith HTML report upload - build-and-test: CMake configure, build, and CTest execution
- documentation: Doxygen generation with warning enforcement and artifact upload on failure
- Based on Google style with customizations
- Column limit: 100
- Indent with four spaces, no tabs
- Pointer alignment: left (
int* p) - Access modifier offset: -4
- GoogleTest is fetched automatically via
FetchContentduring CMake configuration - The
checktarget runscppcheckwith 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-getand uses reusable actions for style, build, and documentation steps
Wiki pages you might want to explore: