Computer Networks [BCS502]
Department of Computer Science Engineering – ( Data Science)
Introduction to Network Simulation
Network simulation is an important tool in developing, testing and evaluating network protocols.
Simulation can be used without the target physical hardware, making it economical and practical
for almost any scale of network topology and setup.
It is possible to simulate a link of any bandwidth and delay, even if such a link is currently
impossible in the real world.
With simulation, it is possible to set each simulated node to use any desired software.
Results are also easier to obtain and analyse, because extracting information from important points
in the simulated network is done by simply parsing the generated trace files.
Types of Simulators
 MIT's NETSIM
 NIST
 CPSIM
 INSANE
 NEST
 REAL
 NS
 OPNET
 NCTUns
Major Features of NS2:
Supports Unix like systems and Windows
It is written in C++ and TCL scripting language
OTCL in NS2 adds object oriented concept to TCL.
Open source simulator, which is object oriented in nature
Protocol Support in NS2:
Network Layer [Routing agent]
Transport layer[Traffic agent-TCP and UDP]
Logic link Control layer[IEEE 802.2, AR]
Interface Queue[Priority queue, FIFO queue, Drop tail queue]
Major Components:
NAM[Network Animator]:
Used to view the Network simulation traces
Supports packet transmission, topology, data inspection etc
During the execution of simulation, it supports animation
Trace File:
Used to store the coverage information or overall network information
To generate a trace file, we have to first create a trace file using OTCL Script.
X-Graph:
Used to visualize the resulting graph
AWK Script:

Tool Command Language (Tcl):
Scripting language used to create configuration files in NS2.
Used to build the network topology and structure
It is easy to code and integrate with other languages like OTCL and C++
Overall Script format contains[Simulator object, trace file, finish procedure, network setup(node, link, agent,
parameter), event scheduling(run and stop simulation)]
Steps in writing a Script in NS2:
Create an event scheduler
Turn on tracing
Create the network and setup routing
Insert Error and create transport connection
Create traffic
Transmit application level data
Basic Architecture of NS2
NS 2 programming
Basically NS 2 programming contains the following steps
1. Create the event scheduler
2.Turn on tracing
Two types of trace
i. generic trace - for use with xgraph, and other things
ii. nam trace - for use with visualization
3. Creating network
i. Computing setup routing
ii. Creating transport connection- Agents
iii. Creating traffic- Applications
4. Monitoring
i. Visualization using nam
Tcl scripting
 Tcl is a general purpose scripting language. [Interpreter]
 Tcl runs on most of the platforms such as Unix, Windows, and Mac.
 The strength of Tcl is its simplicity.
 It is not necessary to declare a data type for variable prior to the usage.
 In order to have output files with data on the simulation (trace files) or files used for visualization (nam files),
we need to create the files using “open” command
#Open the Trace file #Open the NAM trace file
set tracefile1 [open out.tr w]
$ns trace-all $tracefile1
set namfile [open out.nam w]
$ns namtrace-all $namfile
Structure of Trace Files
The trace is organized in 12 fields as follows in fig shown below:
Event Time From Node To Node PKT Type PKT Size Flags Fid Src Addr Dest Addr SeqNum Pkt id
 The first field is the event type. It is given by one of four possible symbols
r  receive (at the output of the link),
+  enqueued
-  dequeued
d  dropped.
 The second field gives the time at which the event occurs.
 Gives the input node of the link at which the event occurs.
 Gives the output node of the link at which the event occurs.
 Gives the packet type (eg CBR or TCP)
 Gives the packet size
 Some flags
This is the flow id (fid) of IPv6 that a user can set for each flow at the input,it is also used when
specifying stream color for the NAM display.
This is the source address given in the form of “node.port”.
This is the destination address, given in the same form.
This is the network layer protocol’s packet sequence number. Even though UDP implementations in a
real network do not use sequence number, ns keeps track of UDP packet sequence number for analysis
purposes
The last field shows the Unique id of the packet.
Ns2 Simulation:
Define the Simulation Object
Connect the object with each other through links
Start the Source applications.
Packets are created and transmitted through the network
Exit the simulation at fixed time
Create an Event Scheduler:
 Set ns [ new simulator ]//create a new simulator
$ns at < time > < event >//Schedules the event
$ns run// Start the scheduler
Tracing in NS2:
General syntax: $ns traceall[open filename.tr w]
$ns namtrace-all // open the nam file
To create Network topology:
• Link creation between two nodes:
• First create nodes using
• set n1 [ $ns node ]
• set n2 [ $ns node ]
• Now, create link using the command:
• $ns < link_type(Simplex/duplex)> $n1 $n2 <bandwidth> <delay> <queue-type>
To create transport connection and generate traffic:
• Traffic generation[FTP, telnet]
• set ftp new Application / FTP ]
• set telnet [new Application / Telnet ]
Steps to Run a TCL File:
Install NS2 and set your path
After NS2 Installation, go to $prompt and run ns filename[Ex. ns tcp.tcl]
After this, .nam and .tr files will be created automatically in the same folder [home folder]- here NAM-
Network animator and .tr-trace files have to be initialized in TCL files using commands.
To see the demo in GUI, run nam filename.nam [ex. Tcp.nam]
.tr files are used to check the actual performance of the Network [i.e throughput, packet drop etc]
Parse the .tr files into Xgraph [for graph generation]
Unix Commands
1) grep: The grep filter searches a file for a particular pattern of characters, and displays all lines that
contain that pattern.
Syntax:
grep [options] pattern [files]
Options Description
-c : This prints only a count of the lines that match a pattern
Matching the lines that start with a string :
The ^ regular expression pattern specifies the start of a line. This can be used in grep to match the lines
which start with the given string or pattern.
Example: $ grep "^unix" geekfile.txt
2) exec command in Linux is used to execute a command from the bash itself. This
command does not create a new process it just replaces the bash with the command to
be executed.
Example:$ exec ls
PART-A
Program 1: Implement three nodes point – to – point network with
duplex links between them. Set the queue size, vary the
bandwidth and find the number of packets dropped.
set ns [new Simulator]
set ntrace [open prog1.tr w]
$ns trace-all $ntrace
set namfile [open prog1.nam w]
$ns namtrace-all $namfile
proc Finish {} {
global ns ntrace namfile
$ns flush-trace
close $ntrace
close $namfile
exec nam prog1.nam &
puts "The number of packet drops is"
exec grep -c "^d" prog1.tr &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
$ns duplex-link $n0 $n1 10Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns queue-limit $n0 $n1 10
$ns queue-limit $n1 $n2 05
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink0 [new Agent/TCPSink]
$ns attach-agent $n2 $sink0
$ns connect $tcp0 $sink0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set type_ CBR
$cbr0 set packetSize_ 100
$cbr0 set rate_ 1Mb
$cbr0 set random_ false
$cbr0 attach-agent $tcp0
$tcp0 set class_ 1
$ns at 0.0 "$cbr0 start"
$ns at 5.0 "Finish"
$ns run
OUTPUT
n1
n0
n2
tcp0
cbr0
sink0
10Mb, 10ms
1
M
b
,
1
0
m
s

More Related Content

PPT
Tut hemant ns2
PPTX
Network Simulator overview and its working
PPT
PPTX
Working with NS2
PPT
Ns 2 Network Simulator An Introduction
PDF
cscn1819.pdf
PDF
study-of-network-simulator.pdf
PDF
Introduction to ns2
Tut hemant ns2
Network Simulator overview and its working
Working with NS2
Ns 2 Network Simulator An Introduction
cscn1819.pdf
study-of-network-simulator.pdf
Introduction to ns2

Similar to NErwork Lab Simulation Introduction.pptx (20)

PPT
Network Simulator Tutorial
PPT
NS2-tutorial.ppt
PDF
18CSL51 - Network Lab Manual.pdf
PDF
Network simulator 2 a simulation tool for linux
PDF
Ns2pre
PPTX
Introduction to ns3
PPT
Introduction to NS2 - Cont..
PPTX
Plenzogan technology
PPT
Ns network simulator
PDF
Final Report(Routing_Misbehavior)
PDF
Cs757 ns2-tutorial-exercise
PPT
Venkat ns2
PPS
Ns2 introduction 2
PPTX
PDF
NS2-tutorial.pdf
PPT
Network simulator 2
PPT
Network simulator 2
PPTX
Network simulator 2
PPT
Ns fundamentals 1
Network Simulator Tutorial
NS2-tutorial.ppt
18CSL51 - Network Lab Manual.pdf
Network simulator 2 a simulation tool for linux
Ns2pre
Introduction to ns3
Introduction to NS2 - Cont..
Plenzogan technology
Ns network simulator
Final Report(Routing_Misbehavior)
Cs757 ns2-tutorial-exercise
Venkat ns2
Ns2 introduction 2
NS2-tutorial.pdf
Network simulator 2
Network simulator 2
Network simulator 2
Ns fundamentals 1
Ad

More from AmbikaVenkatesh4 (18)

PPTX
Module-3Key Management and Distribution.pptx
PPTX
Module-2Other Public-Key Cryptosystems.pptx
PPTX
Module-2 Public-Key Cryptography and RSA.pptx
PPTX
Block Ciphers and the data encryption standard.pptx
PPTX
moudule-1classical Encyption Techniques.pptx
PPTX
Business Intelligence Module 3_Datawarehousing.pptx
PPTX
big data analytics (BAD601) Module-5.pptx
PPTX
UHV Module-4 Exploring_Harmony_Assignment.pptx
PPTX
Universal Human Values (BUHK408)Module-4.pptx
PPTX
Aptitude Training Module-2_Data Suffciency.pptx
PPTX
Big Data Analytics (BAD601) Module-4.pptx
PPTX
Big data analytics(BAD601) module-1 ppt
PPTX
UHV(BUHK408) Module-value education and self exploration
PPTX
Os Module 4_Virtual Memory Management.pptx
PPTX
Operating Systems Module 4_Memory Management.pptx
PPTX
Introduction to Big data analytics subject
PPTX
Big data Analytics(BAD601) -module-1 ppt
PPTX
Network Lab simulation program ping.pptx
Module-3Key Management and Distribution.pptx
Module-2Other Public-Key Cryptosystems.pptx
Module-2 Public-Key Cryptography and RSA.pptx
Block Ciphers and the data encryption standard.pptx
moudule-1classical Encyption Techniques.pptx
Business Intelligence Module 3_Datawarehousing.pptx
big data analytics (BAD601) Module-5.pptx
UHV Module-4 Exploring_Harmony_Assignment.pptx
Universal Human Values (BUHK408)Module-4.pptx
Aptitude Training Module-2_Data Suffciency.pptx
Big Data Analytics (BAD601) Module-4.pptx
Big data analytics(BAD601) module-1 ppt
UHV(BUHK408) Module-value education and self exploration
Os Module 4_Virtual Memory Management.pptx
Operating Systems Module 4_Memory Management.pptx
Introduction to Big data analytics subject
Big data Analytics(BAD601) -module-1 ppt
Network Lab simulation program ping.pptx
Ad

Recently uploaded (20)

PPTX
Integrated Management of Neonatal and Childhood Illnesses (IMNCI) – Unit IV |...
PPTX
PLASMA AND ITS CONSTITUENTS 123.pptx
PPTX
Reproductive system-Human anatomy and physiology
PDF
African Communication Research: A review
PDF
Everyday Spelling and Grammar by Kathi Wyldeck
PPT
hemostasis and its significance, physiology
PPTX
Climate Change and Its Global Impact.pptx
PPTX
principlesofmanagementsem1slides-131211060335-phpapp01 (1).ppt
PPTX
Neurology of Systemic disease all systems
PDF
fundamentals-of-heat-and-mass-transfer-6th-edition_incropera.pdf
PDF
0520_Scheme_of_Work_(for_examination_from_2021).pdf
PDF
Laparoscopic Dissection Techniques at WLH
PPTX
Power Point PR B.Inggris 12 Ed. 2019.pptx
PPTX
pharmaceutics-1unit-1-221214121936-550b56aa.pptx
PPTX
ACFE CERTIFICATION TRAINING ON LAW.pptx
PDF
faiz-khans about Radiotherapy Physics-02.pdf
PDF
The TKT Course. Modules 1, 2, 3.for self study
PPTX
Thinking Routines and Learning Engagements.pptx
PPTX
Designing Adaptive Learning Paths in Virtual Learning Environments
PDF
Health aspects of bilberry: A review on its general benefits
Integrated Management of Neonatal and Childhood Illnesses (IMNCI) – Unit IV |...
PLASMA AND ITS CONSTITUENTS 123.pptx
Reproductive system-Human anatomy and physiology
African Communication Research: A review
Everyday Spelling and Grammar by Kathi Wyldeck
hemostasis and its significance, physiology
Climate Change and Its Global Impact.pptx
principlesofmanagementsem1slides-131211060335-phpapp01 (1).ppt
Neurology of Systemic disease all systems
fundamentals-of-heat-and-mass-transfer-6th-edition_incropera.pdf
0520_Scheme_of_Work_(for_examination_from_2021).pdf
Laparoscopic Dissection Techniques at WLH
Power Point PR B.Inggris 12 Ed. 2019.pptx
pharmaceutics-1unit-1-221214121936-550b56aa.pptx
ACFE CERTIFICATION TRAINING ON LAW.pptx
faiz-khans about Radiotherapy Physics-02.pdf
The TKT Course. Modules 1, 2, 3.for self study
Thinking Routines and Learning Engagements.pptx
Designing Adaptive Learning Paths in Virtual Learning Environments
Health aspects of bilberry: A review on its general benefits

NErwork Lab Simulation Introduction.pptx

  • 1. Computer Networks [BCS502] Department of Computer Science Engineering – ( Data Science)
  • 2. Introduction to Network Simulation Network simulation is an important tool in developing, testing and evaluating network protocols. Simulation can be used without the target physical hardware, making it economical and practical for almost any scale of network topology and setup. It is possible to simulate a link of any bandwidth and delay, even if such a link is currently impossible in the real world. With simulation, it is possible to set each simulated node to use any desired software. Results are also easier to obtain and analyse, because extracting information from important points in the simulated network is done by simply parsing the generated trace files.
  • 3. Types of Simulators  MIT's NETSIM  NIST  CPSIM  INSANE  NEST  REAL  NS  OPNET  NCTUns
  • 4. Major Features of NS2: Supports Unix like systems and Windows It is written in C++ and TCL scripting language OTCL in NS2 adds object oriented concept to TCL. Open source simulator, which is object oriented in nature Protocol Support in NS2: Network Layer [Routing agent] Transport layer[Traffic agent-TCP and UDP] Logic link Control layer[IEEE 802.2, AR] Interface Queue[Priority queue, FIFO queue, Drop tail queue]
  • 5. Major Components: NAM[Network Animator]: Used to view the Network simulation traces Supports packet transmission, topology, data inspection etc During the execution of simulation, it supports animation Trace File: Used to store the coverage information or overall network information To generate a trace file, we have to first create a trace file using OTCL Script. X-Graph: Used to visualize the resulting graph AWK Script: 
  • 6. Tool Command Language (Tcl): Scripting language used to create configuration files in NS2. Used to build the network topology and structure It is easy to code and integrate with other languages like OTCL and C++ Overall Script format contains[Simulator object, trace file, finish procedure, network setup(node, link, agent, parameter), event scheduling(run and stop simulation)] Steps in writing a Script in NS2: Create an event scheduler Turn on tracing Create the network and setup routing Insert Error and create transport connection Create traffic Transmit application level data
  • 8. NS 2 programming Basically NS 2 programming contains the following steps 1. Create the event scheduler 2.Turn on tracing Two types of trace i. generic trace - for use with xgraph, and other things ii. nam trace - for use with visualization 3. Creating network i. Computing setup routing ii. Creating transport connection- Agents iii. Creating traffic- Applications 4. Monitoring i. Visualization using nam
  • 9. Tcl scripting  Tcl is a general purpose scripting language. [Interpreter]  Tcl runs on most of the platforms such as Unix, Windows, and Mac.  The strength of Tcl is its simplicity.  It is not necessary to declare a data type for variable prior to the usage.  In order to have output files with data on the simulation (trace files) or files used for visualization (nam files), we need to create the files using “open” command #Open the Trace file #Open the NAM trace file set tracefile1 [open out.tr w] $ns trace-all $tracefile1 set namfile [open out.nam w] $ns namtrace-all $namfile
  • 10. Structure of Trace Files The trace is organized in 12 fields as follows in fig shown below: Event Time From Node To Node PKT Type PKT Size Flags Fid Src Addr Dest Addr SeqNum Pkt id  The first field is the event type. It is given by one of four possible symbols r  receive (at the output of the link), +  enqueued -  dequeued d  dropped.  The second field gives the time at which the event occurs.  Gives the input node of the link at which the event occurs.  Gives the output node of the link at which the event occurs.  Gives the packet type (eg CBR or TCP)
  • 11.  Gives the packet size  Some flags This is the flow id (fid) of IPv6 that a user can set for each flow at the input,it is also used when specifying stream color for the NAM display. This is the source address given in the form of “node.port”. This is the destination address, given in the same form. This is the network layer protocol’s packet sequence number. Even though UDP implementations in a real network do not use sequence number, ns keeps track of UDP packet sequence number for analysis purposes The last field shows the Unique id of the packet.
  • 12. Ns2 Simulation: Define the Simulation Object Connect the object with each other through links Start the Source applications. Packets are created and transmitted through the network Exit the simulation at fixed time
  • 13. Create an Event Scheduler:  Set ns [ new simulator ]//create a new simulator $ns at < time > < event >//Schedules the event $ns run// Start the scheduler Tracing in NS2: General syntax: $ns traceall[open filename.tr w] $ns namtrace-all // open the nam file
  • 14. To create Network topology: • Link creation between two nodes: • First create nodes using • set n1 [ $ns node ] • set n2 [ $ns node ] • Now, create link using the command: • $ns < link_type(Simplex/duplex)> $n1 $n2 <bandwidth> <delay> <queue-type> To create transport connection and generate traffic: • Traffic generation[FTP, telnet] • set ftp new Application / FTP ] • set telnet [new Application / Telnet ]
  • 15. Steps to Run a TCL File: Install NS2 and set your path After NS2 Installation, go to $prompt and run ns filename[Ex. ns tcp.tcl] After this, .nam and .tr files will be created automatically in the same folder [home folder]- here NAM- Network animator and .tr-trace files have to be initialized in TCL files using commands. To see the demo in GUI, run nam filename.nam [ex. Tcp.nam] .tr files are used to check the actual performance of the Network [i.e throughput, packet drop etc] Parse the .tr files into Xgraph [for graph generation]
  • 16. Unix Commands 1) grep: The grep filter searches a file for a particular pattern of characters, and displays all lines that contain that pattern. Syntax: grep [options] pattern [files] Options Description -c : This prints only a count of the lines that match a pattern Matching the lines that start with a string : The ^ regular expression pattern specifies the start of a line. This can be used in grep to match the lines which start with the given string or pattern. Example: $ grep "^unix" geekfile.txt
  • 17. 2) exec command in Linux is used to execute a command from the bash itself. This command does not create a new process it just replaces the bash with the command to be executed. Example:$ exec ls
  • 18. PART-A Program 1: Implement three nodes point – to – point network with duplex links between them. Set the queue size, vary the bandwidth and find the number of packets dropped.
  • 19. set ns [new Simulator] set ntrace [open prog1.tr w] $ns trace-all $ntrace set namfile [open prog1.nam w] $ns namtrace-all $namfile proc Finish {} { global ns ntrace namfile $ns flush-trace close $ntrace close $namfile exec nam prog1.nam & puts "The number of packet drops is" exec grep -c "^d" prog1.tr & exit 0 } set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] $ns duplex-link $n0 $n1 10Mb 10ms DropTail $ns duplex-link $n1 $n2 1Mb 10ms DropTail $ns queue-limit $n0 $n1 10 $ns queue-limit $n1 $n2 05
  • 20. set tcp0 [new Agent/TCP] $ns attach-agent $n0 $tcp0 set sink0 [new Agent/TCPSink] $ns attach-agent $n2 $sink0 $ns connect $tcp0 $sink0 set cbr0 [new Application/Traffic/CBR] $cbr0 set type_ CBR $cbr0 set packetSize_ 100 $cbr0 set rate_ 1Mb $cbr0 set random_ false $cbr0 attach-agent $tcp0 $tcp0 set class_ 1 $ns at 0.0 "$cbr0 start" $ns at 5.0 "Finish" $ns run