नेटवर्क सिम्युलेटर ट्यूटोरियल एनएस -3। अध्याय 3


अध्याय १.२


3 आरंभ किया जा रहा है
3.1 अवलोकन
3.2 पूर्वापेक्षाएँ
3.2.1 स्रोत संग्रह के रूप में ns-3 रिलीज को
डाउनलोड करें 3.3 3.3 git के साथ ns-3 को डाउनलोड करें। 3.3 के साथ
डाउनलोड करें ns-3 Bake
3.4 के साथ ns-3
3.4.1 बनाएँ build.py
3.4.2 Bake के साथ बनाएँ
3.4.3 Waf
3.5 परीक्षण ns-3
3.6 के साथ बनाएँ स्क्रिप्ट रनिंग
3.6.1 कमांड लाइन तर्क
3.6.2 डिबगिंग
3.6.3 वर्किंग डायरेक्टरी


अध्याय 3


शुरू करना


, , , , , 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 . :


  1. ns‑3.29: , ; , tarball;


  2. ns‑3-dev: , ;


  3. ns-allinone-3.29: , , Click Network Simulation Cradle, Openflow ns-3.


  4. 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 
}

कमांड के पिछले संस्करण की यह सजावट वर्तमान कार्यशील निर्देशिका को बचाता है, Waf निर्देशिका में परिवर्तन करता है , और फिर Waf को निर्देश देता है कि वह कार्यशील निर्देशिका को वर्तमान कार्यशील निर्देशिका में बदल दे जो कि प्रोग्राम शुरू होने से पहले बच गई थी। हम - -cwdपूर्णता के लिए आदेश का उल्लेख करते हैं , अधिकांश उपयोगकर्ता बस एक उच्च-स्तरीय निर्देशिका से Waf लॉन्च करते हैं और वहां आउटपुट फाइलें उत्पन्न करते हैं।


जारी: अध्याय 4


All Articles