
85465ddf791554ce55336edb6489bf55.ppt
- Количество слайдов: 24
Tutorial on Network Simulator (NS 2) Hemant Kumar Rath Infonet Lab, Dept of Electrical Engineering IIT Bombay, Mumbai - 400076 Network Simulator (NS 2) 1
Introduction Ø Discrete event simulator targeted at networking research and education v Protocol design, traffic studies, etc v Protocol comparison v Wired and wireless networks Ø Back end is in C++ and front end is in o. Tcl Ø Provide a collaborative environment v Open source, Freely distributed • Share code, protocols, models, etc • No code guarantee v Easy comparison of similar protocols Network Simulator (NS 2) 2
Simulation Network Ø Wired Network v Routing: Distance Vector, Link State v Transportation: TCP and UDP v Queuing disciplines: drop-tail, RED, FQ, SFQ, DRR, RR v Qo. S: Int. Serv and Diff. Serv Ø Wireless v Ad-hoc routing and mobile IP: AODV v Sensor-MAC, Wi. MAX (new) v Power control in wireless networks Ø Tracing, Visualization, Analysis, Other utilities Network Simulator (NS 2) 3
NS 2 Functionalities Ø Traffic models and applications v Web, FTP, Telnet, CBR, real time traffic Ø Transport protocols v Unicast: TCP (Reno, New-Reno, Vegas, etc. ), UDP v Multicast: SRM Ø Routing and queuing v Wired and ad-hoc routing and directed diffusion v Queuing protocols: RED, drop-tail, etc Ø Physical media v Wired (point-to-point, LANs), wireless (multiple propagation models), error models, satellite Network Simulator (NS 2) 4
How to work in NS 2 ? Ø Download the software Ø Install NS 2 in your home directory v Compile the latest version of NS 2 v Validate NS 2 Ø Create your topology v Need to understand the real topology and the directory structure in NS 2 v Modify the existing codes • C++ and/or. tcl files v Create your own. tcl script for this Ø Execute the script v Analyze your result Network Simulator (NS 2) 5
Download and Installation of NS 2 Ø Select the Operating System v NS 2 is available for both Windows and Linux v Linux is desirable as C++ compiler is free and easy to debug Ø Check your Hardware v Processor speed, RAM, home directory space • Minimum 400 MB space is required Ø Download the appropriate source file v Available locally in the course home page • http: //sharada. iitb. ac. in/~ee 706/ns 2. html v Read the instructions in details before installation Network Simulator (NS 2) 6
Download and Installation of NS 2 Ø Install NS 2 in your home directory v Follow the instructions given in the course home page v For trouble shooting refer to the links provided in the course home page • http: //nsnam. isi. edu/nsnam/index. php/Troubleshooting v Else, do a google search Ø Solutions to most of the problems are available in the NS 2 mailing list v http: //www. isi. edu/nsnam/ns/ns-lists. html Network Simulator (NS 2) 7
Create your Topology Ø Decide what do you want to simulate v Wired or wireless network v What are the protocols? v How many nodes, what are the measuring parameters? v What are the applications involved, etc? Ø Make a rough sketch of the topology v Figure out the concerned files (C++ or. tcl) v Based on the requirement do the following • Edit the existing C++ files and/or the. tcl files • You can create new C++ files Network Simulator (NS 2) 8
Data and Control Separation Ø o. TCL in the Front End v Control part of NS 2 v Topology (Simulation scenario) configurations v Event driven • Periodic or Triggered action v Manipulates existing C++ objects v Easy to write and edit Ø C++ in the Back End v Core of NS 2, data part of NS 2 v Easy to modify the code • Not fully layered and structured v Packet processing and execution Network Simulator (NS 2) 9
Directory Structure Ø Main directories v bin, ns-2 xx, lib, man, include, etc in ns 2 home Ø ns-2. xx v Readme file v Makefile, installation file, tutorial, etc v Source files related to the protocols • All. cpp and. h files related needed for editing v Need understanding of interaction among the functions/sub routines v Not fully layered like Qual. Network Simulator (NS 2) 10
Compiling NS 2 Ø Create / Modify the C++ file v If you are creating new C++ file, include the name of the new files in the Makefile v If you are editing the existing C++ files, keep a copy of the original file v Add comments to your modifications with date Ø Compile NS 2 v After creation/editing, compile NS 2 using • (make clean; ) make; • Check for errors, if any and rectify Network Simulator (NS 2) 11
Executing NS 2 Ø Create your. tcl script as per your topology Ø Run the. tcl file using ns command v Check which ns 2 you are using v Create a huge output file (trace file) to analyze v Need to understand the file contents v Perl scripts are also available to analyze the trace file Ø Analyze using nam v Visual network animator Ø Single thread of control v No locking or race conditions to worry about Network Simulator (NS 2) 12
Functional Diagram of NS 2 Problem Result Analysis/debug Topology Modify ns (. cpp/. tcl) Setup/execute simulation with ns (. tcl) Network Simulator (NS 2) 13
Simulation with NS 2 Ø Create a New Event Scheduler (simulator env. ) Ø Turn on Tracing v Can use nam also Ø Topology Creation v Create Nodes, Network, Queuing, etc. v Setup Routing v Send Data • Create Transport Connection, Create Traffic, Start Applications v Insert Errors Ø Analyze the Trace File Network Simulator (NS 2) 14
Event Scheduler Ø Event v Generation of a packet, start/finish of transmission Ø Create a New Event Scheduler set ns [new Simulator] Ø Schedule Events $ns at
Tracing and Analyzing Ø Packet Tracing v On all links • $ns trace-all [open cwnd. tr w] v On one specific link • $ns trace-queue $n 0 $n 1$tr
Topology Creation Ø Create Nodes v set n 0 [$ns node] v set n 1 [$ns node] Ø Assign Links and Queuing v $ns
Setup Routing Ø Unicast v $ns rtproto
Sending Data Ø Create UDP Agent and Attach v set udp 0 [new Agent/UDP] v $ns attach-agent $n 0 $udp 0 Ø Create CBR Traffic v set src [new Application/Traffic/CBR] • set cbr 0 [new Application/Traffic/CBR] • $cbr 0 set packet. Size_ 500 • $cbr 0 set interval_ 0. 005 • $cbr 0 attachagent $udp 0 Ø Create Traffic Sink and Attach v set null [new Agent/Null] v $ns attach-agent $n 1 $null Network Simulator (NS 2) 19
Sending Data Ø Create Exponential or Pareto on-off v set src [new Application/Traffic/Exponential] v set src [new Application/Traffic/Pareto Ø Connect two Agents v $ns connect $udp 0 $null Ø Start and Stop of Data v $ns at 0. 5 “$cbr 0 start” v $ns at 4. 5 “$cbr 0 stop” Ø Create TCP Agent and Attach v set tcp 0 [new Agent/TCP] v $ns attach-agent $n 0 $tcp 0 Network Simulator (NS 2) 20
Sending Data Ø Create Traffic Sink and Attach v set null 0 [new Agent/TCPSink] v $ns attach-agent $n 1 $null 0 Ø Connect the Agents v $ns connect $tcp 0 $null 0 Ø Traffic on Top of TCP v FTP • set ftp [new Application/FTP] • $ftp attach-agent $tcp 0 v Telnet • set telnet [new Application/Telnet] • $telnet attach-agent $tcp 0 Network Simulator (NS 2) 21
Inserting Errors Ø Creating Error Module v set loss_module [new Error. Model] v $loss_module set rate_ 0. 01 v $loss_module unit pkt v $loss_module ranvar [new Random. Variable/Uniform] v $loss_module drop-target [new Agent/Null] Ø Inserting Error Module v $ns lossmodel $loss_module $n 0 $n 1 Network Simulator (NS 2) 22
Analyze the Trace File Ø Trace files are huge in size v Only redirect the parameters you want to measure v Traces begin with a single character or abbreviation v It indicates the type of trace, followed by a fixed or variable trace format Ø Perl scripts are available to analyze trace files Ø Refer for the details v http: //nsnam. isi. edu/nsnam/index. php/NS-2_Trace_Formats Network Simulator (NS 2) 23
Queries? hemantr@ee. iitb. ac. in Network Simulator (NS 2) 24