# broadcom/csg-htsim architecture

> Architecture diagram of the GitHub repository broadcom/csg-htsim, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/broadcom/csg-htsim
- Repository: https://github.com/broadcom/csg-htsim

## Overview

1. **Overall shape**
   - This repository is a **single-process C++ discrete-event network simulator** (`htsim`), plus a large set of **scenario drivers, experiments, and plotting scripts**.
   - The main architecture is: **topology + traffic matrix + protocol model + queue/switch model + event scheduler + logging/post-processing**.

2. **Core simulation kernel**
   - The `sim/` directory contains the reusable simulation engine.
   - Key runtime primitives are `eventlist`, `clock`, `rng`, `pipe`, `network`, `route/routetable`, and `trigger/callback` support.
   - These components provide time advancement, packet delivery, scheduling, and instrumentation for all protocol variants.

3. **Protocol model layer**
   - The simulator models multiple transport/control families: **TCP, DCTCP, NDP, Swift, HPCC, RoCE, EQDS, MPTCP/MTCP, and STRACK**.
   - Each protocol has its own implementation files and packet types, such as `tcppacket`, `ndppacket`, `swiftpacket`, `hpccpacket`, `rocepacket`, and related transfer/control classes.
   - This layer is where congestion-control behavior and sender/receiver logic are separated from the network fabric.

4. **Queueing and switch behavior**
   - A major architectural boundary is the **switch/queue subsystem**, with many queue disciplines: `ecnqueue`, `prioqueue`, `faircompositequeue`, `pullqueue`, `lossless`, `randomqueue`, and priority/composite variants.
   - Switch-level forwarding and buffering behavior is factored into `switch`, `queue`, `compositequeue`, `compositeprioqueue`, `ecnprioqueue`, and related classes.
   - This is where link congestion, ECN marking, PFC/lossless behavior, and forwarding policy are modeled.

5. **Datacenter topology subsystem**
   - `sim/datacenter/` holds the **topology models** used by the experiments: fat-tree, oversubscribed fat-tree, multihomed fat-tree, VL2, dragonfly, BCube/CamCube, star, and generic topologies.
   - Topology classes define how hosts, switches, routes, and links are wired together and how traffic can traverse the fabric.
   - This layer is the main architectural boundary between “network shape” and “transport behavior.”

6. **Traffic/connection matrix inputs**
   - Datacenter scenarios are driven by **connection matrix files** (`*.cm`) and generators in `sim/datacenter/connection_matrices/`.
   - These matrices define who talks to whom, when, and with what flow sizes or permutations, making them the primary workload description for experiments.
   - The connection-matrix layer feeds the transport/topology layer with specific communication patterns such as incast, permutation, all-to-all, and all-reduce.

7. **Entry-point binaries**
   - The `sim/datacenter/main_*.cpp` files are **scenario-specific executables** that combine a protocol model with a topology and a traffic pattern.
   - There are separate mains for TCP, NDP, HPCC, EQDS, RoCE, Swift, and some legacy/alternate variants.
   - This indicates the simulator is built as a family of focused binaries rather than one monolithic app with runtime plugin loading.

8. **Logging, metrics, and output processing**
   - Simulation output is written through `logfile`, `loggers`, `parse_output`, and protocol-specific logger helpers.
   - Outputs are then post-processed by Python scripts in the examples and experiments directories to generate CDFs, overlap plots, sensitivity curves, and comparison charts.
   - The data flow is: **simulation run → raw logs/rates → Python processing → gnuplot/PDF figures**.

9. **Experiments directory**
   - `experiments/` contains curated reproductions of research-style scenarios, especially for **fat-tree all-to-all** and **fat-tree spraying** cases.
   - Each subexperiment typically includes a run script, a connection matrix or workload file, a gnuplot script, and the resulting PDF.
   - These folders show the repo’s intended use: controlled comparison of transport/queueing designs under fixed workloads.

10. **Test harness**
   - `sim/tests/` contains automated regression tests for specific topology/protocol combinations such as dumbbell, bidirectional, multipath, and multihop cases.
   - Tests use `test_config.json` inputs and `default.ref` golden outputs, so the simulator is validated by comparing generated traces/metrics against expected results.
   - This is a useful architectural boundary: the simulator core is exercised through scenario-level integration tests rather than unit-only checks.

11. **Legacy and comparative models**
   - `sim/datacenter/old_tests/` preserves many older scenario drivers, including DCTCP, NDP, Swift, TCP, and lossless/lossy variants.
   - Their presence suggests the codebase evolved by accreting protocol models and scenario reproductions over time, while keeping older experiment definitions around for reference.

12. **Build and runtime environment**
   - The simulator is standard C++ and builds with `make`; there is a separate `Makefile` in `sim/` and one in `sim/datacenter/`.
   - Experiments assume **bash, Python 3, and gnuplot** for orchestration and visualization.
   - No external services or distributed runtime are involved; all behavior is simulated locally and deterministically from input files.

13. **How to draw the architecture**
   - A good diagram would place **scenario drivers/experiments** on the left, feeding **connection matrices and topology definitions** into the **core event-driven simulator** in the center.
   - Inside the simulator, show **transport protocols** interacting with **queue/switch models** over **links/routes**, all coordinated by the **event scheduler**.
   - On the right, show **logging/output processing** leading to **plots and PDFs**, with **tests** as a parallel validation path using golden references.

Main entry points: [`sim/datacenter/main_tcp.cpp`](https://github.com/broadcom/csg-htsim/blob/master/sim/datacenter/main_tcp.cpp) (Scenario mains), [`sim/switch.h`](https://github.com/broadcom/csg-htsim/blob/master/sim/switch.h) (Switch queues), [`sim/logfile.h`](https://github.com/broadcom/csg-htsim/blob/master/sim/logfile.h) (Logging and parse), [`sim/datacenter/topology.h`](https://github.com/broadcom/csg-htsim/blob/master/sim/datacenter/topology.h) (Topologies)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_core["Simulation core"]
  node_node_eventlist(("Event scheduler<br/>core runtime<br/>[eventlist.h]"))
  node_node_time_rng(("Clock and RNG<br/>runtime support<br/>[clock.h]"))
  node_node_network["Network fabric<br/>packet flow<br/>[network.h]"]
  node_node_routing["Routing table<br/>[routetable.h]"]
  node_node_switches["Switch queues<br/>queueing<br/>[switch.h]"]
  node_node_tcp["TCP family<br/>transport<br/>[tcp.h]"]
  node_node_ndp["NDP family<br/>transport<br/>[ndp.h]"]
  node_node_swift["Swift family<br/>transport<br/>[swift.h]"]
  node_node_hpcc["HPCC<br/>transport<br/>[hpcc.h]"]
  node_node_roce["RoCE<br/>transport<br/>[roce.h]"]
  node_node_eqds["EQDS<br/>transport<br/>[eqds.h]"]
  node_node_strack["STRACK<br/>transport<br/>[strack.h]"]
  node_node_mtcp["MTCP<br/>transport<br/>[mtcp.h]"]
  node_node_logging["Logging and parse<br/>output pipeline<br/>[logfile.h]"]
end

subgraph group_group_dc["Datacenter scenarios"]
  node_node_topologies["Topologies<br/>datacenter topology<br/>[topology.h]"]
  node_node_connmats["Conn. matrices<br/>workload input"]
  node_node_main_bins["Scenario mains<br/>entry binaries<br/>[main_tcp.cpp]"]
end

subgraph group_group_tools["Experiments and output"]
  node_node_examples["Examples<br/>scripts"]
  node_node_experiments["Experiments<br/>repro cases"]
end

subgraph group_group_tests["Validation"]
  node_node_tests["Regression tests<br/>validation<br/>[main.cpp]"]
end

node_node_eventlist -->|"schedules"| node_node_network
node_node_time_rng -->|"drives"| node_node_eventlist
node_node_routing -->|"installs routes"| node_node_network
node_node_topologies -->|"defines paths"| node_node_routing
node_node_topologies -->|"contains"| node_node_switches
node_node_connmats -->|"feeds workload"| node_node_main_bins
node_node_main_bins -->|"selects fabric"| node_node_topologies
node_node_main_bins -->|"may use"| node_node_tcp
node_node_main_bins -->|"may use"| node_node_ndp
node_node_main_bins -->|"may use"| node_node_swift
node_node_main_bins -->|"may use"| node_node_hpcc
node_node_main_bins -->|"may use"| node_node_roce
node_node_main_bins -->|"may use"| node_node_eqds
node_node_main_bins -->|"may use"| node_node_strack
node_node_main_bins -->|"may use"| node_node_mtcp
node_node_tcp -->|"competes in queues"| node_node_switches
node_node_ndp -->|"competes in queues"| node_node_switches
node_node_swift -->|"competes in queues"| node_node_switches
node_node_hpcc -->|"competes in queues"| node_node_switches
node_node_logging -->|"feeds plots"| node_node_examples
node_node_logging -->|"feeds plots"| node_node_experiments
node_node_tests -->|"exercises"| node_node_main_bins
node_node_examples -->|"runs"| node_node_main_bins
node_node_experiments -->|"runs"| node_node_main_bins
node_node_tests -->|"checks output"| node_node_logging

click node_node_eventlist "https://github.com/broadcom/csg-htsim/blob/master/sim/eventlist.h"
click node_node_time_rng "https://github.com/broadcom/csg-htsim/blob/master/sim/clock.h"
click node_node_network "https://github.com/broadcom/csg-htsim/blob/master/sim/network.h"
click node_node_routing "https://github.com/broadcom/csg-htsim/blob/master/sim/routetable.h"
click node_node_switches "https://github.com/broadcom/csg-htsim/blob/master/sim/switch.h"
click node_node_tcp "https://github.com/broadcom/csg-htsim/blob/master/sim/tcp.h"
click node_node_ndp "https://github.com/broadcom/csg-htsim/blob/master/sim/ndp.h"
click node_node_swift "https://github.com/broadcom/csg-htsim/blob/master/sim/swift.h"
click node_node_hpcc "https://github.com/broadcom/csg-htsim/blob/master/sim/hpcc.h"
click node_node_roce "https://github.com/broadcom/csg-htsim/blob/master/sim/roce.h"
click node_node_eqds "https://github.com/broadcom/csg-htsim/blob/master/sim/eqds.h"
click node_node_strack "https://github.com/broadcom/csg-htsim/blob/master/sim/strack.h"
click node_node_mtcp "https://github.com/broadcom/csg-htsim/blob/master/sim/mtcp.h"
click node_node_topologies "https://github.com/broadcom/csg-htsim/blob/master/sim/datacenter/topology.h"
click node_node_connmats "https://github.com/broadcom/csg-htsim/blob/master/sim/datacenter/connection_matrix.h"
click node_node_main_bins "https://github.com/broadcom/csg-htsim/blob/master/sim/datacenter/main_tcp.cpp"
click node_node_examples "https://github.com/broadcom/csg-htsim/tree/master/sim/EXAMPLES"
click node_node_experiments "https://github.com/broadcom/csg-htsim/tree/master/experiments"
click node_node_logging "https://github.com/broadcom/csg-htsim/blob/master/sim/logfile.h"
click node_node_tests "https://github.com/broadcom/csg-htsim/blob/master/sim/tests/main.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node_eventlist,node_node_time_rng,node_node_network,node_node_routing,node_node_switches,node_node_tcp,node_node_ndp,node_node_swift,node_node_hpcc,node_node_roce,node_node_eqds,node_node_strack,node_node_mtcp,node_node_logging toneBlue
class node_node_topologies,node_node_connmats,node_node_main_bins toneAmber
class node_node_examples,node_node_experiments toneMint
class node_node_tests toneRose
```

## Components

### Simulation core

Event-driven engine, packet models, queues, and protocol logic.

- [Event scheduler](https://github.com/broadcom/csg-htsim/blob/master/sim/eventlist.h): core runtime · Drives simulated time and scheduled events. · `sim/eventlist.h`
- [Clock and RNG](https://github.com/broadcom/csg-htsim/blob/master/sim/clock.h): runtime support · Timekeeping and randomness used across simulations. · `sim/clock.h`
- [Network fabric](https://github.com/broadcom/csg-htsim/blob/master/sim/network.h): packet flow · Links packets, pipes, and routes through the simulated fabric. · `sim/network.h`
- [Routing table](https://github.com/broadcom/csg-htsim/blob/master/sim/routetable.h): routing · Builds and resolves routes between endpoints. · `sim/routetable.h`
- [Switch queues](https://github.com/broadcom/csg-htsim/blob/master/sim/switch.h): queueing · Forwarding, buffering, ECN, priority, and lossless queue disciplines. · `sim/switch.h`
- [TCP family](https://github.com/broadcom/csg-htsim/blob/master/sim/tcp.h): transport · TCP, DCTCP, and related transfer logic. · `sim/tcp.h`
- [NDP family](https://github.com/broadcom/csg-htsim/blob/master/sim/ndp.h): transport · NDP, tunnel, and transfer control logic. · `sim/ndp.h`
- [Swift family](https://github.com/broadcom/csg-htsim/blob/master/sim/swift.h): transport · Swift variants and scheduler/transfer behavior. · `sim/swift.h`
- [HPCC](https://github.com/broadcom/csg-htsim/blob/master/sim/hpcc.h): transport · HPCC transport model and packet format. · `sim/hpcc.h`
- [RoCE](https://github.com/broadcom/csg-htsim/blob/master/sim/roce.h): transport · RoCE packet and control model. · `sim/roce.h`
- [EQDS](https://github.com/broadcom/csg-htsim/blob/master/sim/eqds.h): transport · EQDS transport model, packets, and logging hooks. · `sim/eqds.h`
- [STRACK](https://github.com/broadcom/csg-htsim/blob/master/sim/strack.h): transport · STRACK transport and packet model. · `sim/strack.h`
- [MTCP](https://github.com/broadcom/csg-htsim/blob/master/sim/mtcp.h): transport · Multipath TCP and subflow control. · `sim/mtcp.h`
- [Logging and parse](https://github.com/broadcom/csg-htsim/blob/master/sim/logfile.h): output pipeline · Logfile, logger helpers, and output parsing for rates and traces. · `sim/logfile.h`

### Datacenter scenarios

Topology models, workload matrices, and scenario entry points.

- [Topologies](https://github.com/broadcom/csg-htsim/blob/master/sim/datacenter/topology.h): datacenter topology · Fat-tree, VL2, dragonfly, BCube, star, and generic fabric models. · `sim/datacenter/topology.h`
- [Conn. matrices](https://github.com/broadcom/csg-htsim/blob/master/sim/datacenter/connection_matrix.h): workload input · Connection-matrix files and generators for incast, permutation, all-to-all, and all-reduce. · `sim/datacenter/connection_matrix.h`
- [Scenario mains](https://github.com/broadcom/csg-htsim/blob/master/sim/datacenter/main_tcp.cpp): entry binaries · Protocol-specific datacenter executables that combine topology and workload. · `sim/datacenter/main_tcp.cpp`

### Experiments and output

Reproducible experiment folders, scripts, and post-processing.

- [Examples](https://github.com/broadcom/csg-htsim/tree/master/sim/EXAMPLES): scripts · Curated example runs, plots, and processing scripts under sim/EXAMPLES. · `sim/EXAMPLES`
- [Experiments](https://github.com/broadcom/csg-htsim/tree/master/experiments): repro cases · Research-style experiment folders with run scripts, plots, and workload files. · `experiments`

### Validation

Scenario-level regression tests and golden references.

- [Regression tests](https://github.com/broadcom/csg-htsim/blob/master/sim/tests/main.cpp): validation · Scenario-level tests with config JSON and golden reference outputs. · `sim/tests/main.cpp`

## Connections

- Event scheduler → Network fabric: schedules · Advances events that move packets through the network.
- Clock and RNG → Event scheduler: drives · Provides time and randomization for simulation execution.
- Routing table → Network fabric: installs routes · Resolves paths used by packet delivery.
- Topologies → Routing table: defines paths · Topology objects create links and route structure.
- Topologies → Switch queues: contains · Topology builds switch and host fabric elements.
- Conn. matrices → Scenario mains: feeds workload · Connection matrices describe which flows scenarios launch.
- Scenario mains → Topologies: selects fabric · Scenario mains instantiate a specific topology.
- Scenario mains → TCP family: may use · One family of scenario binaries uses TCP/DCTCP.
- Scenario mains → NDP family: may use · One family of scenario binaries uses NDP variants.
- Scenario mains → Swift family: may use · One family of scenario binaries uses Swift variants.
- Scenario mains → HPCC: may use · One family of scenario binaries uses HPCC.
- Scenario mains → RoCE: may use · One family of scenario binaries uses RoCE.
- Scenario mains → EQDS: may use · One family of scenario binaries uses EQDS.
- Scenario mains → STRACK: may use · One family of scenario binaries uses STRACK.
- Scenario mains → MTCP: may use · One family of scenario binaries uses MPTCP/MTCP.
- TCP family → Switch queues: competes in queues · TCP-family flows interact with switch buffering and marking.
- NDP family → Switch queues: competes in queues · NDP-family flows interact with switch buffering and marking.
- Swift family → Switch queues: competes in queues · Swift-family flows interact with switch buffering and marking.
- HPCC → Switch queues: competes in queues · HPCC interacts with fabric queueing and congestion signals.
- Logging and parse → Examples: feeds plots · Simulation output is post-processed into charts and PDFs.
- Logging and parse → Experiments: feeds plots · Experiment scripts consume logs and produce figures.
- Regression tests → Scenario mains: exercises · Regression tests run scenario binaries under fixed configs.
- Examples → Scenario mains: runs · Example scripts invoke the simulator with curated workloads.
- Experiments → Scenario mains: runs · Experiment folders orchestrate scenario binaries and post-processing.
- Regression tests → Logging and parse: checks output · Golden references validate emitted traces and metrics.
