ns2 tutorial part i n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
NS2 Tutorial – Part I PowerPoint Presentation
Download Presentation
NS2 Tutorial – Part I

Loading in 2 Seconds...

play fullscreen
1 / 27

NS2 Tutorial – Part I - PowerPoint PPT Presentation


  • 68 Views
  • Uploaded on

NS2 Tutorial – Part I. Internet Computing Laboratory @ KUT Youn-Hee Han. VINT and NS (Network Simulator). VINT V irtual I nter N et T estbed a collaborative project between USC/ISI, LBL/UC Berkeley, and Xerox PARC Goal

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'NS2 Tutorial – Part I' - joella


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
ns2 tutorial part i

NS2 Tutorial – Part I

Internet Computing Laboratory @ KUT

Youn-Hee Han

vint and ns network simulator
VINT and NS (Network Simulator)
  • VINT
    • Virtual InterNet Testbed
    • a collaborative project between USC/ISI, LBL/UC Berkeley, and Xerox PARC
    • Goal
      • to extend the ns simulator so that network researchers can study the complex interactions between network protocols (e.g., unicast routing, multicast routing, TCP, reliable multicast, integrated services, etc.) in complex topologies and with a rich set of traffic generators.

ISI/USC: University of Southern California/Information Sciences Institute

LBL/UC Berkeley: Lawrence Berkeley National Laboratory/University of California, Berkeley

Data Structure

what is ns
What is NS?
  • http://www.isi.edu/nsnam
  • NS version2 is a discrete-event driven and object-oriented network simulator
    • Events  Packet and Timer
  • Characteristics
    • Freely distributed and open source
    • Discrete event simulator
    • Packet-level Event
    • Wired and wireless
    • Network Stacks from Layer 1 to Layer 7
    • Node mobility

Data Structure

what is ns1
What is NS?
  • History
    • Columbia NEST
    • UCB REAL
    • ns-1
      • Modified from REAL network simulator
    • ns-2
      • 100K lines of C++
      • 70K lines of OTcl
      • 30K lines of test suite
      • 20K lines of documentation

Data Structure

functionality of ns
Functionality of NS
  • Wired world
    • Point-to-point link, LAN
    • Unicast/multicast routing
    • QoS
      • Intserve, Diffserv
    • Transport
      • TCP, UDP
      • Congestion control
    • Application layer
      • Web Caching
      • Mulimedia
  • Wireless
    • Mobile IP
    • Ad hoc routing
  • Tracing, visualization, various utilities

Data Structure

ns flatform
NS Flatform
  • Most UNIX and UNIX-like systems
    • Linux
      • It is preferred
      • Remote access with Xmanager
    • FreeBSD or NetBSD
    • Sun Solaris
  • Window 95/98/NT
    • with Cygwin
      • Some of features are not supported
  • Emulation only for FreeBSD for now
  • VMWare
    • Window host
    • Linux guest

Data Structure

ns components
NS Components
  • NS – Simulator
  • NAM – Network AniMator
    • visual demonstration of NS output
  • Preprocessing
    • Handwritten TCL or
    • Topology generator
  • Post analysis
    • Trace analysis using Perl/TCL/AWK/GnuProt/MATLAB

We just saw this…

Now I will show you this…

tcl script

(specification

of experiment)

trace file

(output)

ns-2

nam

Data Structure

current status
Current Status
  • Users from approximately
    • 600 institutes
    • 50 countries
  • Releases
    • Periodic releases (currently 2.29_3)
    • NS3 project just started (July 1, 2006)
    • Available from: USC (University of Southern California)/ISI (Information Sciences Institute), UC Berkeley, UK mirror

Data Structure

ns2 language
NS2 Language
  • NS2 is written in C++ and OTcl
    • OTcl = Tcl + OO
    • C++ implements the code that executed frequently
      • It implements the system behavior of NS2 (e.g., routing)
    • OTcl configures the system (e.g., topology).
  • Object-oriented (C++, OTcl)
    • Fine-grained object composition
  • Modular approach

Data Structure

c and otcl separation
C++ and OTcl Separation
  • C++ for “data/behavior”
    • NS2 Core & packet processing
    • Fast Execution
    • Good for…
      • Frequent Access & Less Compilation
  • OTcl for “control”
    • Periodic or triggered action
    • Simulation Scenario setup
    • Good for…
      • Less Access & Frequent Configuration
  • Pros.
    • Compromise between composibility and speed
  • Cons.
    • Learning and debugging

Data Structure

otcl and c the duality
OTcl and C++: The Duality

Pure OTcl

objects

Pure C++

objects

C++/OTcl split objects

C++

OTcl

ns

Data Structure

otcl and c the duality1

Simulation Scenario

2

C++ Implementation

1

OTcl and C++: The Duality

set ns_ [new Simulator]

set node_(0) [$ns_ node]

set node_(1) [$ns_ node]

Tcl Script

class MobileNode : public Node

{

friend class PositionHandler;

public:

MobileNode();

}

Data Structure

object correspondence

Agent/DSDV

Agent

TclObject

TclObject()

AgentDSDV()

Agent()

Constructor

Constructor

Constructor

Constructor

Constructor

Constructor

Create C++

Invoke parent

Invoke parent

OTcl shadow

init complete

init complete

Do nothing,

Invoke parent

Invoke parent

bind and return

bind and return

return

Object Correspondence

TCL

C++

Data Structure

user s perspective
User’s Perspective
  • From the user’s perspective, NS−2 is an OTcl interpreter that takes an OTcl script as input and produces a trace file as output

Data Structure

extending tcl interpreter

Network

Components

TclCL

Event

Scheduler

OTcl

Extending Tcl Interpreter
  • Otcl
    • object-oriented Tcl
  • TclCL (Tcl with classes)
    • C++ and OTcl linkage
  • Discrete event scheduler
  • Data network components
    • Link layer and up
    • Emulation support

Tcl

C/C++

ns-2

Data Structure

discrete event simulator

2

Time: 1.5 sec

Time: 1.7 sec

1

Time: 2.0 sec

Time: 1.8 sec

Discrete event simulator
  • ns-2 is an discrete event driven simulation
    • Physical activities are translated to events
    • Events are queued and processed in the order of their scheduled occurrences
    • Time progresses as the events are processed

Data Structure

using ns2
Using NS2

Problem

Result

analysis

Simulation

model

Modify

ns

Setup/run

simulation

with ns

Data Structure

otcl overview
programming language used for setting up simulation environment

object oriented

interpreted (slow)

Used for

Setting up topology

Placing agents

Injecting events

Configuring tracing

OTcl overview

Examples:

  • variables
    • set x 10
    • puts “x is $x”
  • expressions
    • set y [pow x 2]
    • set y [expr x+x*3]
  • control
    • if ($x>0) { return $x } else { return [expr -$x] }
    • while ($x >0) { puts $x
      • set x [eval x+1] }

Data Structure

otcl overview1
programming language used for setting up simulation environment

object oriented

interpreted (slow)

Used for

Setting up topology

Placing agents

Injecting events

Configuring tracing

OTcl overview

Examples:

  • variables
    • set x 10
    • puts “x is $x”
  • expressions
    • set y [pow x 2]
    • set y [expr x+x*3]
  • control
    • if ($x>0) { return $x } else { return [expr -$x] }
    • while ($x >0) { puts $x
      • set x [eval x+1] }

Data Structure

basic ns 2
Basic ns-2
  • Create scheduler
    • set ns [new Simulator]
  • Create node
    • set <var> [$ns node]
    • example: set n0 [$ns node]
  • Create link
    • $ns <link-type> <node1> <node2> <bandwidth> <delay> <queuetype>
    • example: $ns duplex-link $n0 $n1 10Mb 100ms DropTail
  • Schedule event
    • $ns at <time> <event>
    • example: $ns at 10.0 “$ftp start”
  • Start scheduler
    • $ns run

Data Structure

the 1 st ns 2 script two nodes one link
The 1st ns-2script (two nodes, one link)

Create the simulator object

set ns [new Simulator]

set nf [open out.nam w]

$ns namtrace-all $nf

proc finish {} {

global ns nf

$ns flush-trace

close $nf

exec nam out.nam &

exit 0

}

$ns at 5.0 "finish"

$ns run

Open a file for nam trace data

“finish” procedure

Closes the trace file and starts nam

Execute the finish procedure after 5.0 seconds

Data Structure

the 1 st ns 2 script two nodes one link1
The 1st ns-2script (two nodes, one link)

set n0 [$ns node]

set n1 [$ns node]

$ns duplex-link $n0 $n1 1Mb 10ms DropTail

Creates two nodes and assigns them to the handle “n0” and “n1”

connect the nodes n0 and n1 with a duplex link with the bandwidth 1Megabit, a delay of 10ms and a DropTail queue

Data Structure

the 1 st ns 2 script two nodes one link2
The 1st ns-2script (two nodes, one link)

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 500

$cbr0 set interval_ 0.005

$cbr0 attach-agent $udp0

set null0 [new Agent/Null]

$ns attach-agent $n1 $null0

$ns connect $udp0 $null0

Create a UDP agent and attach it to node n0

Create a CBR traffic source and attach it to udp0

Create a Null agent and attach it to node n1

Connect the two agents

Data Structure

the 1 st ns 2 script two nodes one link3
The 1st ns-2script (two nodes, one link)

$ns at 0.5 "$cbr0 start"

$ns at 4.5 "$cbr0 stop"

tell the CBR agent when to send data and when to stop sending

Data Structure

the 2 nd ns 2 script three nodes two links
The 2ndns-2script (three nodes, two links)

Create the simulator object

set ns [new Simulator]

set nf [open out.nam w]

$ns namtrace-all $nf

proc finish {} {

global ns nf

$ns flush-trace

close $nf

exec nam out.nam &

exit 0

}

$ns at 10.0 "finish"

$ns run

Open a file for nam trace data

“finish” procedure

Closes the trace file and starts nam

Execute the finish procedure after 10.0 seconds

Data Structure

the 2 nd ns 2 script three nodes two links1
The 2ndns-2script (three nodes, two links)

Creates three nodes and assigns them to the handle “n0”, “n1”, and “n1”

#Create three nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

#Create link between the nodes

$ns duplex-link $n0 $n1 4Mb 10ms DropTail

$ns duplex-link $n2 $n1 1Mb 10ms DropTail

$ns queue-limit $n1 $n2 10

connect the nodes n0 and n1 with a duplex link with the bandwidth 4Megabit, a delay of 10ms and a DropTail queue

connect the nodes n0 and n2 with a duplex link with the bandwidth 1Megabit, a delay of 10ms and a DropTail queue

the maximum buffer size (#packets) of the queue in the link

n0

n1

n2

Data Structure

the 2 nd ns 2 script three nodes two links2
The 2ndns-2script (three nodes, two links)

#Create a TCP agent and attach it to node n0

set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

#Create a TCP sink agent and attach it to node n2

set sink [new Agent/TCPSink]

$ns attach-agent $n2 $sink

#Connect both agents

$ns connect $tcp0 $sink

# create an FTP source

set ftp [new Application/FTP]

$ftp set maxpkts_ 1000

$ftp attach-agent $tcp0

#Inject starting events

$ns at 0.0 "$ftp start"

$ns at 10.0 "$ftp stop"

$ns at 10.1 "finish"

#Run the simulation

$ns run

Create a TCP agent and attach it to node n0

Create a TCP sink and attach it to node n2

Connect the two agents

Create a FTP application and attach it to agent tcp0

The maximum number of packets generated by the source.

ftp

tcp

tcp-sink

n0

n1

n2

Data Structure