DCN Practical
DCN Practical
THEORY
Network simulator 2, or Ns-2, is an open-source, discrete event-
driven network simulation program that is frequently used in
academic and research contexts to examine computer network
behaviour. It offers a versatile and potent framework for modelling
different network topologies and protocols. ns-2, which was
created as a component of the virtual internetwork testbed (VINT)
project, has proven crucial in assessing network applications and
protocols.
2. Event-Driven Architecture
- Utilizes discrete-event simulation, where events like packet
transmission and reception are scheduled and processed in sequence.
3. Open Source:
- Available for free under the GNU General Public License (GPL).
- Extensible, enabling researchers to modify existing protocols or create
new ones.
4. Comprehensive Libraries
- Provides a broad range of pre-configured models for various OSI
layers, including physical, MAC, routing, and transport layers.
Architecture Of NS -2
NS-2’s architecture is comprised of three key components:
2. Simulation Engine
- Written in C++, it performs the core functions, such as event
scheduling, packet processing, and managing interactions between
network layers.
Applications Of NS-2
1. Protocol Development and Testing
- Allows for simulating new routing, transport, and MAC protocols
before deploying them in real-world scenarios.
2. Performance Evaluation
- Assesses the performance of existing protocols across various
network conditions and topologies.
3. Education
- Used as an educational tool to teach networking concepts,
algorithms, and protocols.
4. Research
- Widely used in academic and industrial research to study and
analyze network behavior.
Advantages Of NS-2
1. Comprehensive Protocol Support
- Supports a wide variety of protocols, enabling detailed simulation of
different network behaviors.
2. Extensibility
- Customizable and modifiable to meet specific research
requirements, allowing users to add or modify features as needed.
3. Visualization Support
- The graphical representation of simulations enhances
understanding and aids in debugging.
Disadvantages Of NS-2
1. Complexity
- Has a steep learning curve due to the need to use both TCL for
simulation scripting and C++ for core modifications.
2. Performance Issues
- May struggle to scale efficiently when running very large
simulations.
3. Outdated Support
- Development has slowed, with a shift towards newer tools like ns-3
which may result in limited updates and community focus on ns-2.
Setting Up NS-2
1. System Requirements
- ns-2 is compatible with Linux-based systems.
- Can be installed on Windows through virtualization or using
compatibility layers like Cygwin.
3. Running a Simulation
- Create a TCL script to define the network topology, nodes,
protocols, and events.
- Run the script with the `ns` command.
- Analyze the generated trace files or use NAM for visualization of the
simulation results.
Experiment-2
Code:
#Creation Of Simulator Object
set ns [new simulator]
#Creation Of
Nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
$n0 label "source node"
$n1 label "router"
$n2 label "destination node"
Protocol)
#TCP Agent
#Color Setup
$ns color 1 "red"
$tcp set class_ 1
Output :
Experiment-3
Aim Write A TCL Script To Transmit Data
:
Between Nodes.
Code:
#creation of simulator
object set ns [new
simulator]
#creation of output files
set tracefile [open exp2.tr w]
$ns trace-all $tracefile
set namfile [open exp2.nam w]
$ns namtrace-all $namfile
#creation of
nodes set n0 [$ns
node] set n1 [$ns
node] set n2 [$ns
node]
$n0 label "source node"
$n1 label "router"
$n2 label "destination node"
#creation of links between nodes with droptail
queue
$ns duplex-link $n0 $n1 100kb 2ms droptail
$ns duplex-link $n1 $n2 2mb 5ms droptail
protocol) #udpagent
#color setup
$ns color 1 "blue"
$cbr set class_ 1
#start traffic
# at 1s i want to start teraffic of cbr
$ns at 0.2 "$cbr start"
#Creation Of
Nodes set n0 [$ns
node] set n1 [$ns
node] set n2 [$ns
node] set n3 [$ns
node]
$n0 label "tcp source node"
$n1 label "udp source node"
$n2 label "router"
$n3 label "destination"
#Creation Of Links Between Nodes With Droptail Queue
$ns duplex-link $n0 $n2 100kb 2ms droptail
$ns duplex-link $n1 $n2 2mb 2ms droptail
$ns duplex-link $n2 $n3 5mb 2ms droptail
#Udp Agent
#Creation Of UDP Agent At Node N1 And Null Agent At
Node N3
set udp [new agent/udp]
set null [new agent/null]
#Attaching Of UDP Agent To Node No And Null To Node N3
$ns attach-agent $n1 $udp
$ns attach-agent $n3 $null
#Virtual Connections Between Two Agents
$ns connect $udp $null
$ns connect $udp $null
#Color Setup
$ns color 1 "green"
$ns color 2 "red"
$tcp set class_ 1
$cbr set class_ 2
Output:
Experiment-5
#Creation Of
Nodes set n0
[$ns node] set n1
[$ns node] set n2
[$ns node] set n3
[$ns node] set n4
[$ns node] set n5
[$ns node]
#Creation Of Links Between Nodes With Droptail
Queue
$ns duplex-link $n0 $n1 5mb 2ms droptail
$ns duplex-link $n1 $n2 10mb 5ms droptail
$ns duplex-link $n1 $n4 3mb 10ms droptail
$ns duplex-link $n4 $n3 100mb 2ms droptail
$ns duplex-link $n4 $n5 4mb 10ms droptail
#Creation Of Agents:Udp,Tcp
#TCPAgent
#CBR Application
set cbr [new application/traffic/cbr]
#Application CBR Is Attached To Agent Udp
$cbr attach-agent $udp
#Ftp Application
proc finish {} {
global ns tracefile namfile
$ns flush-
trace close
$tracefile
close $namfile
exec nam
exp4.nam & exit 0
}
$ns run
Output:
Experiment-6
Aim Write a TCL Script To Create Scenario
: And
Study The Performance Of Star Topology
Through Simulation.
Code:
set ns [new
simulator] set nf
[open ex1.nam w]
#create six
nodes set n0 [$ns
node] set n1 [$ns
node] set n2 [$ns
node] set n3 [$ns
node] set n4 [$ns
node] set n5 [$ns
node]
#change the shape of center node in a star topology
$n0 shape square
#create links between the nodes
$ns duplex-link $n0 $n1 1mb 10ms droptail
$ns duplex-link $n0 $n2 1mb 10ms droptail
$ns duplex-link $n0 $n3 1mb 10ms droptail
$ns duplex-link $n0 $n4 1mb 10ms droptail
$ns duplex-link $n0 $n5 1mb 10ms droptail
#create a tcp agent and attach it to node n0
set tcp0 [new agent/tcp]
$tcp0 set class_ 1
$ns attach-agent $n1 $tcp0
#create a tcp sink agent (a traffic sink) for tcp and attach
it to node n3
set sink0 [new agent/tcpsink]
$ns attach-agent $n3 $sink0
#connect the traffic sources with the traffic sink
$ns connect $tcp0 $sink0
Output:
Experiment-7
Aim Write A TCL Script To Simulate And To
:
Study About Go Back N Protocol And
Selective Repeat Using NS-2.
Output:
Program For Selective Repeat:
Output:
G B PANT DSEU OKHLA-I CAMPUS
DATA COMMUNICATION
AND NETWORK
Lab File