0% found this document useful (0 votes)
0 views61 pages

Lect6-0-TCP and UDP Fundamentals_Sadick

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1/ 61

CN 211: COMPUTER

NETWORKING PROTOCOLS

TCP and UDP Fundamentals


TCP and UDP Fundamentals
• TCP frame format.
• UDP frame format.
• Connection oriented vs. connectionless
protocols.
• Reliable and un-reliable protocols.
• The use of port numbers/addressing.
• Connection-opening and closing.
• Segmentation of data and data sequencing.
• Error recovery, Flow control using windowing.
Introduction to TCP and UDP
• Transmission Control Protocol (TCP)
— connection-oriented protocol that ensures reliable,
ordered, and error-checked delivery of data between
applications.
— It establishes a connection through a three-way
handshake before data transfer and manages
retransmissions if data packets are lost.
— Key Features
• Reliable and ensures data is delivered without errors.
• Guarantees the correct order of data packets.
• Supports flow control and congestion management.
—Use Cases
• File transfer protocols (FTP, SFTP).
• Web browsing (HTTP, HTTPS).
• Email services (SMTP, IMAP, POP3).
Introduction to TCP and UDP
• User Datagram Protocol (UDP)
— connectionless protocol that provides fast,
lightweight communication without guaranteeing
reliability or order.
— It does not establish a connection and skips error
recovery mechanisms to prioritize speed.

— Key Features
• Low latency and minimal overhead.
• No guarantee of delivery or packet order.
• Suitable for real-time and time-sensitive data transmission.
—Use Cases
• Live video and audio streaming (e.g., YouTube, Zoom).
• Online gaming.
• Domain Name System (DNS) queries.
• Voice over IP (VoIP).
TCP frame format
• Transmission Control Protocol (TCP) is the
transport layer protocol in the TCP/IP suite, which
provides a reliable stream delivery and virtual
connection service to applications through the
use of sequenced acknowledgment with
retransmission of packets when necessary.

• Along with the Internet Protocol (IP), TCP


represents the heart of the Internet protocols.
TCP frame format
• Since many network applications may be running on the
same machine, computers need something to make
sure the correct software application on the destination
computer gets the data packets from the source
machine, and some way to make sure replies get routed
to the correct application on the source computer.

• This is accomplished through the use of the TCP “port


numbers”.

• The combination of IP address of a network station and


its port number is known as a “socket” or an “endpoint”.
TCP frame format
• TCP establishes connections or virtual circuits
between two “endpoints” for reliable communications.

• Among the services TCP provides are:-


— Stream data transfer.
— Reliability.
— Efficient flow control.
— Full-duplex operation, and
— Multiplexing.

• With stream data transfer: TCP delivers an


unstructured stream of bytes identified by sequence
numbers.
TCP frame format
• This service benefits applications because the
application does not have to chop data into blocks
before handing it off to TCP.

• TCP can group bytes into segments and pass them to IP


for delivery.

• TCP offers reliability by: providing connection-


oriented, end-to-end reliable packet delivery.

• It does this by sequencing bytes with a forwarding


acknowledgment number that indicates to the
destination the next byte the source expects to receive.
TCP frame format
• Bytes not acknowledged within a specified time period
are retransmitted.

• The reliability mechanism of TCP allows devices to deal


with lost, delayed, duplicate, or misread packets.

• A time-out mechanism allows devices to detect lost


packets and request retransmission.

• TCP offers efficient flow control - When sending


acknowledgments back to the source, the receiving TCP
process indicates the highest sequence number it can
receive without overflowing its internal buffers.
TCP frame format
• Full-duplex operation: TCP processes can both
send and receive packets at the same time.

• Multiplexing in TCP: Numerous simultaneous


upper-layer conversations can be multiplexed
over a single connection.
TCP frame format
TCP frame format
TCP frame format
• Source port -- Identifies points at which upper-
layer source process receives TCP services.

• Destination port -- Identifies points at which


upper-layer Destination process receives TCP
services.

• Sequence number -- Usually specifies the


number assigned to the first byte of data in the
current message.

• In the connection-establishment phase, this field


also can be used to identify an initial sequence
number to be used in an upcoming transmission.
TCP frame format
• Acknowledgment number – Contains the
sequence number of the next byte of data the
sender of the packet expects to receive.

• Once a connection is established, this value is


always sent.

• Data offset -- 4 bits. The number of 32-bit words in


the TCP header indicates where the data begins.

• Reserved -- 6 bits. Reserved for future use. Must be


zero.
TCP frame format
• Control bits (Flags) -- 6 bits. Carry a variety of
control information. The control bits may be:-
— U (URG) Urgent pointer field significant.
— A (ACK) Acknowledgment field significant.
— P (PSH) Push function.
— R (RST) Reset the connection.
— S (SYN) Synchronize sequence numbers.
— F (FIN) No more data from sender.

• Window -- 16 bits. Specifies the size of the


sender’s receive window, that is, the buffer space
available in octets for incoming data.
TCP frame format
• Checksum -- 16 bits. Indicates whether the header
was damaged in transit.

• Urgent Pointer -- 16 bits. Points to the first urgent


data byte in the packet.

• Option + Paddling – Specifies various TCP options.


There are two possible formats for an option: a single
octet of option type; an octet of option type, an octet
of option length and the actual option data octets.

• Data – contains upper-layer information.


UDP frame format
• User Datagram protocol (UDP) is a
connectionless transport layer (layer 4) protocol
in the OSI model which provides a simple and
unreliable message service for transaction-
oriented services.

• UDP is basically an interface between IP and


upper-layer processes.

• UDP protocol ports distinguish multiple


applications running on a single device from one
another.
UDP frame format
• Since many network applications may be running on
the same machine, computers need something to
make sure the correct software application on the
destination computer gets the data packets from the
source machine and some way to make sure replies
get routed to the correct application on the source
computer.

• This is accomplished through the use of the UDP


“port numbers”.

• For example, if a station wished to use a Domain


Name System (DNS) on the station 128.1.123.1, it
would address the packet to station 128.1.123.1 and
insert destination port number 53 in the UDP header.
UDP frame format
• The source port number identifies the application
on the local station that requested domain name
server, and all response packets generated by
the destination station should be addressed to
that port number on the source station.

• Unlike TCP, UDP adds no reliability, flow-control,


or error-recovery functions to IP. Because of
UDP’s simplicity, UDP headers contain fewer
bytes and consume less network overhead than
TCP.
UDP frame format
• UDP is useful in situations where the reliability
mechanisms of TCP are not necessary, such as in
cases where a higher-layer protocol or
application might provide error and flow control.

• UDP is the transport protocol for several well-


known application layer protocols, including
Network File System (NFS), Simple Network
Management Protocol (SNMP), Domain Name
System (DNS), and Trivial File Transfer Protocol
(TFTP).
UDP frame format
UDP frame format
UDP frame format
• Source port – 16 bits. Source port is an optional
field.

• When used, it indicates the port of the sending


process and may be assumed to be the port to
which a reply should be addressed in the
absence of any other information. If not used, a
value of zero is inserted.

• Destination port – 16 bits. Destination port has


a meaning within the context of a particular
Internet destination address.
UDP frame format
• Length – 16 bits. The length in octets of this user
datagram, including this header and the data.
The minimum value of the length is eight.

• Checksum -- 16-bits The sum of a pseudo


header of information from the IP header, the
UDP header and the data, padded with zero
octets at the end, if necessary, to make a
multiple of two octets.

• Data – Contains upper-level data information.


Connection oriented vs. connectionless
protocols
• The Transport layer can be connectionless or
connection-oriented.

• Both a connection-oriented (TCP) and


connectionless (UDP) protocol are Transport layer
protocols.

• But, TCP and UDP have differences in their


operation at Transportation layer.

• The differences between TCP and UDP are:-


Connection oriented vs. connectionless
protocols
TCP UDP

Sequenced Unsequenced

Reliable Unreliable

Connection-oriented Connectionless

Virtual circuit Low overhead

Acknowledgments No acknowledgment

Windowing flow control No windowing or flow control


Reliable and un-reliable protocols.
• TCP Provides a reliable service with error correction
and flow control .

• The cost of providing a reliable service is more overhead


in connection setup and closedown, processing power
for correcting errors and data transmission, but some
applications need reliability irrespective of cost.

• UDP Just extends IP’s connectionless datagram service


to applications that do not require reliability .

• UDP datagrams can be sent to a network without the


overhead of creating and maintaining a connection.
Reliable and un-reliable protocols.
• In fundamental, reliable, connection-oriented
data transfer, datagrams are delivered to the
receiving host in exactly the same sequence
they’re transmitted—and the transmission fails if
this order is breached!

• If any data segments are lost, duplicated, or


damaged along the way, a failure will transmit.

• This problem is solved by having the receiving


host acknowledge that it has received each and
every data segment.
Reliable and un-reliable protocols.
• Unlike TCP, UDP adds no reliability, flow-control,
or error-recovery functions to IP.

• Because of UDP’s simplicity, UDP headers


contain fewer bytes and consume less network
overhead than TCP.
The use of port numbers
• TCP and UDP must use port numbers to
communicate with the upper layers, because
they’re what keeps track of different conversations
crossing the network simultaneously.

• Originating source port numbers are dynamically


assigned by the source host and will equal some
number starting at 1024.

• 1023 and below are defined in RFC 3232 (or just


see www.iana.org), which discusses what are
called well-known port numbers.
The use of port numbers
• Virtual circuits that don’t use an application with
a well-known port number are assigned port
numbers randomly from a specific range instead.

• These port numbers identify the source and


destination application or process in the TCP
segment.
Port addressing
• Key uses of ports
—Identifying Services:
• Port numbers enable a device to distinguish between
different services or applications running simultaneously.
• For example:
– Port 80 is typically used for HTTP (web traffic).
– Port 443 is used for HTTPS (secure web traffic).
—Facilitating Multiplexing and Demultiplexing:
• Multiplexing: Multiple applications can send data over
the same network simultaneously using unique port
numbers.
• Demultiplexing: The receiver uses port numbers to
deliver incoming data to the correct application.
Port addressing
• Key uses of ports
—Enabling Communication Between Hosts:
• Port numbers allow two devices to establish a connection
for a specific service.
• Example: A web browser (client) sends a request to a
web server on port 80, and the server sends a response
back to the browser.
—Supporting Connection Management:
• TCP uses port numbers during the connection
establishment (via a three-way handshake) to identify
the applications involved in the communication.
—Distinguishing Between Multiple Connections:
• A single device can maintain multiple connections with
different remote hosts or even with the same host using
different port numbers.
Port addressing
• The well-known ports are managed by the
Internet Assigned Numbers Authority (IANA) -
RFC 3232 (or just see www.iana.org).

• Virtual circuits that don’t use an application with


a well-known port number are assigned port
numbers randomly from a specific range instead.

• These port numbers identify the source and


destination application or process in the TCP
segment.
Port addressing

Source and Destination Port Number


Port addressing (Request)
Source Port Source Port ǥǤ
ǤǤ

Host Web Server

SP DP

2024 80 ǥǤ
Ǥ

Define virtual circuit Define upper layer


process or application

Source and Destination Port Number


Port addressing (Response)
Source Port Source Port ǥǤ
ǤǤ

Host Web Server

SP DP

80 2024 ǥǤ
Ǥ

Define upper layer


Define virtual circuit
process or application

Source and Destination Port Number


Port addressing
• The Summary of different port numbers that can
be used are:

— Numbers below 1024 are considered well-known port


numbers and are defined in RFC 3232.

— Numbers 1024 and above are used by the upper layers


to set up sessions with other hosts, and by TCP to use
as source and destination addresses in the TCP
segment.
Port addressing

Port numbers for TCP and UDP


Connection-opening and closing
• An entity may transmit data to another entity in
such a way that each PDU is treated
independently of all prior PDUs.

• This process is known as connectionless data


transfer; an example is the use of the datagram.

• While this mode is useful, an equally important


technique is connection-oriented data transfer, of
which the virtual circuit is an example.
Connection-opening and closing
• Connection-oriented data transfer is to be
preferred (even required) if stations anticipate a
lengthy exchange of data and/or certain details
of their protocol must be worked out dynamically.

• A logical association, or connection, is


established between the entities.

• Three phases occur:-


i. Connection establishment
ii. Data transfer
iii. Connection termination
Connection-opening and closing

The phases of a connection-oriented data


Connection-opening and closing
• During the connection establishment phase, two
entities agree to exchange data.

• Typically, one station will issue a connection


request (in connectionless fashion!) to the other.

• A central authority may or may not be involved.

• In simpler protocols, the receiving entity either


accepts or rejects the request and, in the former
case, away they go.
Connection-opening and closing
• In more complex proposals, this phase includes a
negotiation concerning the syntax, semantics, and
timing of the protocol.

• Both entities must, of course, be using the same


protocol.

• But the protocol may allow certain optional features,


and these must be agreed upon by means of
negotiation.

• For example, the protocol may specify a PDU size of


up to 8000 octets; one station may wish to restrict
this to 1000 octets.
Connection-opening and closing
• Following connection establishment, the data
transfer phase is entered; here, both data and
control information (e.g., flow control, error
control) are exchanged.

• The figure shows a situation in which all of the


data flows in one direction, with
acknowledgments returned in the other direction.

• More typically, data and acknowledgments flow


in both directions.
Connection-opening and closing
• Finally, one side or the other wishes to terminate
the connection and does so by sending a
termination request.

• Alternatively, a central authority might forcibly


terminate a connection.

• The key characteristic of connection-oriented data


transfer is that sequencing is used.

• Each side sequentially numbers the PDUs that it


sends to the other side.
Connection-opening and closing
• Because each side remembers that it is engaged in a
logical connection: it can keep track of both outgoing
numbers, which it generates, and incoming numbers,
which are generated by the other side.

• Indeed, one can essentially define a connection


oriented data transfer as one in which both sides
number PDUs and keep track of the incoming and
outgoing numbers.

• Sequencing supports three main functions: ordered


deliver, flow control, and error control.
Segmentation of data and data sequencing
• A protocol is concerned with exchanging streams of data
between two entities.

• Usually, the transfer can be characterized as consisting of


a sequence of blocks of data of some bounded size.

• At the application level, we refer to a logical unit of data


transfer as a message.

• Now, whether the application entity sends data in


messages or in a continuous stream, lower-level protocols
may need to break the data up into blocks of some smaller
bounded size: this process is called segmentation.
Segmentation of data and data sequencing
• For convenience, we refer to a block of data
exchanged between two entities via a protocol as
a protocol data unit (PDU).

• There are a number of motivations for


segmentation, depending on the context.

• Among the typical reasons for segmentation are:-


— The communications network may only accept blocks of
data up to a certain size. For example, an ATM network
is limited to blocks of 53 octets; Ethernet imposes a
maximum size of 1526 octets.
Segmentation of data and data sequencing
— Error control may be more efficient with a smaller PDU size.
For example, fewer bits need to be retransmitted using
smaller blocks with the selective repeat technique.

— More equitable access to shared transmission facilities, with


shorter delay, can be provided. For example, without a
maximum block size, one station could monopolize a
multipoint medium.

— A smaller PDU size may mean that receiving entities can


allocate smaller buffers.

— An entity may require that data transfer comes to some sort


of closure from time to time, for checkpoint and
restart/recovery operations.
Segmentation of data and data sequencing
• There are several disadvantages to segmentation that
argue for making blocks as large as possible:-
— Each PDU, as we shall see, contains a fixed minimum amount
of control information. Hence, the smaller the block, the
greater the percentage overhead.

— PDU arrival may generate an interrupt that must be serviced.


Smaller blocks result in more interrupts.

— More time is spent processing smaller, more numerous PDUs.

• All of these factors must be taken into account by the


protocol designer in determining minimum and
maximum PDU size.
Segmentation of data and data sequencing
• The counterpart of segmentation is reassembly.

• Eventually, the segmented data must be reassembled into


messages appropriate to the application level.

• If PDUs arrive out of order, the task is complicated.

• But by using sequence number the PDUs that it sends to the


other side can be assured of reassembling.

• sequencing Used in virtual circuits and segmentation to


number segments so they can be put back together again
in the correct order.
Segmentation of data and data sequencing
• Since each side remembers that it is engaged in a
logical connection: it can keep track of both outgoing
numbers, which it generates, and incoming numbers,
which are generated by the other side.

• Indeed, one can essentially define a connection-


oriented data transfer as one in which both sides
number PDUs and keep track of the incoming and
outgoing numbers.

• Sequencing supports three main functions: ordered


deliver, flow control, and error control.
Ordered Delivery
• If two communicating entities are in different hosts
connected by a network, there is a risk that PDUs will
not arrive in the order in which they were sent,
because they may traverse different paths through
the network.

• In connection-oriented protocols, it is generally


required that PDU order be maintained.

• If each PDU is given a unique number, and numbers


are assigned sequentially, then it is a logically simple
task for the receiving entity to reorder received PDUs
on the basis of sequence number.
Error recovery
• Techniques are needed to guard against loss or
damage of data and control information.

• Most techniques involve error detection, based on


a frame check sequence, and PDU retransmission.

• Retransmission is often activated by a timer.

• If a sending entity fails to receive an


acknowledgment to a PDU within a specified
period of time, it will retransmit.
Error recovery
• Error control is a function that must be performed
at various levels of protocol.

• The network access protocol should include error


control to assure that data are successfully
exchanged between station and network.

• However, a packet of data may be lost inside the


network, and the process-to-process protocol
should be able to recover from this loss.
Flow control using windowing
• Flow control is a function performed by a receiving
entity to limit the amount or rate of data that is sent
by a transmitting entity.

• The simplest form of flow control is a stop-and-wait


procedure, in which each PDU must be
acknowledged before the next can be sent.

• More efficient protocols involve some form of credit


provided to the transmitter, which is the amount of
data that can be sent without an acknowledgment.
Flow control using windowing
• The sliding-window technique is an example of
this mechanism.

• Flow control is a good example of a function that


must be implemented in several protocols.

• Consider a figure below, the network will need to


exercise flow control over station 1's network
services module via the network access protocol,
in order to enforce network traffic control.
Flow control using windowing
Flow control using windowing
• At the same time, station 2's network services
module has only limited buffer space and needs to
exercise flow control over station 1's network
services module via the process-to-process protocol.

• Finally, even though station 2's network service


module can control its data flow, station 2's
application may be vulnerable to overflow.

• For example, the application could be hung up


waiting for disk access. Thus, flow control is also
needed over the application-oriented protocol.
Feature by Feature Comparison – TCP vs UDP

You might also like