1 / 27

NS2 Tutorial – Part I

Learn about NS2 (Network Simulator) and its functionalities for studying network protocols and complex topologies. Explore its components, simulation scenarios, and programming capabilities.

lmcquaid
Download Presentation

NS2 Tutorial – Part I

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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

  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 • 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 • 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 • 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 – 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

  8. 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

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

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

  12. 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

  13. 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

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

  16. 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

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

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

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

  20. 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

  21. 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

  22. 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

  23. 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

  24. 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

  25. 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

  26. 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

  27. 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

More Related