如何用Linux系统安装ns3,NS3中文教学手册(5):NS3在Linux/Unbuntu下安装的全过程...

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:

Linux x86 gcc 4.2, 4.1, and, 3.4.6.

Linux x86_64 gcc 4.4.0, 4.3.2, 4.2.3, 4.2.1, 4.1.3, 3.4.6

MacOS X ppc and x86 (gcc 4.0.x and 4.2.x)

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.

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 bazaarsudo apt-get install bzr

A GTK-based configuration systemsudo 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 imagemagicksudo 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 tracessudo apt-get install tcpdump

Database support for statistics frameworksudo 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 visualizersudo 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):cdmkdir tarballscd tarballswgettar 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/ READMEconstants.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 compilerCXX=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 --shellcd build/debug/examplesgdb 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 histogramPASS: TestSuite ns3-wifi-interferencePASS: TestSuite ns3-tcp-cwndPASS: TestSuite ns3-tcp-interoperabilityPASS: 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 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值