Download presentation
Presentation is loading. Please wait.
1
ECE 6610 Sandeep Kakumanu GNAN research Lab
Network Simulator - ns2 ECE 6610 Sandeep Kakumanu GNAN research Lab
2
Announcements T-Square wiki is up:
Go to Login with your prism ID. Select ECE6610 tab. Use wiki to post questions on class/assignments/ns2/others. Groups have been formed. Assignment 1 has been posted.
3
Outline Discrete event Simulations ns-2 architecture Working with Tcl
Working with C++ Important files Trace analysis Miscellaneous Assignment 1 overview
4
Classification of simulation paradigms
Computer simulation Discrete models Continuous time models event driven time-stepped
5
Discrete event simulations:
As-fast-as-possible execution of simulation as opposed to scaled real-time simulation. Event based scheduling. A single queue of events. Each event has a time stamp. Chronological execution of events. An event might create more events. These new events are inserted into the queue.
6
Ns-2: Introduction NS-2: network simulator version 2
Discrete event simulator Packet level simulation Features Open source Scheduling, routing and congestion control Wired networks: P2P links, LAN Wireless networks: terrestrial (ad-hoc, cellular; GPRS, UMTS, WLAN, Bluetooth), satellite Emulation and trace
7
Ns-2 Paradigm Object-oriented programming Protocol layering
Modularity and extensibility Large scale simulation Maintenance and reusability Split-language programming Scripting language (Tcl) System programming language (C++)
8
Ns-2: Split Languages Tcl scripts (Tcl/OTcl) Interpreted (interactive)
Setup and configuration C codes (C/C++) Compiled (efficient) Algorithms and protocols TclCL (OTcl/C++) Link Tcl/OTcl scripts and C/C++ codes Provide a layer of C++ glue over OTcl
9
OTcl/C++ split objects
NS-2: Split Objects OTcl/C++ split objects Pure OTcl objects Pure C++ objects TclCL linkage OTcl C++ NS-2
10
NS-2: Directory Structure
ns-allinone ... Tcl8 TK8 OTcl TclCL ns-2 nam-1 tcl ... C++ code ex test lib mcast ... examples validation tests OTcl code
11
Structure of a wired node
12
Structure of a wired simplex link
13
A wired LAN
14
A wireless node
15
Setting up ns-2 Requirements: Linux box with at least 500 MB free space. Download the latest ns-allinone-2.33.tar.gz from the ns-2 website (google ns-2). Untar the archive: > tar –xvfz ns-allinone-2.33.tar.gz Install: > cd ns-allinone-2.33 > ./install Setup the environment variables in the bash or csh script. Close xterm and open again. ns-2 should work now.
16
Setting the environment variables
Bash: $ vi .bashrc export PATH=$PATH:/path_to_ns-allinone-2.33/bin:/path_to_ns- allinone-etc/ export LD_LIBRARY_PATH=$PATH:/path_to_ns-allinone…etc/ export TCL_LIBRARY=$PATH:/path_to_ns-allinone…etc/ Csh: > vi .cshrc setenv PATH /path_to_ns-allinone-2.33/bin:/path_to_ns-allinone- etc/:$PATH
17
Working with tcl Tcl is the front-end in ns-2.
Define node configurations, node topology, agents etc. Agents can be UDP/TCP, CBR/FTP/VBR/Webtraffic/... For wired nodes: setup links, define link delays, link errors, define LAN configurations, buffer sizes... For wireless nodes: node positions, node mobility, chose from different MAC, routing protocols. Simple procedures for printing aggregated results like total throughput, total simulation time etc.
18
Working with tcl (cont'd)
A command consists of words cmdName arg1 arg2 … cmdName: core command or procedure set, puts, expr, open, if, for, … All words are considered as strings White space (space/tab) separates arguments Newline or semicolon (;) terminates a command Command evaluation: parsing and execution The interpreter does “substitution” and “grouping” (parsing) before running a command Every command returns a result string after execution
19
Basic Tcl commands: puts - tcl equivalent of printf Ex – puts $a; #will print the value of a set – set value to variable Ex – set a 3; #set value of a=3 expr – evaluate a mathematical expression Ex – expr $a+2 ; #add 2 to a. Complex groupings: set rate [expr 5*$a]; #compute a*5 and set to rate
20
Tcl: procedures Procedures are like functions in C.
Variables defined outside a procedure are invisible inside it. Global variables are visible everywhere. Variable length of arguments using args. Examples proc add args { set s 0 foreach i $args {incr s $i} return $s } proc inc {var {dv 1}} { set a [expr $var+$dv] return $a }
21
Tcl Core commands Control flow if, switch, while, for, foreach
File access open, close, flush, puts, gets String manipulation glob-style and regular expression List manipulation llength, lindex, linsert, lreplace lappend
22
A simple tcl script set ns [new Simulator]
set nf [open out.tr w];$ns trace-all $nf for {set i 0} {$i<2} {incr i} { ;# create the nodes set n($i) [$ns node]} $ns duplex-link $n(0) $n(1) 1Mb 10ms DropTail set udp(0) [new Agent/UDP] # Create a UDP agent $ns attach-agent $n(0) $udp(0) set null0 [new Agent/LossMonitor] $ns attach-agent $n(1) $null0 set cbr(0) [new Application/Traffic/CBR] $cbr(0) set packetSize_500 $cbr(0) set rate_ 100kb $cbr(0) attach-agent $udp(0) $ns connect $udp(0) $null0 $ns at 0.0 "$cbr(0) start" $ns at 10.0 "$cbr(0) stop" proc finish {} { global ns nf $ns flush-trace; close $nf } $ns at 10.0 "finish" $ns run
23
Working with C++ All protocols are written in C++.
Everything is an object. Otcl will attach the necessary C++ objects. All objects are inherited from tclclass. Every object has atleast one header (.h) file and one .cc file. Different objects talk to each other using packets. Every object has a recv() function which receives a packet, and has pointers to all the other attached objects known as targets (uptarget_, downtarget_ etc).
24
Packet Packets are events Can be scheduled to “arrive”
Packets contain header section and data Header section is a cascade of all in-use headers Each packet contains a common header packet size (used to compute transmission time) packet type timestamp, uid, … All in-use headers are included when simulation starts Change packet size to reflect header cascading
25
Important files packet.h – defines all the headers for packets.
scheduler.h,.cc – the C++ scheduler class. agent.h,.cc – the base class for all agents. tcp.h,.cc – TCP, udp.h,.cc – UDP, cbr_traffic.cc – cbr traffic, mac-802_11.h,.cc – MAC. tcl/lib/ns-defaults.tcl – All the default parameters for configurations of the various protocols. tcl/lib/ns-lib.tcl – Otcl script connecting the various layers of the network stack in a single node.
26
Modifying C++ files Modify existing C++ files.
C++ files are inside /path/ns-allinone-2.33/ns-2.33 directory. The directory also has a Makefile. When you edit only a .cc file: $ make When you edit a .h file: $ make clean
27
Traces Ns-2 simulations provide a number of traces.
A trace file is used for post-processing of the simulation and find out what events happened at different times of the simulation. Traces for wired and wireless simulations have different format. Traces are text files. Trace formats at: 2_Trace_Formats Different ways to parse the traces – C, awk, perl... Use anyone in which you are comfortable.
28
Sample trace cbr cbr cbr cbr cbr cbr r cbr cbr cbr cbr cbr r cbr cbr cbr cbr
29
Miscellaneous utlities
nam – Network animator: Used to animate the network events after the simulation has finished. nam will parse a name trace and show the animation. cbrgen – create traffic patterns. setdest – generate wireless topologies and set up mobility patterns using random waypoint model.
30
More help Marc Greis tutorial (Chapters I-VI & VIII-XI). ns-2 manual.
ns-2 mailing list. T-square wiki.
31
Puzzle Are there two dogs in world with the same number of hairs ?
(Make reasonable assumptions)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.