Transport Layer
Transport Layer
MODULE 3
Transport Layer
• The transport layer in the TCP/IP suite is located between
the application layer and the network layer.
• It provides services to the application layer and receives
services from the network layer.
• Provide logical communication between app processes
running on different hosts
• it is the end-to-end logical vehicle for transferring data from
one point to another in the Internet.
Network vs Transport Layer
• The network layer is responsible for communication at the
computer level (host-to-host communication).
• A network-layer protocol can deliver the message only to the
destination computer.
• The message still needs to be handed to the correct process. This
is done by transport-layer protocol.
• A transport-layer protocol is responsible for delivery of the
message to the appropriate process.
• The destination IP address defines the host among the different
hosts in the world.
• After the host has been selected, the port number defines
one of the processes on this particular host.
Q: differentiate TCP and UDP
Transport layer services
• Process-to-Process Communication
• Addressing: Port Numbers
• Encapsulation and Decapsulation
• Multiplexing and Demultiplexing
• Flow Control
• Error Control
• Congestion Control
Addressing port numbers
• For communication, we must define the local host, local process,
remote host, and remote process.
• The local host and the remote host are defined using IP addresses .
• To define the processes, we need second identifiers, called port
numbers.
• In the TCP/IP protocol suite, the port numbers are integers between
0 and 65,535 (16 bits).
• The client program defines itself with a port number, called the
ephemeral port number.
• The word ephemeral means short-lived and is used because the
life of a client is normally short.
• An ephemeral port number is recommended to be greater than
1,023.
• The server process must also define itself with a port number.
• This port number cannot be chosen randomly.
• TCP/IP has decided to use universal port numbers for servers; these
are called well-known port numbers.
• ICANN has divided the port numbers into three ranges: well-known,
registered, and dynamic (or private).
• The ports ranging from 0 to 1,023 are assigned and controlled by
ICANN. These are the well-known ports.
• The ports ranging from 1,024 to 49,151 are not assigned or controlled
by ICANN. They can only be registered with ICANN to prevent
duplication. These are known as registered ports.
• The ports ranging from 49,152 to 65,535 are neither controlled nor
registered. They can be used as temporary or private port numbers.
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 layers in the Internet are called
user datagrams, segments, or packets, depending on what
transport-layer protocol we use.
• 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.
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; the
transport layer at the destination performs demultiplexing.
• Although there is only one message, we use demultiplexer.
Flow Control
• If the items are produced faster than they can be consumed, the
consumer can be overwhelmed and may need to discard some
items.
• Flow control is related to this issue.
• We need to prevent losing the data items at the consumer site.
• 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.
• One of the solutions is normally to use two buffers: one at the
sending transport layer and the other at the receiving transport layer.
• A buffer is a set of memory locations that can hold packets at the
sender and receiver.
• The flow control communication can occur by sending signals
from the consumer to the producer.
• When the buffer of the sending transport layer is full, it informs the
application layer to stop passing chunks of messages; when there are
some vacancies, it informs the application layer that it can pass
message chunks again.
• When the buffer of the receiving transport layer is full, it informs the
sending transport layer to stop sending packets. When there are some
vacancies, it informs the sending transport layer that it can send
packets again.
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
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 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.
Multiplexing and Demultiplexing
• Transport layer responsible for delivering data segments to
appropriate applications running in a host.
• There can be more than one socket at receiving host and
each socket has a unique identifier.
• Identifier format depends on if the socket is UDP or TCP.
• Each transport layer segment has multiple fields.
• The gathering of data chunk at source host and
encapsulating header information with data chunks to create
segment and passing segments to network layer is called
multiplexing.
• At receiving end transport layer examines field to identify
receiving socket and direct segment to that socket.The job
delivering segment to correct socket is known as
demultiplexing.
• For multiplexing transport layer requires
1. Socket have unique identifier
2. Each segment have field that indicate the socket to which
segment is delivered. Which source and destination port
number. Port number varies from 0 to 65535.
• host receives IP
datagrams each datagram
has source IP address,
destination IP address.
• Each datagram carries
one transport-layer
segment each segment
has source, destination
port number .
Connectionless Multiplexing and Demultiplexing
• DatagramSocket mySocket1 = new DatagramSocket(12534);
• recall: when creating datagram to send into UDP socket, must
specify destination IP address and destination port number
• When host receives UDP segment: checks destination port
number in segment directs UDP segment to socket with that
port number.
• IP datagrams with same dest. port number, but different source
IP addresses and/or source port numbers will be directed to
same socket at destination.
Connection Oriented Multiplexing and Demultiplexing
• TCP socket is identified by 4 tuple (source ip address, source
port number, destination ip address,destination port number).
• First establish connection through welcome socket.
• Once welcomes connection is established and TCP segments
that matches the four values will be demultiplexed to this
socket.
UDP
• UDP take message from application layer adds source and
destination port no along with two other field and send to
network layer.
• no three way handshake.
• DNS uses UDP connection to avoid TCP connection
establishment delays.
• Why prefer UDP over TCP? ( 4 points)
UDP segment structure
• Source Port: Source Port is a 2 Byte long field used to identify
the port number of the source.
• Destination Port: It is a 2 Byte long field, used to identify the
port of the destined packet.
• Length: Length is the length of UDP including the header and
the data. It is a 16-bits field.
• Checksum: Checksum is 2 Bytes long field. It is the 16-bit
one’s complement of the one’s complement sum of the UDP
header, the pseudo-header of information from the IP header,
and the data, padded with zero octets at the end (if necessary)
to make a multiple of two octets.
CHECKSUM
• It is used to check whether bits within the UDP segment has been
altered as it moved from source to destination.
Sender side:
• It treats segment contents as sequence of 16-bit integers.
• All segments are added. Let's call it sum.
• Checksum: 1's complement of sum.(In 1's complement all 0s are converted into 1s and all 1s are
converted into 0s).
• Sender puts this checksum value in UDP checksum field.
Receiver side:
• Calculate checksum
• All segments are added and then sum is added with sender's checksum.
• Check that any 0 bit is presented in checksum. If receiver side checksum contains any 0 then error is
detected. So the packet is discarded by receiver.
As an example, suppose that we have the bit stream 01100110011001100101010101010000111100001111
This bit stream is divided into segments of 16-bits integers.
0110011001100110 (16-bit integer segment)
0101010101010101
0000111100001111
The sum of first of these 16-bit words is:
0110011001100110
0101010101010101
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
1011101110111011
Adding the third word to the above sum gives
1011101110111011
0000111100001111
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
1100101011001010 (sum of all segments)
• Now to calculate checksum 1's complement of sum is taken. As I mentioned
earlier, 1's complement is achieved by converting all 1s into 0s and all 0s into
1s. So, the checksum at sender side is: 0011010100110101.
• Now at the receiver side, again all segments are added .and sum is added with
sender's checksum.
• If any 0 bit is presented in the header than there is an error in checksum. So,
the packet is discarded.
Principles of reliable data transfer