Module13 tcp1 PDF
Module13 tcp1 PDF
Overview
Byte Stream
TCP TCP
IP Internetwork
1
Connection-Oriented
Data Transer
Disconnect
Reliable
Detecting errors:
2
Byte Stream Service
queue of queue of
bytes to be bytes that
Segments
TCP transmitted TCP have been
received
TCP Format
0 15 16 31
DATA
3
TCP header fields
Port Number:
A port number identifies the endpoint of a connection.
A pair <IP address, port number> identifies one
endpoint of a connection.
Two pairs <client IP address, server port number>
and <server IP address, server port number> identify
a TCP connection.
Applications Applications
IP IP
4
TCP header fields
10
5
TCP header fields
11
Flag bits:
URG: Urgent pointer is valid
If the bit is set, the following bytes contain an urgent message in
the range:
SeqNo <= urgent message <= SeqNo+urgent pointer
ACK: Acknowledgement Number is valid
PSH: PUSH Flag
Notification from sender to the receiver that the receiver should
pass all data that it has to the application.
Normally set by sender when the senders buffer is empty
12
6
TCP header fields
Flag bits:
RST: Reset the connection
The flag causes the receiver to reset the connection
Receiver of a RST terminates the connection and indicates
higher layer application about the reset
SYN: Synchronize sequence numbers
Sent in the first packet when initiating a connection
FIN: Sender is finished with sending
Used for closing a connection
Both sides of a connection must send a FIN
13
Window Size:
Each side of the connection advertises the window size
Window size is the maximum number of bytes that a
receiver can accept.
Maximum window size is 2 16-1= 65535 bytes
TCP Checksum:
TCP checksum covers over both TCP header and TCP
data (also covers some parts of the IP header)
Urgent Pointer:
Only valid if URG flag is set
14
7
TCP header fields
Options:
End of
Options kind=0
1 byte
NOP
(no operation) kind=1
1 byte
Maximum maximum
Segment Size kind=2 len=4
segment size
1 byte 1 byte 2 bytes
Window Scale
Factor kind=3 len=3 shift count
1 byte 1 byte 1 byte
15
Options:
NOP is used to pad TCP header to multiples of 4 bytes
Maximum Segment Size
Window Scale Options
Increases the TCP window from 16 to 32 bits, I.e., the window
size is interpreted differently
Q: What is the different interpretation ?
This option can only be used in the SYN segment (first
segment) during connection establishment time
Timestamp Option
Can be used for roundtrip measurements
16
8
Connection Management in TCP
17
18
9
Three-Way Handshake
aida.poly.edu mng.poly.edu
SYN (Seq
No = x)
+1)
y, AckNo = x
SYN (SeqNo =
(SeqNo = x+
1, AckNo =
y+1)
19
aida issues
an "telnet mng"
aida.poly.edu mng.poly.edu
1 aida.poly.edu.1121 > mng.poly.edu.telnet: S 1031880193:1031880193(0)
win 16384 <mss 1460,nop,wscale 0,nop,nop,timestamp>
2 mng.poly.edu.telnet > aida.poly.edu.1121: S 172488586:172488586(0)
ack 1031880194 win 8760 <mss 1460>
3 aida.poly.edu.1121 > mng.poly.edu.telnet: . ack 172488587 win 17520
4 aida.poly.edu.1121 > mng.poly.edu.telnet: P 1031880194:1031880218(24)
ack 172488587 win 17520
5 mng.poly.edu.telnet > aida.poly.edu.1121: P 172488587:172488590(3)
ack 1031880218 win 8736
6 aida.poly.edu.1121 > mng.poly.edu.telnet: P 1031880218:1031880221(3)
ack 172488590 win 17520
20
10
Three-Way Handshake
aida.poly.edu mng.poly.edu
S 103188
0193:1031
win 16384 880193(0)
<mss 146
0, ...>
172488 6(0)
58
S 172488586: ss 1460>
94 win 8760 <m
ack 10318801
ack 172488
587 win 1752
0
21
aida.poly.edu mng.poly.edu
S 1031
880193
win 16 :10318 The red
384 <m 80193(0)
ss 146 line is a
0, ...>
delayed
S 1532 duplicate
211235
4:15322 packet.
win 163 112354
84 <ms (0)
s 1460,
...>
0) Will be discarded
8586(
586:17248 > as a duplicate
488 60
S 172 0 <mss 14 SYN
in 876
w
11
TCP Connection Termination
23
aida issues
an "telnet mng"
aida.poly.edu mng.poly.edu
24
12
TCP Connection Termination
aida.poly.edu mng.poly.edu
F 172488734:172488734(0)
ack 1031880221 win 8733
. ack 17
2488735
win 1748
4
F 10318
8022
ack 1724 1:1031880221(0
88735 w )
in 17520
22 win 8733
. ack 10318802
25
TCP States
State Description
26
13
TCP States in Normal Connection Lifetime
CLOSED
27
CLOSED
passive open active open
close or send: SYN
send: . / .
timeout
LISTEN
Application sends data
send: SYN
recv: recv: SYN
RST send: SYN, ACK
28
14
TCP State Transition Diagram
Closing A Connection
29
Why?
TCP is given a chance to resent the final ACK. (Server will
timeout after sending the FIN segment and resend the FIN)
The MSL is set to 2 minutes or 1 minute or 30 seconds.
30
15
Resetting Connections
31
16