Presentation is loading. Please wait.

Presentation is loading. Please wait.

Internet Computing KUT Youn-Hee Han

Similar presentations


Presentation on theme: "Internet Computing KUT Youn-Hee Han"— Presentation transcript:

1 Internet Computing Laboratory @ KUT Youn-Hee Han
NS2 Tutorial – Part I Internet Computing KUT Youn-Hee Han

2 VINT and NS (Network Simulator)
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

3 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

4 What is NS? History Columbia NEST UCB REAL ns-1 ns-2 100K lines of C++
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

5 Functionality of NS Wired world Wireless
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

6 NS Flatform Most UNIX and UNIX-like systems Window 95/98/NT
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

7 NS Components ns-2 nam 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) ns-2 trace file (output) nam Data Structure

8 Current Status Users from approximately Releases 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

9 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

10 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 Less Access & Frequent Configuration Pros. Compromise between composibility and speed Cons. Learning and debugging Data Structure

11 OTcl and C++: The Duality
Pure C++ objects Pure OTcl objects C++/OTcl split objects C++ OTcl ns Data Structure

12 OTcl and C++: The Duality
Simulation Scenario 1 2 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(); } C++ Implementation Data Structure

13 Object Correspondence
Agent/DSDV Constructor Agent Constructor Invoke parent TclObject Constructor Invoke parent AgentDSDV() Constructor Create C++ init complete init complete OTcl shadow TCL C++ TclObject() Constructor Invoke parent Do nothing, return Agent() Constructor Invoke parent bind and return bind and return Data Structure

14 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

15 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 Event Scheduler Network Components TclCL OTcl Tcl C/C++ ns-2 Data Structure

16 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 Time: 1.5 sec Time: 1.7 sec 1 2 Time: 2.0 sec Time: 1.8 sec Data Structure

17 Using NS2 Problem Result Simulation Modify analysis model ns Setup/run
with ns Data Structure

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

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

20 Basic ns-2 Create scheduler Create node Create link Schedule event
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

21 The 1st ns-2 script (two nodes, one link)
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 Create the simulator object 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

22 The 1st ns-2 script (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

23 The 1st ns-2 script (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

24 The 1st ns-2 script (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

25 The 2nd ns-2 script (three nodes, two links)
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 Create the simulator object 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

26 The 2nd ns-2 script (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

27 The 2nd ns-2 script (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


Download ppt "Internet Computing KUT Youn-Hee Han"

Similar presentations


Ads by Google