CCN Lab Manual-2022 Cycle 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

Computer Communication Networks Lab – 18TEL66 2021-22

PART A

NETWORK SIMULATOR NS2

NS (Network Simulator) is a name for a series of discrete event network simulators,


specifically NS-1, NS-2, NS-3 and NS-4. All are discrete-event computer network simulators,
primarily used in research and teaching.

NS2 stands for Network Simulator Version 2. It is an open-source event-driven simulator


designed specifically for research in computer communication networks.

FEATURES OF NS2

1. It is a discrete event simulator for networking research.


2. It provides substantial support to simulate bunch of protocols like TCP, FTP, UDP, https
and DSR.
3. It simulates wired and wireless network.
4. It is primarily UNIX based.
5. Uses TCL as its scripting language.
6. OTCL : Object oriented support
7. TCLCL : C++ and otcl linkage
8. Discrete event scheduler
The general process of creating a simulation can be divided into several steps:
Topology definition: To ease the creation of basic facilities and define their
interrelationships, ns-3 has a system of containers and helpers that facilitates this
process.

Model development: Models are added to simulation (for example, UDP, IPv4,
point-to-point devices and links, applications); most of the time this is done using
helpers.

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 1


Computer Communication Networks Lab – 18TEL66 2021-22

Node and link configuration: models set their default values (for example, the size
of packets sent by an application or MTU of a point-to-point link); most of the time
this is done using the attribute system.

Execution: Simulation facilities generate events, data requested by the user is


logged.

Performance analysis: After the simulation is finished and data is available as a


time-stamped event trace. This data can then be statistically analysed with tools
like R to draw conclusions.

Graphical Visualization: Raw or processed data collected in a simulation can be


graphed using tools like Gnuplot, matplotlib or XGRAPH.

NSG2

It takes a lot of time to write TCL scripts for ns2, NSG2 is a tool for creating TCL scripts
automatically. It is a free software.

NS2 Scenarios Generator 2(NSG2) is a JAVA based ns2 scenarios generator. Since NSG2 is
written by JAVA language, you can run NSG on any platform. NSG2 is capable of generating
both wired and wireless TCL scripts for ns2. Some major functions of NSG2 are listed below:
1. Creating wired and wireless nodes
2. Creating connection between nodes
3. Creating links (Duplex-Link and Simplex-Link)
4. Creating agents (TCP and UDP)
5. Creating applications (CBR and FTP)
6. Node movement
.
General procedure

Create a folder in root's home / ccnuser1's home


Oen a terminal and type cd ns2
Type ‘ls‘ and check for list of copied files and type the command “ java –jar
NSG2.jar”
Go the scenario and select “ New wired /wireless scenario”

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 2


Computer Communication Networks Lab – 18TEL66 2021-22

Click on the nodes and place the nodes for the required scenario and connect them
with link between nodes by choosing any one of them below mentioned according to
the requirement.
Duplex link - > TCP
Simplex link - > UDP
Connect the agent to the nodes suitably [TCP & UDP]
Fix the application for the agent as shown
TCP - > application -> FTP
UDP - > application -> CBR
Connect the agent between source node and destination node.
Click on parameters in the toolbar & rename trace file and nam file and save it.
Click on TCL and generate TCL script for the scenario
Save the TCL file with same name as trace and nam file with .tcl extension
Go the terminal and type command : “ns filename.tcl”
Run trace file and check the movement of packet from source to destination.
To measure the performance of the experiment we create AWK file.
To create AWK file goto menu->accessories-> gedit.
Type the awk code and save in the same location.
To execute awk file goto terminal and type command awk –f filename.awk
filename.tr

Analyzing the trace file

Trace file format for wired scenario


Event Time Where To Pkt Pkt Flags Flow Src Dest Seq Pkt id
from node type size id addr addr no
node

Trace file Event

Event Meaning
+ Added to queue
- Removed from queue
r Received at node
d Dropped

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 3


Computer Communication Networks Lab – 18TEL66 2021-22

Trace file format for wireless scenario

Action Time Where Layer Flags Seq Type Size flags


from no
node

1. Action s – sent
r – Rxd
d - dropped
2. Time : when the action happened
3. From node : The node where action happened
4. Layer
AGT -> Application layer ( Application)
RTR – Network Layer (Routing)
LL – Link layer ( ARP is done here)
IFQ – Outgoing packet queue(between link & MAC layer)
MAC –
Phy – Physical
5. Flags :
6. Seq no : the sequence number of the packet
7. Type : Packet type
Cbr -> CBR data stream pkt
DSR -> DSR routing pkt
RTS -> RTS pkt generated by MAC 802.11
APR -> Link layer ARP Packet
8. Size : The size of pkt at current layer, when pkt goes dwon, size
[ a b c d] : a -> pkt duration in MAC layer header
b -> The MAC address of destination
c -> The MAC address of source
d -> The MAC type of the pkt body
9. Flags :

Source node Port no of Port no ip ip of next hop


I/P Dest node i/p Header ttl (0 means node 0 or
(-1 Means broadcast) broadcast)

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 4


Computer Communication Networks Lab – 18TEL66 2021-22

Experiment 1

Simulate 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.

AIM: To simulate 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.

Fig 1. Four-node Point to Point Network with TCP Link

Fig 2. Four-node Point to Point Network with UDP Link

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 5


Computer Communication Networks Lab – 18TEL66 2021-22

Procedure:
1. Create the required network and save the tcl file in your folder
2. Open a terminal and type cd (your folder name)
3. To run the tcl file type ns (tcl file name )
4. Type gedit (filename.awk) to create awk file for your experiment
5. Type the awk code and save it
6. To run the awk script type awk -f (awk file name) (trace file name)
7. Note down the packets received and dropped
8. Change the Bandwidth in the tcl file and repeat steps from 3 - 7

TCL FILE
#===================================
# Simulation parameters setup
#===================================
set val (stop) 5.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Open the NS trace file


set tracefile [open out.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open out.nam w]
$ns namtrace-all $namfile

#===================================
# Nodes Definition
#===================================
#Create 4 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n1 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n1 50
$ns duplex-link $n1 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n1 $n2 50
$ns duplex-link $n2 $n3 100.0Mb 10ms DropTail # change BW and verify performance
$ns queue-limit $n2 $n3 50

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 6


Computer Communication Networks Lab – 18TEL66 2021-22

#Give node position (for NAM)


$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n1 $n2 orient right
$ns duplex-link-op $n2 $n3 orient right

#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n3 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 7


Computer Communication Networks Lab – 18TEL66 2021-22

TRACE FILE

AWK SCRIPT:
BEGIN{
sent=0
recd=0
drop=0
}
{
if($1=="+"&&$3=="1"&&$5=="tcp"&&$6=="1540")
{
sent++;
}
if($1=="r"&&$4=="3"&&$5=="tcp"&&$6=="1540")
{
recd++;
}
if($1=="d"&&$4=="3"&&$5=="tcp"&&$6=="1540")
{
drop++;
}
}
END{
printf("\n total number of data packets sent from Node 0: %d\n", sent);
printf("\n total number of data packets received at Node 3: %d\n", recd);
printf("\n total number of packets dropped at Node 3: %d\n", drop);
}
Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 8
Computer Communication Networks Lab – 18TEL66 2021-22

NETWORK ANIMATION (LAB1.nam):

RESULTS

N0 – N1 N1-N2 N2-N3 No of No of
Bandwidth Bandwidth Bandwidth Packets Packets
Sent Received
100 Mb 100 Mb 100 Mb
100 Mb 100 Mb 10 Mb
100 Mb 100 Mb 5 Mb

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 9


Computer Communication Networks Lab – 18TEL66 2021-22

Experiment 2

Build a Four-node Point to Point Network with links n0-n2, n1-n2 and n2-n3. Connect a
TCP link between n0-n3 and UDP link between n1-n3.
(i) Define BERs for Links. Compare TCP and UDP Protocols when errors occur.
(ii) Modify to Simulate a Link Failure between the Host and the Target Node. Compare
TCP and UDP Protocols when the Target Node is not accessible.
(i) Define BERs for Links. Compare TCP and UDP Protocols when errors occur.

AIM: To simulate a Four-node Point to Point Network with links n0-n2, n1-n2 and n2-n3.
And define BERs for Links. Compare TCP and UDP Protocols when errors occur.

Fig 3. Four-node Point to Point Network with TCP & UDP Links
Procedure :
01. Create the required network and save the TCL file in your folder
02.Open a terminal and type cd (your folder name)
03. run the tcl file type ns (tcl file name )
04. Type gedit (filename.awk) to create awk file for your experiment
05. Type the awk code and save it
06. run the awk script
07. Note down the packets sent, received and dropped
08. Repeat the experiment by changing the bit error rate in the tcl file.
09. Create a link failure and re simulate it.
Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 10
Computer Communication Networks Lab – 18TEL66 2021-22

TCL FILE
set val(stop) 10.0 ;# time of simulation end
#Create a ns simulator
set ns [new Simulator]

#Open the NS trace file


set tracefile [open out.tr w]
$ns trace-all $tracefile
#Open the NAM trace file
set namfile [open out.nam w]
$ns namtrace-all $namfile

#Create 4 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

#Createlinks between nodes


$ns duplex-link $n0 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n2 50
$ns duplex-link $n1 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n1 $n2 50
$ns duplex-link $n2 $n3 100.0Mb 10ms DropTail
$ns queue-limit $n2 $n3 50

#Give node position (for NAM)


$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right

#set err [new ErrorModel]


#$ns lossmodel $err $n2 $n3
#$err set rate_ 0.1 // change the error rate

#Setup a TCP connection


set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink2 [new Agent/TCPSink]
$ns attach-agent $n3 $sink2
$ns connect $tcp0 $sink2
$tcp0 set packetSize_ 1500
#Setup a UDP connection
set udp1 [new Agent/UDP]
$ns attach-agent $n1 $udp1
set null3 [new Agent/Null]
$ns attach-agent $n3 $null3
$ns connect $udp1 $null3
$udp1 set packetSize_ 1500
#Setup a FTP Application over TCP connection
Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 11
Computer Communication Networks Lab – 18TEL66 2021-22

set ftp0 [new Application/FTP]


$ftp0 attach-agent $tcp0
$ns at 0.0 "$ftp0 start"
$ns at 1.0 "$ftp0 stop"
#Setup a CBR Application over UDP connection
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
$cbr1 set packetSize_ 1000
$cbr1 set rate_ 1.0Mb
$cbr1 set random_ null
$ns at 1.0 "$cbr1 start"
$ns at 2.0 "$cbr1 stop"

#Define a 'finish' procedure


proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

Network Animation:

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 12


Computer Communication Networks Lab – 18TEL66 2021-22

(ii) Modify to Simulate a Link Failure between the Host and the Target Node. Compare
TCP and UDP Protocols when the Target Node is not accessible.

AIM: To simulate a Four-node Point to Point Network with links n0-n2, n1-n2 and n2-n3. and
modify to Simulate a Link Failure between the Host and the Target Node. Compare TCP and
UDP Protocols when the Target Node is not accessible.

set val(stop) 10.0 ;# time of simulation end


#Create a ns simulator
set ns [new Simulator]

#Open the NS trace file


set tracefile [open out.tr w]
$ns trace-all $tracefile
#Open the NAM trace file
set namfile [open out.nam w]
$ns namtrace-all $namfile
#Create 4 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

#Createlinks between nodes


$ns duplex-link $n0 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n2 50
$ns duplex-link $n1 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n1 $n2 50
$ns duplex-link $n2 $n3 100.0Mb 10ms DropTail
$ns queue-limit $n2 $n3 50
#Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right

#set err [new ErrorModel]


#$ns lossmodel $err $n2 $n3
#$err set rate_ 0.1

#Setup a TCP connection


set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink2 [new Agent/TCPSink]
$ns attach-agent $n3 $sink2
$ns connect $tcp0 $sink2
$tcp0 set packetSize_ 1500
#Setup a UDP connection
set udp1 [new Agent/UDP]
$ns attach-agent $n1 $udp1
set null3 [new Agent/Null]
$ns attach-agent $n3 $null3
$ns connect $udp1 $null3

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 13


Computer Communication Networks Lab – 18TEL66 2021-22

$udp1 set packetSize_ 1500


#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 20.0 "$ftp0 stop"
#Setup a CBR Application over UDP connection
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
$cbr1 set packetSize_ 1000
$cbr1 set rate_ 1.0Mb
$cbr1 set random_ null
$ns at 25.0 "$cbr1 start"
$ns at 48.0 "$cbr1 stop"

$ns at 0.5 "$ns detach-agent $n0 $tcp0 ; $ns detach-agent $n3 $sink2"
$ns at 1.5 "$ns detach-agent $n0 $udp1 ; $ns detach-agent $n3 $null3"

#Define a 'finish' procedure


proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

Awk Script
BEGIN{
a=0;b=0;c=0;
e=0;f=0;g=0;
}
{
if($1=="+"&&$3=="0"&&$5=="tcp"&&$6=="1540")
a++;
if($1=="r"&&$4=="3"&&$5=="tcp"&&$6=="1540")
b++
if($1=="d"&&$3=="2"&&$5=="tcp"&&$6=="1540")
c++
if($1=="+"&&$3=="1"&&$5=="cbr"&&$6=="1000")
e++;
if($1=="r"&&$4=="3"&&$5=="cbr"&&$6=="1000")
f++;
if($1=="d"&&$3=="2"&&$5=="cbr"&&$6=="1000")
g++;
}
Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 14
Computer Communication Networks Lab – 18TEL66 2021-22

END{
printf("\n total number of packets sent by tcp: %d\n", a++);
printf("\n total number of packets received by tcp: %d\n", b++);
printf("\n total number of packets dropped by tcp: %d\n", c++);
printf("\n total number of packets sent by udp: %d\n", e++);
printf("\n total number of packets received by udp: %d\n", f++);
printf("\n total number of packets dropped by udp: %d\n", g++);

Network Animation:

Results for TCP Link

Error No of TCP No of TCP No of TCP No of TCP No of TCP Packets


Rate Packets Packets Packets Packets Received Dropped
Sent Received Dropped After Link failure After Link failure
0
0.1
0.3

Results for UDP Link

Error No of UDP No of UDP No of UDP No of UDP No of UDP


Rate Packets Packets Packets Packets Received Packets Dropped
Sent Received Dropped After Link failure After Link failure
0
0.1
0.3

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 15


Computer Communication Networks Lab – 18TEL66 2021-22

Experiment 3

Simulate a Network with a Star Topology (One Router and several Hosts). Declare
Applications (TCP or UDP) to send Packets from Hosts and to receive (on one Host).
Test the Bandwidth and the Delay, when Buffers are of infinite Capacities and Buffers
are of Limited Capacities.

Fig 4. Five node Point to Point Network in Star Topology

Procedure :
01. Create the required network and save the TCL file in your folder
02.Open a terminal and type cd (your folder name)
03. run the tcl file type ns (tcl file name )
04. Type gedit (filename.awk) to create awk file for your experiment
05. Type the awk code and save it
06. run the awk script
07. Note down the packets sent, received and dropped
08. Repeat the experiment by changing the buffer size in the tcl file.

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 16


Computer Communication Networks Lab – 18TEL66 2021-22

TCL File :
#===================================
# Simulation parameters setup
#===================================
set val(stop) 10.0 ;# time of simulation end

#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

#Open the NS trace file


set tracefile [open out.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open out.nam w]
$ns namtrace-all $namfile
#===================================
# Nodes Definition
#===================================
#Create 5 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]

#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n2 50
$ns duplex-link $n1 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n1 $n2 50
$ns duplex-link $n3 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n3 $n2 50
$ns duplex-link $n4 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n4 $n2 50 # change the que limit to 1 or 1.5 and resimulate

#Give node position (for NAM)


$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient left-down
$ns duplex-link-op $n3 $n2 orient right-up
$ns duplex-link-op $n4 $n2 orient left-up
#===================================
# Agents Definition
Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 17
Computer Communication Networks Lab – 18TEL66 2021-22

#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink4 [new Agent/TCPSink]
$ns attach-agent $n4 $sink4
$ns connect $tcp0 $sink4
$tcp0 set packetSize_ 1500

#Setup a TCP connection


set tcp1 [new Agent/TCP]
$ns attach-agent $n1 $tcp1
set sink3 [new Agent/TCPSink]
$ns attach-agent $n4 $sink3
$ns connect $tcp1 $sink3
$tcp1 set packetSize_ 1500

#Setup a TCP connection


set tcp2 [new Agent/TCP]
$ns attach-agent $n3 $tcp2
set sink5 [new Agent/TCPSink]
$ns attach-agent $n4 $sink5
$ns connect $tcp2 $sink5
$tcp2 set packetSize_ 1500

#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 2.0 "$ftp0 stop"

#Setup a FTP Application over TCP connection


set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ns at 1.0 "$ftp1 start"
$ns at 2.0 "$ftp1 stop"

#Setup a FTP Application over TCP connection


set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2
$ns at 1.0 "$ftp2 start"
$ns at 2.0 "$ftp2 stop"

#===================================
# Termination
#===================================
#Define a 'finish' procedure

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 18


Computer Communication Networks Lab – 18TEL66 2021-22

proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

NAM File :

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 19


Computer Communication Networks Lab – 18TEL66 2021-22

AWK script:

BEGIN{
recd=0
drop=0
}
{
if($1=="r"&&$4=="4"&&$5=="tcp"&&$6=="1540")
{
recd++;
}
if($1=="d"&&$3=="

3"&&$5=="tcp"&&$6=="1540")
{
drop++;
}
}
END{
printf("\n total number of data packets received at Node 3: %d\n", recd++);
printf("\n total number of packets dropped at Node 3: %d\n", drop++);
}

Results:

Buffer Packets Packets


Size Received dropped
50
5
2

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 20


Computer Communication Networks Lab – 18TEL66 2021-22

Experiment 4

Implementation of Link State Routing Algorithm.

Theory :
Link state routing is a technique in which each router shares the knowledge of its
neighborhood with every other router in the internetwork.

The three keys to understand the Link State Routing algorithm:

o Knowledge about the neighborhood: Instead of sending its routing table, a router
sends the information about its neighborhood only. A router broadcast its identities and
cost of the directly attached links to other routers.
o Flooding: Each router sends the information to every other router on the internetwork
except its neighbors. This process is known as Flooding. Every router that receives the
packet sends the copies to all its neighbors. Finally, each and every router receives a
copy of the same information.
o Information sharing: A router sends the information to every other router only when
the change occurs in the information.

Link State Routing has two phases:


Reliable Flooding
o Initial state: Each node knows the cost of its neighbors.
o Final state: Each node knows the entire graph.

Route Calculation

Each node uses Dijkstra's algorithm on the graph to calculate the optimal routes to all nodes.

o The Link state routing algorithm is also known as Dijkstra's algorithm which is used to
find the shortest path from one node to every other node in the network.
o The Dijkstra's algorithm is an iterative, and it has the property that after kth iteration of
the algorithm, the least cost paths are well known for k destination nodes.

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 21


Computer Communication Networks Lab – 18TEL66 2021-22

Fig 5. Five node Point to Point Network for LSRA

Procedure :
1. Create the required network and save the tcl file in your folder
2. Open a terminal and type cd (your folder name)
3. Run the tcl file type ns (tcl file name )
4. Note down the path of packet transmission
5. Repeat the experiment by changing the cost of links in the tcl file.

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 22


Computer Communication Networks Lab – 18TEL66 2021-22

TCL FILE

set val(stop) 10.0 ;# time of simulation end


#Create a ns simulator
set ns [new Simulator]
#Open the NS trace file
set tracefile [open link.tr w]
$ns trace-all $tracefile
#Open the NAM trace file
set namfile [open link.nam w]
$ns namtrace-all $namfile
#Create 5 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
#Createlinks between nodes
$ns duplex-link $n0 $n1 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n1 50
$ns duplex-link $n0 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n2 50
$ns duplex-link $n2 $n3 100.0Mb 10ms DropTail
$ns queue-limit $n2 $n3 50
$ns duplex-link $n1 $n3 100.0Mb 10ms DropTail
$ns queue-limit $n1 $n3 50
$ns duplex-link $n3 $n4 100.0Mb 10ms DropTail
$ns queue-limit $n3 $n4 50
$ns duplex-link $n0 $n3 100.0Mb 10ms DropTail
$ns queue-limit $n0 $n3 50
$ns duplex-link $n1 $n2 100.0Mb 10ms DropTail
$ns queue-limit $n1 $n2 50

#Give node position (for NAM)


$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n1 $n3 orient left-down
$ns duplex-link-op $n3 $n4 orient left-down
$ns duplex-link-op $n0 $n3 orient right-down
$ns duplex-link-op $n1 $n2 orient left-down

#Set the link costs. All link costs are symmetric


$ns cost $n0 $n1 2
$ns cost $n0 $n2 1
$ns cost $n0 $n3 3
$ns cost $n1 $n0 2
$ns cost $n1 $n2 2
$ns cost $n1 $n3 3
$ns cost $n2 $n1 2
$ns cost $n2 $n0 1
Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 23
Computer Communication Networks Lab – 18TEL66 2021-22

$ns cost $n2 $n3 1


$ns cost $n3 $n2 1
$ns cost $n3 $n1 3
$ns cost $n3 $n0 3
$ns cost $n3 $n4 2
$ns cost $n4 $n3 2

#Setup a UDP connection


set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set null1 [new Agent/Null]
$ns attach-agent $n4 $null1
$ns connect $udp0 $null1
$udp0 set packetSize_ 1500
#Setup a CBR Application over UDP connection
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 1000
$cbr0 set rate_ 1.0Mb
$cbr0 set random_ null
$ns at 1.0 "$cbr0 start"
$ns at 5.0 "$cbr0 stop"
$ns rtproto LS
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam link.nam &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 24


Computer Communication Networks Lab – 18TEL66 2021-22

Network Animation:

6. Total Number of Routing Paths: 4


7. N0-N1-N2-N3-N4: Total Cost is of 7
8. N0-N2- N1 -N3-N4 : Total Cost is of 8
9. N0-N2-N3-N4 : Total Cost is of 4
10. N0-N3-N4 : Total Cost is of 5

RESULT

Shortest according to Link State algorithm is N0-N2-N3-N4 having


Total Cost is of 4

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 25


Computer Communication Networks Lab – 18TEL66 2021-22

Experiment 5

Simulate the Transmission of Ping Messages over a Network Topology


consisting of Six Nodes and Find the Number of Packets dropped due to
Congestion.
AIM: To simulate transmission of Ping Messages over a Network Topology consisting of
Six Nodes and Find the Number of Packets dropped due to Congestion.

Theory:
Ping is a computer network administration software utility used to test the reachability of
a host on an Internet Protocol (IP) network. It measures the round-trip time for messages
sent from the originating host to a destination computer that are echoed back to the source.
Ping operates by sending Internet Control Message Protocol (ICMP) echo
request packets to the target host and waiting for an ICMP echo reply. The program reports
errors, packet loss, and a statistical summary of the results, typically including the
minimum, maximum, the mean round-trip times, and standard deviation of the mean.
The Internet Control Message Protocol (ICMP) is a supporting protocol in the Internet
protocol suite. It is used by network devices, including routers, to send error messages and
operational information indicating, for example, that a requested service is not available or
that a host or router could not be reached. ICMP differs from transport protocols such
as TCP and UDP in that it is not typically used to exchange data between systems, nor is it
regularly employed by end-user network applications (with the exception of some
diagnostic tools like ping and traceroute).

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 26


Computer Communication Networks Lab – 18TEL66 2021-22

Procedure:

1. Create the required network and save the TCL file in your folder
2. Edit the TCL file to create PING agents, connect and schedule them.
3. Run the tcl file type ns (tcl file name )
4. Type gedit (filename.awk) to create awk file for your experiment
5. Type the awk code and save it
6. Run the awk script
7. Change the error rate in the TCL file and tabulate the results.

TCL FILE
#Create a ns simulator
set ns [new Simulator]
#Open the NS trace file
set tracefile [open out.tr w]
$ns trace-all $tracefile
#Open the NAM trace file
set namfile [open out.nam w]
$ns namtrace-all $namfile
#Create 6 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]
#Createlinks between nodes
$ns duplex-link $n0 $n2 1.0Mb 10ms DropTail
$ns queue-limit $n0 $n2 50
$ns duplex-link $n1 $n2 1.0Mb 10ms DropTail
$ns queue-limit $n1 $n2 50
$ns duplex-link $n2 $n3 1.0Mb 10ms DropTail
$ns queue-limit $n2 $n3 50
$ns duplex-link $n3 $n4 1.0Mb 10ms DropTail
$ns queue-limit $n3 $n4 50
$ns duplex-link $n3 $n5 1.0Mb 10ms DropTail
$ns queue-limit $n3 $n5 50
#Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link-op $n3 $n4 orient right-up
$ns duplex-link-op $n3 $n5 orient right-down
#Define a 'recv' function for the class 'Agent/Ping'
Agent/Ping instproc recv {from rtt} {
$self instvar node_
puts "node [$node_ id] received ping answer from \
#$from with round-trip-time $rtt ms."
}
Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 27
Computer Communication Networks Lab – 18TEL66 2021-22

#Create ping agents and attach them to the nodes


set p0 [new Agent/Ping]
$ns attach-agent $n0 $p0

set p1 [new Agent/Ping]


$ns attach-agent $n1 $p1

set p2 [new Agent/Ping]


$ns attach-agent $n4 $p2

set p3 [new Agent/Ping]


$ns attach-agent $n5 $p3

#Connect the two agents


$ns connect $p0 $p2
$ns connect $p1 $p3

#Schedule events
$ns at 0.2 "$p0 send"
$ns at 0.4 "$p1 send"
$ns at 0.6 "$p2 send"
$ns at 0.8 "$p3 send"

$ns at 1.0 "finish"


#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}
$ns run

Awk Script
BEGIN{
a=0
b=0
}
{
if($1=="r")
{
a++;
}
if($1=="d")
{
b++;
}
Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 28
Computer Communication Networks Lab – 18TEL66 2021-22

}
END{
printf("\n total number of packets received packet: %d\n", a++);
printf("\n total number of packets Dropped Packets: %d\n", b++);
}

Network Animation:

Results:

Error Rate No of Packets received No of Packets dropped


0.0
0.1

Department of Electronics &Telecommunication Engineering, BIT, Bangalore. 29

You might also like