Top Banner
Transmission Control Protocol (TCP) Antonio Carzaniga Faculty of Informatics Università della Svizzera italiana November 9, 2018
101

Transmission Control Protocol (TCP) - USI - Faculty of

Mar 19, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Transmission Control Protocol (TCP) - USI - Faculty of

Transmission Control Protocol (TCP)

Antonio Carzaniga

Faculty of InformaticsUniversità della Svizzera italiana

November 9, 2018

Page 2: Transmission Control Protocol (TCP) - USI - Faculty of

Outline

Introduction to TCP

Sequence numbers and acknowledgment numbers

Timeouts and RTT estimation

Reliable data transfer in TCP

Connection management

Page 3: Transmission Control Protocol (TCP) - USI - Faculty of

Transmission Control Protocol

The Internet’s primary transport protocol

◮ defined in RFC 793, RFC 1122, RFC 1323, RFC 2018, and RFC 2581

Page 4: Transmission Control Protocol (TCP) - USI - Faculty of

Transmission Control Protocol

The Internet’s primary transport protocol

◮ defined in RFC 793, RFC 1122, RFC 1323, RFC 2018, and RFC 2581

Connection-oriented service

◮ endpoints “shake hands” to establish a connection

◮ not a circuit-switched connection, nor a virtual circuit

Page 5: Transmission Control Protocol (TCP) - USI - Faculty of

Transmission Control Protocol

The Internet’s primary transport protocol

◮ defined in RFC 793, RFC 1122, RFC 1323, RFC 2018, and RFC 2581

Connection-oriented service

◮ endpoints “shake hands” to establish a connection

◮ not a circuit-switched connection, nor a virtual circuit

Full-duplex service

◮ both endpoints can both send and receive, at the same time

Page 6: Transmission Control Protocol (TCP) - USI - Faculty of

Preliminary Definitions

Page 7: Transmission Control Protocol (TCP) - USI - Faculty of

Preliminary Definitions

TCP segment: envelope for TCP data

◮ TCP data are sent within TCP segments

◮ TCP segments are usually sent within an IP packet

Page 8: Transmission Control Protocol (TCP) - USI - Faculty of

Preliminary Definitions

TCP segment: envelope for TCP data

◮ TCP data are sent within TCP segments

◮ TCP segments are usually sent within an IP packet

Maximum segment size (MSS):maximum amount of application datatransmitted in a single segment

◮ typically related to the MTU of the connection, to avoid network-levelfragmentation (we’ll talk about all of this later)

Page 9: Transmission Control Protocol (TCP) - USI - Faculty of

Preliminary Definitions

TCP segment: envelope for TCP data

◮ TCP data are sent within TCP segments

◮ TCP segments are usually sent within an IP packet

Maximum segment size (MSS):maximum amount of application datatransmitted in a single segment

◮ typically related to the MTU of the connection, to avoid network-levelfragmentation (we’ll talk about all of this later)

Maximum transmission unit (MTU): largest link-layer frame available to thesender host

◮ path MTU: largest link-layer frame that can be sent on all links from the senderhost to the receiver host

Page 10: Transmission Control Protocol (TCP) - USI - Faculty of

TCP Segment Format

0 31

source port destination port

sequence number

acknowledgment number

hdrlen unused U A P R S F receive window

Internet checksum urgent data pointer

options field

data

Page 11: Transmission Control Protocol (TCP) - USI - Faculty of

TCP Header Fields

Page 12: Transmission Control Protocol (TCP) - USI - Faculty of

TCP Header Fields

Source and destination ports: (16-bit each) application identifiers

Page 13: Transmission Control Protocol (TCP) - USI - Faculty of

TCP Header Fields

Source and destination ports: (16-bit each) application identifiers

Sequence number: (32-bit) used to implement reliable data transfer

Acknowledgment number: (32-bit) used to implement reliable data transfer

Page 14: Transmission Control Protocol (TCP) - USI - Faculty of

TCP Header Fields

Source and destination ports: (16-bit each) application identifiers

Sequence number: (32-bit) used to implement reliable data transfer

Acknowledgment number: (32-bit) used to implement reliable data transfer

Receive window: (16-bit) size of the “window” on the receiver end

Page 15: Transmission Control Protocol (TCP) - USI - Faculty of

TCP Header Fields

Source and destination ports: (16-bit each) application identifiers

Sequence number: (32-bit) used to implement reliable data transfer

Acknowledgment number: (32-bit) used to implement reliable data transfer

Receive window: (16-bit) size of the “window” on the receiver end

Header length: (4-bit) size of the TCP header in 32-bit words

Page 16: Transmission Control Protocol (TCP) - USI - Faculty of

TCP Header Fields

Source and destination ports: (16-bit each) application identifiers

Sequence number: (32-bit) used to implement reliable data transfer

Acknowledgment number: (32-bit) used to implement reliable data transfer

Receive window: (16-bit) size of the “window” on the receiver end

Header length: (4-bit) size of the TCP header in 32-bit words

Optional and variable-length options field: may be used to negotiate protocolparameters

Page 17: Transmission Control Protocol (TCP) - USI - Faculty of

TCP Header Fields

Page 18: Transmission Control Protocol (TCP) - USI - Faculty of

TCP Header Fields

ACK flag: (1-bit) signals that the value contained in the acknowledgment numberrepresents a valid acknowledgment

Page 19: Transmission Control Protocol (TCP) - USI - Faculty of

TCP Header Fields

ACK flag: (1-bit) signals that the value contained in the acknowledgment numberrepresents a valid acknowledgment

SYN flag: (1-bit) used during connection setup and shutdown

Page 20: Transmission Control Protocol (TCP) - USI - Faculty of

TCP Header Fields

ACK flag: (1-bit) signals that the value contained in the acknowledgment numberrepresents a valid acknowledgment

SYN flag: (1-bit) used during connection setup and shutdown

RST flag: (1-bit) used during connection setup and shutdown

Page 21: Transmission Control Protocol (TCP) - USI - Faculty of

TCP Header Fields

ACK flag: (1-bit) signals that the value contained in the acknowledgment numberrepresents a valid acknowledgment

SYN flag: (1-bit) used during connection setup and shutdown

RST flag: (1-bit) used during connection setup and shutdown

FIN flag: (1-bit) used during connection shutdown

Page 22: Transmission Control Protocol (TCP) - USI - Faculty of

TCP Header Fields

ACK flag: (1-bit) signals that the value contained in the acknowledgment numberrepresents a valid acknowledgment

SYN flag: (1-bit) used during connection setup and shutdown

RST flag: (1-bit) used during connection setup and shutdown

FIN flag: (1-bit) used during connection shutdown

PSH flag: (1-bit) “push” flag, used to solicit the receiver to pass the data to theapplication immediately

Page 23: Transmission Control Protocol (TCP) - USI - Faculty of

TCP Header Fields

ACK flag: (1-bit) signals that the value contained in the acknowledgment numberrepresents a valid acknowledgment

SYN flag: (1-bit) used during connection setup and shutdown

RST flag: (1-bit) used during connection setup and shutdown

FIN flag: (1-bit) used during connection shutdown

PSH flag: (1-bit) “push” flag, used to solicit the receiver to pass the data to theapplication immediately

URG flag: (1-bit) “urgent” flag, used to inform the receiver that the sender hasmarked some data as “urgent”. The location of this urgent data is marked bythe urgent data pointer field

Page 24: Transmission Control Protocol (TCP) - USI - Faculty of

TCP Header Fields

ACK flag: (1-bit) signals that the value contained in the acknowledgment numberrepresents a valid acknowledgment

SYN flag: (1-bit) used during connection setup and shutdown

RST flag: (1-bit) used during connection setup and shutdown

FIN flag: (1-bit) used during connection shutdown

PSH flag: (1-bit) “push” flag, used to solicit the receiver to pass the data to theapplication immediately

URG flag: (1-bit) “urgent” flag, used to inform the receiver that the sender hasmarked some data as “urgent”. The location of this urgent data is marked bythe urgent data pointer field

Checksum: (16-bit) used to detect transmission errors

Page 25: Transmission Control Protocol (TCP) - USI - Faculty of

Sequence Numbers

Page 26: Transmission Control Protocol (TCP) - USI - Faculty of

Sequence Numbers

Sequence numbers are associated with bytes in the data stream◮ not with segments, as we have used them before

Page 27: Transmission Control Protocol (TCP) - USI - Faculty of

Sequence Numbers

Sequence numbers are associated with bytes in the data stream◮ not with segments, as we have used them before

The sequence number in a TCP segment indicates the sequence number of thefirst byte carried by that segment

Page 28: Transmission Control Protocol (TCP) - USI - Faculty of

Sequence Numbers

Sequence numbers are associated with bytes in the data stream◮ not with segments, as we have used them before

The sequence number in a TCP segment indicates the sequence number of thefirst byte carried by that segment

application data stream

4Kb

Page 29: Transmission Control Protocol (TCP) - USI - Faculty of

Sequence Numbers

Sequence numbers are associated with bytes in the data stream◮ not with segments, as we have used them before

The sequence number in a TCP segment indicates the sequence number of thefirst byte carried by that segment

application data stream

4Kb

MSS=1024b

Page 30: Transmission Control Protocol (TCP) - USI - Faculty of

Sequence Numbers

Sequence numbers are associated with bytes in the data stream◮ not with segments, as we have used them before

The sequence number in a TCP segment indicates the sequence number of thefirst byte carried by that segment

application data stream

4Kb

MSS=1024b

Page 31: Transmission Control Protocol (TCP) - USI - Faculty of

Sequence Numbers

Sequence numbers are associated with bytes in the data stream◮ not with segments, as we have used them before

The sequence number in a TCP segment indicates the sequence number of thefirst byte carried by that segment

application data stream

4Kb

MSS=1024b

1. . . . . . 1024 1025. . . 2048 2049. . . 3072 3073. . . 4096

Page 32: Transmission Control Protocol (TCP) - USI - Faculty of

Sequence Numbers

Sequence numbers are associated with bytes in the data stream◮ not with segments, as we have used them before

The sequence number in a TCP segment indicates the sequence number of thefirst byte carried by that segment

application data stream

4Kb

MSS=1024b

1. . . . . . 1024 1025. . . 2048 2049. . . 3072 3073. . . 4096

a TCP segment

Page 33: Transmission Control Protocol (TCP) - USI - Faculty of

Sequence Numbers

Sequence numbers are associated with bytes in the data stream◮ not with segments, as we have used them before

The sequence number in a TCP segment indicates the sequence number of thefirst byte carried by that segment

application data stream

4Kb

MSS=1024b

1. . . . . . 1024 1025. . . 2048 2049. . . 3072 3073. . . 4096

a TCP segment

2049

Page 34: Transmission Control Protocol (TCP) - USI - Faculty of

Sequence Numbers

Sequence numbers are associated with bytes in the data stream◮ not with segments, as we have used them before

The sequence number in a TCP segment indicates the sequence number of thefirst byte carried by that segment

application data stream

4Kb

MSS=1024b

1. . . . . . 1024 1025. . . 2048 2049. . . 3072 3073. . . 4096

a TCP segment

2049

sequence number

Page 35: Transmission Control Protocol (TCP) - USI - Faculty of

Acknowledgment Numbers

Page 36: Transmission Control Protocol (TCP) - USI - Faculty of

Acknowledgment Numbers

An acknowledgment number represents the first sequence number not yetseen by the receiver

◮ TCP acknowledgments are cumulative

Page 37: Transmission Control Protocol (TCP) - USI - Faculty of

Acknowledgment Numbers

An acknowledgment number represents the first sequence number not yetseen by the receiver

◮ TCP acknowledgments are cumulative

A B

Page 38: Transmission Control Protocol (TCP) - USI - Faculty of

Acknowledgment Numbers

An acknowledgment number represents the first sequence number not yetseen by the receiver

◮ TCP acknowledgments are cumulative

A B

[Seq# = 1200, . . .], size(data) = 1000

Page 39: Transmission Control Protocol (TCP) - USI - Faculty of

Acknowledgment Numbers

An acknowledgment number represents the first sequence number not yetseen by the receiver

◮ TCP acknowledgments are cumulative

A B

[Seq# = 1200, . . .], size(data) = 1000

[Seq# = 2200, . . .], size(data) = 500

Page 40: Transmission Control Protocol (TCP) - USI - Faculty of

Acknowledgment Numbers

An acknowledgment number represents the first sequence number not yetseen by the receiver

◮ TCP acknowledgments are cumulative

A B

[Seq# = 1200, . . .], size(data) = 1000

[Seq# = 2200, . . .], size(data) = 500

[Seq# = . . . , Ack# = 2700]

Page 41: Transmission Control Protocol (TCP) - USI - Faculty of

Sequence Numbers and ACK Numbers

Page 42: Transmission Control Protocol (TCP) - USI - Faculty of

Sequence Numbers and ACK Numbers

Notice that a TCP connection is a full-duplex link

◮ therefore, there are two streams

◮ two different sequence numbers

Page 43: Transmission Control Protocol (TCP) - USI - Faculty of

Sequence Numbers and ACK Numbers

Notice that a TCP connection is a full-duplex link

◮ therefore, there are two streams

◮ two different sequence numbers

E.g., consider a simple “Echo” application:

A B

Page 44: Transmission Control Protocol (TCP) - USI - Faculty of

Sequence Numbers and ACK Numbers

Notice that a TCP connection is a full-duplex link

◮ therefore, there are two streams

◮ two different sequence numbers

E.g., consider a simple “Echo” application:

A B

[Seq# = 100, Data =“C”]

Page 45: Transmission Control Protocol (TCP) - USI - Faculty of

Sequence Numbers and ACK Numbers

Notice that a TCP connection is a full-duplex link

◮ therefore, there are two streams

◮ two different sequence numbers

E.g., consider a simple “Echo” application:

A B

[Seq# = 100, Data =“C”]

[Ack# = 101, Seq# = 200, Data =“C”]

Page 46: Transmission Control Protocol (TCP) - USI - Faculty of

Sequence Numbers and ACK Numbers

Notice that a TCP connection is a full-duplex link

◮ therefore, there are two streams

◮ two different sequence numbers

E.g., consider a simple “Echo” application:

A B

[Seq# = 100, Data =“C”]

[Ack# = 101, Seq# = 200, Data =“C”]

[Seq# = 101, Ack# = 201, Data =“i”]

Page 47: Transmission Control Protocol (TCP) - USI - Faculty of

Sequence Numbers and ACK Numbers

Notice that a TCP connection is a full-duplex link

◮ therefore, there are two streams

◮ two different sequence numbers

E.g., consider a simple “Echo” application:

A B

[Seq# = 100, Data =“C”]

[Ack# = 101, Seq# = 200, Data =“C”]

[Seq# = 101, Ack# = 201, Data =“i”]

[Seq# = 201, Ack# = 102, Data =“i”]

Page 48: Transmission Control Protocol (TCP) - USI - Faculty of

Sequence Numbers and ACK Numbers

Notice that a TCP connection is a full-duplex link

◮ therefore, there are two streams

◮ two different sequence numbers

E.g., consider a simple “Echo” application:

A B

[Seq# = 100, Data =“C”]

[Ack# = 101, Seq# = 200, Data =“C”]

[Seq# = 101, Ack# = 201, Data =“i”]

[Seq# = 201, Ack# = 102, Data =“i”]

Acknowledgments are “piggybacked” on data segments

Page 49: Transmission Control Protocol (TCP) - USI - Faculty of

Reliability and Timeout

TCP provides reliable data transfer using a timer to detect lost segments

◮ timeout without an ACK→ lost packet→ retransmission

Page 50: Transmission Control Protocol (TCP) - USI - Faculty of

Reliability and Timeout

TCP provides reliable data transfer using a timer to detect lost segments

◮ timeout without an ACK→ lost packet→ retransmission

How long to wait for acknowledgments?

Page 51: Transmission Control Protocol (TCP) - USI - Faculty of

Reliability and Timeout

TCP provides reliable data transfer using a timer to detect lost segments

◮ timeout without an ACK→ lost packet→ retransmission

How long to wait for acknowledgments?

Retransmission timeouts should be larger than the round-trip time RTT = 2L

◮ as close as possible to the RTT

Page 52: Transmission Control Protocol (TCP) - USI - Faculty of

Reliability and Timeout

TCP provides reliable data transfer using a timer to detect lost segments

◮ timeout without an ACK→ lost packet→ retransmission

How long to wait for acknowledgments?

Retransmission timeouts should be larger than the round-trip time RTT = 2L

◮ as close as possible to the RTT

TCP controls its timeout by continuously estimating the current RTT

Page 53: Transmission Control Protocol (TCP) - USI - Faculty of

Round-Trip Time Estimation

Page 54: Transmission Control Protocol (TCP) - USI - Faculty of

Round-Trip Time Estimation

RTT is measured using ACKs

◮ only for packets transmitted once

Given a single sample S at any given time

Exponential weighted moving average (EWMA)

RTT = (1 − α)RTT′+ αS

Page 55: Transmission Control Protocol (TCP) - USI - Faculty of

Round-Trip Time Estimation

RTT is measured using ACKs

◮ only for packets transmitted once

Given a single sample S at any given time

Exponential weighted moving average (EWMA)

RTT = (1 − α)RTT′+ αS

◮ RFC 2988 recommends α = 0.125

Page 56: Transmission Control Protocol (TCP) - USI - Faculty of

Round-Trip Time Estimation

RTT is measured using ACKs

◮ only for packets transmitted once

Given a single sample S at any given time

Exponential weighted moving average (EWMA)

RTT = (1 − α)RTT′+ αS

◮ RFC 2988 recommends α = 0.125

TCP also measures the variability of RTT

DevRTT = (1 − β )DevRTT′+ β |RTT

′− S |

Page 57: Transmission Control Protocol (TCP) - USI - Faculty of

Round-Trip Time Estimation

RTT is measured using ACKs

◮ only for packets transmitted once

Given a single sample S at any given time

Exponential weighted moving average (EWMA)

RTT = (1 − α)RTT′+ αS

◮ RFC 2988 recommends α = 0.125

TCP also measures the variability of RTT

DevRTT = (1 − β )DevRTT′+ β |RTT

′− S |

◮ RFC 2988 recommends β = 0.25

Page 58: Transmission Control Protocol (TCP) - USI - Faculty of

Timeout Value

Page 59: Transmission Control Protocol (TCP) - USI - Faculty of

Timeout Value

The timeout interval T must be larger than the RTT◮ so as to avoid unnecessary retransmission

However, T should not be too far from RTT◮ so as to detect (and retransmit) lost segments as quickly as possible

Page 60: Transmission Control Protocol (TCP) - USI - Faculty of

Timeout Value

The timeout interval T must be larger than the RTT◮ so as to avoid unnecessary retransmission

However, T should not be too far from RTT◮ so as to detect (and retransmit) lost segments as quickly as possible

TCP sets its timeouts using the estimated RTT (RTT) and the variability estimate

DevRTT :

T = RTT + 4DevRTT

Page 61: Transmission Control Protocol (TCP) - USI - Faculty of

Reliable Data Transfer (Sender)

A simplified TCP sender

r_send(data)

if (timer not running)start_timer()

u_send([data,next_seq_num])next_seq_num← next_seq_num + length(data)

Page 62: Transmission Control Protocol (TCP) - USI - Faculty of

Reliable Data Transfer (Sender)

A simplified TCP sender

r_send(data)

if (timer not running)start_timer()

u_send([data,next_seq_num])next_seq_num← next_seq_num + length(data)

timeout

u_send(pending segment with smallest sequence number)start_timer()

Page 63: Transmission Control Protocol (TCP) - USI - Faculty of

Reliable Data Transfer (Sender)

A simplified TCP sender

r_send(data)

if (timer not running)start_timer()

u_send([data,next_seq_num])next_seq_num← next_seq_num + length(data)

timeout

u_send(pending segment with smallest sequence number)start_timer()

u_recv([ACK,y])

if (y > base)base← yif (there are pending segments)start_timer()

else . . .

Page 64: Transmission Control Protocol (TCP) - USI - Faculty of

Acknowledgment Generation (Receiver)

Page 65: Transmission Control Protocol (TCP) - USI - Faculty of

Acknowledgment Generation (Receiver)

Arrival of in-order segment with expected sequence number; all data up toexpected sequence number already acknowledged

Page 66: Transmission Control Protocol (TCP) - USI - Faculty of

Acknowledgment Generation (Receiver)

Arrival of in-order segment with expected sequence number; all data up toexpected sequence number already acknowledged◮ Delayed ACK: wait 500ms for another in-order segment; If that does not arrive,send ACK

Page 67: Transmission Control Protocol (TCP) - USI - Faculty of

Acknowledgment Generation (Receiver)

Arrival of in-order segment with expected sequence number; all data up toexpected sequence number already acknowledged◮ Delayed ACK: wait 500ms for another in-order segment; If that does not arrive,send ACK

Arrival of in-order segment with expected sequence number. One otherin-order segment waiting for ACK (see above)

Page 68: Transmission Control Protocol (TCP) - USI - Faculty of

Acknowledgment Generation (Receiver)

Arrival of in-order segment with expected sequence number; all data up toexpected sequence number already acknowledged◮ Delayed ACK: wait 500ms for another in-order segment; If that does not arrive,send ACK

Arrival of in-order segment with expected sequence number. One otherin-order segment waiting for ACK (see above)◮ Cumulative ACK: immediately send cumulative ACK (for both segments)

Page 69: Transmission Control Protocol (TCP) - USI - Faculty of

Acknowledgment Generation (Receiver)

Arrival of in-order segment with expected sequence number; all data up toexpected sequence number already acknowledged◮ Delayed ACK: wait 500ms for another in-order segment; If that does not arrive,send ACK

Arrival of in-order segment with expected sequence number. One otherin-order segment waiting for ACK (see above)◮ Cumulative ACK: immediately send cumulative ACK (for both segments)

Arrival of out of order segment with higher-than-expected sequence number(gap detected)

Page 70: Transmission Control Protocol (TCP) - USI - Faculty of

Acknowledgment Generation (Receiver)

Arrival of in-order segment with expected sequence number; all data up toexpected sequence number already acknowledged◮ Delayed ACK: wait 500ms for another in-order segment; If that does not arrive,send ACK

Arrival of in-order segment with expected sequence number. One otherin-order segment waiting for ACK (see above)◮ Cumulative ACK: immediately send cumulative ACK (for both segments)

Arrival of out of order segment with higher-than-expected sequence number(gap detected)◮ Duplicate ACK: immediately send duplicate ACK

Page 71: Transmission Control Protocol (TCP) - USI - Faculty of

Acknowledgment Generation (Receiver)

Arrival of in-order segment with expected sequence number; all data up toexpected sequence number already acknowledged◮ Delayed ACK: wait 500ms for another in-order segment; If that does not arrive,send ACK

Arrival of in-order segment with expected sequence number. One otherin-order segment waiting for ACK (see above)◮ Cumulative ACK: immediately send cumulative ACK (for both segments)

Arrival of out of order segment with higher-than-expected sequence number(gap detected)◮ Duplicate ACK: immediately send duplicate ACK

Arrival of segment that (partially or completely) fills a gap in the received data

Page 72: Transmission Control Protocol (TCP) - USI - Faculty of

Acknowledgment Generation (Receiver)

Arrival of in-order segment with expected sequence number; all data up toexpected sequence number already acknowledged◮ Delayed ACK: wait 500ms for another in-order segment; If that does not arrive,send ACK

Arrival of in-order segment with expected sequence number. One otherin-order segment waiting for ACK (see above)◮ Cumulative ACK: immediately send cumulative ACK (for both segments)

Arrival of out of order segment with higher-than-expected sequence number(gap detected)◮ Duplicate ACK: immediately send duplicate ACK

Arrival of segment that (partially or completely) fills a gap in the received data◮ Immediate ACK: immediately send ACK if the packet start at the lower end of thegap

Page 73: Transmission Control Protocol (TCP) - USI - Faculty of

Reaction to ACKs (Sender)

Page 74: Transmission Control Protocol (TCP) - USI - Faculty of

Reaction to ACKs (Sender)

u_recv([ACK,y])

if (y > base)base← yif (there are pending segments)start_timer()

Page 75: Transmission Control Protocol (TCP) - USI - Faculty of

Reaction to ACKs (Sender)

u_recv([ACK,y])

if (y > base)base← yif (there are pending segments)start_timer()

else

ack_counter[y] ← ack_counter[y] + 1if (ack_counter[y] = 3)u_send(segment with sequence number y)

Page 76: Transmission Control Protocol (TCP) - USI - Faculty of

Connection Setup

Page 77: Transmission Control Protocol (TCP) - USI - Faculty of

Connection Setup

Three-way handshake

Page 78: Transmission Control Protocol (TCP) - USI - Faculty of

Connection Setup

Three-way handshake

client server

Page 79: Transmission Control Protocol (TCP) - USI - Faculty of

Connection Setup

Three-way handshake

client server

[SYN, Seq# = cli_init_seq]

Page 80: Transmission Control Protocol (TCP) - USI - Faculty of

Connection Setup

Three-way handshake

client server

[SYN, Seq# = cli_init_seq]

[SYN, ACK, Ack# = cli_init_seq + 1, Seq# = srv_init_seq]

Page 81: Transmission Control Protocol (TCP) - USI - Faculty of

Connection Setup

Three-way handshake

client server

[SYN, Seq# = cli_init_seq]

[SYN, ACK, Ack# = cli_init_seq + 1, Seq# = srv_init_seq]

[ACK, Seq# = cli_init_seq + 1, Ack# = srv_init_seq + 1]

Page 82: Transmission Control Protocol (TCP) - USI - Faculty of

Connection Shutdown

“This is it.”“Okay, Bye now.”“Bye.”

Page 83: Transmission Control Protocol (TCP) - USI - Faculty of

Connection Shutdown

“This is it.”“Okay, Bye now.”“Bye.”

client server

Page 84: Transmission Control Protocol (TCP) - USI - Faculty of

Connection Shutdown

“This is it.”“Okay, Bye now.”“Bye.”

client server

[FIN]

Page 85: Transmission Control Protocol (TCP) - USI - Faculty of

Connection Shutdown

“This is it.”“Okay, Bye now.”“Bye.”

client server

[FIN]

[ACK]

Page 86: Transmission Control Protocol (TCP) - USI - Faculty of

Connection Shutdown

“This is it.”“Okay, Bye now.”“Bye.”

client server

[FIN]

[ACK]

[FIN]

Page 87: Transmission Control Protocol (TCP) - USI - Faculty of

Connection Shutdown

“This is it.”“Okay, Bye now.”“Bye.”

client server

[FIN]

[ACK]

[FIN]

[ACK]

Page 88: Transmission Control Protocol (TCP) - USI - Faculty of

The TCP State Machine (Client)

CLOSED

Page 89: Transmission Control Protocol (TCP) - USI - Faculty of

The TCP State Machine (Client)

CLOSED

SYN_SENT

applicationopens connection

send SYN

Page 90: Transmission Control Protocol (TCP) - USI - Faculty of

The TCP State Machine (Client)

CLOSED

SYN_SENT

applicationopens connection

send SYN

ESTABLISHED

receive SYN,ACK

send ACK

Page 91: Transmission Control Protocol (TCP) - USI - Faculty of

The TCP State Machine (Client)

CLOSED

SYN_SENT

applicationopens connection

send SYN

ESTABLISHED

receive SYN,ACK

send ACK

FIN_WAIT_1

applicationcloses connection

send FIN

Page 92: Transmission Control Protocol (TCP) - USI - Faculty of

The TCP State Machine (Client)

CLOSED

SYN_SENT

applicationopens connection

send SYN

ESTABLISHED

receive SYN,ACK

send ACK

FIN_WAIT_1

applicationcloses connection

send FIN

FIN_WAIT_2

receive ACK

Page 93: Transmission Control Protocol (TCP) - USI - Faculty of

The TCP State Machine (Client)

CLOSED

SYN_SENT

applicationopens connection

send SYN

ESTABLISHED

receive SYN,ACK

send ACK

FIN_WAIT_1

applicationcloses connection

send FIN

FIN_WAIT_2

receive ACK

TIME_WAIT

receive FIN

send ACK

Page 94: Transmission Control Protocol (TCP) - USI - Faculty of

The TCP State Machine (Client)

CLOSED

SYN_SENT

applicationopens connection

send SYN

ESTABLISHED

receive SYN,ACK

send ACK

FIN_WAIT_1

applicationcloses connection

send FIN

FIN_WAIT_2

receive ACK

TIME_WAIT

receive FIN

send ACK

wait 30 seconds

Page 95: Transmission Control Protocol (TCP) - USI - Faculty of

The TCP State Machine (Server)

CLOSED

Page 96: Transmission Control Protocol (TCP) - USI - Faculty of

The TCP State Machine (Server)

CLOSED

LISTEN

applicationopens server socket

Page 97: Transmission Control Protocol (TCP) - USI - Faculty of

The TCP State Machine (Server)

CLOSED

LISTEN

applicationopens server socket

SYN_RCVD

receive SYN

send SYN,ACK

Page 98: Transmission Control Protocol (TCP) - USI - Faculty of

The TCP State Machine (Server)

CLOSED

LISTEN

applicationopens server socket

SYN_RCVD

receive SYN

send SYN,ACK

ESTABLISHED

receive ACK

Page 99: Transmission Control Protocol (TCP) - USI - Faculty of

The TCP State Machine (Server)

CLOSED

LISTEN

applicationopens server socket

SYN_RCVD

receive SYN

send SYN,ACK

ESTABLISHED

receive ACK

CLOSE_WAIT

receive FIN

send ACK

Page 100: Transmission Control Protocol (TCP) - USI - Faculty of

The TCP State Machine (Server)

CLOSED

LISTEN

applicationopens server socket

SYN_RCVD

receive SYN

send SYN,ACK

ESTABLISHED

receive ACK

CLOSE_WAIT

receive FIN

send ACK

LAST_ACK

send FIN

Page 101: Transmission Control Protocol (TCP) - USI - Faculty of

The TCP State Machine (Server)

CLOSED

LISTEN

applicationopens server socket

SYN_RCVD

receive SYN

send SYN,ACK

ESTABLISHED

receive ACK

CLOSE_WAIT

receive FIN

send ACK

LAST_ACK

send FIN

receive ACK