SlideShare a Scribd company logo
1 of 26
Presentation on-
Working with Network
Simulator 2
Presented By-
Chanchal
Agarwal
Id-47043
M.Tech 1st year
Hello World - Interactive Mode
chanchal>ns
% set ns [new Simulator]
_o3
% $ns at 1 “puts “Hello World!””
1
% $ns at 1.5 “exit”
2
% $ns run
Hello World!
chanchal>
Hello World - Batch Mode
simple.tcl
set ns [new Simulator]
$ns at 1 “puts “Hello World!””
$ns at 1.5 “exit”
$ns run
chanchal> ns simple.tcl
Hello World!
chanchal>
Tcl and OTcl
 TCL- Tool Command Language and pronounced
as "Tickle“.
 TCL is a scripting programming language -
similar to PERL or Python.
 Very good for quick and dirty jobs
 Object TCL (OTCL) is an object oriented
extension of TCL. OTcl is written in C++.
 OTCL's library of objects can
be extended by adding object definitions in
the C++ source code
NS-2 Design
NS-2 Design
 To use NS-2, a user programs should be in the
OTcl script language.
 An OTcl script will do the following.
 Initiates an event scheduler.
 Sets up the network topology using the network
objects.
 Tells traffic sources when to start/stop
transmitting packets through the event
scheduler.
 Depending on the user’s purpose for an OTcl
simulation script, simulation results are stored as
trace files, which can be loaded for analysis by
an external application:
1. A NAM trace file (file.nam) for use with the
Network Animator Tool.
2. A Trace file (file.tr) for use with XGraph or
TraceGraph.
Flow of events for a Tcl file
Languages Used in NS-2
 Split-Language programming is used .
Scripting Language (Tcl - Tool Command
Language and pronounced ‘tickle’)
System Programming Language (C/C++)
 Ns is a Tcl interpreter to run Tcl Scripts .
 By using C++/OTcl, the network simulator is
completely Object-oriented.
 TclCL is the language used to provide a linkage
between C++ and OTcl.
OTcl and C++: The Duality
NAM
 NAM- Network Animator.
 Provides a visual interpretation of the network
created.
 Can be executed directly from a Tcl script.
 Presents information such as throughput,
number packets on each link.
 Provides a drag and drop interface for creating
topologies.
Trace Files
 Syntax For Creating A Trace File
# Open the trace file
set nf [open out.tr w]
$ns trace-all $nf
# Define finish procedure
proc finish {} {
global ns nf
$ns flush-trace
close nf
exit 0 }
Creating Network
 Nodes
set n0 [$ns node]
set n1 [$ns node]
 The following creates 5 nodes, with handles n0-n4
for {set i 0} {$i<5} {incr i} {Set n($i) [$ns node] }
 To set the colour of a node, the following code is used.
$n0 color <colour>
where <colour> is black, red, blue, seaGreen.
n0 n1
Creating Network
 Links and queuing
$ns duplex-link $n0 $n1 <bandwidth> <delay>
<queue_type>
1. <bandwidth>: 1000b, 1kb, 0.001Mb, …
2. <delay>: 1ms, 0.001s, …
3. <queue_type>: DropTail, RED, CBQ, FQ,
SFQ, DRR.
n0 n1
Creating Connection – Agents
 UDP
1. set src [new Agent/UDP]
2. set rcv [new Agent/Null]
3. $ns attach-agent $n0 $src
4. $ns attach-agent $n1 $rcv
5. $ns connect $src $rcv
 TCP
1. set tcp [new Agent/TCP]
2. set tcpsink [new Agent/TCPSink]
3. $ns attach-agent $n0 $src
4. $ns attach-agent $n1 $rcv
5. $ns connect $tcp $tcpsink
Traffic Applications
 The OTcl code to implement a CBR traffic
source in a simulation is as follows:
1. set my_cbr [new Application/Traffic/CBR]
2. $my_cbr attach-agent $udp
3. $ns at <time> “$my_cbr start”
 Parameters:
1. start: starts sending packets according to
the configuration parameters
2. stop: stops sending packets
Traffic Applications
 Configuration parameters:
1. PacketSize_: constant size of packets
generated e.g. 48
2. rate_: sending rate e.g. 64kb
3. interval_: (optional) interval time between
packets e.g. 0.05
4. random_: Flag to introduce noise in the
departure times, default is off, 1 for on
5. maxpkts_: the maximum number of packets
to send e.g. 1000
Traffic Applications
 Two simulation applications exist to send traffic on top of a TCP object:
Application/FTP and Application/Telnet.
File Transfer Protocol (FTP- for simulating bulk data transfer)
1. set ftp [new Application/FTP]
2. $ftp attach-agent $tcp
3. $ns at <time> “$ftp start”
Parameters
1. attach-agent: attaches an Application/FTP agent to an agent
2. start: start the Application/FTP to send data .
3. stop: stop sending data.
4. produce n: where n is the counter of packets to be sent .
5. producemore n: where n is the new increased value of packets to be sent .
6. send n: similar to producemore, but sends n bytes instead of packets .
Traffic Applications
 Telnet
1. OTcl code for using Telnet in a simulation:
2. set telnet [new Application/Telnet]
3. $telnet attach-agent $tcp
Parameters
1. start; start producing packets.
2. stop: stop producing packets.
3. attach-agent: attaches a Telnet object to an
agent.
Example-2
#Create a simulator object
set ns [new Simulator]
#Open the namtrace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Execute nam on the trace file
exec nam out.nam &
exit 0
}
Example-2
#Create two nodes
set n0 [$ns node]
set n1 [$ns node]
#Create a duplex link between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
#Call the finish procedure after 5 seconds of simulation
time
$ns at 5.0 "finish"
#Run the simulation
$ns run
Example-3
#Create a simulator object
set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 0 Blue
#Open the namtrace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Execute nam on the trace file
exec nam out.nam &
exit 0
}
Example-3
#Create two nodes
set n0 [$ns node]
set n1 [$ns node]
#Create a duplex link between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
#Give node position (for NAM)
$ns duplex-link-op $n0 $n1 orient right-down
#Create a UDP agent and attach it to node n0
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
Example-3
#Create a Null agent (a traffic sink) and attach it to node n1
set null0 [new Agent/Null]
$ns attach-agent $n1 $null0
#Connect the traffic source with the traffic sink
$ns connect $udp0 $null0
#Schedule events for the CBR agent
$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run
THANK
YOU

More Related Content

What's hot

Unicasting , Broadcasting And Multicasting New
Unicasting , Broadcasting And Multicasting NewUnicasting , Broadcasting And Multicasting New
Unicasting , Broadcasting And Multicasting Newtechbed
 
Directed diffusion for wireless sensor networking
Directed diffusion for wireless sensor networkingDirected diffusion for wireless sensor networking
Directed diffusion for wireless sensor networkingHabibur Rahman
 
Wireless Local Area Networks
Wireless Local Area NetworksWireless Local Area Networks
Wireless Local Area NetworksDilum Bandara
 
wireless network IEEE 802.11
 wireless network IEEE 802.11 wireless network IEEE 802.11
wireless network IEEE 802.11Shreejan Acharya
 
W-LAN (Wireless Local Area Network)
W-LAN (Wireless Local Area Network)W-LAN (Wireless Local Area Network)
W-LAN (Wireless Local Area Network)Parvesh Taneja
 
Computer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESS
Computer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESSComputer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESS
Computer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESSDr. SELVAGANESAN S
 
Popular network devices
Popular network devicesPopular network devices
Popular network devicesMahesh_Naidu
 
Classless inter domain routing
Classless inter domain routingClassless inter domain routing
Classless inter domain routingVikash Gangwar
 
Nat presentation
Nat presentationNat presentation
Nat presentationhassoon3
 
Physical Layer of ISO-OSI model and Devices
Physical Layer of ISO-OSI model and DevicesPhysical Layer of ISO-OSI model and Devices
Physical Layer of ISO-OSI model and DevicesShahid Khan
 

What's hot (20)

Addressing
AddressingAddressing
Addressing
 
~Ns2~
~Ns2~~Ns2~
~Ns2~
 
Ipx protocol slide share
Ipx protocol slide shareIpx protocol slide share
Ipx protocol slide share
 
Unicasting , Broadcasting And Multicasting New
Unicasting , Broadcasting And Multicasting NewUnicasting , Broadcasting And Multicasting New
Unicasting , Broadcasting And Multicasting New
 
Switching
SwitchingSwitching
Switching
 
Directed diffusion for wireless sensor networking
Directed diffusion for wireless sensor networkingDirected diffusion for wireless sensor networking
Directed diffusion for wireless sensor networking
 
Vlan
Vlan Vlan
Vlan
 
Wireless Local Area Networks
Wireless Local Area NetworksWireless Local Area Networks
Wireless Local Area Networks
 
Vpn
VpnVpn
Vpn
 
wireless network IEEE 802.11
 wireless network IEEE 802.11 wireless network IEEE 802.11
wireless network IEEE 802.11
 
W-LAN (Wireless Local Area Network)
W-LAN (Wireless Local Area Network)W-LAN (Wireless Local Area Network)
W-LAN (Wireless Local Area Network)
 
Computer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESS
Computer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESSComputer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESS
Computer Networks Unit 2 UNIT II DATA-LINK LAYER & MEDIA ACCESS
 
Popular network devices
Popular network devicesPopular network devices
Popular network devices
 
X.25
X.25X.25
X.25
 
Classless inter domain routing
Classless inter domain routingClassless inter domain routing
Classless inter domain routing
 
Channel Allocation.pptx
Channel Allocation.pptxChannel Allocation.pptx
Channel Allocation.pptx
 
Nat presentation
Nat presentationNat presentation
Nat presentation
 
Sdn ppt
Sdn pptSdn ppt
Sdn ppt
 
Virtual LAN
Virtual LANVirtual LAN
Virtual LAN
 
Physical Layer of ISO-OSI model and Devices
Physical Layer of ISO-OSI model and DevicesPhysical Layer of ISO-OSI model and Devices
Physical Layer of ISO-OSI model and Devices
 

Viewers also liked

NS-2 Tutorial
NS-2 TutorialNS-2 Tutorial
NS-2 Tutorialcode453
 
Protocol implementation on NS2
Protocol implementation on NS2Protocol implementation on NS2
Protocol implementation on NS2amreshrai02
 
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.34Shaikhul Islam Chowdhury
 
NS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesNS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesTeerawat Issariyakul
 
Use of NS-2 to Simulate MANET Routing Algorithms
Use of NS-2 to Simulate MANET Routing AlgorithmsUse of NS-2 to Simulate MANET Routing Algorithms
Use of NS-2 to Simulate MANET Routing AlgorithmsGiancarlo Romeo
 
Cour simulation ns2
Cour simulation ns2Cour simulation ns2
Cour simulation ns2Gilles Samba
 
IEEE NS2 & NS3 PROJECT TITLE 2015-16
IEEE NS2 & NS3  PROJECT TITLE 2015-16IEEE NS2 & NS3  PROJECT TITLE 2015-16
IEEE NS2 & NS3 PROJECT TITLE 2015-16Spiro Vellore
 
Malicious node detection in vanet
Malicious node detection in vanetMalicious node detection in vanet
Malicious node detection in vanetVYSAKHMANAYATH
 
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 proramMeenakshi Devi
 
NS2 Projects Source Code NS2 Projects 2013 Wireless Sensor Networks Cognitive...
NS2 Projects Source Code NS2 Projects 2013 Wireless Sensor Networks Cognitive...NS2 Projects Source Code NS2 Projects 2013 Wireless Sensor Networks Cognitive...
NS2 Projects Source Code NS2 Projects 2013 Wireless Sensor Networks Cognitive...ns2matrixcube
 
Routage dans les réseaux ad hoc
Routage dans les réseaux ad hocRoutage dans les réseaux ad hoc
Routage dans les réseaux ad hochamouze
 
Vanet - routage unicast et adressage
Vanet - routage unicast et adressageVanet - routage unicast et adressage
Vanet - routage unicast et adressageGhazi Tekaya
 
NS2 Projects for Final Year Students, MANET, VANET, Ad-Hoc Networks...
NS2 Projects for Final Year Students, MANET, VANET, Ad-Hoc Networks...NS2 Projects for Final Year Students, MANET, VANET, Ad-Hoc Networks...
NS2 Projects for Final Year Students, MANET, VANET, Ad-Hoc Networks...Manoj Subramanian
 
QoS of WLAN (WiFi) - French
QoS of WLAN (WiFi) - FrenchQoS of WLAN (WiFi) - French
QoS of WLAN (WiFi) - FrenchAssia Mounir
 
Simulation d'un réseau Ad-Hoc sous NS2
Simulation d'un réseau Ad-Hoc sous NS2Simulation d'un réseau Ad-Hoc sous NS2
Simulation d'un réseau Ad-Hoc sous NS2Rihab Chebbah
 

Viewers also liked (20)

NS-2 Tutorial
NS-2 TutorialNS-2 Tutorial
NS-2 Tutorial
 
Protocol implementation on NS2
Protocol implementation on NS2Protocol implementation on NS2
Protocol implementation on NS2
 
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
 
Ns2programs
Ns2programsNs2programs
Ns2programs
 
NS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesNS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variables
 
Ns2
Ns2Ns2
Ns2
 
Use of NS-2 to Simulate MANET Routing Algorithms
Use of NS-2 to Simulate MANET Routing AlgorithmsUse of NS-2 to Simulate MANET Routing Algorithms
Use of NS-2 to Simulate MANET Routing Algorithms
 
Dynamic UID
Dynamic UIDDynamic UID
Dynamic UID
 
Cour simulation ns2
Cour simulation ns2Cour simulation ns2
Cour simulation ns2
 
IEEE NS2 & NS3 PROJECT TITLE 2015-16
IEEE NS2 & NS3  PROJECT TITLE 2015-16IEEE NS2 & NS3  PROJECT TITLE 2015-16
IEEE NS2 & NS3 PROJECT TITLE 2015-16
 
Malicious node detection in vanet
Malicious node detection in vanetMalicious node detection in vanet
Malicious node detection in vanet
 
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 Projects Source Code NS2 Projects 2013 Wireless Sensor Networks Cognitive...
NS2 Projects Source Code NS2 Projects 2013 Wireless Sensor Networks Cognitive...NS2 Projects Source Code NS2 Projects 2013 Wireless Sensor Networks Cognitive...
NS2 Projects Source Code NS2 Projects 2013 Wireless Sensor Networks Cognitive...
 
Routage dans les réseaux ad hoc
Routage dans les réseaux ad hocRoutage dans les réseaux ad hoc
Routage dans les réseaux ad hoc
 
Marketing
MarketingMarketing
Marketing
 
Vanet - routage unicast et adressage
Vanet - routage unicast et adressageVanet - routage unicast et adressage
Vanet - routage unicast et adressage
 
Marketing
MarketingMarketing
Marketing
 
NS2 Projects for Final Year Students, MANET, VANET, Ad-Hoc Networks...
NS2 Projects for Final Year Students, MANET, VANET, Ad-Hoc Networks...NS2 Projects for Final Year Students, MANET, VANET, Ad-Hoc Networks...
NS2 Projects for Final Year Students, MANET, VANET, Ad-Hoc Networks...
 
QoS of WLAN (WiFi) - French
QoS of WLAN (WiFi) - FrenchQoS of WLAN (WiFi) - French
QoS of WLAN (WiFi) - French
 
Simulation d'un réseau Ad-Hoc sous NS2
Simulation d'un réseau Ad-Hoc sous NS2Simulation d'un réseau Ad-Hoc sous NS2
Simulation d'un réseau Ad-Hoc sous NS2
 

Similar to Working with NS2

Similar to Working with NS2 (20)

Cs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exerciseCs757 ns2-tutorial-exercise
Cs757 ns2-tutorial-exercise
 
NS2-tutorial.ppt
NS2-tutorial.pptNS2-tutorial.ppt
NS2-tutorial.ppt
 
study-of-network-simulator.pdf
study-of-network-simulator.pdfstudy-of-network-simulator.pdf
study-of-network-simulator.pdf
 
Network Simulator Tutorial
Network Simulator TutorialNetwork Simulator Tutorial
Network Simulator Tutorial
 
Ns network simulator
Ns network simulatorNs network simulator
Ns network simulator
 
Introduction to ns2
Introduction to ns2Introduction to ns2
Introduction to ns2
 
NS2-tutorial.pdf
NS2-tutorial.pdfNS2-tutorial.pdf
NS2-tutorial.pdf
 
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
 
Ns2: OTCL - PArt II
Ns2: OTCL - PArt IINs2: OTCL - PArt II
Ns2: OTCL - PArt II
 
Ns2
Ns2Ns2
Ns2
 
Ns2pre
Ns2preNs2pre
Ns2pre
 
NS2 (1).docx
NS2 (1).docxNS2 (1).docx
NS2 (1).docx
 
ns2-lecture.ppt
ns2-lecture.pptns2-lecture.ppt
ns2-lecture.ppt
 
Tut hemant ns2
Tut hemant ns2Tut hemant ns2
Tut hemant ns2
 
cscn1819.pdf
cscn1819.pdfcscn1819.pdf
cscn1819.pdf
 
Venkat ns2
Venkat ns2Venkat ns2
Venkat ns2
 
Introduction to NS2 - Cont..
Introduction to NS2 - Cont..Introduction to NS2 - Cont..
Introduction to NS2 - Cont..
 
Ns2 ns3 training in mohali
Ns2 ns3 training in mohaliNs2 ns3 training in mohali
Ns2 ns3 training in mohali
 
Ns tutorial
Ns tutorialNs tutorial
Ns tutorial
 
Ns2 introduction 2
Ns2 introduction 2Ns2 introduction 2
Ns2 introduction 2
 

Recently uploaded

Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSrknatarajan
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 

Recently uploaded (20)

Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 

Working with NS2

  • 1. Presentation on- Working with Network Simulator 2 Presented By- Chanchal Agarwal Id-47043 M.Tech 1st year
  • 2. Hello World - Interactive Mode chanchal>ns % set ns [new Simulator] _o3 % $ns at 1 “puts “Hello World!”” 1 % $ns at 1.5 “exit” 2 % $ns run Hello World! chanchal>
  • 3. Hello World - Batch Mode simple.tcl set ns [new Simulator] $ns at 1 “puts “Hello World!”” $ns at 1.5 “exit” $ns run chanchal> ns simple.tcl Hello World! chanchal>
  • 4. Tcl and OTcl  TCL- Tool Command Language and pronounced as "Tickle“.  TCL is a scripting programming language - similar to PERL or Python.  Very good for quick and dirty jobs  Object TCL (OTCL) is an object oriented extension of TCL. OTcl is written in C++.  OTCL's library of objects can be extended by adding object definitions in the C++ source code
  • 6. NS-2 Design  To use NS-2, a user programs should be in the OTcl script language.  An OTcl script will do the following.  Initiates an event scheduler.  Sets up the network topology using the network objects.  Tells traffic sources when to start/stop transmitting packets through the event scheduler.
  • 7.  Depending on the user’s purpose for an OTcl simulation script, simulation results are stored as trace files, which can be loaded for analysis by an external application: 1. A NAM trace file (file.nam) for use with the Network Animator Tool. 2. A Trace file (file.tr) for use with XGraph or TraceGraph.
  • 8. Flow of events for a Tcl file
  • 9. Languages Used in NS-2  Split-Language programming is used . Scripting Language (Tcl - Tool Command Language and pronounced ‘tickle’) System Programming Language (C/C++)  Ns is a Tcl interpreter to run Tcl Scripts .  By using C++/OTcl, the network simulator is completely Object-oriented.  TclCL is the language used to provide a linkage between C++ and OTcl.
  • 10. OTcl and C++: The Duality
  • 11. NAM  NAM- Network Animator.  Provides a visual interpretation of the network created.  Can be executed directly from a Tcl script.  Presents information such as throughput, number packets on each link.  Provides a drag and drop interface for creating topologies.
  • 12.
  • 13. Trace Files  Syntax For Creating A Trace File # Open the trace file set nf [open out.tr w] $ns trace-all $nf # Define finish procedure proc finish {} { global ns nf $ns flush-trace close nf exit 0 }
  • 14. Creating Network  Nodes set n0 [$ns node] set n1 [$ns node]  The following creates 5 nodes, with handles n0-n4 for {set i 0} {$i<5} {incr i} {Set n($i) [$ns node] }  To set the colour of a node, the following code is used. $n0 color <colour> where <colour> is black, red, blue, seaGreen. n0 n1
  • 15. Creating Network  Links and queuing $ns duplex-link $n0 $n1 <bandwidth> <delay> <queue_type> 1. <bandwidth>: 1000b, 1kb, 0.001Mb, … 2. <delay>: 1ms, 0.001s, … 3. <queue_type>: DropTail, RED, CBQ, FQ, SFQ, DRR. n0 n1
  • 16. Creating Connection – Agents  UDP 1. set src [new Agent/UDP] 2. set rcv [new Agent/Null] 3. $ns attach-agent $n0 $src 4. $ns attach-agent $n1 $rcv 5. $ns connect $src $rcv  TCP 1. set tcp [new Agent/TCP] 2. set tcpsink [new Agent/TCPSink] 3. $ns attach-agent $n0 $src 4. $ns attach-agent $n1 $rcv 5. $ns connect $tcp $tcpsink
  • 17. Traffic Applications  The OTcl code to implement a CBR traffic source in a simulation is as follows: 1. set my_cbr [new Application/Traffic/CBR] 2. $my_cbr attach-agent $udp 3. $ns at <time> “$my_cbr start”  Parameters: 1. start: starts sending packets according to the configuration parameters 2. stop: stops sending packets
  • 18. Traffic Applications  Configuration parameters: 1. PacketSize_: constant size of packets generated e.g. 48 2. rate_: sending rate e.g. 64kb 3. interval_: (optional) interval time between packets e.g. 0.05 4. random_: Flag to introduce noise in the departure times, default is off, 1 for on 5. maxpkts_: the maximum number of packets to send e.g. 1000
  • 19. Traffic Applications  Two simulation applications exist to send traffic on top of a TCP object: Application/FTP and Application/Telnet. File Transfer Protocol (FTP- for simulating bulk data transfer) 1. set ftp [new Application/FTP] 2. $ftp attach-agent $tcp 3. $ns at <time> “$ftp start” Parameters 1. attach-agent: attaches an Application/FTP agent to an agent 2. start: start the Application/FTP to send data . 3. stop: stop sending data. 4. produce n: where n is the counter of packets to be sent . 5. producemore n: where n is the new increased value of packets to be sent . 6. send n: similar to producemore, but sends n bytes instead of packets .
  • 20. Traffic Applications  Telnet 1. OTcl code for using Telnet in a simulation: 2. set telnet [new Application/Telnet] 3. $telnet attach-agent $tcp Parameters 1. start; start producing packets. 2. stop: stop producing packets. 3. attach-agent: attaches a Telnet object to an agent.
  • 21. Example-2 #Create a simulator object set ns [new Simulator] #Open the namtrace file set nf [open out.nam w] $ns namtrace-all $nf #Define a 'finish' procedure proc finish {} { global ns nf $ns flush-trace #Close the trace file close $nf #Execute nam on the trace file exec nam out.nam & exit 0 }
  • 22. Example-2 #Create two nodes set n0 [$ns node] set n1 [$ns node] #Create a duplex link between the nodes $ns duplex-link $n0 $n1 1Mb 10ms DropTail #Call the finish procedure after 5 seconds of simulation time $ns at 5.0 "finish" #Run the simulation $ns run
  • 23. Example-3 #Create a simulator object set ns [new Simulator] #Define different colors for data flows (for NAM) $ns color 0 Blue #Open the namtrace file set nf [open out.nam w] $ns namtrace-all $nf #Define a 'finish' procedure proc finish {} { global ns nf $ns flush-trace #Close the trace file close $nf #Execute nam on the trace file exec nam out.nam & exit 0 }
  • 24. Example-3 #Create two nodes set n0 [$ns node] set n1 [$ns node] #Create a duplex link between the nodes $ns duplex-link $n0 $n1 1Mb 10ms DropTail #Give node position (for NAM) $ns duplex-link-op $n0 $n1 orient right-down #Create a UDP agent and attach it to node n0 set udp0 [new Agent/UDP] $ns attach-agent $n0 $udp0 # Create a CBR traffic source and attach it to udp0 set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.005 $cbr0 attach-agent $udp0
  • 25. Example-3 #Create a Null agent (a traffic sink) and attach it to node n1 set null0 [new Agent/Null] $ns attach-agent $n1 $null0 #Connect the traffic source with the traffic sink $ns connect $udp0 $null0 #Schedule events for the CBR agent $ns at 0.5 "$cbr0 start" $ns at 4.5 "$cbr0 stop" #Call the finish procedure after 5 seconds of simulation time $ns at 5.0 "finish" #Run the simulation $ns run