Ns 2 Manual For Karthik
Ns 2 Manual For Karthik
Ns 2 Manual For Karthik
MREM Page 1
Dept. of ECE DCN Lab Manual
MREM Page 2
Dept. of ECE DCN Lab Manual
AIM:
To write a TCL script to create two nodes and Links between Nodes.
SOFTWARE REQUIRED:
S No. COMPONENT
1. Computer with Win XP or 7
2. TCL Script
PROCEDURE:
1. Open TCL scripting language in the system and start a new file.
2. Perform simulations and get necessary outputs
PROGRAM:
#Create a simulator object
set ns [new Simulator]
#Open the nam trace 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
MREM Page 3
Dept. of ECE DCN Lab Manual
RESULT:
MREM Page 4
Dept. of ECE DCN Lab Manual
AIM:
SOFTWARE REQUIRED:
S No. COMPONENT
1. Computer with Win XP or 7
2. TCL Script
PROCEDURE:
1. Open TCL scripting language in the system and start a new file.
2. Perform simulations and get necessary outputs
PROGRAM:
MREM Page 5
Dept. of ECE DCN Lab Manual
RESULT:
MREM Page 6
Dept. of ECE DCN Lab Manual
AIM:
SOFTWARE REQUIRED:
S No. COMPONENT
1. Computer with Win XP or 7
2. NS2
PROCEDURE:
PROGRAM:
STAR TOPOLOGY:
#Create a simulator object
set ns [new Simulator]
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
MREM Page 7
Dept. of ECE DCN Lab Manual
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Executenam on the trace file
exec nam out.nam &
exit0
}
#Create four 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
# Create a CBR traffic source and attach it to tcp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.01
$cbr0 attach-agent $tcp0
MREM Page 8
Dept. of ECE DCN Lab Manual
#Schedule events for the CBR agents
$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
BUS TOPOLOGY:
#Create a simulator object
set ns [new Simulator]
#Open the nam trace 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
#Executenam on the trace file
exec nam out.nam &
exit 0
}
#Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
MREM Page 9
Dept. of ECE DCN Lab Manual
MREM Page 10
Dept. of ECE DCN Lab Manual
#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
# Create a CBR traffic source and attach it to tcp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.01
$cbr0 attach-agent $tcp0
#Schedule events for the CBR agents
$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
RING TOPOLOGY:
#Create a simulator object
set ns [new Simulator]
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
MREM Page 11
Dept. of ECE DCN Lab Manual
proc finish {} { global ns nf
MREM Page 12
Dept. of ECE DCN Lab Manual
$ns flush-trace
#Close the trace file
close $nf
#Executenam on the trace file
exec nam out.nam &
exit0
}
#Create four 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]
#Create links between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 10ms DropTail
$ns duplex-link $n3 $n4 1Mb 10ms DropTail
$ns duplex-link $n4 $n5 1Mb 10ms DropTail
$ns duplex-link $n5 $n0 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]
MREM Page 13
Dept. of ECE DCN Lab Manual
$ns attach-agent $n3 $sink0
#Connect the traffic sources with the traffic sink
$ns connect $tcp0 $sink0
# Create a CBR traffic source and attach it to tcp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.01
$cbr0 attach-agent $tcp0
#Schedule events for the CBR agents
$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
MREM Page 14
Dept. of ECE DCN Lab Manual
RESULT:
MREM Page 15
Dept. of ECE DCN Lab Manual
AIM:
To evaluate the performance of Drop Tail and RED queue management schemes.
SOFTWARE REQUIRED:
S No. COMPONENT
1. Computer with Win XP or 7
2. NS2
PROCEDURE:
MREM Page 16
Dept. of ECE DCN Lab Manual
PROGRAM:
RESULT:
AIM:
To evaluate the performance of CBQ and FQ Scheduling Mechanisms.
SOFTWARE REQUIRED:
S No. COMPONENT
1. Computer with Win XP or 7
2. NS2
PROCEDURE:
MREM Page 17
Dept. of ECE DCN Lab Manual
PROGRAM:
RESULT:
AIM:
To evaluate the performance of TCP and UDP Protocols.
SOFTWARE REQUIRED:
S No. COMPONENT
1. Computer with Win XP or 7
2. NS2
PROCEDURE:
MREM Page 18
Dept. of ECE DCN Lab Manual
PROGRAM:
PROGRAM: (TCP VS UDP CONGESTION CONTROL USING NS2 – Program in .tcl):
#create simulator
set ns [new Simulator]
# to create the link between the nodes with bandwidth, delay and queue
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 0.3Mb 200ms DropTail
$ns duplex-link $n3 $n4 0.5Mb 40ms DropTail
$ns duplex-link $n3 $n5 0.5Mb 30ms DropTail
MREM Page 19
Dept. of ECE DCN Lab Manual
MREM Page 20
Dept. of ECE DCN Lab Manual
RESULT:
Thus the congestion control algorithm was studied and simulated using Network
simulator.
MREM Page 21
Dept. of ECE DCN Lab Manual
AIM:
To evaluate the performance of TCP, New Reno and Vegas.
SOFTWARE REQUIRED:
S No. COMPONENT
1. Computer with Win XP or 7
2. NS2
PROCEDURE:
MREM Page 22
Dept. of ECE DCN Lab Manual
PROGRAM:
RESULT:
AIM:
To evaluate the performance of AODV and DSR routing protocols
SOFTWARE REQUIRED:
S No. COMPONENT
1. Computer with Win XP or 7
2. NS2
PROCEDURE:
MREM Page 23
Dept. of ECE DCN Lab Manual
PROGRAM:
RESULT:
AIM:
To evaluate the performance of AODV and DSDV routing protocols.
SOFTWARE REQUIRED:
S No. COMPONENT
1. Computer with Win XP or 7
2. NS2
PROCEDURE:
MREM Page 24
Dept. of ECE DCN Lab Manual
PROGRAM:
RESULT:
AIM:
To evaluate the performance of IEEE 802.11 and IEEE 802.15.4.
SOFTWARE REQUIRED:
S No. COMPONENT
1. Computer with Win XP or 7
2. NS2
PROCEDURE:
MREM Page 25
Dept. of ECE DCN Lab Manual
PROGRAM:
RESULT:
AIM:
To evaluate the performance of IEEE 802.11 and SMAC.
SOFTWARE REQUIRED:
S No. COMPONENT
1. Computer with Win XP or 7
2. NS2
PROCEDURE:
MREM Page 26
Dept. of ECE DCN Lab Manual
PROGRAM:
RESULT:
AIM:
To capture and analysis of TCP and IP Packets
SOFTWARE REQUIRED:
S No. COMPONENT
3. Computer with Win XP or 7
4. NS2
PROCEDURE:
MREM Page 27
Dept. of ECE DCN Lab Manual
PROGRAM:
RESULT:
AIM:
To simulate and analysis of ICMP and IGMP Packets.
SOFTWARE REQUIRED:
S No. COMPONENT
5. Computer with Win XP or 7
6. NS2
PROCEDURE:
MREM Page 28
Dept. of ECE DCN Lab Manual
PROGRAM:
RESULT:
AIM:
To analyze the protocols SCTP, ARP, NetBIOS, IPX VINES.
SOFTWARE REQUIRED:
S No. COMPONENT
7. Computer with Win XP or 7
8. NS2
PROCEDURE:
MREM Page 29
Dept. of ECE DCN Lab Manual
PROGRAM:
RESULT:
AIM:
To analyze HTTP, DNS and DHCP Protocols.
SOFTWARE REQUIRED:
S No. COMPONENT
9. Computer with Win XP or 7
10. NS2
PROCEDURE:
MREM Page 30
Dept. of ECE DCN Lab Manual
PROGRAM:
RESULT:
16. Writing a TCL Script to create two nodes and links between nodes
17. Writing a TCL Script to transmit data between nodes
18. Evaluate the performance of various LAN Topologies
19. Evaluate the performance of Drop Tail and RED queue management schemes
20. Evaluate the performance of CBQ and FQ Scheduling Mechanisms
21. Evaluate the performance of TCP and UDP Protocols
22. Evaluate the performance of TCP, New Reno and Vegas
23. Evaluate the performance of AODV and DSR routing protocols
24. Evaluate the performance of AODV and DSDV routing protocols
25. Evaluate the performance of IEEE 802.11 and IEEE 802.15.4
26. Evaluate the performance of IEEE 802.11 and SMAC
27. Capturing and Analysis of TCP and IP Packets
28. Simulation and Analysis of ICMP and IGMP Packets
29. Analyze the Protocols SCTP, ARP, NetBIOS, IPX VINES
30. Analysis of HTTP, DNS and DHCP Protocols
#######################
# Creat Network Topology #
MREM Page 31
Dept. of ECE DCN Lab Manual
#######################
#########################
# Setup FTP-TCP connections #
#########################
#Setup TCP
for {set i 1} {$i <= $tcp_num} {incr i} {
set tcp($i) [new Agent/TCP/Reno]
set sink($i) [new Agent/TCPSink]
$ns attach-agent $s($i) $tcp($i)
$ns attach-agent $r($i) $sink($i)
$ns connect $tcp($i) $sink($i)
##########################
# Start FTP Applications #
##########################
for {set i 1} {$i <= $tcp_num} {incr i} {
$ns at 0 "$ftp($i) start"
$ns at 80 "$ftp($i) stop"
}
MREM Page 32
Dept. of ECE DCN Lab Manual
$ns run
MREM Page 33