TCP, Part 1
TCP segment structure, Estimation of Timeout Interval, Simplified TCP protocol
Transport Layer – TCP
Copyright By PowCoder代写 加微信 powcoder
Encapsulation in TCP/IP
IP datagram
Transport Layer – TCP
RFC 2018
RFC 2581
application writes data
socket door
application reads data
socket door
TCP: Overview
Error detection, retransmission, cumulative ACKs, timers, header fields for sequence and ACK numbers
TCP is defined in:
RFC 793 – when to send data from TCP send buffer, to the network layer
RFC 1122
RFC 1323 – TCP extensions for high-speed networks, how packet reordering problems can be completely avoided
TCP send buffer
TCP receive buffer
Transport Layer – TCP
socket door
application writes data
application reads data
flow controlled:
sender will not ”flood”
bi-directional app. data flow in same connection at the same time
reliable, in-order byte stream:
MSS: maximum segment size(amount of app data)
no message boundaries pipelined:
connection-oriented:
TCP congestion and flow control set window size
3-way handshake (exchange of control msgs) init’s sender, receiver state before data exchange
send & receive buffers
TCP send buffer
TCP receive buffer
TCP: Overview
Error detection, retransmission, cumulative ACKs, timers, header fields for sequence and ACK numbers
point-to-point:
Always one sender, one
full duplex data:
receiver with dTaratnasport Layer – TCP B
socket door
application writes data
application reads data
socket door
Reliable Data Transfer Mechanisms:
Checksum
– Verification of integrity of packet
Timer – Signals necessary re-transmission is required
Sequence number
ACK NAK
– Keeps track of which packet has been sent and received – Indicates receipt of packet in good or bad form
TCP send buffer
TCP receive buffer
Window, pipelining 5 – Allows for the sending of multiple yet-to-be-acknowledged packets
Transport Layer – TCP
Internet Checksum Example
When adding numbers, a carryout from the most
significant bit needs to be added to the result Example: add two 16-bit integers
11110011001100110 11101010101010101
wraparound 1 11011101110111011
sum checksum
11011101110111100 10100010001000011
1 1 1 1 1 1 1 1 1 1 1 1 1 1Tran1sport1Layer–TCP B
Connection-Oriented Transport: TCP
TCP Segment Structure
SEQ and ACK numbers
Calculating the Timeout Interval
The Simplified TCP Sender
ACK Generation Recommendation (RFC 1122, RFC 2581) Interesting Transmission Scenarios
Flow Control
TCP Connection Management
Transport Layer – TCP
TCP segment structure
URG: urgent data (generally not used)
ACK: if ACK # is valid
source port # dest. port # sequence number
(not segments!)
Header length (4-BITS) – in 32- bit words
acknowledgement number head not Header
PSH: push data now (generally not used)
used UAPRSF checksum
rcvr window size URGent data ptr
# bytes the rcvr is willing to accept
RST, SYN, FIN: connection established (setup, tear down commands)
Options (variable length)
Internet checksum (as in UDP)
application data
We can view these teeny-weeny
details using WireShark.
(variable length)
In practice, PSH, URG, and the Urgent Data Pointer are not used.
negotiate MSS
Transport Layer – TCP
Data stream: file consisting of 500,000 bytes MSS: 1,000 bytes
First byte of data stream: numbered as 0
Suppose that a process in Host A wants to send a stream of data to a process in Host B over a TCP connection.
TCP constructs 500 segments out of the data stream.
500,000 bytes/1,000 bytes = 500 segments
In practice, both Ethernet and PPP link-layer protocols have an MTU of 1,500 bytes. Thus a typical value of MSS is 1460 bytes.
Transport Layer – TCP
TCP sequence #’s and ACKs
… 0 1 2 3 4 …..999 1000 1001 1002….1999
Segment 1 Segment 2
First byte of data stream: numbered as 0 First segment contains data from 0 to 999
Transport Layer – TCP
TCP sequence #’s and ACKs
… 0 1 2 3 4 …..999 1000 1001 1002….1999
Segment 1 Segment 2
Sequence. Numbers (#’s):
byte stream ‘number’ of first byte in segment’s data
Do not necessarily start from 0, use random initial number R
• Segment1:0+R
• Segment 2: 1000 + R etc… ACKs (acknowledgment):
Seq # of next byte expected from other side (last byte +1) Cumulative ACK
If received segment 1, waits for segment 2
E.g. Ack=1000 + R (received up to 999th byte)
Transport Layer – TCP
Yet another server echo example
User types ‘Hello’
Host A Host B
I’m sending data starting at seq. num=42 time
ACK tells about up to what byte has been received and what is the next
starting byte the host is expecting to receive
Transport Layer – TCP
Yet another server echo example
User types ‘Hello’
host ACKs receipt of echoed ‘Hello’ send something else
Send me the bytes from 47 onward ACK is being piggy-backed on server-to-client data
I’m sending data starting at seq. num=42
host ACKs receipt of
ACK tells about up to what byte has been received and what is the next
starting byte the host is expecting to receive
Transport Layer – TCP
‘Hello’, echoes back
Yet another server echo example
Host A: seq=42 ack=79
Host A ‘Hello’
Assuming that the starting sequence numbers for Host A and Host B are: 42 and 79 respectively
seq=47 ack=84
host ACKs receipt
Send me the bytes from 47 onward ACK is being piggy-backed on server-to-client data
User types
host ACKs Host receipt of B:
I’m sending data starting at seq. num=42
seq=79 ack=47
of echoed ‘Hello’
send something else
seq=84 ack=50
ACK tells about up to what byte has been received and what is the next
starting byte the host is expecting to receive
Transport Layer – TCP
‘Hello’, echoes back
TCP sequence #’s and ACKs
Assuming that the starting sequence numbers for Host A and Host B are: 42 and 79 respectively
host ACKs receipt
Send me the bytes from 43 onward ACK is being piggy-backed on server-to-client data
simple telnet scenario (with echo on)
Q: how receiver handles out- User
of-order segments
A: TCP specs. does not say, – decide when implementing
I’m sending data starting at seq. num=42 receipt of ‘C’, echoes
Host B server host ACKs
of echoed ‘C’
Even if no data is being carried in the segment, a Sequence number needs to be provided
Transport Layer – TCP
TCP Round Trip Time and Timeout
Main Issue: How long is the sender willing to wait before re-transmitting the packet?
Q: how to set TCP timeout value?
Must be set longer than RTT *
because RTT will vary If set too short: premature
Wait for an ACK
unnecessary retransmissions
If set too long: slow reaction to segment loss
* RTT = round trip time
Timeout interval
Transport Layer – TCP
Q: how to estimate RTT?
Timeout interval
TCP Round Trip Time and Timeout
SampleRTT: measured time from segment transmission until ACK receipt
Main Issue: How long is the sender willing to wait before re-transmitting the packet?
Wait for an ACK
SampleRTT will vary, we would want estimated RTT to be ”smoother”
ignore retransmissions, cumulatively ACKed segments
use several recent measurements, not just current SampleRTT
Transport Layer – TCP
TCP Round Trip Time and Timeout
How to estimate the timeout interval?
Timeout interval
Estimated RTT margin
Transport Layer – TCP
TCP Round Trip Time and Timeout
EstimatedRTT = (1-x) * EstimatedRTT + x * SampleRTT
Exponential weighted moving average
influence of given sample decreases exponentially fast typical value of x: 0.125 (RFC 6298)
Setting the timeout
EstimatedRTT plus ”safety margin”
A large variation in EstimatedRTT will produce a larger safety
recommended value of x: 0.25
Deviation = (1-x) * Deviation +
x * |SampleRTT-EstimatedRTT|
Timeout = EstimatedRTT + (4 * Deviation)
Recommended Initial Timeout =1sec. (RFC 6298)
Timeout is doubled when a timeout occurs
It is recalculated again upon receipt of new segments
Transport Layer – TCP
Sample Calculations
EstimatedRTT = 0.875 * EstimatedRTT + 0.125 * SampleRTT
EstimatedRTT after the receipt of the ACK of segment 1: EstimatedRTT = RTT for Segment 1 = 0.02746 second
Recommended Initial Timeout =1sec. (RFC 6298)
EstimatedRTT after the receipt of the ACK of segment 2: EstimatedRTT = 0.875 * 0.02746 + 0.125 * 0.035557 = 0.0285
EstimatedRTT after the receipt of the ACK of segment 3: EstimatedRTT = 0.875 * 0.0285 + 0.125 * 0.070059 = 0.0337
EstimatedRTT after the receipt of the ACK of segment 4: EstimatedRTT = 0.875 * 0.0337+ 0.125 * 0.11443 = 0.0438
EstimatedRTT after the receipt of the ACK of segment 5: EstimatedRTT = 0.875 * 0.0438 + 0.125 * 0.13989 = 0.0558
EstimatedRTT after the receipt of the ACK of segment 6: EstimatedRTT = 0.875 * 0.0558 + 0.125 * 0.18964 = 0.0725
Transport Layer – TCP
RTT Samples and RTT estimates
Estimated RTT
Sample RTT
The variations in the SampleRTT are smoothed out in the computation of the EstimatedRTT.
Transport Layer – TCP
RTT (msec.)
An Actual RTT estimation:
RTT: gaia.cs.umass.edu to fantasia.eurecom.fr
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
SampleRTT Estimated RTT
Transport Layer – TCP
RTT (milliseconds)
Transport Layer – TCP
FSM of TCP for Reliable Data Transfer
Simplified TCP sender, event: data received
Assumptions:
– one way data transfer
– data from App. Layer is
from application above create, send segment
less than MSS
– no flow, congestion control
event: timer timeout for segment with seq. number y
retransmit segment
event: ACK received, with ACK number y
process ACK
Transport Layer – TCP
SIMPLIFIED TCP SENDER
Assumptions:
• sender is not constrained by TCP flow or congestion control • that data from above is less than MSS in size
• that data transfer is in one direction only
Associated with the oldest unACKed segment
loop (forever) {
switch(event)
event: data received from application above
Don’t use estimation equation
08 09 10 11 12 13 15 16 17 18 19 20
nextseqnum
pass segment to IP
nextseqnum = nextseqnum + length(data)
Use timeout estimation equation
event: ACK received, with ACK field value of y
if (y > sendbase) { /* cumulative ACK of all data up to y */
sendbase = initial_sequence number nextseqnum = initial_sequence number
create TCP segment with sequence number nextseqnum If (timer is currently not running) start timer for segment
event: timer timeout
retransmit not-yet-ACKed segment with smallest Seq. #
Start timer
sendbase = y
If (there are currently any not-yet-ACKed segments)
start timer }
} /* end of loop forever */
Transport Layer – TCP
Seq=92 timeout
lost ACK scenario
premature timeout, cumulative ACKs
TCP: Interesting Scenarios
Simplified TCP version
Retransmit
packet (with Seq=92), then restart Timer
Retransmission due to lost ACK
Segment with Seq=100 not retransmitted Transport Layer – TCP
discard retransmitted data
discard retransmitted data Cumulative
Send duplicate ACK
ACK is sent
Seq=92 timeout
TCP: Retransmission Scenario
Cumulative ACK avoids retransmission of the first segment.
Transport Layer – TCP
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com