39. Rc1 Simulazione-ns3

download 39. Rc1 Simulazione-ns3

of 31

Transcript of 39. Rc1 Simulazione-ns3

  • 8/9/2019 39. Rc1 Simulazione-ns3

    1/80

      Simulation of computer networks 1

    Corso di Reti di Calcolatori I

    Network simulation with ns-3

  • 8/9/2019 39. Rc1 Simulazione-ns3

    2/80

      Simulation of computer networks 2

    Outline of presentation

    • Breve introduzione al concetto disimulazione di computer networks

    •Tutorial su ns-3 – ntroduzione – !rchitettura

     – "ettura di codice

  • 8/9/2019 39. Rc1 Simulazione-ns3

    3/80

    Simulation of computer networks 3

    To evaluate protocols and distri#uted al$orithms forcomputer networks the followin$ alternatives are

    possi#le%

    1& Small scale e'perimental test#eds (in the la#orator)&

    2& Test#ed sperimentali su media scala (wide area&* +lanet"a#

    3& Sistemi di network emulation

    ,& !m#ienti di simulazione $enerali per reti di calcolatori

    • ns-3* "./.S/* .+N0T* NTns*

    1& Strumenti di simulazione sviluppati ad hoc 

    2& /odelli matematici del sistema

    Simulation of computer networks

  • 8/9/2019 39. Rc1 Simulazione-ns3

    4/80

  • 8/9/2019 39. Rc1 Simulazione-ns3

    5/80

    Simulation of computer networks 4

    What is simulation?

    system under study(has deterministic rulesgoverning its behavior)

    exogenous inputsto system

    (the environment)

    system boundary

    observer

    “real” life

    computer program

    simulates deterministicrules governing behavior

    pseudo random inputs

    to system(models environment)

    program boundary

    observer

    “simulated” life

  • 8/9/2019 39. Rc1 Simulazione-ns3

    6/80

    Simulation of computer networks 5

    Why Simulation?

    goal: stud) s)stem performance, operation real-s)stem not available, is complex/costly or

    dangerous ( e$% space simulations* fli$ht simulations& 6uickl) evaluate desi$n alternatives (e$% different

    s)stem confi$urations& evaluate complex functions for which closed form

    formulas or numerical techni6ues not availa#le Need of complete control over the inputs of the s)stem

  • 8/9/2019 39. Rc1 Simulazione-ns3

    7/80

    Simulation of computer networks 7

     !strazione enerazione di scenari (topolo$ie* pattern di

    traffico* 888&

    +ro$ramma#ilit9

    0stendi#ilit9 :isponi#ilit9 di un;ampia $amma di moduli

    di protocolli riutilizza#ili* affida#ili e validati

    +ossi#ilit9 di modificare protocolli esistenti

  • 8/9/2019 39. Rc1 Simulazione-ns3

    8/80

    Simulation of computer networks =

    Prorammin a simulation

    >hat ?s in a simulation pro$ram@ simulated time: internal (to simulation pro$ram& varia#le thatkeeps track of simulated time

    system “state”: varia#les maintained #) simulation pro$ramdefine s)stem Astate

    e8$8* ma) track num#er (possi#l) order& of packets in 6ueue* currentvalue of retransmission timer 

    events: points in time when s)stem chan$es state each event has associated event time

    e8$8* arrival of packet to 6ueue* departure from 6ueue

    precisel) at these points in time that simulation musttake action (chan$e state and ma) cause new futureevents&

    model for time #etween events (pro#a#ilistic& caused #) e'ternalenvironment

  • 8/9/2019 39. Rc1 Simulazione-ns3

    9/80

    Simulation of computer networks C

    !iscrete "vent Simulation

    simulation pro$ram maintains and updates list of futureevents% event list

    simulator structure%

    initialize event list

    $et ne't (nearest future&event from event list

    time D event time

    process event(chan$e state values* addEdelete

    future events from event list

    update statistics

    done@no

    Need%

    well defined set ofevents

    for each event%simulated s)stemaction* updatin$ ofevent list

     yes

  • 8/9/2019 39. Rc1 Simulazione-ns3

    10/80

    Simulation of computer networks 1F

    Thins to remem#er a#out !iscrete "vent Simulation

    The pro$rammin$ model revolves around Aevents(e$% packet arrivals&% 0vents tri$$er particular su#-routines

    Gu$e Aswitch statement to classif) events and call appropriatesu#routine

    The su#routine ma) schedule new eventsH (cannot scheduleevents for past* 8e8* events are causal&

    Iarel) )ou mi$ht introduce new event types

    0vents have associated with them% 0vent t)pe* event data structures (e$% packet&

    Simulation time when the event is scheduled Je) event operations% Enqueue (8e8 schedule a event&

    :e6ueue is handled #) the simulation en$ine

  • 8/9/2019 39. Rc1 Simulazione-ns3

    11/80

    Simulation of computer networks 11

    !iscrete "vent Simulation$ Scheduler 

    +urpose% maintain a notion of simulation time* scheduleevents8 !8k8a% Asimulation en$ine Simulation time ≠ Ieal time

     ! simulation for 4 sec of video transmission might  take 1 hourH

    0vents are sorted #) simulation time (not #) t)peH&%priorit) 6ueue or heap data structure  !fter all su#routines for an event have #een e'ecuted* control is

    transferred to the simulation en$ine The simulation en$ine schedules the ne't event availa#le at the same

    time (if an)& .nce all the events for current time have #een e'ecuted* simulation time

    is advanced and nearest future event is e'ecuted8 Simulation time D time of currentl) e'ecutin$ event

  • 8/9/2019 39. Rc1 Simulazione-ns3

    12/80

    Simulation of computer networks 12

    Simulation$ e%ample

    packets arrive (av$8 interrarrival time% 1E λ& to router (av$8e'ecution time 1Eµ& with two out$oin$ links arrivin$ packet Koins link i with pro#a#ilit) φi

    µ1

    µ2

    state of s)stem% size of each 6ueue

    s)stem events%  packet arrivals

     service time completions

    λ

  • 8/9/2019 39. Rc1 Simulazione-ns3

    13/80

    Simulation of computer networks 13

    Simulation$ e%ample

    µ1

    µ2

    λSimulator actions on arrival  event choose a link

    if link idle Lplace pkt in service* determine service time(random num#er drawn from service time distri#ution& add

    future event onto event list for pkt transfer completion* setnum#er of pkts in 6ueue to 1M

     if #uffer full Lincrement dropped packets* i$nore arrivalM  else increment num#er in 6ueue where 6ueued

    create event for ne't arrival ($enerate interarrivaltime& stick event on event list

  • 8/9/2019 39. Rc1 Simulazione-ns3

    14/80

    Simulation of computer networks 1,

    Simulation$ e%ample

    µ1

    µ2

    λSimulator actions on departure event

    remove event* update simulation time* updateperformance statistics

    decrement counter of num#er of pkts in 6ueue f (num#er of Ko#s in 6ueue O F& put ne't pkt into

    service – schedule completion event ($enerateservice time for put&

  • 8/9/2019 39. Rc1 Simulazione-ns3

    15/80

      Simulation of computer networks 14

    &s'( tutorial$ assumptions

    • Some familiarit) with PP pro$rammin$lan$ua$e

    • Some familiarit) with ni' Network+ro$rammin$ (e8$8* sockets&

    • Some familiarit) with discrete-eventsimulators

  • 8/9/2019 39. Rc1 Simulazione-ns3

    16/80

  • 8/9/2019 39. Rc1 Simulazione-ns3

    17/80

      Simulation of computer networks 17

    Resources

    >e# site%http%EEwww8nsnam8or$

    /ailin$ list%

    http%EEmailman8isi8eduEmailmanElistinfoEns-developers

    Tutorial%

    http%EEwww8nsnam8or$EdocsEtutorialEtutorial8html

    ode server%

    http%EEcode8nsnam8or$

    >iki%

    http%EEwww8nsnam8or$EwikiEinde'8phpE/ainQ+a$e

    http://www.nsnam.org/http://mailman.isi.edu/mailman/listinfo/ns-developershttp://www.nsnam.org/docs/tutorial/tutorial.htmlhttp://code.nsnam.org/http://www.nsnam.org/wiki/index.php/Main_Pagehttp://www.nsnam.org/wiki/index.php/Main_Pagehttp://www.nsnam.org/wiki/index.php/Main_Pagehttp://code.nsnam.org/http://code.nsnam.org/http://www.nsnam.org/docs/tutorial/tutorial.htmlhttp://www.nsnam.org/docs/tutorial/tutorial.htmlhttp://mailman.isi.edu/mailman/listinfo/ns-developershttp://www.nsnam.org/http://www.nsnam.org/

  • 8/9/2019 39. Rc1 Simulazione-ns3

    18/80

      Simulation of computer networks 1=

    Resources )*+

    • /ost of the ns-3 !+ is documented with:o')$en

    http%EEwww8nsnam8or$Edo')$enEinde'8html

  • 8/9/2019 39. Rc1 Simulazione-ns3

    19/80

      Simulation of computer networks 1C

    Outline of the tutorial

    • ntroduction to ns-3

    •  !rchitecture of ns-3

    • Ns-3 lo$$in$ and tracin$• Ns-3 e'amples

  • 8/9/2019 39. Rc1 Simulazione-ns3

    20/80

      Simulation of computer networks 2F

    Introduction to ns'(

    • ns-3 is written in PP

    • Bindin$s in +)thon

    • ns-3 uses the waf #uild s)stem• simulation pro$rams are either PP

    e'ecuta#les or p)thon scripts

  • 8/9/2019 39. Rc1 Simulazione-ns3

    21/80

      Simulation of computer networks 21

    the waf #uild system

    • >af is a +)thon-#ased framework forconfi$urin$* compilin$ and installin$ applications8

     – t is a replacement for other tools such as !utotools* Scons* /ake or !nt

     – http%EEcode8$oo$le8comEpEwafE

    • To download the simulator 

     – h$ clone http%EEcode8nsnam8or$Ens-3-allinone

    •Steps to #uild the simulator  – cd ns-3-dev

     – 8Ewaf R-d optimizedde#u$ confi$ure R--ena#le-modulesDnetanim

     – make -O 8Ewaf 

     – make test -O 8Ewaf check (run unit tests&

    http://code.google.com/p/waf/http://code.google.com/p/waf/

  • 8/9/2019 39. Rc1 Simulazione-ns3

    22/80

      Simulation of computer networks 22

    waf key concepts

    • an run pro$rams throu$h a special wafshellU e8$8 – ./waf --run simple-point-to-point

     – (this $ets the li#rar) paths ri$ht for )ou&

  • 8/9/2019 39. Rc1 Simulazione-ns3

    23/80

      Simulation of computer networks 23

    Outline of the tutorial

    • ntroduction to ns-3

    •  !rchitecture of ns-3

    • Ns-3 lo$$in$ and tracin$• Ns-3 e'amples

  • 8/9/2019 39. Rc1 Simulazione-ns3

    24/80

      Simulation of computer networks 2,

     !pplication

    ,rchitecture$ the #asic model

     !pplication

    +rotocolstack

    Node

    Net:eviceNet:evice

     !pplication !pplication

    +rotocolstack

    Node

    Net:eviceNet:evice

    Sockets-like !+

    hannel

    hannel

    +acket(s&

  • 8/9/2019 39. Rc1 Simulazione-ns3

    25/80

      Simulation of computer networks 24

    -undamentals

    Je) o#Kects in the simulator are Nodes*+ackets* and hannels

    Nodes ma) contain !pplications* Astacks*and Net:evices

  • 8/9/2019 39. Rc1 Simulazione-ns3

    26/80

      Simulation of computer networks 25

    &ode #asics

     ! Node is a husk of a computer to whichapplications* stacks* and Ns are added

     !pplication !pplication !pplication

    Astacks

  • 8/9/2019 39. Rc1 Simulazione-ns3

    27/80

      Simulation of computer networks 27

    &et!evices and Channels

    Net:evices are stron$l) #ound to hannelsof a matchin$ t)pe

    Nodes are architected for multiple interfaces

    Wifi&et!evice

    WifiChannel

  • 8/9/2019 39. Rc1 Simulazione-ns3

    28/80

      Simulation of computer networks 2=

    &ode #asics

    Two ke) a#stractions are maintained%1& applications use an (as)nchrounous for

    the moment& sockets !+

     – Based on the BS: Socket !+2& the #oundar) #etween + and la)er 2

    mimics the #oundar) at the device-

    independent su#la)er in "inu'i8e8* "inu' +acket Sockets

  • 8/9/2019 39. Rc1 Simulazione-ns3

    29/80

      Simulation of computer networks 2C

    &s'( packets

    • each network packet contains a #)te #uffer*a list of ta$s* and metadata – #uffer$  #it-#)-#it (serialized& representation of

    headers and trailers

     – tas$  set of ar#itrar)* user-provided datastructures (e8$8* per-packet cross-la)ermessa$es* or flow identifiers&

     – metadata$  descri#es t)pes of headers andand trailers that have #een serialized

    • optional-- disa#led #) default

  • 8/9/2019 39. Rc1 Simulazione-ns3

    30/80

      Simulation of computer networks 3F

    &s'( packets )*+

    • 0ach t)pe of header is represented #) asu#class of ns3%%Geader 

    • to add a new header* su#class fromGeader* and write )our Serialize(& and:eserialize(& methods – how #its $et written toEfrom the Buffer 

    • Similar for +acket Ta$s

  • 8/9/2019 39. Rc1 Simulazione-ns3

    31/80

      Simulation of computer networks 31

    Simulation #asics

    • Simulation time moves discretel) fromevent to event

    •  ! simulation scheduler orders the event

    e'ecution• Simulation%%Iun(& $ets it all started

    • Simulation stops at specific time or when

    events end (Simulation%%Stop(&&

  • 8/9/2019 39. Rc1 Simulazione-ns3

    32/80

      Simulation of computer networks 32

    &s'( o#.ect metadata system

    • ns-3 is* at heart* a PP o#Kect s)stem

    • ns-3 o#Kects that inherit from #ase classns3%%.#Kect $et several additional features

     – d)namic run-time o#Kect a$$re$ation

     – an attri#ute s)stem

     – smart-pointer memor) mana$ement

  • 8/9/2019 39. Rc1 Simulazione-ns3

    33/80

      Simulation of computer networks 33

    O#.ect areation

    • Vou can a$$re$ate o#Kects to one anotherat run-time

     – !voids the need to modif) a #ase class to

    provide pointers to all possi#le connectedo#Kects

    • .#Kect a$$re$ation is planned to #e the

    main wa) to create new Node t)pes(rather than su#classin$ Node&

  • 8/9/2019 39. Rc1 Simulazione-ns3

    34/80

      Simulation of computer networks 3,

    O#.ect areation e%ample

    • Gow a$$re$ation works

    • Gow to access on a$$re$ated o#Kect

  • 8/9/2019 39. Rc1 Simulazione-ns3

    35/80

      Simulation of computer networks 34

    ,ttri#utes

    •  !n !ttri#ute represents a value in ours)stem

    •  !n !ttri#ute can #e connected to anunderl)in$ varia#le or function

     – e8$8 TcpSocket%%mQcwndU

     – or a trace source

  • 8/9/2019 39. Rc1 Simulazione-ns3

    36/80

      Simulation of computer networks 35

    ,ttri#utes )*+

    • >hat would users like to do@ – Set a default initial value for a varia#le

     – Set or $et the current value of a varia#le

     – Jnow what are all the attri#utes that affect thesimulation at run time

     – nitialize the value of a varia#le when a

    constructor is called• The attri#ute s)stem is a unified wa) of

    handlin$ these functions

  • 8/9/2019 39. Rc1 Simulazione-ns3

    37/80

      Simulation of computer networks 37

    /ow to handle attri#utes?

    • The traditional PP wa)%

     – e'port attri#utes as part of a classWs pu#lic !+

     – walk pointer chains (and iterators* when

    needed& to find what )ou need

     – use static varia#les for defaults

    • The attri#ute s)stem provides a more

    convenient !+ to the user to do thesethin$s

  • 8/9/2019 39. Rc1 Simulazione-ns3

    38/80

      Simulation of computer networks 3=

    The traditional C00 way

    class Foo {

    public:  void SetVar1 (uint32t value!"

      uint32t #etVar1 (void!"

      static void Set$nitialVar1(uint32t value!"

      void SetVar2 (uint32t value!"

      uint32t #etVar2 (void!"

      static void Set$nitialVar2(uint32t value!"

      ...

    private:  uint32t mvar1" // document var1

      uint32t mvar2" // document var2

      static uint32t minitialvar1"

      static uint32t minitialvar2"

    %

    Foo::Foo(! : mvar1(Foo::minitialvar1!& mvar2(Foo::minitialvar2!{

    %

    To modif) an instance of Xoo* $et the pointer somehow* and use the pu#lic accessor functions

    To modif) the default values* modif) the statics

    :efault values ma) #e availa#le in a separate framework (e8$8 ns-2 Bind(&&

  • 8/9/2019 39. Rc1 Simulazione-ns3

    39/80

      Simulation of computer networks 3C

    &aviatin the attri#utes

    •  !ttri#utes are e'ported into a strin$-#asednamespace* with files)stem-like paths

     – namespace supports re$ular e'pressions

    • 0'amples% – Nodes with identifiers 1* 3* ,* 4* =* C* 1F* 11%

    AENode"istER3-4R=-11

     – dp",+rotocol o#Kect instance a$$re$ated to matchin$ nodes%

    AENode"istER3-4R=-11EYdp",+rotocol – dp",+rotocol o#Kect instances of all nodes%

    AENode"istEZEYdp",+rotocol

     – 0nd+oints which match the Src+ortD1F24 specification%

    AE0nd+ointsEZ%Src+ortD1F24

  • 8/9/2019 39. Rc1 Simulazione-ns3

    40/80

      Simulation of computer networks ,F

    Creatin references in the namespace

    • Names%%!dd ([server[* serverNode&U• Names%%!dd ([serverEethF[* server:evice&U

    • 888

    • onfi$%%Set([ENamesEserverEethFET'\ueueE/a'+ackets[* inte$er

  • 8/9/2019 39. Rc1 Simulazione-ns3

    41/80

      Simulation of computer networks ,1

    ,ttri#utes$ details

    •  !ttri#utes also can #e referred to withoutthe paths – e8$8 'ans)ifi*+,::#ain

    •  ! onfi$ class allows users to manipulatethe attri#utes – e8$8% Set a default initial value for a varia#le

     – (Note% this replaces :efault

  • 8/9/2019 39. Rc1 Simulazione-ns3

    42/80

      Simulation of computer networks ,2

    ,ttri#utes$ details

    • Set or $et the current value of a varia#le• Gere* one needs the path in the namespace to the

    ri$ht instance of the o#Kect0onfi::Set4ttribute('/5ode6ist/7/evice6ist/

    3/ans)ifi*+,/#ain& ouble(1.!!"ouble d 80onfi::#et4ttribute('/5ode6ist/7/5etevice/3/ans)ifi*+,/#ain!"

    • sers can $et +trs to instances also* and+trs to trace sources* in the same wa)

  • 8/9/2019 39. Rc1 Simulazione-ns3

    43/80

      Simulation of computer networks ,3

    /ow is all this implemented )overview+

    class Foo: public 9bect

    {public:

      static ,pe$d #et,pe$d (void!"

    private:

      uint32t mvar1" // document var1

      uint32t mvar2" // document var2

    %

    Foo::Foo(! {%

    ,pe$d Foo::#et,pe$d (void!

    {

      static ,pe$d tid 8 ,pe$d('Foo!

      .4dd0onstructor;Foo< (!"

      .4dd4ttribute ('mvar1& 'document var1&

      =$nteer(3!&  >a?e=$nteer4ccessor (@Foo::mvar1!&

      >a?e=$nteer0+ec?er;uint32t< (!!

      return tid"

    %

  • 8/9/2019 39. Rc1 Simulazione-ns3

    44/80

      Simulation of computer networks ,,

    , real TypeId e%ample

    ,pe$d

    Aandom)al?2d>obilit,>odel::#et,pe$d (void!{

      static ,pe$d tid 8 ,pe$d (BAandom)al?>obilit,>odelB!

      .Set*arent;>obilit,>odel< (!

      .Set#roup5ame (B>obilit,B!

      .4dd0onstructor;Aandom)al?2d>obilit,>odel< (!

      .4dd4ttribute (BboundsB&

      BCounds of t+e area to cruise.B&

      Aectanle (.& .& 1.& 1.!&  >a?eAectanle4ccessor (@Aandom)al?2d>obilit,>odel::mbounds!&

      >a?eAectanle0+ec?er (!!

      .4dd4ttribute (BtimeB&

      B0+ane current direction and speed after movin for t+is dela,.B&

      Seconds (1.!&

      >a?eime4ccessor (@Aandom)al?2d>obilit,>odel::mmodeime!&

      >a?eime0+ec?er (!!

      .4dd4ttribute (BdistanceB&  B0+ane current direction and speed after movin for t+is distance.B&

      Seconds (1.!&

      >a?eime4ccessor (@Aandom)al?2d>obilit,>odel::mmodeime!&

      >a?eime0+ec?er (!!

  • 8/9/2019 39. Rc1 Simulazione-ns3

    45/80

      Simulation of computer networks ,4

    O#.ect system$ smart pointers

    • ns-3 uses reference-countin$ smartpointers at its !+s to limit memor) leaks

     – .r Apass #) value or Apass #) reference toconst where appropriate

    •  ! Asmart pointer #ehaves like a normalpointer (s)nta'& #ut does not lose memor)when reference count $oes to zero

    • se them like #uilt-in pointers%  *tr;>,0lass< p 8 0reate9bect;>,0lass< (!"

      p-

  • 8/9/2019 39. Rc1 Simulazione-ns3

    46/80

      Simulation of computer networks ,5

    CreateO#.ect12 )+3

    • reate.#Kect]O is a wrapper for operator new8

    • >h) not Kust* e8$8* Node Z node D new Node(&@ – Vou have to mana$e the memor) allocation and

    deallocation• ns3%%.#Kect are created on the heap usin$

    reate.#Kect]O (&* which returns a smartpointerU e8$8

    *tr;5ode< r5ode 8 0reate9bect;5ode< (!"

  • 8/9/2019 39. Rc1 Simulazione-ns3

    47/80

      Simulation of computer networks ,7

    Create12 )+3

    • >hat is reate]O (&@

    • reate]O provides some smart pointerhelp for o#Kects that use ns3%%+tr]O #utthat do not inherit from .#Kect8

    • +rincipall)* class ns3%%+acket*tr;*ac?et< p 8 0reate;*ac?et<

    (data&siDe!"

  • 8/9/2019 39. Rc1 Simulazione-ns3

    48/80

      Simulation of computer networks ,=

    &on'default constructors

    • The attri#ute s)stem allows )ou to alsopass them throu$h the reate.#Kect]Oconstructor8

    • This provides a generic  non-defaultconstructor for users (an) com#ination ofparameters&* e8$8%

    *tr;ans)ifi*+,< p+, 8 0reate9bect;ans)ifi*+,<('#ain& ouble (1.!!"

  • 8/9/2019 39. Rc1 Simulazione-ns3

    49/80

      Simulation of computer networks ,C

    /ow to parse command line aruments

    • To confiure the from the command line ns'(provides the Command  facility

    • int main (int ar$c* char Zar$vR&

     L

      888

    ommand"ine cmdU  cmd8+arse (ar$c* ar$v&U

      888

    M

    • The snippet of code a#ove ena#les the settin of all

    the attri#utes in the ns'( attri#utes namespace

    • 8Ewaf --run [scratchEfirst --ns3%%+ointTo+ointNet:evice%%:ataIateD4/#ps[

  • 8/9/2019 39. Rc1 Simulazione-ns3

    50/80

      Simulation of computer networks 4F

    /ow to parse command line aruments )*+

    • ustom $lo#al properties can #e set fromthe command line as well – int main(int ar$c* char Z ar$vR&L

    888

    uint32Qt n+ackets D 1U

    ommand"ine cmdUcmd8!dd

  • 8/9/2019 39. Rc1 Simulazione-ns3

    51/80

      Simulation of computer networks 41

    /elpers o#.ects

    • +rovide simple Ws)ntactical su$arW to makesimulation scripts look nicer and easier to read fornetwork researchers

    • Gelpers make it easier to repeat the sameoperations on a set of resources (e8$8 nodes*interfaces&

    • The settin$s are applied to the helper and used to

    perform the operations on the resources• 0ach function applies a sin$le operation on a WWset

    of same o#Kects

  • 8/9/2019 39. Rc1 Simulazione-ns3

    52/80

      Simulation of computer networks 42

    /elper O#.ects )*+

    • nternetStackGelper • /o#ilit)Gelper 

    • .lsrGelper 

    • 888 0ach model provides a helper class• >hat does this appl) to@

     – Nodeontainer% vector of +tr]NodeO

     – Net:eviceontainer% vector of +tr]Net:eviceO

    T t i l tli

  • 8/9/2019 39. Rc1 Simulazione-ns3

    53/80

      Simulation of computer networks 43

    Tutorial outline

    • ntroduction to ns-3•  !rchitecture of ns-3

    • Ns-3 lo$$in$ and tracin$

    • Ns-3 e'amples

  • 8/9/2019 39. Rc1 Simulazione-ns3

    54/80

      Simulation of computer networks 4,

    &s'( loin

    • ns-3 has a #uilt-in lo$$in$ facilit) to stderr 

    • Xeatures% – /ultiple lo$ levels like s)slo$

     – can #e driven from shell environmentvaria#les

     – Xunction and call ar$ument tracin$

    • ntended for de#u$$in$* #ut can #e

    a#used to provide tracin$ – t is not $uaranteed that format is unchan$in$

  • 8/9/2019 39. Rc1 Simulazione-ns3

    55/80

      Simulation of computer networks 44

    &s'( loin e%ample

    • 4oin facilities

     – NSQ".Q0II.I -- "o$ error messa$esU – NSQ".Q>!IN -- "o$ warnin$ messa$esU

     – NSQ".Q:0B -- "o$ relativel) rare* ad-hoc de#u$$in$ messa$esU

     – NSQ".QNX. -- "o$ informational messa$es a#out pro$ram pro$ressU

     – NSQ".QXNT.N -- "o$ a messa$e descri#in$ each function calledU

     – NSQ".Q". -- "o$ messa$es descri#in$ lo$ical flow within a functionU

     – NSQ".Q!"" -- "o$ ever)thin$8 – NSQ".QN.N:(& – "o$ unconditionall) (irrespective to the de#u$ settin$s&U

    • /ow to activate loin messaes$

     – Xrom the shell

    • e'port NSQ".D>ifiNet:evice%Vans>ifihannel (ni'&

    • e'port NSQ".DZ (ni'&

    • e'port NSQ".Ddp0cholient!pplicationDlevelQall

     – n the code

    • "o$omponent0na#le([lass[* ".NQ"0

  • 8/9/2019 39. Rc1 Simulazione-ns3

    56/80

      Simulation of computer networks 45

    Tracin model

    • Tracin$ is a structured form of simulation output

     – tracin$ format should #e relativel) static across simulatorreleases

    • 0'ample (from ns-2&%

    E 1.G3H7 2 cbr 21 ------- . 3.1 227 I1

    - 1.G3H7 2 cbr 21 ------- . 3.1 227 I1

    r 1.GGH1 2 1 cbr 21 ------- 1 3. 1. 1J7 I

    r 1.G7II 2 ac? G ------- 2 3.2 .1 2 I2

    E 1.G7II 2 tcp 1 ------- 2 .1 3.2 12 I11

    • Needs var) widel)

  • 8/9/2019 39. Rc1 Simulazione-ns3

    57/80

      Simulation of computer networks 47

    Crude tracin

    Kinclude ;iostream<

    ...

    int main (!

    {  ...

      std::cout ;; B+e value of is B ;; ;;

    std::endl"

      ...

    %

  • 8/9/2019 39. Rc1 Simulazione-ns3

    58/80

      Simulation of computer networks 4=

    Slihtly less crude

    Kinclude ;iostream<

    ...

    int main (!

    {  ...

      5S69#=5095 (B+e value of is B ;; !"

      ...

    %

  • 8/9/2019 39. Rc1 Simulazione-ns3

    59/80

      Simulation of computer networks 4C

    Simple ns'( tracin

    • these are wrapper functionsEclasses

    • see e'amplesEmi'ed-wireless8cc Kinclude Bns3/ascii-trace.+B

      4sciirace asciitrace (Bmied-wireless.trB!"

      asciitrace.race4llLueues (!"

      asciitrace.race4ll5eteviceA (!"

  • 8/9/2019 39. Rc1 Simulazione-ns3

    60/80

      Simulation of computer networks 5F

    Simple ns'( tracin )pcap version+

    • these are wrapper functionsEclasses

    • see e'amplesEmi'ed-wireless8cc Kinclude Bns3/pcap-trace.+B

      *caprace pcaptrace (Bmied-wireless.pcapB!"

      pcaptrace.race4ll$p (!"

  • 8/9/2019 39. Rc1 Simulazione-ns3

    61/80

      Simulation of computer networks 51

    &s'( tracin model

    • Xundamental 1% decouple trace sourcesfrom trace sinks

    • Xundamental 2% prefer standard trace

    outputs for #uilt-in traces

    Trace source

    Trace source

    Trace source

    Trace sink

    unchaninconfiura#le #yuser 

  • 8/9/2019 39. Rc1 Simulazione-ns3

    62/80

      Simulation of computer networks 52

    Tracin overview

    • Simulator provides a set of pre-confi$uredtrace sources

     – sers ma) edit the core to add their own

    • sers provide trace sinks and attach to thetrace source

     – Simulator core provides a few e'amples for

    common cases• /ultiple trace sources can connect to a

    trace sink

  • 8/9/2019 39. Rc1 Simulazione-ns3

    63/80

      Simulation of computer networks 53

    5ultiple levels of tracin

    • Gi$hest-level% se #uilt-in trace sourcesand sinks and hook a trace file to them

    • /id-level% ustomize trace sourceEsink

    #ehavior usin$ the tracin$ namespace

    • "ow-level% !dd trace sources to thetracin$ namespace

     – .r e'pose trace source e'plicitl)

  • 8/9/2019 39. Rc1 Simulazione-ns3

    64/80

      Simulation of computer networks 5,

    /ih'level of tracin

    • Gi$h-level% se #uilt-in trace sources andsinks and hook a trace file to them

      // 4lso confiure some tcpdump traces" eac+ interface will be traced

      // +e output files will be named

      // simple-point-to-point.pcap-;node$d

  • 8/9/2019 39. Rc1 Simulazione-ns3

    65/80

      Simulation of computer networks 54

    /ih level of tracin )*+

    //Su Helper di interfaccia

    ...

    void EnablePcap (std::string prefix, Ptr

  • 8/9/2019 39. Rc1 Simulazione-ns3

    66/80

      Simulation of computer networks 55

    Readin pcap files

    • pcap files can #e read #) means of  – >ireshark – Tcpdump

      // Nample of tcpdump usae

      tcpdump -nn -tt -r simple-point-to-point.pcap

      readin from file m,first--.pcap& lin?-t,pe *** (***!

      2. $* 1.1.1.1.GJ173 < 1.1.1.2.J: =*& lent+ 12G

      2.71GIG $* 1.1.1.2.J < 1.1.1.1.GJ173: =*& lent+ 12G

     

  • 8/9/2019 39. Rc1 Simulazione-ns3

    67/80

      Simulation of computer networks 57

    5id'level of tracin

    • /id-level% ustomize trace sourceEsink#ehavior usin$ the tracin$ namespace

    static void &+ndracer (uint')t oldval, uint')t ne+val$

    -

      NS)0)1N# (23oving c+nd fro! 2

  • 8/9/2019 39. Rc1 Simulazione-ns3

    68/80

      Simulation of computer networks 5=

    4ow'level of tracin

    • :efine )our own trace sources• Xor specific advanced needs

    • Need to modif) the core of ns-3

     –an #e defined in custom-elements –0as) to appl) to an) e'istin$ o#Kect

    attri#ute

  • 8/9/2019 39. Rc1 Simulazione-ns3

    69/80

      Simulation of computer networks 5C

    ,n additional trace method$ statistics

    •  !void lar$e trace files

    • ollect statistics of the simulation

    • Ieuse tracin$ framework

    • .ne similar approach% ns-2-measure proKect – http%EEinfo8iet8unipi8itE^cn$Ens2measureE

     – Static AStat o#Kect that collects samples of varia#les #ased on e'plicitfunction calls inserted into the code

     – raphical front end* and framework for replicatin$ simulation runs

    • Xlow/on is currentl) availa#le

     – http%EEtelecom8inescn8ptE^$KcEflowmon-presentation8pdf 

    & ( i l

  • 8/9/2019 39. Rc1 Simulazione-ns3

    70/80

      Simulation of computer networks 7F

    &s'( tutorial

    • ntroduction to ns-3

    •  !rchitecture of ns-3

    • "o$$in$ and tracin$

    • Ns-3 e'amples

    l 6 di t

  • 8/9/2019 39. Rc1 Simulazione-ns3

    71/80

      Simulation of computer networks 71

    e%amples6 directory

    • e'amplesE contains other scripts with similar themesO lscsma-broadcast.cc simple-point-to-point.cc

    csma-multicast.cc tcp-lare-transfer-errors.cc

    csma-one-subnet.cc tcp-lare-transfer.cc

    csma-pac?et-soc?et.cc tcp-nonlistenin-server.cc

    mied-lobal-routin.cc tcp-small-transfer-oneloss.ccsimple-alternate-routin.cc tcp-small-transfer.cc

    simple-error-model.cc udp-ec+o.cc

    simple-lobal-routin.cc wafsimple-point-to-point-olsr.cc wscript

    -irst e%ample )udp'echo+

  • 8/9/2019 39. Rc1 Simulazione-ns3

    72/80

      Simulation of computer networks 72

    -irst e%ample )udp'echo+

    • >e simulate a simple network with 2nodes connected throu$h an ethernet link

    • .ne node send a (udp& packet to asecond node

    • The second node receives the packet andsend a cop) of the packet #ack

     

    udp'echo

  • 8/9/2019 39. Rc1 Simulazione-ns3

    73/80

      Simulation of computer networks 73

    udp'echo

     • Xirst step% create nodes – ode!ontainer n

     – n"!reate (#$%

    •   nstall the fundamental T+E+ entitieson the nodes – &nternet'tac)elper internet%

     – internet"&nstall (n$%

    7dp'echo )*+

  • 8/9/2019 39. Rc1 Simulazione-ns3

    74/80

      Simulation of computer networks 7,

    7dp'echo )*+

    • reate the local network (i8e8 ethernetnetwork& – !sma)elper csma%

     – csma"'et!hannel*ttribute (+ata-ate+,

    ata-ate.alue (ata-ate (000000$$$% – csma"'et!hannel*ttribute (+elay+, 1ime.alue

    (2illi'econds (3$$$%

     – csma"'etevice*ttribute (+2tu+, 4integer.alue

    (5#00$$% – etevice!ontainer d 6 csma"&nstall (n$%

    7dp'echo )(+

  • 8/9/2019 39. Rc1 Simulazione-ns3

    75/80

      Simulation of computer networks 74

    7dp echo )(+

    •  !ssi$n the addresses to the nodesWinterfaces – &pv#*ddress)elper ipv#%

     – ipv#"'et7ase (+50"5"5"0+, +3"3"3"0+$%

     – &pv#&nterface!ontainer i 6 ipv#"*ssign (d$% – server*ddress 6 *ddress(i"8et*ddress (5$$%

    udp'echo

  • 8/9/2019 39. Rc1 Simulazione-ns3

    76/80

      Simulation of computer networks 75

    udp echo

    • nstall the server application on node 1 – uint59t port 6 ;% // well

  • 8/9/2019 39. Rc1 Simulazione-ns3

    77/80

      Simulation of computer networks 77

    udp echo

    • nstall the client application on node F – uint=3t pacet'i>e 6 503#% – uint=3t max?acet!ount 6 5%

     – 1ime inter?acet&nterval 6 'econds (5"$%

     – 4dpEcho!lient)elper client (server*ddress, port$%

     – client"'et*ttribute (+2ax?acets+, 4integer.alue(max?acet!ount$$%

     – client"'et*ttribute (+&nterval+, 1ime.alue (inter?acet&nterval$$%

     – client"'et*ttribute (+?acet'i>e+, 4integer.alue (pacet'i>e$$%

     – apps 6 client"&nstall (n"8et (0$$%

     – apps"'tart ('econds (3"0$$%

     – apps"'top ('econds (50"0$$%

    udp'echo

  • 8/9/2019 39. Rc1 Simulazione-ns3

    78/80

      Simulation of computer networks 7=

    udp echo

    • 0na#le netanim lo$s – Rinclude [ns3Enetanim-module8h[ – !nimationnterface anim ([udp-echo8'ml[&U

    • 0na#le pcap lo$s

     – !sciiTraceGelper asciiU – csma80na#le!scii!ll (ascii8reateXileStream ([udp-

    echo8tr[&&U

     – csma80na#le+cap!ll ([udp-echo[* false&U

    • Start the simulation – Simulator%%Iun (&

    One more thin ns ( sed for em lation

  • 8/9/2019 39. Rc1 Simulazione-ns3

    79/80

      Simulation of computer networks 7C

    One more thin$ ns'( used for emulation

    virtualmachine ns-3

    virtualmachine realmachine

    ns-3

      Test#ed  Test#ed

    realmachine

    ns-3

    1& ns-3 interconnects virtualmachines

    2& test#eds interconnect ns-3stacks

    real machine

    Summary

  • 8/9/2019 39. Rc1 Simulazione-ns3

    80/80

    =F

    Summary

    • ns-3 is an emer$in$ simulator to replace ns-2

    • onsider ns-3 if )ou are interested in% – /odular architecture

    • 0asil) e'tenda#le

     – /ore faithful representations of real computers andthe nternet

     – nte$ration with test#eds – ! powerful low-level !+ – +)thon scriptin$