Reinforcement learning meets packet simulation, finally
ns3-gym bridges OpenAI Gym and ns-3 so you can train RL agents against actual network stacks, not toy environments.

What it does ns3-gym is a C++ framework that wraps the ns-3 network simulator as an OpenAI Gym environment. You implement six callback functions in your ns-3 simulation—observation space, action space, reward logic, and so on—and Python RL agents can then step through live packet-level simulations as if they were playing CartPole.
The interesting bit The integration is bidirectional and real-time: the agent doesn’t train on a log file or pre-captured trace, it steers an actual running ns-3 process. The included cognitive radio example shows an agent learning to dodge a periodic interferer by sensing channel occupancy, with reward shaped purely by collision outcomes inside the simulator.
Key highlights
- Exposes any ns-3 variable or parameter to the RL agent through a generic C++ interface
- Ships with a working cognitive radio example (channel selection against periodic interference)
- Includes a TCP congestion-control hook: monitor socket state and manipulate
CongestionWindowandSlowStartThresholdfrom Python - Python-side
ns3gympackage installs via pip from the repo itself - Published and maintained by TU Berlin networking researchers since 2019
Caveats
- RL-TCP example is explicitly “still under development”; only the interface and a TCP NewReno proof-of-concept are released
- Requires careful directory naming (
contrib/opengym, notns3-gym) and branch selection (app-ns-3.36+) during install gym.make('ns3-v0')is broken with newer OpenAI Gym; you must usens3env.Ns3Env()directly
Verdict Worth a look if you’re doing networking research and need RL baselines against realistic MAC-layer or transport behavior. Skip it if you want polished, ready-to-train environments—this is academic infrastructure with rough edges still visible.