SlideShare ist ein Scribd-Unternehmen logo
1 von 55
Downloaden Sie, um offline zu lesen
Institut für Telematik | Universität zu Lübeck




                                                 Ns2 Tutorial


                                                 Ns2 Tutorial

                                                 08.02.2006
Tutorial Outline

Part I
   NS fundamentals
   Wired world
   Walk-thru an example NS script
Part II
   Visualization tools & other utilities
   Help and references
Outcome of this tutorial
   You know the concept of ns2
   You are able to set-up a network topology on your own (with nam-
   editor)
   You are able to add traffic like ftp/telnet or cbr to your simulation
   You are able to start the ns and the nam.
   You understand the ns-script code generated by nam-editor
What Is NS?

Started as REAL in 1989
Discrete event, packet level simulator
Written in C++ with Otcl front-end
Wired, wireless and emulation modes
Link layer and up for most wired
Additional lower layers for wireless
Platforms

Most UNIX and UNIX-like systems
  Linux
  FreeBSD
  SunOS/Solaris
  HP/SGI (with some tweaking)
Windows 95/98/NT/ME/2000/XP
  Best based on cygwin
  Tips on build available
  However validation tests don’t work
ns Architecture

    Object-oriented (C++ and Otcl)
    C++ for “data”
      Per packet action
      Algorithms over large data sets, per packet handling in
      C++
    OTcl for control
      Configuration, “one-time” task
      Fast to run, quick to re-configure
      Fine grained object composition
+   Compromise between composibility and speed
–   Learning and debugging
OTcl and C++: The Duality




  Pure C++                            Pure OTcl
   objects                             objects




             C++/OTcl split objects
 C++                                       OTcl

                      ns
Basic tcl

set a 43
set b 27
proc test { a b } {
   set c [expr $a + $b]
   set d [expr [expr $a - $b] * $c]
   for {set k 0} {$k < 10} {incr k} {
    if {$k < 5} {
      puts “k < 5, pow = [expr pow($d, $k)]”
    } else {
      puts “k >= 5, mod = [expr $d % $k]”
    }
  }
}


To invoke tclshell, type “tclsh”; To exit the shell type “exit”
Basic OTcl

                                       set mom [new Mom]
                                       $mom set age_ 45
Class Mom
                                       set kid [new Kid]
Mom instproc greet {} {
                                       $kid set age_ 15
   $self instvar age_
   puts “$age_ years old
   mom: How are you doing?”            $mom greet
}                                      $kid greet

Class Kid -superclass Mom
Kid instproc greet {} {
   $self instvar age_
   puts “$age_ years old
   kid: What’s up, dude?”
}

To invoke otclshell, type “otclsh”;
   To exit the shell type “exit”; to
   run this example type “ns”
   (otherwise new will not work!!!)
Hello World - Interactive Mode

sunray01>ns
% set ns [new Simulator]
_o3
% $ns at 1 “puts “Hello World!””
1
% $ns at 1.5 “exit”
2
% $ns run
Hello World!
sunray01>
Hello World - Batch Mode

simple.tcl
   set   ns [new Simulator]
   $ns   at 1 “puts “Hello World!””
   $ns   at 1.5 “exit”
   $ns   run
sunray01> ns simple.tcl
Hello World!
sunray01>
Event Driven Simulation

Scheduler – main controller of events
Scheduler clock - simulator virtual time
[$ns_ now] returns the current simulator time
Event queue - holds events in the order of their firing times
Events have a firing time and a handler function
Two types of events possible – packets and “at-events”
Discrete Event Scheduler


       Event
       Queue           time_, uid_, next_, handler_
                                      Dispatch
Head_ ->       Deque
Head_ ->                  handler_ -> handle()
                                       Reschedule
           Insert      time_, uid_, next_, handler_



  Example:
  $ns at 0.5 “$ftp start”
  $ns at 4.5 “$ftp stop”
  $ns run
Elements of Ns-2

Create the event scheduler
[Turn on tracing]
Create network
Setup routing
[Insert errors]
Create transport connection
Create traffic
Are you Confused?
Before getting into even more Details let‘s practice
a bit

Login with your account name

Open a shell; create subdirectory „ns-test“ and
move there

Type quot;nam &quot;
Example

Create the following topology


        n0                        n1

Attach a TCP Agent and a TCPSink and connect an
ftp application on top of TCP
Save the simulation as „ftpexample.ns“
Run the simulation
Start the vizualization tool
Example (cont.)
Example (cont.)
Example (cont.)
Example (cont.)
Example Output and ns script




           n0                                       n1

set ns [new Simulator]
set n0 [$ns node]                    set ftp [new Application/FTP]
set n1 [$ns node]                    $ftp attach-agent $tcp
                                     $ns at 0.2 quot;$ftp startquot;
                                     $ns at 1.2 ”exitquot;
$ns duplex-link $n0 $n1 1.5Mb        $ns run
  10ms DropTail
set tcp [$ns create-connection TCP
   $n0 TCPSink $n1 0]
Creating Event Scheduler




Create event scheduler
  set ns [new Simulator]
Schedule events
  $ns at <time> <event>
  <event>: any legitimate ns/tcl commands
Start scheduler
  $ns run
Tracing



  Trace packets on all links
     $ns trace-all [open test.out w]
<event> <time> <from> <to> <pkt>    <size> -- <fid> <src>
   <dst> <seq> <attr>
    + 1 0 2 cbr 210 ------- 0 0.0   3.1 0   0
    - 1 0 2 cbr 210 ------- 0 0.0   3.1 0   0
    r 1.00234 0 2 cbr 210 -------   0 0.0   3.1 0 0


  Trace packets on all links in nam format
     $ns namtrace-all [open test.nam w]
     $ns namtrace-all-wireless [open wtest.nam w]
Tracing

Turn on tracing on specific links
  $ns trace-queue $n0 $n1
  $ns namtrace-queue $n0 $n1
Trace-all commands must appear
immediately after creating scheduler
Tracing

Event tracing
  $ns eventtrace-all [$file]
  Add eventtrace after trace-all as trace-all file is used as
  default
  Example script: ~ns/tcl/ex/tcp-et.tcl
Creating Network Topology



Nodes
  set n0 [$ns node]
  set n1 [$ns node]
Links and queuing
  $ns duplex-link $n0 $n1 <bandwidth> <delay>
  <queue_type>
  <queue_type>: DropTail, RED, CBQ, FQ, SFQ,
  DRR
  $ns duplex-link $n0 $n1 5Mb 2ms DropTail
Inserting Errors



Creating Error Module
   set loss_module [new ErrorModel]
   $loss_module set rate_ 0.01
   $loss_module unit pkt
   $loss_module ranvar [new
   RandomVariable/Uniform]
   $loss_module drop-target [new Agent/Null]
Inserting Error Module
   $ns lossmodel $loss_module $n0 $n1
Network Dynamics

Link failures
  Hooks in routing module to reflect routing
  changes
Four models
$ns   rtmodel Trace <config_file> $n0 $n1
$ns   rtmodel Exponential {<params>} $n0 $n1
$ns   rtmodel Deterministic {<params>} $n0 $n1
$ns   rtmodel-at <time> up|down $n0 $n1

Parameter list
[<start>] <up_interval> <down_interval> [<finish>]
Setup Routing

Unicast
  $ns rtproto <type>
  <type>: Static, Session, DV, LS, Manual or hierarchical
Multicast
  $ns multicast (right after [new Simulator])
  $ns mrtproto <type>
  <type>: CtrMcast, DM, ST, BST
Creating Connection: TCP

One-way TCP sending agent [Tahoe, Reno,
NewReno, Sack, Vegas and Fack]
  set tcp [new Agent/TCP]
  set tcpsink [new Agent/TCPSink]
  $ns attach-agent $n0 $tcp
  $ns attach-agent $n1 $tcpsink
  $ns connect $tcp $tcpsink
Transport




                        n0                                                              n1

                        Port                                                            Port
                      Classifier             dst_=1.0                                 Classifier             dst_=0.0
           Addr                       Agent/TCP                            Addr                     Agent/TCPSink
         Classifier            0   agents_
                                                                         Classifier            0   agents_
                  0       dmux_                                                   1       dmux_
                                                   Link n0-n1
entry_            1                                             entry_            0
          classifier_                                                     classifier_




                                                   Link n1-n0
set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
Creating Traffic: On Top of TCP

FTP
  set ftp [new Application/FTP]
  $ftp attach-agent $tcp
Telnet
  set telnet [new Application/Telnet]
  $telnet attach-agent $tcp
Application




                        n0                                                                 n1

                        Port                     Application/FTP                           Port
                      Classifier             dst_=1.0                                    Classifier             dst_=0.0
           Addr                       Agent/TCP                               Addr                     Agent/TCPSink
         Classifier            0   agents_
                                                                            Classifier            0   agents_
                  0       dmux_                                                      1       dmux_
                                                  Link n0-n1
entry_            1                                                entry_            0
          classifier_                                                        classifier_




                                                  Link n1-n0
set ftp [new Application/FTP]
$tcp attach-agent $ftp
Plumbing: Packet Flow




                      n0                                                       n1

                    Port               Application/FTP                       Port
                  Classifier       dst_=1.0                                Classifier        dst_=0.0
           Addr                Agent/TCP                            Addr                Agent/TCPSink
         Classifier        0                                      Classifier        0
                 0                                                        1
                                           Link n0-n1
entry_           1                                       entry_           0



                                           Link n1-n0
Network Topology - Link



                   n0                                n1




                                                                 n1
head_                                                            entry_
           enqT_        queue_      deqT_    link_        ttl_


         Tracing        drophead_    drpT_

$ns duplex-link $n0 $n1 1Mb 10ms DropTail
Summary: Generic Script Structure

set ns [new Simulator]
# [Turn on tracing]
# Create topology
# Setup packet loss, link dynamics
# Create routing agents
# Create:
# - multicast groups
# - protocol agents
# - application and/or setup traffic sources
# Post-processing procs
# Start simulation
Example - TCP

Simple scenario with TCP and UDP connections




        n0                               n5
        TCP                              UDP
                                         recvr
                 n1           n2
     5Mb                           5Mb
     2ms              1.5Mb        2ms
                      10ms
       n4                                n3
       UDP
                                         TCPSink
TCP : Step 1

Scheduler & tracing
#Create scheduler
Set ns [new Simulator]

#Turn on tracing
set f [open out.tr w]
$ns trace-all $f
Set nf [open out.nam w]
$ns namtrace-all $nf
TCP : Step 2

Create topology
#create nodes
set n0 [$ns node]
set n1 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
TCP : Step 3

#create links
$ns duplex-link $n0 $n1 5Mb 2ms DropTail
$ns duplex-link $n1 $n2 1.5Mb 10ms DropTail
$ns duplex-link $n2 $n3 5Mb 2ms DropTail
$ns queue-limit $n1 $n2 25
$ns queue-limit $n2 $n1 25
  … (for UDP)
TCP : Step 4

Create TCP agents
   set tcp [new Agent/TCP]
   set sink [new Agent/TCPSink]
   $ns attach-agent $n0 $tcp
   $ns attach-agent $n3 $sink
   $ns connect $tcp $sink
… (for UDP)
TCP : Step 5

Attach traffic
    set ftp [new Application/FTP]
    $ftp attach-agent $tcp
    #start application traffic
    $ns at 1.1 “$ftp start”

  … (for UDP)
TCP : Step 6

End of simulation wrapper (as usual)
$ns at 2.0 “finish”
Proc finish {} {
  global ns f nf
  close $f
  close $nf
  puts “Running nam…”
  exec nam out.nam &
  exit 0
}
$ns run
Viz Tools

Nam (Network AniMator)
  Packet-level animation
  Well-supported by ns
  Commandline start: “nam <nam-tracefile>”

Xgraph
   Convert trace output into xgraph format
 Commandline start: “xgraph”

Gnuplot
  Convert ASCII Text e.g. trace into 2D/3D plot
 Commandline start: “gnuplot <scriptfile>”
Ns-nam Interface

Color
Node manipulation
Link manipulation
Topology layout
Protocol state
Misc
Nam Interface: Color

Color mapping
$ns color 40 red
$ns color 41 blue
$ns color 42 chocolate

Color ↔ flow id association
$tcp0 set fid_ 40   ;# red packets
$tcp1 set fid_ 41   ;# blue packets
Nam Interface: Nodes

Color
$node color red

Shape (can’t be changed after sim starts)
$node shape box ;# circle, box, hexagon

Marks (concentric “shapes”)
$ns   at   1.0   “$n0   add-mark m0   blue box”
$ns   at   2.0   “$n0   delete-mark   m0”

Label (single string)
$ns at 1.1 “$n0 label ”web cache 0””
nam Interfaces: Links




 Color
  $ns duplex-link-op $n0 $n1 color quot;greenquot;

 Label
  $ns duplex-link-op $n0 $n1 label quot;abcedquot;

 Dynamics (automatically handled)
  $ns rtmodel Deterministic {2.0 0.9 0.1} $n0 $n1

 Asymmetric links not allowed
Nam Interface: Topo Layout

“Manual” layout: specify everything
$ns   duplex-link-op   $n(0)   $n(1)   orient   right
$ns   duplex-link-op   $n(1)   $n(2)   orient   right-up
$ns   duplex-link-op   $n(2)   $n(3)   orient   down
$ns   duplex-link-op   $n(3)   $n(4)   orient   60deg


If anything missing               automatic layout
Nam Interface: Protocol State

Monitor values of agent variables
$ns add-agent-trace $srm0 srm_agent0
$ns monitor-agent-trace $srm0
$srm0 tracevar C1_
$srm0 tracevar C2_
# … …
$ns delete-agent-trace $tcp1
Nam Interface: Misc




 Annotation
   Add textual explanation to your sim

  $ns at 3.5 quot;$ns trace-annotate “packet dropquot;“


 Set animation rate
  $ns at 0.0 quot;$ns set-animation-rate 0.1msquot;
Ns Features

Areas in wired domain
   LANs
   diffserv/intserv
   Multicast
   Full TCP
   Applications like web-caching
Wireless domain
   Ad hoc routing
   Mobile IP
   Satellite networking
   Directed diffusion (sensor networks)
Emulator
   Connect simulator in a real network
   Can receive and send out live packets from/into the real world
Resources

Ns distribution download
   http://www.isi.edu/nsnam/ns/ns-build.html
Installation problems and bug-fix
   http://www.isi.edu/nsnam/ns/ns-problems.html
Ns-users mailing list
   Ns-users@isi.edu
   See http://www.isi.edu/nsnam/ns/ns-lists.html
   Archives from above URL
Resources (contd..)

Marc Greis’ tutorial
  http://www.isi.edu/nsnam/ns/tutorial
Ns-users archive
Ns-manual
  http://www.isi.edu/nsnam/ns/ns-documentation.html
Tcl (Tool Command Language)
  http://dev.scriptics.com/scripting
  Practical programming in Tcl and Tk, Brent Welch
Otcl (MIT Object Tcl)
  ~otcl/doc/tutorial.html (in distribution)
Let’s practice a bit II

     CBR1
     UDP1
                        Use the nam editor and use default values if               NULL
N1                      not otherwise specified.
                                                                              N3
            Ethernet                                              Ethernet
            10Mbps                                                10Mbps
            Delay 1ms        R1                         R2        Delay 1ms
                                       Serial Link
     CBR2                              2Mbps
                                       Delay 10ms
     UDP2   Ethernet
            10Mbps                                               Ethernet          NULL
N2          Delay 1ms                                            10Mbps
                                                                 Delay 1ms
                                                                              N4




CBR1: starts at 0s mark it blue
CBR2: start at 0.1s mark it red               Is the distribution fair?
Institut für Telematik | Universität zu Lübeck

Weitere ähnliche Inhalte

Was ist angesagt?

Network Simulator Tutorial
Network Simulator TutorialNetwork Simulator Tutorial
Network Simulator Tutorialcscarcas
 
Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34Shaikhul Islam Chowdhury
 
Protocol implementation on NS2
Protocol implementation on NS2Protocol implementation on NS2
Protocol implementation on NS2amreshrai02
 
Network Simulation
Network SimulationNetwork Simulation
Network Simulationlohch3
 
Error Control in Multimedia Communications using Wireless Sensor Networks report
Error Control in Multimedia Communications using Wireless Sensor Networks reportError Control in Multimedia Communications using Wireless Sensor Networks report
Error Control in Multimedia Communications using Wireless Sensor Networks reportMuragesh Kabbinakantimath
 
От Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей РодионовОт Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей РодионовYandex
 
От Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей РодионовОт Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей РодионовYandex
 

Was ist angesagt? (20)

Ns2
Ns2Ns2
Ns2
 
Ns2
Ns2Ns2
Ns2
 
Session 1 introduction to ns2
Session 1   introduction to ns2Session 1   introduction to ns2
Session 1 introduction to ns2
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
 
Network Simulator Tutorial
Network Simulator TutorialNetwork Simulator Tutorial
Network Simulator Tutorial
 
Ns network simulator
Ns network simulatorNs network simulator
Ns network simulator
 
Ns2
Ns2Ns2
Ns2
 
Ns2 introduction 2
Ns2 introduction 2Ns2 introduction 2
Ns2 introduction 2
 
Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34
 
Protocol implementation on NS2
Protocol implementation on NS2Protocol implementation on NS2
Protocol implementation on NS2
 
Venkat ns2
Venkat ns2Venkat ns2
Venkat ns2
 
Introduction to ns2
Introduction to ns2Introduction to ns2
Introduction to ns2
 
Network Simulation
Network SimulationNetwork Simulation
Network Simulation
 
Ns2pre
Ns2preNs2pre
Ns2pre
 
Extending ns
Extending nsExtending ns
Extending ns
 
Ns fundamentals 1
Ns fundamentals 1Ns fundamentals 1
Ns fundamentals 1
 
Ns2
Ns2Ns2
Ns2
 
Error Control in Multimedia Communications using Wireless Sensor Networks report
Error Control in Multimedia Communications using Wireless Sensor Networks reportError Control in Multimedia Communications using Wireless Sensor Networks report
Error Control in Multimedia Communications using Wireless Sensor Networks report
 
От Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей РодионовОт Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей Родионов
 
От Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей РодионовОт Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей Родионов
 

Ähnlich wie NS-2 Tutorial

NS2-tutorial.ppt
NS2-tutorial.pptNS2-tutorial.ppt
NS2-tutorial.pptWajath
 
ns2-lecture.ppt
ns2-lecture.pptns2-lecture.ppt
ns2-lecture.pptAnniModgil
 
Cs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exerciseCs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exercisePratik Joshi
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2AAKASH S
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2AAKASH S
 
study-of-network-simulator.pdf
study-of-network-simulator.pdfstudy-of-network-simulator.pdf
study-of-network-simulator.pdfJayaprasanna4
 
Ns2: OTCL - PArt II
Ns2: OTCL - PArt IINs2: OTCL - PArt II
Ns2: OTCL - PArt IIAjit Nayak
 
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdfSelvaraj Seerangan
 
CEPH中的QOS技术
CEPH中的QOS技术CEPH中的QOS技术
CEPH中的QOS技术suncbing1
 
Doing QoS Before Ceph Cluster QoS is available - David Byte, Alex Lau
Doing QoS Before Ceph Cluster QoS is available - David Byte, Alex LauDoing QoS Before Ceph Cluster QoS is available - David Byte, Alex Lau
Doing QoS Before Ceph Cluster QoS is available - David Byte, Alex LauCeph Community
 
Yapc::Asia 2008 Tokyo - Easy system administration programming with a framewo...
Yapc::Asia 2008 Tokyo - Easy system administration programming with a framewo...Yapc::Asia 2008 Tokyo - Easy system administration programming with a framewo...
Yapc::Asia 2008 Tokyo - Easy system administration programming with a framewo...Gosuke Miyashita
 
Training Slides: 153 - Working with the CLI
Training Slides: 153 - Working with the CLITraining Slides: 153 - Working with the CLI
Training Slides: 153 - Working with the CLIContinuent
 

Ähnlich wie NS-2 Tutorial (20)

Ns tutorial
Ns tutorialNs tutorial
Ns tutorial
 
NS2-tutorial.pdf
NS2-tutorial.pdfNS2-tutorial.pdf
NS2-tutorial.pdf
 
NS2-tutorial.ppt
NS2-tutorial.pptNS2-tutorial.ppt
NS2-tutorial.ppt
 
Ns2 ns3 training in mohali
Ns2 ns3 training in mohaliNs2 ns3 training in mohali
Ns2 ns3 training in mohali
 
ns2-lecture.ppt
ns2-lecture.pptns2-lecture.ppt
ns2-lecture.ppt
 
cscn1819.pdf
cscn1819.pdfcscn1819.pdf
cscn1819.pdf
 
NS2 (1).docx
NS2 (1).docxNS2 (1).docx
NS2 (1).docx
 
Cs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exerciseCs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exercise
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
 
study-of-network-simulator.pdf
study-of-network-simulator.pdfstudy-of-network-simulator.pdf
study-of-network-simulator.pdf
 
Ns2: OTCL - PArt II
Ns2: OTCL - PArt IINs2: OTCL - PArt II
Ns2: OTCL - PArt II
 
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
 
Introduction to ns2
Introduction to ns2Introduction to ns2
Introduction to ns2
 
Tcpdump
TcpdumpTcpdump
Tcpdump
 
3-sdn-lab.pdf
3-sdn-lab.pdf3-sdn-lab.pdf
3-sdn-lab.pdf
 
CEPH中的QOS技术
CEPH中的QOS技术CEPH中的QOS技术
CEPH中的QOS技术
 
Doing QoS Before Ceph Cluster QoS is available - David Byte, Alex Lau
Doing QoS Before Ceph Cluster QoS is available - David Byte, Alex LauDoing QoS Before Ceph Cluster QoS is available - David Byte, Alex Lau
Doing QoS Before Ceph Cluster QoS is available - David Byte, Alex Lau
 
Yapc::Asia 2008 Tokyo - Easy system administration programming with a framewo...
Yapc::Asia 2008 Tokyo - Easy system administration programming with a framewo...Yapc::Asia 2008 Tokyo - Easy system administration programming with a framewo...
Yapc::Asia 2008 Tokyo - Easy system administration programming with a framewo...
 
Training Slides: 153 - Working with the CLI
Training Slides: 153 - Working with the CLITraining Slides: 153 - Working with the CLI
Training Slides: 153 - Working with the CLI
 

Kürzlich hochgeladen

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Kürzlich hochgeladen (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

NS-2 Tutorial

  • 1. Institut für Telematik | Universität zu Lübeck Ns2 Tutorial Ns2 Tutorial 08.02.2006
  • 2. Tutorial Outline Part I NS fundamentals Wired world Walk-thru an example NS script Part II Visualization tools & other utilities Help and references Outcome of this tutorial You know the concept of ns2 You are able to set-up a network topology on your own (with nam- editor) You are able to add traffic like ftp/telnet or cbr to your simulation You are able to start the ns and the nam. You understand the ns-script code generated by nam-editor
  • 3. What Is NS? Started as REAL in 1989 Discrete event, packet level simulator Written in C++ with Otcl front-end Wired, wireless and emulation modes Link layer and up for most wired Additional lower layers for wireless
  • 4. Platforms Most UNIX and UNIX-like systems Linux FreeBSD SunOS/Solaris HP/SGI (with some tweaking) Windows 95/98/NT/ME/2000/XP Best based on cygwin Tips on build available However validation tests don’t work
  • 5. ns Architecture Object-oriented (C++ and Otcl) C++ for “data” Per packet action Algorithms over large data sets, per packet handling in C++ OTcl for control Configuration, “one-time” task Fast to run, quick to re-configure Fine grained object composition + Compromise between composibility and speed – Learning and debugging
  • 6. OTcl and C++: The Duality Pure C++ Pure OTcl objects objects C++/OTcl split objects C++ OTcl ns
  • 7. Basic tcl set a 43 set b 27 proc test { a b } { set c [expr $a + $b] set d [expr [expr $a - $b] * $c] for {set k 0} {$k < 10} {incr k} { if {$k < 5} { puts “k < 5, pow = [expr pow($d, $k)]” } else { puts “k >= 5, mod = [expr $d % $k]” } } } To invoke tclshell, type “tclsh”; To exit the shell type “exit”
  • 8. Basic OTcl set mom [new Mom] $mom set age_ 45 Class Mom set kid [new Kid] Mom instproc greet {} { $kid set age_ 15 $self instvar age_ puts “$age_ years old mom: How are you doing?” $mom greet } $kid greet Class Kid -superclass Mom Kid instproc greet {} { $self instvar age_ puts “$age_ years old kid: What’s up, dude?” } To invoke otclshell, type “otclsh”; To exit the shell type “exit”; to run this example type “ns” (otherwise new will not work!!!)
  • 9. Hello World - Interactive Mode sunray01>ns % set ns [new Simulator] _o3 % $ns at 1 “puts “Hello World!”” 1 % $ns at 1.5 “exit” 2 % $ns run Hello World! sunray01>
  • 10. Hello World - Batch Mode simple.tcl set ns [new Simulator] $ns at 1 “puts “Hello World!”” $ns at 1.5 “exit” $ns run sunray01> ns simple.tcl Hello World! sunray01>
  • 11. Event Driven Simulation Scheduler – main controller of events Scheduler clock - simulator virtual time [$ns_ now] returns the current simulator time Event queue - holds events in the order of their firing times Events have a firing time and a handler function Two types of events possible – packets and “at-events”
  • 12. Discrete Event Scheduler Event Queue time_, uid_, next_, handler_ Dispatch Head_ -> Deque Head_ -> handler_ -> handle() Reschedule Insert time_, uid_, next_, handler_ Example: $ns at 0.5 “$ftp start” $ns at 4.5 “$ftp stop” $ns run
  • 13. Elements of Ns-2 Create the event scheduler [Turn on tracing] Create network Setup routing [Insert errors] Create transport connection Create traffic
  • 14. Are you Confused? Before getting into even more Details let‘s practice a bit Login with your account name Open a shell; create subdirectory „ns-test“ and move there Type quot;nam &quot;
  • 15. Example Create the following topology n0 n1 Attach a TCP Agent and a TCPSink and connect an ftp application on top of TCP Save the simulation as „ftpexample.ns“ Run the simulation Start the vizualization tool
  • 20. Example Output and ns script n0 n1 set ns [new Simulator] set n0 [$ns node] set ftp [new Application/FTP] set n1 [$ns node] $ftp attach-agent $tcp $ns at 0.2 quot;$ftp startquot; $ns at 1.2 ”exitquot; $ns duplex-link $n0 $n1 1.5Mb $ns run 10ms DropTail set tcp [$ns create-connection TCP $n0 TCPSink $n1 0]
  • 21. Creating Event Scheduler Create event scheduler set ns [new Simulator] Schedule events $ns at <time> <event> <event>: any legitimate ns/tcl commands Start scheduler $ns run
  • 22. Tracing Trace packets on all links $ns trace-all [open test.out w] <event> <time> <from> <to> <pkt> <size> -- <fid> <src> <dst> <seq> <attr> + 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0 - 1 0 2 cbr 210 ------- 0 0.0 3.1 0 0 r 1.00234 0 2 cbr 210 ------- 0 0.0 3.1 0 0 Trace packets on all links in nam format $ns namtrace-all [open test.nam w] $ns namtrace-all-wireless [open wtest.nam w]
  • 23. Tracing Turn on tracing on specific links $ns trace-queue $n0 $n1 $ns namtrace-queue $n0 $n1 Trace-all commands must appear immediately after creating scheduler
  • 24. Tracing Event tracing $ns eventtrace-all [$file] Add eventtrace after trace-all as trace-all file is used as default Example script: ~ns/tcl/ex/tcp-et.tcl
  • 25. Creating Network Topology Nodes set n0 [$ns node] set n1 [$ns node] Links and queuing $ns duplex-link $n0 $n1 <bandwidth> <delay> <queue_type> <queue_type>: DropTail, RED, CBQ, FQ, SFQ, DRR $ns duplex-link $n0 $n1 5Mb 2ms DropTail
  • 26. Inserting Errors Creating Error Module set loss_module [new ErrorModel] $loss_module set rate_ 0.01 $loss_module unit pkt $loss_module ranvar [new RandomVariable/Uniform] $loss_module drop-target [new Agent/Null] Inserting Error Module $ns lossmodel $loss_module $n0 $n1
  • 27. Network Dynamics Link failures Hooks in routing module to reflect routing changes Four models $ns rtmodel Trace <config_file> $n0 $n1 $ns rtmodel Exponential {<params>} $n0 $n1 $ns rtmodel Deterministic {<params>} $n0 $n1 $ns rtmodel-at <time> up|down $n0 $n1 Parameter list [<start>] <up_interval> <down_interval> [<finish>]
  • 28. Setup Routing Unicast $ns rtproto <type> <type>: Static, Session, DV, LS, Manual or hierarchical Multicast $ns multicast (right after [new Simulator]) $ns mrtproto <type> <type>: CtrMcast, DM, ST, BST
  • 29. Creating Connection: TCP One-way TCP sending agent [Tahoe, Reno, NewReno, Sack, Vegas and Fack] set tcp [new Agent/TCP] set tcpsink [new Agent/TCPSink] $ns attach-agent $n0 $tcp $ns attach-agent $n1 $tcpsink $ns connect $tcp $tcpsink
  • 30. Transport n0 n1 Port Port Classifier dst_=1.0 Classifier dst_=0.0 Addr Agent/TCP Addr Agent/TCPSink Classifier 0 agents_ Classifier 0 agents_ 0 dmux_ 1 dmux_ Link n0-n1 entry_ 1 entry_ 0 classifier_ classifier_ Link n1-n0 set tcp [new Agent/TCP] $ns attach-agent $n0 $tcp
  • 31. Creating Traffic: On Top of TCP FTP set ftp [new Application/FTP] $ftp attach-agent $tcp Telnet set telnet [new Application/Telnet] $telnet attach-agent $tcp
  • 32. Application n0 n1 Port Application/FTP Port Classifier dst_=1.0 Classifier dst_=0.0 Addr Agent/TCP Addr Agent/TCPSink Classifier 0 agents_ Classifier 0 agents_ 0 dmux_ 1 dmux_ Link n0-n1 entry_ 1 entry_ 0 classifier_ classifier_ Link n1-n0 set ftp [new Application/FTP] $tcp attach-agent $ftp
  • 33. Plumbing: Packet Flow n0 n1 Port Application/FTP Port Classifier dst_=1.0 Classifier dst_=0.0 Addr Agent/TCP Addr Agent/TCPSink Classifier 0 Classifier 0 0 1 Link n0-n1 entry_ 1 entry_ 0 Link n1-n0
  • 34. Network Topology - Link n0 n1 n1 head_ entry_ enqT_ queue_ deqT_ link_ ttl_ Tracing drophead_ drpT_ $ns duplex-link $n0 $n1 1Mb 10ms DropTail
  • 35. Summary: Generic Script Structure set ns [new Simulator] # [Turn on tracing] # Create topology # Setup packet loss, link dynamics # Create routing agents # Create: # - multicast groups # - protocol agents # - application and/or setup traffic sources # Post-processing procs # Start simulation
  • 36. Example - TCP Simple scenario with TCP and UDP connections n0 n5 TCP UDP recvr n1 n2 5Mb 5Mb 2ms 1.5Mb 2ms 10ms n4 n3 UDP TCPSink
  • 37. TCP : Step 1 Scheduler & tracing #Create scheduler Set ns [new Simulator] #Turn on tracing set f [open out.tr w] $ns trace-all $f Set nf [open out.nam w] $ns namtrace-all $nf
  • 38. TCP : Step 2 Create topology #create nodes set n0 [$ns node] set n1 [$ns node] set n3 [$ns node] set n4 [$ns node] set n5 [$ns node]
  • 39. TCP : Step 3 #create links $ns duplex-link $n0 $n1 5Mb 2ms DropTail $ns duplex-link $n1 $n2 1.5Mb 10ms DropTail $ns duplex-link $n2 $n3 5Mb 2ms DropTail $ns queue-limit $n1 $n2 25 $ns queue-limit $n2 $n1 25 … (for UDP)
  • 40. TCP : Step 4 Create TCP agents set tcp [new Agent/TCP] set sink [new Agent/TCPSink] $ns attach-agent $n0 $tcp $ns attach-agent $n3 $sink $ns connect $tcp $sink … (for UDP)
  • 41. TCP : Step 5 Attach traffic set ftp [new Application/FTP] $ftp attach-agent $tcp #start application traffic $ns at 1.1 “$ftp start” … (for UDP)
  • 42. TCP : Step 6 End of simulation wrapper (as usual) $ns at 2.0 “finish” Proc finish {} { global ns f nf close $f close $nf puts “Running nam…” exec nam out.nam & exit 0 } $ns run
  • 43. Viz Tools Nam (Network AniMator) Packet-level animation Well-supported by ns Commandline start: “nam <nam-tracefile>” Xgraph Convert trace output into xgraph format Commandline start: “xgraph” Gnuplot Convert ASCII Text e.g. trace into 2D/3D plot Commandline start: “gnuplot <scriptfile>”
  • 44. Ns-nam Interface Color Node manipulation Link manipulation Topology layout Protocol state Misc
  • 45. Nam Interface: Color Color mapping $ns color 40 red $ns color 41 blue $ns color 42 chocolate Color ↔ flow id association $tcp0 set fid_ 40 ;# red packets $tcp1 set fid_ 41 ;# blue packets
  • 46. Nam Interface: Nodes Color $node color red Shape (can’t be changed after sim starts) $node shape box ;# circle, box, hexagon Marks (concentric “shapes”) $ns at 1.0 “$n0 add-mark m0 blue box” $ns at 2.0 “$n0 delete-mark m0” Label (single string) $ns at 1.1 “$n0 label ”web cache 0””
  • 47. nam Interfaces: Links Color $ns duplex-link-op $n0 $n1 color quot;greenquot; Label $ns duplex-link-op $n0 $n1 label quot;abcedquot; Dynamics (automatically handled) $ns rtmodel Deterministic {2.0 0.9 0.1} $n0 $n1 Asymmetric links not allowed
  • 48. Nam Interface: Topo Layout “Manual” layout: specify everything $ns duplex-link-op $n(0) $n(1) orient right $ns duplex-link-op $n(1) $n(2) orient right-up $ns duplex-link-op $n(2) $n(3) orient down $ns duplex-link-op $n(3) $n(4) orient 60deg If anything missing automatic layout
  • 49. Nam Interface: Protocol State Monitor values of agent variables $ns add-agent-trace $srm0 srm_agent0 $ns monitor-agent-trace $srm0 $srm0 tracevar C1_ $srm0 tracevar C2_ # … … $ns delete-agent-trace $tcp1
  • 50. Nam Interface: Misc Annotation Add textual explanation to your sim $ns at 3.5 quot;$ns trace-annotate “packet dropquot;“ Set animation rate $ns at 0.0 quot;$ns set-animation-rate 0.1msquot;
  • 51. Ns Features Areas in wired domain LANs diffserv/intserv Multicast Full TCP Applications like web-caching Wireless domain Ad hoc routing Mobile IP Satellite networking Directed diffusion (sensor networks) Emulator Connect simulator in a real network Can receive and send out live packets from/into the real world
  • 52. Resources Ns distribution download http://www.isi.edu/nsnam/ns/ns-build.html Installation problems and bug-fix http://www.isi.edu/nsnam/ns/ns-problems.html Ns-users mailing list Ns-users@isi.edu See http://www.isi.edu/nsnam/ns/ns-lists.html Archives from above URL
  • 53. Resources (contd..) Marc Greis’ tutorial http://www.isi.edu/nsnam/ns/tutorial Ns-users archive Ns-manual http://www.isi.edu/nsnam/ns/ns-documentation.html Tcl (Tool Command Language) http://dev.scriptics.com/scripting Practical programming in Tcl and Tk, Brent Welch Otcl (MIT Object Tcl) ~otcl/doc/tutorial.html (in distribution)
  • 54. Let’s practice a bit II CBR1 UDP1 Use the nam editor and use default values if NULL N1 not otherwise specified. N3 Ethernet Ethernet 10Mbps 10Mbps Delay 1ms R1 R2 Delay 1ms Serial Link CBR2 2Mbps Delay 10ms UDP2 Ethernet 10Mbps Ethernet NULL N2 Delay 1ms 10Mbps Delay 1ms N4 CBR1: starts at 0s mark it blue CBR2: start at 0.1s mark it red Is the distribution fair?
  • 55. Institut für Telematik | Universität zu Lübeck