UDP and TCP Notes
UDP and TCP Notes
UDP and TCP Notes
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.
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.
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.
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.
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.
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.