Вы находитесь на странице: 1из 51

300095: Computer Networks and Internets

Week 11
TCP
Outline
 TCP overview
 Data transfer
Connection setup
Data transfer
Connection termination
 TCP control
Flow control
Error control
Congestion control
 TCP options
 Examples
300095, Autumn 2011 2
TCP Overview
 TCP is a connection-oriented reliable transport protocol
Supports process-to-process communications using port numbers
Provides connection-oriented service to application layer by
employing connectionless network service
 Support stream-oriented (or byte-oriented) delivery service
Emulates a data pipe between the source process and the
destination process
 About 90% of Internet applications use TCP as the
transport protocol
Reliable
In-order delivery
End-to-end service
300095, Autumn 2011 3
Process-to-Process Communications
The two ends of the virtual data pipe are called
sockets
A socket is uniquely identified by (IP address, port
number) pair

300095, Autumn 2011 4


Numbering of TCP Segments
A number of bytes (typically 1KB) are grouped
into a packet called segment
Each byte of data is numbered by TCP
The Initial Sequence Number (ISN) is randomly
generated for each connection
The ISN is between 0 and 232-1
The Sequence Number field in TCP segment
indicates the first data byte
Enables TCP to provide stream-oriented service

300095, Autumn 2011 5


TCP Segment Format

300095, Autumn 2011 6


Control Bits
6 control bits (or flags) used for connection setup,
termination, connection abortion, and control of
data transfer

300095, Autumn 2011 7


Window Size
A 16-bit field in TCP header
Indicates the receiving window (rwnd) determined
by the receiver
Maximum is 65,535
Larger window size can be defined by using TCP
Window Scaling option
Used for flow control
The sender’s send window (swnd) must not exceed the
rwnd indicated by the receiver
Prevent a fast sender from swamping a slow receiver
300095, Autumn 2011 8
Checksum
A 16-bit field in TCP header
Used for error control
A compulsory requirement for TCP
implementation
Guarantees reliable transfer
Calculated using 1’s compliment algorithm
A pseudo-header included in the checksum
calculation
300095, Autumn 2011 9
TCP Pseudo-header
A header used for the purpose of checksum
calculation
12 bytes in length
Part of IP header
Not actually sent
IP addresses included in checksum calculation
Avoid TCP segments being sent to the wrong host or
wrong application

300095, Autumn 2011 10


Continue…

300095, Autumn 2011 11


Urgent Pointer
A 16-bit field in TCP header
Maximum urgent data is 65,535 bytes
Big enough for most applications
Only valid when the URG flag is set in TCP header
The urgent data starts from the first byte in a TCP
segment
Urgent data can be sent together with normal data
Urgent pointer actually indicates the end of urgent
data
E.g. “control+c” to abort a connection
300095, Autumn 2011 12
TCP Connection Setup
TCP has to set up a connection first before
data transfer can take place
Connection-oriented transport protocol
Facilitates acknowledgment
Retransmission of corrupted/lost segments
Three-way handshaking is used in TCP
connection setup
Using SYN segments

300095, Autumn 2011 13


Three-Way Handshaking
 Initiated by Client
(Sends a SYN
segment)
ISN=8000
 Server replies
with a
SYN+ACK
segment
ISN=15000
 Client sends a
ACK segment to
acknowledge
Cumulative
ACK

300095, Autumn 2011 14


Continue…
SYN segment consumes one sequence number
ACK segment consumes no sequence number
However, SYN+ACK and SYN+Data segments
consume sequence number
SYN segment notifies the other party of its
ISN
So the receiver can acknowledge

300095, Autumn 2011 15


Data Transfer
Data flows in both
directions
Full-duplex
Acknowledgement
can be sent together
with data segments
Piggybacking

300095, Autumn 2011 16


Connection Termination
 Initiated by
either TCP
client or
server
 FIN segment
used for this
purpose
 Three-way
handshaking
used

300095, Autumn 2011 17


TCP Flow Control
Sliding window is used to accomplish flow control
in TCP
Byte-oriented
Window opened after data is ACKed or larger send
window is allowed
Window size = Min(rwnd, cwnd)
rwnd dictated by the receiver
cwnd depends on network congestion
Dictated by TCP congestion control

300095, Autumn 2011 18


Sliding Window
Window sliding right allows new data bytes
to be sent

300095, Autumn 2011 19


TCP Error Control
 TCP is a reliable transport protocol, free of:
Corrupted segments
Lost segments
Out-of-order segments
Duplicated segments
 16-bit checksum used
Employs 1’s compliment algorithm
Pseudoheader included in checksum calculation
IP addresses and protocol protected
− TCP segments sent to the correct host
− TCP segments sent to the correct higher layer protocol
 Corrupted/lost segments are retransmitted
RTO (Retransmission Time-Out) timer expires
300095, Autumn 2011 20
Retransmission of TCP Segments

300095, Autumn 2011 21


TCP Congestion Control
Mechanisms control network congestion
Different from flow control
Keeps network load below network capacity
Consequence of congestion:
Packet loss
TCP employs Slow Start and Congestion
Avoidance as the congestion control mechanism
Consists of two phases
Slow Start
Congestion Avoidance

300095, Autumn 2011 22


Continue…

 Slow Start: in blue background


 Congestion Avoidance: in yellow background
300095, Autumn 2011 23
Congestion Control Mechanism
Congestion indicated by retransmission
timeout
Sliding Window mechanism used for
Congestion control
Window size is control as follows
Increased upon receipt of ACKs
Decreased upon expiration of retransmission
timer

300095, Autumn 2011 24


Slow Start
Starts with 1 MSS (slow start)
cwnd = 1 MSS
Increases cwnd by doubling cwnd upon receipt of
ACK
cwnd doubled each RTT (Round-Trip Time)
Exponential increase
Enters Congestion Avoidance phase when
congestion is detected
No ACK arrives after RTO timer times out
Indicates that the network is congested

300095, Autumn 2011 25


Continue…

300095, Autumn 2011 26


Congestion Avoidance
Entered from Slow Start phase
Increases cwnd linearly
Slowly
In recognition of network congestion
Algorithm used:
AIMD: Additive Increase Multiplicative Decrease

300095, Autumn 2011 27


Continue…

300095, Autumn 2011 28


AIMD
Additive Increase phase
Increases cwnd by 1 cwnd for each ACK
received
Window size (cwnd) increased by 1 every RTT
Transition from Exponential
Variable ssthresh = ½ initial window size
Upon loss, ssthresh set to half the current
window size
300095, Autumn 2011 29
Reaction to Congestion
RTO times out
Network heavily congested
ssthresh (slow start threshold) = cwnd/2
cwnd = 1 MSS
Starts Slow Start phase again
Three duplicate ACKs received
Moderate congestion
ssthresh = cwnd/2
cwnd = cwnd/2
Starts Congestion Avoidance phase
300095, Autumn 2011 30
Fast Retransmission and
Fast Recovery
Fast retransmission
Retransmits a segment after 3 duplicate ACKs arrive
Without waiting for RTO to time out
Fast Recovery
Reduces cwnd by half and starts congestion avoidance
phase
Without restarting from slow start phase (cwnd = 1 MSS)
Improves TCP throughput

300095, Autumn 2011 31


TCP Options
Up to 40 bytes of optional data
1-byte options
End of Option (EOP)
No-Operation (NOP)
Multiple-byte options
Maximum Segment Size (MSS)
Window Scale Factor
Timestamp
SACK (Selective ACK)

300095, Autumn 2011 32


Example 1
Q: What is pseudo-header? Why TCP
includes the pseudo-header in checksum
calculation?

300095, Autumn 2011 33


Example 1
Q: What is pseudo-header? Why TCP
includes the pseudo-header in checksum
calculation?

A: A header used for the purpose of checksum


calculation using part of IP header, used to
avoid TCP segments being sent to the
wrong host or wrong application.
300095, Autumn 2011 34
Example 2
Q: A client can piggyback ACK segments in
data segments. Assume, in Figure 15.9, the
client has 10,000 bytes of data to send, and
the maximum TCP segment size (MSS) is
1000 bytes. Use a time diagram to show
TCP segments exchange between the client
and the server.

300095, Autumn 2011 35


Example 2

300095, Autumn 2011 36


seq: 8001
ack: 1500
1
A
P
Data
Bytes: 80
01-9000

seq: 9001
ack: 1500
1
A P
Data
Bytes: 90
01-10000

seq: 1000
1
ack: 1500
1
A P
Data
Bytes: 10
001-1100
0

seq: 1100
1
ack: 1500
1
A P
Data
Bytes: 11
001-1200
0

seq: 1200
1
ack: 1500
1
A P
Data
Bytes: 12
001-1300
0

001
seq: 15
001
ack: 13
P
A

300095, Autumn 2011 37


seq: 1300
1
ack: 1500
1
A
P
Data
Bytes: 13
001-1400
0

seq: 1400
1
ack: 1500
1
A P
Data
Bytes: 14
001-1500
0

seq: 1500
1
ack: 1500
1
A P
Data
Bytes: 15
001-1600
0

seq: 1600
1
ack: 1500
1
A P
Data
Bytes: 16
001-1700
0

seq: 1700
1
ack: 1500
1
A P
Data
Bytes: 17
001-1800
0

001
seq: 13
001
ack: 18
P
A

300095, Autumn 2011 38


Example 3
Refer to Figure 15.37. Assume MSS = 1KB
and RTT = 1 second, what’s the average
TCP throughput in the first 8 seconds?

300095, Autumn 2011 39


Example 3

300095, Autumn 2011 40


Example 3
8 seconds = 8 RTTs
20 segments in 8 seconds = 20 x MSS =
20KB

Aversge throughput = 20KB/8s = 2.5KBps

300095, Autumn 2011 41


Further Reading
Ch15, textbook.

300095, Autumn 2011 42


UDP
Outline
UDP overview
Socket address
Comparison with TCP
Examples

300095, Autumn 2011 44


User Datagram Protocol: UDP
One of the two transport protocol (Layer 4) for the
Internet
The other one is TCP (covered last week)
A light-weighted transport protocol
Connectionless
No connection setup
Unreliable
No flow control
No error control
No retransmission of corrupted/lost segments

300095, Autumn 2011 45


Applications Using UDP
 About 10—15% of Internet traffic employs UDP
 Mainly used by:
Multimedia applications
User data is usually small
Not efficient if TCP is used
Real-time applications
Streaming audio/video
Cannot wait for retransmission of lost segments
Multicasting
Very difficult if TCP is used

300095, Autumn 2011 46


Socket Address
 TCP/UDP supports process-to-process communications by
using socket address
 A socket address identifies a process (or application) at an
end-system
 TCP socket address is defined as a tuple of {src IP, src port
#, dest IP, dest port #}
 UDP socket address is defined as a tuple of {src IP, src
port #, dest IP, dest port #}
 Applications write to (or read from) sockets
Interface to application layer
Transparent to application layer

300095, Autumn 2011 47


UDP Socket Address
Identified by {dest IP, dest port#}
E.g. {200.23.56.8, 69}
Supports connectionless multiplexing

300095, Autumn 2011 48


Multiplexing at Transport Layer

= socket = process

application P3 P1
P1 application P2 P4 application

transport transport transport

network network network

link link link

physical physical physical

host 2 host 3
host 1

300095, Autumn 2011 49


Why is there a UDP?
no connection establishment (which can add
delay)
simple: no connection state at sender,
receiver
small segment header
no congestion control: UDP can blast away
as fast as desired

300095, Autumn 2011 50


Further Reading
Ch14, textbook.

300095, Autumn 2011 51

Вам также может понравиться