CN Lab Manual
CN Lab Manual
LIST OF EXPERIMENTS
1. Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute.
Capture ping and traceroute PDUs using a network protocol analyzer and examine.
2. Write a HTTP web client program to download a web page using TCP sockets.
3. Applications using TCP sockets like:
a) Echo client and echo server
b) Chat
4. Simulation of DNS using UDP sockets.
5. Use a tool like wireshark to capture packets and examine the packets.
6. Write a code simulating ARP /RARP protocols.
7. Study of Network simulator (NS) and Simulation of Congestion Control
Algorithms using NS.
8. Study of TCP/UDP performance using Simulation tool.
9.Simulation of Distance Vector/ Link State Routing algorithm.
10. Simulation of error correction code (like CRC).
EXP NO.05 Use a tool like Wireshark to capture packets and examine the
packets
AIM:
Installing Wireshark
Go to https://www.wireshark.org/download.html to visit the Wireshark download
page.
You must ensure that you use the full URL.
The output will look similar to the following:
Capturing Packets
Go to the Capture drop-down menu option.
Options lets you change the network interface.
Press the shark symbol with the word Start.
Once you are finished capturing the traffic, press the red square with the
word Stop on it.
These menus are context-sensitive; for example, the Stop button does not become
live until after the Start button appears.
Tip
Always have your web browser ready before you press ‘Start’.
Once you start up Wireshark, you will capture a vast amount of traffic.
After capturing it, you can filter the different types of traffic.
Aim:
To write a java program for simulating ARP protocols using TCP
ALGORITHM:
Client
Server
Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientarp
{
public static void main(String args[])
{
try
{
{
System.out.println(e);
}
}
}
Server:
import java.io.*;
import
java.net.*;
import
java.util.*;
class Serverarp
{
public static void main(String args[])
{
try
{
ServerSocket obj=new
ServerSocket(5604);
Socket obj1=obj.accept();
while(true)
{
DataInputStream din=new DataInputStream(obj1.getInputStream());
DataOutputStream dout=new
DataOutputStream(obj1.getOutputStream()); String str=din.readLine();
String ip[]={"165.165.80.80","165.165.79.1"};
String mac[]={"6A:08:AA:C2","8A:BC:E3:FA"};
for(int i=0;i<ip.length;i++)
{
if(str.equals(ip[i]))
{
dout.writeBytes(mac[i]+'\n');
break;
}
}
obj.close();
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Output:
E:\networks>java Serverarp
E:\networks>java Clientarp
Enter the Logical address(IP):
165.165.80.80
The Physical Address is: 6A:08:AA:C2
Result:
Thus the ARP protocol using TCP Sockets program was executed.
EX.NO 6(B) Program for Reverse Address Resolution Protocol (RARP) using UDP
Aim:
To write a java program for simulating RARP protocols using UDP
ALGORITHM
Client
Server
Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientrarp
{
public static void main(String args[])
{
try
{
Server:
import java.io.*;
import java.net.*;
import java.util.*;
class Serverrarp
{
public static void main(String args[])
{
try
{
Output:
I:\ex>java Serverrarp12
I:\ex>java Clientrarp12
Enter the Physical address
(MAC): 6A:08:AA:C2
The Logical Address is(IP): 165.165.80.80
Result :
Thus the RARP program using UDP was executed.
EX.NO: 7(A) STUDY OF NETWORK SIMULATOR (NS)
AIM:
To study about NS2 simulator in detail.
THEORY:
The above figure shows the basic architecture of NS2. NS2 provides users
with an
executable command ns which takes on input argument, the name of a Tcl
simulation scripting file. Users are feeding the name of a Tcl simulation
script (which sets up a simulation) as an input argument of an NS2
executable command ns.
In most cases, a simulation trace file is created, and is used to plot graph
and/or to create animation. NS2 consists of two key languages: C++ and
Object-oriented Tool Command Language (OTcl). While the C++ defines
the internal mechanism (i.e., a backend) of the
simulation objects, the OTcl sets up simulation by assembling and
configuring the objects as well as scheduling discrete events (i.e., a
frontend).
The C++ and the OTcl are linked together using TclCL. Mapped to a C++
object, variables in the OTcl domains are sometimes referred to as handles.
Conceptually, a handle (e.g., n as a Node handle) is just a string (e.g.,_o10)
in the OTcl domain, and does not contain any functionality. instead, the
functionality (e.g., receiving a packet) is defined in the mapped C++ object
(e.g., of class Connector). In the OTcl domain, a handle acts as a frontend
which interacts with users and other OTcl objects. It may defines its own
procedures and variables to facilitate the interaction. Note that the member
procedures and variables in the OTcl domain are called instance procedures
(instprocs) and instance variables (instvars), respectively
Tcl scripting:
• Tcl runs on most of the platforms such as Unix, Windows, and Mac.
• It is not necessary to declare a data type for variable prior to the usage
Basics of TCL
Syntax: command arg1 arg2 arg3
Hello World!
puts stdout{Hello, World!}
Hello, World!
Variables
Command Substitution
set a 5 set len [string length foobar]
set b $a set len [expr [string length foobar] + 9]
Simple Arithmetic
expr 7.2 / 4
Procedures
proc Diag {a b} {
set c [expr sqrt($a * $a + $b * $b)]
return $c }
puts ―Diagonal of a 3, 4 right triangle is [Diag 3 4]‖
Output: Diagonal of a 3, 4 right triangle is 5.0
Loops
while{$i < $n} { for {set i 0} {$i < $n} {incr i} {
... ...
} }
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.
Which is thus the first line in the tcl script? This line declares a new
variable as using the set command, you can call this variable as you wish,
In general people declares it as ns because it is an instance of the
Simulator class, so an object the code[new Simulator] is indeed the
installation of the class Simulator using the reserved word new.
In order to have output files with data on the simulation (trace files) or
files used for visualization (nam files), we need to create the files using
―”open” command: #Open the Trace file
set tracefile1 [open out.tr w]
The above creates a dta trace file called ―out.tr‖ and a nam visualization
trace file called ―out.nam‖.Within the tcl script,these files are not called
explicitly by their names, but instead by pointers that are declared above
and called ―tracefile1 and ―nam file respectively. Remark that they
begins with a # symbol.The second line open the file ―out.tr‖ to be used
for writing, declared with the letter ―w‖.The third line uses a simulator
method called trace-all that have as parameter the name of the file where
the traces will go.
The last line tells the simulator to record all simulation traces in NAM
input format. It also gives the file name that the trace will be written to
later by the command $ns flush-trace. In our case, this will be the file
pointed at by the pointer ―$namfile ,i.e the file ―out.tr‖. The termination
of the program is done using a ―finish‖ procedure.
#Define a ‘finish’ procedure
Proc finish { } {
global ns tracefile1 namfile
$ns flush-trace
Close $tracefile1
Close $namfile
Exec nam out.nam &
Exit 0
The word proc declares a procedure in this case called finish and without
arguments. The word global is used to tell that we are using variables
declared outside the procedure. The simulator method ―flush-trace” will
dump the traces on the respective files. The tcl command
―close” closes the trace files defined before and exec executes the nam
program for visualization.
The command exit will ends the application and return the number 0 as
status to the system. Zero
is the default for a clean exit. Other values can be used to say that is a exit
because something fails.
At the end of ns program we should call the procedure ―finish‖ and
specify at what time the termination should occur. For example,
$ns at 125.0 “finish”
$ns run
The node is created which is printed by the variable n0. When we shall
refer to that node in the
script we shall thus write $n0.
Once we define several nodes, we can define the links that connect them.
An example of a definition of a link is:
$ns duplex-link $n0 $n2 10Mb 10ms DropTail
Which means that $n0 and $n2 are connected using a bi-directional link
that has 10ms of propagation delay and a capacity of 10Mb per sec for
each direction. To define a directional link instead of a bi-directional one,
we should replace “duplexlink” by “simplex link”.
In NS, an output queue of a node is implemented as a part of each link
whose input is that node. The definition of the link then includes the way
to handle overflow at that queue. In our case, if the buffer capacity of the
output queue is exceeded then the last packet to
arrive is dropped. Many alternative options exist, such as the RED
(Random Early Discard) mechanism, the FQ (Fair Queuing), the DRR
(Deficit Round Robin), the stochastic Fair Queuing (SFQ) and the CBQ
(which including a priority and a round-robin scheduler). In ns, an output
queue of a node is implemented as a part of each link whose input is that
node. We should also define the buffer capacity of the queue related to
each link. An example would be:
#set Queue Size of link (n0-n2) to 20
$ns queue-limit $n0 $n2 20
Above shows the definition of a CBR application using a UDP agent. The
command $ns attach-agent $n4 $sink defines the destination node. The
command $ns connect $tcp $sink finally makes the TCP connection
between the source and destination nodes.
TCP has many parameters with initial fixed defaults values that can be
changed if mentioned explicitly. For example, the default TCP packet size
has a size of 1000bytes.This can be changed to another value, say 552bytes,
using the command $tcp set packetSize_ 552. When we have several flows,
we may wish to distinguish them so that we can identify them with different
colors in the visualization part. This is done by the command $tcp set fid_
1 that assigns to the TCP connection a flow identification of “1”.We shall
later give the flow identification of “2” to the UDP connection.
CBR over UDP
A UDP source and destination is defined in a similar way as in the case of
TCP. Instead of defining the rate in the command $cbr set rate_ 0.01Mb,
one can define the time interval between transmission of packets using the
command.
$cbr set interval_ 0.005
The packet size can be set to some value using
Scheduling Events
NS is a discrete event based simulation. The tcp script defines when event
should occur. The initializing command set ns [new Simulator] creates an
event scheduler, and events are then scheduled using the format:
$ns at <time> <event>
The scheduler is started when running ns that is through the command $ns
run. The beginning and end of the FTP and CBR application can be done
through the following command
$ns at 0.1 “$cbr start”
$ns at 1.0 “ $ftp start”
$ns at 124.0 “$ftp stop”
$ns at 124.5 “$cbr stop”
RESULT:
Thus the Network Simulator 2 is studied in detail.
EX.NO: 7(B) Simulation of congestion control algorithm
Aim:
Theory: The main concept of the leaky bucket algorithm is that the
output data flow remains constant despite the variant input traffic, such as
the water flow in a bucket with a small hole at the bottom. In case the
bucket contains water (or packets) then the output flow follows a constant
rate, while if the bucket is full any additional load will be lost because of
spillover. In a similar way if the bucket is empty the output will be zero.
From network perspective, leaky bucket consists of a finite queue
(bucket) where all the incoming packets are stored in case there is space
in the queue, otherwise the packets are discarded. In order to regulate the
output flow, leaky bucket transmits one packet from the queue in a fixed
time (e.g. at every clock tick). In the following figure we can notice the
main rationale of leaky bucket algorithm, for both the two approaches
(e.g. leaky bucket with water (a) and with packets (b))
Output:
E:\nwlab>java Leaky
Enter 0 element: 23
Enter 1 element: 34
Enter 2 element: 34
Enter 3 element: 334
Enter 4 element: 334
Enter 5 element: 34
Enter 6 element: 34
Enter 7 element: 34
Enter 8 element: 34
Enter 9 element: 34
Enter 10 element: 4
Queue is full
Lost Packet: 4
Leaked Packet: 23
Leaked Packet: 34
Leaked Packet: 34
Leaked Packet: 34
Leaked Packet: 34
Leaked Packet: 34
Leaked Packet: 34
Leaked Packet: 34
E:\nwlab>
Result: Thus the program for congestion control using leaky bucket
algorithm is implemented and executed successfully.
EX.NO 8. Study of TCP/UDP Performance using simulation tool
STUDY – 1 TCP
Features
• TCP is reliable protocol. That is, the receiver always sends either positive
or negative acknowledgement about the data packet to the sender, so that
the sender always has bright clue about whether the data packet is
reached the destination or it needs to resend it.
• TCP ensures that the data reaches intended destination in the same order
it was sent.
• TCP is connection oriented. TCP requires that connection between two
remote points be established before sending actual data.
• TCP provides error-checking and recovery mechanism.
• TCP provides end-to-end communication.
• TCP provides flow control and quality of service.
• TCP operates in Client/Server point-to-point mode.
• TCP provides full duplex server, i.e. it can perform roles of both
Header
60 bytes.
Addressing
Connection Management
Establishment
Client initiates the connection and sends the segment with a Sequence
number. Server acknowledges it back with its own Sequence number
and ACK of client’s segment which is one more than client’s Sequence
number. Client after receiving ACK of its segment sends an
acknowledgement of Server’s response.
Release
Either of server and client can send TCP segment with FIN flag set to
1. When the receiving end responds it back by Acknowledging FIN, that
direction of TCP communication is closed and connection is released.
Bandwidth Management
Multiplexing
Congestion Control
Timer Management
TCP uses different types of timer to control and
Retransmission timer:
Persist timer:
• If
this segment never reaches the other end, both ends may wait for
each other for infinite time.
• When the Persist timer expires, the host re-sends its window size
to let the other end know.
• Persist Timer helps avoid deadlocks in communication.
Timed-Wait:
Crash Recovery
STUDY – 2 UDP
Requirement of UDP
UDP Header
UDP application
Result:
Thus, We studied in detail about the Performance of TCP and UDP protocols.
EX.No 9. Simulation of Distance Vector/Link State Routing.
.
a) Distance Vector routing protocol ROUTING
Aim:
To simulate and study the link state routing algorithm using simulation using NS2.
Algorithm
There are several variants of flooding algorithm. Most work roughly
as follows:
1. Each node acts as both a transmitter and a receiver.
2. Each node tries to forward every message to every one of its
neighbours except the source node. This results in every
message eventually being delivered to all reachable parts of the
network. Algorithms may need to be more complex than this,
since, in some case, precautions have to be taken to avoid
wasted duplicate deliveries and infinite loops, and to allow
messages to eventually expire from the system. A variant of
flooding called selective flooding partially addresses these
issues by only sending packets to routers in the same direction.
In selective flooding the routers don't send every incoming
packet on every line but only on those lines which are going
approximately in the right direction.
Program:
set ns [new Simulator]
proc finish {} {
global nf ns tr
$ns flush-trace
close $tr
exec nam out.nam &
exit 0
}
$ns rtproto DV
$ns run
Result:
Thus the Distance Vector Routing Algorithm was Simulated and studied
EX.No 9. Simulation of Distance Vector/Link State Routing.
ALGORITHM:
1. Create a simulator object
2. Define different colors for different data flows
3. Open a nam trace file and define finish procedure then close the trace
file, and execute nam on trace file.
4. Create n number of nodes using for loop
5. Create duplex links between the nodes
6. Setup UDP Connection between n(0) and n(5)
7. Setup another UDP connection between n(1) and n(5)
8. Apply CBR Traffic over both UDP connections
9. Choose Link state routing protocol to transmit data from
sender to receiver. 10. Schedule events and run the
program.
Program:
set ns [new Simulator]
proc finish {} {
global nf ns tr
$ns flush-trace
close $tr
exec nam out.nam &
exit 0
}
$ns rtproto LS
$ns run
Result:
Thus the program for creating Simulation of Distance Vector/Link State Routing was
implemented.
EX.NO: 10 Simulation of Error Correction Code(CRC)
AIM :
To Simulation of Error Correction Code using Java.
Theory:
Example :
Procedure:
1. Open the editor and type the program for error detection
2. Get the input in the form of bits.
3. Append the redundancy bits.
4. Divide the appended data using a divisor polynomial.
5. The resulting data should be transmitted to the receiver.
6. At the receiver the received data is entered.
7. The same process is repeated at the receiver.
8. If the remainder is zero there is no error otherwise there is some error in
the received bits 9. Run the program.
Program:
import java.io.*;
class CRC
{
public static void main(String args[]) throws IOException
{
BufferedReaderbr=newBufferedReader(newInputStreamReader(
System.in));
System.out.println("Enter Generator:");
String gen = br.readLine();
System.out.println("Enter Data:");
String data = br.readLine();
String code = data;
while(code.length() < (data.length() + gen.length() - 1))
code = code + "0";
code = data + div(code,gen);
System.out.println("The transmitted Code Word
is: " + code); System.out.println("Please enter
the received Code Word: "); String rec =
br.readLine();
if(Integer.parseInt(div(rec,gen)) == 0)
System.out.println("The received code word contains
no errors."); else
System.out.println("The received code word
contains errors."); }
Result:
Thus the error detection and error correction is implemented successfully