SlideShare une entreprise Scribd logo
1  sur  47
Network Simulator Tutorial



                  Advanced Computer Networks
                  (CS378)




1                         Vacha Dave, University of Texas at Austin
Network Simulation *

    Motivation:             Overview:
     Learn fundamentals of  fundamentals of discrete
      evaluating network      event simulation
      performance via        ns-2 simulation
      simulation




2                                     *Jim Kurose, University of Massa
What is simulation? *
                                       system boundary

     exogenous inputs      system under study
        to system          (has deterministic rules           “real” life
    (the environment)      governing its behavior)


                                  observer
                                        program boundary

    psuedo random inputs      computer program
                           simulates deterministic
         to system
                           rules governing behavior      “simulated” life
    (models environment)
                                    observer


3                                              *Jim Kurose, University of Massa
Why Simulation? *

       real-system not available, is complex/costly or
        dangerous (eg: space simulations, flight simulations)
       quickly evaluate design alternatives (eg: different
        system configurations)
       evaluate complex functions for which closed form
        formulas or numerical techniques not available




4                                         *Jim Kurose, University of Massa
Simulation: advantages/drawbacks*

       advantages:
        –   sometimes cheaper
        –   find bugs (in design) in advance
        –   generality: over analytic/numerical techniques
        –   detail: can simulate system details at arbitrary level
       drawbacks:
        –    caution: does model reflect reality
        –    large scale systems: lots of resources to simulate
            (especially accurately simulate)
        –    may be slow (computationally expensive – 1 min real
            time could be hours of simulated time)
        –   art: determining right level of model complexity
        –   statistical uncertainty in results
5                                                 *Jim Kurose, University of Massa
The evaluation spectrum*

     Numerical    models
     Simulation
     Emulation
     Prototype
     Operational   system




6                            *Jim Kurose, University of Massa
Programming a simulation*

    What ‘s in a simulation program?
     simulated time: internal (to simulation program) variable that
      keeps track of simulated time
     system “state”: variables maintained by simulation program
      define system “state”
        –   e.g., may track number (possibly order) of packets in queue, current
            value of retransmission timer
       events: points in time when system changes state
        –   each event has associate event time
              e.g., arrival of packet to queue, departure from queue
              precisely at these points in time that simulation must take action
                (change state and may cause new future events)
        –   model for time between events (probabilistic) caused by external
            environment

7                                                      *Jim Kurose, University of Massa
Simulator Structure*

     simulation program maintains and
      updates list of future events: event list
    Need:
     well defined set of events
     for each event: simulated system action,
      updating of event list



8                                      *Jim Kurose, University of Massa
Simulator Block Diagram*

            initialize event list

         get next (nearest future)
           event from event list

            time = event time
                 process event
       (change state values, add/delete
         future events from event list)
             update statistics
               n
                   done?
9                                         *Jim Kurose, University of Massa
NS2 Outline

      What is it?
      How do I get it?
      How do I use it?
      How do I add to it?
      Documentation
      Bug-Fixing




10                           Vacha Dave, University of Texas
What is NS2?

      Network Simulator
      A package of tools that simulates behavior of
       networks
       –   Create Network Topologies
       –   Log events that happen under any load
       –   Analyze events to understand the network
           behavior



11                                      Vacha Dave, University of Texas
Creating Topologies

             5Mbps,              300Kbps,
             10ms                100ms
       n1                                       n5
                      n3

                           500Kbps,
                           50ms

                      n4

       n2
            2Mbps,                              n6
                               300Kbps,
            20ms
                               100ms


12                                    Vacha Dave, University of Texas
Creating Topologies

      Nodes
       –   Set properties like queue length, location
       –   Protocols, routing algorithms
      Links
       –   Set types of link – Simplex, duplex, wireless,
           satellite
       –   Set bandwidth, latency etc.
      Done    through tcl Scripts

13                                         Vacha Dave, University of Texas
Observing Network Behavior

        Observe    behavior by tracing “events”         Src Dst IP
                                                        Address, Port
         –   Eg. packet received, packet drop etc.




time




14                                          Vacha Dave, University of Texas
Observing Network Behavior

      NAM:
       –   Network Animator
       –   A visual aid showing how packets flow along the
           network
      We’ll   see a demo..




15                                       Vacha Dave, University of Texas
Outline

      What is it?
      How do I get it?
      How do I use it?
      How do I add to it?
      Documentation
      Bug-Fixing




16                           Vacha Dave, University of Texas
How Do I get NS2?

      NS   already Installed for us at:
       –   /u/yzhang/ns-allinone-2.27-oolsr-0.99.15/ns-2.27
      NAM    already installed at :
       –   /u/yzhang/ns-allinone-2.27-oolsr-0.99.15/nam-
           1.10
       –   Add this to the PATH variable of your shell
             For   tcsh, add the following lines to your ~/.cshrc file

       setenv PATH “/u/yzhang/ns-allinone-2.27-ooslr-0.99.15/ns-2.27:$PATH”
       setenv PATH “/u/yzhang/ns-allinone-2.27-ooslr-0.99.15/nam1.10:$PATH”
17                                                  Vacha Dave, University of Texas
Outline

      What is it?
      How do I get it?
      How do I use it?
      How do I add to it?
      Documentation
      Bug-Fixing




18                           Vacha Dave, University of Texas
How Do I use it?

      Creating a Simple Topology
      Getting Traces
      Using NAM




19                                  Vacha Dave, University of Texas
Basics of using NS2

      Define  Network topology, load, output files in
       Tcl Script
      To run,
        $ ns simple_network.tcl
      Internally,NS2 instantiates C++ classes
       based on the tcl scripts
      Output is in form of trace files



20                                   Vacha Dave, University of Texas
A simple Example – Creating the
     topology


                Bandwidth:1Mbps
                Latency: 10ms
          n1                         n2




21                                Vacha Dave, University of Texas
Creating the topology
     #create a new simulator object
     set ns [new Simulator]

     #open the nam trace file
     set nf [open out.nam w]
     $ns namtrace-all $nf

     #define a 'finish' procedure
     proc finish {} {
         global ns nf
         $ns flush-trace

         #close the trace file
         close $nf

         #execute nam on the trace file
         exec nam out.nam &

         exit 0
22   }                                    Vacha Dave, University of Texas
Creating the topology (Contd)
     #create two nodes
     set n0 [$ns node]
     set n1 [$ns node]

     #create a duplex link between the nodes
     $ns duplex-link $n0 $n1 1Mb 10ms DropTail




23                                       Vacha Dave, University of Texas
Demo




Vacha Dave, University of Texas at Austin   24
Adding traffic
                                1Mbps,10ms
                   n1                                                 n2


         udp
                                                                             null

      cbr
                                                                                    node
                                                                                    agent
Packet Size: 500 bytes
rate: 800Kbps                                                                       source
                                                                                    link

                             cbr traffic

                  0.5                                     4.5              time
            0.0                                                 5.0
                         Vacha Dave, University of Texas at Austin                         25
Putting it together..
#create a udp agent and attach it to node n0
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0

#Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0

#create a Null agent(a traffic sink) and attach it to node n1
set null0 [new Agent/Null]
$ns attach-agent $n1 $null0

#Connect the traffic source to the sink
$ns connect $udp0 $null0

#Schedule events for CBR traffic
$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"

#call the finish procedure after 5 secs of simulated time
$ns at 5.0 "finish"

#run the simulation
                             Vacha Dave, University of Texas at Austin   26
$ns run
Demo




Vacha Dave, University of Texas at Austin   27
A second Scenario * (from NS by
     Example)




                             Taken from NS by
                             Example by Jae Chung
                             and
                             Mark Claypool



28                           Vacha Dave, University of Texas
A second Example (From NS by
     Example)

     #Create a simulator object
     set ns [new Simulator]

     #Define different colors for data flows (for NAM)
     $ns color 1 Blue
     $ns color 2 Red

     #Open the NAM trace file
     set nf [open out.nam w]
     $ns namtrace-all $nf

     #Define a 'finish' procedure
     proc finish {} {
             global ns nf
             $ns flush-trace
             #Close the NAM trace file
             close $nf
             #Execute NAM on the trace file
             exec nam out.nam &
29           exit 0                                 Vacha Dave, University of Texas
     }
A Second Scenario (Contd.)
     #Create four nodes
     set n0 [$ns node]
     set n1 [$ns node]
     set n2 [$ns node]
     set n3 [$ns node]

     #Create links between the nodes
     $ns duplex-link $n0 $n2 2Mb 10ms DropTail
     $ns duplex-link $n1 $n2 2Mb 10ms DropTail
     $ns duplex-link $n2 $n3 1.7Mb 20ms DropTail

     #Set Queue Size of link (n2-n3) to 10
     $ns queue-limit $n2 $n3 10


30                                       Vacha Dave, University of Texas
A Second Scenario (Contd.)

     #Give node position (for NAM)
     $ns duplex-link-op $n0 $n2 orient right-down
     $ns duplex-link-op $n1 $n2 orient right-up
     $ns duplex-link-op $n2 $n3 orient right

     #Monitor the queue for link (n2-n3). (for NAM)
     $ns duplex-link-op $n2 $n3 queuePos 0.5




31                                       Vacha Dave, University of Texas
A Second Scenario (Contd.)

     #Setup a TCP connection   To create agents or traffic sources, we need
     set tcp [new Agent/TCP]   to know the class names these objects
     $tcp set class_ 2         (Agent/TCP, Agent/TCPSink, Application/FTP
     $ns attach-agent $n0 $tcp and so on).
     set sink [new Agent/TCPSink] information can be found in the NS
                               This
                               documentation.
     $ns attach-agent $n3 $sink one shortcut is to look at the "ns-
                               But
     $ns connect $tcp $sink    2/tcl/libs/ns-default.tcl" file.
     $tcp set fid_ 1

     #Setup a FTP over TCP connection
     set ftp [new Application/FTP]
     $ftp attach-agent $tcp
     $ftp set type_ FTP

32                                                Vacha Dave, University of Texas
A Second Scenario (Contd.)

     #Setup a UDP connection
     set udp [new Agent/UDP]
     $ns attach-agent $n1 $udp
     set null [new Agent/Null]
     $ns attach-agent $n3 $null
     $ns connect $udp $null
     $udp set fid_ 2

     #Setup a CBR over UDP connection
     set cbr [new Application/Traffic/CBR]
     $cbr attach-agent $udp
     $cbr set type_ CBR
     $cbr set packet_size_ 1000
     $cbr set rate_ 1mb
     $cbr set random_ false
33                                        Vacha Dave, University of Texas
A Second Scenario (Contd.)
     #Schedule events   for the CBR and FTP agents
     $ns at 0.1 "$cbr   start"
     $ns at 1.0 "$ftp   start"
     $ns at 4.0 "$ftp   stop"
     $ns at 4.5 "$cbr   stop"

     #Detach tcp and sink agents (not really necessary)
     $ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"

     #Call the finish procedure after 5 seconds of simulation time
     $ns at 5.0 "finish"

     #Print CBR packet size and interval
     puts "CBR packet size = [$cbr set packet_size_]"
     puts "CBR interval = [$cbr set interval_]"

     #Run the simulation
     $ns run

34                                                   Vacha Dave, University of Texas
Demo




Vacha Dave, University of Texas at Austin   35
Outline

      What is it?
      How do I get it?
      How do I use it?
      How do I add to it?
      Documentation
      Bug-Fixing




36                           Vacha Dave, University of Texas
How can I add to NS2?

      Adding    Protocols to NS2 is possible
       –   Need to create the C++ class
       –   Need to create the OTcl Linkage
      More   info at:
       –   http://www.isi.edu/nsnam/ns/tutorial/index.html
       –   Tutorial about how to add a simple protocol to
           NS2


37                                        Vacha Dave, University of Texas
Outline

      What is it?
      How do I get it?
      How do I use it?
      How do I add to it?
      Documentation
      Bug-Fixing




38                           Vacha Dave, University of Texas
Documentation – NS2 Documentation

      NS2   Manual
       –   Information about Otcl interpreter, C++ class
           hierarchy, parameters for various protocols
       –   http://www.isi.edu/nsnam/ns/doc/index.html
       –   Very detailed, useful when looking for something
           specific, like:
             What are the shadowing models available for wireless?
              How do I select them?
             How do I make my routing strategy to be Distance
              Vector routing?


39                                            Vacha Dave, University of Texas
Documentation – NS2 documentation

      NS2    Tutorial by Marc Greis
       –   http://www.isi.edu/nsnam/ns/tutorial/index.html
       –   Good starting point for understanding the overall
           structure of NS2
       –   Examples:
             What is the relation between c++ classes and Otcl
             classes?
             basic info on instantiating NS2 instance, tcl scripting




40                                               Vacha Dave, University of Texas
Documentation – NS2 Documentation

      NS2     for beginners
       –   http://www-sop.inria.fr/maestro/personnel/Eitan.Altman/COURS-NS/n3.pdf
       –   More detailed than Marc Greis’ Tutorial
       –   More info on getting it up and running – rather
           than internals
       –   Examples:
             What does each line of a tcl script do?
             Most common examples of trace formats that are useful




41                                                     Vacha Dave, University of Texas
Documentation – Tcl Documentation

      Tcl   Tutorial
       –   http://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.html
      Tcl   Manual
       –   All commands and their explanation
       –   http://www.tcl.tk/man/tcl8.6/TclCmd/contents.htm




42                                           Vacha Dave, University of Texas
Outline

      What is it?
      How do I get it?
      How do I use it?
      How do I add to it?
      Documentation
      Bug-Fixing




43                           Vacha Dave, University of Texas
Bug-Fixing – When things go wrong..

      Googling   for the problem! 
       –   Extensive NS2 mailing lists
       –   Chances are that other people have had the
           same problem are very high
       –   Responsive forums




44                                      Vacha Dave, University of Texas
Bug-Fixing – When things go wrong..

      NS2    in-built examples
       –   Extensive inbuilt examples
             “diffing”   with the examples helps a lot
       –   Sometimes a good idea to start from a script that
           does something similar




45                                                 Vacha Dave, University of Texas
Bug-Fixing – When things go wrong..

      Taking      a look at the code
       –   Everyone adds to NS2 
       –   May not always confirm to the norms
             IP   TTL set to 32 instead of 256 




46                                                  Vacha Dave, University of Texas
Bug-Fixing Questions
        What is the expected behaviour of the network?
        Have I connected the network right?
        Am I logging trace information at the right level? Can
         I change it to narrow down on the problem?
        Has anyone else out there had the same problem?
        Is there something similar in examples that I can
         look at, and build upon?
        Does the code really do what the protocol says? Are
         all the default parameters correct?
        Is Tcl being picky here? 

47                                          Vacha Dave, University of Texas

Contenu connexe

Tendances

Multicastingand multicast routing protocols
Multicastingand multicast routing protocolsMulticastingand multicast routing protocols
Multicastingand multicast routing protocolsIffat Anjum
 
WSN NETWORK -MAC PROTOCOLS - Low Duty Cycle Protocols And Wakeup Concepts – ...
WSN NETWORK -MAC PROTOCOLS - Low Duty Cycle Protocols And Wakeup Concepts –  ...WSN NETWORK -MAC PROTOCOLS - Low Duty Cycle Protocols And Wakeup Concepts –  ...
WSN NETWORK -MAC PROTOCOLS - Low Duty Cycle Protocols And Wakeup Concepts – ...ArunChokkalingam
 
Classification of routing protocols
Classification of routing protocolsClassification of routing protocols
Classification of routing protocolsMenaga Selvaraj
 
Directed diffusion for wireless sensor networking
Directed diffusion for wireless sensor networkingDirected diffusion for wireless sensor networking
Directed diffusion for wireless sensor networkingHabibur Rahman
 
Energy consumption of wsn
Energy consumption of wsnEnergy consumption of wsn
Energy consumption of wsnDeepaDasarathan
 
Network layer - design Issues
Network layer - design IssuesNetwork layer - design Issues
Network layer - design Issuesقصي نسور
 
ASYNCHRONOUS TRANSFER MODE (ATM)
ASYNCHRONOUS TRANSFER MODE (ATM)ASYNCHRONOUS TRANSFER MODE (ATM)
ASYNCHRONOUS TRANSFER MODE (ATM)ZillayHuma Mehmood
 
Communication primitives
Communication primitivesCommunication primitives
Communication primitivesStudent
 
Common protocols
Common protocolsCommon protocols
Common protocolsMr SMAK
 
Multiplexing in mobile computing
Multiplexing in mobile computingMultiplexing in mobile computing
Multiplexing in mobile computingZituSahu
 
Routing protocols-network-layer
Routing protocols-network-layerRouting protocols-network-layer
Routing protocols-network-layerNitesh Singh
 
switching techniques in data communication and networking
switching techniques in data communication and networkingswitching techniques in data communication and networking
switching techniques in data communication and networkingHarshita Yadav
 
Flow & Error Control
Flow & Error ControlFlow & Error Control
Flow & Error Controltameemyousaf
 

Tendances (20)

Multicastingand multicast routing protocols
Multicastingand multicast routing protocolsMulticastingand multicast routing protocols
Multicastingand multicast routing protocols
 
WSN NETWORK -MAC PROTOCOLS - Low Duty Cycle Protocols And Wakeup Concepts – ...
WSN NETWORK -MAC PROTOCOLS - Low Duty Cycle Protocols And Wakeup Concepts –  ...WSN NETWORK -MAC PROTOCOLS - Low Duty Cycle Protocols And Wakeup Concepts –  ...
WSN NETWORK -MAC PROTOCOLS - Low Duty Cycle Protocols And Wakeup Concepts – ...
 
Classification of routing protocols
Classification of routing protocolsClassification of routing protocols
Classification of routing protocols
 
Directed diffusion for wireless sensor networking
Directed diffusion for wireless sensor networkingDirected diffusion for wireless sensor networking
Directed diffusion for wireless sensor networking
 
Energy consumption of wsn
Energy consumption of wsnEnergy consumption of wsn
Energy consumption of wsn
 
Routing Protocols in WSN
Routing Protocols in WSNRouting Protocols in WSN
Routing Protocols in WSN
 
Network layer - design Issues
Network layer - design IssuesNetwork layer - design Issues
Network layer - design Issues
 
ASYNCHRONOUS TRANSFER MODE (ATM)
ASYNCHRONOUS TRANSFER MODE (ATM)ASYNCHRONOUS TRANSFER MODE (ATM)
ASYNCHRONOUS TRANSFER MODE (ATM)
 
Communication primitives
Communication primitivesCommunication primitives
Communication primitives
 
middleware
middlewaremiddleware
middleware
 
Transport layer
Transport layer Transport layer
Transport layer
 
Routing ppt
Routing pptRouting ppt
Routing ppt
 
Common protocols
Common protocolsCommon protocols
Common protocols
 
Multiplexing in mobile computing
Multiplexing in mobile computingMultiplexing in mobile computing
Multiplexing in mobile computing
 
Routing protocols-network-layer
Routing protocols-network-layerRouting protocols-network-layer
Routing protocols-network-layer
 
Layered Architecture
Layered ArchitectureLayered Architecture
Layered Architecture
 
Ad-Hoc Networks
Ad-Hoc NetworksAd-Hoc Networks
Ad-Hoc Networks
 
switching techniques in data communication and networking
switching techniques in data communication and networkingswitching techniques in data communication and networking
switching techniques in data communication and networking
 
Congestion control in TCP
Congestion control in TCPCongestion control in TCP
Congestion control in TCP
 
Flow & Error Control
Flow & Error ControlFlow & Error Control
Flow & Error Control
 

Similaire à Ns2

NS2 Overview - Network Simulator Tutorial
NS2 Overview - Network Simulator TutorialNS2 Overview - Network Simulator Tutorial
NS2 Overview - Network Simulator TutorialNguynQuangV13
 
Network Simulator Tutorial
Network Simulator TutorialNetwork Simulator Tutorial
Network Simulator Tutorialcscarcas
 
Introduction to NS2 - Cont..
Introduction to NS2 - Cont..Introduction to NS2 - Cont..
Introduction to NS2 - Cont..cscarcas
 
Plenzogan technology
Plenzogan technologyPlenzogan technology
Plenzogan technologyplenzogan
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2AAKASH S
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2AAKASH S
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2AAKASH S
 
Final Report(Routing_Misbehavior)
Final Report(Routing_Misbehavior)Final Report(Routing_Misbehavior)
Final Report(Routing_Misbehavior)Ambreen Zafar
 
Network simulator
Network simulatorNetwork simulator
Network simulatorjausmin kj
 
Lifetime maximization of wireless sensor networks with a mobile
Lifetime maximization of wireless sensor networks with a mobileLifetime maximization of wireless sensor networks with a mobile
Lifetime maximization of wireless sensor networks with a mobileNexgen Technology
 
Simulation of Scale-Free Networks
Simulation of Scale-Free NetworksSimulation of Scale-Free Networks
Simulation of Scale-Free NetworksGabriele D'Angelo
 

Similaire à Ns2 (20)

Ns2
Ns2Ns2
Ns2
 
NS2 Overview - Network Simulator Tutorial
NS2 Overview - Network Simulator TutorialNS2 Overview - Network Simulator Tutorial
NS2 Overview - Network Simulator Tutorial
 
Network Simulator Tutorial
Network Simulator TutorialNetwork Simulator Tutorial
Network Simulator Tutorial
 
Venkat ns2
Venkat ns2Venkat ns2
Venkat ns2
 
Tut hemant ns2
Tut hemant ns2Tut hemant ns2
Tut hemant ns2
 
Introduction to ns2
Introduction to ns2Introduction to ns2
Introduction to ns2
 
Dc project 1
Dc project 1Dc project 1
Dc project 1
 
Introduction to NS2 - Cont..
Introduction to NS2 - Cont..Introduction to NS2 - Cont..
Introduction to NS2 - Cont..
 
Ns2pre
Ns2preNs2pre
Ns2pre
 
Ns2
Ns2Ns2
Ns2
 
Plenzogan technology
Plenzogan technologyPlenzogan technology
Plenzogan technology
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
 
Final Report(Routing_Misbehavior)
Final Report(Routing_Misbehavior)Final Report(Routing_Misbehavior)
Final Report(Routing_Misbehavior)
 
Ns fundamentals 1
Ns fundamentals 1Ns fundamentals 1
Ns fundamentals 1
 
Network simulator
Network simulatorNetwork simulator
Network simulator
 
Ns network simulator
Ns network simulatorNs network simulator
Ns network simulator
 
Lifetime maximization of wireless sensor networks with a mobile
Lifetime maximization of wireless sensor networks with a mobileLifetime maximization of wireless sensor networks with a mobile
Lifetime maximization of wireless sensor networks with a mobile
 
Simulation of Scale-Free Networks
Simulation of Scale-Free NetworksSimulation of Scale-Free Networks
Simulation of Scale-Free Networks
 

Ns2

  • 1. Network Simulator Tutorial Advanced Computer Networks (CS378) 1 Vacha Dave, University of Texas at Austin
  • 2. Network Simulation * Motivation: Overview:  Learn fundamentals of  fundamentals of discrete evaluating network event simulation performance via  ns-2 simulation simulation 2 *Jim Kurose, University of Massa
  • 3. What is simulation? * system boundary exogenous inputs system under study to system (has deterministic rules “real” life (the environment) governing its behavior) observer program boundary psuedo random inputs computer program simulates deterministic to system rules governing behavior “simulated” life (models environment) observer 3 *Jim Kurose, University of Massa
  • 4. Why Simulation? *  real-system not available, is complex/costly or dangerous (eg: space simulations, flight simulations)  quickly evaluate design alternatives (eg: different system configurations)  evaluate complex functions for which closed form formulas or numerical techniques not available 4 *Jim Kurose, University of Massa
  • 5. Simulation: advantages/drawbacks*  advantages: – sometimes cheaper – find bugs (in design) in advance – generality: over analytic/numerical techniques – detail: can simulate system details at arbitrary level  drawbacks: – caution: does model reflect reality – large scale systems: lots of resources to simulate (especially accurately simulate) – may be slow (computationally expensive – 1 min real time could be hours of simulated time) – art: determining right level of model complexity – statistical uncertainty in results 5 *Jim Kurose, University of Massa
  • 6. The evaluation spectrum*  Numerical models  Simulation  Emulation  Prototype  Operational system 6 *Jim Kurose, University of Massa
  • 7. Programming a simulation* What ‘s in a simulation program?  simulated time: internal (to simulation program) variable that keeps track of simulated time  system “state”: variables maintained by simulation program define system “state” – e.g., may track number (possibly order) of packets in queue, current value of retransmission timer  events: points in time when system changes state – each event has associate event time  e.g., arrival of packet to queue, departure from queue  precisely at these points in time that simulation must take action (change state and may cause new future events) – model for time between events (probabilistic) caused by external environment 7 *Jim Kurose, University of Massa
  • 8. Simulator Structure*  simulation program maintains and updates list of future events: event list Need:  well defined set of events  for each event: simulated system action, updating of event list 8 *Jim Kurose, University of Massa
  • 9. Simulator Block Diagram* initialize event list get next (nearest future) event from event list time = event time process event (change state values, add/delete future events from event list) update statistics n done? 9 *Jim Kurose, University of Massa
  • 10. NS2 Outline  What is it?  How do I get it?  How do I use it?  How do I add to it?  Documentation  Bug-Fixing 10 Vacha Dave, University of Texas
  • 11. What is NS2?  Network Simulator  A package of tools that simulates behavior of networks – Create Network Topologies – Log events that happen under any load – Analyze events to understand the network behavior 11 Vacha Dave, University of Texas
  • 12. Creating Topologies 5Mbps, 300Kbps, 10ms 100ms n1 n5 n3 500Kbps, 50ms n4 n2 2Mbps, n6 300Kbps, 20ms 100ms 12 Vacha Dave, University of Texas
  • 13. Creating Topologies  Nodes – Set properties like queue length, location – Protocols, routing algorithms  Links – Set types of link – Simplex, duplex, wireless, satellite – Set bandwidth, latency etc.  Done through tcl Scripts 13 Vacha Dave, University of Texas
  • 14. Observing Network Behavior  Observe behavior by tracing “events” Src Dst IP Address, Port – Eg. packet received, packet drop etc. time 14 Vacha Dave, University of Texas
  • 15. Observing Network Behavior  NAM: – Network Animator – A visual aid showing how packets flow along the network  We’ll see a demo.. 15 Vacha Dave, University of Texas
  • 16. Outline  What is it?  How do I get it?  How do I use it?  How do I add to it?  Documentation  Bug-Fixing 16 Vacha Dave, University of Texas
  • 17. How Do I get NS2?  NS already Installed for us at: – /u/yzhang/ns-allinone-2.27-oolsr-0.99.15/ns-2.27  NAM already installed at : – /u/yzhang/ns-allinone-2.27-oolsr-0.99.15/nam- 1.10 – Add this to the PATH variable of your shell  For tcsh, add the following lines to your ~/.cshrc file setenv PATH “/u/yzhang/ns-allinone-2.27-ooslr-0.99.15/ns-2.27:$PATH” setenv PATH “/u/yzhang/ns-allinone-2.27-ooslr-0.99.15/nam1.10:$PATH” 17 Vacha Dave, University of Texas
  • 18. Outline  What is it?  How do I get it?  How do I use it?  How do I add to it?  Documentation  Bug-Fixing 18 Vacha Dave, University of Texas
  • 19. How Do I use it?  Creating a Simple Topology  Getting Traces  Using NAM 19 Vacha Dave, University of Texas
  • 20. Basics of using NS2  Define Network topology, load, output files in Tcl Script  To run, $ ns simple_network.tcl  Internally,NS2 instantiates C++ classes based on the tcl scripts  Output is in form of trace files 20 Vacha Dave, University of Texas
  • 21. A simple Example – Creating the topology Bandwidth:1Mbps Latency: 10ms n1 n2 21 Vacha Dave, University of Texas
  • 22. Creating the topology #create a new simulator object set ns [new Simulator] #open the nam trace file set nf [open out.nam w] $ns namtrace-all $nf #define a 'finish' procedure proc finish {} { global ns nf $ns flush-trace #close the trace file close $nf #execute nam on the trace file exec nam out.nam & exit 0 22 } Vacha Dave, University of Texas
  • 23. Creating the topology (Contd) #create two nodes set n0 [$ns node] set n1 [$ns node] #create a duplex link between the nodes $ns duplex-link $n0 $n1 1Mb 10ms DropTail 23 Vacha Dave, University of Texas
  • 24. Demo Vacha Dave, University of Texas at Austin 24
  • 25. Adding traffic 1Mbps,10ms n1 n2 udp null cbr node agent Packet Size: 500 bytes rate: 800Kbps source link cbr traffic 0.5 4.5 time 0.0 5.0 Vacha Dave, University of Texas at Austin 25
  • 26. Putting it together.. #create a udp agent and attach it to node n0 set udp0 [new Agent/UDP] $ns attach-agent $n0 $udp0 #Create a CBR traffic source and attach it to udp0 set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.005 $cbr0 attach-agent $udp0 #create a Null agent(a traffic sink) and attach it to node n1 set null0 [new Agent/Null] $ns attach-agent $n1 $null0 #Connect the traffic source to the sink $ns connect $udp0 $null0 #Schedule events for CBR traffic $ns at 0.5 "$cbr0 start" $ns at 4.5 "$cbr0 stop" #call the finish procedure after 5 secs of simulated time $ns at 5.0 "finish" #run the simulation Vacha Dave, University of Texas at Austin 26 $ns run
  • 27. Demo Vacha Dave, University of Texas at Austin 27
  • 28. A second Scenario * (from NS by Example) Taken from NS by Example by Jae Chung and Mark Claypool 28 Vacha Dave, University of Texas
  • 29. A second Example (From NS by Example) #Create a simulator object set ns [new Simulator] #Define different colors for data flows (for NAM) $ns color 1 Blue $ns color 2 Red #Open the NAM trace file set nf [open out.nam w] $ns namtrace-all $nf #Define a 'finish' procedure proc finish {} { global ns nf $ns flush-trace #Close the NAM trace file close $nf #Execute NAM on the trace file exec nam out.nam & 29 exit 0 Vacha Dave, University of Texas }
  • 30. A Second Scenario (Contd.) #Create four nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] #Create links between the nodes $ns duplex-link $n0 $n2 2Mb 10ms DropTail $ns duplex-link $n1 $n2 2Mb 10ms DropTail $ns duplex-link $n2 $n3 1.7Mb 20ms DropTail #Set Queue Size of link (n2-n3) to 10 $ns queue-limit $n2 $n3 10 30 Vacha Dave, University of Texas
  • 31. A Second Scenario (Contd.) #Give node position (for NAM) $ns duplex-link-op $n0 $n2 orient right-down $ns duplex-link-op $n1 $n2 orient right-up $ns duplex-link-op $n2 $n3 orient right #Monitor the queue for link (n2-n3). (for NAM) $ns duplex-link-op $n2 $n3 queuePos 0.5 31 Vacha Dave, University of Texas
  • 32. A Second Scenario (Contd.) #Setup a TCP connection To create agents or traffic sources, we need set tcp [new Agent/TCP] to know the class names these objects $tcp set class_ 2 (Agent/TCP, Agent/TCPSink, Application/FTP $ns attach-agent $n0 $tcp and so on). set sink [new Agent/TCPSink] information can be found in the NS This documentation. $ns attach-agent $n3 $sink one shortcut is to look at the "ns- But $ns connect $tcp $sink 2/tcl/libs/ns-default.tcl" file. $tcp set fid_ 1 #Setup a FTP over TCP connection set ftp [new Application/FTP] $ftp attach-agent $tcp $ftp set type_ FTP 32 Vacha Dave, University of Texas
  • 33. A Second Scenario (Contd.) #Setup a UDP connection set udp [new Agent/UDP] $ns attach-agent $n1 $udp set null [new Agent/Null] $ns attach-agent $n3 $null $ns connect $udp $null $udp set fid_ 2 #Setup a CBR over UDP connection set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set type_ CBR $cbr set packet_size_ 1000 $cbr set rate_ 1mb $cbr set random_ false 33 Vacha Dave, University of Texas
  • 34. A Second Scenario (Contd.) #Schedule events for the CBR and FTP agents $ns at 0.1 "$cbr start" $ns at 1.0 "$ftp start" $ns at 4.0 "$ftp stop" $ns at 4.5 "$cbr stop" #Detach tcp and sink agents (not really necessary) $ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink" #Call the finish procedure after 5 seconds of simulation time $ns at 5.0 "finish" #Print CBR packet size and interval puts "CBR packet size = [$cbr set packet_size_]" puts "CBR interval = [$cbr set interval_]" #Run the simulation $ns run 34 Vacha Dave, University of Texas
  • 35. Demo Vacha Dave, University of Texas at Austin 35
  • 36. Outline  What is it?  How do I get it?  How do I use it?  How do I add to it?  Documentation  Bug-Fixing 36 Vacha Dave, University of Texas
  • 37. How can I add to NS2?  Adding Protocols to NS2 is possible – Need to create the C++ class – Need to create the OTcl Linkage  More info at: – http://www.isi.edu/nsnam/ns/tutorial/index.html – Tutorial about how to add a simple protocol to NS2 37 Vacha Dave, University of Texas
  • 38. Outline  What is it?  How do I get it?  How do I use it?  How do I add to it?  Documentation  Bug-Fixing 38 Vacha Dave, University of Texas
  • 39. Documentation – NS2 Documentation  NS2 Manual – Information about Otcl interpreter, C++ class hierarchy, parameters for various protocols – http://www.isi.edu/nsnam/ns/doc/index.html – Very detailed, useful when looking for something specific, like:  What are the shadowing models available for wireless? How do I select them?  How do I make my routing strategy to be Distance Vector routing? 39 Vacha Dave, University of Texas
  • 40. Documentation – NS2 documentation  NS2 Tutorial by Marc Greis – http://www.isi.edu/nsnam/ns/tutorial/index.html – Good starting point for understanding the overall structure of NS2 – Examples:  What is the relation between c++ classes and Otcl classes?  basic info on instantiating NS2 instance, tcl scripting 40 Vacha Dave, University of Texas
  • 41. Documentation – NS2 Documentation  NS2 for beginners – http://www-sop.inria.fr/maestro/personnel/Eitan.Altman/COURS-NS/n3.pdf – More detailed than Marc Greis’ Tutorial – More info on getting it up and running – rather than internals – Examples:  What does each line of a tcl script do?  Most common examples of trace formats that are useful 41 Vacha Dave, University of Texas
  • 42. Documentation – Tcl Documentation  Tcl Tutorial – http://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.html  Tcl Manual – All commands and their explanation – http://www.tcl.tk/man/tcl8.6/TclCmd/contents.htm 42 Vacha Dave, University of Texas
  • 43. Outline  What is it?  How do I get it?  How do I use it?  How do I add to it?  Documentation  Bug-Fixing 43 Vacha Dave, University of Texas
  • 44. Bug-Fixing – When things go wrong..  Googling for the problem!  – Extensive NS2 mailing lists – Chances are that other people have had the same problem are very high – Responsive forums 44 Vacha Dave, University of Texas
  • 45. Bug-Fixing – When things go wrong..  NS2 in-built examples – Extensive inbuilt examples  “diffing” with the examples helps a lot – Sometimes a good idea to start from a script that does something similar 45 Vacha Dave, University of Texas
  • 46. Bug-Fixing – When things go wrong..  Taking a look at the code – Everyone adds to NS2  – May not always confirm to the norms  IP TTL set to 32 instead of 256  46 Vacha Dave, University of Texas
  • 47. Bug-Fixing Questions  What is the expected behaviour of the network?  Have I connected the network right?  Am I logging trace information at the right level? Can I change it to narrow down on the problem?  Has anyone else out there had the same problem?  Is there something similar in examples that I can look at, and build upon?  Does the code really do what the protocol says? Are all the default parameters correct?  Is Tcl being picky here?  47 Vacha Dave, University of Texas

Notes de l'éditeur

  1. - The goal for us is to understand how networks work by simulating them. - we’ll be looking at the following in particulat - fundamentals of event simulation – what are events? How are they tracke? - details of a particular popular network simulator other - other examples are opnet, qualnet etc
  2. We want to study the behaviour of system under a given set of external factors - For Internet, our system is the way we have placed nodes, routers, our protocols running on them (HTTP, TCP) etc. - Our “exogenous” behaviour” can be, for exampe – how users are using the system – for example growth of online streaming video with youtube. - We want to model the system so that we can engineer better systems - Its clear that simulation becomes harder as we have large systems and varied inputs. We should be able to distiguish between the important and the non-imp. Properties, so that we can observe the relevant ones
  3. We should go ahead and observe tha actual system if possible, but we can’t do so for a variety of reasons. More importantly, Simulation can let you abstract out some of the complexity. Simulation is repeatable – When studying flash crowds, its hard to create flash crowds again and again, but its possible to simulate them as many times as needed
  4. Simulation lets you separate the design bugs from the implementation bugs (for example – a server farm - have not got enough provisioning) – estimate etc
  5. Start out with a numerical model – a scheme of mathematical equations Maintain abstractions, but try to grab general idea using simulation Emulation – you try to model the exact behaviour of an intented system Small scale deployment
  6. Read
  7. Read
  8. Basic block diagram: read
  9. We are going to now look at a particular simulator – the NS2 simulator Its open source – available at source forge
  10. Read
  11. NS2 lets us create topologies with different nodes, different types of links in betweeb them
  12. The picture shows an example trace file: - + shows that a packet entered the queue - shows that a packet left the queue - r shows the packet was received time, type of packet etc
  13. Apart from having a trace file, it comes with a Network animator tool that allows visualization of nodes (much like the diagrams that we see in text books)
  14. Read Installing NS2 is non-trivial on the cs machines because of various dependencies, so its been already done for us.
  15. Our major section is devoted to this part, which is how to use the simulator
  16. We’ll look at how to create topologies, how to get the traces and then how to use NAM to visualise our network
  17. Read
  18. So lets start by creating a topology is NS2, we’re just defining stuff, no packets are going through yet
  19. set ns [new Simulator]: generates an NS simulator object instance, and assigns it to variable ns (italics is used for variables and values in this section). What this line does is the following:   Create a scheduler (default is calendar scheduler)   The "Simulator" object has member functions that do the following:   Create compound objects such as nodes and links (described later) Connect network component objects created (ex. attach-agent) Set network component parameters (mostly for compound objects) Create connections between agents (ex. make connection between a "tcp" and "sink")  
  20. set n0 [ $ns node]: The member function node creates a node. A node in NS is compound object made of address and port classifiers (described in a later section). Users can create a node by separately creating an address and a port classifier objects and connecting them together. However, this member function of Simulator object makes the job easier. $ns duplex-link node1 node2 bandwidth delay queue-type : creates two simplex links of specified bandwidth and delay, and connects the two specified nodes. In NS, the output queue of a node is implemented as a part of a link, therefore users should specify the queue-type when creating links. In the above simulation script, DropTail queue is used. If the reader wants to use a RED queue, simply replace the word DropTail with RED.
  21. We are going to extend the example now: we are going to attach a udp agent to n1 and a sink at n2. (agents are abstractions – of “sockets” that are present in unix) We are going to use udp to send constant bit-rate traffic – what this means is – that the rate is constant and packet size is constant (we will set these parameters)
  22. $ns attach-agent node agent : The attach-agent member function attaches an agent object created to a node object. Actually, what this function does is call the attach member function of specified node, which attaches the given agent to itself. Therefore, a user can do the same thing by, for example, $n0 attach $tcp. Similarly, each agent object has a member function attach-agent that attaches a traffic source object to itself.   $ns connect agent1 agent2 : After two agents that will communicate with each other are created, the next thing is to establish a logical network connection between them. This line establishes a network connection by setting the destination address to each others' network and port address pair.
  23. $ns duplex-link-op node1 node2 ... : The next couple of lines are used for the NAM display. To see the effects of these lines, users can comment these lines out and try the simulation.
  24. et tcp [new Agent/TCP ]: This line shows how to create a TCP agent. But in general, users can create any agent or traffic sources in this way. Agents and traffic sources are in fact basic objects (not compound objects), mostly implemented in C++ and linked to OTcl. Therefore, there are no specific Simulator object member functions that create these object instances. To create agents or traffic sources, a user should know the class names these objects (Agent/TCP, Agnet/TCPSink, Application/FTP and so on). This information can be found in the NS documentation or partly in this documentation. But one shortcut is to look at the "ns-2/tcl/libs/ns-default.tcl" file. This file contains the default configurable parameter value settings for available network objects. Therefore, it works as a good indicator of what kind of network objects are available in NS and what are the configurable parameters.   $ns attach-agent node agent : The attach-agent member function attaches an agent object created to a node object. Actually, what this function does is call the attach member function of specified node, which attaches the given agent to itself. Therefore, a user can do the same thing by, for example, $n0 attach $tcp. Similarly, each agent object has a member function attach-agent that attaches a traffic source object to itself.   $ns connect agent1 agent2 : After two agents that will communicate with each other are created, the next thing is to establish a logical network connection between them. This line establishes a network connection by setting the destination address to each others' network and port address pair.