The Transport Abstraction
• Transport provides three key services
– Application Multiplexing
Several processes can send and receive data between ports using a
single host-to-host IP link.
– Connection-Orientation
data are sent and received as a seamless stream of bytes, rather
than fixed-size packets
– Error Controlled
packets which are lost or received out-of order are transparent to
the receiving application
• TCP provides all these abstractions
• UDP provides only the first one
2
The Transmission Control Protocol
(TCP)
• End-to-End communication for user processes
• Processes can communicate in a simple stream of
binary data
• Each byte of data will arrive in the order it was
sent
• If some part of the data cannot be received this will be
made explicit by an error being passed to the user code
(e.g. an Exception)
3
Fundamentals of TCP
• Basically a Sliding Window protocol
– Data sent in segments in IP packets
– Very large (32-bit) sequence number
• represents byte offset of segment
4
TCP Process Communication
• Two processes communicating via TCP sockets.
• Each side of a TCP connection has a socket which can be
identified by the pair
< IP_address, port_number >
• Two processes communicating over TCP form a logical
connection that is uniquely identifiable by the two
sockets involved, that is by the combination
< local_IP_address, local_port, remote_IP_address,
remote_port>
6
TCP Facilities
Stream Data Transfer
• From the application's viewpoint, TCP transfers a
contiguous stream of bytes.
• TCP does this by grouping the bytes in TCP
segments, which are passed to IP for
transmission to the destination.
• TCP itself decides how to segment the data and it
may forward the data at its own convenience.
7
TCP Facilities
Reliability
TCP assigns a sequence number to each byte
transmitted, and expects a positive acknowledgment
(ACK) from the receiving TCP.
• If the ACK is not received within a timeout interval, the
data is retransmitted.
• The receiving TCP uses the sequence numbers to
rearrange the segments when they arrive out of order,
and to eliminate duplicate segments.
8
TCP Facilities
Flow Control
• The receiving TCP, when sending an ACK back to the
sender, also indicates to the sender the number of
bytes it can receive beyond the last received TCP
segment, without causing overrun and overflow in its
internal buffers.
• This is sent in the ACK in the form of the highest
sequence number it can receive without problems.
9
TCP Facilities
Multiplexing
• To allow for many processes within a single host to use
TCP communication facilities simultaneously, the TCP
provides a set of addresses or ports within each host.
• Concatenated with the network and host addresses
from the internet communication layer, this forms a
socket.
• A pair of sockets uniquely identifies each connection.
10
TCP Facilities
Logical Connections
• The reliability and flow control mechanisms described
above require that TCP initializes and maintains certain
status information for each data stream.
• The combination of this status, including sockets,
sequence numbers and window sizes, is called a logical
connection.
• Each connection is uniquely identified by the pair of
sockets used by the sending and receiving processes.
11
TCP HEADER
• The SrcPort and DstPort fields identify the source and
destination ports,respectively. These two fields plus the
source and destination IP addresses, combine to
uniquely identify each TCP connection.
• The sequence number identifies the byte in the stream
of data from the sending TCP to the receiving TCP that
the first byte of data in this segment represents.
15
TCP HEADER
• The Acknowledgement number field contains the
next sequence number that the sender of the
acknowledgement expects to receive.
• This is therefore the sequence number plus 1 of the
last successfully received byte of data.
• This field is valid only if the ACK flag is on.
• Once a connection is established the Ack flag is
always on.
16
TCP HEADER
• The Acknowledgement, SequenceNum, and AdvertisedWindow fields are
all involved in TCP's sliding window algorithm.
• The Acknowledgement and AdvertisedWindow fields carry information
about the flow of data going in the other direction.
• In TCP's sliding window algorithm the reciever advertises a window size to
the sender.
• This is done using the AdvertisedWindow field.
• The sender is then limited to having no more than a value of
AdvertisedWindow bytes of un acknowledged data at any given time.
• The receiver sets a suitable value for the AdvertisedWindow based on the
amount of memory allocated to the connection for the purpose of buffering
data
17
TCP HEADER
• The header length gives the length of the header
in 32-bit words. This is required because the
length of the options field is variable.
• The 6-bit Flags field is used to relay control
information between TCP peers. The possible
flags include SYN, FIN, RESET, PUSH, URG, and
ACK.
18
TCP HEADER
• The Checksum covers the TCP segment: the TCP header
and the TCP data. This is a mandatory field that must be
calculated by the sender, and then verified by the
receiver.
• The Option field is the maximum segment size option,
called the MSS. Each end of the connection normally
specifies this option on the first segment exchanged. It
specifies the maximum sized segment the sender wants
to receive.
• The data portion of the TCP segment is optional. 19
The User Datagram Protocol (UDP)
• UDP is a commonly used transport protocol
employed by many types of applications
• A connectionless transport – doesn’t guarantee
either packet delivery or packets arrive in
sequential order
• Bytes are grouped together in discrete packets
not an ordered sequence of bytes using I/O
stream
20
The User Datagram Protocol
(UDP)
• The packet may travel along different path as
selected by the various network routers that
distribute traffic flow (network congestion,
priority of routes and the cost of transmission)
• Possibility of packet missing or discarded exist
• No notification is available to update the status of
delivery
21
UDP Advantages
• UDP communication can be more efficient than
guaranteed-delivery data streams. If the amount is
small and the data is sent frequently, it may make sense
to avoid the overhead of guaranteed delivery
• Overhead to establish connection can be reduced as
compared to TCP
• Real time applications that demand up-to-the-second or
better performance maybe the candidates for UDP,
since fewer delay due to the error checking and flow
control of TCP
22
The User Datagram Protocol (UDP)
• UDP Length: length of datagram in bytes,
including header and data, max is 65,535 bytes
• Checksum: optional -- 16-bit checksum over
header and data, or zero
24
TCP vs. UDP
• How do we send and reconstruct multiple large objects
with each protocol?
25
TCP vs. UDP
How do we send and reconstruct multiple large objects with UDP?
– Fragment objects in to byte blocks
agree a size and add delimiters between objects which
share the same block, number each block and say which
object it belongs to
– Send blocks one at a time
– When a block is received check which object it is for, place it in
a buffer for that object
– When the end block of an object is found, if that object
is complete, return it to the application, if not, request
retransmission of missing blocks
26
TCP vs. UDP
What is UDP useful for?
– Fire-and-Forget data
• informational (time server updates, keep alives)
• wide-area search (service discovery, P2P search)
– Real time data
• Any application where we don’t care about data from
the past, only current data
– voice over IP
– streaming video/audio
– multiplayer games
27