CCN Lab Manual-2022 Cycle 1
CCN Lab Manual-2022 Cycle 1
CCN Lab Manual-2022 Cycle 1
PART A
FEATURES OF NS2
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.
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.
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
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
Event Meaning
+ Added to queue
- Removed from queue
r Received at node
d Dropped
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 :
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.
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]
#===================================
# 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
#===================================
# 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
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
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
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]
#Create 4 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
Network Animation:
(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.
$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"
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:
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.
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.
TCL File :
#===================================
# Simulation parameters setup
#===================================
set val(stop) 10.0 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#===================================
# 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
#===================================
#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
#===================================
# 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
NAM File :
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:
Experiment 4
Theory :
Link state routing is a technique in which each router shares the knowledge of its
neighborhood with every other router in the internetwork.
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.
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.
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.
TCL FILE
Network Animation:
RESULT
Experiment 5
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).
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
#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"
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: