面向5G车联网仿真平台的搭建
本博客是基于SRTP(面向5G车联网仿真平台设计与开发)而搭建的“面向5G车联网的网络仿真平台”,以供大家学习使用。
目录
工具/环境
书籍(后续安装ns-3需要用):
官方文档阅读:
环境:
1.sudo apt-get install gcc g++ python python-dev //C++和python安装,必装
2.sudo apt-get install mercurial //NS3代码维护使用的源码版本控制管理系统
3.sudo apt-get install bzr //运行python绑定ns-3-dev需要bazaar这个组件
4.sudo apt-get install libgtk2.0-0 libgtk2.0-dev //基于GTK的配置系统
5.sudo apt-get install gdb valgrind //调试工具
6.sudo apt-get install doxygen graphviz imagemagick //文档生成器
7.sudo apt-get install texlive texlive-latex-extra //文档生成器,从源代码中生成说明文档
8.sudo apt-get install texinfo dia texlive-extra-utils texi2html //ns-3手册和tutorial编写查看工具
9.sudo apt-get install flex bison //仿真必需的词法分析器和语法分析生成器,必装
10.sudo apt-get install libgoocanvas-dev //部分移动场景仿真的可视化测试需要 这个组件
11.sudo apt-get install tcpdump //读取pcap的packet traces,即包嗅探器
12.sudo apt-get install sqlite sqlite3 libsqlite3-dev //支持统计特性的数据库软件
13.sudo apt-get install libxml2 //xml的配置存储软件
14.sudo apt-get install python-pygraphviz python-kiwi python-pygoocanvas //Gustavo's ns-3-pyviz的可视化软件
15.sudo apt-get install qt4-qmake
16.sudo apt-get install qt4-dev-tools
ps:安装过程中肯定会出现各种各样的错误,不过一般网上都有答案,这里我也就不需要一一列出来来,这个要根据安装实际情况而定。
mkdir tarballs //创建名字为tarballs的文件夹
cd tarballs //进入tarballs文件夹
wget http://www.nsnam.org/release/ns-allinone-3.26.tar.bz2 //连网下载NS-3.26版本
tar xjf ns-allinone-3.26.tar.bz2 //使用tar解压
进入到目录ns-allinone-3.26,能看到如下文件和目录:
$ ls
bake constants.py ns-3.26 README
build.py netanim-3.107 pybindgen-0.17.0.post57+nga6376f2 util.py
ns-3下载工作到这里就基本完成了,接下来可以开始构建ns-3了。
$ ./build.py --enable-examples --enable-tests
编译完成后,您会看到显示的是构建脚本构建你下载的各种内容的信息。最终显示如下:
Waf: Leaving directory `/path/to/workspace/ns-allinone-3.26/ns-3.26/build'
'build' finished successfully (6m25.032s)
Modules 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 mpi
netanim (no Python) network nix-vector-routing
olsr openflow (no Python) point-to-point
point-to-point-layout propagation sixlowpan
spectrum stats tap-bridge
test (no Python) topology-read traffic-control
uan virtual-net-device visualizer
wave wifi wimax
Modules not built (see ns-3 tutorial for explanation):
brite click
尚未被构建的部分:
Modules not built (see ns-3 tutorial for explanation):
brite click
这只是意味着某些ns-3模块依赖的外部库可能尚未安装,或者配置文件专门指定的不构建他们。这并不意味着模拟器没有成功构建,也不意味着其会对正在构建的(被列出的)模块给出错误的的结果。
$ ./waf clean //清除以前的版本
$ ./waf -d debug --enable-examples --enable-tests configure //重新配置ns-3项目,并构建系统检查各种依赖关系
正式编译:
$ ./waf
输出如下结果:
[2593/2631] Linking build/bindings/python/ns/traffic_control.so
[2594/2631] Linking build/bindings/python/ns/network.so
[2595/2631] Linking build/bindings/python/ns/wifi.so
[2596/2631] Linking build/bindings/python/ns/nix_vector_routing.so
[2597/2631] Linking build/bindings/python/ns/lte.so
[2598/2631] Linking build/bindings/python/ns/buildings.so
[2599/2631] Linking build/bindings/python/ns/aodv.so
[2600/2631] Linking build/bindings/python/ns/point_to_point.so
[2601/2631] Linking build/bindings/python/ns/fd_net_device.so
[2602/2631] Linking build/bindings/python/ns/mpi.so
[2603/2631] Linking build/bindings/python/ns/wave.so
[2604/2631] Linking build/bindings/python/ns/csma.so
[2605/2631] Linking build/bindings/python/ns/dsdv.so
[2606/2631] Linking build/bindings/python/ns/topology_read.so
[2607/2631] Linking build/bindings/python/ns/internet_apps.so
[2608/2631] Linking build/utils/ns3.26-print-introspected-doxygen-debug
[2609/2631] Linking build/scratch/subdir/subdir
[2610/2631] Linking build/bindings/python/ns/energy.so
[2611/2631] Linking build/bindings/python/ns/antenna.so
[2612/2631] Linking build/bindings/python/ns/internet.so
[2613/2631] Linking build/bindings/python/ns/tap_bridge.so
[2614/2631] Linking build/bindings/python/ns/wimax.so
[2615/2631] Linking build/bindings/python/ns/_core.so
[2616/2631] Linking build/bindings/python/ns/spectrum.so
[2617/2631] Linking build/bindings/python/ns/sixlowpan.so
[2618/2631] Linking build/bindings/python/ns/mobility.so
[2619/2631] Linking build/bindings/python/ns/stats.so
[2620/2631] Linking build/utils/ns3.26-test-runner-debug
[2621/2631] Compiling src/fd-net-device/helper/tap-device-creator.cc
[2622/2631] Compiling src/fd-net-device/helper/encode-decode.cc
[2623/2631] Compiling src/fd-net-device/helper/creator-utils.cc
[2624/2631] Linking build/src/fd-net-device/ns3.26-tap-device-creator-debug
[2625/2631] Compiling src/fd-net-device/helper/raw-sock-creator.cc
[2626/2631] Compiling src/fd-net-device/helper/encode-decode.cc
[2627/2631] Compiling src/fd-net-device/helper/creator-utils.cc
[2628/2631] Linking build/src/fd-net-device/ns3.26-raw-sock-creator-debug
[2630/2631] Compiling src/tap-bridge/model/tap-encode-decode.cc
[2630/2631] Compiling src/tap-bridge/model/tap-creator.cc
[2631/2631] Linking build/src/tap-bridge/ns3.26-tap-creator-debug
Waf: Leaving directory `/home/xuminghua/tmp/ns-allinone-3.26/ns-3.26/build'
Build commands will be stored in build/compile_commands.json
'build' finished successfully (14m15.932s)
Modules 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 mpi
netanim (no Python) network nix-vector-routing
olsr point-to-point point-to-point-layout
propagation sixlowpan spectrum
stats tap-bridge test (no Python)
topology-read traffic-control uan
virtual-net-device visualizer wave
wifi wimax
Modules not built (see ns-3 tutorial for explanation):
brite click openflow
构建完成之后,我们就可以开始测试ns-3是否能运行了。
./test.py -c core //测试ns-3发行版示范编译正确
输出如下所示:
……
PASS: TestSuite traced-value-callback
PASS: TestSuite aodv-routing-id-cache
PASS: TestSuite routing-aodv
PASS: TestSuite routing-aodv-loopback
PASS: TestSuite routing-aodv-regression
PASS: TestSuite ns3-wifi-msdu-aggregator
PASS: TestSuite lte-frequency-reuse
230 of 233 tests passed (230 passed, 3 skipped, 0 failed, 0 crashed, 0 valgrind errors)
List of SKIPped tests:
ns3-tcp-cwnd
ns3-tcp-interoperability
nsc-tcp-loss
由输出可以看出,除来未安装成功的三个依赖包,其他均测试成功。
- 运行脚本进行测试
运行ns-allinone-3.26/ns-3.26/scratch文件夹下的脚本文件scratch-simulator.cc
在ns-allinone-3.26/ns-3.26文件夹下,键入以下命令(因为waf在这个文件夹下,也可以将waf 和 waf.bat 移至scratch文件夹下再进行运行)
$ ./waf --run scratch/scratch-simulator
waf首先执行检查以确保程序已经正确构建,并在需要时执行构建。然后执行该程序,产生以下输出:
Waf: Entering directory `/home/xuminghua/tmp/ns-allinone-3.26/ns-3.26/build'
Waf: Leaving directory `/home/xuminghua/tmp/ns-allinone-3.26/ns-3.26/build'
Build commands will be stored in build/compile_commands.json
'build' finished successfully (1.912s)
Scratch Simulator
输出了Scratch Simulator,表明ns-3网络仿真平台已经搭建完成来,接下来就是用你的代码进行编译,并进行数据可视化分析展示了。
数据可视化主要有两种PyViz和NetAnim,都是作为可视化动画演示工具。
PyViz
PyViz安装
安装依赖包
sudo apt-get install python-dev python-pygraphviz python-kiwi python-pygoocanvas python-gnome2 python-gnomedesktop python-rsvg
安装交互式Python使得GUI上有控制台按钮
sudo apt-get install ipython
./waf --pyrun src/flow-monitor/examples/wifi-olsr-flowmon.py --visualize
./waf --run src/olsr/examples/simple-point-to-point-olsr --vis
obj=bld.create_ns3_program('simple-point-to-point-olsr', ['point-to-point', 'internet', 'olsr', 'applications', 'wifi'])
修改成
obj=bld.create_ns3_program('simple-point-to-point-olsr', ['point-to-point', 'internet', 'olsr', 'applications', 'wifi', 'visualizer'])
NetAnim
NetAnim安装
sudo apt-get install mercurial
sudo apt-get install qt4-dev-tools
hg clone http://code.nsnam.org/jabraham3/netanim
cd netanim
make clean
qmake NetAnim.pro (For MAC Users: qmake -spec macx-g++ NetAnim.pro)
make
运行实例产生.xml文件供NetAnim解析
在src/netanim/examples目录下执行下面两个命令:
./waf --run "dumbbell-animation --nLeftLeaf=5 --nRightLeaf=5 --animFile=dumbbell.xml"
./waf --run "grid-animation --xSize=5 --ySize=5 --animFile=grid.xml"
若出现”权限不够“,则退出到ns-3.26目录下,执行下面两条命令:
./waf --run "src/netanim/examples/dumbbell-animation --nLeftLeaf=5 --nRightLeaf=5 --animFile=dumbbell.xml"
./waf --run "src/netanim/examples/grid-animation --xSize=5 --ySize=5 --animFile=grid.xml"
运行NetAnim来解析xml文件:
cd ns-allinone-3.26/netanim-3.107
./NetAnim
打开NetAnim界面如下:
打开xml文件,进行解析:
好了,以上就是整个平台的搭建以及可视化全过程……
最后再进行数据分析等过程……