# ns-3.34 - [doc](https://www.nsnam.org/releases/ns-3-34/documentation/) - [getting started](https://www.nsnam.org/docs/release/3.34/tutorial/html/getting-started.html) A strong contender of ns-3 is the celebrated OMNET++. However, a [2016 paper](https://arxiv.org/pdf/1307.4129.pdf) demonstrated that ns-3 won by a slight margin. The codebase of ns-3 is well-designed from a C++ programming perspective. - Better yet, ns-3 introduced a pattern named [*direct code execution*](https://www.nsnam.org/about/projects/direct-code-execution/) (DCE), which reuses the existing linux network stack to perform simulation. This results in less code and better performance. - From *my* perspective, there are a few pain points: - ns-3 uses both *mercurial* and *git* for source control; at times, it's rather confusing! - ns-3 uses a special build system called *waf*. I gave up to learning waf; I restricted myself to the simple usage outlined in the tutorials. How I wish that ns-3 used cmake and vcpkg. - Due to compatibility, ns-3 restricts to using the C++11 features supported by gcc4.9. How archaic, considering that C\++20 is already out. - ns-3 uses the templated `Ptr<>` type which are superceded by the standard defined *smart pointers*. - ns-3 follows the tasteless [GNU coding style](https://www.nsnam.org/develop/contributing-code/coding-style/). ## Packet Core ![](https://i.imgur.com/VgPpZAs.png) ## Roadmap :::info Essential are the concepts capable of emulation. To understand the essentials of LTE, look no further than the ns-3 LTE module documentation. ::: - **Main entry**: [ns-3 Model Library](https://www.nsnam.org/docs/models/html/index.html) - **Primary**: [LTE Module](https://www.nsnam.org/docs/models/html/lte.html). The design guide and user guide are *sufficient* to understand LTE. - [Design Guide](https://www.nsnam.org/docs/models/html/lte-design.html). Must read! - [User Guide](https://www.nsnam.org/docs/models/html/lte-user.html). Must read! - [Testing Guide](https://www.nsnam.org/docs/models/html/lte-testing.html) - [Profiling Guide](https://www.nsnam.org/docs/models/html/lte-profiling.html) - [References](https://www.nsnam.org/docs/models/html/lte-references.html). Very useful; look no further. - **Secondary**: [Mobility](https://www.nsnam.org/docs/models/html/mobility.html), [Propagation](https://www.nsnam.org/docs/models/html/propagation.html). Use these pre-built mobility and propagation models to customize your emulations. Design your own mobility and propagation models similar to those. - **Ternary**: [Network Module](https://www.nsnam.org/docs/models/html/network.html), [Wi-Fi Module](https://www.nsnam.org/docs/models/html/wifi.html). Could these be used to model 5G. ## Programming - [Quickstart](https://www.nsnam.org/docs/tutorial/html/getting-started.html); prefer this. - [Official installation guide](https://www.nsnam.org/wiki/Installation) Ns-3 requires Python 3. If Python 3 is missing, install it. It's best to have Python 3.7+; update pip if necessary: ```bash # choose whichever suitable for pip3 pip install --upgrade pip pip3 install --upgrade pip ``` I'll call the project root directory `root`. Install *bake* in `root` and setup a python virtual environment: ```bash mkdir root cd root git clone https://gitlab.com/nsnam/bake python3 -m venv env source env/bin/activate cd bake bake.py check bake.py configure -e ns-3.34 bake.py show bake.py deploy -vvv cd .. # now you are back in root ln -s `pwd`/bake/source/ns-3.34 ns-3.34 ``` The directory layout would now look like this: - root - bake - source - ns-3.34 - ns-3.34 Test with: ```bash # from root cd ns-3.34 ./waf --run hello-simulator # Hello Simulator ``` :::info Offline documentation can be obtained [here](https://www.nsnam.org/releases/ns-3-34/documentation/). ::: ## Building Custom Scripts ```bash ./waf clean ./waf configure \ --disable-tests \ --disable-examples \ --disable-python \ --enable-mpi \ --boost-mt \ --boost-includes=/opt/homebrew/Cellar/boost/1.76.0/include \ --boost-libs=/opt/homebrew/Cellar/boost/1.76.0/lib \ --cxx-standard="-std=c++17" ./waf build # -j8 # ./test ``` :::info It doesn't matter that ``` List of FAILed tests: int64x64 ``` ::: In root, do: ```bash mkdir -p sim/src ln -s $PWD/ns-3.34/build/scratch sim/build rm -fr ns-3.34/scratch ln -s $PWD/sim/src ns-3.34/scratch ``` Create the *executable* `root/sim/compile` with content: ```bash (cd ~/Documents/ns-3/ns-3.34 && exec ./waf) ``` ## ns-3 C++ Library Quickstart - [entry](https://www.nsnam.org/docs/tutorial/singlehtml/index.html#ns3-namespace) - [object overview](https://www.nsnam.org/docs/manual/singlehtml/index.html#object-overview) Basic example with 2 UE and 1 eNB that are all immobile: ```cpp #include <ns3/core-module.h> #include <ns3/lte-module.h> #include <ns3/mobility-module.h> #include <ns3/network-module.h> using namespace ns3; int main() { auto lteHelper = CreateObject<LteHelper>(); MobilityHelper mobility; NodeContainer enbNodes(1); mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel"); mobility.Install(enbNodes); auto enbDevs = lteHelper->InstallEnbDevice(enbNodes); NodeContainer ueNodes(2); mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel"); mobility.Install(ueNodes); auto ueDevs = lteHelper->InstallUeDevice(ueNodes); lteHelper->Attach(ueDevs, enbDevs.Get(0)); lteHelper->ActivateDataRadioBearer(ueDevs, EpsBearer(EpsBearer::GBR_CONV_VOICE)); Simulator::Stop(MilliSeconds(5)); Simulator::Run(); Simulator::Destroy(); } ``` ## C++17 ```bash CXXFLAGS="-std=c++17" ./waf configure ```