Chinaunix首页 | 论坛 | 博客
  • 博客访问: 844864
  • 博文数量: 180
  • 博客积分: 10029
  • 博客等级: 上将
  • 技术积分: 2185
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-06 09:15
文章存档

2010年(133)

2009年(47)

我的朋友

分类: 系统运维

2010-03-13 19:17:34

  声明:引用和转载相关内容,请尊重作者、翻译者和审稿者的辛勤付出,我们坚信开源的思想,我们希望自己的工作可以为更多的人提供帮助,我们不希望成为随意粘贴和任意复制的对象。    
 
(由于NS3出来没多久,材料还都没有中文的版本, 本人和网友正着手翻译相关文档, 欢迎有意为中国学术界网络协议研究做贡献的网友的参与, 邮件我: , 以便分工和汇总
或加入翻译的QQ交流群:Nsto3 21930554 )
 
(我机子的系统是 Unbuntu的, Linux的其他系统的安装过程应该是类似的)
 
      首先你需要下载 ns3的安装包(现在的最新版本是:ns-allinone-3.7.tar.bz2)
下载的地址:
(初学者,应该安装稳定版,而不是mercurial 版本
 
 
1. Build essential, 安装 gcc, g++, python, python-dev 等
  

sudo apt-get install gcc g++ python python-dev

或者:

sudo apt-get update

sudo apt-get install build-essentials

  
2.用cd命令转到ns-allinone-3.7.tar.bz2的文件夹目录下
      首先解压包:  tar xvf ns-allinone-3.7.tar.bz2
      cd进入解压得到的文件夹中,找到 build.py文件;
      运行命令:  ./build.py
 
      大概需要20分钟左右, 最后将看到终端显示如下内容:
      
---- Summary of optional NS-3 features:
Threading Primitives          : enabled
Real Time Simulator           : enabled
GtkConfigStore                : not enabled (library 'gtk+-2.0 >= 2.12' not found)
SQlite stats data output      : enabled
Network Simulation Cradle     : not enabled (--enable-nsc configure option not given)
Python Bindings               : enabled
Python API Scanning Support   : not enabled (Missing 'pygccxml' Python module)
Configuration finished successfully; project is now ready to build.
      恭喜你,安装成功!
 
3. 你可以check一下NS3果真安装好了
   在/home/usernma/allinone-3.7/ns-3.7目录下
    运行命令: ./waf --check
        看到如下内容:
 
   
Waf: Entering directory `/home/cat/ns-allinone-3.7/ns-3.7/build'
[669/670] get-unit-tests-list
[670/670] print-introspected-doxygen
[671/704] run-unit-test(AddressHelper)
.
.
[701/704] run-unit-test(Object)
[702/704] run-unit-test(Ptr)
[703/704] run-unit-test(Callback)
[704/704] collect-unit-tests-results
C++ UNIT TESTS: all 33 tests passed.
Waf: Leaving directory `/home/cj/ns-allinone-3.7/ns-3.7/build'
'build' finished successfully (5.670s)
 
   NS3的安装到此结束, 可以参考NS3的官方网站,运行一些简单的例程!
   我也会在后续的博客中发布我的使用记录和我编写的部分代码!  敬请期待!
 
   (本人和网友正在翻译NS3的手册和相关材料,欢迎有兴趣的网友参与, 无论你的英文如何,相信你都会在这一个过程中通过合作使自己得到锻炼, 邮件: ,以便分工和汇总)
 
 
近期刚看到的一个关于NS3安装的详细摘要,写的很好哦!
 

ns-3安装问题解决

Supported platforms

ns-3 is primarily developed on GNU/Linux platforms, and the minimal requirements to run basic simulations are a gcc installation of gcc-3.4/g++-3.4 or greater, and python 2.4 or greater.

ns-3 is supported on the following primary platforms:

  1. Linux x86 gcc 4.2, 4.1, and, 3.4.6.
  2. Linux x86_64 gcc 4.4.0, 4.3.2, 4.2.3, 4.2.1, 4.1.3, 3.4.6
  3. MacOS X ppc and x86 (gcc 4.0.x and 4.2.x)
  4. gcc 3.4.4 (debug only), gcc 4.3.2 (debug and optimized)

    Prerequisites

    The core of ns-3 requires a gcc/g++ installation of 3.4 or greater, and python 2.4 or greater. As mentioned above, different options require additional support. This is a list of packages (for Debian/Ubuntu systems) that are needed to support different ns-3 options. Note that other distributions (e.g., Fedora, FreeBSD) may have different package names or capitalization (e.g. ImageMagik). Installation should be similar for Red Hat/Fedora based systems, with "yum" replacing "apt-get", but some differences exist, so below is a guide for both Ubuntu (should generally apply to Debian) and Fedora/RedHat-based systems:

    Ubuntu/Debian(个人使用ubuntu 9.10)

    The following list of packages should be accurate for Ubuntu 9.10 release; other releases or other Debian-based systems may slightly vary.


  5. minimal requirements for C++ (release): This is the minimal set of packages needed to run ns-3 from a released tarball.
 sudo 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.
 sudo apt-get install gcc g++ python python-dev
  • Running regression tests requires mercurial to fetch the trace repositories. mercurial is also needed in general to work with ns-3 development repositories.
 sudo apt-get install mercurial
  • Running python bindings from the ns-3 development tree (ns-3-dev) requires bazaar
 sudo apt-get install bzr
  • A GTK-based configuration system
 sudo apt-get install libgtk2.0-0 libgtk2.0-dev
  • Debugging:
 sudo apt-get install gdb valgrind 
  • Doxygen and related inline documentation:
 sudo apt-get install doxygen graphviz imagemagick
sudo apt-get install texlive texlive-pdf texlive-latex-extra texlive-generic-extra texlive-generic-recommended
此处运行显示找不到texlive-pdf,将此删掉即可!
  • The ns-3 manual and tutorial are written in Texinfo (doc/tutorial or doc/manual):
 sudo apt-get install texinfo dia texlive texlive-pdf texlive-latex-extra texlive-extra-utils texlive-generic-recommended texi2html
此处运行显示找不到texlive-pdf,将此删掉即可!
  • The Network Simulation Cradle (nsc) requires the flex lexical analyzer and bison parser generator:
 sudo apt-get install flex bison
  • Some basic mobility visualization tests require goocanvas:
 sudo apt-get install libgoocanvas-dev
  • To install gcc-3.4 for some Network Simulation Cradle (nsc) stacks:
 sudo apt-get install g++-4.0 gcc-4.0
  • To read pcap packet traces
sudo apt-get install tcpdump
  • 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
  • Support for Gustavo's ns-3-pyviz visualizer
sudo apt-get install python-pygraphviz python-kiwi python-pygoocanvas

Installation

The ns-3 code is available in Mercurial repositories on the server (look for the latest release e.g., "ns-3.4"). You can download a tarball of the latest release at or you can work with our repositories using Mercurial. We recommend using Mercurial unless there's a good reason not to (See the end of this section for instructions on how to get a tarball release).

The simplest way to get started using Mercurial repositories is to use the ns-3-allinone environment. This is a set of scripts that manages the downloading and building of various subystems of ns-3 for you. We recommend that you begin your ns-3 adventures in this environment as it can really simplify your life at this point.

Downloading ns-3 Using a Tarball

The process for downloading ns-3 via tarball is simpler than the Mercurial process since all of the pieces are pre-packaged for you. You just have to pick a release, download it and decompress it.

As mentioned above, one practice is to create a directory called repos in one's home directory under which one can keep local Mercurial repositories. One could also keep a tarballs directory. If you adopt the tarballs directory approach, you can get a copy of a release by typing the following into your Linux shell (substitute the appropriate version numbers, of course):

 cd
mkdir tarballs
cd tarballs
wget
tar xjf ns-allinone-3.7.1.tar.bz2

If you change into the directory ns-allinone-3.7.1 you should see a number of files:

 build.py*     ns-3.7.1/             nsc-0.5.1/             README  
constants.py ns-3.7.1-ref-traces/ pybindgen-0.12.0.703/ util.py

You are now ready to build the ns-3 distribution.

Building ns-3 with ns-3-allinone

The first time you build the ns-3 project you should build using the allinone environment. This will get the project configured for you in the most commonly useful way.

Change into the directory you created in the download section above. If you downloaded using Mercurial you should have a directory called ns-3-allinone under your ~/repos directory. If you downloaded using a tarball you should have a directory called something like ns-3-allinone-3.4 under your ~/tarballs directory. Type the following:

 ./build.py

You will see lots of typical compiler output messages displayed as the build script builds the various pieces you downloaded. Eventually you should see the following magic words:

 Build finished successfully (00:02:37)
Leaving directory `./ns-3-dev'

Once the project has built you typically will not use ns-3-allinone scripts. You will now interact directly with Waf and we do it in the ns-3-dev directory and not in the ns-3-allinone directory.

Configuration with Waf

To see valid configure options, type ./waf --help. The most important option is -d . Valid debug levels (which are listed in waf --help) are: "debug" or "optimized". It is also possible to change the flags used for compilation with (e.g.):

 CXXFLAGS="-O3" ./waf configure 

or, alternately, the gcc compiler

 CXX=g++-4.0 ./waf configure

Note: Unlike some other build tools, to change the build target, the option must be supplied during the configure stage rather than the build stage (i.e., "./waf -d optimized" will not work; instead, do

 ./waf -d optimized configure; ./waf 

The resulting binaries are placed in build//srcpath. For example, in a debug build you can find the executable for the first.cc example as build/debug/examples/first. You can debug the executable directly by:

 ./waf --shell
cd build/debug/examples
gdb first

Of course, you can run gdb in emacs, or use your favorite debugger such as ddd or insight just as easily. In an optimized build you can find the executable for the first.cc example as build/optimized/examples/first.

In order to forcibly disable python bindings, you can provide the following option:

 ./waf --disable-python configure

In order to tell the build system to use the sudo program to set the suid bit if required, you can provide the following option:

 ./waf --enable-sudo configure

To start over a configuration from scratch, type:

 ./waf distclean

Or if you get stuck and all else fails:

 rm -rf build

followed by changing back into ns-3-allinone and doing:

 ./build.py

will basically reset your build state.

To see all waf options:

 ./waf --help

Validating

ns-3 has unit tests that can be run to verify the installation:

 ./test.py

which should produce output like:

PASS: TestSuite histogram
PASS: TestSuite ns3-wifi-interference
PASS: TestSuite ns3-tcp-cwnd
PASS: TestSuite ns3-tcp-interoperability
PASS: TestSuite sample
...

To run the regression tests mentioned above:

 ./waf --regression

Remember to cd back into the top-level ns-3 directory after you are done:

cd ../../../../..

Running a Script

We typically run scripts under the control of Waf. This allows the build system to ensure that the shared library paths are set correctly and that the libraries are available at run time. To run a program, simply use the --run option in Waf. Let’s run the ns-3 equivalent of the ubiquitous hello world program by typing the following:

  ./waf --run hello-simulator

Waf first checks to make sure that the program is built correctly and executes a build if required. Waf then executes the program, which produces the following output.

  Hello Simulator

Congratulations. You are now an ns-3 user.

What do I do if I don’t see the output?

If you don’t see waf messages indicating that the build was completed successfully, but do not see the “Hello Simulator” output, chances are that you have switched your build mode to “optimized” in the “Building with Waf” section, but have missed the change back to “debug” mode. All of the console output used in this tutorial uses a special ns-3 logging component that is useful for printing user messages to the console. Output from this component is automatically disabled when you compile optimized code – it is “optimized out.” If you don’t see the “Hello Simulator” output, type the following,

  ./waf -d debug configure

to tell waf to build the debug versions of the ns-3 programs. You must still build the actual debug version of the code by typing,

  ./waf

Now, if you run the hello-simulator program, you should see the expected output.

If you want to run programs under another tool such as gdb or valgrind, see this .

阅读(10520) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2011-04-23 13:53:56

非常感谢!