Download - Session 1 introduction to ns2
![Page 1: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/1.jpg)
Introduction to NS2
T S Pradeep KumarVIT University- Chennai campushttp://www.pradeepkumar.org
![Page 2: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/2.jpg)
Overview•Linux Vs Windows•Network Simulation •Introduction to NS2•About NS2•NS2 Architecture•OTCL
![Page 3: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/3.jpg)
Linux for NS2
Windows for NS2
Versus
![Page 4: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/4.jpg)
Why not Windows?•Support has been stopped beyond NS-2.27•Package Configuration is tedious•Use NS2 at your own risk
• Verss
![Page 5: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/5.jpg)
Linux for NS2 Fedora (10, 12)
If DVD Version- no need of additional package installation Install all the packages (if default installation selected, then additional packages have to be
installed) Ubuntu (9.04, 9.10, 10.04, 10.10)
Additional packages to be installed, there may be GCC Issues, xgraph and NAM issues Red Hat Enterprise Linux 5 (RHEL5)
Cent OS is the alternative for RHEL Basic commands (ls, chmod, tar, rpm, make, gedit, vi, pwd, passwd, echo, cd, etc) Directory structure and shell prompt Path variables setting, Installation of packages and dependencies
![Page 6: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/6.jpg)
Basic Linux Commands• ls – to list the directory contents• chmod – changing the mode of the file• tar – tape archive (to compress or decompress)• rpm – a type of installation file for linux• make – to compile or recompile in linux• gedit or vi – editors (similar like notepad)• pwd - present working directory • passwd – to change the user passwd• echo – to echo to the screen• cd – change directory• mkdir – to create a directory
![Page 7: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/7.jpg)
Linux basics
• To run the install file within the directory scope• $prompt] ./install
• To run the install file in global scope is – $prompt] install
TS PRADEEP KUMAR
![Page 8: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/8.jpg)
Network Simulation• Approaches– Experiment
• Put all network Devices and measure the results/performance• Pros - realistic• Cons - Expensive/Sometime impossible
– Mathematical model• Model devices using a graph model• Insight• Need to make assumptions
– Simulation• Use programming to represent devices• Easy and can be easily verified• Not much insight, need to make assumptions
TS PRADEEP KUMAR
![Page 9: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/9.jpg)
Network Simulation
• Network Simulation– Time Driven• Events occurs within the interval is assumed to be
occur at the end of the interval• Simulation finishes at a pre-specified time• a, b,c,d are events• a is assumed to occur at t=2Δ
TS PRADEEP KUMAR
![Page 10: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/10.jpg)
Network Simulation• Network Simulation
– Event Driven• Every event provide a reference to the next event (Example: using
pointer)
• Simulation finishes– When there are no more events– At pre-specified time
TS PRADEEP KUMAR
A B C
![Page 11: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/11.jpg)
About NS2
• NS is a discrete event simulator • It provides support for – Simulation of TCP– Routing– Multicast Protocols over Wired and Wireless
networks
TS PRADEEP KUMAR
![Page 12: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/12.jpg)
About NS2
• NS is not a polished and finished product, but the result of an on-going effort of research and development.
• In particular, bugs in the software are still being discovered and corrected.
• Users of ns are responsible for verifying for themselves that their simulations are not invalidated by bugs
TS PRADEEP KUMAR
![Page 13: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/13.jpg)
TS PRADEEP KUMAR
![Page 14: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/14.jpg)
NS2 Architecture
• Network Simulator 2 is an event driven Simulator
• It consists of – C++ (Internally)– OTCL (User Interface)– TclCL (Interface between C++ and OTCL)
TS PRADEEP KUMAR
![Page 15: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/15.jpg)
NS2 Architecture
TS PRADEEP KUMAR
![Page 16: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/16.jpg)
NS2 Architecture
TS PRADEEP KUMAR
![Page 17: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/17.jpg)
![Page 18: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/18.jpg)
OTCL
• NS is a OTCL interpreter with network simulation object libraries
• Relation between TCL and OTCL is similar to C and C++
• A Simple example follows..• To run these examples– ns filename.tcl (or) tclsh filename.tcl
![Page 19: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/19.jpg)
TCL Example# Writing a procedure called "test“proc test {} {
set a 43set b 27set c [expr $a + $b]set d [expr [expr $a - $b] * $c]for {set k 0} {$k < 10} {incr k} {if {$k < 5} { puts "k < 5, pow = [expr pow($d, $k)]"} else { puts "k >= 5, mod = [expr $d % $k]"} } }
# Calling the "test" procedure created abovetest
![Page 20: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/20.jpg)
OTCL Example
# Create a class call "mom" and add a member function call "greet"Class mommom instproc greet {} { $self instvar age_ puts "$age_ years old mom say: How are you doing?"}
![Page 21: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/21.jpg)
OTCL Example
# Create a child class of "mom" called "kid" and overide the member function "greet"Class kid -superclass momkid instproc greet {} { $self instvar age_ puts "$age_ years old kid say: What's up, dude?"}
![Page 22: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/22.jpg)
OTCL Example
• # Create a mom and a kid object set each age• set a [new mom]• $a set age_ 45• set b [new kid]• $b set age_ 15
• # Calling member function "greet" of each object• $a greet• $b greet
![Page 23: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/23.jpg)
OTCL Example
• class keyword is used to create a class• instproc is used to create a instance procedure
(define a member function)• $self is similar to “this” in C++• instvar checks if the variable is already declared in its
class or superclass. If the variable name given is already declared, the variable is referenced, if not a new one is declared
![Page 24: Session 1 introduction to ns2](https://reader035.vdocuments.us/reader035/viewer/2022081508/5580b8bbd8b42ac6088b4dec/html5/thumbnails/24.jpg)
Lets practice Linux for sometime…..
TS PRADEEP KUMAR