SlideShare a Scribd company logo
Introduction to
Network Simulator v 2 (ns2)
Presented By:
Dr. Sharad Sharma, Professor, MMDU, Mullana
Outline
NS2 Overview
Working with NS2
Extending NS2
NS2 OVERVIEW
History
NS was developed by UC Berkeley
Maintained by USC Berkeley
Popular simulator in scientific
environment
Other popular network simulators
-Qualnet
-GloMoSim
-OPNET etc.
Help & Resources
NS main web page:
 http://www.isi.edu/nsnam/ns/
 Tutorials:
http://www.isi.edu/nsnam/ns/tutorial/index.html
 http://www.isi.edu/nsnam/ns/ns-tutorial/
 NS Manual:
 http://www.isi.edu/nsnam/ns/ns-
documentation.html
Supporting OS: Most UNIX and UNIX
like systems
-Linux
-SunOS
-Solaris
(Windows)
-95/98/2000/NT/ME
Some work, some do not
NS2 Goals
To support networking research and
education
-Protocol design, traffic studies, etc.
-Protocol comparison
-New architecture designs are also
supported
2 Languages
TCL-Tool command language (Front
end design) . It is easy to code but runs
slowly
C++ (Back end support). It is fast to
run but slower to code and change
C++ is used mainly for the creation of
objects. It is fast to run but slower to
change, making it suitable for detailed
protocol implementation.
OTcl is used as a front-end to setup the
simulator, configure objects and
schedule events. It runs much slower
but can be changed very quickly and
interactively, making it ideal for
simulation configuration.
Protocols/Models Supported by NS2
Wired Networking
-Routing:Unicast, Multicast, and
Hierarchical Routing, etc.
-Transportation:TCP, UDP, others.
-Traffic sources:web, ftp, telnet, cbr, etc.
-Queuing disciplines:Drop-tail, RED, etc.
Protocols/Models Supported by NS2
Ad hoc routing and mobile IP
-Routing Protocol:AODV, DSDV, DSR,
etc.
-MAC layer Protocol:TDMA, CDMA, IEEE
Mac 802.x, etc.
-Physical layers:Different channels,
directional antenna
Sensor Networks
Working with
NS2
-Let‟s start at the very beginning,
a very nice place to start,
when you sing, you begin with A,B,C,
when you simulate, you begin with the
topology,………
Tools
NAM (Network Animator-Visualized
trace tool)
Xgraph-Output (Bandwidth, Cumulative
Packet Loss, Queue Size, etc.)
Trace Files (Tracing on different links)
Steps in Writing a Simulation Script
Create the event scheduler
Turn on tracing
Create network
Setup routing
Create transport connection
Create traffic
Transmit application-level data
A Simple Simulation
0
1
2 3
2Mbps,10ms
2Mbps,10ms
1.7Mbps,20ms
A Simple Simulation
It can be done with a simple Tcl script.
set ns [new Simulator] ;#Create a simulator object
$ns color 1 Blue ;#Define different colors(NAM)
$ns color 2 Red
set nf [open out.nam w] ;Create trace files for simulation
$ns namtrace-all $nf
set tf [open trace.tr w]
$ns trace-all $tf
proc finish {} { ;Define a „finish‟ procedure
global ns nf tf ;nf-nam trace,tf-ns2 trace file
$ns flush-trace
A Simple Simulation
#Close the NAM trace file
close $nf
#Close the ns2 trace file
close $tf
exit 0
}
#Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
A Simple Simulation
#Create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms Droptail
$ns duplex-link $n1 $n2 2Mb 10ms Droptail
$ns duplex-link $n2 $n3 1.7Mb 10ms Droptail
#Set Queue Size of link (n2-n3) to 10
$ns queue-limit $n2 $n3 10
#Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
A Simple Simulation
#Monitor the queue for link (n2-n3,for NAM)
$ns duplex-link-op $n2 $n3 queuePos 0.5
#Setup a TCP connection:from node 0 to node 3
set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
A Simple Simulation
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP ;fro NAM
#Setup a UDP connection:from node 1 to node 3
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
$udp set fid_ 2
A Simple Simulation
#Setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp $cbr
set type_ CBR $cbr ;used by NAM
set packet_size_ 1000 $cbr
set rate_ 1mb $cbr
set random_ false ;generating traffic periodically
#Schedule events for the CBR and FTP agents
$ns at 0.1 “$cbr start”
$ns at 1.0 “$ftp start”
$ns at 4.0 “$ftp stop”
$ns at 4.5 “$cbr stop”
A Simple Simulation
#Detach tcp and sink agents
$ns at 4.5 “ns detach-agent $n0 $tcp ; $ns detach-agent $n3
$sink”
#Call the finish procedure after 5 seconds
$ns at 5.0 “finish”
#Run the simulation
$ns run
The Trace File
Turn on tracing on specific links
$ns_ trace-queue $n0 $n1
Each line in the trace file is in the format
<event> <time> <from> <to> <pkt-type>
<pkt-size> <flags> <fid> <src.port>
<dst.port> <seq> <unique pkt id>
Trace example:
+ 1 0 2 cbr 210--------------0 0.0.3.1 0 0
Event: s send, r receive, + enqueue, -
dequeue, d drop, f forward
A wireless Simulation
Scenario
2 mobile nodes
moving within 500mX500m flat
topology
using DSDV ad hoc routing protocol
TCP traffic
Step 1
# Define Global Variables
# create simulator
set ns_ [new Simulator]
# create a topology in a 500m x 500m area
set topo [new Topography]
$topo load_flatgrid 500 500
Step 2
# Define standard ns/nam trace
# ns trace
set tracefd [open demo.tr w]
$ns_ trace-all $tracefd
# nam trace
set namtrace [open demo.nam w]
$ns_ namtrace-all-wireless $namtrace
500 500
Step 3
# Create God
set god [create-god 2]
God: store an array of the smallest number of hops
required to reach one node to an other
Optimal case against which to compare routing
protocol performance
Automatically generated by scenario file
Step 4
# Define how a mobile node should be created
$ns_ node-config 
-adhocRouting DSDV 
-llType LL 
-macType Mac/802_11 
-ifqLen 50 
-ifqType Queue/DropTail/PriQueue 
-antType Antenna/OmniAntenna 
-propType Propagation/TwoRayGround 
-phyType Phy/WirelessPhy 
-channelType Channel/WirelessChannel 
-topoInstance $topo
-agentTrace ON 
-routerTrace OFF 
-macTrace OFF
Step 5
Single Node
# Create a mobile node, attach it to the channel
set node_(0) [$ns_ node]
# disable random motion
$node_(0) random-motion 0
Set of Nodes
Use “for” loop to create 2 or more nodes:
for {set i < 0} {$i < 2} {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 0
}
Step 6
Node Movement
$node_(0) set X_ 200.00
$node_(1) set X_ 100.00
$node_(0) set Y_ 400.00
$node_(1) set Y_ 350.00
$node_(0) set Z_ 0.00
$node_(1) set Z_ 0.00
$ns_ at 10 $node_(0) setdest 400.00 300.00
5.00
$ns_ at 12 $node_(1) setdest 300.00 150.00
10.00
Extending NS2
Creating New Components
Extending ns in Otcl
source your changes in your simulation
scripts
Extending ns in C++
Change Makefile (if created new files)
make depend
recompile
Thanks.
Any Query?
.
.
.
Demo

More Related Content

What's hot

Ns 2 Network Simulator An Introduction
Ns 2 Network Simulator An IntroductionNs 2 Network Simulator An Introduction
Ns 2 Network Simulator An Introduction
Jaipur National University, Jaipur, Rajasthan, India
 
Cs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exerciseCs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exercise
Pratik Joshi
 
Ns2 introduction 2
Ns2 introduction 2Ns2 introduction 2
Ns2 introduction 2
Rohini Sharma
 
Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34
Shaikhul Islam Chowdhury
 
Ns2 ns3 training in mohali
Ns2 ns3 training in mohaliNs2 ns3 training in mohali
Ns2 ns3 training in mohali
Arwinder paul singh
 
Fast and cost effective geospatial analysis pipeline with AWS lambda
Fast and cost effective geospatial analysis pipeline with AWS lambdaFast and cost effective geospatial analysis pipeline with AWS lambda
Fast and cost effective geospatial analysis pipeline with AWS lambda
Mila Frerichs
 
Introduction to tcpdump
Introduction to tcpdumpIntroduction to tcpdump
Introduction to tcpdump
Lev Walkin
 
Scapy
ScapyScapy
Linux50commands
Linux50commandsLinux50commands
Linux50commands
NIRMAL FELIX
 
Ns2: OTCL - PArt II
Ns2: OTCL - PArt IINs2: OTCL - PArt II
Ns2: OTCL - PArt II
Ajit Nayak
 
Bo2004
Bo2004Bo2004
Bo2004
Dan Kaminsky
 
Tcpdump
TcpdumpTcpdump
Tcpdump
Sourav Roy
 
This is not your father's monitoring.
This is not your father's monitoring.This is not your father's monitoring.
This is not your father's monitoring.
Mathias Herberts
 
Basic linux commands
Basic linux commands Basic linux commands
Basic linux commands
Raghav Arora
 
Glomosim scenarios
Glomosim scenariosGlomosim scenarios
Glomosim scenarios
Kathirvel Ayyaswamy
 
Artimon - Apache Flume (incubating) NYC Meetup 20111108
Artimon - Apache Flume (incubating) NYC Meetup 20111108Artimon - Apache Flume (incubating) NYC Meetup 20111108
Artimon - Apache Flume (incubating) NYC Meetup 20111108
Mathias Herberts
 
DRb at the Ruby Drink-up of Sophia, December 2011
DRb at the Ruby Drink-up of Sophia, December 2011DRb at the Ruby Drink-up of Sophia, December 2011
DRb at the Ruby Drink-up of Sophia, December 2011
rivierarb
 
50 most frequently used unix
50 most frequently used unix50 most frequently used unix
50 most frequently used unix
Teja Bheemanapally
 
40 basic linux command
40 basic linux command40 basic linux command
40 basic linux command
Teja Bheemanapally
 

What's hot (19)

Ns 2 Network Simulator An Introduction
Ns 2 Network Simulator An IntroductionNs 2 Network Simulator An Introduction
Ns 2 Network Simulator An Introduction
 
Cs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exerciseCs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exercise
 
Ns2 introduction 2
Ns2 introduction 2Ns2 introduction 2
Ns2 introduction 2
 
Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34Simulation and Performance Analysis of AODV using NS-2.34
Simulation and Performance Analysis of AODV using NS-2.34
 
Ns2 ns3 training in mohali
Ns2 ns3 training in mohaliNs2 ns3 training in mohali
Ns2 ns3 training in mohali
 
Fast and cost effective geospatial analysis pipeline with AWS lambda
Fast and cost effective geospatial analysis pipeline with AWS lambdaFast and cost effective geospatial analysis pipeline with AWS lambda
Fast and cost effective geospatial analysis pipeline with AWS lambda
 
Introduction to tcpdump
Introduction to tcpdumpIntroduction to tcpdump
Introduction to tcpdump
 
Scapy
ScapyScapy
Scapy
 
Linux50commands
Linux50commandsLinux50commands
Linux50commands
 
Ns2: OTCL - PArt II
Ns2: OTCL - PArt IINs2: OTCL - PArt II
Ns2: OTCL - PArt II
 
Bo2004
Bo2004Bo2004
Bo2004
 
Tcpdump
TcpdumpTcpdump
Tcpdump
 
This is not your father's monitoring.
This is not your father's monitoring.This is not your father's monitoring.
This is not your father's monitoring.
 
Basic linux commands
Basic linux commands Basic linux commands
Basic linux commands
 
Glomosim scenarios
Glomosim scenariosGlomosim scenarios
Glomosim scenarios
 
Artimon - Apache Flume (incubating) NYC Meetup 20111108
Artimon - Apache Flume (incubating) NYC Meetup 20111108Artimon - Apache Flume (incubating) NYC Meetup 20111108
Artimon - Apache Flume (incubating) NYC Meetup 20111108
 
DRb at the Ruby Drink-up of Sophia, December 2011
DRb at the Ruby Drink-up of Sophia, December 2011DRb at the Ruby Drink-up of Sophia, December 2011
DRb at the Ruby Drink-up of Sophia, December 2011
 
50 most frequently used unix
50 most frequently used unix50 most frequently used unix
50 most frequently used unix
 
40 basic linux command
40 basic linux command40 basic linux command
40 basic linux command
 

Similar to Introduction to ns2

Network Simulator Tutorial
Network Simulator TutorialNetwork Simulator Tutorial
Network Simulator Tutorial
cscarcas
 
NS2-tutorial.ppt
NS2-tutorial.pptNS2-tutorial.ppt
NS2-tutorial.ppt
Wajath
 
NS2-tutorial.pdf
NS2-tutorial.pdfNS2-tutorial.pdf
NS2-tutorial.pdf
srinivasa gowda
 
Tut hemant ns2
Tut hemant ns2Tut hemant ns2
Tut hemant ns2
crescent000
 
Ns2
Ns2Ns2
Study of aloha protocol using ns2 network java proram
Study of aloha protocol using ns2 network java proramStudy of aloha protocol using ns2 network java proram
Study of aloha protocol using ns2 network java proram
Meenakshi Devi
 
Ns2
Ns2Ns2
Ns2
namitay
 
NS2 (1).docx
NS2 (1).docxNS2 (1).docx
NS2 (1).docx
SanjayDharmaraj
 
Venkat ns2
Venkat ns2Venkat ns2
Venkat ns2
venkatnampally
 
~Ns2~
~Ns2~~Ns2~
ns-simple.pdf
ns-simple.pdfns-simple.pdf
ns-simple.pdf
Jayaprasanna4
 
ns2-lecture.ppt
ns2-lecture.pptns2-lecture.ppt
ns2-lecture.ppt
AnniModgil
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
AAKASH S
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
AAKASH S
 
link-state-routing-3.pdf
link-state-routing-3.pdflink-state-routing-3.pdf
link-state-routing-3.pdf
Jayaprasanna4
 
study-of-network-simulator.pdf
study-of-network-simulator.pdfstudy-of-network-simulator.pdf
study-of-network-simulator.pdf
Jayaprasanna4
 
cscn1819.pdf
cscn1819.pdfcscn1819.pdf
cscn1819.pdf
Anil Sagar
 
Ns2
Ns2Ns2
B.Tech. Lab Record for Data Communication & Computer Networks
B.Tech.  Lab Record for  Data Communication & Computer NetworksB.Tech.  Lab Record for  Data Communication & Computer Networks
B.Tech. Lab Record for Data Communication & Computer Networks
swapnilherage
 
Error Control in Multimedia Communications using Wireless Sensor Networks report
Error Control in Multimedia Communications using Wireless Sensor Networks reportError Control in Multimedia Communications using Wireless Sensor Networks report
Error Control in Multimedia Communications using Wireless Sensor Networks report
Muragesh Kabbinakantimath
 

Similar to Introduction to ns2 (20)

Network Simulator Tutorial
Network Simulator TutorialNetwork Simulator Tutorial
Network Simulator Tutorial
 
NS2-tutorial.ppt
NS2-tutorial.pptNS2-tutorial.ppt
NS2-tutorial.ppt
 
NS2-tutorial.pdf
NS2-tutorial.pdfNS2-tutorial.pdf
NS2-tutorial.pdf
 
Tut hemant ns2
Tut hemant ns2Tut hemant ns2
Tut hemant ns2
 
Ns2
Ns2Ns2
Ns2
 
Study of aloha protocol using ns2 network java proram
Study of aloha protocol using ns2 network java proramStudy of aloha protocol using ns2 network java proram
Study of aloha protocol using ns2 network java proram
 
Ns2
Ns2Ns2
Ns2
 
NS2 (1).docx
NS2 (1).docxNS2 (1).docx
NS2 (1).docx
 
Venkat ns2
Venkat ns2Venkat ns2
Venkat ns2
 
~Ns2~
~Ns2~~Ns2~
~Ns2~
 
ns-simple.pdf
ns-simple.pdfns-simple.pdf
ns-simple.pdf
 
ns2-lecture.ppt
ns2-lecture.pptns2-lecture.ppt
ns2-lecture.ppt
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
 
link-state-routing-3.pdf
link-state-routing-3.pdflink-state-routing-3.pdf
link-state-routing-3.pdf
 
study-of-network-simulator.pdf
study-of-network-simulator.pdfstudy-of-network-simulator.pdf
study-of-network-simulator.pdf
 
cscn1819.pdf
cscn1819.pdfcscn1819.pdf
cscn1819.pdf
 
Ns2
Ns2Ns2
Ns2
 
B.Tech. Lab Record for Data Communication & Computer Networks
B.Tech.  Lab Record for  Data Communication & Computer NetworksB.Tech.  Lab Record for  Data Communication & Computer Networks
B.Tech. Lab Record for Data Communication & Computer Networks
 
Error Control in Multimedia Communications using Wireless Sensor Networks report
Error Control in Multimedia Communications using Wireless Sensor Networks reportError Control in Multimedia Communications using Wireless Sensor Networks report
Error Control in Multimedia Communications using Wireless Sensor Networks report
 

Recently uploaded

UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
vmspraneeth
 
Mechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineeringMechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineering
sachin chaurasia
 
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
nedcocy
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
upoux
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
Divyanshu
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
Roger Rozario
 
Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...
Prakhyath Rai
 
Open Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surfaceOpen Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surface
Indrajeet sahu
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
21UME003TUSHARDEB
 
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENTNATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
Addu25809
 
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Transcat
 
smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...
um7474492
 
2. protection of river banks and bed erosion protection works.ppt
2. protection of river banks and bed erosion protection works.ppt2. protection of river banks and bed erosion protection works.ppt
2. protection of river banks and bed erosion protection works.ppt
abdatawakjira
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
Kamal Acharya
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
shadow0702a
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
Gino153088
 
Generative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdfGenerative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdf
mahaffeycheryld
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 
OOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming languageOOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming language
PreethaV16
 
TIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptxTIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptx
CVCSOfficial
 

Recently uploaded (20)

UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
 
Mechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineeringMechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineering
 
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
 
Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...
 
Open Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surfaceOpen Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surface
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
 
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENTNATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
 
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
 
smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...
 
2. protection of river banks and bed erosion protection works.ppt
2. protection of river banks and bed erosion protection works.ppt2. protection of river banks and bed erosion protection works.ppt
2. protection of river banks and bed erosion protection works.ppt
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
 
Generative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdfGenerative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdf
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 
OOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming languageOOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming language
 
TIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptxTIME TABLE MANAGEMENT SYSTEM testing.pptx
TIME TABLE MANAGEMENT SYSTEM testing.pptx
 

Introduction to ns2

  • 1. Introduction to Network Simulator v 2 (ns2) Presented By: Dr. Sharad Sharma, Professor, MMDU, Mullana
  • 4. History NS was developed by UC Berkeley Maintained by USC Berkeley Popular simulator in scientific environment Other popular network simulators -Qualnet -GloMoSim -OPNET etc.
  • 5. Help & Resources NS main web page:  http://www.isi.edu/nsnam/ns/  Tutorials: http://www.isi.edu/nsnam/ns/tutorial/index.html  http://www.isi.edu/nsnam/ns/ns-tutorial/  NS Manual:  http://www.isi.edu/nsnam/ns/ns- documentation.html
  • 6. Supporting OS: Most UNIX and UNIX like systems -Linux -SunOS -Solaris (Windows) -95/98/2000/NT/ME Some work, some do not
  • 7. NS2 Goals To support networking research and education -Protocol design, traffic studies, etc. -Protocol comparison -New architecture designs are also supported
  • 8. 2 Languages TCL-Tool command language (Front end design) . It is easy to code but runs slowly C++ (Back end support). It is fast to run but slower to code and change
  • 9. C++ is used mainly for the creation of objects. It is fast to run but slower to change, making it suitable for detailed protocol implementation. OTcl is used as a front-end to setup the simulator, configure objects and schedule events. It runs much slower but can be changed very quickly and interactively, making it ideal for simulation configuration.
  • 10. Protocols/Models Supported by NS2 Wired Networking -Routing:Unicast, Multicast, and Hierarchical Routing, etc. -Transportation:TCP, UDP, others. -Traffic sources:web, ftp, telnet, cbr, etc. -Queuing disciplines:Drop-tail, RED, etc.
  • 11. Protocols/Models Supported by NS2 Ad hoc routing and mobile IP -Routing Protocol:AODV, DSDV, DSR, etc. -MAC layer Protocol:TDMA, CDMA, IEEE Mac 802.x, etc. -Physical layers:Different channels, directional antenna Sensor Networks
  • 12. Working with NS2 -Let‟s start at the very beginning, a very nice place to start, when you sing, you begin with A,B,C, when you simulate, you begin with the topology,………
  • 13. Tools NAM (Network Animator-Visualized trace tool) Xgraph-Output (Bandwidth, Cumulative Packet Loss, Queue Size, etc.) Trace Files (Tracing on different links)
  • 14. Steps in Writing a Simulation Script Create the event scheduler Turn on tracing Create network Setup routing Create transport connection Create traffic Transmit application-level data
  • 15. A Simple Simulation 0 1 2 3 2Mbps,10ms 2Mbps,10ms 1.7Mbps,20ms
  • 16. A Simple Simulation It can be done with a simple Tcl script. set ns [new Simulator] ;#Create a simulator object $ns color 1 Blue ;#Define different colors(NAM) $ns color 2 Red set nf [open out.nam w] ;Create trace files for simulation $ns namtrace-all $nf set tf [open trace.tr w] $ns trace-all $tf proc finish {} { ;Define a „finish‟ procedure global ns nf tf ;nf-nam trace,tf-ns2 trace file $ns flush-trace
  • 17. A Simple Simulation #Close the NAM trace file close $nf #Close the ns2 trace file close $tf exit 0 } #Create four nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node]
  • 18. A Simple Simulation #Create links between the nodes $ns duplex-link $n0 $n2 2Mb 10ms Droptail $ns duplex-link $n1 $n2 2Mb 10ms Droptail $ns duplex-link $n2 $n3 1.7Mb 10ms Droptail #Set Queue Size of link (n2-n3) to 10 $ns queue-limit $n2 $n3 10 #Give node position (for NAM) $ns duplex-link-op $n0 $n2 orient right-down $ns duplex-link-op $n1 $n2 orient right-up $ns duplex-link-op $n2 $n3 orient right
  • 19. A Simple Simulation #Monitor the queue for link (n2-n3,for NAM) $ns duplex-link-op $n2 $n3 queuePos 0.5 #Setup a TCP connection:from node 0 to node 3 set tcp [new Agent/TCP] $ns attach-agent $n0 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n3 $sink $ns connect $tcp $sink $tcp set fid_ 1
  • 20. A Simple Simulation #Setup a FTP over TCP connection set ftp [new Application/FTP] $ftp attach-agent $tcp $ftp set type_ FTP ;fro NAM #Setup a UDP connection:from node 1 to node 3 set udp [new Agent/UDP] $ns attach-agent $n1 $udp set null [new Agent/Null] $ns attach-agent $n3 $null $ns connect $udp $null $udp set fid_ 2
  • 21. A Simple Simulation #Setup a CBR over UDP connection set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set type_ CBR $cbr ;used by NAM set packet_size_ 1000 $cbr set rate_ 1mb $cbr set random_ false ;generating traffic periodically #Schedule events for the CBR and FTP agents $ns at 0.1 “$cbr start” $ns at 1.0 “$ftp start” $ns at 4.0 “$ftp stop” $ns at 4.5 “$cbr stop”
  • 22. A Simple Simulation #Detach tcp and sink agents $ns at 4.5 “ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink” #Call the finish procedure after 5 seconds $ns at 5.0 “finish” #Run the simulation $ns run
  • 23. The Trace File Turn on tracing on specific links $ns_ trace-queue $n0 $n1 Each line in the trace file is in the format <event> <time> <from> <to> <pkt-type> <pkt-size> <flags> <fid> <src.port> <dst.port> <seq> <unique pkt id> Trace example: + 1 0 2 cbr 210--------------0 0.0.3.1 0 0 Event: s send, r receive, + enqueue, - dequeue, d drop, f forward
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31. A wireless Simulation Scenario 2 mobile nodes moving within 500mX500m flat topology using DSDV ad hoc routing protocol TCP traffic
  • 32. Step 1 # Define Global Variables # create simulator set ns_ [new Simulator] # create a topology in a 500m x 500m area set topo [new Topography] $topo load_flatgrid 500 500
  • 33. Step 2 # Define standard ns/nam trace # ns trace set tracefd [open demo.tr w] $ns_ trace-all $tracefd # nam trace set namtrace [open demo.nam w] $ns_ namtrace-all-wireless $namtrace 500 500
  • 34. Step 3 # Create God set god [create-god 2] God: store an array of the smallest number of hops required to reach one node to an other Optimal case against which to compare routing protocol performance Automatically generated by scenario file
  • 35. Step 4 # Define how a mobile node should be created $ns_ node-config -adhocRouting DSDV -llType LL -macType Mac/802_11 -ifqLen 50 -ifqType Queue/DropTail/PriQueue -antType Antenna/OmniAntenna -propType Propagation/TwoRayGround -phyType Phy/WirelessPhy -channelType Channel/WirelessChannel -topoInstance $topo -agentTrace ON -routerTrace OFF -macTrace OFF
  • 36. Step 5 Single Node # Create a mobile node, attach it to the channel set node_(0) [$ns_ node] # disable random motion $node_(0) random-motion 0 Set of Nodes Use “for” loop to create 2 or more nodes: for {set i < 0} {$i < 2} {incr i} { set node_($i) [$ns_ node] $node_($i) random-motion 0 }
  • 37. Step 6 Node Movement $node_(0) set X_ 200.00 $node_(1) set X_ 100.00 $node_(0) set Y_ 400.00 $node_(1) set Y_ 350.00 $node_(0) set Z_ 0.00 $node_(1) set Z_ 0.00 $ns_ at 10 $node_(0) setdest 400.00 300.00 5.00 $ns_ at 12 $node_(1) setdest 300.00 150.00 10.00
  • 39. Creating New Components Extending ns in Otcl source your changes in your simulation scripts Extending ns in C++ Change Makefile (if created new files) make depend recompile
  • 40.
  • 41.
  • 42.
  • 43.