参考这篇博客,似乎NS3-gym已经进行了一些更新,NS3.36及以上的版本也可以正常编译运行NS3-gym并使用可视化了。
TL;DR
wget -O /tmp/ns3.38.sh "https://ns3.minaduki.dev/ns3.38.sh" && chmod +x /tmp/ns3.38.sh && /tmp/ns3.38.sh
安装依赖
NS3相关
sudo apt install gcc g++ python gcc g++ python3 python3-dev mercurial python3-setuptools git qt5-default gir1.2-goocanvas-2.0 python3-gi python3-gi-cairo python3-pygraphviz gir1.2-gtk-3.0 ipython3 ipython3 openmpi-bin openmpi-common openmpi-doc libopenmpi-dev autoconf cvs bzr unrar gdb valgrind uncrustify doxygen graphviz imagemagick texlive texlive-extra-utils texlive-latex-extra texlive-font-utils texlive-lang-portuguese dvipng latexmk python3-sphinx dia gsl-bin libgslcblas0 libgsl-dev flex bison libfl-dev tcpdump sqlite sqlite3 libsqlite3-dev libxml2 libxml2-dev cmake libc6-dev libc6-dev-i386 libclang-dev llvm-dev automake libgtk2.0-0 libgtk2.0-dev vtun lxc libboost-all-dev libboost-filesystem-dev pkg-config sqlite3 cmake libc6-dev libc6-dev-i386 libclang-6.0-dev llvm-6.0-dev automake python3-pip
似乎新的NS3版本依赖于cppyy
,可视化需要安装kiwi
,因此:
pip3 install cppyy kiwi
NS3-gym相关
sudo apt install libzmq5 libzmq3-dev libprotobuf-dev protobuf-compiler
下载NS3.38
使用3.38版本是因为之前的测试结果,本来想使用3.36版本,但是在编译的时候似乎找不到protobuf的头文件,参考了这个issue因此使用了3.38版本。
cd ~
wget https://www.nsnam.org/releases/ns-allinone-3.38.tar.bz2
tar -jxvf ns-allinone-3.38.tar.bz2
编译测试NS3
cd ns-allinone-3.38
cd ns-3.38
./ns3 configure --enable-python-bindings --enable-test --enable-examples
./ns3
运行测试
./test.py -c core
运行可视化
./ns3 run third --vis
在此基础上安装ns3-gym
准备源码
mkdir -p ~/ns-allinone-3.38/ns-3.38/contrib
cd ~/ns-allinone-3.38/ns-3.38/contrib
git clone https://github.com/tkn-tub/ns3-gym.git ./opengym
cd opengym/
git checkout app-ns-3.36+
编译
cd ~/ns-allinone-3.38/ns-3.38
./ns3 configure --enable-python-bindings --enable-test --enable-examples
./ns3 build
安装python module
cd ~/ns-allinone-3.38/ns-3.38/contrib/opengym/
pip3 install --user ./model/ns3gym
运行测试
测试一:
cd ~/ns-allinone-3.38/ns-3.38/contrib/opengym/examples/opengym/
./simple_test.py
测试二:
# Terminal 1
cd ~/ns-allinone-3.38/ns-3.38
./ns3 run "opengym"
# Terminal 2
cd ~/ns-allinone-3.38/ns-3.38/contrib/opengym/examples/opengym/
./test.py --start=0
复制这些就行
编译
sudo apt install -y gcc g++ python gcc g++ python3 python3-dev mercurial python3-setuptools git qt5-default gir1.2-goocanvas-2.0 python3-gi python3-gi-cairo python3-pygraphviz gir1.2-gtk-3.0 ipython3 ipython3 openmpi-bin openmpi-common openmpi-doc libopenmpi-dev autoconf cvs bzr unrar gdb valgrind uncrustify doxygen graphviz imagemagick texlive texlive-extra-utils texlive-latex-extra texlive-font-utils texlive-lang-portuguese dvipng latexmk python3-sphinx dia gsl-bin libgslcblas0 libgsl-dev flex bison libfl-dev tcpdump sqlite sqlite3 libsqlite3-dev libxml2 libxml2-dev cmake libc6-dev libc6-dev-i386 libclang-dev llvm-dev automake libgtk2.0-0 libgtk2.0-dev vtun lxc libboost-all-dev libboost-filesystem-dev pkg-config sqlite3 cmake libc6-dev libc6-dev-i386 libclang-6.0-dev llvm-6.0-dev automake python3-pip
sudo apt install -y libzmq5 libzmq3-dev libprotobuf-dev protobuf-compiler
pip3 install cppyy kiwi
cd ~
wget https://www.nsnam.org/releases/ns-allinone-3.38.tar.bz2
tar -jxvf ns-allinone-3.38.tar.bz2
mkdir -p ~/ns-allinone-3.38/ns-3.38/contrib
cd ~/ns-allinone-3.38/ns-3.38/contrib
git clone https://github.com/tkn-tub/ns3-gym.git ./opengym
cd opengym/
git checkout app-ns-3.36+
cd ~/ns-allinone-3.38/ns-3.38
./ns3 configure --enable-python-bindings --enable-test --enable-examples
./ns3 build
cd ~/ns-allinone-3.38/ns-3.38/contrib/opengym/
pip3 install --user ./model/ns3gym
测试
cd ~/ns-allinone-3.38/ns-3.38/
./test.py -c core
./ns3 run third --vis
cd ~/ns-allinone-3.38/ns-3.38/contrib/opengym/examples/opengym/
./simple_test.py
# Terminal 1
cd ~/ns-allinone-3.38/ns-3.38
./ns3 run "opengym"
# Terminal 2
cd ~/ns-allinone-3.38/ns-3.38/contrib/opengym/examples/opengym/
./test.py --start=0
./ns3 run third –vis
NS_ASSERT failed, cond=”uid != 0″, msg=”Assert in TypeId::LookupByName: ns3::VisualSimulatorImpl not found”, file=/home/fe1/ns-allinone-3.38/ns-3.38/src/core/model/type-id.cc, line=843
NS_FATAL, terminating
terminate called without an active exception
Command ‘build/examples/tutorial/ns3.38-third-default –SimulatorImplementationType=ns3::VisualSimulatorImpl’ died with .
可视化模块的依赖都正确安装了吗,`./ns3 configure`的输出中有没有`PyViz visualizer: enabled`?
你好博主,我的ns版本为ns3.36.1,我在编译过程中出现以下报错,是你所说的在编译的时候找不到protobuf的头文件的问题嘛?谢谢
In file included from /home/houliang/tarballs/ns-allinone-3.36.1/ns-3.36.1/build/include/ns3/opengym-module.h:7,
from /home/houliang/tarballs/ns-allinone-3.36.1/ns-3.36.1/contrib/opengym/examples/interference-pattern/mygym.h:26,
from /home/houliang/tarballs/ns-allinone-3.36.1/ns-3.36.1/contrib/opengym/examples/interference-pattern/mygym.cc:21:
/home/houliang/tarballs/ns-allinone-3.36.1/ns-3.36.1/build/include/ns3/container.h:27:10: fatal error: messages.pb.h: 没有那个文件或目录
27 | #include “messages.pb.h”
| ^~~~~~~~~~~~~~~
是的,一模一样的报错,我因此换到了3.38版本。
博主牛逼,我就是3.36报错,弄了一早上没解决,按照博主升级成3.38就好了,博主666666666666