您的位置:首页 > 运维架构 > Linux

Linux安装NS3

2016-05-16 16:43 253 查看
我写的内容多是重复NS3官方文档里面的内容,如果看不懂我写的东西或我的内容与官方文档有冲突,以官方文档为准。建议大家多看看文档(程序员的必备技能)。

下载NS3

有多种下载NS3方式,最简单的是直接从官网下载NS3。从官网找到下载地址,下载安装包ns-allinone-3.25.tar.bz2,解压缩得到文件夹ns-allinone-3.25。不知道是什么原因,官网有时候连接不上,我给一个百度网盘的地址http://pan.baidu.com/s/1bplwXsV

安装前准备

安装NS3需要许多软件的支持,比如Python。网址https://www.nsnam.org/wiki/Installation介绍了不同系统需要安装什么软件支持,有提供下载安装方式。其实它就是NS3的详细的安装教程,你可以直接阅读教程而不需要看我的这篇文章。

编译

安装NS3也有多种方式。(下面的操作许多都要管理员权限,先su获取管理员权限吧)

使用build.py编译

最简单的是build.py。进入文件夹ns-allinone-3.25

cd ns-allinone-3.25
ls


可以看到:

bake constants.py ns-3.25 README

build.py netanim-3.107 pybindgen-0.17.0.post49+ng0e4e3bc util.py

建议看看README。

执行

./build.py --enable-examples --enable-tests


看到下面的内容说明你已经编译好了

Build commands will be stored in build/compile_commands.json

‘build’ finished successfully (12.537s)

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 wave wifi

wimax

Modules not built (see ns-3 tutorial for explanation):

brite click openflow

编译过程你可能会发现有红色字体出现,如(红色字体在这里用加粗字体表示)

—- Summary of optional NS-3 features:

Build profile : debug

Build directory :

Python Bindings : not enabled (Python library or headers missing)

BRITE Integration : not enabled (BRITE not enabled (see option –with-brite))

NS-3 Click Integration : not enabled (nsclick not enabled (see option –with-nsclick))

GtkConfigStore : enabled

XmlIo : enabled

Threading Primitives : enabled

Real Time Simulator : enabled

File descriptor NetDevice : enabled

Tap FdNetDevice : enabled

Emulation FdNetDevice : enabled

PlanetLab FdNetDevice : not enabled (PlanetLab operating system not detected (see option –force-planetlab))

Network Simulation Cradle : not enabled (NSC not found (see option –with-nsc))

MPI Support : not enabled (option –enable-mpi not selected)

NS-3 OpenFlow Integration : not enabled (OpenFlow not enabled (see option –with-openflow))

SQlite stats data output : enabled

Tap Bridge : enabled

PyViz visualizer : not enabled (Python Bindings are needed but not enabled)

Use sudo to set suid bit : not enabled (option –enable-sudo not selected)

Build tests : enabled

Build examples : enabled

GNU Scientific Library (GSL) : enabled

Gcrypt library : not enabled (libgcrypt not found: you can use libgcrypt-config to find its location.)

‘configure’ finished successfully (5.419s)

不用担心,这只是显示NS3的一些功能或特性没有启动(个人认为),不会影响NS3的安装。

使用Waf编译

文档推荐使用Waf编译NS3。

首先进入文件夹ns-3.25

cd ns-allinone-3.25/ns-3.25
ls


也可以看到有一个README文件,里面也有安装教程,可以看看。

继续编译

./waf clean
./waf --build-profile=debug --enable-examples --enable-tests configure


这一步是配置NS3,“–build-profile=debug”是让NS3以debug模式运行,可以在运行时查看日志信息,方便调试。最后出现

‘configure’ finished successfully (2.493s)

说明配置成功。接着编译

./waf


最后看到

Build commands will be stored in build/compile_commands.json

‘build’ finished successfully (7m41.748s)

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 wave wifi

wimax

Modules not built (see ns-3 tutorial for explanation):

brite click openflow

visualizer

说明编译成功。

安装

这一步不是必须的。缺少这一步,只能在ns-3.25文件夹中使用NS3,不能在ns-3.25文件夹以外的文件夹中使用NS3。我就没有执行这一步。

./waf install


执行之后,会把NS3的安装到其他的位置,文档是这么说的:

By default, the prefix for installation is /usr/local, so ./waf install will install programs into

/usr/local/bin, libraries into /usr/local/lib, and headers into /usr/local/include.

测试

测试看看是否成功地安装好NS3:

./test.py -c core


最后输出

219 of 222 tests passed (219 passed, 3 skipped, 0 failed, 0 crashed, 0 valgrind errors)

List of SKIPped tests:

ns3-tcp-cwnd

ns3-tcp-interoperability

nsc-tcp-loss

0 failed, 0 crashed, 0 valgrind errors,虽然有skipped,应该不影响使用。

好了,你已经安装成功了!

运行脚本

执行第一个程序(又是Hello world)

./waf --run hello-simulator


直接执行命令,如果出现

Hello Simu
a99b
lator


恭喜你,你可以使用NS3了!

如果没有出现,可能是配置NS3时,不是使用debug模式,而是”optimized”

./waf --build-profile=optimized --enable-examples --enable-tests configure


那么控制台就不会输出
Hello Simulator
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  NS3 安装