0% found this document useful (0 votes)
29 views

CN LAB Programs Part-A

This part of the document describes simulation experiments to be performed using network simulation tools like NS2, NS3, OPNET or NetSim. The experiments include implementing simple point-to-point networks, applying TCP and UDP agents in a four node network, analyzing Ethernet LAN performance by varying error rates and data rates, observing congestion windows with multiple traffic sources, implementing an ESS in a wireless LAN, and demonstrating link state routing.

Uploaded by

bhavithathummala
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

CN LAB Programs Part-A

This part of the document describes simulation experiments to be performed using network simulation tools like NS2, NS3, OPNET or NetSim. The experiments include implementing simple point-to-point networks, applying TCP and UDP agents in a four node network, analyzing Ethernet LAN performance by varying error rates and data rates, observing congestion windows with multiple traffic sources, implementing an ESS in a wireless LAN, and demonstrating link state routing.

Uploaded by

bhavithathummala
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Computer Networks Laboratory (18ECL76)

Introduction to Computer Networks


 A computer network (or) data network is a digital telecommunications network which allows
nodes to share resources. In computer networks, computing devices exchange data with each other
using connections between nodes (data links.)

Node Configuration

 NS-2 is an event driven simulation tool, which is useful in studying the dynamic nature of
communication networks.
 Simulation of wired as well as wireless network functions and protocols (e.g., routing algorithms,
TCP, UDP) can be done using NS2.

Overview of NS2 Architecture

Dept. of ECE, BITM, Ballari Page 1


Computer Networks Laboratory (18ECL76)

 Toolkit Command Language [TCL] is a general purpose scripting language. It is an Interpreter,


which interprets the instruction line by line.
 Trace file is a text file that contains events logged during simulation (e.g., Packet drop, packet
reception etc.).
Trace file Analysis
When tracing into an output ascii file, the trace is organized into 12 fields as follows
1 2 3 4 5 6 7 8 9 10 11 12
From To Pkt Pkt Src Dst Seq Pkt
Event Time Flags Fid
node node type size addr addr num id

Ex: r 40.639943289 _1_ AGT--- 1569 tcp 1032 [a2 1 2 800] ------- [0:0 1:0 32 1] [35 0] 2 0
The meanings of the fields are:
1. The first field is the event type. It is given by one of five possible symbols r, +, −, d, h, which
correspond respectively to receive (at the output of the link), enqueued, dequeued, dropped and hop.
2. The second field gives the time at which the event occurs.
3. The third field gives the input node of the link at which the event occurs.
4. The fourth field gives the output node of the link at which the event occurs.
5. The fifth field gives the packet type (for example, CBR, or TCP). The type corresponds to the name
that we gave to those applications.
6. The sixth field gives the packet size.
7. Some flags follow
8. This is the flow id (fid) of IPv6 that a user can set for each flow at the input OTcl script. One can
further use this field for analysis purposes; it is also used when specifying stream color for the
NAM display.
9. This is the source address given in the form of “node port".
10. This is the destination address, given in the same form.
11. This is the network layer protocol’s packet sequence number. Even though UDP implementations in
a real network do not use sequence number, NS-2 keeps track of UDP packet sequence number for
analysis purposes.
12. The last field shows the unique id of the packet.
XGRAPH
The xgraph program draws a graph on an x-display given data read from either data file or
from standard input if no files are specified. It can display upto 64 independent data sets using
different colors and line styles for each set. It annotates the graph with a title, axis labels, grid lines or
tick marks, grid labels and a legend.
Syntax: Xgraph file-name.xg

Dept. of ECE, BITM, Ballari Page 2


Computer Networks Laboratory (18ECL76)

Trace file Analysis for wireless network


1 2 3 4 5 6 7 8 9 10 11 12
IP Src.
Global MAC
Node Pkt. Pkt. & TCP
Event Time MAC ---- Seq. Layer ----
Number Type Size Dst. Info
No. Info.
addr.

Ex: r 40.639943289 _1_ AGT--- 1569 tcp 1032 [a2 1 2 800] ------- [0:0 1:0 32 1] [35 0] 2 0
 The first field is a letter that can have the values r,s,f,D for “received", “sent", “forwarded" and
“dropped", respectively. It can also be M for giving a location or a movement indication, this is
described later.
 The second field is the time.
 The third field is the node number.
 The fourth field is MAC to indicate if the packet refers to a MAC layer; it is AGT to indicate the
transport layer (e.g., tcp) packet, or RTR if it refers to the routed packet. It can also be IFQ to
indicate events related to the interference priority queue (like drop of packets).
 After the dashes, the global sequence number of the packet (this is not the tcp sequence number).
 At the next field comes more information on the packet type (e.g., tcp, ack or udp).
 Then the packet size in bytes.
 Mac layer information.
o The first hexadecimal number, a2 (which equals 162 in decimal) specifies the expected time in
seconds to send this data packet over the wireless channel. The second number, 1, stands for the
MAC-id of the sending node, and the third, 2, is that of the receiving node. The fourth number,
800, specifies that the MAC type is ETHERTYPE_IP.
o The next numbers in the second square brackets refer to the IP source and destination addresses,
then the ttl (Time To Live) of the packet.
o The third brackets concern the tcp information: its sequence number and the acknowledgement
number.

Trace File analysis for Movement of node


Ex: M 10.00000 0 (5.00, 5.00, 0.00), (250.00, 250.00), 3.00
1 2 3 4 5 6
Event Time Node no. Original location Destination location Speed

 Where the first number is the time, the second is the node number, then comes the origin and
destination locations, and finally the speed is given.

 Network Animator [NAM] is an animation tool for viewing network simulation traces.

Dept. of ECE, BITM, Ballari Page 3


Computer Networks Laboratory (18ECL76)

Visualisation Using NAM


1. Orientation
o $ns duplex-link-op $n0 $n1 orient right-down
o $ns duplex-link-op $n1 $n2 orient right-up

2. Coloring the Node


o $n0 color red
o $n1 color blue

3. Shape of Node
o $n1 shape box (or instead of “box" one can use “hexagon" or
“circle")

4. Coloring the link


o $ns duplex-link-op $n0 $n2 color "green"

Keywords
 set : to assign a value to a variable

 unset : to remove the value assigned for variable

 proc : to define a procedure

 $ : used with the variable name

 # : comment

 Basic Unix commands

ls List your files


cd Change directory
mv filename1 filename2 Moves a file
cp filename1 filename2 Copies a file
chmod Change the mode
gedit filename.ext Create or edit the file
grep Find the particular data
awk Performs mathematical operations
gcc filename.ext Compile C/C++ program
./a.out Run the C Program

Dept. of ECE, BITM, Ballari Page 4


Computer Networks Laboratory (18ECL76)

PART-A

Dept. of ECE, BITM, Ballari Page 5


Computer Networks Laboratory (18ECL76)

PART-A:

Simulation experiments using NS2/ NS3/ OPNET/ NCTUNS/


NetSim/QualNet/ Packet Tracer or any other equivalent tool

1. Implement a point to point network with four nodes and duplex links between
them. Analyze the network performance by setting the queue size and varying the
bandwidth.

2. Implement a four node point to point network with links n0-n2, n1-n2 and n2-n3.
Apply TCP agent between n0-n3 and UDP between n1-n3. Apply relevant
applications over TCP and UDP agents changing the parameter and determine the
number of packets sent by TCP/UDP.

3. Implement Ethernet LAN using n (6-10) nodes. Compare the throughput by


changing the error rate and data rate.

4. Implement Ethernet LAN using n nodes and assign multiple traffic to the nodes
and obtain congestion window for different sources/ destinations.

5. Implement ESS with transmission nodes in Wireless LAN and obtain the
performance parameters.

6. Implementation of Link state routing algorithm

Dept. of ECE, BITM, Ballari Page 6


Computer Networks Laboratory (18ECL76)

1. Implement a point to point network with four nodes and duplex links
between them. Analyze the network performance by setting the queue size
and varying the bandwidth.

Description:
 A duplex data transmission means that data can be transmitted in both directions on a signal carrier
at the same time.
 Network performance refers to measures of service quality of a network.
 There are many different ways to measure the performance of a network, they are
o Bandwidth commonly measured in bits/second is the maximum rate that information can be transferred
o Throughput is the actual rate that information is transferred
o Latency the delay between the sender and the receiver decoding it, this is mainly a function of the signals
travel time, and processing time at any nodes the information traverses
o Jitter variation in packet delay at the receiver of the information
o Error rate the number of corrupted bits expressed as a percentage or fraction of the total sent
 CBR stands for constant bitrate, and is an encoding method that keeps the bitrate the same.

Design:

Source code:

set ns [new Simulator]

set f [open lab1.tr w]


$ns trace-all $f

set nf [open lab1.nam w]


$ns namtrace-all $nf

proc finish {} {
global f nf ns
$ns flush-trace
close $f
close $nf
exec nam lab1.nam &
exit 0

Dept. of ECE, BITM, Ballari Page 7


Computer Networks Laboratory (18ECL76)

}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

$ns duplex-link $n0 $n1 0.3Mb 10ms DropTail #vary bandwidth 0.3, 0.4, 0.5 0.7
$ns duplex-link $n1 $n2 0.3Mb 20ms DropTail #vary bandwidth 0.3, 0.4, 0.5 0.7
$ns duplex-link $n2 $n3 0.3Mb 20ms DropTail #vary bandwidth 0.3, 0.4, 0.5 0.7

$ns queue-limit $n0 $n1 20


$ns queue-limit $n1 $n2 20
$ns queue-limit $n2 $n3 20

set udp0 [new Agent/UDP]


$ns attach-agent $n0 $udp0

set cbr0 [new Application/Traffic/CBR]


$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005

set null0 [new Agent/Null]


$ns attach-agent $n3 $null0

$ns connect $udp0 $null0

$ns at 0.1 "$cbr0 start"


$ns at 4.5 "$cbr0 stop"
$ns at 5.0 "finish"
$ns run

Steps for execution:


 Open gedit editor & type program. Program name should have the extension “ .tcl ”
[root@localhost ~]# gedit lab1.tcl
 Save the program and quit.
 Run the simulation program
[root@localhost~]# ns lab1.tcl
 Here “ns” indicates network simulator. We get the topology shown in the network animator. Now
press the play button in the simulation window and the simulation will begins.

Dept. of ECE, BITM, Ballari Page 8


Computer Networks Laboratory (18ECL76)

Calculation of network performance

Units in bps (bits per second)


 For calculating total number of received packets size, execute the following command
[root@localhost~]# grep ^r lab1.tr | grep “2 3 cbr” |awk „{s+=$6}END{print s}‟
1 2 3 4 5 6 7 8 9 10 11 12
Event Time From To Pkt Pkt Flags Fid Src Dst Seq Pkt
Node Node Type Size Addr Addr Num Id

 For calculating the single packet transmission time,

 Write the value of network performance in observation sheet. Repeat the above step by changing the
bandwidth to [0.3Mb, 0.4Mb, 0.5Mb, 0.7Mb]

Sl. No. Bandwidth Network Performance

1. 0.3

2. 0.4

3. 0.5

4. 0.7

Dept. of ECE, BITM, Ballari Page 9


Computer Networks Laboratory (18ECL76)

2. Implement a four node point to point network with links n0-n2, n1-n2
and n2-n3. Apply TCP agent between n0-n3 and UDP between n1-n3.
Apply relevant applications over TCP and UDP agents changing the
parameter and determine the number of packets sent by TCP/UDP.
Description:
 The TCP and UDP protocols are two different protocols that handle data communications
between terminals in an IP network (the Internet).
 Transmission Control Protocol (TCP) is one of the main protocols in TCP/IP networks. Whereas
the IP protocol deals only with packets, TCP enables two hosts to establish a connection and
exchange streams of data. TCP guarantees delivery of data and also guarantees that packets will
be delivered in the same order in which they were sent.
 User Datagram Protocol (UDP) is part of the Internet Protocol suite used by programs running
on different computers on a network. UDP is used to send short messages called datagrams but
overall, it is an unreliable, connectionless protocol.
 File Transfer Protocol (FTP) is the commonly used protocol for exchanging files over
the Internet. FTP uses the Internet's TCP/IP protocols to enable data transfer. FTP promotes
sharing of files via remote computers with reliable and efficient data transfer

Design:

Dept. of ECE, BITM, Ballari Page 10


Computer Networks Laboratory (18ECL76)

Source code:

set ns [new Simulator]

set f [open lab2.tr w]


$ns trace-all $f

set nf [open lab2.nam w]


$ns namtrace-all $nf

$ns color 1 "Blue"


$ns color 2 "Red"

proc finish {} {
global ns f nf
$ns flush-trace
close $f
close $nf
exec nam lab2.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

$ns duplex-link $n0 $n2 2Mb 10ms DropTail


$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 2.75Mb 20ms DropTail

$ns queue-limit $n2 $n3 50

set tcp0 [new Agent/TCP]


$ns attach-agent $n0 $tcp0
$tcp0 set class_ 1

set ftp0 [new Application/FTP]


$ftp0 attach-agent $tcp0

set sink [new Agent/TCPSink]


$ns attach-agent $n3 $sink
$ns connect $tcp0 $sink

set udp0 [new Agent/UDP]


$ns attach-agent $n1 $udp0
$udp0 set class_ 2

set cbr0 [new Application/Traffic/CBR]

Dept. of ECE, BITM, Ballari Page 11


Computer Networks Laboratory (18ECL76)

$cbr0 attach-agent $udp0


$cbr0 set packetSize_ 1000
$cbr0 set interval_ 0.005

set null0 [new Agent/Null]


$ns attach-agent $n3 $null0
$ns connect $udp0 $null0

$ns at 0.1 "$cbr0 start"


$ns at 1.0 "$ftp0 start"
$ns at 4.0 "$ftp0 stop"
$ns at 4.5 "$cbr0 stop"

$ns at 5.0 "finish"


$ns run

Steps for execution:


 Open gedit editor & type program. Program name should have the extension “ .tcl ”
[root@localhost ~]# gedit lab2.tcl
 Save the program and quit.
 Run the simulation program
[root@localhost~]# ns lab2.tcl

Execute the following command to check


Packets Sent/ Received – TCP/UDP/ ACK
 To calculate the number of packets sent by TCP. 
[root@localhost~]# grep ^r lab2.tr | grep “2 3 tcp” -c

 To calculate the number of packets sent by UDP. 
[root@localhost~]# grep ^r lab2.tr | grep “2 3 cbr” –c

 To calculate the number of TCP-ACK received. 


[root@localhost~]# grep ^r lab2.tr | grep “3 2 ack” –c

Dept. of ECE, BITM, Ballari Page 12


Computer Networks Laboratory (18ECL76)

3. Implement Ethernet LAN using n (6-10) nodes. Compare the throughput


by changing the error rate and data rate.
Description:
 Ethernet is the name of the most commonly used LAN today.
 A LAN (Local Area Network) is a network of computers that covers a small area like a room, an
office, a building or a campus.
 Ethernet is a network protocol that controls how data is transmitted over a LAN. Technically it is
referred to as the IEEE 802.3 protocol.
 The protocol has evolved and improved over time and can now deliver at the speed of a gigabit per
second.

Design:

Source code:

set ns [new Simulator]

set trf [open lab3.tr w]


$ns trace-all $trf

set naf [open lab3.nam w]


$ns namtrace-all $naf

proc finish { } {
global nf ns tf
exec nam lab3.nam &
close $naf
close $trf
exit 0
}
set n0 [$ns node]
set n1 [$ns node

Dept. of ECE, BITM, Ballari Page 13


Computer Networks Laboratory (18ECL76)

set n2 [$ns node]


set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
set n6 [$ns node]

$n1 label "Source"


$n2 label "Error Node"
$n5 label "Destination"

$ns make-lan "$n0 $n1 $n3 $n2" 10Mb 10ms LL Queue/DropTail Mac/802_3
$ns make-lan "$n5 $n6 $n4" 10Mb 10ms LL Queue/DropTail Mac/802_3

$ns duplex-link $n2 $n6 30Mb 100ms DropTail


$ns duplex-link-op $n2 $n6 orient right

set udp0 [new Agent/UDP]


$ns attach-agent $n1 $udp0

set cbr0 [ new Application/Traffic/CBR]


$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 100
$cbr0 set interval_ 0.001
$udp0 set class_ 1
set null5 [new Agent/Null]
$ns attach-agent $n5 $null5

$ns connect $udp0 $null5

set err [new ErrorModel]


$ns lossmodel $err $n2 $n6
$err set rate_ 0.8 #vary error rate 0, 0.4, 0.8 and 1.0

$ns at 0.1 "$cbr0 start"


$ns at 4.0 "$cbr0 stop"

$ns at 6.0 "finish"


$ns run

Steps for execution:


 Open gedit editor & type program. Program name should have the extension “ .tcl ”
[root@localhost ~]# gedit lab3.tcl
 Save the program and quit.
 Run the simulation program
[root@localhost~]# ns lab3.tcl

Dept. of ECE, BITM, Ballari Page 14


Computer Networks Laboratory (18ECL76)

Calculation of Throughput

Units in bps (bits per second)


 For calculating total number of received packets size, execute the following command
[root@localhost~]# grep ^r lab3.tr | grep “2 6 cbr” | awk „{s+=$6}END{print s}‟
1 2 3 4 5 6 7 8 9 10 11 12
Event Time From To Pkt Pkt Flags Fid Src Dst Seq Pkt
Node Node Type Size Addr Addr Num Id

 For calculating the single packet transmission time,

 Write the value of throughput in observation sheet. Repeat the above step by changing the error rate
to the following line of the program

$err set rate_ 0.7 #vary error rate 0, 0.4, 0.8 and 1.0

Sl. No. Error rate Throughput

1. 0

2. 0.4

3. 0.8

4. 1.0

Dept. of ECE, BITM, Ballari Page 15


Computer Networks Laboratory (18ECL76)

4. Implement Ethernet LAN using n nodes and assign multiple traffic to the
nodes and obtain congestion window for different sources/
destinations.
Description:

Congestion means Blockage of traffic (or) Heavy traffic (or) Crowded traffic.
During “Multiple Traffic Transmission”, the congestion of traffic is occurred. Hence the
throughput is decreased substantially.
 Here Congestion window determines the number of bytes outstanding at a time. Its size varies
according to the network state.
 TCP follows the following steps to avoid the Congestion:
o Initially the window size increases rapidly
o When it reaches a large value, it grows slowly.
o When congestion is detected, the window size decreases drastically.
o This mechanism allows resolving congestion rapidly and yet using efficiently the network’s
bandwidth.
Design:

Source code:

set ns [new Simulator]

set f [open lab4.tr w]


$ns trace-all $f

set nf [open lab4.nam w]


$ns namtrace-all $nf

proc finish { } {
global ns f nf outFile1 outFile2

Dept. of ECE, BITM, Ballari Page 16


Computer Networks Laboratory (18ECL76)

$ns flush-trace
close $f
close $nf
exec nam lab4.nam &
exec xgraph Congestion1.xg Congestion2.xg -geometry 400x400 &
exit 0
}

set n0 [$ns node]


set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]

$n0 label "Src1"


$n4 label "Dst1"
$n1 label "Src2"
$n5 label "Dst2"

$ns make-lan "$n0 $n1 $n2 $n3 $n4 $n5 " 10Mb 30ms LL Queue/DropTail Mac/802_3
#vary bandwidth 1, 10

set tcp1 [new Agent/TCP]


$ns attach-agent $n0 $tcp1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
set sink1 [new Agent/TCPSink]
$ns attach-agent $n4 $sink1
$ftp1 set maxPkts_ 1000
$ns connect $tcp1 $sink1

set tcp2 [new Agent/TCP/Reno]


$ns attach-agent $n1 $tcp2
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2
set sink2 [new Agent/TCPSink]
$ns attach-agent $n5 $sink2
$ftp2 set maxPkts_ 1000
$ns connect $tcp2 $sink2

set outFile1 [open Congestion1.xg w]


set outFile2 [open Congestion2.xg w]
proc findWindowSize {tcpSource outFile} {
global ns
set now [$ns now]
set cWindSize [$tcpSource set cwnd_]
puts $outFile "$now $cWindSize"
$ns at [expr $now + 0.1] "findWindowSize $tcpSource $outFile"
}

Dept. of ECE, BITM, Ballari Page 17


Computer Networks Laboratory (18ECL76)

$ns at 0.0 "findWindowSize $tcp1 $outFile1"


$ns at 0.1 "findWindowSize $tcp2 $outFile2"
$ns at 0.3 "$ftp1 start"
$ns at 0.5 "$ftp2 start"
$ns at 50.0 "$ftp1 stop"
$ns at 50.0 "$ftp2 stop"
$ns at 50.0 "finish"
$ns run

Steps for execution:


 Open gedit editor & type program. Program name should have the extension “ .tcl ”
[root@localhost ~]# gedit lab4.tcl
 Save the program and quit.
 Run the simulation program
[root@localhost~]# ns lab4.tcl

Dept. of ECE, BITM, Ballari Page 18


Computer Networks Laboratory (18ECL76)

5. Implement ESS with transmission nodes in Wireless LAN and obtain the
performance parameters.

Description:

 Wireless LAN: It is a type of network where the data is not transmitted via cables but over the air
through the use of wireless transmitters and receivers. Most modern WLANs are based on IEEE
802.11 standards.
 Important Parameters related to wireless network:
o Stations [STA]: All components that can connect into a wireless medium in a network are referred to as
stations.
o Basic service set [BSS]: The basic service set (BSS) is a set of all stations that can communicate with each
other at PHY layer.
o Extended service set [ESS]: An extended service set (ESS) is a set of connected BSSs.
 List of basic parameters which need to be assigned (configured) for wireless node
o Channel type- Wireless Channel
o Radio Propagation type- TwoRayGround
o Routing Protocol- DSDV
o
o Network Interface type- WirelessPhy
(Physical Layer Type)
o Link layer type- LL Mac Type- 802_11
o Antenna Type- Omni Antenna
o Interface Queue Type- Queue/DropTail/PriQueue
o Queue Length- 50
o Number of mobile nodes- 2
o agentTrace ON
o routerTrace ON
 In wired nodes, connectivity is determined by wires (defined by duplex-link, simplex-link).
But, the connectivity of wireless nodes is determined by their distance from one another.
 Because wireless nodes can MOVE, their distances from one another change over time
 To keep track of their positions in the topology grid, we need to create a General Operations
Director (GOD) object.
 The God object stores:
 o the total number of mobile nodes
o a table of shortest number of hops required to reach from one node to another.

Design:

Dept. of ECE, BITM, Ballari Page 19


Computer Networks Laboratory (18ECL76)

Source code:

set ns [new Simulator]

set tf [open lab5.tr w]


$ns trace-all $tf

set topo [new Topography]


$topo load_flatgrid 1300 1300

set nf [open lab5.nam w]


$ns namtrace-all-wireless $nf 1300 1300

$ns node-config -adhocRouting DSDV \


-llType LL \
-macType Mac/802_11 \
-ifqType Queue/DropTail/PriQueue\
-channelType Channel/WirelessChannel \
-propType Propagation/TwoRayGround \
-antType Antenna/OmniAntenna \
-ifqLen 50 \
-phyType Phy/WirelessPhy \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON
create-god 3

set n0 [$ns node]


set n1 [$ns node]
set n2 [$ns node]

$n0 label "ESS"


$n1 label "mob1"
$n2 label "mob2"

$n0 set X_ 10
$n0 set Y_ 600
$n0 set Z_ 0
$n1 set X_ 80
$n1 set Y_ 600
$n1 set Z_ 0
$n2 set X_ 1200
$n2 set Y_ 600
$n2 set Z_ 0

$ns at 0.1 "$n0 setdest 10 600 15"


$ns at 0.1 "$n1 setdest 80 600 25"
$ns at 0.1 "$n2 setdest 1200 600 25"

Dept. of ECE, BITM, Ballari Page 20


Computer Networks Laboratory (18ECL76)

set tcp0 [new Agent/TCP]


$ns attach-agent $n0 $tcp0
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n1 $sink1
$ns connect $tcp0 $sink1

set tcp1 [new Agent/TCP]


$ns attach-agent $n0 $tcp1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
set sink2 [new Agent/TCPSink]
$ns attach-agent $n2 $sink2
$ns connect $tcp1 $sink2

$ns at 2 "$ftp0 start"


$ns at 15 "$ftp1 start"
$ns at 3 "$n1 setdest 1000 600 250"
$ns at 3 "$n2 setdest 80 600 250"

proc finish { } {
global ns nf tf
$ns flush-trace
exec nam lab5.nam &
close $tf
exit 0
}
$ns at 20 "finish"
$ns run

Steps for execution:


 Open gedit editor & type program. Program name should have the extension “ .tcl ”
[root@localhost ~]# gedit lab5.tcl
 Save the program and quit.
 Run the simulation program
[root@localhost~]# ns lab5.tcl

Dept. of ECE, BITM, Ballari Page 21


Computer Networks Laboratory (18ECL76)

 To calculate the throughput. Execute the following command.


  For calculating number of received packets
[root@localhost~]# grep ^r lab5.tr | grep “AGT” | grep “tcp” | awk „{s+=$8}END{print s}‟
  For calculating total time
[root@localhost~]# grep ^r lab5.tr | grep “AGT” | grep “tcp” | awk „{s+=$2}END{print s}‟

1 2 3 4 5 6 7 8 9 10 11 12
IP Src.
MAC
Node Global Pkt. Pkt. & TCP
Event Time MAC ---- Layer ----
Number Seq. No. Type Size Dst. Info
Info.
addr.

Throughput = (Total Packet received/ Total Time) (bps)

Dept. of ECE, BITM, Ballari Page 22


Computer Networks Laboratory (18ECL76)

6. Implementation of Link state routing algorithm

Description:

 A router is a networking device that forwards data packets between computer networks.
 When a data packet comes in on one of the lines, the router reads the network address
information in the packet to determine the ultimate destination.
 Routing is the process of selecting paths in a network along which to send network traffic.
 Goals of routing are correctness, simplicity, robustness, stability, fairness & optimality.
 Routing is performed for many kinds of network, including the telephone network, electronic
data network & transportation networks.
 Routing algorithms can be classified based on the following:
o Static or Dynamic routing
o Distributed or Centralized
o Single path or Multi-path
o Flat or Hierarchical
o Intra Domain or Inter Domain
o Link State or Distance vector

 The basic concept of link-state routing is that every node constructs a map of the connectivity to the
network, in the form of a graph, showing which nodes are connected to which other nodes.
 Each node then independently calculates the next best logical path from it to every possible
destination in the network. Each collection of best paths will then form each node's routing table.

Design:

Dept. of ECE, BITM, Ballari Page 23


Computer Networks Laboratory (18ECL76)

Source code:

set ns [new Simulator]

$ns rtproto LS

set nf [open lab6.nam w]


$ns namtrace-all $nf

proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam lab6.nam &
exit 0
}
for {set i 0} {$i < 7} {incr i} {
set n($i) [$ns node]
}
for {set i 0} {$i < 7} {incr i} {
$ns duplex-link $n($i) $n([expr ($i+1)%7]) 1Mb 10ms DropTail
}

set udp0 [new Agent/UDP]


$ns attach-agent $n(0) $udp0

set cbr0 [new Application/Traffic/CBR]


$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0

Set null0 [new Agent/Null]


$ns attach-agent $n(3) $null0

$ns connect $udp0 $null0

$ns at 0.5 "$cbr0 start"


$ns rtmodel-at 1.0 down $n(1) $n(2)
$ns rtmodel-at 2.0 up $n(1) $n(2)
$ns at 4.5 "$cbr0 stop"
$ns at 5.0 "finish"

$ns run
Steps for execution:
 Open gedit editor & type program. Program name should have the extension “ .tcl ”
[root@localhost ~]# gedit lab6.tcl
 Save the program and quit.
 Run the simulation program
[root@localhost~]# ns lab6.tcl
Dept. of ECE, BITM, Ballari Page 24

You might also like