ns3

    在ns-3的wiki上有专门介绍如何安装ns-3。

    http://www.nsnam.org/wiki/index.php/Installation

    在google上的一个ns-3小组,里面有一篇讨论给出了Ubuntu8.04下安装ns-3失败的解决方案

    http://groups.google.com/group/ns-3-users/browse_thread/thread/add32f88902c576b

    1.(Ubuntu/Debian 环境搭建步骤)(目录结构:home/username/ns3/ns-3.17)

    • minimal requirements for C++ (release):

    sudo apt-get install gcc g++ python

    • minimal requirements for Python (release):

    sudo apt-get install gcc g++ python python-dev//C++和python安装,必装

    • Mercurial is needed to work with ns-3 devel //仿真必需的词法分析器和语法分析生成器,必装
    • opment repositories. //NS3代码维护使用的源码版本控制管理系统

    sudo apt-get install mercurial

    • Running python bindings from the ns-3 development tree (ns-3-dev) requires bazaar /运行python绑定ns-3-dev需要bazaar这个组件

    sudo apt-get install bzr

    • Debugging: //调试工具

    sudo apt-get install gdb valgrind

    • GNU Scientific Library (GSL) support for more accurate WiFi error models //基于GTK的配置系统

    sudo apt-get install gsl-bin libgsl0-dev libgsl0ldbl

    • The Network Simulation Cradle (nsc) requires the flex lexical analyzer and bison parser generator:

    sudo apt-get install flex bison libfl-dev 

    sudo apt-get install flex bison//仿真必需的词法分析器和语法分析生成器,必装

    • To install gcc-3.4 for some Network Simulation Cradle (nsc) stacks:

    sudo apt-get install g++-3.4 gcc-3.4

    (降低系统本身的高版本GCC,G++:

    因为编译内核的需要, Ubuntu 自带的 gcc4.3 版本太高,需要使用 gcc3.x ,因此需要安装低版本的 gcc ,我选择的是 gcc3.4.4.

    ( 1 )下载 deb 安装包,我下载的包为:

    gcc-3.4-base_3.4.6-6ubuntu3_i386.deb 、

    gcc-3.4_3.4.6-6ubuntu3_i386.deb 、

    cpp-3.4_3.4.6-6ubuntu3_i386.deb 、

    g++-3.4_3.4.6-6ubuntu3_i386.deb 、

    libstdc++6-dev_3.4.6-6ubuntu3_i386.deb

    下载地址为: http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-3.4/

    ( 2 )安装这些包

    sudo dpkg –force-depends –i xxx.deb

    ( 3 )系统配置

    安装完成之后,在系统里会多出: gcc-3.4

    目前系统里有两个版本的 gcc ,缺省时 gcc4.3 ;需要改变系统的缺省配置:

    增加 gcc3.4 和 gcc4.3 可选项

    $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 40

    $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-3.4 30

    切换版本到 gcc-3.4

    $ sudo update-alternatives --config gcc

    现有 2 个可选项,它们都提供了“ gcc ”

    < 选择 可选项 -----------------------------------------------

    *+1 /usr/bin/gcc-3.4

    2 /usr/bin/gcc-4.2

    要维持缺省值 [*] ,按回车键,或者键入选择的编号: 1

    使用“ /usr/bin/gcc-3.4 ”来提供“ gcc ”。

    (同理可以设置G++的备用选项,然后执行替换g++换成3.4之后出现ns3无法编译的问题,所以换回4.7)

    )

    • To read pcap packet traces

    sudo apt-get install tcpdump//读取pcap的packet traces,即包嗅探器

    • Database support for statistics framework

    sudo apt-get install sqlite sqlite3 libsqlite3-dev//支持统计特性的数据库软件

    • Xml-based version of the config store (requires libxml2 >= version 2.7)

    sudo apt-get install libxml2 libxml2-dev //xml的配置存储软件

    • A GTK-based configuration system

    sudo apt-get install libgtk2.0-0 libgtk2.0-dev

    • To experiment with virtual machines and ns-3

    sudo apt-get install vtun lxc

    • Support for utils/check-style.py code style check program

    sudo apt-get install uncrustify

    • Doxygen and related inline documentation:

    sudo apt-get install doxygen graphviz imagemagick//文档生成器
    sudo apt-get install texlive texlive-extra-utils texlive-latex-extra //文档生成器,从源代码中生成说明文档

    sudo apt-get install texlive texlive-pdf texlive-latex-extra texlive-generic-extra texlive-generic-recommended

    sudo apt-get install texinfo dia texlive texlive-pdf texlive-latex-extra texlive-extra-utils texlive-generic-recommended

    • 此处运行显示找不到texlive-pdf,将此删掉即可!
    • The ns-3 manual and tutorial are written in reStructuredText for Sphinx (doc/tutorial, doc/manual, doc/models), and figures typically in dia:

    sudo apt-get install python-sphinx dia

    • Support for Gustavo Carneiro's ns-3-pyviz visualizer

    sudo apt-get install python-pygraphviz python-kiwi python-pygoocanvas libgoocanvas-dev//Gustavo's ns-3-pyviz的可视化软件

    • Support for openflow module (requires some boost libraries)

    sudo apt-get install libboost-signals-dev libboost-filesystem-dev

    sudo apt-get install libgoocanvas-dev //部分移动场景仿真的可视化测试需要这个组件

    • Support for MPI-based distributed emulation

    sudo apt-get install openmpi*

    (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". )

    ---------------------------------------------------------------------------------------------------------------

    2.安装NS3

    下载NS3安装包并解压,官网上(www.nsnam.org)下载的3.13版本格式为ns-allinone-3.13.tar.bz2

    在终端运行以下命令进行解压缩:

    bzip2 -d ns-allinone-3.13.tar.bz2

    tar xvf ns-allinone-3.13.tar

    2.2命令终端进入解压缩文件夹 执行命令

    ./build.py

    2.3 进入ns-3.13目录使用waf构建(waf是ns-3采用的基于Python的Build System)

    ./waf -d optimized configure

    ./waf -d debug configure

    ./waf

    ./waf -d debug --enable-sudo configure

    ./waf configure --enable-tests//使测试可用

    ./waf configure --enable-examples//使例子可用

    ---------------------------------------------------------------------------------

    3. 脚本运行

    退到上级目录(如ns3)

    ./build.py --enable-examples --enable-tests//执行后才以下语句才有用

    ./waf --run hello-simulator//不加.cc

    会输出如下信息: hello simulator

    -----------------------------------------------------------------------------------

    4.出现的问题

    brite click openflow visualizer没有完成安装

    (1)brite安装

    #: hg clone http://code.nsnam.org/jpelkey3/BRITE

    #: cd BRITE

    #: make

    # cd..

    #: hg clone http://code.nsnam.org/jpelkey3/ns-3-brite-modular

    #: cd ns-3-brite-modular

    #: ./waf configure --with-brite=BRITE的路径

    #: ./waf

    测试:

    #: ./waf –run ‘brite-generic-example –verbose=1’

    (2)click模块

    click是一个构建可配置路由器的软件架构,通过使用称之为元素element(即包处理单元)的不同组合,click路由器能够执行特定功能,这种灵活性提供了测试和实验不同协议的优良平台。

    *下载click(http://read.cs.ucla.edu/click/download)

    *进入click目录配置编译click

    cd click

    ./configure --enable-userlevel --disable-linuxmodule --enable-nsclick --enable-wifi

    ./make (没有必要使用make install,或者用make)

    *重新配置和构建ns3(进入ns3.17目录)

    ./waf configure --enable-examples --enable-tests --with-nsclick=click源码路径

    如果click安装在ns-3-allinone文件夹中,即ns-3文件夹的上层文件夹中,"--with-nsclick=click源码路径"不需要,ns3构建器能够自动找到click源码

    ./waf

    *测试click

    ./waf --run nsclick-simple-lan

    将得到两个.pcap跟踪结果文件:nsclick-simple-lan-0-0.pcap和nsclick-simple-lan-0-1.pcap

    (2)openflow

    openflow交换广泛用于科研中,通过openflow API可以对OpenFlow交换进行配置。openflow交换拥有针对服务质量的多协议标签交换(MPLS)扩展和支持service-level-agreement。通过使用openflow交换,ns3能够精确仿真多种不同的交换。

    *下载openflow

    hg clone http://code.nsnam.org/jpelkey3/openflow

    *配置和构建openflow(在openflow文件夹下运行)

    ./waf configure

    ./waf build

    此时生成libopenflow.a库文件

    *链接OpenFlow模块到ns3(在ns3的源码文件夹下运行,如ns-3.12.1)

    ./waf configure --enable-examples --enable-tests --with-openflow=下载的openflow源码路径(openflow)

    此时并没有用OpenFlow的自带模块

    ./waf build (构建ns3并激活ns3的openflow模块)

    *测试openflow

    ./waf --run openflow-switch

    ./waf --run "openflow-switch -v"(查看日志细节)

    *验证openflow模块

    ./test.py --suite=openflow

    注释说明:

    NS3本身自带的只是openflow的封装接口,这些接口要去调用openflow的库,就是后面下载的那一部分。在安装的过程中它会编译成相应的库连接到NS3中。在你没有安装openflow的时候在build/debug/src下是看不到的openflow模块的,只有完成以上操作是的时候,才能找到openflow的模块,进而可以执行openflow下相应的程序。

    ./waf --run openflow-switch openflow-switch是src下openflow模块下的代码编译的可执行文件。并不是下载的openlfow里面的。

    ------------------------------------------------------------------------------------------------------------------

    5、NS3的特点

    NS3完全用C++编写(可选Python接口),脚本采用C++或Python语言,采用四种类型的网络构件(Node、NetDevice、Channel、Application)

    其脚本大致内容或步骤如下:

    (From:http://hi.baidu.com/czlaner/blog/item/77a0a4ce9903a90493457e06.html

    1) 创建节点Node(使用类NodeContainer::Create( )方法)

    2) 使用链路Helper类来帮助设置链路(包括PointToPointHelper、CsmaHelper、WifiHelper等类型)。 Helper类虽然不属于上述四类的网络构件,但它却极大地方便了拓扑的搭建,它可以帮助我们处理实际中诸如在两个终端安装网卡、连网线、Modern、配置上网方式、链路属性等底层工作,简化了仿真过程,使我们可以更专注于仿真的目的

    3) 安装IP协议栈(使用类InternetStackHelper::Install( )方法)

    4) 设置IP地址(使用类Ipv4AddressHelper::SetBase( )/Assign( )方法)

    5) 在节点Node上安装应用程序(目前支持UdpServerServer、UdpEchoClient、PacketSink等)

    6) 设置仿真时间、启动仿真

posted @ 2013-07-17 14:58  苝極鉯苝  阅读(1874)  评论(0编辑  收藏  举报