How broadcom/csg-htsim works
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: main_tcp.cpp Scenario mains · switch.h Switch queues · logfile.h Logging and parse · topology.h Topologies
Components 20
Simulation core
Event-driven engine, packet models, queues, and protocol logic.
- Event scheduler · Drives simulated time and scheduled events.
sim/eventlist.h - Clock and RNG · Timekeeping and randomness used across simulations.
sim/clock.h - Network fabric · Links packets, pipes, and routes through the simulated fabric.
sim/network.h - Routing table · Builds and resolves routes between endpoints.
sim/routetable.h - Switch queues · Forwarding, buffering, ECN, priority, and lossless queue disciplines.
sim/switch.h - TCP family · TCP, DCTCP, and related transfer logic.
sim/tcp.h - NDP family · NDP, tunnel, and transfer control logic.
sim/ndp.h - Swift family · Swift variants and scheduler/transfer behavior.
sim/swift.h - HPCC · HPCC transport model and packet format.
sim/hpcc.h - RoCE · RoCE packet and control model.
sim/roce.h - EQDS · EQDS transport model, packets, and logging hooks.
sim/eqds.h - STRACK · STRACK transport and packet model.
sim/strack.h - MTCP · Multipath TCP and subflow control.
sim/mtcp.h - Logging and parse · Logfile, logger helpers, and output parsing for rates and traces.
sim/logfile.h
Datacenter scenarios
Topology models, workload matrices, and scenario entry points.
- Topologies · Fat-tree, VL2, dragonfly, BCube, star, and generic fabric models.
sim/datacenter/topology.h - Conn. matrices · Connection-matrix files and generators for incast, permutation, all-to-all, and all-reduce.
sim/datacenter/connection_matrix.h - Scenario mains · 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 · Curated example runs, plots, and processing scripts under sim/EXAMPLES.
sim/EXAMPLES - Experiments · Research-style experiment folders with run scripts, plots, and workload files.
experiments
Validation
Scenario-level regression tests and golden references.
- Regression tests · Scenario-level tests with config JSON and golden reference outputs.
sim/tests/main.cpp
Connections 25
- 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.