主要参考胡博文章,在20.04的Vultr主机上测试上可行。
由于Ubuntu 18.04上涉及到两个python,过于麻烦,因此尝试使用20.04安装。
TL;DR
wget -O /tmp/ns3.34.sh "https://ns3.minaduki.dev/ns3.34.sh" && chmod +x /tmp/ns3.34.sh && /tmp/ns3.34.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-gym相关
sudo apt install libzmq5 libzmq3-dev libprotobuf-dev protobuf-compiler
下载NS3.34
使用3.34版本是因为之前的测试结果,在18.04上使用gcc-7.4能安装3.34和3.35,其他版本未作测试,目前仅测试了3.34版本和ns3-gym的兼容性。
cd ~
wget https://www.nsnam.org/releases/ns-allinone-3.34.tar.bz2 # 3.34或3.35,之后的版本会提示gcc版本低于8,暂未测试
tar -jxvf ns-allinone-3.34.tar.bz2
编译测试NS3
cd ns-allinone-3.34
# ./build.py
cd ns-3.34
./waf configure --enable-test --enable-examples
./waf
运行测试
./test.py -c core
运行可视化
./waf --run third --vis
在此基础上安装ns3-gym
准备源码
cd ~/ns-allinone-3.34/ns-3.34/contrib
git clone https://github.com/tkn-tub/ns3-gym.git ./opengym
cd opengym/
git checkout app
编译
cd ~/ns-allinone-3.34/ns-3.34
./waf configure --enable-test --enable-examples
./waf build
安装python module
cd ~/ns-allinone-3.34/ns-3.34/contrib/opengym/
pip3 install --user ./model/ns3gym
运行测试
Ubuntu 20.04自带的protobuf版本是3.6.1,相对低了一点,因此在运行是会报错:
_message.Message._CheckCalledFromGeneratedFile() TypeError: Descriptors cannot not be created directly. If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0. If you cannot immediately regenerate your protos, some other possible workarounds are: 1. Downgrade the protobuf package to 3.20.x or lower. 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).
所以在运行时先设置环境变量
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
再运行。
测试一:
cd ~/ns-allinone-3.34/ns-3.34/contrib/opengym/examples/opengym/
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python ./simple_test.py
测试二:
# Terminal 1
cd ~/ns-allinone-3.34/ns-3.34
./waf --run "opengym"
# Terminal 2
cd ~/ns-allinone-3.34/ns-3.34/contrib/opengym/examples/opengym/
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python ./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
cd ~
wget https://www.nsnam.org/releases/ns-allinone-3.34.tar.bz2
tar -jxvf ns-allinone-3.34.tar.bz2
cd ns-allinone-3.34
# ./build.py
cd ns-3.34
# ./waf configure --enable-test --enable-examples
# ./waf
cd ~/ns-allinone-3.34/ns-3.34/contrib
git clone https://github.com/tkn-tub/ns3-gym.git ./opengym
cd opengym/
git checkout app
cd ~/ns-allinone-3.34/ns-3.34
./waf configure --enable-test --enable-examples
./waf build
cd ~/ns-allinone-3.34/ns-3.34/contrib/opengym/
pip3 install --user ./model/ns3gym
测试
cd ~/ns-allinone-3.34/ns-3.34/
./test.py -c core
./waf --run third --vis
cd ~/ns-allinone-3.34/ns-3.34/contrib/opengym/examples/opengym/
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python ./simple_test.py
# Terminal 1
cd ~/ns-allinone-3.34/ns-3.34
./waf --run "opengym"
# Terminal 2
cd ~/ns-allinone-3.34/ns-3.34/contrib/opengym/examples/opengym/
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python ./test.py --start=0
请问ns3.36安装教程有吗
3.35是可以用这套装的,3.36改了编译的框架,还在研究,把./waf改成./ns3是可以运行的,但是提示缺少python bindings没法启用可视化。
太感谢了,在ubuntu20.04上完美解决
sudo apt-get install python-dev # for python2.x installs
sudo apt-get install python3-dev
您好,请问Pyviz的问题解决了吗,我也卡在这里没有办法enable可视化模块了
看了看NS3-gym的更新我发现新的版本似乎没有问题了,我发了一篇新的文章,应该可以解决问题。