Chapter 1. Introduction to Data Communications
Networks, Security, and Privacy
158.235
A/Prof. Julian Jang-Jaccard
Massey University
Transport
Layer
Reading: Chapter 5 in the prescribed textbook
Transport Layer
• Layer 4 in the Internet
model
• Main function;
– Links application and
network layers
– Responsible for
segmentation and
reassembly
– Connection Management:
end-to-end delivery of
messages
Application
Transport
Network
Data Link
Physical
Internet Model
Outline
• Transport layer functions
– Linking to the application layer
– Segmentation
– Connection Management
Linking to Application Layer
• TCP may serve several Application Layer
protocols at the same time
• Which application layer program to send a
message to?
• Ports used to identify application (2-byte
numbers)
Linking to the application layer
• Many source/destination ports follow
standards
– Common port standards
• HTTP: TCP port 80
• HTTPS: TCP port 443
• FTP: TCP ports 20 and 21
• SMTP: TCP port 25
• IMAP: TCP port 143
• POP3: TCP port 110 (more commonly TCP port
995 secure version)
• DNS: TCP or UDP port 53 (most commonly UDP)
Application Layer Services
Outline
• Transport layer functions
– Linking to the application layer
– Segmentation
– Connection Management
Segmentation
• Segmenting
– Breaking up large application data into
smaller segments (and putting them back
together)
– Segments may be passed individually to
application layer or after reassembly
– How large are the segments?
• Size depends on the network and data link layer protocols
• Maximum Segment Size (MSS) is negotiated during TCP
handshake
Sender PDU Receiver
Application
Packet
Transport Segment
Network Packet
Data
Link
Frame
Transport Layer Functions
Outline
• Transport layer functions
– Linking to the application layer
– Segmentation
– Connection Management
• Connectionless (UDP)
• Connection-oriented (TCP)
• Quality of Service (QoS)
Connection Management
• Connectionless Routing is provided by UDP
– Sending packets individually without a virtual connection,
emphasis on reduced latency over reliability
– Each packet is sent independently of one another, and
will be routed separately, following different routes and
arriving at different times
• Connection Oriented is provided by TCP
– Setting up a virtual connection, or a TCP connection for a
reliable transmission
• Packet deliveries are acknowledged
• Used by HTTP, SMTP, FTP
• QoS Routing
– A special kind connection oriented routing with priorities
User Datagram Protocol (UDP)
• Operates at the transport layer
• PDU called a segment
• Used in time-sensitive situations, for
control messages, or when reliability is
handled by the application layer
• 32-64 bits (4-8 bytes) of overhead
• Source port is optional in IPv4 and IPv6, Checksum
is optional in IPv4
Destination
Port
(16 bits)
Source
Port
(16 bits)
Length
(16 bits)
Checksum
(16 bits)
User
Data
(varies)
UDP – User Datagram Protocol
• “No frills”, “bare bones” transport protocol
• “Best Effort” service
– Can be lost or delivered out-of-order to app
• Connectionless messaging
– No handshaking between UDP sender and receiver
– Each UDP segment handled independently of others
• UDP: Efficiency before reliability
– Used in time-sensitive situations, for control messages,
or when reliability is handled by the application layer
– Commonly used for application control messages that
are usually small, such as DNS, DHCP, RIP and SNMP
– Can also be used for applications where a packet can be
lost, such as information rich video/audio
Transport Layer Protocols
• Transmission Control Protocol (TCP)
– Most common transport layer protocol
– PDU called a segment
– Used for reliable transmission of data
– 160 – 192 bits (20 -24 bytes) of overhead
• Options field is not required
Destination
Port
(16 bits)
Unused
(6 bits)
Source
Port
(16 bits)
Sequence
Number
(32 bits)
ACK
number
(32 bits)
Header
Length
(4 bits)
Flags
(6 bits)
Flow
Control
(16 bits)
CRC-16
(16 bits)
Urgent
Pointer
(16 bits)
Options
(32 bits)
User
Data
(varies)
Reliable Data Transfer
Sequence number
Acknowledgment
Retransmission
Host A Host B
Packet
X
Packet
Packet
Reliable Data Transfer
Timer
Host A Host B
Packet
X
Acknowledgement
Reliable Data Transfer
• Sequence Numbers
– byte stream “number” of first byte in segment’s data
• Acknowledgement Numbers
– seq # of next byte expected from other side
– cumulative ACK
• Timer
– Ensure acknowledgement has received within the
expected time frame
• Retransmission
– Retransmit the data after timeout
SEQ and ACK
User
types
‘C’
host ACKs
receipt
of echoed
‘C’
host ACKs
receipt of
‘C’, echoes
back ‘C’
simple telnet scenario
Host B Host A
Retransmission
lost ACK scenario
Host B Host A
X tim
e
o
u
t
premature timeout
Host B Host A
ti
m
e
o
u
t
SendBase=100
SendBase=120
SendBase=120
SendBase=92
Retransmission
X
cumulative ACK
Host B Host A
ti
m
e
o
u
t
Connection Management
• Before exchanging data, sender/receiver
“handshake”:
• Agree to establish connection (each knowing
the other willing to establish connection)
• Agree on connection parameters
Q: will 2-way
handshake always
work in network?
• can’t “see” other side
• variable delays
• retransmitted
messages (e.g.
req_conn(x)) due to
message loss
• message reordering
2-way handshake:
Let’s talk
OK
ESTAB
ESTAB
choose x
req_conn(x)
ESTAB
ESTAB
acc_conn(x)
Establish a connection
Establish a connection
2-way handshake failure scenarios:
retransmit
req_conn(x)
ESTAB
req_conn(x)
half open connection!
(no client!)
client
terminates
server
forgets x
connection
x completes
retransmit
req_conn(x)
ESTAB
req_conn(x)
data(x+1)
retransmit
data(x+1)
accept
data(x+1)
choose x
req_conn(x)
ESTAB
ESTAB
acc_conn(x)
client
terminates
ESTAB
choose x
req_conn(x)
ESTAB
acc_conn(x)
data(x+1) accept
data(x+1)
connection
x completes server
forgets x
TCP3-way handshake
SYNbit=1, Seq=x
choose init seq num, x
send TCP SYN msg
ESTAB
SYNbit=1, Seq=y
ACKbit=1; ACKnum=x+1
choose init seq num, y
send TCP SYNACK
msg, acking SYN
ACKbit=1, ACKnum=y+1
received SYNACK(x)
indicates server is live;
send ACK for SYNACK;
this segment may contain
client-to-server data
received ACK(y)
indicates client is live
SYNSENT
ESTAB
SYN RCVD
client state
LISTEN
server state
LISTEN
Closing a connection
client, server each close their side of
connection
send TCP segment with FIN bit = 1
respond to received FIN with ACK
on receiving FIN, ACK can be combined with
own FIN
simultaneous FIN exchanges can be
handled
FIN_WAIT_2
CLOSE_WAIT
FINbit=1, seq=y
ACKbit=1; ACKnum=y+1
ACKbit=1; ACKnum=x+1
wait for server
close
can still
send data
can no longer
send data
LAST_ACK
CLOSED
TIMED_WAIT
timed wait
for 2*max
segment lifetime
CLOSED
TCP 4-way handshake
FIN_WAIT_1 FINbit=1, seq=x can no longer
send but can
receive data
clientSocket.close()
client state
server state
ESTAB ESTAB
Setting up and Tearing down
TCP Connections
A B
SYN_SENT
FIN
Connection Establishment
Phase
(via TCP 3-way handshake)
Data Transfer Phase
ACK
ACK
FIN
ACK
Listen
SYN_RSVD
ESTABLISHED
ESTABLISHED
Connection Termination Phase
(via TCP 4-way handshake)
FIN_WAIT1
FIN_WAIT2
CLOSE_WAIT
LAST_ACK
TIME_WAIT
DATA
DATA
CLOSED CLOSED
QoS – Quality of Service
• QoS defines and assigns priorities to “classes of
service”
• Timeliness – timely delivery of packets
– Packets be delivered within a certain period of time (to
produce a smooth, continuous output)
– Required by some applications, especially real time
applications (e.g., voice and video frames)
• QoS routing
– Defines classes of service, each with a different priority:
• Real-time applications such as VoIP- highest
• A graphical file for a Web page – a lower priority
• E-mail – lowest (can wait a long time before delivery)
Protocols Supporting QoS
• TCP/IP protocol suite
– Resource Reservation Protocol (RSVP)
• Sets up virtual circuits for general
purpose real-time applications
– Real-Time Streaming Protocol (RTSP)
• Sets up virtual circuits for audio-video
applications
– Real-Time Transport Protocol (RTP)
• Used after a virtual connection setup by RSVP or RTSP
• Adds a sequence number and a timestamp for helping
applications to synchronize delivery
• Uses UDP (because of its small header) as transport
IP
RTSP RSVP
UDP
RTP
END