NS-3环境搭建
本文主要参考NS-3的官方参考教程搭建NS-3网络仿真工具。
主要包括两个方面:
- 下载源码
- 编译并执行示例和测试程序。
依赖
用途 | 工具 | 最小版本号 | 版本检查方式 |
---|---|---|---|
下载 | git 、tar 、bunzip2 | 无版本要求 | git --version |
编译 | g++ 或clang++ | g++>=10 或clang++11 | g++ --version |
配置 | python3 | python3>=3.8 | python3 -V |
构建 | cmake 或make 、ninja | cmake>=3.13 | cmake --verison |
下载
wget
源码下载:
wget https://www.nsnam.org/releases/ns-allinone-3.44.tar.bz2
tar xfj ns-allinone-3.44.tar.bz2
cd ns-allinone-3.44/ns-3.44
或git
源码下载
git clone https://gitlab.com/nsnam/ns-3-dev.git
cd ns-3-dev
git checkout -b ns-3.44-release ns-3.44
ns-3.44
目录如下:
$ tree -L 1
.
├── AUTHORS
├── CHANGES.md
├── CMakeLists.txt
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── LICENSES
├── README.md
├── RELEASE_NOTES.md
├── VERSION
├── bindings
├── build-support
├── contrib
├── doc
├── examples
├── ns3
├── pyproject.toml
├── scratch
├── setup.cfg
├── setup.py
├── src
├── test.py
├── utils
└── utils.py
10 directories, 15 files
其中ns3
是包装了cmake
的python3脚本,用来进行编译。
构建和测试
下载完源码之后,使用ns3
进行构建,ns3
是对cmake
进行封装的python3脚本。
配置模块:
./ns3 configure --enable-examples --enable-tests --prefix=~/usr
下面可以看到已经配置的模块:
-- ---- Summary of ns-3 settings:
Build profile : default
Build directory : /home/blduan/open_source/ns-3/ns-allinone-3.44/ns-3.44/build
Build with runtime asserts : ON
Build with runtime logging : ON
Build version embedding : OFF (not requested)
BRITE Integration : OFF (Missing headers: "Brite.h" and missing libraries: "brite")
DES Metrics event collection : OFF (not requested)
DPDK NetDevice : OFF (not requested)
Emulation FdNetDevice : ON
Examples : ON
File descriptor NetDevice : ON
GNU Scientific Library (GSL) : OFF (GSL was not found)
GtkConfigStore : OFF (Harfbuzz is required by GTK3 and was not found)
LibXml2 support : ON
MPI Support : OFF (not requested)
ns-3 Click Integration : OFF (Missing headers: "simclick.h" and missing libraries: "nsclick click")
ns-3 OpenFlow Integration : OFF (Missing headers: "openflow.h" and missing libraries: "openflow")
Netmap emulation FdNetDevice : OFF (missing dependency)
PyViz visualizer : OFF (Python Bindings are disabled)
Python Bindings : OFF (not requested)
SQLite support : OFF (Missing headers: "sqlite3.h" and missing libraries: "sqlite3")
Eigen3 support : OFF (Eigen was not found)
Tap Bridge : ON
Tap FdNetDevice : ON
Tests : ON
Modules configured to be built:
antenna aodv applications
bridge buildings config-store
core csma csma-layout
dsdv dsr energy
fd-net-device flow-monitor internet
internet-apps lr-wpan lte
mesh mobility netanim
network nix-vector-routing olsr
point-to-point point-to-point-layout propagation
sixlowpan spectrum stats
tap-bridge test topology-read
traffic-control uan virtual-net-device
wifi wimax zigbee
Modules that cannot be built:
brite click mpi
openflow visualizer
其中不能构建的模块是可选模块,需要外部依赖,暂时不影响使用所以可以不管它。
对已经配置的模块进行构建:
./ns3 build
构建时间依赖于CPU、内存以及构建模式(debug或默认优化模式等)。
构建完成之后就要对模块进行测试,ns-3.44
版本目前具有790个测试项。
测试命令如下:
./test.py
模块测试完成之后会有如下日志:
# ....
790 of 790 tests passed (790 passed, 0 skipped, 0 failed, 0 crashed, 0 valgrind errors)
安装
可以通过在ns3 configure
中设置--prefix=$PREFIX
来指定安装目录,默认安装目录为/usr/local
。
$PREFIX/include
为头文件目录、$PREFIX/lib
为库文件目录、$PREFIX/libexec
为可执行二进制文件目录。
注意:ns3
脚本阻止以root
权限运行,即使sudo
也不行。因此想要安装到默认目录有两个选项:
- 注释掉
ns3
脚本中的refuse_run_as_root()
语句 - 当前用户自身具备写入
/usr/local
目录的权限。
安装NS-3到指定目录:
./ns3 install
- 原文作者:生如夏花
- 原文链接:https://DBL2017.github.io/post/%E4%BC%A0%E8%BE%93%E5%8D%8F%E8%AE%AE/ns-3/ns-3%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。