TCP & UDP - Protocol Details Yen-Cheng Chen [email protected].

34
TCP & UDP - Protocol Details Yen-Cheng Chen [email protected]

Transcript of TCP & UDP - Protocol Details Yen-Cheng Chen [email protected].

Page 1: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

TCP & UDP- Protocol Details

Yen-Cheng [email protected]

Page 2: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

Port Number

Divided into three ranges: Well Known Ports: 0 ~ 1023 Registered Ports: 1024 ~ 49151 Dynamic and/or Private Ports: 49152 ~ 6553

5

http://www.iana.org/assignments/port-numbers

Page 3: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.
Page 4: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

Source Port Destination Port

Length Checksum

Data

16 bits 16 bits

UDP Header RFC 768

Page 5: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

Checksum

Checksum is the 16-bit one's complement of the one's complement sum of a pseudo headerpseudo header of information from the IP header, the UDP headerUDP header, and the datadata.

Page 6: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

Source Address

Destination Address

00000000

32 bits

Protocol (17) UDP Length

Pseudo Header

Page 8: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

How to Ensure the Delivery of UDP Messages

Time OutRetry

Page 9: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

TCP Segment (TCP PDU)

Source port (16 bits)Destination port (16 bits)Sequence number (32 bits)Acknowledgment number (32 bits)Data Offset (4 bits)Reserved (6 bits)Flags (6 bits) : URG, ACK, PSH, RST, SYN, FIN

Window (16 bits)Checksum (16 bits)Urgent Pointer (16 bits)Options (variable)

RFC 793

Page 10: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.
Page 11: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

TCP Header

Page 12: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

Sequence / Acknowledgment Number

Sequence Number: 32 bits The sequence number of the first data octet in

this segment (except when SYN is present). If SYN is present the sequence number is the initial sequence number (ISN) and the first data octet is ISN+1.

Acknowledgment Number: 32 bits If the ACK control bit is set this field contains the

value of the next sequence number the sender of the segment is expecting to receive. Once a connection is established this is always sent.

Page 13: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

(Seq:X, Ack:Y, Data: a bytes)

(Seq:Y, Ack:X+a)

(Seq:X+a, Ack:Y, Data: b bytes)

(Seq:Y, Ack:X+a+b)

Sen

der

Sen

der

Receiv

er

Receiv

er

Unidirectional Transmission

Page 14: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

(Seq:20000, Ack:100, Data: 1000 bytes)

(Seq:100, Ack:21000)

(Seq:21000, Ack:100, Data: 750 bytes)

(Seq:100, Ack:21750)

Sen

der

Sen

der

Receiv

er

Receiv

er

Example - Unidirectional

Page 15: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

(Seq:X, Ack:Y, Data: a bytes)

(Seq:Y, Ack:X+a, Data: m bytes)

(Seq:X+a, Ack:Y+m, Data: b bytes)

(Seq:Y+m, Ack:X+a+b, Data: n bytes)Sen

der

Sen

der

Receiv

er

Receiv

er

Bi-directional Transmission

(Seq:X+a+b, Ack:Y+m+n, Data: c bytes)

Page 16: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

(Seq:25000, Ack:1000, Data:800 bytes)

(Seq:1000, Ack:25800, Data:500 bytes)

(Seq:25800, Ack:1500, Data: 1000 bytes)

(Seq:1500, Ack:26800, Data: 700 bytes)Sen

der

Sen

der

Receiv

er

Receiv

er

(Seq:26800, Ack:2200, Data: 600 bytes)

Example – Bi-directional

Page 17: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

Window (AdvertisedWindow)Window: 16 bits The number of data octets beginning wit

h the one indicated in the acknowledgment field which the sender of this segment is willing to accept.

The sender is limited to having no more than a value of AdvertisedWindowAdvertisedWindow bytes of unacknowledged data in any given time.

Sliding Window

Page 18: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

Flow/Congestion Control

Slow Start Fast Retransmit – Duplicate ACK Fast Recovery

Implementation Tahoe, Reno, Vegas

Page 19: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

Source Destination

Slow Start

Page 20: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

Fast RetransmitPacket 1

Packet 2

Packet 3

Packet 4

Packet 5

Packet 6

Retransmit

packet 3

ACK 1

ACK 2

ACK 2

ACK 2

ACK 6

ACK 2

Sender Receiver

Page 21: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

Data Offset (Header Length)

Data Offset: 4 bits The number of 32 bit32 bit words in the

TCP Header. This indicates where the data begins. The TCP header (even one including options) is an integral number of 32 bits long.

Page 22: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

FlagsControl Bits: 6 bits (from left to right):URG: Urgent Pointer field significant ACK: Acknowledgment field significant PSH: Push Function RST: Reset the connection SYN: Synchronize sequence numbersFIN: No more data from sender

Page 23: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

Urgent Pointer

Urgent Pointer: 16 bits This field communicates the current value

of the urgent pointer as a positive offset from the sequence number in this segment.

The urgent pointer points to the sequence number of the octet following the urgent data. This field is only be interpreted in segments with the URG control bit set.

Page 24: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

Options / Paddings

Options Maximum Segment Size

Padding to ensure that the TCP header ends

and data begins on a 32 bit boundary.

Page 25: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

Connection Progresses

11 States: LISTEN, SYN-SENT, SYN-RECEIVED,

ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, LAST-ACK, TIME-WAIT, and CLOSED.

Page 26: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

CLOSEDCLOSED

LISTENLISTEN

SYN_RCVDSYN_RCVD SYN_SENTSYN_SENT

ESTABLISHEDESTABLISHED

CLOSE_WAITCLOSE_WAIT

LAST_ACKLAST_ACKCLOSINGCLOSING

TIME_WAITTIME_WAIT

FIN_WAIT_2FIN_WAIT_2

FIN_WAIT_1FIN_WAIT_1

Passive openPassive open CloseClose

Send/Send/ SYNSYN

SYN/SYN + ACKSYN/SYN + ACK

SYN + ACK/ACKSYN + ACK/ACK

SYN/SYN + ACKSYN/SYN + ACK

ACKACK

CloseClose /FIN/FIN

FIN/ACKFIN/ACKCloseClose /FIN/FIN

FIN/ACKFIN/ACKACK + FIN/ACK

ACK + FIN/ACK

Timeout after two Timeout after two segment lifetimessegment lifetimes

FIN/ACKFIN/ACK

ACKACK

ACKACK

ACKACK

CloseClose /FIN/FIN

CloseClose

CLOSEDCLOSED

Active openActive open /SYN/SYN

Page 27: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

TCP Connection States (1)

LISTEN - waiting for a connection request SYN-SENT - waiting for a matching connection request after having sent a connection request.SYN-RECEIVED - waiting for a confirming connection request acknowledgment after having both received and sent a connection request.ESTABLISHED - an open connection, data received can be delivered to the user. The normal state for the data transfer phase of the connection.

Page 28: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

TCP Connection States (2)

FIN-WAIT-1 - waiting for a connection termination request from the remote TCP, or an acknowledgment of the connection termination request previously sent.FIN-WAIT-2 - waiting for a connection termination request from the remote TCP.CLOSE-WAIT - waiting for a connection termination request from the local user.CLOSING - represents waiting for a connection termination request acknowledgment from the remote TCP.

Page 29: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

TCP Connection States (3)LAST-ACK - waiting for an acknowledgment of the connection termination request previously sent to the remote TCP (which includes an acknowledgment of its connection termination request). TIME-WAIT - waiting for enough time to pass to be sure the remote TCP received the acknowledgment of its connection termination request. CLOSED - no connection state at all.

Page 30: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

Basic 3-Way Handshake for Connection Synchronization

(Seq:X, Syn.)

(Seq:Y, Ack:X+1, Ack.,Syn.)

(Seq:X+1, Ack:Y+1, Ack.)

Sen

der

Sen

der

Receiv

er

Receiv

er

Data Transmission

Page 31: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

Example -Connection Synchronization

Page 32: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

Closing a Connection (Seq:X, Ack:Y. Ack.,Fin.)

(Seq:Y, Ack:X+1, Ack..)

Req

ueste

rR

eq

ueste

r

Resp

on

der

Resp

on

der

(Seq:Y, Ack:X+1, Ack.,Fin.)

(Seq:X+1, Ack:Y+1. Ack.)

Page 33: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

Example – Closing a Connection

MSL: Maximum Segment Lifetime

Page 34: TCP & UDP - Protocol Details Yen-Cheng Chen ycchen@ncnu.edu.tw.

TCP Pseudo Header