Step 1: Prerequisites
First, ensure you have the necessary tools installed on your macOS system. You can install them using Homebrew.
# Install essential build tools
brew install python3 cmake mercurial
# For C++ compilation
brew install llvm
# Or ensure you have Xcode Command Line Tools installed
# xcode-select --install
Step 2: Download NS3
We will use the ns-3-allinone package, which simplifies the download and build process.
-
Navigate to your main projects directory:
cd /Users/fathanpranaya/Projects/ns3/ -
Clone the
ns-3-allinonerepository. This will create a newns-allinonedirectory.git clone https://gitlab.com/nsnam/ns-3-allinone.git -
Enter the newly created directory:
cd ns-3-allinone -
Use the
download.pyscript to fetch all of the necessary NS3 source code modules.python3 download.py
Step 3: Build NS3
This is the most important step. We will use the provided build script to compile NS3 and its Python bindings.
-
From inside the
ns-3-allinonedirectory, run the build script. This process can take a significant amount of time (20-60 minutes depending on your machine).python3 build.py --enable-examples --enable-testsThis command compiles NS3 and ensures the Python bindings, examples, and tests are all built correctly.
-
After the build completes successfully, you will have a new NS3 directory inside
ns-3-allinone, such asns-3.41or a similar version number.
Step 4: Verify the Installation
Let's run a test to make sure everything works as expected.
-
Navigate into the NS3 directory:
# Replace 'ns-3.41' with the actual version directory that was created cd ns-3.41 -
Run a test simulation using the
./ns3wrapper../ns3 run hello-simulatorIf the installation was successful, you should see the output:
Hello Simulator.
You now have a clean, working installation of NS3 in a predictable location!