1 PyViz
1.1 引言
NS-3 PyViz is a live simulation visualizer, meaning that it uses no trace files. It can be most useful for debugging purposes, i.e. to figure out if mobility models are what you expect, where packets are being dropped, etc. There’s also a builtin interactive python console that can be used to debug the state of the running objects. Although it is mostly written in Python, it works both with Python and pure C++ simulations.
NS-3 PyViz是在线模拟仿真可视化工具,使用python编写,在python和c++环境中都可以使用。
使用Pyviz工具可以更加直观的看出节点间通信的效果。
1.2 安装
在ns-3的3.10版本之后,ns-3中包括了PyViz。(因此不需要单独下载,只需要配置一下就可以了)
sudo ./waf configure --build-profile=debug --enable-example --enable-tests --with-pybindgen=/home/jnbai/桌面/ns3/ns-allinone-3.30.1/pybindgen-0.20.0 --enable-sudo
若有错误提示:PyViz visualizer : not enabled (Missing python modules: pygraphviz),执行以下:
sudo pip3 install pygraphviz
sudo ./waf configure --build-profile=debug --enable-example --enable-tests --with-pybindgen=/home/jnbai/桌面/ns3/ns-allinone-3.30.1/pybindgen-0.20.0 --enable-sudo
成功!
测试一下:
#在ns-3.XX目录下:
./waf --run first --vis
2 NetAnim
NetAnim is an offline animator based on the Qt toolkit. It currently animates the simulation using an XML trace file collected during simulation. The first version was developed by George F Riley.
先安装三个插件:
sudo apt-get install qt4-qmake # 安装工具
sudo apt-get purge libqt4-opengl-dev # 绘图工具(用这个命令可能出错sudo apt-get install libqt4-dev)
sudo apt-get install libxml2-dev # netanim读取程序生成的xml文件,离线展示动画
安装:
cd ns-allinone-3.xx
cd netanim-3.xxx
make clean
qmake NetAnim.pro
make
启动:
./NetAnim
出现界面:
运行:
cp examples/tutorial/first.cc scratch
chmod 777 scratch/first.cc
vim scratch/first.cc
修改scratch/first.cc文件:
//加头文件
#include "ns3/netanim-module.h"
//在Simulator::Run();前面加这三句
AnimationInterface anim("first.xml");
anim.SetConstantPosition(nodes.Get(0), 1.0, 2.0);//描述节点0的坐标
anim.SetConstantPosition(nodes.Get(1), 2.0, 3.0);//描述节点1的坐标
保存退出。
# (普通用户)在ns-3.xx文件下,编译程序
sudo ./waf --run scratch/first
# 在netanim文件夹下重新启动
./NetAnim
在netanim界面中点击open->first.xml->play
成功!