标签:
对于初次接触Linux系统的人来说,ns-3 的安装似乎并不友好。但事实上只要按部就班地来做,其安装过程也没有看上去的那么复杂。本文将官方 Wiki 中的安装过程稍作梳理,希望能为初学者带来一些方便。同时由于官方 Wiki 中的描述已经足够详细,因此本文中将会出现大段引用并且不打算进行翻译,望请见谅。
本节参考官方 Wiki 中 Installation 页面的 Prerequisites - Ubuntu/Debian 小节,详细说明请跳转至 Wiki 页面进行查询。
执行以下指令,安装正确编译和使用 ns-3 所必须的工具:
minimal requirements for C++ (release): This is the minimal set of packages needed to run ns-3 from a released tarball.
apt-get install gcc g++ python
minimal requirements for Python (release): This is the minimal set of packages needed to work with Python bindings from a released tarball.
apt-get install gcc g++ python python-dev
qt4 development tools (Note: qt4, not qt5) needed for NetAnim animator
apt-get install qt4-dev-tools libqt4-dev
以上是安装 ns-3 所必须安装的工具(实际上第三个qt开发包对 ns-3 本身来说并不是必须的,但是它是动画演示工具 NetAnim 所必须的,而该工具是 ns-3 非常常用的工具,所以我认为属于必装工具)。在官方 Wiki 中 Installation 页面的 Prerequisites - Ubuntu/Debian 小节中还有很多其他的可选工具,可以在以后的实际使用中选择自己所需要的进行安装。
因为作者对于 Linux 下的编程也是新手,因此一个优秀的 IDE 对我来说显得必不可少,我选择了Eclipse这款工具作为我调试 ns-3 的工具,因为它是一个功能强大且稳定的 IDE 工具,并且 ns-3 的官方 Wiki 中有关于如何利用 Eclipse 进行调试的说明(相关说明本文后半部分将会详细讲解),所以我选择它来进行调试。同样拥有官方说明的 IDE 工具还有 NetBeans 和 QtCreator。
如果打算使用 Eclipse 进行 ns-3 的开发工作,此时可以先安装 Eclipse 以及 cdt 插件(使 Eclipse 支持 C++ 开发),并且打开 Eclipse 并新建一个工作空间(workspace)。之后下载的 ns-3 工程应当直接放到该工作空间目录中以便 Eclipse 识别。
该工具是 ns-3 新版本中提供的一个集安装、编译与查询缺少工具于一身的工具,但我所使用的一直是手动安装方式(将在下一小节中介绍),从来没有尝试过这种安装方式。所以,在此直接照搬官方 Wiki 中的相关介绍,详情请参考官方 Wiki 中 Installation 页面的 Installation - Installation with Bake 小节。
Bake is a new tool for installing, building and finding out the missing requirements for ns-3 in your own environment.
To use Bake you need to have at least Python (preferably 2.6 and above) and mercurial in your machine (see the section Prerequisites above to see how to install these).
First you need to download Bake using Mercurial, go to where you want Bake to be installed and call
hg clone http://code.nsnam.org/bake
It is advisable to add bake to your path.
export BAKE_HOME=`pwd`/bake export PATH=$PATH:$BAKE_HOME export PYTHONPATH=$PYTHONPATH:$BAKE_HOME
After that you can use Bake to find the missing packages, download build and install ns-3 and its modules.
To find out what is missing in your system and may be needed for installing ns-3 you can call bake check:
bake.py check
You should have seen something like:
> Python - OK
> GNU C++ compiler - OK
> Mercurial - OK
> CVS - OK
> GIT - OK
> Bazaar - OK
> Tar tool - OK
> Unzip tool - OK
> Unrar tool - OK
> 7z data compression utility - OK
> XZ data compression utility - OK
> Make - OK
> cMake - OK
> patch tool - OK
> autoreconf tool - OK
> Path searched for tools: /usr/lib64/qt-3.3/bin
/usr/lib64/ccache /usr/local/bin /usr/bin/bin/usr/local/sbin /usr/sbin
/sbin /user/dcamara/home/scripts/user/dcamara/home/INRIA/Programs/bin
/user/dcamara/home/INRIA/repos/llvm/build/Debug+Asserts/binBefore downloading and building ns-3 you need to configure bake to inform it which are the modules you want added to ns-3, the standard distribution for example.
bake.py configure -e ns-3.17
Then to see the modules it has added, and the specific system requirements for this configuration, you can call bake show:
bake.py show
To download the modules, build and install you can call bake deploy
bake.py deploy
This will download the selected modules, all their dependencies and build ns-3 with all these independent modules. You can also perform this installation step by step, i.e. by calling download and build in different steps.
bake.py download bake.py build
在官方 Wiki Installation 页面中介绍了三种手动安装的选项——使用 Mercurial(一种版本管理工具)进行安装、使用源码安装开发者版本(拥有最新特性但不够稳定)、使用源码安装发布版(即Release版,最新的稳定版本)。官方推荐使用第一种方式,但是作者并没有使用Mercurial,并且手动安装方式相对来说更加简单,所以作者选择了第三种方式进行安装。因此,本节将介绍第三种安装方式,其他两种安装方式请移步官方 Wiki Installation 页面的 Installation-Manual installation 小节查看详情。
cd
mkdir tarballs
cd tarballs
wget http://www.nsnam.org/release/ns-allinone-3.13.tar.bz2
tar xjf ns-allinone-3.13.tar.bz2
在终端中进入 ns-3 工程目录(build.py所在的那一级目录,一般其文件夹名形如“ns-allinone-3.25”)并执行编译脚本:
./build.py
耐心等待一段时间(依电脑配置不同编译时长不同,我的编译时间约有40分钟),编译成功后将会看到如下提示:
Build finished successfully (00:02:37)
Leaving directory `./ns-3.25’
./waf configure --enable-examples --enable-tests
待配置成功后下一次编译时就会将例子程序和测试程序也进行编译并可以执行了。
至此,ns-3 已经在你的电脑里安装成功了。现在进入 ns-3 工程目录(Waf所在目录),运行一下指令可以运行你的第一个 ns-3 程序了(该程序路径为 /ns-allinone-3.25/ns-3.25/scratch/scratch-simulator.cc):
./waf --run scratch-simulator
输出为:
Scratch Simulator
同时也在此验证了你的 ns-3 安装成功。
本章主要根据官方 Wiki 中的《HOWTO configure Eclipse with ns-3》一文,来介绍如何配置 Eclipse 的各项参数,使得可以方便地通过 Eclipse 来完成 ns-3 项目的开发工作。与之前一样,详细介绍请移步官方 Wiki 中 HOWTO configure Eclipse with ns-3 一文。
${workspace_loc:/ns-allinone-3.25/ns-3.25}/waf
其中斜体部分应该换成对应的你的 ns-3 工程的目录名称。
${workspace_loc:/ns-allinone-3.25/ns-3.25}
其中斜体部分应该换成对应的你的 ns-3 工程的目录名称。并且你可以选择通过点击工作目录(Workspace…)按钮来浏览并选择编译目录。
- 选择行为(Behaviour)选项卡
- 将编译(Build (incremental build))后的“all”指令改为“build”
- 点击应用(Apply)或确认(OK)按钮保存设置并退出
点击工程(Project)下的浏览(Browse…)按钮,选择你的 ns-3 工程
选择环境(Environment)选项卡
${workspace_loc:ns-allinone-3.25/ns-3.25}/build
其中斜体部分应该换成对应的你的 ns-3 工程的目录名称。
${workspace_loc:/ns-allinone-3.25/ns-3.25/waf}
其中斜体部分应该换成对应的你的 ns-3 工程的目录名称。
${workspace_loc:/ns-allinone-3.25/ns-3.25}
其中斜体部分应该换成对应的你的 ns-3 工程的目录名称。
- 在参数(Arguments)下的文本框中输入运行参数
–run “${string_prompt}”
这样在通过外部运行工具执行 ns-3 脚本时,可以通过在弹出的文本框中输入需要执行的 ns-3 脚本文件名称来执行该脚本(名称不包括后缀)。
至此,Eclipse 中的配置工作全部完成,可以尝试一下编译、调试和运行功能是否可以正确执行。另外还可以至官方 Wiki 中 HOWTO configure Eclipse with ns-3 一文中查看更多配置信息。
到此为止,ns-3 的安装与配置部分完全结束,你已经可以使用 ns-3 来进行仿真或者开发了。对于 ns-3 的开发,官方网站和官方文档是非常重要的参考资料,尤其是官方在线 API 文档、官方 Wiki 页面以及三本重要官方参考资料——Tutorial、Manual、Models,这三本资料均可通过官网下载。
非常感谢您的阅读,希望我写的这些文字能够给予你你想要的帮助。
标签:
原文地址:http://blog.csdn.net/jojo59516/article/details/51208629