NS-3安装


[TOC]

参考文档

  • 官方安装wiki文档:https://www.nsnam.org/wiki/Installation
  • 参考博客:http://blog.csdn.net/dyzok88/article/details/50816624

环境

我系统的环境

  • ubuntu 16.10
    建议ubuntu 16.04版本以上吧
  • NS版本ns-3.26

安装依赖

  • 注意:如果提示权限不够,在前面加上sudo

  • minimal requirements for C++ (release): This is the minimal set of packages needed to run ns-3 from a released tarball.

1
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.
1
apt-get install gcc g++ python python-dev
  • minimal requirements for Python (development): For use of ns-3-allinone repository (cloned from Mercurial), additional packages are needed to fetch and successfully install pybindgen:
1
apt-get install mercurial python-setuptools git
  • Python API scanning support: cmake libc6-dev libc6-dev-i386 g++-multilib To rescan Python bindings requires gccxml and pygccxml, which are installed by bake. However, for Ubuntu 16.04, gccxml will not build without a patch and a build flag described here: https://www.nsnam.org/bugzilla/show_bug.cgi?id=2451
  • qt4 development tools are needed for Netanim animator (Note: qt version qt4, not qt5, is required)
1
apt-get install qt4-dev-tools libqt4-dev
  • Support for generating modified python bindings
1
apt-get install cmake libc6-dev libc6-dev-i386 g++-multilib
  • and you will want to install gccxml and pygccxml as per the instructions for python bindings (or through the bake build tool as described in the tutorial).

    Debugging:

1
apt-get install gdb valgrind
  • GNU Scientific Library (GSL) support for more accurate WiFi error models
1
apt-get install gsl-bin libgsl2 libgsl-dev
  • The Network Simulation Cradle (nsc) requires the flex lexical analyzer and bison parser generator:
1
apt-get install flex bison libfl-dev
  • To read pcap packet traces
1
apt-get install tcpdump
  • Database support for statistics framework
1
apt-get install sqlite sqlite3 libsqlite3-dev
  • Xml-based version of the config store (requires libxml2 >= version 2.7)
1
apt-get install libxml2 libxml2-dev
  • A GTK-based configuration system
1
apt-get install libgtk2.0-0 libgtk2.0-dev
  • To experiment with virtual machines and ns-3
1
apt-get install vtun lxc
  • Support for utils/check-style.py code style check program
1
apt-get install uncrustify
  • Doxygen and related inline documentation:
1
2
apt-get install doxygen graphviz imagemagick
apt-get install texlive texlive-extra-utils texlive-latex-extra texlive-font-utils texlive-lang-portuguese dvipng
  • The ns-3 manual and tutorial are written in reStructuredText for Sphinx (doc/tutorial, doc/manual, doc/models), and figures typically in dia (also needs the texlive packages above):
1
apt-get install python-sphinx dia
  • Note: Sphinx version >= 1.12 required for ns-3.15. To check your version, type “sphinx-build”. To fetch this package alone, outside of the Ubuntu package system, try “sudo easy_install -U Sphinx”.

    • Support for Gustavo Carneiro’s ns-3-pyviz visualizer
1
apt-get install python-pygraphviz python-kiwi python-pygoocanvas libgoocanvas-dev ipython
  • Support for openflow module (requires some boost libraries)
1
apt-get install libboost-signals-dev libboost-filesystem-dev
  • Support for MPI-based distributed emulation
1
apt-get install openmpi-bin openmpi-common openmpi-doc libopenmpi-dev

安装NS-3

  1. 下载NS-3安装包:官网首页下载
  2. 建立文件夹NS3(可自己定义)

enter description here

  1. 将下载的安装包解压到NS3目录中

enter description here

  1. 编译
    1)使用build.py编译
1
sudo ./build.py --enable-examples --enable-tests

编译成功:

enter description here

2)使用waf编译

一旦工程已经编译过,就不能再使用build.py脚本
使用waf重新配置和编译ns-3系统

  • sudo ./waf clean 清除先前配置编译
  • ./waf -d optimized –enable-examples–enable-tests configure 重新配置ns-3,优化编译例子和测试(默认测试和例子是不编译的)
    optimized参数,优化模式下默认是禁止ns-3特殊的日志系统(logging),这样导致运行的的结果不能再控制台上显示。因此,建议更改为./waf -d debug --enable-examples --enable-tests configure
  • ./waf 正式编译

    3) 运行测试

    使用test.py测试,从`ns`目录中进入到`ns-3.26`目录下找到test.py文件,运行:
    
1
2
cd ns-3.26
sudo ./test.py

enter description here

运行成功:

enter description here

编程工具安装VIM

我比较喜欢vim编辑器,感觉比较原生,你也可以使用eclips,大部分是截取i前辈的文档,但是他们的x有些下载地址进不去,就自己修改了点。

首先说明一下几个配置文件的作用:

  • vim 文件夹,这个文件夹放置 vim 的配置文件,包括 vim 的插件和 doc
    文件,ubuntu 下面名字以 . 开始说明默认是隐藏的,如果想看可以进入文件夹
    所在的目录按 CTRL+H,显示隐藏文件,或者在终端下面输入 ls -a 命令。.vim
    是自己创建的,放在主文件夹下面。
    创建过程:首先打开终端,一般默认是主文件夹,也可以输入 cd ~命令进
    入主文件夹,然后,输入 mkdir .vim 创建文件夹。输入 cd .vim 进入文件夹,创
    建 plugin, doc, tags 文件夹, plugin 放置的是 vim 的一些插件,文件名后缀是.vim,
    doc 是插件的帮助文档,tags 放 ctags 生成的 tag 文件(tags 这个可选,可以放在
    任何位置,只要在.vimrc 文件中设置正确即可)。
  • vimrc 文件,这个文件里面存储 vim 的配置信息,也是自己创建的,和.vim
    在同一级目录下。
    创建过程:打开终端,输入:cd ~,然后输入 vim .vimrc 命令,会出现一
    个.vimrc 文件的 vim 编辑界面。按 i 键进入编辑模式,在文件里面添加如下命令:
    filetype plugin indent on
    set helplang=cn
    set encoding=utf-8
    syntax enable
    syntax on
    然后按 esc 键,输入:wq 命令,保存退出!

下面是主要配置环节

  1. ctags安装
    1
    sudo apt-get install ctags

太繁琐了,不想写了,留着以后有时间再弄吧。暂时用eclipse吧。


编程工具安装之eclipse

安装eclipse

1
2
sudo apt-get install eclipse
sudo apt-get install eclipse-cdt

eclipse与ns-3对接

1.新建ns3空工程
FILE->new->c++project

2.将原来的ns3文件夹下的ns-3.26文件夹下的内容全复制到eclipse的工作目录下

并且在改目录下使用下面的命令配置项目:

1
./waf -d dubug --enable-examples --enable-tests configure

3.设置eclipse中的ns3编译器为waf
在eclipse中的`project exploer中的项目文件上右键,选择properties选项,进行如下设置

enter description here
这时右键点击build project进行编译

4.设置eclipse执行工具使用外部工具
选择run->External Tools->Externel tools Configuration

然后出现:

5.仿真结果

热评文章