0% found this document useful (0 votes)
5 views5 pages

UDP and TCP Notes

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 5

UDP

UDP stands for User Datagram Protocol.


UDP is a simple protocol and it provides nonsequenced transport functionality.
UDP is a connectionless protocol.
This type of protocol is used when reliability and security are less important than speed and size.
UDP is an end-to-end transport level protocol that adds transport-level addresses, checksum
error control, and length information to the data from the upper layer.
The packet produced by the UDP protocol is known as a user datagram.
User Datagram Format
The user datagram has a 16-byte header which is shown below:

Where,
Source port address: It defines the address of the application process that has delivered a
message. The source port address is of 16 bits address.
Destination port address: It defines the address of the application process that will receive the
message. The destination port address is of a 16-bit address.
Total length: It defines the total length of the user datagram in bytes. It is a 16-bit field.
Checksum: The checksum is a 16-bit field which is used in error detection.

Disadvantages of UDP protocol


UDP provides basic functions needed for the end-to-end delivery of a transmission.
It does not provide any sequencing or reordering functions and does not specify the damaged
packet when reporting an error.
UDP can discover that an error has occurred, but it does not specify which packet has been lost
as it does not contain an ID or sequencing number of a particular data segment.
TCP
TCP stands for Transmission Control Protocol.
It provides full transport layer services to applications.
It is a connection-oriented protocol means the connection established between both the ends
of the transmission. For creating the connection, TCP generates a virtual circuit between sender
and receiver for the duration of a transmission.
It lies between Application Layer and Network Layer
Features Of TCP protocol
1. Segment Numbering System:
TCP keeps a track of the segments being transmitted or received by assigning numbers to
each and every single segment.
A specific Byte Number is assigned to data bytes that are to be transferred while segments
are given sequence numbers
Acknowledgement Numbers are assigned to received segments.
2. FLOW CONTROL:
It limits the rate at which the sender transfers data. This is done to ensure reliable delivery .
The receiver continously hints to the sender on how much data can be received.
3. Error Control:
TCP Implements an error control mechanism for reliable data transfer.
Error control is byte oriented .
Segments are checked for error detection using checksum.
Error control includes corrupted segments , duplicate segments, lost segments.
4. Congestion Control:
TCP takes into account the level of congestion in network.
Congestion level is determined by the amount of data sent by sender.

Suppose the process A wants to send and receive the data from process B. The following steps
occur:
Establish a connection between two TCPs.
Data is exchanged in both the directions. Where,
The Connection is terminated. Source port address: It is used to define the
TCP Segment Format address of the application program in a source
computer. It is a 16-bit field.
Destination port address: It is used to define
the address of the application program in a
destination computer. It is a 16-bit field.
Sequence number: A stream of data is divided
into two or more TCP segments. The 32-bit
sequence number field represents the position
of the data in an original data stream.

Acknowledgement number: A 32-field acknowledgement number acknowledge the data from


other communicating devices. If ACK field is set to 1, then it specifies the sequence number that
the receiver is expecting to receive.
Header Length (HLEN): It specifies the size of the TCP header in 32-bit words. The minimum size
of the header is 5 words, and the maximum size of the header is 15 words. Therefore, the
maximum size of the TCP header is 60 bytes, and the minimum size of the TCP header is 20 bytes.
Reserved: It is a six-bit field which is reserved for future use.
Control bits: Each bit of a control field functions individually and independently. A control bit
defines the use of a segment or serves as a validity check for other fields.
There are total six types of flags in control field:
URG: The URG field indicates that the data in a segment is urgent.
ACK: When ACK field is set, then it validates the acknowledgement number.
PSH: The PSH field is used to inform the sender that higher throughput is needed so if possible,
data must be pushed with higher throughput.
RST: The reset bit is used to reset the TCP connection when there is any confusion occurs in the
sequence numbers.
SYN: The SYN field is used to synchronize the sequence numbers in three types of segments:
connection request, connection confirmation ( with the ACK bit set ), and confirmation
acknowledgement.
FIN: The FIN field is used to inform the receiving TCP module that the sender has finished
sending data. It is used in connection termination in three types of segments: termination
request, termination confirmation, and acknowledgement of termination confirmation.
Window Size: The window is a 16-bit field that defines the size of the window.
Checksum: The checksum is a 16-bit field used in error detection.
Urgent pointer: If URG flag is set to 1, then this 16-bit field is an offset from the sequence
number indicating that it is a last urgent data byte.
Options and padding: It defines the optional fields that convey the additional information to the
receiver.

ADVANTAGES :
1. It is a reliable protocol.
2. It provides error checking mechanism as well as one for recovery
3. It gives flow control.
4. It makes sure that the data reaches proper destination in exact order that was sent.

Disadvantages :
1. TCP is made for Wide Area Networks
2. It runs on several layers so it can slow down speed of network.
3. It is not generic in nature.

Differences b/w TCP & UDP

Basis for Comparison TCP UDP

Definition TCP establishes a virtual circuit before UDP transmits the data directly to the
transmitting the data. destination computer without verifying whether
the receiver is ready to receive or not.

Connection Type It is a Connection-Oriented protocol It is a Connectionless protocol

Speed slow high

Reliability It is a reliable protocol. It is an unreliable protocol.

Header size 20 bytes 8 bytes

acknowledgement It waits for the acknowledgement of data and It neither takes the acknowledgement, nor it
has the ability to resend the lost packets. retransmits the damaged frame.
In the network layer, before the network can make Quality of service guarantees, it must know
what traffic is being guaranteed. One of the main causes of congestion is that traffic is often
bursty.

Traffic Shaping is a mechanism to control the amount and the rate of traffic sent to the
network. Approach of congestion management is called Traffic shaping. Traffic shaping helps to
regulate the rate of data transmission and reduces congestion.
There are 2 types of traffic shaping algorithms:
Leaky Bucket
Token Bucket
Leaky bucket algorithm
in networking, a technique called leaky bucket can smooth out bursty traffic. Bursty chunks are
stored in the bucket and sent out at an average rate.
we assume that the network has committed a bandwidth of 3 Mbps for a host. The use of the
leaky bucket shapes the input traffic to make it conform to this commitment. In the above
figure, the host sends a burst of data at a rate of 12 Mbps for 2s, for a total of 24 Mbits of data.
The host is silent for 5 s and then sends data at a rate of 2 Mbps for 3 s, for a total of 6 Mbits of
data.
In all, the host has sent 30 Mbits of data in 10 s. The leaky bucket smooths out the traffic by
sending out data at a rate of 3 Mbps during the same 10 s.
Without the leaky bucket, the beginning burst may have hurt the network by consuming more
bandwidth than is set aside for this host. We can also see that the leaky bucket may prevent
congestion..

A simple leaky bucket algorithm can be implemented using FIFO queue. A FIFO queue holds the
packets. If the traffic consists of fixed-size packets (e.g., cells in ATM networks), the process
removes a fixed number of packets from the queue at each tick of the clock. If the traffic
consists of variable-length packets, the fixed output rate must be based on the number of bytes
or bits.
The following is an algorithm for variable-length packets:
Initialize a counter to n at the tick of the clock.
Repeat until n is smaller than the packet size of the packet at the head of the queue.
Pop a packet out of the head of the queue, say P.
Send the packet P, into the network
Decrement the counter by the size of packet P.
Reset the counter and go to step 1.

Token Bucket
Algorithm
to deal with the more traffic, we need a flexible algorithm so that the data is not lost. One such
approach is the token bucket algorithm.
Let us understand this algorithm step wise as given below −
Step 1 − In regular intervals tokens are thrown into the bucket f.
Step 2 − The bucket has a maximum capacity f.
Step 3 − If the packet is ready, then a token is removed from the bucket, and the packet is sent.
Step 4 − Suppose, if there is no token in the bucket, the packet cannot be sent.
In figure (a) the bucket holds two tokens,
and three packets are waiting to be sent
out of the interface.
In Figure (b) two packets have been sent
out by consuming two tokens, and 1
packet is still left.
When compared to Leaky bucket the token
bucket algorithm is less restrictive that means
it allows more traffic. The limit of busyness is
restricted by the number of tokens available in
the bucket at a particular instant of time.
The implementation of the token bucket
algorithm is easy − a variable is used to count
the tokens. For every t seconds the counter is
incremented and then it is decremented
whenever a packet is sent. When the counter
reaches zero, no further packet is sent out.

Leaky Bucket Token Bucket

When the host has to send a In this, the bucket holds tokens
packet , packet is thrown in generated at regular intervals of
bucket. time.

Bucket leaks at constant rate Bucket has maximum capacity.

If there is a ready packet , a


Bursty traffic is converted into
token is removed from Bucket
uniform traffic by leaky bucket.
and packet is send.

In practice bucket is a finite If there is no token in the bucket,


queue outputs at finite rate then the packet cannot be sent.

You might also like