What this module models
The module is the interface between an ns-3 process and a learning agent rather than a network model. OpenGymInterface on the C++ side is stepped through Notify() each step, and the transition is latched inside GetObservation so the reward is computed from state the action has actually reached. The C++ and Python sides share a protobuf schema over a Boost.Interprocess shared-memory segment; the handshake carries a protocol version, a module version and an FNV-1a schema digest, so a mismatch is reported as an error. Ns3AiMsgInterface exchanges fixed-layout structs and vectors through a pybind11 module. The fork targets Python 3.10 to 3.13, NumPy 2 and Gymnasium 1.0, and a CMake helper disables link-time optimization per pybind11 target to fix the ns-3.43 import failure.
An AI-RAN inference contract (AiranInferenceClient and AiranInferenceServer) exchanges length-prefixed protobuf over in-process FIFO or TCP channels, parses Triton config.pbtxt files, and ships deterministic mock runtimes for a beam index classifier and a CSI-to-precoder model; a native grpc++ transport is not implemented yet. The ns3_ai_ntn Python package provides four NTN environments (HandoverEnv, BeamMgmtEnv, SliceEnv, PowerCtrlEnv), which are synthetic and do not boot ns-3, plus a Stable-Baselines3 PPO trainer, a PyTorch Geometric GAT model and parameter-shared multi-agent wrappers. The environment that runs on a measured radio is OranNtnGymHandover in oran-ntn. Bundled upstream examples cover RL-TCP congestion control, Wi-Fi rate control, LTE CQI prediction and multi-BSS channel access.
Outputs
- Gymnasium 1.0 observations, actions and rewards over shared memory
- Fixed-layout struct and vector messages through the pybind11 message module
- AI-RAN inference requests and replies as length-prefixed protobuf
Key numbers
Stated in the module documentation, each with the conditions it was measured under.
- CPU cycles per C++ to Python transfer, ns3-gym versus the ns3-ai Gym interface (18x fewer)
- 117,017 vs 6,518 cycles
- CPU cycles per Python to C++ transfer, ns3-gym versus the ns3-ai Gym interface (17x fewer)
- 127,148 vs 7,584 cycles
- CPU cycles per RL decision, message interface versus pure C++ (libtorch)
- 733,702 vs 279,648 cycles
- mean serving SINR over 10 Gym steps of OranNtnGymHandover on the measured radio
- 15.71 dB
Examples (9)
- LEO path delay through the Gym interfaceA Starlink-like shell (SGP4) serves a terminal in Toulouse through a gateway in Madrid. Each step, ns-3 sends the up-link and feeder one-way delays to a Python agent over the Gym bridge, and the agent returns the end-to-end delay. Altitude, inclination and minimum elevation change the delays, the handovers and the satellites on the globe.
- LEO path delay with a shared structThe same Toulouse to Madrid LEO bent pipe, exchanged with the Python agent as a shared C struct: two one-way delays in, the end-to-end delay back, every answer checked. The run records the serving satellites and reports the delay range and handovers.
- LEO path delay with shared vectorsThe LEO bent-pipe delays batched three samples at a time in shared vectors, the vector variant of the ns3-ai message API. Reports the end-to-end delay range, handovers and outage, and records the pass on the globe.
- LTE CQI prediction with a Python modelAn LTE downlink with one fast-moving UE; the scheduler passes the CQI history to a Python predictor over shared memory, so predicted and reported CQI can be compared.
- Multi-BSS Wi-Fi with a learning agentDense 802.11ax residential deployment with overlapping BSSs; with drl=true a Python agent tunes the CCA sensitivity. Measure throughput and overlapping transmissions.
- Wi-Fi rate control, constant-rate agentWi-Fi stations behind a CSMA and point-to-point backbone, with the rate chosen by a Python agent through ns3-ai (raa=AiConstantRate). The constant-rate baseline.
- Wi-Fi rate control, Thompson samplingWi-Fi stations behind a CSMA and point-to-point backbone, with the rate chosen by a Python Thompson-sampling agent through ns3-ai (raa=AiThompsonSampling).
- RL TCP congestion control (Gym)TCP flows over a dumbbell bottleneck where a Python RL agent controls the congestion window through the ns3-ai Gym interface. Compare with the classic TCP variants.
- RL TCP congestion control (message API)TCP flows over a dumbbell bottleneck where a Python RL agent controls the congestion window through the ns3-ai shared-memory message interface.
Run it
In the browser
Pick an example in the run panel above, set its parameters and press Run. The console streams live and the result opens with KPI charts.
In the ns-3 console
The browser console accepts ns-3 style commands, for example
ns3 run "ns3ai_apb_gym --PrintHelp".Locally with Docker
The public image has the whole toolkit prebuilt. This runs
ns3ai_apb_gymwith its built-in defaults.docker run --rm -it uzairdocker69/ns3-ntn-toolkit:latest ./ns3 run "ns3ai_apb_gym"
Cite this
If you use this module, please cite the article that describes the toolkit: doi:10.1109/OJCOMS.2026.3745010.
M. Uzair, B. G. Aldahlan, A. A. Albar, H. Althumali and A. Alghammas, "ns3-ntn-toolkit: An integrated ns-3 platform for 6G non-terrestrial networks," IEEE Open Journal of the Communications Society, vol. 7, pp. 13440-13467, 2026, doi: 10.1109/OJCOMS.2026.3745010.
@article{uzair2026ns3ntntoolkit,
author = {Uzair, Muhammad and Aldahlan, Bassma G. and Albar, Ali A. and
Althumali, Huda and Alghammas, Adnan},
title = {ns3-ntn-toolkit: An Integrated ns-3 Platform for 6G
Non-Terrestrial Networks},
journal = {IEEE Open Journal of the Communications Society},
volume = {7},
pages = {13440--13467},
year = {2026},
doi = {10.1109/OJCOMS.2026.3745010}
}