Skip to content
Module · ns3-ai-ntn

ns3-ai-ntn: a Gymnasium 1.0 reinforcement-learning bridge for ns-3

ns3-ai-ntn is a fork of the ns3-ai module that connects ns-3.49 simulations to Python agents through Gymnasium 1.0 over shared memory, with a versioned handshake that rejects schema mismatches. It adds an AI-RAN inference contract over in-process or TCP channels and a Python package of NTN reinforcement-learning environments and trainers.

Run it in the browser

Choose an example, set its parameters and run the real ns-3 binary on this server. The scene shows the configured geometry before the run and the results after it.

LEO path delay through the Gym interface

A 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.

~10 sns3ai_apb_gym
The server starts the paired Python agent together with the simulation.
Parameters
Walker shell altitude (km)
Walker shell inclination (deg)
Minimum elevation at both ground ends (deg)
Exchanges with the Python agent
Time between samples of the pass (s)
Scene: ns3-ai agents
The interactive 3D globe loads here.

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 cyclesupstream ns3-ai benchmark on the RL-TCP example, 6 seeds, mean over seeds; measured by the upstream authors, not re-measured on this fork
CPU cycles per Python to C++ transfer, ns3-gym versus the ns3-ai Gym interface (17x fewer)
127,148 vs 7,584 cyclesupstream ns3-ai benchmark on the RL-TCP example, 6 seeds; not re-measured on this fork
CPU cycles per RL decision, message interface versus pure C++ (libtorch)
733,702 vs 279,648 cyclesupstream ns3-ai benchmark on the RL-TCP example, 6 seeds; not re-measured on this fork
mean serving SINR over 10 Gym steps of OranNtnGymHandover on the measured radio
15.71 dBone 12 s run of oran-ntn-gym-handover-example in in-process mode, 3 satellites, 2 UEs

Examples (9)

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_gym with its built-in defaults.

    shell
    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.

BibTeX
@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}
}