Module 2
Module 2
Transport Layer
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.
• The transport layer acts as a liaison between a client program and a
server program, process-to-process connection .
• It is the end-to-end logical vehicle
• The heart of the TCP/IP protocol suite.
Transport-Layer
Services
• Process-to-Process Communication
• Addressing: Port Numbers
• Encapsulation and Decapsulation
• Multiplexing and Demultiplexing
• Flow Control
• Error Control
• Congestion Control
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).
• A process on the local host (client), needs services from a
process usually on the remote host(server).
• Both processes (client and server) have the same name.
Host-to-host communication Vs
process-to-process communication
• The network layer is responsible (host-to-host communication).
• A network-layer protocol can deliver the message only to the destination
computer.
• A transport-layer protocol is responsible for delivery of the message to
the appropriate process.
• The destination IP address defines the host and the port number
defines one of the processes on this particular host.
Network layer versus transport
layer
Addressing: Port
Numbers
• 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 port numbers.
• 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 (short-lived).
• 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.
• The ports ranging from 49,152 to 65,535 are neither controlled nor registered. They can be used as temporary or private port
numbers .
ICANN stands for Internet Corporation for Assigned Names and Numbers.
It is a nonprofit organization responsible for coordinating the global Domain Name System (DNS), IP address allocation, and other internet
infrastructure functions.
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.
• The transport layer receives the data and adds the
transport-layer header.
• 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
Multiplexing and Demultiplexing
• The transport layer at the source performs multiplexing; the
transport layer at the destination performs 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).
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.
• 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
;there is a need for flow control,
• 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.
• 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
• Since the 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.
• We can add a field to the transport-layer packet to hold the sequence
number of the packet.
• When a packet is corrupted or lost, the receiving transport layer can
somehow inform the sending transport layer to resend that packet
using the sequence number.
• For error control, the sequence numbers are modulo 2m, where m is
the size of the sequence number field in bits.
• The receiver side can send an acknowledgment (ACK) for each of a
collection of 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.
• These two requirements can be combined if we use two numbered
buffers, one at the sender, one at the receiver.
• At the sender, when a packet is prepared to be sent, we use the
number of the next free location, x, in the buffer as the sequence
number of the packet.
• When the packet is sent, a copy is stored at memory location x,
awaiting the acknowledgment from the other end.
• When an acknowledgment related to a sent packet arrives, the
packet is purged and the memory location becomes free.
• At the receiver, when a packet with sequence number y arrives, it is
stored at the memory location y until the application layer is ready to
receive it.
• An acknowledgment can be sent to announce the arrival of packet y.
Sliding Window
• A circle can represent the sequence numbers from 0 to 2^m − 1
• The buffer is represented as a set of slices, called the sliding window, that occupies
part of the circle at any time.
• At the sender site, when a packet is sent, the corresponding slice is marked.
• When an acknowledgment arrives, the corresponding slice is unmarked.
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.
Principles of Congestion Control
• A TCP sender can be slowed down due to congestion within the IP
network; this form of sender control is referred to as congestion
control.
• Specific TCP mechanisms are used to provide for a reliable
data transfer service in the face of packet loss.
• Packet loss typically results from the overflowing of router buffers
as the network becomes congested.
• Packet retransmission thus treats a symptom of network
congestion (the loss of a specific transport-layer segment) but
does not treat the cause of network congestion.
CONGESTION CONTROL
Congestion Window
• The sender window size is determined by the available buffer space in
the receiver (rwnd).
• It is only the receiver that can dictate to the sender the size of the
sender’s window.
TCP/IP Protocol Suite 12
Congestion Window
• Ifthe network cannot deliver the data as fast as it is
created by the sender, it must tell the sender to slow down.
• In other words, in addition to the receiver, the network is
a second entity that determines the size of the sender’s window.
• The sender has two pieces of information:
▪ the receiver-advertised window size
▪ and the congestion window size.
• The actual size of the window is the minimum of these two.
Actual window size = minimum (rwnd, cwnd)
Congestion Policy
• TCP’s general policy for handling congestion is based on three phases:
• Slow start, congestion avoidance, and congestion detection.
a. It sets the value of the threshold to half of the current window size.
b. It reduces cwnd back to one segment.
c. It starts the slow start phase again.
2. If three duplicate ACKs arereceived, there is a weaker
possibility of congestion; a segment may have been dropped but
some segments after that have arrived safely since three duplicate
ACKs are received. This is called fast transmission and fast recovery.
a. It sets the value of the threshold to half of the current window size.
b. It sets cwnd to the value of the threshold (some implementations add
three segment sizes to the threshold).
c. It starts the congestion avoidance phase.
Connectionless and Connection-Oriented Services
• The client and the server first need to establish a logical connection
between themselves.
• The data exchange can only happen after the connection
establishment.
• After data exchange, the connection needs to be turn down.
• We can implement flow control, error control, and congestion control
in a connection oriented protocol.
PROTOCOLS FOR RELIABLE DATA
TRANSFER (unidirectional)
• Simple Protocol
• Stop-and-Wait Protocol
• Go-Back-N Protocol (GBN)
• Selective-Repeat Protocol
States of Simple Protocol
Simple Protocol
Ans: If the system is using GBN, it means that packets 0, 1, and 2 have been received uncorrupted
and
the receiver is expecting packet 3. If the system is using SR, it means that packet 3 has been
received uncorrupted; the ACK does not say anything about other packets.
Bidirectional Protocols:
Piggybacking
• In real life, data packets are normally flowing in both directions: from
client to server and from server to client.
• This means that acknowledgments also need to flow in
both directions.
• A technique called piggybacking is used to improve the efficiency of
the bidirectional protocols.
• When a packet is carrying data from A to B, it can also carry
acknowledgment feedback about arrived packets from B.
Internet Transport-Layer
Protocols
• UDP and TCP
• These protocols are located between the application layer and the
network layer and serve as the intermediary between the application
programs and the network operations.
• UDP is an unreliable connectionless transport-layer protocol used for
its simplicity and efficiency in applications where error control can be
provided by the application-layer process.
• TCP is a reliable connection-oriented protocol that can be used in any
application where reliability is important.
UDP takes messages from the application process, attaches
source and destination port number fields for the
multiplexing/demultiplexing service, adds two other small
fields, and passes the resulting segment to the network
layer.
▪ The network layer encapsulates the transport-layer
segment into an IP datagram and then makes a best-effort
attempt to deliver the segment to the receiving host.
▪ If the segment arrives at the receiving host, UDP uses the
destination port number to deliver the segment’s data to the
correct application process.
▪ Note that with UDP there is no handshaking between
sending and receiving transport-layer entities before
sending a segment. For this reason, UDP is said to be
connectionless.
Many applications are better suited for UDP for the
following reasons:
1. application-level control over what data is sent, and
when.
2. No connection establishment-UDP does not introduce
any delay to establish a connection. This is probably
the principal reason why DNS runs over UDP rather
than TCP.
3. No connection state.
4. Small packet header overhead. The TCP segment has
20 bytes of header overhead in every segment,
whereas UDP has only 8 bytes of overhead.
Explanation
application-level control over what data is sent, and when
an application process passes data to UDP, UDP will
package the data inside a UDP segment and immediately
pass the segment to the network layer.
0100101011000001
1
-----------------------
0100101011000010
Note that this last addition had overflow, which was wrapped
around.
At the receiver, all four 16-bit words are added, including the
checksum. If no errors are introduced into the packet, then
clearly the sum at the receiver will be 1111111111111111.
IP
header
Fram
e
heade
r
TCP
payload IP
payload
Data-link layer payload
TCP/IP Protocol Suite 69
TCP Connection phases
• TCP is connection-oriented.
• In TCP, connection-oriented transmission requires three phases:
• connection establishment
• data transfer
• connection termination.
Connection Establishment
• TCP at one end may deny a connection request, may abort an existing
connection, or may terminate an idle connection.
• All of these are done with the RST (reset) flag.
Mechanisms for reliable data transfer
• Checksum
• Used to detect bit errors in a transmitted packet.
• Timer
• Used to timeout/retransmit a packet, possibly because the packet (or its ACK) was
lost within the channel.
• Sequence number
• Used for sequential numbering of packets of data flowing from sender to receiver.
• Acknowledgment
• Used by the receiver to tell the sender that a packet or set of packets has been
received correctly.
• Negative acknowledgment
• Used by the receiver to tell the sender that a packet has not been received
correctly.
• Window, pipelining
• The sender may be restricted to sending only packets with sequence numbers that
SYN Flooding Attack