Network Lab New
Network Lab New
Network Lab New
Capture ping and traceroute PDUs using a network protocol analyzer and examine
AIM: To Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute
1. Tcpdump
The tcpdump utility allows you to capture packets that flow within your network to
assist in network troubleshooting. The following are several examples of using
tcpdump with different options. Traffic is captured based on a specified filter.
Options Description
-D Print a list of network interfaces.
Specify an interface on which to
-i
capture.
Specify the number of packets to
-c
receive.
-v, -vv, -vvv Increase the level of detail (verbosity).
-w Write captured data to a file.
-r Read captured data from a file.
Many other options and arguments can be used with tcpdump. The following are some
specific examples of the power of the tcpdump utility.
To display all traffic between two hosts (represented by variables host1 and host2):
Provide the protocol as an argument to display only traffic for a specific protocol, for example
tcp, udp, icmp, arp:
# tcpdump protocol
# tcpdump tcp
2.Netstat
Netstat is a common command line TCP/IP networking available in most versions of Windows,
Linux, UNIX and other operating systems. Netstat provides information and statistics about
protocols in use and current TCP/IP network connections. The Windows help screen
(analogous to a Linux or UNIX for netstat reads as follows:
netstat [-a] [-e] [-n] [-o] [-p Protocol] [-r] [-s] [Interval]
Parameters
Used without
displays active TCP connections.
parameters
Displays all active TCP connections and the TCP and UDP ports on which the
-a
computer is listening.
Displays Ethernet statistics, such as the number of bytes and packets sent and
-e
received. This parameter can be combined with -s.
Displays active TCP connections, however, addresses and port numbers are
-n
expressed numerically and no attempt is made to determine names.
-o Displays active TCP connections and includes the process ID (PID) for each
connection. You can find the application based on the PID on the Processes tab
in Windows Task Manager. This parameter can be combined with -a, -n, and -p.
Shows connections for the protocol specified by Protocol. In this case, the
Protocol can be tcp, udp, tcpv6, or udpv6. If this parameter is used with -s to
-p
display statistics by protocol, Protocol can be tcp, udp, icmp, ip, tcpv6, udpv6,
icmpv6, or ipv6.
Displays statistics by protocol. By default, statistics are shown for the TCP, UDP,
ICMP, and IP protocols. If the IPv6 protocol for Windows XP is installed,
-s
statistics are shown for the TCP over IPv6, UDP over IPv6, ICMPv6, and IPv6
protocols. The -p parameter can be used to specify a set of protocols.
Displays the contents of the IP routing table. This is equivalent to the route
-r
print command.
Redisplays the selected information every Interval seconds. Press CTRL+C to
Interval stop the redisplay. If this parameter is omitted, netstat prints the selected
information only once.
/? - Displays help at the command prompt.
3. Ifconfig
Using ipconfig
From the command prompt, type ipconfig to run the utility with default options. The output
of the default command contains the IP address, network mask, and gateway for all physical
and virtual network adapter
Syntax
Parameters
Used without
displays the IP address, subnet mask, and default gateway for all adapters.
parameters
Displays the full TCP/IP configuration for all adapters. Without this parameter,
ipconfig displays only the IP address, subnet mask, and default gateway values
/all
for each adapter. Adapters can represent physical interfaces, such as installed
network adapters, or logical interfaces, such as dial-up connections.
/renew Renews DHCP configuration for all adapters (if an adapter is not specified) or
for a specific adapter if the Adapter parameter is included. This parameter is
available only on computers with adapters that are configured to obtain an IP
[Adapter]
address automatically. To specify an adapter name, type the adapter name
that appears when you use ipconfig without parameters.
Sends a DHCPRELEASE message to the DHCP server to release the current
DHCP configuration and discard the IP address configuration for either all
/release adapters (if an adapter is not specified) or for a specific adapter if the Adapter
[Adapter] parameter is included. This parameter disables TCP/IP for adapters configured
to obtain an IP address automatically. To specify an adapter name, type the
adapter name that appears when you use ipconfig without parameters.
Flushes and resets the contents of the DNS client resolver cache. During DNS
/flushdns troubleshooting, you can use this procedure to discard negative cache entries
from the cache, as well as any other entries that have been added dynamically.
Displays the contents of the DNS client resolver cache, which includes both
entries preloaded from the local Hosts file and any recently obtained resource
/displaydns records for name queries resolved by the computer. The DNS Client service
uses this information to resolve frequently queried names quickly, before
querying its configured DNS servers.
Initiates manual dynamic registration for the DNS names and IP addresses that
are configured at a computer. You can use this parameter to troubleshoot a
failed DNS name registration or resolve a dynamic update problem between a
/registerdns
client and the DNS server without rebooting the client computer. The DNS
settings in the advanced properties of the TCP/IP protocol determine which
names are registered in DNS.
Adapter Displays the DHCP class ID for a specified adapter. To see the DHCP
class ID for all adapters, use the asterisk (*) wildcard character in place of
/showclassid
Adapter. This parameter is available only on computers with adapters that are
configured to obtain an IP address automatically.
Adapter [ClassID] Configures the DHCP class ID for a specified adapter. To set
the DHCP class ID for all adapters, use the asterisk (*) wildcard character in
/setclassid place of Adapter. This parameter is available only on computers with adapters
that are configured to obtain an IP address automatically. If a DHCP class ID is
not specified, the current class ID is removed.
Examples:
The nslookup (which stands for name server lookup) command is a network utility
program used to obtain information about internet servers. It finds name server information
for domains by querying the Domain Name System.
5. traceroute
Traceroute is a network diagnostic tool used to track the pathway taken by a packet on
an IP network from source to destination. Traceroute also records the time taken for each hop
the packet makes during its route to the destination.
Traceroute uses Internet Control Message Protocol (ICMP) echo packets with variable time to
live (TTL) values. The response time of each hop is calculated. To guarantee accuracy, each
hop is queried multiple times (usually three times) to better measure the response of that
particular hop.
tracert www.google.com
With the tracert command shown above, we're asking tracert to show us the path from the
local computer all the way to the network device with the hostname www.google.com.
Tracing route to www.l.google.com [209.85.225.104]
over a maximum of 30 hops:
1 <1 ms <1 ms <1 ms 10.1.0.1
2 35 ms 19 ms 29 ms 98.245.140.1
3 11 ms 27 ms 9 ms te-0-3.dnv.comcast.net [68.85.105.201]
...
13 81 ms 76 ms 75 ms 209.85.241.37
14 84 ms 91 ms 87 ms 209.85.248.102
15 76 ms 112 ms 76 ms iy-f104.1e100.net [209.85.225.104]
Trace complete.
EX.NO 2. Write a HTTP web client program to download a web page using TCP sockets.
Aim:
To write a java program for socket for HTTP for web page upload and download .
Algorithm
1.Start the program.
2.Get the frame size from the user
3.To create the frame based on the user request.
4.To send frames to server from the client side.
5.If your frames reach the server it will send ACK signal to client otherwise it will
send NACK signal to client.
6.Stop the program
Program :
Client
import javax.swing.*;
import java.net.*;
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
class Server {
public static void main(String args[]) throws Exception{
ServerSocket server=null;
Socket socket;
server=new ServerSocket(4000); System.out.println("Server
Waiting for image"); socket=server.accept();
System.out.println("Client connected."); InputStream in =
socket.getInputStream();
DataInputStream dis = new DataInputStream(in);
int len = dis.readInt();
System.out.println("Image Size: " + len/1024 + "KB"); byte[] data = new byte[len];
dis.readFully(data);
dis.close();
in.close();
InputStream ian = new
ByteArrayInputStream(data); BufferedImage
bImage = ImageIO.read(ian);
JFrame f = new JFrame("Server");
ImageIcon icon = new ImageIcon(bImage);
JLabel l = new JLabel();
l.setIcon(icon);
f.add(l);
f.pack();
f.setVisible(true);
}
}
Output
When you run the client code, following output screen would appear on client side.
Viva questions:
Result:
Thus the program for creating sockets for HTTP web page upload and
download was implemented.
EX.NO 3 Applications using TCP sockets like:
A. Echo client and echo server
B. Chat
C File Transfer
EX.NO 3(A) Applications using TCP sockets like Echo client and Echo server
Aim
To write a java program for application using TCPSockets Links
Algorithm
EchoServer.java
import java.net.*;
import java.io.*;
public class EServer
{
public static void main(String args[])
{
ServerSocket s=null;
String line;
DataInputStream is;
PrintStream ps;
Socket c=null;
try
{
s=new ServerSocket(9000);
}
catch(IOException e)
{
}
try
{
System.out.println(e);
c=s.accept();
is=new DataInputStream(c.getInputStream()); ps=new
PrintStream(c.getOutputStream()); while(true)
{
line=is.readLine();
ps.println(line);
}
}
catch(IOException e)
{
System.out.println(e);
}
}
}
EClient.java
import java.net.*;
import java.io.*;
public class EClient
{
public static void main(String arg[])
{
Socket c=null; String
line; DataInputStream
is,is1; PrintStream os;
try
{
InetAddress ia = InetAddress.getLocalHost();
c=new Socket(ia,9000);
}
catch(IOException e)
{
}
try
{
System.out.println(e);
os=new PrintStream(c.getOutputStream());
is=new DataInputStream(System.in);
is1=new DataInputStream(c.getInputStream());
while(true)
{ System.out.println("Client:");
line=is.readLine();
os.println(line);
System.out.println("Server:" + is1.readLine());
}}
catch(IOException e)
{
System.out.println("Socket Closed!");
}
}
}
Output
Server
C:\Program Files\Java\jdk1.5.0\bin>javac EServer.java
Note: EServer.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
C:\Program Files\Java\jdk1.5.0\bin>java EServer
C:\Program Files\Java\jdk1.5.0\bin>
Client
C:\Program Files\Java\jdk1.5.0\bin>javac EClient.java
Note: EClient.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
C:\Program Files\Java\jdk1.5.0\bin>java EClient
Client:
Hai Server
Server:Hai Server
Client:
Hello
Server:Hello
Client:
end
Server:end
Client:
ds
Socket Closed!
Viva questions:
Result:
Thus the java program to concurrently communicate using TCP Sockets was executed
successfully
B.CHAT
AIM:
UDPclient.java
import java
.io.*; import
java.net.*;
class UDPclient
{
public static DatagramSocket ds;
public static int clientport=789,serverport=790;
OUTPUT:
Server
C:\Program Files\Java\jdk1.5.0\bin>java
UDPserver press ctrl+c to quit the program
Client:Hai Server
Client
Viva Questions:
Algorithm
Server
Client
Program
File Client
.
Viva questions:
RESULT
Thus the java program file transfer application using TCP Sockets was executed
EX.NO 4. Simulation of DNS using UDP sockets.
Algorithm
Program
OUTPUT
Server
javac udpdnsserver.java
java udpdnsserver
Press Ctrl + C to Quit Request for host yahoo.com
Request for host cricinfo.com
Request for host youtube.com
Client
javac udpdnsclient.java
java udpdnsclient
Enter the hostname : yahoo.com
IP Address: 68.180.206.184
java udpdnsclient
Enter the hostname : cricinfo.com
IP Address: 80.168.92.140
java udpdnsclient
Enter the hostname : youtube.com
IP Address: Host Not Found
Viva Questions:
1. What is DNS?
2. What is the port number of DNS?
3. What is the main purpose of DNS server?
4. What is forward lookup?
5. What is reverse lookup?
6. What are the different types of DNS Server?
7. What are the different types of Resource Records in bind?
8. What are the different types of Resource Records in bind?
9. What is the main use of port number in DNS?
10. Mention some real time applications of DNS
Result:
Server
Program
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(139); 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
Viva Questions
1. What is ARP?
2. To Which OSI Layer ARP belong?
3. What is the use of ARP?
4. What is an ARP Request Packet is Generated?
Resut: Thus the ARP protocol using TCP Sockets program was executed.
EX.NO (5(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
Clientrarp12
{
public static void main(String args[])
{
try
{
DatagramSocket client=new DatagramSocket();
InetAddress
addr=InetAddress.getByName("127.0.0.1"); byte[]
sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
BufferedReader in=new BufferedReader(new
InputStreamReader(System.in)); System.out.println("Enter the Physical
address (MAC):")
String str=in.readLine(); sendbyte=str.getBytes();
DatagramPacket
sender=newDatagramPacket(sendbyte,sendbyte.length,addr,1309);
client.send(sender);
DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);
client.receive(receiver);
String s=new String(receiver.getData());
System.out.println("The Logical Address is(IP):
"+s.trim());
client.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Server:
import
java.io.*;
import
java.net.*;
import
java.util.*;
class
Serverrarp12
{
public static void main(String args[])
{
try
{
DatagramSocket server=new DatagramSocket(1309);
while(true)
{
byte[] sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
DatagramPacket receiver=new
DatagramPacket(receivebyte,receivebyte.length);
server.receive(receiver);
String str=new
String(receiver.getData()); String
s=str.trim();
InetAddress addr=receiver.getAddress();
int port=receiver.getPort(); 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(s.equals(mac[i]))
{
sendbyte=ip[i].getBytes();
DatagramPacket
sender=newDatagramPacket(sendbyte,sendbyte.length,addr,port);
server.send(sender);
break;
}
}
break;
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
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
Ns Functionalities
Wireles
s
Most network simulators use discrete event simulation, in which a list of pending "events" is
stored, and those events are processed in order, with some events triggering future events
such as the event of the arrival of a packet at one node triggering the event of the arrival of
that packet at a downstream node. Simulation of networks is a very complex task. For
example, if congestion is high, then estimation of the average occupancy is challenging
because of high variance. To estimate the likelihood of a buffer overflow in a network,
the time required for an accurate answer can be extremely large. Specialized techniques
such as "control variants" and "importance sampling" have been developed to speed
simulatio
n.
Examples of network simulators
There are many both free/open-source and proprietary network simulators. Examples of
notable network simulation software are, ordered after how often they are mentioned in
research papers:
ns (open source)
OPNET (proprietary software)
NetSim (proprietary software)
Uses of network simulators
Network simulators serve a variety of needs. Compared to the cost and time involved in
setting up an entire test bed containing multiple networked computers, routers and data
links, network simulators are relatively fast and inexpensive. They allow engineers,
researchers to test scenarios that might be particularly difficult or expensive to emulate
using real hardware - for instance,simulating a scenario with several nodes or
experimenting with a new protocol in the network. Network simulators are particularly useful
in allowing researchers to test new networking protocols or changes to existing protocols
in a controlled and reproducible environment. A typical network simulator encompasses
a wide range of networking technologies and can help the users to build complex networks
from basic building blocks such as a variety of nodes and links. With the help of
simulators, one can design hierarchical networks using various types of nodes like
computers, hubs, bridges, routers, switches, links, mobile units etc. Various types of Wide
Area Network (WAN) technologies like TCP, ATM, IP etc. and Local Area Network (LAN)
technologies like Ethernet, token rings etc., can all be simulated with a typical simulator
and the user can test, analyse various standard results apart from devising some novel
protocol or strategy for routing etc. Network simulators are also widely used to
simulate battlefield networks in Network-centric warfare There are a wide variety of network
simulators, ranging from the very simple to the very complex. Minimally, a network
simulator must enable a user to represent a network topology, specifying the nodes on
the network, the links between those nodes and the traffic between the nodes. More
complicated systems may allow the user to specify everything about the protocols used to
handle traffic in a network. Graphical applications allow users to easily visualize the
workings of their simulated environment. Text-based applications may provide a less
intuitive interface, but may permit more advanced forms of customization.
Packet loss occurs when one or more packets of data travelling across a computer network
fail to reach their destination. Packet loss is distinguished as one of the three main error types
encountered in digital communications; the other two being bit error and spurious packets
caused due to noise. Packets can be lost in a network because they may be dropped when
a queue in the network node overflows. The amount of packet loss during the steady
state is another important property of a congestion control scheme. The larger the value
of packet loss, the more difficult it is for transport layer protocols to
Throughpu
t
This is the main performance measure characteristic, and most widely used.In
communication networks, such as Ethernet or packetradio, throughput or network
throughput is the average rate of successful message delivery over a communication
channel. The throughput is usually measured inbitsper second (bit/s or bps), and
sometimes in data packets per second or data packets per time slot This measure how soon
the receiver is able to get a certain amount of data send by the sender. It is determined as
the ratio of the total data received to the end to end delay. Throughput is an important factor
which directly impacts the network performance
Dela
y
Delay is the time elapsed while a packet travels from one point e.g., source premise or
network ingress to destination premise or network degrees. The larger the value of delay,
the more difficult it is for transport layer protocols to maintain highband widths. We will
calculate end to end delay
Queue
Length
A queuing system in networks can be described as packets arriving for service, waiting for
service if it is not immediate, and if having waited for service, leaving the system after being
served. Thus queue length is very important characteristic to determine that how well
the active queue management of the congestion control algorithm has been working.
EX.NO 7. Study of TCP/UDP Performance using Simulation Tool
The transmission Control Protocol (TCP) is one of the most important protocols of Internet
Protocols suite. It is most widely used protocol for data transmission in communication network
such as internet.
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 receiver and sender.
Header
The length of TCP header is minimum 20 bytes long and maximum 60 bytes.
Source Port (16-bits) - It identifies source port of the application process on the sending
device.
Destination Port (16-bits) - It identifies destination port of the application process on the
receiving device.
Sequence Number (32-bits) - Sequence number of data bytes of a segment in a session.
Acknowledgement Number (32-bits) - When ACK flag is set, this number contains the next
sequence number of the data byte expected and works as acknowledgement of the
previous data received.
Data Offset (4-bits) - This field implies both, the size of TCP header (32-bit words) and the
offset of data in current packet in the whole TCP segment.
Reserved (3-bits) - Reserved for future use and all are set zero by default.
Flags (1-bit each)
o NS - Nonce Sum bit is used by Explicit Congestion Notification signaling process.
o CWR - When a host receives packet with ECE bit set, it sets Congestion Windows
Reduced to acknowledge that ECE received.
o ECE -It has two meanings:
If SYN bit is clear to 0, then ECE means that the IP packet has its CE
(congestion experience) bit set.
If SYN bit is set to 1, ECE means that the device is ECT capable.
o URG - It indicates that Urgent Pointer field has significant data and should be
processed.
o ACK - It indicates that Acknowledgement field has significance. If ACK is cleared to
0, it indicates that packet does not contain any acknowledgement.
o PSH - When set, it is a request to the receiving station to PUSH data (as soon as it
comes) to the receiving application without buffering it.
o RST - Reset flag has the following features:
It is used to refuse an incoming connection.
It is used to reject a segment.
It is used to restart a connection.
o SYN - This flag is used to set up a connection between hosts.
o FIN - This flag is used to release a connection and no more data is exchanged
thereafter. Because packets with SYN and FIN flags have sequence numbers, they
are processed in correct order.
Windows Size - This field is used for flow control between two stations and indicates the
amount of buffer (in bytes) the receiver has allocated for a segment, i.e. how much data is
the receiver expecting.
Checksum - This field contains the checksum of Header, Data and Pseudo Headers.
Urgent Pointer - It points to the urgent data byte if URG flag is set to 1.
Options - It facilitates additional options which are not covered by the regular header.
Option field is always described in 32-bit words. If this field contains data less than 32-bit,
padding is used to cover the remaining bits to reach 32-bit boundary.
Addressing
TCP communication between two remote hosts is done by means of port numbers (TSAPs). Ports
numbers can range from 0 – 65535 which are divided as:
Connection Management
TCP communication works in Server/Client model. The client initiates the connection and the
server either accepts or rejects it. Three-way handshaking is used for 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
TCP uses the concept of window size to accommodate the need of Bandwidth management.
Window size tells the sender at the remote end, the number of data byte segments the receiver at
this end can receive. TCP uses slow start phase by using window size 1 and increases the window
size exponentially after each successful communication.
For example, the client uses windows size 2 and sends 2 bytes of data. When the
acknowledgement of this segment received the windows size is doubled to 4 and next sent the
segment sent will be 4 data bytes long. When the acknowledgement of 4-byte data segment is
received, the client sets windows size to 8 and so on.
If an acknowledgement is missed, i.e. data lost in transit network or it received NACK, then the
window size is reduced to half and slow start phase starts again.
TCP uses port numbers to know what application process it needs to handover the data segment.
Along with that, it uses sequence numbers to synchronize itself with the remote host. All data
segments are sent and received with sequence numbers. The Sender knows which last data
segment was received by the Receiver when it gets ACK. The Receiver knows about the last
segment sent by the Sender by referring to the sequence number of recently received packet.
If the sequence number of a segment recently received does not match with the sequence
number the receiver was expecting, then it is discarded and NACK is sent back. If two segments
arrive with the same sequence number, the TCP timestamp value is compared to make a decision.
Multiplexing
The technique to combine two or more data streams in one session is called Multiplexing. When a
TCP client initializes a connection with Server, it always refers to a well-defined port number which
indicates the application process. The client itself uses a randomly generated port number from
private port number pools.
Using TCP Multiplexing, a client can communicate with a number of different application process
in a single session. For example, a client requests a web page which in turn contains different
types of data (HTTP, SMTP, FTP etc.) the TCP session timeout is increased and the session is kept
open for longer time so that the three-way handshake overhead can be avoided.
This enables the client system to receive multiple connection over single virtual connection. These
virtual connections are not good for Servers if the timeout is too long.
Congestion Control
When large amount of data is fed to system which is not capable of handling it, congestion occurs.
TCP controls congestion by means of Window mechanism. TCP sets a window size telling the other
end how much data segment to send. TCP may use three algorithms for congestion control:
Timer Management
TCP uses different types of timer to control and management various tasks:
Keep-alive timer:
Retransmission timer:
Persist timer:
Timed-Wait:
After releasing a connection, either of the hosts waits for a Timed-Wait time to terminate
the connection completely.
This is in order to make sure that the other end has received the acknowledgement of its
connection termination request.
Timed-out can be a maximum of 240 seconds (4 minutes).
Crash Recovery
TCP is very reliable protocol. It provides sequence number to each of byte sent in segment. It
provides the feedback mechanism i.e. when a host receives a packet, it is bound to ACK that
packet having the next sequence number expected (if it is not the last segment).
When a TCP Server crashes mid-way communication and re-starts its process it sends TPDU
broadcast to all its hosts. The hosts can then send the last data segment which was never
unacknowledged and carry onwards.
The User Datagram Protocol (UDP) is simplest Transport Layer communication protocol available
of the TCP/IP protocol suite. It involves minimum amount of communication mechanism. UDP is
said to be an unreliable transport protocol but it uses IP services which provides best effort
delivery mechanism.
In UDP, the receiver does not generate an acknowledgement of packet received and in turn, the
sender does not wait for any acknowledgement of packet sent. This shortcoming makes this
protocol unreliable as well as easier on processing.
Requirement of UDP
A question may arise, why do we need an unreliable protocol to transport the data? We deploy
UDP where the acknowledgement packets share significant amount of bandwidth along with the
actual data. For example, in case of video streaming, thousands of packets are forwarded towards
its users. Acknowledging all the packets is troublesome and may contain huge amount of
bandwidth wastage. The best delivery mechanism of underlying IP protocol ensures best efforts to
deliver its packets, but even if some packets in video streaming get lost, the impact is not
calamitous and can be ignored easily. Loss of few packets in video and voice traffic sometimes
goes unnoticed.
Features
UDP is used when acknowledgement of data does not hold any significance.
UDP is good protocol for data flowing in one direction.
UDP is simple and suitable for query based communications.
UDP is not connection oriented.
UDP does not provide congestion control mechanism.
UDP does not guarantee ordered delivery of data.
UDP is stateless.
UDP is suitable protocol for streaming applications such as VoIP, multimedia streaming.
UDP Header
Source Port - This 16 bits information is used to identify the source port of the packet.
Destination Port - This 16 bits information, is used identify application level service on
destination machine.
Length - Length field specifies the entire length of UDP packet (including header). It is 16-
bits field and minimum value is 8-byte, i.e. the size of UDP header itself.
Checksum - This field stores the checksum value generated by the sender before sending.
IPv4 has this field as optional so when checksum field does not contain any value it is made
0 and all its bits are set to zero.
UDP application
Link State
routing
Routing is the process of selecting best paths in a network. In the past, the term
routing was also used to mean forwarding network traffic among networks. However this
latter function is muchbetter described as simply forwarding. Routing is performed for
many kinds of networks, including the telephone network (circuit switching), electronic
data networks (such as the Internet), and transportation networks. This article is concerned
primarily with routing in electronic data networks using packet switching technology .In
packet switching networks, routing directs packet forwarding (the transit of logically
addressed network packets from their source toward their ultimate destination) through
intermediate nodes. Intermediate nodes are typically network hardware devices such as
routers, bridges, gateways, firewalls, or switches. General-purpose computers can also
forward packets and perform routing, though they are not specialized hardware and may
suffer from limited performance. The routing process usually directs forwarding on the basis
of routing tables which maintain a record of the routes to various network destinations. Thus,
constructing routing tables, which are held in the router's memory, is very important for
efficient routing. Most routing algorithms use only one network path at a time. Multipath
routing techniques enable the use of multiple alternative paths. In case of overlapping/equal
routes, the following elements are considered in order to decide which routes get
installed into the routing table (sorted by priority):
1. Prefix-Length: where longer subnet masks are preferred (independent of whether it is
within a routing
protocol or over different routing protocol)
2. Metric: where a lower metric/cost is preferred (only valid within one and the same
routing protocol)
3. Administrative distance: where a lower distance is preferred (only valid between
different routing protocols) Routing, in a more narrow sense of the term, is often
contrasted with bridging in its assumption that network addresses are structured and that
similar addresses imply proximity within the network. Structured addresses allow a single
routing table entry to represent the route to a group of devices. In large networks,
structured addressing (routing, in the narrow sense) outperforms unstructured
addressing (bridging). Routing has become the dominant form of addressing on the
Internet. Bridging is still widely used within localized environments.
b) FLOODING
Flooding is a simple routing algorithm in which every incoming packet is sent through
every outgoing link except the one it arrived on Flooding is used in bridging and in systems
such as Usenet and peer-to-peer file sharing and as part of some routing protocols, including
OSPF, DVMRP, and those used in ad-hoc wireless networks.There are generally two types
of flooding available, Uncontrolled Flooding and Controlled Flooding.Uncontrolled Flooding
is the fatal law of flooding. All nodes have neighbours and route packets indefinitely. More
than two neighbours create a broadcast storm. Controlled Flooding has its own two
algorithms to make it reliable, SNCF (Sequence Number Controlled Flooding) and RPF
(Reverse Path Flooding). In SNCF, the node attaches its own
address and sequence number to the packet, since every node has a memory of addresses
and sequence numbers. If it receives a packet in memory, it drops it immediately while in
RPF, the node will only send the packet forward. If it is received from the next node, it sends
it back to the sender.
Algorith
m
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.
Advantages
packet can be delivered, it will (probably multiple
times).
Since flooding naturally utilizes every path through the network, it will also use the shortest
path. This algorithm is very simple to implement.
Disadvantag
e
Flooding can be costly in terms of wasted bandwidth. While a message may only have one
destination it has to be sent to every host. In the case of a ping flood or a denial of service
attack, it can be harmful to the reliability of a computer network.Messages can become
duplicated in the network further increasing the load on the networks bandwidth as well
as requiring an increase in processing complexity to disregard duplicate messages.
Duplicate packets may circulate forever, unless certain precautions are taken:Use a hop
count or a time to live count and include it with each packet. This value should take into
account the number of nodes that a packet may have to pass through on the way to
its destination. Have each node keep track of every packet seen and only forward each
packet once Enforce
a network topology without oops
Count-to-infinity problem
The Bellman–Ford algorithm does not prevent routing loops from happening and suffers
from the count to infinity problem. The core of the count-to-infinity problem is that if A
tells B that it has a path somewhere, there is no way for B to know if the path has B as a
part of it. To see the problem clearly, imagine a subnet connected like A–B–C–D–E–F, and let
the metric between the routers be "number of jumps". Now suppose that A is taken offline. In
the vector-update-process B notices that the route to A, which was distance 1, is down – B
does not receive the vector update from A. The problem is, B also gets an update from C,
and C is still not aware of the fact that A is down – so it tells B that A is only two jumps from C
(C to B to A), which is false. This slowly propagates through the network until it reaches infinity
(in which case the algorithm corrects itself, due to the relaxation property of Bellman–Ford).
Sample program:
set ns [new Simulator]
set nr [open thro.tr w]
$ns trace-all $nr
setnf [open thro.nam w]
$ns namtrace-all
$nf proc finish { }
{global ns nr nf
$ns flush-
trace close
$nf
close $nr
execnamthro.na
m& exit 0}
for { set i 0 }
{ $i < 12}
{ incr i 1 }
{set n($i) [$ns node]}
for {set i 0}
{$i < 8}
{incr i}
{$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }
$ns duplex-link $n(0) $n(8) 1Mb 10ms DropTail
$ns duplex-link $n(1) $n(10) 1Mb 10ms DropTail
$ns duplex-link $n(0) $n(9) 1Mb 10ms DropTail
$ns duplex-link $n(9) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(10) $n(11) 1Mb 10ms DropTail
Sample Output:
Link made down:
Result:
Thus the program for creating Simulation of Distance Vector/Link State Routing
was implemented.
ALGORITHM:
Step 1: Start network simulator OTCL editor.
Step 2: Create new simulator using set ns [new Simulator] syntax
Step 3: Create Trace route to Network Animator
set nf [open out.nam w]
$ns namtrace-all $nf
Step 4: Create procedure to trace all path
proc finish {} {
global ns
$ns flush-trace
puts "running nam..."
exec nam out.nam &
exit 0
}
RESULT:
Thus the Routing Protocols performance compared by using NS-2 and output
verified by using Network Animator.
EX.NO 10 Simulation of Error Correction Code(CRC)
Procedure:
Unlike checksum scheme, which is based on addition, CRC is based on binary division.
In CRC, a sequence of redundant bits, called cyclic redundancy check bits, are
appended to the end of data unit so that the resulting data unit becomes exactly
divisible by a second, predetermined binary number.
At the destination, the incoming data unit is divided by the same number. If at this step
there is no remainder, the data unit is assumed to be correct and is therefore
accepted.
A remainder indicates that the data unit has been damaged in transit and therefore
must be rejected.
Example :
AIM:
ALGORITHM:
RECEIVER PROGRAM
for(i=1;i<=nf;i++)
{ rptr=++rptr%8;
rbuf[rptr]=in.readLine();
System.out.println("The received Frame " +rptr+" is : "+rbuf[rptr]);
}
rws-=nf;
System.out.println("\nAcknowledgmen
t sent\n"); p.println(rptr+1); rws+=nf; }
else
break;
ch=in.readLine();
}
while(ch.equals("yes"));
}
}
OUTPUT:
//SENDER OUTPUT
Enter the no. of frames : 4
Enter 4 Messages to be send
hiii
how r u
i am fine
how is evryone
Acknowledgment received for 4 frames
//RECEIVER OUTPUT
Result:
Thus the program for S l i di n g W i n d ow P ro to c o l was implemented.
EX.NO:2 Implementation of Stop and Wait Protocol
AIM
ALGORITHM:
PROGRAM
/SENDER PROGRAM
import java.io.*;
import java.net.*;
public class Sender{
Socket sender;
ObjectOutputStream out;
ObjectInputStream in;
String packet,ack,str, msg;
int n,i=0,sequence=0;
Sender(){}
public void run(){
try{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in)); System.out.println("Waiting for
Connection....");
sender = new Socket("localhost",2004);
sequence=0;
out=new ObjectOutputStream(sender.getOutputStream());
out.flush();
in=new
ObjectInputStream(sender.getInputStream());
str=(String)in.readObject();
System.out.println("reciver > "+str);
System.out.println("Enter the data to send....");
packet=br.readLine();
n=packet.length();
do{ try{ i
f(i<n){
msg=String.valueOf(sequence);
msg=msg.concat(packet.substring(i,i+1));
}
else if(i==n){
msg="end";out.writeObject(msg);break;
} out.writeObject(msg);
sequence=(sequence==0)?
1:0; out.flush();
System.out.println("data sent>"+msg);
ack=(String)in.readObject();
System.out.println("waiting for
ack.....\n\n");
if(ack.equals(String.valueOf(sequence))){ i+
+;
System.out.println("receiver > "+" packet recieved\n\n");
}
else{
System.out.println("Time out resending data....\n\n");
sequence=(sequence==0)?1:0;
}
}catch(Exception e){}
}while(i<n+1);
System.out.println("All data sent. exiting.");
}catch(Exception e){}
finally{ try{
in.close();
out.close();
sender.close();
}
catch(Exception e){}
}
}
public static void main(String args[]){
Sender s=new Sender();
s.run();
}
}
//RECEIVER PROGRAM
import java.io.*;
import java.net.*;
public class Reciever{
ServerSocket reciever;
Socket connection=null;
ObjectOutputStream out;
ObjectInputStream in;
String packet,ack,data="";
int i=0,sequence=0;
Reciever(){}
public void run(){
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
reciever = new ServerSocket(2004,10);
System.out.println("waiting for
connection..."); connection=reciever.accept();
sequence=0;
System.out.println("Connection established :");
out=new ObjectOutputStream(connection.getOutputStream());
out.flush();
in=new ObjectInputStream(connection.getInputStream());
out.writeObject("connected .");
do{ try{ packet=(String)in.read
Object();
if(Integer.valueOf(packet.substring(0,1))==sequence)
{ data+=packet.substring(1);
sequence=(sequence==0)?1:0;
System.out.println("\n\nreceiver >"+packet);
}
else
{
System.out.println("\n\nreceiver >"+packet +" duplicate data");
} if(i<3)
{ out.writeObject(String.valueOf(sequence));i+
+;
}
else{ out.writeObject(String.valueOf((sequence+1)
%2)); i=0;
}
}
catch(Exception e){}
}while(!packet.equals("end"));
System.out.println("Data recived="+data);
out.writeObject("connection ended .");
}
catch(Exception e){}
finally{ try{
in.close();
out.close();
reciever.close();
}
catch(Exception e){}
}
}
public static void main(String args[])
{ Reciever s=new Reciever();
while(true){
s.run();
}
}
}
OUTPUT:
//SENDER OUTPUT
Waiting for Connection....
reciver > connected .
Enter the data to send....
myname
data sent>0m
waiting for ack.....
receiver > packet recieved
data sent>1y
waiting for ack.....
receiver > packet recieved
data sent>0n
waiting for ack.....
receiver > packet recieved
data sent>1a
waiting for ack.....
Time out resending
data.... data sent>1a
waiting for ack.....
receiver > packet recieved
data sent>0m
waiting for ack.....
receiver > packet recieved
data sent>1e
waiting for ack.....
receiver > packet recieved
All data sent. exiting.
//RECEIVER OUTPUT
waiting for connection...
Connection established :
receiver >0m
receiver >1y
receiver >0n
receiver >1a
receiver >1a duplicate data
receiver >0m
receiver >1e
Data recived=myname
waiting for connection...
Viva Questions
1. What happens when a sender doesn’t receive a packet after a certain amount of time?
2. Which packet number is assigned to a new packet if “packet 0” didn’t receive an ACK?
3. Can you identify issue(s) with the Stop-and-Wait Protocol?
4. What is time out?
5. Difference between sliding window and stop and wait?
6. In which layer stop and wait protocol is used?
7. What are the rules for sender in stop and wait?
8. What are the rules for receiver in stop and wait?
Result:
Thus the program for S to p / Wa i t p ro to c o l was implemented.
List of Virtual Lab Experiments
1. TCP/UDP Performance
2. Performance Evaluation of Routing Protocol