Professional Documents
Culture Documents
Relates to Lab 5. First module on TCP which covers packet format, data transfer, and connection management.
Overview
TCP = Transmission Control Protocol Connection-oriented protocol Provides a reliable unicast end-to-end byte stream over an unreliable internetwork.
Byte Stream Byte Stream
TCP
TCP
IP Internetwork
Connection-Oriented
Before any data transfer, TCP establishes a connection: One TCP entity is waiting for a connection (server) The other TCP entity (client) contacts the server The actual procedure for setting up connections is more complex. SERVER Each connection is CLIENT Request a co nnection full duplex
Accept a c onnection
Data Transer
Disconnect
Reliable
Byte stream is broken up into chunks which are called segments Receiver sends acknowledgements (ACKs) for segments TCP maintains a timer. If an ACK is not received in time, the segment is retransmitted Detecting errors: TCP has checksums for header and data. Segments with invalid checksums are discarded Each byte that is transmitted has a sequence number
4
Application
1. read 40 bytes 2. read 40 bytes 3. read 40 bytes
TCP
Segments
TCP
TCP Format
TCP segments have a minimum 20 byte header with >= 0 bytes of data.
IP header
20 bytes 0 Source Port Number
TCP header
20 bytes 15 16
TCP data
31
Flags
TCP checksum
Ports:
23 80 104 TCP IP
80 16 TCP IP
Ports:
Each sequence number identifies a byte in the byte stream Initial Sequence Number (ISN) of a connection is set during connection establishment
The AckNo contains the next SeqNo that a hosts wants to receive Example: The acknowledgement for a segment with sequence number 0 and 1500 data bytes is AckNo=1500+1
9
Example: Assume: Sender sends two segments with 0..1500 and 1501..3000, but receiver only gets the second segment. In this case, the receiver cannot acknowledge the second packet. It can only send AckNo=0+1
10
11
12
13
14
kind=0
1 byte
kind=1
1 byte
kind=2
1 byte
len=4
1 byte
kind=3
1 byte
len=3
1 byte
shift count
1 byte
Timestamp
kind=8
1 byte
len=10
1 byte
timestamp value
4 bytes
15
Timestamp Option
Can be used for roundtrip measurements
16
Opening a TCP Connection Closing a TCP Connection Special Scenarios State Diagram
17
18
Three-Way Handshake
aida.poly.edu
mng.poly.edu
SYN (Seq
No = x)
(SeqNo = x
+1, AckNo =
y+1)
19
20
Three-Way Handshake
aida.poly.edu
S 103188 0193:1031 880193(0) win 16384 <mss 146 0 , .. .> 8586(0) 8 4 2 7 :1 6 8 5 8 8 S 1724 <mss 1460> 0 6 7 8 in w 4 9 1 ack 1031880
mng.poly.edu
ack 172488
20
21
aida.poly.edu S 1031 880193 :10318 win 16 384 <m 80193(0) ss 146 0, ...> S 1532 211235 win 163 4:1532211235 4 84 < ms s 1460, (0) ...> 86(0) 5 8 8 4 :172 6 8 5 8 48 460> 2 1 7 s 1 s S 0 <m 6 7 8 w in
When aida initiates the data transfer (starting with SeqNo=15322112355), mng will reject all data.
22
Four steps involved: (1) X sends a FIN to Y (active close) (2) Y ACKs the FIN,
(at this time: Y can still send data to X)
(3) and Y sends a FIN to X (passive close) (4) X ACKs the FIN.
23
1 mng.poly.edu.telnet > aida.poly.edu.1121: F 172488734:172488734(0) ack 1031880221 win 8733 2 aida.poly.edu.1121 > mng.poly.edu.telnet: . ack 172488735 win 17484 3 aida.poly.edu.1121 > mng.poly.edu.telnet: F 1031880221:1031880221(0) ack 172488735 win 17520 4 mng.poly.edu.telnet > aida.poly.edu.1121: . ack 1031880222 win 8733
24
aida.poly.edu
F 172488734:172488734(0) ack 1031880221 win 8733 . ack 1 7 2488735 win 174 84
mng.poly.edu
25
TCP States
State CLOSED LISTEN SYN RCVD SYN SENT ESTABLISHED FIN WAIT 1 FIN WAIT 2 TIMED WAIT CLOSING CLOSE WAIT LAST ACK Description No connection is active or pending The server is waiting for an incoming call A connection request has arrived; wait for Ack The client ha s started to open a connection Normal data transfer state Client has said it is finished Server has agreed to release Wait for pending packets ( 2MSL wait state ) Both Sides have tried to close simultaneously Server has initiated a release Wait for pending packets
26
SYN (SeqNo = x)
LISTEN
(passive open)
y, AckN = o N q e (S N Y S
o=x+1)
SYN_RCVD
(AckNo = y + 1 )
ESTABLISHED ESTABLISHED FIN_WAIT_1 (active close) FIN_WAIT_2
FIN (SeqNo = m)
(AckNo = m+ 1 )
CLOSE_WAIT (passive close)
FIN (SeqNo = n )
TIME_WAIT
(AckNo =
LAST_ACK
n+1)
CLOSED
27
LISTEN
recv: RST recv: SYN send: SYN, ACK
SYN RCVD
recvd: ACK send: . / . send: FIN recvd: FIN
SYN SENT
recv: SYN, ACK send: ACK
ESTABLISHED
send: FIN
28
ESTABLISHED
recv: FIN send: ACK
FIN_WAIT_1
recv: ACK send: . / .
CLOSING
recvd: ACK send: . / .
CLOSE_WAIT
application closes send: FIN
LAST_ACK
FIN_WAIT_2
TIME_WAIT
Timeout (2 MSL) recv: ACK send: . / .
CLOSED
29
30
Resetting Connections
Resetting connections is done by setting the RST flag When is the RST flag set? Connection request arrives and no server process is waiting on the destination port Abort (Terminate) a connection Causes the receiver to throw away buffered data. Receiver does not acknowledge the RST segment
31