ns-3 network simulator qhia. Tshooj 3

ns-3 network simulator qhia. Tshooj 3
nqe 1,2

3 Pib pib
3.1 Txheej txheem cej luam
3.2 Yam yuavtsum tau kawm uantej
3.2.1 Rub tawm ns-3 tso tawm raws li qhov chaw khaws cia
3.3 Download ns-3 siv Git
3.3.1 Chaw thau khoom ns-3 siv Bake
3.4 Sib dhos ns-3
3.4.1 Tsev nrog build.py
3.4.2 Tsev nrog Ci
3.4.3 Tsim nrog Waf
3.5 Test ns-3
3.6 Khiav cov ntawv
3.6.1 Cov kab lus hais kom ua
3.6.2 Debugging
3.6.3 Cov ntaub ntawv ua haujlwm

Tshooj 3

Pib pib

Tshooj no yog npaj los npaj tus nyeem ntawv pib nrog lub computer uas tej zaum yuav tsis tau nruab ns-3. Nws suav nrog kev txhawb nqa platforms, yam yuav tsum tau ua ua ntej, yuav ua li cas kom tau ns-3, yuav ua li cas los tsim ns-3, thiab yuav ua li cas kuaj koj tsim thiab khiav cov kev pab cuam yooj yim.

3.1 Txheej txheem cej luam

Lub ns-3 simulator yog tsim los ua ib qho kev sib koom tes ntawm cov tsev qiv ntawv software. Thaum sib sau ua ke, cov cai ntawm cov neeg siv cov kev pab cuam txuas nrog cov tsev qiv ntawv no. C ++ lossis Python programming languages ​​yog siv los sau cov kev cai.

Ns-3 tau muab faib ua qhov chaws, uas txhais tau hais tias lub hom phiaj system yuav tsum muaj qhov chaw tsim kho software txhawm rau tsim cov tsev qiv ntawv thawj zaug thiab tom qab ntawd tsim cov neeg siv kev pab cuam. Hauv txoj ntsiab cai, ns-3 tuaj yeem muab faib ua cov tsev qiv ntawv npaj txhij rau ib qho kev tshwj xeeb, thiab yav tom ntej lawv yuav raug faib raws li qhov no. Tab sis tam sim no ntau tus neeg siv tau ua lawv txoj haujlwm los ntawm kev kho ns-3 nws tus kheej, yog li nws muaj txiaj ntsig zoo kom muaj cov cai los tsim cov tsev qiv ntawv. Yog tias leej twg xav ua haujlwm ntawm kev tsim cov tsev qiv ntawv npaj txhij thiab pob khoom rau kev khiav haujlwm, thov hu rau daim ntawv xa ntawv ns- developers.

Tom ntej no, peb yuav saib peb txoj hauv kev rub tawm thiab tsim ns-3. Thawj yog mus download tau thiab tsim lub official tso tawm los ntawm lub ntsiab site. Qhov thib ob yog kev xaiv thiab sib sau ua ke ntawm cov ntawv theej ntawm kev txhim kho versions ntawm qhov yooj yim ns-3 installation. Qhov thib peb yog siv cov cuab yeej tsim ntxiv kom thauj khoom ntxiv rau ns-3. Peb yuav dhau los ntawm txhua tus vim tias cov cuab yeej sib txawv me ntsis.

Cov neeg siv Linux paub txog yuav xav paub yog vim li cas ns-3 tsis muab raws li pob zoo li feem ntau lwm lub tsev qiv ntawv uas siv tus thawj tswj pob? Txawm hais tias muaj binary pob rau ntau yam Linux faib (xws li Debian), cov neeg siv feem ntau xaus rau kho cov tsev qiv ntawv thiab yuav tsum rov tsim kho ns-3 lawv tus kheej, yog li muaj cov cai muaj nyob hauv. Vim li no, peb yuav tsom mus rau kev txhim kho los ntawm qhov chaw.

Rau feem ntau daim ntawv thov ns-3 txoj cai hauv paus tsis xav tau, nws raug nquahu kom siv tus neeg siv tsis tau txais tus account.

3.2 Yam yuavtsum tau kawm uantej

Tag nrho cov txheej txheem ntawm ns-3 cov tsev qiv ntawv muaj ntau qhov kev cia siab ntawm cov tsev qiv ntawv thib peb, tab sis rau feem ntau ns-3 tuaj yeem tsim thiab siv nrog kev txhawb nqa rau ntau yam (feem ntau ntsia los ntawm lub neej ntawd) cov khoom: C ++ compiler, Python, tus kws kho qhov chaw code (piv txwv li, vim, emacs los yog dab noj hnub) thiab, yog siv cov chaw khaws ntaub ntawv txhim kho, Git version tswj tshuab. Feem ntau cov neeg siv thawj zaug yuav tsis tas yuav txhawj xeeb yog tias lawv qhov teeb tsa qhia qee qhov ns-3 cov yam ntxwv siab heev uas ploj lawm, tab sis rau cov neeg uas xav tau kev teeb tsa tag nrho, qhov project muab wiki uas suav nrog nplooj ntawv nrog ntau cov lus qhia muaj txiaj ntsig thiab kev ua kom yuam kev. Ib nplooj ntawv zoo li no yog nplooj Installation, nrog cov lus qhia kev teeb tsa rau ntau lub tshuab, muaj nyob ntawm: https://www.nsnam.org/wiki/Installation.

Cov Yam yuav tsum tau ua ua ntej ntawm qhov wiki no piav qhia cov pob twg yuav tsum tau txhawb nqa cov kev xaiv ns-3 thiab tseem muab cov lus txib uas siv los nruab rau ntawm cov khoom siv sib txawv ntawm Linux lossis macOS.

Koj tuaj yeem siv lub sijhawm no los tshawb txog ns-3 wiki nplooj ntawv lossis lub vev xaib tseem ceeb: https://www.nsnam.org, vim muaj ntau cov ntaub ntawv nyob ntawd. Pib nrog qhov tseeb version ntawm ns-3 (ns-3.29), cov cuab yeej hauv qab no yuav tsum tau khiav ns-3:

Tool Package/Version

  • C++ compiler
    clang ++ lossis g ++ (g ++ version 4.9 lossis siab dua)
  • Nab hab sej
    python2 version>= 2.7.10, lossis python3 version>=3.4
  • Cia li mus
    txhua qhov tseeb version (kom nkag mus rau ns-3 ntawm GitLab.com)
  • tar
    txhua qhov tseeb version (rau unpacking ns-3 tso tawm)
  • bunzip 2
    txhua qhov tseeb version (rau unpacking ns-3 tso tawm)

Txhawm rau txheeb xyuas lub neej ntawd version ntawm Python, ntaus python -V. Txhawm rau txheeb xyuas g ++ version, ntaus g++ -v. Yog tias cov cuab yeej ploj lawm lossis qub dhau lawm, thov mus saib daim ntawv qhia kev teeb tsa ntawm nplooj ntawv ns-3 wiki.

Txij no mus, peb xav tias tus nyeem ntawv tab tom khiav Linux, MacOS, lossis Linux emulator, thiab muaj tsawg kawg yog cov cuab yeej saum toj no.

3.2.1 Rub tawm ns-3 tso tawm raws li qhov chaw khaws cia

Nov yog chav kawm ntawm kev nqis tes ua rau tus neeg siv tshiab uas xav rub tawm thiab sim nrog qhov tseeb tso tawm thiab pob versions ntawm ns-3. ns-3 tso tawm yog luam tawm raws li compressed qhov chaw archives, qee zaum hu ua pob tawb. pob tawb yog ib qho tshwj xeeb software archive hom uas muaj ob peb cov ntaub ntawv ua ke ua ke. Lub archive feem ntau yog compressed. ns-3 boot process via pob tawb yog qhov yooj yim, koj tsuas yog yuav tsum xaiv qhov tso tawm, rub tawm thiab qhib nws.

Cia peb xav tias koj, raws li ib tug neeg siv, xav tsim ns-3 nyob rau hauv ib lub zos directory hu ua Ntshoo. Koj tuaj yeem tau txais daim ntawv luam tawm ua haujlwm los ntawm kev nkag mus rau hauv qab no rau hauv Linux console (hloov cov lej tsim nyog, tau kawg)

$ 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 

Ua tib zoo saib xyuas cov khoom siv hluav taws xob siv saum toj no wget, uas yog cov kab lus hais kom rub cov khoom los ntawm Is Taws Nem. Yog tias koj tsis tau nruab nws, koj tuaj yeem siv koj tus browser rau qhov no.

Ua raws li cov kauj ruam no yuav coj koj mus rau ns-allinone-3.29 directory, nyob ntawd koj yuav tsum pom ntau cov ntaub ntawv thiab cov npe

$ 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

Tam sim no koj tau npaj los tsim ns-3 lub hauv paus faib thiab tuaj yeem txav mus rau ntu ntawm lub tsev ns-3.

3.3 Download ns-3 siv Git

ns-3 code muaj nyob rau hauv Git repositories ntawm GitLab.com ntawm https://gitlab.com/nsnam/. Pab pawg nsnam coj los ua ke ntau qhov chaw cia khoom siv los ntawm qhov project qhib.

Qhov yooj yim tshaj plaws los pib siv Git repositories yog fork lossis clone ib puag ncig ns-3-allinone hmoov. Qhov no yog ib txheej ntawm cov ntawv sau uas tswj cov chaw thau khoom thiab sib dhos ntawm feem ntau siv ns-3 subsystems. Yog tias koj tshiab rau Git, cov lus "khob" thiab "clone" yuav tsis paub rau koj; Yog tias muaj, peb xav kom koj tsuas yog clone (ua koj tus kheej daim ntawv theej) lub chaw cia khoom nyob rau ntawm GitLab.com zoo li no:

$ cd 
$ mkdir workspace 
$ cd workspace 
$ git clone https://gitlab.com/nsnam/ns-3-allinone.git 
$ cd ns-3-allinone 

Nyob rau theem no, saib ntawm koj daim ntawv teev npe ns-3-allinone hmoov me ntsis txawv ntawm qhov tso tawm archive directory piav saum toj no. Nws yuav tsum zoo li no:

$ ls
build.py constants.py download.py README util.py

Thov nco ntsoov tias muaj ib tsab ntawv download.py, uas tseem yuav rho tawm ns-3 thiab nrog rau qhov chaws. Ntawm no koj muaj kev xaiv: yog download tau qhov tseeb ns-3 kev txhim kho snapshot:

$ python download.py

los yog nyiam ns-3 tso tawm siv tus chij -n qhia tus naj npawb tso tawm:

$ python download.py -n ns-3.29

Tom qab cov kauj ruam no mus rau lub directory ns-3-allinone hmoov ntxiv repositories yuav raug downloaded ns- 3, ci, pybindgen ua ΠΈ netanim.

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅
Ntawm lub tshuab nrog huv Ubuntu16.04, Kuv xav tau hloov cov lus txib rau qhov no: $ sudo python3 download.py -n ns-3.29 (tom qab no tus neeg txhais lus sau ntawv).

3.3.1 Chaw thau khoom ns-3 siv Bake

Ob txoj hauv kev saum toj no (qhov chaw khaws cia lossis chaw cia khoom ns-3-allinone hmoov ntawm Git) muaj txiaj ntsig zoo kom tau txais qhov yooj yim tshaj plaws ns-3 kev teeb tsa nrog ntau yam addons (pybindgen ua los tsim Python bindings thiab netanim rau network animation). Qhov thib peb repository muab los ntawm lub neej ntawd hauv ns-3-allinone hu ua ci.

Ci yog lub cuab yeej rau kev sib koom ua ke ntawm software los ntawm ntau qhov chaw cia khoom, tsim rau ns-3 qhov project. Ci tuaj yeem siv tau kom tau txais kev txhim kho versions ntawm ns-3, nrog rau rub tawm thiab tsim txuas ntxiv ntawm lub hauv paus version ntawm ns-3 faib, xws li ib puag ncig Direct Code Execution, CradleNetwork Simulation Cradle, muaj peev xwm tsim Python tshiab khi thiab ntau yam ns-3 "apps".

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅
CradleNetwork Simulation Cradle yog lub moj khaum uas tso cai rau koj siv tiag tiag TCP / IP network pawg hauv lub network simulator.

Yog tias koj cia siab tias koj qhov kev teeb tsa ns-3 kom muaj kev tshaj lij lossis cov yam ntxwv ntxiv, koj tuaj yeem ua raws li txoj kev teeb tsa no.

Hauv qhov tseeb ns-3 tso tawm Ci tau ntxiv rau qhov tso tawm tar. Qhov kev tso tawm suav nrog cov ntaub ntawv teeb tsa uas tso cai rau koj rub tawm cov software tam sim no thaum lub sijhawm tso tawm. Ntawd yog, piv txwv li, version Ci, uas tau muab faib nrog kev tso tawm ns-3.29, tuaj yeem siv los khaws cov khoom rau qhov kev tso tawm ntawm ns-3 lossis ua ntej, tab sis tsis tuaj yeem siv los khaws cov khoom rau tom qab tso tawm (yog tias cov ntaub ntawv piav qhia pob bakeconf.xml tsis hloov tshiab).

Koj tseem tuaj yeem tau txais daim ntawv theej kawg cilos ntawm kev nkag mus rau cov lus txib hauv qab no rau hauv koj lub console Linux (piv txwv tias koj tau nruab Git):

$ cd 
$ mkdir workspace 
$ cd workspace 
$ git clone https://gitlab.com/nsnam/bake.git

Thaum koj khiav git hais kom ua, koj yuav tsum pom qee yam zoo li hauv qab no:

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.

Tom qab cov lus txib ua tiav clone koj yuav tsum muaj ib daim ntawv teev npe ci, cov ntsiab lus uas yuav tsum zoo li no:

$ cd bake
$ ls
bake bakeconf.xml bake.py doc examples generate-binary.py test TODO

Nco ntsoov tias koj tau thauj ntau tus lej Python, ib qho Python module npe ci thiab XML configuration file. Cov kauj ruam tom ntej yog siv cov ntawv no los rub tawm thiab tsim cov ns-3 faib ntawm koj xaiv. Muaj ntau lub hom phiaj customization muaj:

  1. ns- 3.29: module sib raug rau kev tso tawm; nws yuav rub tawm cov khoom zoo ib yam li kev tso tawm hauv tarball;

  2. ns-3-dev: ib qho zoo sib xws module, tab sis siv cov cai los ntawm tsob ntoo kev loj hlob;

  3. ns-allinone-3.29: Ib qho qauv uas suav nrog lwm yam ntxiv xws li Nyem routing thiab Network Simulation Cradle, Openflow rau ns-3.

  4. ns-3-allinone hmoov: zoo ib yam li tso tawm version ntawm lub module allinone, tab sis rau txoj kev loj hlob.

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅
Nyem - modular software architecture rau tsim routers.

Openflow yog tus txheej txheem rau kev tswj cov txheej txheem ntawm kev ua cov ntaub ntawv xa tawm ntawm cov ntaub ntawv network los ntawm routers thiab keyboards, siv software-txhais network technology.

Kev txhim kho tam sim no snapshot (tsis tso tawm) ns-3 tuaj yeem pom ntawm:https://gitlab.com/nsnam/ns-3-dev.git.

Cov neeg tsim tawm sim khaws cov chaw khaws cia no hauv kev ua haujlwm zoo ib yam, tab sis lawv nyob hauv thaj chaw txhim kho thiab muaj cov cai tsis tau tso tawm, yog li yog tias koj tsis npaj yuav siv cov yam ntxwv tshiab, ces xaiv cov ntawv tso tawm.

Koj tuaj yeem pom qhov tseeb version ntawm cov cai los ntawm kev tshawb xyuas cov npe ntawm cov chaw khaws cia, lossis los ntawm kev mus rau ns-3 Tshaj tawm lub vev xaib:https://www.nsnam.org/releases/ thiab nyem rau ntawm qhov txuas tshiab kawg. Hauv qhov piv txwv no peb yuav txuas ntxiv nrog ns-3.29.

Tam sim no, kom tau txais ns-3 cov khoom peb xav tau, peb yuav siv lub cuab yeej Ci. Cia peb hais ob peb lo lus qhia txog kev ua haujlwm Ci.

Ci ua haujlwm los ntawm kev thauj khoom pob khoom mus rau hauv cov npe qhov chaw thiab txhim kho cov tsev qiv ntawv rau hauv cov ntaub ntawv tsim. Ci tuaj yeem khiav los ntawm kev xa cov binary, tab sis yog tias koj xav khiav Ci tsis yog los ntawm cov directory nyob rau hauv uas nws tau downloaded, nws yog advisable mus ntxiv txoj kev rau ci rau koj txoj kev (PATH ib puag ncig hloov pauv), piv txwv li hauv qab no (piv txwv li Linux bash plhaub). Mus rau "ci" directory thiab tom qab ntawd teeb tsa cov kev hloov pauv hauv qab no:

$ export BAKE_HOME=`pwd` 
$ export PATH=$PATH:$BAKE_HOME:$BAKE_HOME/build/bin 
$ export PYTHONPATH=$PYTHONPATH:$BAKE_HOME:$BAKE_HOME/build/lib

Qhov no yuav tso qhov program puv.py mus rau lub plhaub txoj kev thiab yuav tso cai rau lwm cov kev pab cuam nrhiav cov executables thiab cov tsev qiv ntawv uas nws tsim ci. Hauv qee qhov kev siv ci, PATH thiab PYTHONPATH teeb tsa tau piav qhia saum toj no tsis tas yuav tsum muaj, tab sis kev tsim ua tiav ntawm ns-3-allinone (nrog cov pob ntxiv) feem ntau xav tau nws.

Mus rau koj cov npe ua haujlwm thiab nkag mus rau hauv qab no hauv console:

$ ./bake.py configure -e ns-3.29

Tom ntej no peb yuav nug Ci xyuas yog tias peb muaj cov cuab yeej txaus los thauj cov khoom sib txawv. Dial:

$ ./bake.py check

Koj yuav tsum pom qee yam zoo li hauv qab no:

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

Tshwj xeeb, upload cov cuab yeej xws li Mercurial, CVS, Git thiab Bazaar yog qhov tseem ceeb hauv cov kauj ruam no vim lawv tso cai rau peb kom tau txais cov cai. Nyob rau theem no, teeb tsa cov cuab yeej uas ploj lawm hauv txoj hauv kev ib txwm rau koj lub cev (yog tias koj paub yuav ua li cas) lossis hu rau koj tus thawj tswj hwm kev pabcuam.

Tom ntej no, sim download tau lub software:

$ ./bake.py download

Qhov tshwm sim yuav tsum yog qee yam xws li:

>> 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

Qhov no yuav txhais tau tias peb qhov chaw tau rub tawm. Tam sim no mus rau qhov chaw directory thiab ntaus ls; Koj yuav tsum pom:

$ cd source 
$ ls
netanim-3.108 ns-3.29 pybindgen

Tam sim no koj npaj txhij los tsim ns-3 kev faib tawm.

3.4 Sib dhos ns-3

Raws li nrog rub tawm ns-3, muaj ntau txoj hauv kev los tsim ns-3. Qhov tseem ceeb uas peb xav hais txog yog tias ns-3 yog tsim los siv lub cuab yeej tsim hu ua Wafpiav hauv qab no. Cov neeg siv feem ntau yuav ua haujlwm nrog Waf, tab sis muaj ob peb phau ntawv siv tau los pab koj pib lossis teeb tsa ntau txoj kev tsim. Yog li thov, ua ntej koj nyeem txog Waf, saib ua.py thiab sib dhos nrog ci.

3.4.1 Tsev nrog build.py

Ceev faj Cov kauj ruam tsim no tsuas yog muaj los ntawm qhov chaw archive version tau raws li tau piav qhia saum toj no; thiab tsis rub tawm ntawm git lossis ci.

Thaum ua haujlwm nrog cov ntaub ntawv tso tawm pob tawb, nyob rau hauv ns-3-allinone hmoov Nws muaj cov ntawv sau ua ke uas tuaj yeem ua kom cov khoom sib dhos yooj yim dua. Nws hu ua build.py. Qhov kev pab cuam no yuav teeb tsa qhov project rau koj hauv txoj kev muaj txiaj ntsig tshaj plaws. Txawm li cas los xij, nco ntsoov tias kev teeb tsa ntau dua thiab ua haujlwm nrog ns-3 feem ntau yog siv ns-3 tus kheej tsim, Waf, uas yuav qhia tom qab hauv qhov kev qhia no.

Yog hais tias koj downloaded siv pob tawb, tom qab ntawd hauv koj phau ntawv teev npe ~ / chaw ua haujlwm ib daim ntawv teev npe nrog ib yam dab tsi zoo li ns-allinone-3.29. Sau cov hauv qab no:

$ ./build.py --enable-examples --enable-tests

Thaum hu ua.py Peb siv cov lus txib kab lus sib cav los tsim cov piv txwv thiab cov kev sim siv hauv qhov kev qhia no, uas tsis yog tsim los ntawm lub neej ntawd hauv ns-3. Los ntawm lub neej ntawd, qhov kev zov me nyuam kuj tsim tag nrho cov modules muaj. Tom qab ntawd, yog tias koj xav tau, koj tuaj yeem tsim ns-3 yam tsis muaj piv txwv thiab kev sim, lossis tshem tawm cov qauv uas tsis xav tau rau koj txoj haujlwm.

Koj yuav pom ntau cov lus tso tawm cov lus tso tawm los ntawm tsab ntawv vim nws tsim ntau qhov chaw koj tau thauj khoom. Ua ntej tsab ntawv yuav sim tsim cov animator netanim, ces lub binding generator pybindgen ua thiab thaum kawg ns-3. Thaum cov txheej txheem tiav, koj yuav tsum pom cov hauv qab no:

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

Hauv peb kab kawg ntawm cov npe peb pom cov lus hais txog modules uas tsis tau tsim:

Modules not built (see ns-3 tutorial for explanation):
brite                     click

Qhov no tsuas yog txhais tau hais tias qee qhov ns-3 modules nyob ntawm cov tsev qiv ntawv sab nraud yuav tsis tau tsim, lossis lawv tsis tas yuav tsum tau tsim rau qhov kev teeb tsa no. Qhov no tsis txhais tau hais tias lub simulator tsis tau sib sau ua ke lossis cov khoom sib dhos yuav tsis ua haujlwm raug.

3.4.2 Tsev nrog Ci

Yog tias koj siv ci saum toj no kom tau txais qhov chaws los ntawm qhov project repositories, koj tuaj yeem txuas ntxiv siv nws los tsim ns-3. Dial:

$ ./bake.py build

thiab koj yuav tsum pom tej yam zoo li:

>> Building pybindgen-0.19.0.post4+ng823d8b2 - OK 
>> Building netanim-3.108 - OK 
>> Building ns-3.29 - OK

Hint: Koj tuaj yeem ua ob qho tib si rub tawm thiab tsim cov kauj ruam ib zaug los ntawm kev hu "bake.py deploy".

Kev sib dhos tag nrho cov khoom yuav ua tsis tiav, tab sis kev sib dhos yuav txuas ntxiv yog tias tsis tas yuav tsum muaj cov khoom sib dhos. Piv txwv li, qhov teeb meem portability tsis ntev los no yog qhov ntawd castxml tuaj yeem ua ke los ntawm cov cuab yeej ci tsis nyob hauv txhua lub platform. Hauv qhov no, cov lus zoo li no yuav tshwm sim:

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

Txawm li cas los, castxml tsuas yog xav tau yog tias koj xav tsim Python bindings tshiab. Rau cov neeg siv feem ntau tsis tas yuav muaj qhov no (tsawg kawg kom txog thaum lawv hloov ns-3), yog li cov lus ceeb toom no tuaj yeem tsis quav ntsej txog kev nyab xeeb rau tam sim no.

Yog tias nws ua tsis tiav, cov lus txib hauv qab no yuav muab lus qhia rau koj txog qhov tsis muaj kev vam meej:

$ ./bake.py show

Ntau yam kev vam khom ntawm cov pob uas koj tab tom sim tsim yuav raug teev tseg.

3.4.3 Tsim nrog Waf

Txog rau qhov no, pib tsim ns-3, peb siv cov ntawv sau ua.py, los yog cuab yeej ci. Cov cuab yeej no muaj txiaj ntsig zoo rau kev tsim ns-3 thiab tswj cov tsev qiv ntawv. Qhov tseeb, tsim lawv khiav cov cuab yeej tsim Waf los ntawm ns-3 directory. Waf ntsia nrog ns-3 qhov chaws. Cov neeg siv feem ntau txav mus sai sai rau kev siv ncaj qha los teeb tsa thiab sib sau ua ke ns-3 Waf. Yog li, txhawm rau txuas ntxiv, thov mus rau ns-3 directory uas koj tau tsim ua ntej.

Qhov no tsis yog qhov yuav tsum tau nruj me ntsis rau lub sijhawm no, tab sis nws yuav muaj txiaj ntsig zoo rau kev rov qab me ntsis thiab saib yuav ua li cas hloov pauv rau qhov project configuration. Tej zaum qhov kev hloov pauv uas muaj txiaj ntsig tshaj plaws uas koj tuaj yeem ua tau yog los tsim kom tau qhov zoo tshaj plaws ntawm cov cai. Los ntawm lub neej ntawd, koj tau teeb tsa koj qhov project los tsim ib qho kev debug version. Cia wb mus saib ib qhov project los tsim ib qho kev tsim kho kom zoo. Txhawm rau piav qhia rau Waf tias nws yuav tsum ua kom zoo tshaj plaws tsim uas suav nrog cov piv txwv thiab kev sim, koj yuav tsum tau khiav cov lus txib hauv qab no:

$ ./waf clean 
$ ./waf configure --build-profile=optimized --enable-examples --enable-tests

Qhov no yuav tso tawm Waf sab nraum lub zos directory (rau koj yooj yim). Thawj cov lus txib ntxuav tawm los ntawm kev tsim yav dhau los, qhov no feem ntau tsis yog qhov tsim nyog, tab sis nws yog qhov kev coj ua zoo (tseem saib cov qauv hauv qab no); qhov no yuav tshem tawm cov tsev qiv ntawv uas tau tsim yav dhau los thiab cov khoom siv nyob hauv phau ntawv teev npe tsim/. Thaum qhov project yog reconfigured thiab lub build system xyuas ntau yam dependencies, koj yuav tsum pom cov zis zoo ib yam li cov hauv qab no:

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)

Thov nco ntsoov qhov kawg ntawm cov npe saum toj no. Qee qhov kev xaiv ns-3 tsis tau qhib los ntawm lub neej ntawd lossis xav tau kev txhawb nqa kom ua haujlwm zoo. Piv txwv li, txhawm rau pab XmlTo, lub tsev qiv ntawv yuav tsum muaj nyob rau hauv lub system libxml-2.0. Yog tias tsis pom lub tsev qiv ntawv no thiab qhov sib txuas ns-3 muaj nuj nqi tsis tau qhib, cov lus yuav tshwm sim. Kuj tseem nco ntsoov tias nws muaj peev xwm siv cov lus txib sudo los teeb lub suid me ntsis "set group ID ntawm runtime" rau tej yam kev pab cuam. Nws tsis yog enabled los ntawm lub neej ntawd thiab yog li no feature tshwm li "tsis enabled". Thaum kawg, kom tau txais cov npe ntawm cov kev xaiv qhib, siv Waf nrog parameter --check-config.

Tam sim no cia peb rov qab mus thiab hloov rov qab mus rau qhov kev debug tsim uas muaj cov piv txwv thiab kev sim.

$ ./waf clean 
$ ./waf configure --build-profile=debug --enable-examples --enable-tests

Lub kaw lus tsim tam sim no tau teeb tsa thiab koj tuaj yeem tsim kho qhov kev daws teeb meem ntawm ns-3 cov kev pab cuam los ntawm kev ntaus ntawv yooj yim:

$ ./waf

Cov kauj ruam saum toj no yuav tau yuam kom koj tsim ib feem ntawm ns-3 system ob zaug, tab sis tam sim no koj paub yuav ua li cas hloov cov kev teeb tsa thiab tsim kom zoo code.

Txhawm rau txheeb xyuas qhov profile twg ua haujlwm rau qhov kev teeb tsa qhov project, muaj lus txib:

$ ./waf --check-profile 
Waf: Entering directory `/path/to/ns-3-allinone/ns-3.29/build' 
Build profile: debug

Cov xwm txheej saum toj no ua.py kuj txhawb kev sib cav --enable-examples ΠΈ --enable-tests, tab sis lwm txoj kev xaiv Waf nws tsis txhawb ncaj qha. Piv txwv li, qhov no yuav tsis ua haujlwm:

$ ./build.py --disable-python

Cov tshuaj tiv thaiv yuav zoo li no:

build.py: error: no such option: --disable-python

Txawm li cas los xij, tus neeg teb xov tooj tshwj xeeb - tuaj yeem siv los hla cov kev txwv ntxiv ntawm waf uaYog li es tsis txhob saum toj no cov lus txib hauv qab no yuav ua haujlwm:

$ ./build.py -- --disable-python

vim nws generates lub ntsiab lus txib ./waf configure --disable-python. Nov yog qee cov lus qhia ntxiv txog Waf.

Txhim kho qhov yuam kev

ns-3 tso tawm tau sim ntawm qhov tseeb C ++ compilers muaj nyob rau lub sijhawm tso tawm ntawm Linux thiab MacOS kev faib tawm. Txawm li cas los xij, dhau sij hawm, kev faib tawm tshiab tau tso tawm nrog cov neeg sau tshiab, thiab cov ntawv sau tshiab no yuav ua rau muaj kev ceeb toom ntau dua. ns-3 configures nws tsim los kho tag nrho cov lus ceeb toom ua yuam kev, yog li qee zaum yog tias koj tab tom khiav ib qho qub version ntawm lub kaw lus tshiab, cov lus ceeb toom compiler yuav nres qhov tsim.

Piv txwv li, yav dhau los muaj kev tso tawm ntawm ns-3.28 rau Fedora 28, uas suav nrog cov ntawv loj tshiab gcc (gcc-8). Tsim qhov tso tawm ns-3.28 lossis cov qauv ua ntej hauv qab Fedora 28, nrog Gtk2+ ntsia, qhov yuam kev hauv qab no yuav tshwm sim:

/usr/include/gtk-2.0/gtk/gtkfilechooserbutton.h:59:8: error: unnecessary parentheses ,!in declaration of β€˜__gtk_reserved1’ [-Werror=parentheses] void (*__gtk_reserved1);

Hauv kev tshaj tawm pib los ntawm ns-3.28.1, hauv Waf muaj kev xaiv los daws cov teeb meem no. Nws lov tes taw teeb tsa "-Werror" chij hauv g ++ thiab clang ++. Qhov no yog qhov kev xaiv "--disable-werror" thiab yuav tsum tau siv thaum lub sijhawm teeb tsa:

$ ./waf configure --disable-werror --enable-examples --enable-tests

Configure los yog assemble

Qee cov lus txib Waf muaj lub ntsiab lus tsuas yog nyob rau hauv lub configuration theem, thiab ib co tsuas siv tau nyob rau hauv lub tsim theem. Piv txwv li, yog tias koj xav siv ns-3 emulation nta, koj tuaj yeem ua kom qhov chaw me ntsis sab qab teb siv sudo, raws li tau piav saum toj no. Qhov no yuav override lub configuration kauj ruam commands, thiab yog li koj muaj peev xwm hloov lub configuration siv cov nram qab no hais kom ua, uas kuj muaj xws li cov piv txwv thiab cov kev xeem.

$ ./waf configure --enable-sudo --enable-examples --enable-tests

Yog koj ua li no Waf yuav tso tawm sudohloov emulation code qhov (socket) creation cov kev pab cuam khiav nrog kev tso cai hauv paus. Cov Waf Muaj ntau ntau lwm yam kev xaiv muaj rau kev teeb tsa thiab tsim cov kauj ruam. Txhawm rau tshawb xyuas koj cov kev xaiv, nkag mus:

$ ./waf --help

Hauv seem tom ntej no peb yuav siv qee qhov kev ntsuam xyuas ntsig txog kev xaiv.

Sib dhos Profiles

Peb twb pom tias koj tuaj yeem teeb tsa li cas Waf rau cov rooj sib txoos debug ΠΈ optimized:

$ ./waf --build-profile=debug

Kuj tseem muaj qhov nruab nrab sib dhos profile, tso tawm. Kev xaiv -d yog synonymous nrog --build-profile. Tus tsim profile tswj kev siv cov ntawv txiav, kev lees paub, thiab kev ua kom zoo tshaj plaws ntawm cov keyboards:

ns-3 network simulator qhia. Tshooj 3

Raws li koj tuaj yeem pom, kev sau npe thiab kev lees paub tsuas yog muaj nyob rau hauv kev debug tsim. Qhov kev coj ua uas pom zoo yog los tsim koj tsab ntawv hauv hom kev debug, tom qab ntawd ua haujlwm rov ua dua (rau kev txheeb cais lossis kev hloov pauv) hauv qhov kev tsim kho kom zoo.

Yog tias koj muaj cov cai uas yuav tsum tsuas yog khiav hauv qee qhov kev tsim profile, siv 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;)

Raws li, Waf qhov chaw tsim artifacts nyob rau hauv lub build directory. Koj tuaj yeem hais qhia cov ntawv tso zis sib txawv siv qhov kev xaiv -β€―-out, piv txwv:

$ ./waf configure --out=my-build-dir

Los ntawm kev sib txuas qhov no nrog tsim cov profiles, koj tuaj yeem yooj yim hloov ntawm cov kev xaiv sib txawv:

$ ./waf configure --build-profile=debug --out=build/debug
$ ./waf build
... 
$ ./waf configure --build-profile=optimized --out=build/optimized 
$ ./waf build
...

Uas tso cai rau koj ua hauj lwm nrog ntau lub rooj sib txoos tsis tas yuav rov sau dua tshiab los ua ke txhua zaus. Thaum koj hloov mus rau lwm qhov profile, Waf yuav compile nkaus xwb, tsis tas recompiling txhua yam.

Thaum koj hloov tsim cov profiles hauv qhov no, koj yuav tsum tau ceev faj kom muab cov kev teeb tsa tib lub sijhawm. Kev txhais ntau qhov sib txawv ntawm ib puag ncig yuav pab koj kom tsis txhob yuam kev:

$ 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

Compilers thiab chij

Hauv cov piv txwv saum toj no Waf tsim ns-3 siv C ++ compiler los ntawm GCC ( g ++). Txawm li cas los xij, koj tuaj yeem hloov qhov koj siv Waf C ++ compiler, los ntawm kev txhais cov CXX ib puag ncig hloov pauv. Piv txwv li, siv C ++ compiler Clang, clang ++,

$ CXX="clang++" ./waf configure 
$ ./waf build 

Ib yam li koj tuaj yeem teeb tsa Waf siv faib compilation siv distcc:

$ CXX="distcc g++" ./waf configure 
$ ./waf build

Xav paub ntau ntxiv txog distcc thiab faib muab tso ua ke tuaj yeem pom nyob rau ntawm nplooj ntawv project hauv Cov Ntaub Ntawv seem. Txhawm rau ntxiv cov chij compiler thaum teeb tsa ns-3, siv CXXFLAGS_EXTRA ib puag ncig hloov pauv.

chaw

Waf tuaj yeem siv los txhim kho cov tsev qiv ntawv hauv ntau qhov chaw ntawm qhov system. Los ntawm lub neej ntawd, cov tsev qiv ntawv uas tau muab tso ua ke thiab cov executables nyob rau hauv cov npe tsim, thiab txij li Waf paub qhov chaw ntawm cov tsev qiv ntawv no thiab cov haujlwm ua tiav, tsis tas yuav nruab cov tsev qiv ntawv nyob qhov twg.

Yog tias cov neeg siv xav nruab sab nraum cov ntawv tsim, lawv tuaj yeem khiav cov lus txib ./waf nruab. Lub default prefix rau installation yog / usr / zostias yog vim li cas ./waf nruab yuav nruab cov kev pab cuam hauv / usr / zos / hauv, cov tsev qiv ntawv hauv / usr / zos / lib thiab header files hauv /usr/local/include. Superuser txoj cai feem ntau yuav tsum tau teeb tsa nrog lub npe ua ntej, yog li cov lus txib ib txwm yuav sudo ./waf nruab. Thaum pib, Waf yuav xub xaiv los siv cov tsev qiv ntawv sib koom hauv cov npe tsim, tom qab ntawd nrhiav cov tsev qiv ntawv raws txoj hauv kev mus rau cov tsev qiv ntawv teeb tsa hauv cheeb tsam ib puag ncig. Yog li thaum txhim kho cov tsev qiv ntawv hauv ib qho system, nws yog ib qho kev coj ua zoo los xyuas tias cov tsev qiv ntawv raug siv. Cov neeg siv tuaj yeem xaiv rau nruab nrog lub npe sib txawv los ntawm kev dhau qhov kev xaiv thaum lub sijhawm teeb tsa --prefix, piv txwv:

./waf configure --prefix=/opt/local

Yog tias tom qab ntawd, tom qab tsim, tus neeg siv nkag mus rau cov lus txib installation ./waf, lub prefix yuav siv /opt/local.

pab neeg ./waf clean yuav tsum tau siv ua ntej reconfigure qhov project yog hais tias lub installation yuav siv Waf nyob rau hauv ib tug txawv prefix.

Yog li, siv ns-3 tsis tas yuav hu ./waf install. Cov neeg siv feem ntau yuav tsis xav tau cov lus txib no vim Waf yuav khaws cov tsev qiv ntawv tam sim no los ntawm cov npe tsim, tab sis qee cov neeg siv yuav pom qhov no muaj txiaj ntsig yog tias lawv cov dej num cuam tshuam nrog kev ua haujlwm nrog cov kev pab cuam sab nraum ns-3 directory.

Waf ib

Nyob rau theem sab saum toj ntawm ns-3 qhov chaw ntoo, tsuas muaj ib tsab ntawv Waf xwb. Thaum koj pib ua haujlwm, koj yuav siv sijhawm ntau hauv phau ntawv teev npe scratch/ los yog tob rau hauvsrc/... thiab tib lub sijhawm yuav tsum tau khiav Waf. Koj tsuas nco qab koj nyob qhov twg thiab khiav Waf raws li nram no:

$ ../../../waf ...

tab sis qhov no yuav tedious thiab yuam kev, yog li muaj cov kev daws teeb meem zoo dua. Ib txoj hauv kev yog siv cov ntawv nyeem xws li emacs los yog vim, nyob rau hauv uas ob lub davhlau ya nyob twg tau qhib, ib qho yog siv los tsim ns-3, thiab qhov thib ob yog siv los kho qhov chaws. Yog tias koj tsuas muaj pob tawb, ces qhov kev hloov pauv ib puag ncig tuaj yeem pab:

$ export NS3DIR="$PWD" 
$ function waff { cd $NS3DIR && ./waf $* ; } 

$ cd scratch 
$ waff build

Nyob rau hauv phau ntawv qhia module nws yuav ntxias ntxiv ib qho tsis tseem ceeb waf tsab ntawv zoo li exec ../../waf. Thov, txhob ua li ntawd. Qhov no yog qhov tsis meej pem rau cov neeg tshiab thiab, thaum ua tsis tau zoo, ua rau nyuaj-rau-nrhiav qhov yuam kev. Cov kev daws teeb meem saum toj no yog txoj hauv kev uas yuav tsum tau siv.

3.5 Test ns-3

Koj tuaj yeem khiav ns-3 qhov kev faib tawm chav kuaj los ntawm kev khiav cov ntawv ./test.py:

$ ./test.py

Cov kev ntsuam xyuas no tau khiav ua ke nrog Waf. Thaum kawg koj yuav tsum pom cov lus hais tias:

92 of 92 tests passed (92 passed, 0 failed, 0 crashed, 0 valgrind errors)

Qhov no yog cov lus tseem ceeb rau kev txheeb xyuas qhov kev sib tsoo valgrind, kev sib tsoo lossis yuam kev, qhia txog teeb meem nrog cov cai lossis kev tsis sib haum xeeb ntawm cov cuab yeej thiab cov cai.

Koj tseem yuav pom qhov kawg tso zis los ntawm Waf thiab tus tester khiav txhua qhov kev xeem, uas yuav zoo li no:

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)

Cov lus txib no feem ntau yog khiav los ntawm cov neeg siv kom paub tseeb tias qhov kev faib tawm ns-3 tau tsim kom raug. (Nco ntsoov tias qhov kev txiav txim ntawm "PASS: ... Thiab Wafthiab tes.py yuav ua kom sib luag ua haujlwm thoob plaws lub processor cores ntawm lub tshuab.

3.6 Khiav cov ntawv

Peb feem ntau khiav scripts nyob rau hauv kev tswj Waf. Qhov no tso cai rau cov txheej txheem tsim kom ntseeg tau tias cov tsev qiv ntawv sib koom tau teeb tsa kom raug thiab cov tsev qiv ntawv muaj nyob rau ntawm lub sijhawm ua haujlwm. Txhawm rau khiav qhov program, tsuas yog siv Waf nrog parameter -β€―-run. Cia peb khiav ns-3 sib npaug ntawm qhov kev pab cuam ubiquitous nyob zoo lub ntiaj teb nolos ntawm kev ntaus cov hauv qab no:

$ ./waf --run hello-simulator

Waf yuav xub xyuas seb qhov kev zov me nyuam tau tsim kom raug thiab tsim yog tias tsim nyog. Ces Waf yuav ua ib qhov kev pab cuam uas tsim cov zis hauv qab no.

Hello Simulator

Nrog koj zoo siab! Tam sim no koj yog tus neeg siv ns-3!

Kuv yuav ua li cas yog tias kuv tsis pom cov txiaj ntsig?

Yog koj pom cov lus Wafqhia tias kev tsim ua tiav tiav, tab sis koj tsis pom cov zis "Nyob Zoo Simulator", tom qab ntawd muaj qhov ua tau tias nyob rau hauv ntu [Build-with-Waf] koj hloov koj hom tsim rau optimized, tab sis tsis nco qab hloov mus rau hom debug. Tag nrho cov console tso zis siv nyob rau hauv no nyeem siv ib tug tshwj xeeb ns-3 tivthaiv uas ua kev txiav txim thiab yog siv los luam cov lus kev cai rau lub console. Cov zis tawm los ntawm qhov kev tivthaiv no tau txais kev xiam oob khab thaum optimized code yog compiled - nws yog "optimized". Yog tias koj tsis pom "Hello Simulator" tso tawm, nkag mus rau hauv qab no:

$ ./waf configure --build-profile=debug --enable-examples --enable-tests

rau configure Waf los tsim kev debug versions ntawm ns-3 cov kev pab cuam, uas suav nrog cov piv txwv thiab kev sim. Tom qab ntawd koj yuav tsum rov tsim kho qhov kev debug tam sim no ntawm tus lej los ntawm kev ntaus ntawv

$ ./waf

Tam sim no yog tias koj khiav qhov program nyob zoo-simulator, koj yuav tsum pom qhov kev xav tau.

3.6.1 Cov kab lus hais kom ua

Txhawm rau hla cov kab lus hais kom ua rau ns-3 program, siv cov qauv hauv qab no:

$ ./waf --run <ns3-program> --command-template="%s <args>"

Hloov nrog lub npe ntawm koj qhov program thiab cov lus sib cav. Kev sib cav -β€―-command-template rau Waf yog qhov tseem ceeb ntawm daim ntawv qhia rau kev tsim cov kab hais kom ua tiag tiag Waf siv los ua qhov program. Waf tshawb xyuas tias kev tsim ua tiav, teeb tsa txoj hauv kev sib koom hauv tsev qiv ntawv, tom qab ntawd siv cov kab lus hais kom ua qauv thiab hloov lub npe program rau %s qhov chaw hu rau kev ua tiav. Yog tias koj pom cov syntax nyuaj, muaj ib qho yooj yim version uas cuam tshuam nrog ns-3 qhov kev pab cuam thiab nws cov lus sib cav nyob hauv ib nqe lus:

$ ./waf --run '<ns3-program> --arg1=value1 --arg2=value2 ...'

Lwm qhov piv txwv tshwj xeeb uas muaj txiaj ntsig zoo yog khiav cov chav sim xaiv xaiv. Cia peb xav tias muaj ib chav kuaj hu ua mytest (qhov tseeb tsis muaj). Saum toj no peb siv ./test.py tsab ntawv los khiav ib tug xov tooj ntawm kev xeem nyob rau hauv parallel, uas pheej rov hu rau qhov kev xeem xeem-khiav. Hu xeem-khiav ncaj qha mus khiav ib qho kev xeem:

$ ./waf --run test-runner --command-template="%s --suite=mytest --verbose"

Cov lus sib cav yuav dhau mus rau qhov program xeem-khiav. Txij li tsis muaj mytest, cov lus yuam kev yuav raug tsim tawm. Txhawm rau luam tawm cov kev xaiv xeem-khiav, sau:

$ ./waf --run test-runner --command-template="%s --help"

3.6.2 Debugging

Txhawm rau khiav ns-3 cov kev pab cuam nyob rau hauv lwm qhov chaw siv hluav taws xob, xws li kev debugger (piv txwv li, ua gdb) los yog lub cim xeeb ntsuas (piv txwv li, valgrind ua), siv daim ntawv zoo sib xws -β€―-command-template = "…". Piv txwv li, khiav hauv qhov debugger ua gdb koj nyob zoo-simulator ns-3 qhov kev pab cuam nrog kev sib cav:

$ ./waf --run=hello-simulator --command-template="gdb %s --args <args>"

Nco ntsoov tias ns-3 program npe los nrog kev sib cav -β€―-run, thiab kev tswj kev siv hluav taws xob (ntawm no ua gdb) yog thawj token hauv kev sib cav -β€―-command-template. Kev xaiv -β€―-args qhia ua gdbtias tus so ntawm kab hais kom ua belongs rau qhov kev pab cuam "qis". (Qee versions ua gdb tsis to taub qhov kev xaiv -β€―-args. Hauv qhov no, tshem tawm cov lus sib cav ntawm qhov program -β€―-command-template thiab siv cov lus txib ua gdb args).

$ ./waf --run test-runner --command-template="gdb %s --args --suite=mytest --verbose"

3.6.3 Cov ntaub ntawv ua haujlwm

Waf yuav tsum tau pib los ntawm nws qhov chaw nyob rau saum toj ntawm tsob ntoo ns-3. Cov ntawv tais ceev tseg no dhau los ua cov npe ua haujlwm uas cov ntaub ntawv tso tawm yuav raug sau. Tab sis ua li cas yog tias koj xav khaws cov ntaub ntawv no sab nraum ns-3 qhov chaw ntoo? Siv kev sib cav -β€―-cwd:

$ ./waf --cwd=...

Koj tuaj yeem pom nws yooj yim dua kom tau txais cov ntaub ntawv tso tawm hauv koj daim ntawv teev npe ua haujlwm. Hauv qhov no, kev ua tsis ncaj hauv qab no tuaj yeem pab:

$ function waff {
CWD="$PWD" 
cd $NS3DIR >/dev/null 
./waf --cwd="$CWD" $*
cd - >/dev/null 
}

Qhov kev kho kom zoo nkauj ntawm cov ntawv dhau los ntawm cov lus txib khaws cia cov ntaub ntawv ua haujlwm tam sim no, mus rau hauv phau ntawv teev npe Wafthiab ces qhia Waf hloov cov ntaub ntawv ua haujlwm rov qab mus rau cov npe ua haujlwm tam sim no tau khaws tseg ua ntej pib qhov program. Peb hais txog pab neeg -β€―-cwd Rau kev ua tiav, cov neeg siv feem ntau tsuas yog khiav Waf los ntawm cov ntawv teev npe saum toj kawg nkaus thiab tsim cov ntaub ntawv tso tawm muaj.

Txuas ntxiv: Tshooj 4

Tau qhov twg los: www.hab.com

Ntxiv ib saib