No Slide Title - comp

Download Report

Transcript No Slide Title - comp

Chapter 5:
TCP and UDP Basics
Dr. Rocky K. C. Chang
30 March 2004
1
1. Review
• Summary of the last three chapters
– Chap. 2: focus on two hosts which are directly
connected.
– Chap. 3: focus on two hosts which are NOT directly
connected but within the same type of network.
– Chap. 4: focus on how to interconnect
heterogeneous networks.
2
2. The transport problem
• Problem: How to extend the host-to-host
packet delivery service to a process-toprocess communication channel?
• Best-effort service provided by IP:
–
–
–
–
–
drops messages
re-orders messages
delivers duplicate copies of a given message
limits messages to some finite size
delivers messages after an arbitrarily long delay
3
2. The transport problem
• Expectations from transport layer services:
–
–
–
–
–
guarantee message delivery
deliver messages in the same order they are sent
deliver at most one copy of each message
support arbitrarily large messages
support synchronization between the sender and
receiver
– allow the receiver to apply flow control to the
sender
– support multiple application processes on each host
4
3. Types of transport protocols
• Different transport protocols provide different
sets of services:
– User Datagram Protocol (UDP): Mainly provide a
demultiplexing service.
– Transmission Control Protocol (TCP): Provide a
reliable byte-stream service
– Remote Procedure Call (RPC): Provide services to
transaction-based applications.
– Real Time Protocol (RTP): Provide services for
transporting real-time data over UDP.
5
4. UDP (RFC 768)
• UDP adds a demultiplexing service to IP.
– UDP optionally provides error detection but it
becomes mandatory for UDP over IPv6.
• UDP provides the demultiplexing service
through UDP ports.
– The idea is for a source process to send a message
to a port and for a destination process to receive the
message from a port.
– Process IDs can also be used if all systems run on
the same OS.
6
4. UDP (RFC 768)
– A process is uniquely identified by (Port number, IP
address), which is usually referred to as a socket.
– A port is usually implemented by a message queue.
• How does a process learn the port for the other
party?
– For a server process, it will know the client’s port
whenever the client gets connected.
– For a client process, one approach to learn server’s
port is through the well-known port.
7
4.1 UDP message queues
Application
process
Application
process
Application
process
Ports
Queues
Packets
demultiplexed
UDP
Packets arrive
8
4.2 UDP packet
• UDP header format
0
16
31
SrcPort
DstPort
Checksum
Length
Data
• When a sender computes the optional checksum,
a pseudo-header is first prepended to the UDP
header. Why?
9
5. TCP (RFC 793)
• TCP uses connection as its fundamental
abstraction.
– A TCP connection is specified by a pair of sockets,
each of which identifies an endpoint, i.e. <SrcPort,
SrcIPAddr, DstPort, DstIPAddr>
– Unlike UDP, TCP requires both endpoints to agree
to connect.
• TCP provides a connection-oriented, reliable,
byte stream service to the upper layer.
– Need to obtain an explicit agreement from the other
side before sending data.
10
5. TCP (RFC 793)
– The TCP sender provides a reliable service using a
sliding window mechanism, positive
acknowledgment, and retransmission.
– TCP considers the data passed from applications as
streams of bytes.
• Each byte is therefore identified by a number.
• A TCP receiver does not understand the relationship
among bytes.
– TCP supports full-duplex connections.
– TCP also provides congestion control and flow
control services.
11
5. TCP (RFC 793)
Application process
Application process
…
…
Write
bytes
Read
bytes
TCP
TCP
Send buffer
Receive buffer
Segment
Segment … Segment
Transmit segments
12
5.1 End-to-end issues
• Sliding Window Protocol in TCP
– Potentially connects many different hosts
• need explicit connection establishment and termination
– Potentially different RTT
• need adaptive timeout mechanism
– Potentially long delay in network
• need to be prepared for arrival of very old packets
– Potentially different capacity at destination
• need to accommodate different amounts of buffering
– Potentially different network capacity
• need to be prepared for network congestion
13
5.2 TCP connection establishment
• TCP connection setup is asymmetric.
– The one initiates the connection does an active
open.
– The other end does a passive open.
– It involves a total of three special TCP
messages (SYN segments): A three-way
handshaking (1.5 round-trip time).
• Connection establishment timeout
– TCP client resends a SYN segment with
exponential backoff up to a certain time.
14
5.2 TCP connection establishment
• Information exchange during connection
establishment:
– Initial Sequence Numbers (ISN), which are the
first SNs used by the two sides.
– The SYN segment also advertises window size
(buffer available for receiving data).
– Each side may optionally announce the Maximum
Segment Size (MSS) it expects to receive.
• If the destination IP address is local, set MSS to the
local network’s MTU  40 bytes.
• Otherwise, usually set MSS to 536 bytes.
15
5.3 An example
Client
Server
16
5.4 TCP connection termination
• TCP connection termination is symmetric:
Each side has to close the connection
independently.
– At most four FIN segments are needed.
– By closing the connection, it means that no more
data will be sent, but can still receive data.
• A connection in the TIME_WAIT state
cannot move to the CLOSED state until it
has waited for 2Maximum Segment
Lifetime (MSL).
– Reasons for this?
17
5.5 An example
Client
Server
close()
FIN_WAIT_1
CLOSE_WAIT
FIN_WAIT_2
close()
LAST_ACK
TIME_WAIT
CLOSED
CLOSED
18
5.6 TCP state transition diagram
CLOSED
Active open/SYN
Passive open
Close
Close
LISTEN
SYN_RCVD
SYN/SYN + ACK
Send/SYN
SYN/SYN + ACK
ACK
Close/FIN
SYN_SENT
SYN + ACK/ACK
ESTABLISHED
Close/FIN
FIN/ACK
FIN_WAIT_1
CLOSE_WAIT
FIN/ACK
ACK
Close/FIN
FIN_WAIT_2
CLOSING
FIN/ACK
ACK Timeout after two
segment lifetimes
TIME_WAIT
LAST_ACK
ACK
CLOSED
19
5.7 TCP segments
0
10
4
16
31
SrcPort
DstPort
SequenceNum
Acknow ledgment
HdrLen
0
Flags
AdvertisedWindow
Checksum
UrgPtr
Options (variable)
Data
20
5.7 TCP segments
• Data field is optional.
• SN, AN, and window size are all involved in
the sliding window algorithm.
– SN refers to the number of the first data byte.
• The TCP header is not of fixed length due to the
options (MSS, timestamp, window scale, etc).
• The checksum covers the header and the
payload, i.e., end-to-end checksum.
– A pseudo-header is first prepended to the TCP
header before computing the checksum.
21
5.7 TCP segments
• Both urgent pointer and PUSH can be used to
serve as a signal to the receiver about the
“record boundary.”
– The receiving process needs to be notified when the
URG bit or PUSH bit is set.
– These mechanisms serve as end-of-record markers.
– The PUSH bit can also be used to allow the sending
process to send whatever bytes in the buffer (for
interactive applications).
22