0% found this document useful (0 votes)
12 views16 pages

Encapsulation and Decapsulation in Networks

The document discusses the transport layer of computer networks, focusing on key functions such as process-to-process communication, encapsulation and decapsulation, multiplexing and demultiplexing, flow control, error control, and congestion control. It explains how the transport layer ensures reliable communication by managing packet delivery, handling errors, and controlling data flow between sender and receiver processes. Additionally, it introduces protocols like Go-Back-N and Selective-Repeat for efficient data transmission and error management.

Uploaded by

basavarajbenkond
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views16 pages

Encapsulation and Decapsulation in Networks

The document discusses the transport layer of computer networks, focusing on key functions such as process-to-process communication, encapsulation and decapsulation, multiplexing and demultiplexing, flow control, error control, and congestion control. It explains how the transport layer ensures reliable communication by managing packet delivery, handling errors, and controlling data flow between sender and receiver processes. Additionally, it introduces protocols like Go-Back-N and Selective-Repeat for efficient data transmission and error management.

Uploaded by

basavarajbenkond
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

COMPUTER NETWROKS

MODULE IV
TRANSPORT LAYER
1. Process-to-Process Communication

The first duty of a transport-layer protocol is to provide process-to-process communication. A


process is an application-layer entity (running program) that uses the services of the transport layer. A
transport-layer protocol is responsible for delivery of the message to the appropriate process. Figure 4.1
shows the domains of a network layer and a transport layer.

Figure 4.1: Network layer Versus transport layer

2. Encapsulation and Decapsulation


To send a message from one process to another, the transport-layer protocol encapsulates and
decapsulates messages.
Encapsulation happens at the sender site. When a process has a message to send, it passes the
message to the transport layer along with a pair of socket addresses and some other pieces of
information, which depend on the transport-layer protocol. The transport layer receives the data and
adds the transport-layer header. The packets at the transport layer in the Internet are called user
datagrams, segments, or packets, depending on what transport-layer protocol in use. In general,
transport-layer payloads are called as packets.

Figure .4.2 Encapsulation and Decapsulation

[Link] BLDEA’s [Link].P.G.H CET


COMPUTER NETWROKS

Decapsulation happens at the receiver site. When the message arrives at the destination transport
layer, the header is dropped and the transport layer delivers the message to the process running at the
application layer. The sender socket address is passed to the process in case it needs to respond to the
message received.

3. Multiplexing and Demultiplexing

Whenever an entity accepts items from more than one source, this is referred to as multiplexing
(many to one) , whenever an entity delivers items to more than one source, this is referred to as
demultiplexing (one to many).

The transport layer at the source performs multiplexing and the transport layer at the destination
performs demultiplexing. Figure 4.3 shows communication between a client and two servers. Three
client processes are running at the client site, P1, P2, and P3.

The processes P1 and P3 need to send requests to the corresponding server process running in a
server. The client process P2 needs to send a request to the corresponding server process running at
another server. The transport layer at the client site accepts three messages from the three processes
and creates three packets. It acts as a multiplexer.

The packets 1 and 3 use the same logical channel to reach the transport layer of the first server.
When they arrive at the server, the transport layer does the job of a demultiplexer and distributes the
messages to two different processes. The transport layer at the second server receives packet 2 and
delivers it to the corresponding process.

Figure 4.3: Multiplexing and Demultiplexing

[Link] BLDEA’s [Link].P.G.H CET


COMPUTER NETWROKS

4. Flow Control

Whenever an entity produces items and another entity consumes them, there should be a
balance between production and consumption rates. If the items are produced faster than they can be
consumed, the consumer can be overwhelmed and may need to discard some items. If the items are
produced more slowly than they can be consumed, the consumer must wait, and the system becomes
less efficient. Flow control is related to the first issue. We need to prevent losing the data items at the
consumer site.

Pushing or Pulling

Delivery of items from a producer to a consumer can occur in one of two ways: pushing or
pulling. If the sender delivers items whenever they are produced without a prior request from the
consumer the delivery is referred to as pushing. If the producer delivers the items after the consumer
has requested them, the delivery is referred to as pulling. Figure 4.4 shows these two types of delivery.

Figure 4.4: Pushing and Pulling

Flow Control at Transport Layer

In communication at the transport layer, we are dealing with four entities: sender process,
sender transport layer, receiver transport layer, and receiver process.

The sending process at the application layer is only a producer. It produces message chunks and
pushes them to the transport layer. The sending transport layer has a double role: It is both a consumer
and a producer. It consumes the messages pushed by the producer. It encapsulates the messages in
packets and pushes them to the receiving transport layer. The receiving transport layer also has a
double role: it is the consumer for the packets received from the sender and the producer that
decapsulates the messages and delivers them to the application layer. The last delivery, however, is
normally a pulling delivery; the transport layer waits until the application-layer process asks for
messages.

[Link] BLDEA’s [Link].P.G.H CET


COMPUTER NETWROKS

Figure 4.5: Flow Control at transport Layer

Figure 4.5 shows that we need at least two cases of flow control: from the sending transport layer
to the sending application layer and from the receiving transport layer to the sending transport layer.

5. Error Control

In the Internet, since the underlying network layer (IP) is unreliable, we need to make the
transport layer reliable if the application requires reliability. Reliability can be achieved to add error
control services to the transport layer. Error control at the transport layer is responsible for

1. Detecting and discarding corrupted packets.

2. Keeping track of lost and discarded packets and resending them.

3. Recognizing duplicate packets and discarding them.

4. Buffering out-of-order packets until the missing packets arrive.

It involves only the sending and receiving transport layers. Assume that the message chunks
exchanged between the application and transport layers are error free. Figure 4.6 shows the error
control between the sending and receiving transport layers. As with the case of flow control, the
receiving transport layer manages error control, most of the time, by informing the sending transport
layer about the problems.

Figure 4.6 Error control at the transport layer

Sequence Numbers: Error control requires that the sending transport layer knows which packet
is to be resent and the receiving transport layer knows which packet is a duplicate, or which packet has
arrived out of order. This can be done if the packets are numbered. Add a field to the transport-layer

[Link] BLDEA’s [Link].P.G.H CET


COMPUTER NETWROKS

packet to hold the sequence number of the packet. When a packet is corrupted or lost, the receiving
transport layer can inform the sending transport layer to resend that packet using the sequence number.

The receiving transport layer can also detect duplicate packets if two received packets have the
same sequence number. The out-of-order packets can be recognized by observing gaps in the sequence
numbers. Packets are numbered sequentially. However, because we need to include the sequence
number of each packet in the header, we need to set a limit. If the header of the packet allows m bits for
the sequence number, the sequence numbers range from 0 to 2m -1
For example, if m is 4, the only sequence numbers are 0 through 15, inclusive. However, we can
wrap around the sequence. The sequence numbers are modulo 2m.
The sequence numbers in this case are 0,1,2,3,4,5,6,7,8,9,10,12,13,14,15,0,1,2,3,4,5,6,7,8,9,10...

Acknowledgment: The receiver side can send an acknowledgment (ACK) for each of a collection
of packets that have arrived safe and sound. The receiver can simply discard the corrupted packets. The
sender can detect lost packets if it uses a timer. When a packet is sent, the sender starts a timer. If an
ACK does not arrive before the timer expires, the sender resends the packet. Duplicate packets can be
silently discarded by the receiver. Out-of-order packets can be either discarded (to be treated as lost
packets by the sender), or stored until the missing one arrives.

6. Congestion Control

Congestion in a network may occur if the load on the network—the number of packets sent to
the network is greater than the capacity of the network, the number of packets a network can handle.
Congestion control refers to the mechanisms and techniques that control the congestion and
keep the load below the capacity.
Congestion happens in any system that involves waiting. For example, congestion happens on a
freeway because any abnormality in the flow, such as an accident during rush hour, creates blockage.
Congestion in a network or internetwork occurs because routers and switches have queues—
buffers that hold the packets before and after processing. A router, for example, has an input queue and
an output queue for each interface. If a router cannot process the packets at the same rate at which they
arrive, the queues become overloaded and congestion occurs.
Congestion at the transport layer is actually the result of congestion at the network layer, which
manifests itself at the transport layer.

[Link] BLDEA’s [Link].P.G.H CET


COMPUTER NETWROKS

Figure 4.7 Connectionless Service

Figure 4.8 Connection Oriented Service

[Link] BLDEA’s [Link].P.G.H CET


COMPUTER NETWROKS

Figure 4.9 Connectionless and Connection-oriented Services Represented as FSMs

[Link] BLDEA’s [Link].P.G.H CET


COMPUTER NETWROKS

Stop & Wait Protocol

Figure 4.9 Outline for Stop and Wait Protocol

FSM for Sender & Receiver

Figure 4.10 FSM for the Sender and Receiver for Stop & Wait protocol

[Link] BLDEA’s [Link].P.G.H CET


COMPUTER NETWROKS

Go-Back N Protocol
To improve the efficiency of transmission (to fill the pipe), multiple packets must be in transition
while the sender is waiting for acknowledgment. In other words, we need to let more than one packet be
outstanding to keep the channel busy while the sender is waiting for acknowledgment. One of the
protocols is called Go-Back-N (GBN). The key to Go-back-N is that we can send several packets before
receiving acknowledgements, but the receiver can only buffer one packet. We keep a copy of the sent
packets until the acknowledgement arrive. Figure 4.7 shows the outline of the protocol.

Figure 4.11 Go-Back-N Protocol


Send Window
The send window is an imaginary box covering the sequence numbers of the data packets that
can be in transit or can be sent. In each window position, some of the sequence numbers define the
packets that have been sent, others define which can be sent. The maximum size of the window is 2m-1,
we let the size be fixed and set to the maximum value, Figure 8 shows a sliding window of size 7 (m= 3)
for the Go-Back-N protocol.

Figure 4.12: Send window for Go-Back-N

The send window at any time divides the possible sequence numbers into four regions.
The first region, left of the window, defines the sequence numbers belonging to packets that are
already acknowledged. The sender does not worry about these packets and keeps no copies of them.
The second region, colored, defines the range of sequence numbers belonging to the packets that
have been sent, but have an unknown status. The sender needs to wait to find out if these packets have
been received or were lost. These are called as outstanding packets.

[Link] BLDEA’s [Link].P.G.H CET


COMPUTER NETWROKS

The third range, white in the figure, defines the range of sequence numbers for packets that can
be sent, the corresponding data have not yet been received from the application layer.
The fourth region, right of the window, defines sequence numbers that cannot be used until the
window slides.

Figure 4.13: Send window for Go-Back-N

Figure 4.9 shows how a send window can slide one or more slots to the right when an
acknowledgment arrives from the other end. In the figure, an acknowledgment with ackNo = 6 has
arrived. This means that the receiver is waiting for packets with sequence no 6.

Receive Window
The receive window makes sure that the correct data packets are received and that the correct
acknowledgments are sent. In Go-Back-N, the size of the receive window is always 1.
The receiver is always looking for the arrival of a specific packet. Any packet arriving out of order
is discarded and needs to be resent. Figure 4.10 shows the receive window. It needs only one variable, Rn
(receive window, next packet expected), to define this abstraction.
The sequence numbers to the left of the window belong to the packets already received and
acknowledged and the sequence numbers to the right of this window define the packets that cannot be
received.
Any received packet with a sequence number in these two regions is discarded. Only a packet
with a sequence number matching the value of Rn is accepted and acknowledged.
The receive window also slides, but only one slot at a time. When a correct packet is received,
the window slides, Rn = (Rn + 1) modulo 2m.

Figure 4.14: Receive window for Go-Back-N

[Link] BLDEA’s [Link].P.G.H CET


COMPUTER NETWROKS

FSMs
Figure 4.15 Shows the FSMs for the GBN protocol.

Sender: The sender starts in the ready state, but thereafter it can be in one of the two states: ready or
blocking. The two variables are normally initialized to 0 (Sf = S n = 0).

Ready state: - Four events may occur when the sender is in readystate.
a. If a request comes from the application layer, the sender creates a packet with the sequence number
set to Sn. A copy of the packet is stored and the packet is sent. The sender also starts the only timer if it
is not running. The value of S n is now incremented, (Sn = S n + 1) modulo 2m. If the window is full, S n = (Sf +
Ssize) modulo 2m, the sender goes to the blocking state.
b. If an error-free ACK arrives with ackNo related to one of the outstanding packets, the sender slides the
window (set S f = ackNo), and if all outstanding packets are acknowledged (ackNo = Sn), then the timer is
stopped. If all outstanding packets are not acknowledged, the timer is restarted.
c. If a corrupted ACK or an error-free ACK with ack number not related to the outstanding packet arrives, it is
discarded.
d. If a time-out occurs, the sender resends all outstanding packets and restarts the timer.

Blocking state:- Three events may occur in this case.


a. If an error-free ACK arrives with ackNo related to one of the outstanding packets, the sender slides the
window (set S f = ackNo) and if all outstanding packets are acknowledged (ackNo = Sn), then the timer is
stopped. If all outstanding packets are not acknowledged, the timer is restarted. The sender then
moves to the ready state.
b. If a corrupted ACK or an error-free ACK with the ackNo not related to the outstanding packets arrives, the
ACK is discarded.
c. If a time-out occurs, the sender resends all outstanding packets and restarts the timer.

Receiver: The receiver is always in the ready state. The only variable, Rn, is initialized to 0. Three events
may occur:
a. If an error-free packet with seqNo=Rn arrives, the message in the packet is delivered to the
application layer. The window then slides, Rn = (Rn + 1) modulo 2m. An ACK is sent with ackNo = Rn.
b. If an error-free packet with seqNo outside the window arrives, the packet is discarded, but an ACK
with ackNo = Rn is sent.
c. If a corrupted packet arrives, it is discarded.

[Link] BLDEA’s [Link].P.G.H CET


COMPUTER NETWROKS

Figure 4.15 a: FSMs for Go-Back-N Sender

Figure 4.15 b: FSMs for Go-Back-N Receiver

[Link] BLDEA’s [Link].P.G.H CET


COMPUTER NETWROKS

Selective-Repeat Protocol

The Go-Back-N protocol simplifies the process at the receiver. The receiver keeps track of only
one variable, and there is no need to buffer out-of-order packets, they are simply discarded. This
protocol is inefficient if the network protocol loses a lot of packets. Each time a single packet is lost
or corrupted, the sender resends all outstanding packets, even though some of these packets may
have been received safe and sound but out of order. If the network layer is losing many packets
because of congestion in the network, the resending of all of these outstanding packets makes the
congestion worse and more packets are lost. This has an avalanche effect that may result in the total
collapse of the network.
Another protocol, called the Selective-Repeat (SR) protocol, has been devised which as the name
implies, resends only selective packets, those that are actually lost. The outline of this protocol is shown
in Figure. 4.14

Figure 4.16: Outline of Selective-Repeat

Windows
The Selective-Repeat protocol also uses two windows: a send window and a receive window. First,
the maximum size of the send window is much smaller it is 2m-1. Second, the receive window is the same
size as the send window.
The send window maximum size can be 2m-1. For example, if m = 4, the sequence numbers go
from 0 to 15, but the maximum size of the window is just 8 (it is 15 in the Go-Back-N Protocol). The
Selective-Repeat send window in Figure 4.17 to emphasize the size.
The receive window in Selective-Repeat is totally different from the one in Go-Back-N. The size of
the receive window is the same as the size of the send window (max 2m-1). It allows as many packets as the
size of the receive window to arrive out of order and be kept until there is a set of consecutive packets to
be delivered to the application layer. Because the sizes of the send window and receive window are the
same, all the packets in the send window can arrive out of order and be stored until they can be delivered.
In a reliable protocol the receiver never delivers packets out of order to the application layer.

[Link] BLDEA’s [Link].P.G.H CET


COMPUTER NETWROKS

Figure 4.17: Send window for Selective-Repeat protocol

Figure 4.18 shows the receive window in Selective-Repeat. Those slots inside the window that are shaded
define packets that have arrived out of order and are waiting for the earlier transmitted packet to arrive
before delivery to the application layer.

Figure 4.18: Receive window for Selective-Repeat protocol

FSMs
Figure 4.17 & 4.18 shows the FSMs for the Selective-Repeat protocol. It is similar to the ones for
the GBN, but there are some differences.
Sender
The sender starts in the ready state, but later it can be in one of the two states: ready or blocking.
The following shows the events and the corresponding actions in each state.
Ready state: Four events occur in this case:
a. If a request comes from the application layer, the sender creates a packet with the sequence number
set to Sn. A copy of the packet is stored, and the packet is sent. If the timer is not running, the sender
starts the timer. The value of Sn is now incremented, Sn = (Sn + 1) modulo 2m. If the window is full, Sn = (Sf
+ Ssize) modulo 2m, the sender goes to the blocking state.
b. If an error-free ACK arrives with ackNo related to one of the outstanding packets that packet is marked
as acknowledged. If the ackNo = Sf, the window slides to the right until the Sf points to the first
unacknowledged packet (all consecutive acknowledged packets are now outside the window). If there
are outstanding packets, the timer is restarted otherwise, the timer is stopped.

[Link] BLDEA’s [Link].P.G.H CET


COMPUTER NETWROKS

c. If a corrupted ACK or an error-free ACK with ackNo not related to an outstanding packet arrives, it is
discarded.
d. If a time-out occurs, the sender resends all unacknowledged packets in the window and restarts the
timer.
Blocking state: Three events may occur in this case:
a. If an error-free ACK arrives with ackNo related to one of the outstanding packets, that packet is
marked as acknowledged. In addition, if the ackNo = S f, the window is slid to the right until the Sf points
to the first unacknowledged packet (all consecutive acknowledged packets are now outside the window).
If the window has slid, the sender moves to the ready state.
b. If a corrupted ACK or an error-free ACK with the ackNo not related to outstanding packets arrives, the
ACK is discarded.
c. If a time-out occurs, the sender resends all unacknowledged packets in the window and restarts the
timer.

Figure 4.19: FSM of Sender for Selective-Repeat protocol

Receiver
The receiver is always in the ready state. Three events may occur:
a. If an error-free packet with seqNo in the window arrives, the packet is stored and an ACK with ackNo =
seqNo is sent. If the seqNo = Rn, then the packet and all previously arrived consecutive packets are
delivered to the application layer and the window slides so that the Rn points to the first empty slot.
b. If an error-free packet with seqNo outside the window arrives, the packet is discarded, but an ACK
with ackNo = Rn is returned to the sender. This is needed to let the sender slide its window if some ACKs
related to packets with seqNo < Rn were lost.
c. If a corrupted packet arrives, the packet is discarded.

[Link] BLDEA’s [Link].P.G.H CET


COMPUTER NETWROKS

Figure 4.20: FSM of Receive for Selective-Repeat Protocol

[Link] BLDEA’s [Link].P.G.H CET

You might also like