This file provides guidance to AI agents when working with code in this repository.
ns-3 is a discrete-event network simulator for Internet systems, written in C++ with Python bindings. The project uses CMake for building but provides a custom ns3 wrapper script for easier command-line usage.
Configuration:
./ns3 configure --enable-examples --enable-tests # Basic setup
./ns3 configure --help # Show all optionsBuilding:
./ns3 build # Build entire project
./ns3 build [target] # Build specific targetRunning:
./ns3 run "simple-global-routing" # Run example program
./ns3 run "program [args]" # Run with argumentsTesting:
./test.py # Run all tests
./test.py -s module-name # Run specific module tests, where `module-name`
# is the name of the module to be tested.
./test.py -v # Verbose outputUtilities:
./ns3 clean # Clean build artifacts
./ns3 show targets # List available targetssrc/- 49 official modules (core, network, internet, wifi, lte, etc.)contrib/- Third-party modulesexamples/- Example programs organized by topicscratch/- User simulation scriptsutils/- Development utilities
Each module follows this structure:
src/module-name/
├── CMakeLists.txt # Build configuration
├── model/ # Core implementation (.cc/.h)
├── helper/ # Helper classes for easier usage
├── test/ # Unit tests
├── examples/ # Usage examples
└── doc/ # Documentation
- Attribute System: Configuration through TypeId attributes
- Callback System: Event-driven programming with Callback<> templates
- Smart Pointers: Extensive use of Ptr<> for memory management
- Logging: Hierarchical logging system with NS_LOG_*
- Tracing: Packet and event tracing for analysis
./utils/create-module.py module-name # Generate module templateThe full coding style guide is documented in doc/contributing/source/coding-style.rst.
- Clang-format: Formatting rules and current C++ standard alignment are in .clang-format
- No Unicode symbols: Do not use Unicode mathematical symbols (e.g., ≤, ≥, ×, ÷, ∑, π) or arrows (e.g., →, ←, ⇒, ↑) in comments or Doxygen documentation; use ASCII equivalents instead (e.g.,
<=,>=,*,/,->,=>)
Full guidelines for writing model documentation in Sphinx reStructuredText are in doc/contributing/source/models.rst. An empty outline with the required section structure and elements for a new module can be found in utils/create-module.py. Note that existing modules are not yet universally conformant to this structure; when adding Sphinx documentation to an existing module, find an appropriate insertion point within the existing structure rather than restructuring the whole document.
Full conventions are in doc/contributing/source/coding-style.rst (Comments section). Key rules:
- Coverage: All classes, methods, and member variables must have Doxygen comments. Exceptions: methods inherited from a parent class (docs are copied automatically) and default constructors/destructors.
- Comment style: Use C-style Javadoc blocks (
/** ... */). Use///< brief descriptionfor inline member variable documentation. - Tag delimiter: Use
@not\for all tags (e.g.,@param,@return,@brief). clang-format recognizes@as a Doxygen tag delimiter and formats accordingly. - Parameters and return values: All must be documented with
@paramand@return. - Cross-references: Use
@seefor cross-referencing other classes or methods. - Internal comments: Use
@internal/@endinternalfor documentation not intended for public Doxygen output. - Grouping: Use
@defgroupand@ingroupto bind logically related classes within a module. Test classes should form an ancillary group with@ingroup tests.
Example:
/**
* Brief description of the class.
*/
class MyClass
{
public:
/**
* Constructor.
*
* @param n Number of elements.
*/
MyClass(int n);
/**
* Do something useful.
*
* @param x Input value.
* @return Result of the operation.
*/
int DoSomething(int x);
private:
int m_count; ///< Number of elements
};- All code must build with examples and tests enabled
- Tests must pass before commits
- Use
./test.py -s module-namefor module-specific testing
- Present tense, imperative mood ("Add feature" not "Added feature")
- Reference modules: "core, network: Add new feature"
- if list of edited modules spans more than two, suppress listing
- 72 character limit for first line
- Use "(fixes #issue)" for bug fixes, after the list of modules but before
the summary of the commit, where
#issueis the number of the issue.
./test.py -s core # Run core module tests
./test.py -e simple-global-routing # Run specific exampleTests can be run with ns-3 logging enabled via the NS_LOG environment variable:
NS_LOG="BulkSendApplication" ./ns3 run 'test-runner --suite=applications-bulk-send'Log level can be tuned to reduce noise. Note that filtering to a specific log level deselects prefix information, so prefix_all must be added to recover it:
NS_LOG="BulkSendApplication=level_info|prefix_all" ./ns3 run 'test-runner --suite=applications-bulk-send'./ns3 run "program --help" # Show program options
./ns3 run program --command-template "gdb --args %s" # Run with gdb./ns3 build core # Build only core module
./ns3 build wifi-simple-adhoc # Build specific example.ns3rc- Build configuration settingsCMakeLists.txt- Build system configurationtest.py- Main test runnerutils/create-module.py- Module generator.clang-format- Code formatting rules
When working with modules, understand the dependency hierarchy:
- core - Base classes, logging, attributes
- network - Packets, nodes, devices
- internet - IP, TCP, UDP protocols
- applications - Application layer protocols
- wifi/lte/etc. - Technology-specific implementations
Python bindings are available but may not cover all C++ APIs. Use:
from ns import ns
help(ns.ClassName) # Get class documentationRendered (current release):
- Manual: https://www.nsnam.org/docs/manual/html/
- API Reference: https://www.nsnam.org/docs/doxygen/
- Model Library: https://www.nsnam.org/docs/models/html/
Source (in-tree, for editing):
- Manual:
doc/manual/source/ - Model docs:
doc/models/source/ - Contributing guide:
doc/contributing/source/