CN Lab Manual - 2021
CN Lab Manual - 2021
CN Lab Manual - 2021
LIST OF EXPERIMENTS
LAB 1: Packet Sniffing and Wireshark
LAB 2: Introduction to NS2 and TCL scripting
LAB 3: Simulate a three-node point-to-point network with a duplex link between them for the
following cases:
a. One node act as the sender and receiver and the remaining nodes acts as a repeater
b. One node act as the sender and two nodes acts receiver and data should flow in two
different directions
c. Two nodes acts as sender and one node acts as receiver. Set queue size to 3 and vary the
bandwidth (two cases) and count the packets being dropped
NOTE: Use TCP as transport layer protocol and FTP as traffic source for all cases
Constraint: In all the above cases, no node or link should be kept inactive at any instant of time
LAB 4: Simulate a four-node point-to-point network and connect the link as follows: Apply TCP
agent between n0 and n3. Apply relevant applications over TCP and UDP. Change bandwidth
and latency (two cases) and determine the number of packets sent by two agents
LAB 5: A) Simulate the Link State Routing Protocol for the topology and write the appropriate
conclusion and deduce the relevant inference from your observations
B) Simulate the Distance Vector Routing Protocol for the topology and write the
appropriate conclusion and deduce the relevant inference from your observations
LAB 6: Simulate a 6 node Ethernet LAN network Change Error rate and Data rate and compare
the throughput. Note: Have two cases of different data and error rates
LAB 1
Packet Sniffing and Wireshark
The basic tool for observing the messages exchanged between executing protocol entities is called
a packet sniffer. As the name suggests, a packet sniffer captures (“sniffs”) messages being
sent/received from/by your computer; it will also typically store and/or display the contents of the
various protocol fields in these captured messages. A packet sniffer itself is passive. It observes
messages being sent and received by applications and protocols running on your computer, but
never sends packets itself. Similarly, received packets are never explicitly addressed to the packet
sniffer. Instead, a packet sniffer receives a copy of packets that are sent/received from/by
application and protocols executing on your machine.
Here we use a packet-sniffer called Wireshark. Wireshark (formerly known as ETHEREAL) is a
free (open-source) packet sniffer/analyzer which is available for both UNIX-like (Unix, Linux,
Mac OS X, BSD, and Solaris) and Windows operating systems. It captures packets from a network
interface and displays them with detailed protocol information. Wireshark, however, is a passive
analyzer. It only captures packets without manipulate them; it neither sends packets to the network
nor does other active operations. Wireshark is not an intrusion-detection tool either. It does not
give warning about any network intrusion. It, nevertheless, can help network administrators to
figure out what is going on inside a network and to troubleshoot network problems. In addition of
being an indispensable tool for network administrators, Wireshark is a valuable tool for protocol
developers, who may use it to debug protocol implementations. It is also a great educational tool
for computer-network students who can use it to see details of protocol operations in real time.
Given below is the image of Wireshark Graphical User Interface, during packet capture and
analysis.
Experiment
In this lab, we retrieve a web page and then, using Wireshark, capture packets.
• Start up your web browser and clear the browser's cache memory, but do not access any
site yet.
• Open the Wireshark and start capturing. Use the filter box to capture only frames that the
source or the sink protocol is HTTP.
• Note that you need to type http in lowercase in the filter box and click Apply. Now, go
back to your browser, access one of your favorite web site.
• Stop capturing and save the captured file.
Questions
Using the first frame with the source protocol HTTP, answer the following questions.
1. Is the frame an outgoing or an incoming frame?
2. What is the source IP address of the network-layer header in the frame?
3. What is the destination IP address of the network-layer header in the frame?
4. What is the total number of bytes in the whole frame?
LAB 2
Introduction to NS2 and TCL scripting
Network Simulator (Version 2), widely known as NS2, is an event driven simulation tool that is
useful in studying the dynamic nature of communication networks. NS2 provides users with a way
of specifying such network protocols and simulating their corresponding behaviors. Simulation of
wired as well as wireless network functions and protocols (e.g., routing algorithms, TCP, UDP)
can be done using NS2.
NS uses two languages as the simulator has two different kinds of things it needs to do. On one
hand, detailed simulations of protocols require a system programming language which can
efficiently manipulate bytes, packet headers, and implement algorithms that run over large data
sets. For these tasks run-time speed is important and turn-around time (run simulation, find bug,
fix bug, recompile, re-run) is less important. On the other hand, a large part of network research
involves slightly varying parameters or configurations, or quickly exploring a number of scenarios.
In these cases, iteration time (change the model and re-run) is more important. Since configuration
runs once (at the beginning of the simulation), run-time of this part of the task is less important. ns
meets both of these needs with two languages, C++ and OTcl.
TCL scripting
• Tcl is a general-purpose scripting language. [Interpreter]
• Tcl runs on most of the platforms such as Unix, Windows, and Mac.
• The strength of Tcl is its simplicity.
• It is not necessary to declare a data type for variable prior to the usage.
NS Simulator Preliminaries.
1. Initialization and termination aspects of the ns simulator.
2. Definition of network nodes, links, queues and topology.
3. Definition of agents and of applications.
4. The nam visualization tool.
5. Tracing and random variables.
Program
set ns [new Simulator] # Letter S is capital
$ns namtrace-all $nf # In TCL script files are called by the pointers initialized
$ns trace-all $nt # i.e., nf and nt respectively
proc finish {} {
global ns nf nt
$ns flush-trace # clears trace file contents
close $nf
close $nt
exec nam out.nam &
exit 0
}
And program name when saved should have the extension “ .tcl ”
[root@localhost ~]# gedit lab1.tcl &
Here “ns” indicates network simulator. The network animator window to visualize the simulation
will open.
Now press the play button in the simulation window and the simulation will begins.
LAB 3
Simulate a three node point-to-point network with a duplex link between them for the
following cases:
d. One node a acts as the sender and receiver and the remaining nodes acts as a repeater
e. One node acts as the sender and two nodes acts receiver and data should flow in two
different directions
f. Two nodes acts as sender and one node acts as receiver. Set queue size to 3 and vary
the bandwidth (two cases) and count the packets being dropped
NOTE: Use TCP as transport layer protocol and FTP as traffic source for all cases
Constraint: In all the above cases, no node or link should be kept inactive at any instant of
time
a.
set ns [new Simulator]
$ns color 1 Red
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam sim.nam &
exit 0
}
b.
set ns [new Simulator]
set nf [open sim.nam w]
$ns namtrace-all $nf
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam sim.nam &
exit 0
}
c.
set ns [new Simulator]
$ns color 1 Blue
$ns color 2 Red
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam sim.nam &
exit 0
}
LAB 4
Simulate a four-node point-to-point network and connect the link as follows: Apply TCP
agent between n0 and n3. Apply relevant applications over TCP and UDP. Change
bandwidth and latency (two cases) and determine the number of packets sent by two agents
using awk script.
proc finish {} {
global ns nf nt
$ns flush-trace
close $nf
close $nt
exec nam sim.nam &
exit 0
}
.awk script
Open gedit and type awk program. Program name should have the extension “.awk ”
[root@localhost ~]# gedit filename.awk &
udp++;
}
else if ($1=="r" && $5=="tcp")
{
tcp++;
}
else if ($1=="d" && $5=="tcp")
{
drop++
}
}
END {
printf("Number of packets sent by TCP = %d \n",tcp);
printf("Number of packets sent by UDP = %d\n",udp);
printf("Number of packets dropped by TCP = %d\n",drop);
}
LAB 5
a.
set ns [new Simulator]
set nr [open thro.tr w]
$ns trace-all $nr
set nf [open thro.nam w]
$ns namtrace-all $nf
$ns rtproto DV
# use LS instead of DV for Link State protocol
$ns rtmodel-at 2.0 down $n(2) $n(3)
$ns rtmodel-at 2.8 down $n(1) $n(4)
$ns rtmodel-at 3.0 up $n(1) $n(4)
$ns rtmodel-at 3.5 up $n(2) $n(3)
$ns rtmodel-at 4.0 down $n(2) $n(3)
$ns rtmodel-at 4.0 down $n(2) $n(4)
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exec nam thro.nam &
exit 0
}
b.
set ns [new Simulator]
set nr [open thro.tr w]
$ns trace-all $nr
$ns rtproto LS
$ns rtmodel-at 2.0 down $n(2) $n(3)
$ns rtmodel-at 2.8 down $n(1) $n(4)
$ns rtmodel-at 3.0 up $n(1) $n(4)
$ns rtmodel-at 3.5 up $n(2) $n(3)
$ns rtmodel-at 4.0 down $n(2) $n(3)
$ns rtmodel-at 4.0 down $n(2) $n(4)
LAB 6
Simulate a 6 node ethernet LAN network. Change error rate and Data rate, compare the
throughput. Make node-0 as TCP transmitter, node-1 as UDP transmitter and node-4
receiver & node-5 as NULL
• Use ring topology: Connect each node to next node; node-5 to node-0
• Use bus topology for the tnework shown below
Use set lan [$ns newLan "$n(3) $n(4) $n(5)" 2Mb 40ms LL Queue/DropTail
MAC/802_3 Channel] for bus connection
NOTE: Try for multiple cases of different data and error rates
set lan [$ns newLan "$n(3) $n(4) $n(5)" 1Mb 40ms LL Queue/DropTail MAC/802_3 Channel]
proc finish {} {
global ns nf nt
$ns flush-trace
close $nf
close $nt
exec nam sim.nam &
set tcpsize [exec sh f1.sh]
set tcpnum [exec sh f2.sh]
set udpsize [exec sh f3.sh]
set udpnum [exec sh f4.sh]
set time_of_exec 124.00
puts "Throughput of TCP is [expr $tcpsize * $tcpnum / $time_of_exec] bytes per sec \n"
puts "Throughput of UDP is [expr $udpsize * $udpnum / $time_of_exec] bytes per sec
\n"
exit 0
f1.sh
grep "^r" lab6.tr|grep tcp|tail -n 1|cut -d " " -f 6
f2.sh
grep "^r" lab6.tr |grep -c "tcp"
f3.sh
grep "^r" lab6.tr|grep "cbr"|tail -n 1| cut -d " " -f 6
f4.sh
grep "^r" lab6.tr |grep -c "cbr"
LAB 7
SIMULATION OF STOP AND WAIT PROTOCOL
$ns at 0.0 "$ns trace-annotate \"Stop and Wait with normal operation\""
$ns at 0.05 "$ns trace-annotate \"FTP starts at 0.1\""
$ns at 0.11 "$ns trace-annotate \"Send Packet_0\""
$ns at 0.35 "$ns trace-annotate \"Receive Ack_0\""
$ns at 0.56 "$ns trace-annotate \"Send Packet_1\""
$ns at 0.79 "$ns trace-annotate \"Receive Ack_1\""
$ns at 0.99 "$ns trace-annotate \"Send Packet_2\""
$ns at 1.23 "$ns trace-annotate \"Receive Ack_2 \""
$ns at 1.43 "$ns trace-annotate \"Send Packet_3\""
$ns at 1.67 "$ns trace-annotate \"Receive Ack_3\""
$ns at 1.88 "$ns trace-annotate \"Send Packet_4\""
$ns at 2.11 "$ns trace-annotate \"Receive Ack_4\""
$ns at 2.32 "$ns trace-annotate \"Send Packet_5\""
$ns at 2.55 "$ns trace-annotate \"Receive Ack_5 \""
$ns at 2.75 "$ns trace-annotate \"Send Packet_6\""
$ns at 2.99 "$ns trace-annotate \"Receive Ack_6\""
$ns at 3.1 "$ns trace-annotate \"FTP stops\""
proc finish {} {
global ns nf
$ns flush-trace
close $nf
puts "running nam..."
exec nam stop.nam &
exit 0
}
$ns run
LAB 8
NETSIM EXPERIMENTS- I
a. Understand working of ARP, and IP forwarding within a LAN and across a router
b. Understand the working of “Connection Establishment” in TCP
LAB 9
NETSIM EXPERIMENTS- II
LAB 10