0% found this document useful (0 votes)
20 views59 pages

Transport Layer Protocols-1

The document provides an overview of transport layer protocols, focusing on UDP (User Datagram Protocol) and TCP (Transmission Control Protocol). It discusses key concepts such as multiplexing, demultiplexing, reliable data transfer, flow control, and congestion control, highlighting the differences between connectionless and connection-oriented transport. Additionally, it outlines the structure of transport layer segments and the principles of reliable data transfer, including the importance of sequence numbers and acknowledgments in TCP.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views59 pages

Transport Layer Protocols-1

The document provides an overview of transport layer protocols, focusing on UDP (User Datagram Protocol) and TCP (Transmission Control Protocol). It discusses key concepts such as multiplexing, demultiplexing, reliable data transfer, flow control, and congestion control, highlighting the differences between connectionless and connection-oriented transport. Additionally, it outlines the structure of transport layer segments and the principles of reliable data transfer, including the importance of sequence numbers and acknowledgments in TCP.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

Computer Networks:

Transport Layer Protocols

Rajesh Palit, Ph.D.


North South University, Dhaka

Transport Layer 3-1


Chapter 3: Transport Layer
our goals:
• understand principles • learn about Internet
behind transport transport layer protocols:
layer services: • UDP: connectionless
• multiplexing, transport
demultiplexing • TCP: connection-oriented
• reliable data transfer reliable transport
• flow control • TCP congestion control
• congestion control

Transport Layer 3-2


Transport services and protocols
application
transport
provide logical communication network
data link
between app processes running physical

on different hosts
transport protocols run in end
systems
 send side: breaks app
messages into segments,
passes to network layer
 rcv side: reassembles
segments into messages, application
transport
passes to app layer network
data link

more than one transport physical

protocol available to apps


 Internet: TCP and UDP
Transport Layer 3-3
Transport vs. network layer
network layer: household analogy:
logical
communication 12 kids in Ann’s house
sending letters to 12 kids in
between hosts Bill’s house:
transport layer: • hosts = houses
logical • processes = kids
communication • app messages = letters in
between processes envelopes
 relies on, enhances, • transport protocol = Ann
network layer and Bill who mux/demux to
services in-house siblings
• network-layer protocol =
postal service

Transport Layer 3-4


Internet transport-layer protocols
application
• reliable, in-order transport
network
data link
delivery (TCP) physical
network

• congestion control network


data link
data link
physical
physical
• flow control network
data link
physical
• connection setup network
data link
• unreliable, unordered physical
network

delivery: UDP network


data link
physical

• no-frills extension of data link


physical
network
application
transport

“best-effort” IP data link


physical
network
data link
physical

• services not available:


• delay guarantees
• bandwidth guarantees
Transport Layer 3-5
Multiplexing/demultiplexing
multiplexing at sender:
handle data from multiple demultiplexing at receiver:
sockets, add transport header use header info to deliver
(later used for demultiplexing) received segments to correct
socket

application

application P1 P2 application socket


P3 transport P4
process
transport network transport
network link network
link physical link
physical physical

Transport Layer 3-6


How Mux/DeMux Work?
• Suppose you are downloading Web pages while running one
FTP session and two Telnet sessions. You therefore have four
network application processes running -- two Telnet
processes, one FTP process, and one HTTP process. When the
transport layer in your computer receives data from the
network layer below, it needs to direct the received data to
one of these four processes.

• This job of delivering the data in a transport-layer segment to


the correct application process is called de-multiplexing. The
job of gathering data at the source host from different
application processes, enveloping the data with header
information to create segments, and passing the segments to
the network layer is called multiplexing.
Transport Layer 3-7
Two Protocols in the Transport Layer
Transport layer
UDP TCP
Network Layer
 UDP (User Datagram Protocol)  TCP (Transmission Control P’col)
 connectionless transport  connection-oriented transport
Connect – Data Tx
send, send, -- Disconnect
send, …

App App App App


TCP TCP
UDP UDP
unreliable reliable

Net. Layer Net. Layer Net. Layer Net. Layer

3-8
Unreliable UDP vs. Reliable TCP
UDP TCP

If segments arrive out-of-sequence


If segments arrive out-of-sequence
from network layer,
from network layer,
the receiver does not reorder them.
the receiver reorders them.

If a segment is missing from a


If a segment is missing from a
sequence, the sender does not
sequence, the sender eventually
retransmit it.
retransmits it.

Segments are not ACKed.


Segments are ACKed by receiver.

No flow control is performed. Flow control is performed.

No congestion control is performed. Congestion control is performed.

9
Chapter 3 outline
3.5 connection-oriented
3.1 transport-layer services transport: TCP
3.2 multiplexing and  segment structure
demultiplexing  reliable data transfer
3.3 connectionless transport: UDP  flow control
 connection management
3.4 principles of reliable data
transfer 3.6 principles of congestion
control
3.7 TCP congestion control

Transport Layer 3-10


UDP: User Datagram Protocol [RFC 768]

RIP

SNMP
(Simple Network
Management
Protocol)

Transport Layer 3-11


UDP: segment header
length, in bytes of
32 bits UDP segment,
source port # dest port # including header

length checksum
why is there a UDP?
no connection establishment
application (which can add delay)
data
simple: no connection state
(payload)
at sender, receiver
small header size
no congestion control: UDP
UDP segment format can blast away as fast as
desired

Transport Layer 3-12


UDP checksum
Goal: detect “errors” (e.g., flipped bits) in
transmitted segment
sender: receiver:
• treat segment contents, • compute checksum of received
including header fields, as segment
sequence of 16-bit integers
• check if computed checksum
• checksum: addition (one’s
complement sum) of equals checksum field value:
segment contents • NO - error detected
• sender puts checksum value • YES - no error detected. But
into UDP checksum field maybe errors nonetheless?
More later ….

Transport Layer 3-13


Internet checksum: example

example: add two 16-bit integers


1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0
1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1

wraparound 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1

sum 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0
checksum 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1

Note: when adding numbers, a carryout from the most


significant bit needs to be added to the result

Transport Layer 3-14


Chapter 3 outline
3.5 connection-oriented
3.1 transport-layer services transport: TCP
3.2 multiplexing and  segment structure
demultiplexing  reliable data transfer
3.3 connectionless transport: UDP  flow control
 connection management
3.4 principles of reliable data
transfer 3.6 principles of congestion
control
3.7 TCP congestion control

Transport Layer 3-15


Principles of reliable data transfer
• important in application, transport, link layers
• top-10 list of important networking topics!

• characteristics of unreliable channel will determine complexity of reliable data


transfer protocol (rdt)

Transport Layer 3-16


TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581

socket
application
writes data
application
reads data
socket
• Full-duplex data
door
TCP
send buffer
TCP
receive buffer
door
• bi-directional data flow over
segment same connection

• point-to-point • Connection-oriented
• one sender, one receiver – handshaking (exchange of
control msgs) initializes sender
and receiver states before data
• reliable byte stream exchange
– no “message boundaries”
• Flow controlled
– sender will not overwhelm
• pipelined receiver
– TCP congestion and flow
• Congestion controlled
control set window size
– sender will not overwhelm
receiver
Transport Layer
What is a TCP connection?
Comm.
Networks +
protocols  TCP conn.
Receiver
Sender Receiver Sender
abstraction process process
process process

A connection is identified by (Src Port + Src IP, Dst Port + Dst IP).
A connection has well-defined start and finish events.
Communication parameters are exchanged to establish a
connection: ISN (Initial Sequence Number), RWND (Receive
Window Size), MSS (Maximum Segment Size)

Receiver discards data associated with an old connection (say,


estd. 0.5s back and reset)
TCP Sender gets a confirmation of delivery via an ACK.
TCP Receiver delivers exactly one copy of sender’s data by means of
timeout, retransmission, ACK, sequence #s, and buffering mechanisms.
Flow control: receiver controls its recv. window size.
Congestion control: Timeouts trigger congestion control. 18
TCP: Application Context

Client Server
Read/Write Read/Write
Port/socket Port/socket
Connection
TCP TCP
Internet
IP/Link/PHY IP/Link/PHY

Ports
- Reserved for well-known services
- Telnet/23, SMTP/25, FTP/20,21, HTTP/80,
BGP/179, lp/515
- Free ports 19
Example: A file is viewed as a stream of bytes.
In fact, data produced by any source is considered as a stream of bytes.
Bytes have individual IDs.  Bytes are individually numbered.

ISN+1 ISN+10 ISN+16 ISN+26 ISN+30

ISN: Initial Sequence Number


20
Piggybacking
Data

ACK
Client
Server
Data

ACK

Small segments produce extra overhead:


transmission and processing at routers.

Data

Client
Server
Data

21
TCP Segment Header
0 4 10 16 24 31 (bit number)
Source Port Destination Port
Sequence Number H
Acknowledgment Number
e
Header A R F
a
Length
Reserved
U P S Window size d
Checksum Urgent Pointer e
Options
MSS, Window ( Time stamp,…
Scale, r
) Padding

Data
U: URG (Urgent)
A: ACK S=1  Seq. num. field carries ISN to be used
P: PSH (Push) S=0  Seq. num. = Seq. # of the first data byte in seg.
R: RST (Reset) MSS: Maximum Segment Size
S: SYN (Sync.)
F: FIN (Finish) 22
TCP: Header
• Source/destination Ports
• Port: A 16 bit local unique number on the host
• Port + Host IP => Unique end point of an application
• (Src Port + IP, Dst Port + IP): Unique connection ID
• Source and destination IP: NOT part of a TCP segment
• 32-bit seq. number
• SYN = 0 (DATA segment)
• Position of the first data byte of this segment in the sender’s data
stream
• SYN = 1
• ISN to be used in the sender’s byte stream. (in fact, ISN+1)
• Different each time a host requests a connection

23
TCP seq. numbers, ACKs
outgoing segment from sender
sequence numbers: source port # dest port #
sequence number
• byte stream “number” of acknowledgement number
rwnd
first byte in segment’s checksum urg pointer
data window size
N
acknowledgements:
• seq # of next byte
expected from other side sender sequence number space

• cumulative ACK sent sent, not- usable not


ACKed yet ACKed but not usable
Q: how receiver handles out- (“in- yet sent
flight”)
of-order segments incoming segment to sender
• A: TCP spec doesn’t say, - source port # dest port #
sequence number
up to implementor acknowledgement number
A rwnd
checksum urg pointer

Transport Layer 3-24


TCP: Header
• 32-bit ACK number
• Valid if ACK = 1
• Identifies the sequence number of the NEXT data byte that the
sender of the ACK expects to receive.
• Header length in 4-byte units
• Lets the receiver know the beginning of the data area due to the
variable length of the Option field.
• Reserved (6 bits)
• For future use. All 0’s.

25
TCP: Header
• URG: ‘1’ => Urgent Pointer is valid
• ACK: ‘1’ => ACK Seq# is valid
• PSH:
• ‘1’: The receiving TCP module passes the data to the application
immediately
• ‘0’: The receiving TCP module may delay the data
• RST: ‘1’ => Tells the receiver to abort the conn.
• SYN: This bit requests a connection
• FIN
• ‘1’: Sender has no more data to send, but is ready to receive.

26
TCP: Header
• Window Size
• The number of bytes the sender is willing to receive.
• Used in flow control and congestion control

• Checksum: For error detection; scope: complete seg.


• Urgent Pointer: Valid if URG = ‘1’
• Urgent data
• Start byte is not specified, but it is considered to be the start of the seg.
• Final byte in receiver’s buffer: Seq# + Urgent Ptr.
• The sender can send “control” information to the receiver to be processed
on a priority basis.

27
TCP: Header
• Options
• MSS
• The Max Segment Size accepted by the sender
• Specified during connection set up
• Window Scale
• Allows the use of a larger advertised Window Size
• Time Stamp
• Used in Round-Trip Time (RTT) calculation
• Intended to be used on high-speed connection
• Sequence number may wrap around during a connection.
• New segments are distinguished from old segments by means of
time stamps

28
TCP Conn.: Established in two ways

Server Client Peer Peer

Listen Actively open Active Active


(Passive) a conn.

The server must be running, and attached to a known port.


Example: An HTTP server is attached to TCP at port #80.

29
TCP Connection: 3-way handshake
• Use these fields to understand the opening of a
conn.
• Connection request (SYN)
• Sequence number (ISN)
• Acknowledgement (ACK)
• Receive window size (RWND)

30
TCP Connection: 3-way handshake

Client Server

Passive open
Active open Seg(Seq# = 8000,SYN) Listen()
Connect()

Seg(Seq# =15000, Ack = 8001, 5000 bytes


10,000 bytes SYN+ACK, RWND = 5000) Receive buffer
Receive buffer

Seg(Seq# = 8000, Ack = 15001,


Conn. open ACK, RWND = 10000)

for data transfer Conn. open

31
TCP Connection: 3-way handshake
• SYN segment from client to server
• SYN = 1
• A random initial Seq# (ISN)
• RWND is undefined (defined later …)
• Options
• SYN+ACK segment from server to client
• SYN = 1
• A random initial Seq# (ISN)
• ACK = 1 (server acks the received SYN segment)
• Ack Seq.#: The sequence # of first data byte to be received
• RWND: Receive window size
• ACK from client to server
• ACKs the second SYN segment
• RWND

32
TCP: 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

Transport Layer 3-33


TCP: closing a connection
client state server state
ESTAB ESTAB
clientSocket.close()
FIN_WAIT_1 can no longer FINbit=1, seq=x
send but can
receive data CLOSE_WAIT
ACKbit=1; ACKnum=x+1
can still
FIN_WAIT_2 wait for server send data
close

LAST_ACK
FINbit=1, seq=y
TIMED_WAIT can no longer
send data
ACKbit=1; ACKnum=y+1
timed wait
for 2*max CLOSED
segment lifetime

CLOSED

Transport Layer 3-34


Client/Server Communication and State Transitions
(TCB: Transmission Control Block)

Client Server
Timeout/RST Timeout/RST

Data Tx./ACK

35
Client TCP Operation Server

LISTEN Closed
Closed
Active open Passive open
SYN

SENT
SYN
SYN+ACK

RCVD
SYN
ACK
Read/Write

Established
Read/Write

Established
Active close
FIN

WAIT-1
FIN
ACK

CLOSE
WAIT
Passive close
WAIT-2
FIN

LAST
ACK
2MSL timer FIN
WAIT
TIME

ACK

Closed
Closed

Client states Server states


36
ACK Generation Rules
• When an in-order data segment is received, delay the ACK until
• another data segment is received, OR
• 500 ms has elapsed.

– When an out of sequence segment with a higher sequence #


arrives
• Send an ACK with the expected seq#
– When a missing segment arrives
• Send an ACK to announce the next seq# expected.
– If a duplicate segment arrives, immediately send an ACK.

37
TCP: Flow Control (FC)
• FC: Regulates the amount of data a source can send before receiving
an ACK.

• Sliding Window Protocol with selective repeat is used.


– The bytes within the window are the bytes that can be in
transit.
• There is a separate retransmission timeout (RTO) timer for
each segment (except ACKs)

• The receiver can open/shrink/close its window, dynamically.


App
Read

 FC is performed by the receiver. Recv. Buffer


TCP

38
TCP: Silly Window Syndrome

• Silly Window Syndrome (SWS)


(#of data bytes in a segment/segment length) is too small

Example: 5 bytes of data; seg. length = 5 +20; ratio = 5/25 = 0.2


1000 bytes of data; seg. length = 1000 + 20; ratio = 1000/1020 = 0.98

• SWS occurs if
– the sender and/or the receiver is very slow.
39
TCP: Silly Window Syndrome (Sender produces small data blocks)

Server
Client
Read Write
Port Port

TCP TCP
IP/Link/PHY
Internet IP/LinkPHY

Nagle’s solution
Sender sends the first segment even if it is a small one.
Next, wait until an ACK is received OR a maximum-size segment is accumulated
before sending the next segment
…… and repeat “Next” ...

40
TCP: Silly Window Syndrome (Slow Receiver)
Client is emptying the buffer slowly  RWND is small

Client Server
Read Write
Port Port

TCP TCP
IP/Link/PHY
Internet IP/Link/PHY
Receive buffer

Clarke’s solution
Send an ACK and close the window until another segment
can be received or buffer is ½ empty.

41
TCP: Congestion Control

Host

Total Output rate


H H
Network capacity Ideal behavior
Internet
(Net of routers) Desired behavior
No Undesired
congestion congestion behavior

Total Input rate


H H

Network input
Network output
42
Causes of congestion

• Packets arriving on many input links want to go on the same


output link
 Queue builds up for the outgoing link.
 Router starts dropping packets.

• Slow routers
 Queues build up if computing tasks take too
much time.
 Buffer mngmt., updating RT, running routing p’cols,
looking up RT

• Hosts produce/download too much …

43
General Principles of Congestion Control

- Monitor the system to know


when and where congestion is happening.
- Communicate this information
to where actions can be taken.
- Adjust system operation
to correct the problem.

Introduction 1-44
General Principles of Congestion Control
Monitor: A variety of metrics can be monitored.
Fraction of all packets discarded due to lack of buffer
Average queue length
Number of retransmitted packets
Average packet delay

Communicate: Notify the entities that need to take actions.


Fields in packet headers can be reserved to carry this info.
Hosts and routers can send probe packets to
enquire.
Adjust system operation: Take actions.
Deny service to some users.
Degrade service to some users.
Have users schedule their demand in a more predictable
manner. 45
All protocol layers contribute to congestion
“prevention”
- Link layer

Don’t discard out-of-sequence packets.


(Selective-Repeat is better than Go-back-N.)
Reduce the # of smaller packets (e.g. piggyback ACKs).

- Network layer

Apply load balancing: Spread traffic over many paths.


Use good discard policies.
File transfer: Drop new packets.
Real-time: Drop old packets.
- TCP layer

Next …

46
TCP: Congestion Control (CC)
• CC is achieved by controlling the transmission rate at the
sender after “detecting” congestion.
• Tx rate is controlled by controlling the window
size.
• Main idea in controlling CW (congestion window)
 Slow start (CW = 1 MSS)
but quickly speed up to congestion threshold (CT): 1,2,4, 8, …CT

 Congestion avoidance
beyond threshold, increase linearly: CW++, CW++, …, RWND

v Congestion detection
Go back to slow start ….

47
TCP: Congestion Control
• Slow start • Congestion Avoidance: Additive Inc.
 Initially, CW = 1: Tx 1 Seg. (MSS)  Each time the whole window of
segs. is ACKed
 If ACK received before TO CW = CW + 1
CW = 2 (= CW x 2): Tx 2 Segs. (CWmax = RWND)
 If ACKs received before TO
CW = 4 (= CW x 2): Tx 4 Segs.
 If ACKs received before TO  Congestion Detection
CW = 8 (= CW x 2): Tx 8 Segs.
RTO timer goes off
:
 Continue until you hit a threshold:
CT = CW/2 and CW = 1
Congestion Threshold (CT)

3 duplicate ACKs received


(AAAA)
Normally, CT = 64 KBytes
CT = CW/2 and CW = 1
CT = CW/2 and CW = CT
Congestion Control

• Variable CT
• Congestion Threshold is also known as ssthresh
Transport Layer 3-49
TCP: Timers
Four kinds of timers

Retransmission Timeout (RTO) timer

Persistence Timer

Keep-Alive Timer

TIME-WAIT Timer (2*MSL timer)

50
Example RTT estimation:
RTT: gaia.cs.umass.edu to fantasia.eurecom.fr

350

300

250
RTT (milliseconds)

200

150

100
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)

SampleRTT Estimated RTT

Transport Layer 3-51


TCP: Timers (RTO)
• Operation
• For each segment transmitted (except ACK and RST), start an RTO
• If RTO goes off, retransmit the segment and restart RTO
• RTO
Initially: Default value (60s)
After measurements (RTTM): RTO = RTTS + 4. RTTD

RTTS (RTT Smoothed): α = 0.125 (typical value)


After first measurement RTTS = RTTM
After another measurement RTTS = (1 – α )RTTS + α.RTTM

RTTD (RTT Deviation): β = 0.25 (typical value)


After first measurement RTTD = RTTM/2
After another measurement RTTD = (1 – β )RTTD + β. |RTTS – RTTM|

52
TCP: Persistence Timer
• A receiver can close the window and reopen it with an ACK
 Problem: If the ACK is lost, there is deadlock.
 Solution:
 When a sending TCP receives a segment with RWND = 0, start a persistence
timer.

 Persistence timer goes off: Send a probe segment (1 byte


data) to alert the receiver.
 Persistence timer value
Initially: Equal to RTO
Subsequently: Doubled with each Tx of the probe.
Saturates at 60 sec.

53
TCP: Timers (Keepalive and TIME-WAIT)
• Keepalive Timer
 To sustain mostly idle connections (as between BGP routers)
 Each time the server hears from a client
Reset the timer: 2 hours.
If the server does not hear from the client for 2 hours
Send a probe segment.
If there is no response after 10 probes (75 sec apart)
Assume that the client is down.

 TIME-WAIT Timer (2.MSL) Maximum Segment Lifetime


 Used during connection termination.

 Standard: MSL = 120 sec (implementations choose a smaller


value)
54
TCP throughput
• avg. TCP thruput as function of window size, RTT?
• ignore slow start, assume always data to send
• W: window size (measured in bytes) where loss occurs
• avg. window size (# in-flight bytes) is ¾ W
• avg. thruput is 3/4W per RTT
3 W bytes/sec
avg TCP thruput =
4 RTT
W

W/2

Transport Layer 3-55


TCP Fairness
fairness goal: if K TCP sessions share same
bottleneck link of bandwidth R, each should have
average rate of R/K

TCP connection 1

bottleneck
router
capacity R
TCP connection 2

Transport Layer 3-56


Why is TCP fair?
two competing sessions:
additive increase gives slope of 1, as throughput increases
multiplicative decrease decreases throughput proportionally

R equal bandwidth share

loss: decrease window by factor of 2


congestion avoidance: additive increase
loss: decrease window by factor of 2
congestion avoidance: additive increase

Connection 1 throughput R
Transport Layer 3-57
Fairness (more)
Fairness and UDP Fairness, parallel TCP
• multimedia apps often connections
do not use TCP • application can open
• do not want rate multiple parallel
throttled by congestion connections between two
control hosts
• instead use UDP: • web browsers do this
• send audio/video at
constant rate, tolerate • e.g., link of rate R with 9
packet loss existing connections:
• new app asks for 1 TCP, gets rate
R/10
• new app asks for 11 TCPs, gets R/2

Transport Layer 3-58


Chapter 3: summary
principles behind transport
layer services:
 multiplexing,
demultiplexing next:
 reliable data transfer
 flow control • leaving the network
“edge” (application,
 congestion control transport layers)
instantiation, • into the network
implementation in the “core”
Internet
 UDP
 TCP

Transport Layer 3-59

You might also like