
bab 1.2
3 Memulai
3.1 Tinjauan
3.2 Prasyarat
3.2.1 Unduh rilis ns-3 sebagai arsip sumber
3.3 Unduh ns-3 dengan Git
3.3.1 Unduh ns-3 dengan Bake
3.4 Build ns-3
3.4.1 Build with build.py
3.4.2 Build with Bake
3.4.3 Build with Waf
3.5 Testing ns-3
3.6 Menjalankan skrip
3.6.1 Argumen baris perintah
3.6.2 Debugging
3.6.3 Direktori kerja
bagian 3
Mulai
, , , , , nsā3. , , nsā3, nsā3 .
3.1
nsā3 . , . C++ Python.
Nsā3 , , , , . , nsā3 , . nsā3, . - , , ns-developers.
nsā3. , . ā nsā3. ā nsā3. , .
Linux , nsā3 , , ? , Linux (, Debian), nsā3, . .
nsā3 root , .
3.2
nsā3 , nsā3 ( ) : C++, Python, (, vim, emacs Eclipse) , , Git. , nsā3, , , , . «» , : https://www.nsnam.org/wiki/Installation.
Ā« Ā» - , nsā3, , Linux macOS.
, - nsā3 -: https://www.nsnam.org, . nsā3 (nsā3.29), nsā3 :
/
- C++
clang++ g++ (g++ 4.9 ) - Python
python2 >= 2.7.10, python3 >=3.4 - Git
( nsā3 GitLab.com) - tar
( nsā3) - bunzip2
( nsā3)
Python , python -V
. g++, g++ -v
. - , - nsā3.
, , Linux, MacOS Linux, .
3.2.1 ns-3
, nsā3. nsā3 , tarball. tarball ā , . . nsā3 tarball , , .
, , , nsā3 workspace. , Linux (, )
$ cd
$ mkdir workspace
$ cd workspace
$ wget https://www.nsnam.org/release/ns-allinone-3.29.tar.bz2
$ tar xjf ns-allinone-3.29.tar.bz2
wget, . , .
, ns-allinone-3.29,
$ cd ns-allinone-3.29
$ ls
bake constants.py ns-3.29 README
build.py netanim-3.108 pybindgen-0.17.0.post58+ngcf00cc0 util.py
nsā3 , nsā3.
3.3 ns-3 Git
nsā3 Git GitLab.com https://gitlab.com/nsnam/. nsnam , .
Git ā nsā3-allinone. , nsā3. Git, "" "" ; , ( ) , GitLab.com, :
$ cd
$ mkdir workspace
$ cd workspace
$ git clone https://gitlab.com/nsnam/ns-3-allinone.git
$ cd ns-3-allinone
nsā3-allinone . :
$ ls
build.py constants.py download.py README util.py
download.py, nsā3 . : nsā3:
$ python download.py
nsā3, -n
:
$ python download.py -n ns-3.29
nsā3-allinone nsā3, bake, pybindgen netanim.
Ubuntu16.04 : $ sudo python3 download.py -n ns-3.29
( ).
3.3.1 ns-3 Bake
( nsā3-allinone Git) nsā3 (pybindgen Python netanim ). , nsā3-allinone, bake.
Bake ā , nsā3. Bake nsā3, nsā3, Direct Code Execution, CradleNetwork Simulation Cradle, Python «» nsā3.
CradleNetwork Simulation Cradle ā , TCP / IP.
, nsā3 , .
nsā3 Bake tar-. , . , , Bake, nsā3.29, nsā3 , ( bakeconf.xml ).
bake, Linux ( , Git):
$ cd
$ mkdir workspace
$ cd workspace
$ git clone https://gitlab.com/nsnam/bake.git
git, - :
Cloning into 'bake'...
remote: Enumerating objects: 2086, done.
remote: Counting objects: 100% (2086/2086), done.
remote: Compressing objects: 100% (649/649), done.
remote: Total 2086 (delta 1404), reused 2078 (delta 1399)
Receiving objects: 100% (2086/2086), 2.68 MiB | 3.82 MiB/s, done.
Resolving deltas: 100% (1404/1404), done.
clone bake, :
$ cd bake
$ ls
bake bakeconf.xml bake.py doc examples generate-binary.py test TODO
, Python, Python bake XML. nsā3 . :
nsā3.29: , ; , tarball;
nsā3-dev: , ;
ns-allinone-3.29: , , Click Network Simulation Cradle, Openflow ns-3.
nsā3-allinone: allinone, .
Click ā .
Openflow ā , , - .
() nsā3 :https://gitlab.com/nsnam/ns-3-dev.git.
, , .
, , - Ā«nsā3 ReleasesĀ»:https://www.nsnam.org/releases/ . nsā3.29.
, nsā3, Bake. Bake.
Bake , source . Bake , , Bake , , bake ( PATH), , ( Linux bash). «bake», :
$ export BAKE_HOME=`pwd`
$ export PATH=$PATH:$BAKE_HOME:$BAKE_HOME/build/bin
$ export PYTHONPATH=$PYTHONPATH:$BAKE_HOME:$BAKE_HOME/build/lib
bake.py , bake. bake, PATH PYTHONPATH , nsā3-allinone ( ) .
:
$ ./bake.py configure -e ns-3.29
Bake , . :
$ ./bake.py check
- :
> Python - OK
> GNU C++ compiler - OK
> Mercurial - OK
> Git - OK
> Tar tool - OK
> Unzip tool - OK
> Make - OK
> cMake - OK
> patch tool - OK
> Path searched for tools: /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin ...
, , Mercurial, CVS, Git Bazaar, , . ( ) .
:
$ ./bake.py download
- :
>> Searching for system dependency setuptools - OK
>> Searching for system dependency libgoocanvas2 - OK
>> Searching for system dependency gi-cairo - OK
>> Searching for system dependency pygobject - OK
>> Searching for system dependency pygraphviz - OK
>> Searching for system dependency python-dev - OK
>> Searching for system dependency qt - OK
>> Searching for system dependency g++ - OK
>> Downloading pybindgen-0.19.0.post4+ng823d8b2 (target directory:pybindgen) - OK
>> Downloading netanim-3.108 - OK
>> Downloading ns-3.29 - OK
, . source ls; :
$ cd source
$ ls
netanim-3.108 ns-3.29 pybindgen
nsā3.
3.4 ns-3
nsā3, nsā3. , , nsā3 Waf, . Waf, , . , , Waf, build.py bake.
3.4.1 build.py
! , ; git bake.
tarball, nsā3āallinone , . build.py. . , , nsā3 nsā3, Waf, .
tarball, ~/workspace - ns-allinone-3.29. :
$ ./build.py --enable-examples --enable-tests
build.py , , nsā3 . , . , , nsā3 , .
, . netanim, pybindgen , , nsā3. , :
Waf: Leaving directory '/path/to/workspace/ns-allinone-3.29/ns-3.29/build'
'build' finished successfully (6m25.032s)
Modules built:
antenna aodv applications
bridge buildings config-store
core csma csma-layout
dsdv dsr energy
fd-net-device flow-monitor internet
internet-apps lr-wpan lte
mesh mobility mpi
netanim (no Python) network nix-vector-routing
olsr point-to-point point-to-point-layout
propagation sixlowpan spectrum
stats tap-bridge test (no Python)
topology-read traffic-control uan
virtual-net-device visualizer wave
wifi wimax
Modules not built (see ns-3 tutorial for explanation):
brite click openflow
Leaving directory ./ns-3.29
, :
Modules not built (see ns-3 tutorial for explanation):
brite click
, nsā3, , , , . , .
3.4.2 Bake
bake, nsā3. :
$ ./bake.py build
- :
>> Building pybindgen-0.19.0.post4+ng823d8b2 - OK
>> Building netanim-3.108 - OK
>> Building ns-3.29 - OK
: , , «bake.py deploy».
, . , , castxml bake . :
>> Building castxml - Problem
> Problem: Optional dependency, module "castxml" failed
This may reduce the functionality of the final build.
However, bake will continue since "castxml" is not an essential dependency.
For more information call bake with -v or -vvv, for full verbose mode.
castxml , Python. ( , nsā3), .
, :
$ ./bake.py show
, .
3.4.3 Waf
, nsā3, build.py, bake. nsā3 . , Waf nsā3. Waf nsā3. nsā3 Waf. , , , nsā3, .
, , . , , , . , . . Waf, , , :
$ ./waf clean
$ ./waf configure --build-profile=optimized --enable-examples --enable-tests
Waf ( ). , , ( . ); build/. , , :
Setting top to : /home/ns3user/workspace/bake/source/ns-3-dev
Setting out to : /home/ns3user/workspace/bake/source/ns-3-dev/build
Checking for 'gcc' (C compiler) : /usr/bin/gcc
Checking for cc version : 7.3.0
Checking for 'g++' (C++ compiler) : /usr/bin/g++
Checking for compilation flag -march=native support : ok
Checking for compilation flag -Wl,--soname=foo support : ok
Checking for compilation flag -std=c++11 support : ok
Checking boost includes : headers not found, please ,!provide a --boost-includes argument (see help)
Checking boost includes : headers not found, please ,!provide a --boost-includes argument (see help)
Checking for program 'python' : /usr/bin/python
Checking for python version >= 2.3 : 2.7.15 python-config : /usr/bin/python-config
Asking python-config for pyembed '--cflags --libs --ldflags' flags : yes
Testing pyembed configuration : yes
Asking python-config for pyext '--cflags --libs --ldflags' flags : yes
Testing pyext configuration : yes
Checking for compilation flag -fvisibility=hidden support : ok
Checking for compilation flag -Wno-array-bounds support : ok
Checking for pybindgen location : ../pybindgen ,!(guessed)
Checking for python module 'pybindgen' : 0.19.0. ,!post4+g823d8b2
Checking for pybindgen version : 0.19.0. ,!post4+g823d8b2
Checking for code snippet : yes
Checking for types uint64_t and unsigned long equivalence : no
Checking for code snippet : no
Checking for types uint64_t and unsigned long long equivalence : yes
Checking for the apidefs that can be used for Python bindings : gcc-LP64
Checking for internal GCC cxxabi : complete
Checking for python module 'pygccxml' : not found
Checking for click location : not found
Checking for program 'pkg-config' : /usr/bin/pkg- ,!config
Checking for 'gtk+-3.0' : not found
Checking for 'libxml-2.0' : yes
checking for uint128_t : not found
checking for __uint128_t : yes
Checking high precision implementation : 128-bit integer ,!(default)
Checking for header stdint.h : yes
Checking for header inttypes.h : yes
Checking for header sys/inttypes.h : not found
Checking for header sys/types.h : yes
Checking for header sys/stat.h : yes
Checking for header dirent.h : yes
Checking for header stdlib.h : yes
Checking for header signal.h : yes
Checking for header pthread.h : yes
Checking for header stdint.h : yes
Checking for header inttypes.h : yes
Checking for header sys/inttypes.h : not found
Checking for library rt : yes
Checking for header sys/ioctl.h : yes
Checking for header net/if.h : yes
Checking for header net/ethernet.h : yes
Checking for header linux/if_tun.h : yes
Checking for header netpacket/packet.h : yes
Checking for NSC location : not found
Checking for 'sqlite3' : not found
Checking for header linux/if_tun.h : yes
Checking for python module 'gi' : 3.26.1
Checking for python module 'gi.repository.GObject' : ok
Checking for python module 'cairo' : ok
Checking for python module 'pygraphviz' : 1.4rc1
Checking for python module 'gi.repository.Gtk' : ok
Checking for python module 'gi.repository.Gdk' : ok
Checking for python module 'gi.repository.Pango' : ok
Checking for python module 'gi.repository.GooCanvas' : ok
Checking for program 'sudo' : /usr/bin/sudo
Checking for program 'valgrind' : not found
Checking for 'gsl' : not found python-config : not found
Checking for compilation flag -fstrict-aliasing support : ok
Checking for compilation flag -fstrict-aliasing support : ok
Checking for compilation flag -Wstrict-aliasing support : ok
Checking for compilation flag -Wstrict-aliasing support : ok
Checking for program 'doxygen' : /usr/bin/doxygen
---- Summary of optional ns-3 features:
Build profile : optimized
Build directory :
BRITE Integration : not enabled (BRITE not enabled (see option --with- ,!brite))
DES Metrics event collection : not enabled (defaults to disabled)
Emulation FdNetDevice : enabled
Examples : enabled
File descriptor NetDevice : enabled
GNU Scientific Library (GSL) : not enabled (GSL not found)
Gcrypt library : not enabled
(libgcrypt not found: you can use ,!libgcrypt-config to find its location.) GtkConfigStore : not enabled (library 'gtk+-3.0 >= 3.0' not fou nd)
MPI Support : not enabled (option --enable-mpi not selected)
ns-3 Click Integration : not enabled (nsclick not enabled (see option --with- ,!nsclick))
ns-3 OpenFlow Integration : not enabled (Required boost libraries not found)
Network Simulation Cradle : not enabled (NSC not found (see option --with-nsc))
PlanetLab FdNetDevice : not enabled (PlanetLab operating system not detected ,!(see option --force-planetlab)) PyViz visualizer : enabled
Python API Scanning Support : not enabled (Missing 'pygccxml' Python module)
Python Bindings : enabled
Real Time Simulator : enabled
SQlite stats data output : not enabled (library 'sqlite3' not found)
Tap Bridge : enabled
Tap FdNetDevice : enabled
Tests : enabled
Threading Primitives : enabled
Use sudo to set suid bit : not enabled (option --enable-sudo not selected)
XmlIo : enabled
'configure' finished successfully (6.387s)
. nsā3 . , XmlTo, libxml-2.0. nsā3 , . , sudo suidĀ« ID Ā» . , Ā« Ā» (Ā«not enabledĀ»). , , Waf --check-config
.
, .
$ ./waf clean
$ ./waf configure --build-profile=debug --enable-examples --enable-tests
, nsā3, :
$ ./waf
nsā3 , , .
, :
$ ./waf --check-profile
Waf: Entering directory \`/path/to/ns-3-allinone/ns-3.29/build\'
Build profile: debug
build.py --enable-examples
--enable-tests
, Waf . , :
$ ./build.py --disable-python
:
build.py: error: no such option: --disable-python
, -āÆ- waf, :
$ ./build.py -- --disable-python
./waf configure --disable-python. Waf.
nsā3 C++, Linux MacOS. , , , , , . nsā3 , , , .
, nsā3.28 Fedora 28, gcc (gcc-8). nsā3.28 Fedora 28, Gtk2+, :
/usr/include/gtk-2.0/gtk/gtkfilechooserbutton.h:59:8: error: unnecessary parentheses ,!in declaration of ā__gtk_reserved1ā [-Werror=parentheses] void (*__gtk_reserved1);
, nsā3.28.1, Waf . Ā«-WerrorĀ» g++ clang ++. Ā«--disable-werrorĀ», :
$ ./waf configure --disable-werror --enable-examples --enable-tests
Waf , . , nsā3, suid sudo, . , , .
$ ./waf configure --enable-sudo --enable-examples --enable-tests
, Waf sudo, root. Waf . , :
$ ./waf --help
, .
, Waf debug optimized:
$ ./waf --build-profile=debug
, release. -d
--build-profile
. , (assertions) :

, . , ( ) .
, , Code Wrapper Macro:
NS_BUILD_DEBUG (std::cout << "Part of an output line..." << std::flush; timer.Start ,!()); DoLongInvolvedComputation ();
NS_BUILD_DEBUG (timer.Stop (); std::cout << "Done: " << timer << std::endl;)
, Waf . -āÆ-out
, :
$ ./waf configure --out=my-build-dir
, :
$ ./waf configure --build-profile=debug --out=build/debug
$ ./waf build
...
$ ./waf configure --build-profile=optimized --out=build/optimized
$ ./waf build
...
, . , Waf , .
, , . :
$ export NS3CONFIG="--enable-examples --enable-tests"
$ export NS3DEBUG="--build-profile=debug --out=build/debug"
$ export NS3OPT=="--build-profile=optimized --out=build/optimized"
$ ./waf configure $NS3CONFIG $NS3DEBUG
$ ./waf build
...
$ ./waf configure $NS3CONFIG $NS3OPT
$ ./waf build
Waf nsā3 C++ GCC ( g++). , Waf C++ , CXX. , ++ Clang, clang++,
$ CXX="clang++" ./waf configure
$ ./waf build
Waf distcc:
$ CXX="distcc g++" ./waf configure
$ ./waf build
distcc «». nsā3 , CXXFLAGS_EXTRA .
Waf . , build, Waf , .
, ./waf install. ā /usr/local, ./waf install /usr/local/bin, /usr/local/lib /usr/local/include. , sudo ./waf install. , Waf , , . -, . , --prefix
, :
./waf configure --prefix=/opt/local
, , ./waf
, /opt/local.
./waf clean
, Waf .
, nsā3 ./waf install
. , Waf , , nsā3.
Waf
nsā3 Waf-. , scratch/
, src/...
Waf. , , Waf :
$ ../../../waf ...
, . , emacs vim, , nsā3, . tarball, :
$ export NS3DIR="$PWD"
$ function waff { cd $NS3DIR && ./waf $* ; }
$ cd scratch
$ waff build
waf exec ../../waf
. , . , . , .
3.5 ns-3
nsā3, ./test.py:
$ ./test.py
Waf. ,
92 of 92 tests passed (92 passed, 0 failed, 0 crashed, 0 valgrind errors)
, valgrind, .
Waf , , :
Waf: Entering directory `/path/to/workspace/ns-3-allinone/ns-3-dev/build'
Waf: Leaving directory `/path/to/workspace/ns-3-allinone/ns-3-dev/build'
'build' finished successfully (1.799s)
Modules built:
aodv applications bridge
click config-store core
csma csma-layout dsdv
emu energy flow-monitor
internet lte mesh
mobility mpi netanim
network nix-vector-routing ns3tcp
ns3wifi olsr openflow
point-to-point point-to-point-layout propagation
spectrum stats tap-bridge
template test tools
topology-read uan virtual-net-device
visualizer wifi wimax
PASS: TestSuite ns3-wifi-interference
PASS: TestSuite histogram
...
PASS: TestSuite object
PASS: TestSuite random-number-generators
92 of 92 tests passed (92 passed, 0 failed, 0 crashed, 0 valgrind errors)
nsā3. ( , Ā«PASS: ā¦Ā» , . , ; .) Waf, test.py .
3.6
Waf. , . , Waf -āÆ-run
. nsā3 hello world, :
$ ./waf --run hello-simulator
Waf , , . Waf , .
Hello Simulator
! nsā3!
, ?
Waf, , , Ā«Hello SimulatorĀ», , [--Waf] optimized, debug. , , nsā3, , . ā «». Ā«Hello SimulatorĀ», :
$ ./waf configure --build-profile=debug --enable-examples --enable-tests
Waf nsā3, . ,
$ ./waf
, hello-simulator, .
3.6.1
nsā3, :
$ ./waf --run <ns3-program> --command-template="%s <args>"
<ns3-program> . -āÆ-command-template
Waf ā , , Waf . Waf , , , %s, . , , nsā3 :
$ ./waf --run '<ns3-program> --arg1=value1 --arg2=value2 ...'
, , . , (suite) mytest ( ). ./test.py , test-runner. test-runner :
$ ./waf --run test-runner --command-template="%s --suite=mytest --verbose"
test-runner. mytest , . test-runner :
$ ./waf --run test-runner --command-template="%s --help"
3.6.2
nsā3 , (, gdb) (, valgrind), -āÆ-command-template = "ā¦"
. , gdb hello-simulator nsā3 :
$ ./waf --run=hello-simulator --command-template="gdb %s --args <args>"
, nsā3 -āÆ-run
, ( gdb) -āÆ-command-template
. -āÆ-args
gdb, «» . ( gdb -āÆ-args
. -āÆ-command-template
gdb args.) :
$ ./waf --run test-runner --command-template="gdb %s --args --suite=mytest --verbose"
3.6.3
Waf nsā3. , . , nsā3? -āÆ-cwd
:
$ ./waf --cwd=...
. :
$ function waff {
CWD="$PWD"
cd $NS3DIR >/dev/null
./waf --cwd="$CWD" $*
cd - >/dev/null
}
Dekorasi versi sebelumnya dari perintah ini menyimpan direktori kerja saat ini, pergi ke direktori Waf , dan kemudian menginstruksikan Waf untuk mengubah direktori kerja kembali ke direktori kerja saat ini yang disimpan sebelum program dimulai. Kami menyebutkan perintah -āÆ-cwd
untuk kelengkapan, sebagian besar pengguna hanya meluncurkan Waf dari direktori tingkat atas dan menghasilkan file output di sana.
Lanjutan: Bab 4