100% found this document useful (1 vote)
665 views33 pages

Ns 2 Manual For Karthik

Download as doc, pdf, or txt
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 33

Dept.

of ECE DCN Lab Manual

MREM Page 1
Dept. of ECE DCN Lab Manual

1. Writing a TCL Script to create two nodes and links between


nodes
2. Writing a TCL Script to transmit data between nodes
3. Evaluate the performance of various LAN Topologies
4. Evaluate the performance of Drop Tail and RED queue
management schemes
5. Evaluate the performance of CBQ and FQ Scheduling
Mechanisms
6. Evaluate the performance of TCP and UDP Protocols
7. Evaluate the performance of TCP, New Reno and Vegas
8. Evaluate the performance of AODV and DSR routing protocols
9. Evaluate the performance of AODV and DSDV routing protocols
10.Evaluate the performance of IEEE 802.11 and IEEE 802.15.4
11.Evaluate the performance of IEEE 802.11 and SMAC
12.Capturing and Analysis of TCP and IP Packets
13.Simulation and Analysis of ICMP and IGMP Packets
14.Analyze the Protocols SCTP, ARP, NetBIOS, IPX VINES
15.Analysis of HTTP, DNS and DHCP Protocols

MREM Page 2
Dept. of ECE DCN Lab Manual

EX.NO WRITING A TCL SCRIPT TO CREATE TWO NODES DATE


1 AND LINKS BETWEEN NODES

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

exec nam –a out.nam &


exit 0
}
#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

RESULT:

MREM Page 4
Dept. of ECE DCN Lab Manual

EX.NO WRITING A TCL SCRIPT TO TRANSMIT DATA DATE


2 BETWEEN NODES

AIM:

To write a TCL script to transmit data 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

MREM Page 5
Dept. of ECE DCN Lab Manual

#Close the trace file


close $nf
#Execute nam on the trace file
exec nam –a out.nam &
exit 0
}
#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

RESULT:

MREM Page 6
Dept. of ECE DCN Lab Manual

EX.NO EVALUATE THE PERFORMANCE OF VARIOUS DATE


3 LAN TOPOLOGIES

AIM:

To evaluate the performance of various LAN topologies.

SOFTWARE REQUIRED:

S No. COMPONENT
1. Computer with Win XP or 7
2. NS2

PROCEDURE:

1. Start the program.


2. Get the frame size from the user
3. Create the frame based on the user request.
4. Send frames to server from the client side.
5. If your frames reach the server it will send ACK signal to client otherwise it will send NACK
signal to client.
6. Stop the program

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

OUTPUT: STAR TOPOLOGY:

MREM Page 10
Dept. of ECE DCN Lab Manual

#Create Lan between the nodes


set lan0 [$ns newLan "$n0 $n1 $n2 $n3 $n4" 0.5Mb 40ms LL Queue/DropTail MAC/Csma/Cd 
Channel]

#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

OUTPUT: BUS TOPOLOGY:

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

OUTPUT: RING TOPOLOGY:

MREM Page 14
Dept. of ECE DCN Lab Manual

RESULT:

Thus the implementation of network topologies using Network Simulator was


performed.

MREM Page 15
Dept. of ECE DCN Lab Manual

EX.NO EVALUATE THE PERFORMANCE OF DROP TAIL AND DATE


4 RED QUEUE MANAGEMENT SCHEMES

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:

1. Start the program.


2. Get the frame size from the user
3. Create the frame based on the user request.
4. Send frames to server from the client side.
5. If your frames reach the server it will send ACK signal to client otherwise it will send NACK
signal to client.

MREM Page 16
Dept. of ECE DCN Lab Manual

6. Stop the program

PROGRAM:

RESULT:

EX.NO EVALUATE THE PERFORMANCE OF CBQ AND FQ DATE


5 SCHEDULING MECHANISMS

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:

1. Start the program.


2. Get the frame size from the user
3. Create the frame based on the user request.
4. Send frames to server from the client side.
5. If your frames reach the server it will send ACK signal to client otherwise it will send NACK
signal to client.
6. Stop the program

MREM Page 17
Dept. of ECE DCN Lab Manual

PROGRAM:

RESULT:

EX.NO EVALUATE THE PERFORMANCE OF TCP AND DATE


6 UDP PROTOCOLS

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:

1. Start the program.


2. Get the frame size from the user
3. Create the frame based on the user request.
4. Send frames to server from the client side.
5. If your frames reach the server it will send ACK signal to client otherwise it will send NACK
signal to client.
6. Stop the program

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]

set nr [open thro.tr w]


$ns trace-all $nr
set nf [open thro.nam w]

$ns namtrace-all $nf


proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exec nam thro.nam &
exit 0
}
#to create 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]

# 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

# Sending node is 0 with agent as Reno Agent


set tcp1 [new Agent/TCP/Reno]
$ns attach-agent $n0 $tcp1

# receiving (sink) node is n4


set sink1 [new Agent/TCPSink]
$ns attach-agent $n4 $sink1

# establish the traffic between the source and sink

MREM Page 19
Dept. of ECE DCN Lab Manual

$ns connect $tcp1 $sink1

# Setup a FTP traffic generator on "tcp1"


set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ftp1 set type_ FTP

# start/stop the traffic


$ns at 0.1 "$ftp1 start"
$ns at 75.0 "$ftp1 stop"
$ns at 80.0 "$ftp1 start"
$ns at 95.0 "$ftp1 stop"
# Set simulation end time
$ns at 100.0 "finish"
# procedure to plot the congestion window
proc plotWindow {tcpSource outfile} {
global ns
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
# the data is recorded in a file called congestion.xg (this can be plotted # using xgraph or
gnuplot. this example uses xgraph to plot the cwnd_
puts $outfile "$now $cwnd"
$ns at [expr $now+0.1] "plotWindow $tcpSource $outfile"
}

set outfile [open "congestion.xg" w]


$ns at 0.0 "plotWindow $tcp1 $outfile"
proc finish {} {
exec xgraph congestion.xg -bg "white" -fg "red" -zg "black" -lw "2" -t "Congestion
Window" -x "Simulation Time (Seconds)" -y "Congestion Window" -geometry 600x600 &
exit 0
}
# Run simulation
$ns run

CONGESTION WINDOW – OUTPUT:

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

EX.NO EVALUATE THE PERFORMANCE OF TCP, NEW RENO DATE


7 AND VEGAS

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

1. Start the program.


2. Get the frame size from the user
3. Create the frame based on the user request.
4. Send frames to server from the client side.
5. If your frames reach the server it will send ACK signal to client otherwise it will send NACK
signal to client.
6. Stop the program

PROGRAM:

RESULT:

EX.NO EVALUATE THE PERFORMANCE OF AODV AND DATE


8 DSR ROUTING PROTOCOLS

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

1. Start the program.


2. Get the frame size from the user
3. Create the frame based on the user request.
4. Send frames to server from the client side.
5. If your frames reach the server it will send ACK signal to client otherwise it will send NACK
signal to client.
6. Stop the program

PROGRAM:

RESULT:

EX.NO EVALUATE THE PERFORMANCE OF AODV AND DATE


9 DSDV ROUTING PROTOCOLS

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

1. Start the program.


2. Get the frame size from the user
3. Create the frame based on the user request.
4. Send frames to server from the client side.
5. If your frames reach the server it will send ACK signal to client otherwise it will send NACK
signal to client.
6. Stop the program

PROGRAM:

RESULT:

EX.NO EVALUATE THE PERFORMANCE OF IEEE 802.11 AND DATE


10 IEEE 802.15.4

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

1. Start the program.


2. Get the frame size from the user
3. Create the frame based on the user request.
4. Send frames to server from the client side.
5. If your frames reach the server it will send ACK signal to client otherwise it will send NACK
signal to client.
6. Stop the program

PROGRAM:

RESULT:

EX.NO EVALUATE THE PERFORMANCE OF IEEE 802.11 AND DATE


11 SMAC

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

1. Start the program.


2. Get the frame size from the user
3. Create the frame based on the user request.
4. Send frames to server from the client side.
5. If your frames reach the server it will send ACK signal to client otherwise it will send NACK
signal to client.
6. Stop the program

PROGRAM:

RESULT:

EX.NO CAPTURING AND ANALYSIS OF TCP AND IP DATE


12 PACKETS

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

1. Start the program.


2. Get the frame size from the user
3. Create the frame based on the user request.
4. Send frames to server from the client side.
5. If your frames reach the server it will send ACK signal to client otherwise it will send NACK
signal to client.
6. Stop the program

PROGRAM:

RESULT:

EX.NO SIMULATION AND ANALYSIS OF ICMP AND DATE


13 IGMP PACKETS

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:

1. Start the program.

MREM Page 28
Dept. of ECE DCN Lab Manual

2. Get the frame size from the user


3. Create the frame based on the user request.
4. Send frames to server from the client side.
5. If your frames reach the server it will send ACK signal to client otherwise it will send NACK
signal to client.
6. Stop the program

PROGRAM:

RESULT:

EX.NO ANALYZE THE PROTOCOLS SCTP, ARP, DATE


14 NETBIOS, IPX VINES

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:

1. Start the program.


2. Get the frame size from the user

MREM Page 29
Dept. of ECE DCN Lab Manual

3. Create the frame based on the user request.


4. Send frames to server from the client side.
5. If your frames reach the server it will send ACK signal to client otherwise it will send NACK
signal to client.
6. Stop the program

PROGRAM:

RESULT:

EX.NO ANALYSIS OF HTTP, DNS AND DHCP DATE


15 PROTOCOLS

AIM:
To analyze HTTP, DNS and DHCP Protocols.

SOFTWARE REQUIRED:

S No. COMPONENT
9. Computer with Win XP or 7
10. NS2

PROCEDURE:

1. Start the program.


2. Get the frame size from the user

MREM Page 30
Dept. of ECE DCN Lab Manual

3. Create the frame based on the user request.


4. Send frames to server from the client side.
5. If your frames reach the server it will send ACK signal to client otherwise it will send NACK
signal to client.
6. Stop the program

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

#######################

#Set number of TCP connections


set tcp_num 50

#Making two network nodes


set n(1) [$ns node]
set n(2) [$ns node]

#Making edge nodes


for {set i 1} {$i <= $tcp_num} {incr i} {
set s($i) [$ns node]
set r($i) [$ns node]
}

#Creating the network link


$ns duplex-link $n(1) $n(2) 20Mb 20ms DropTail

#Creating edge links


for {set i 1} {$i <= $tcp_num} {incr i} {
$ns duplex-link $s($i) $n(1) 20Mb 5ms DropTail
$ns duplex-link $n(2) $r($i) 20Mb 5ms DropTail
}

#########################
# 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)

$tcp($i) set ecn_ true


$tcp($i) set fid_ $i
$tcp($i) set window_ 20
$tcp($i) set packetSize_ 1000
}

#Setup FTP Applications


for {set i 1} {$i <= $tcp_num} {incr i} {
set ftp($i) [new Application/FTP]
$ftp($i) attach-agent $tcp($i)
$ftp($i) set type_ FTP
}

##########################
# 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

You might also like