CSEE W4140 Networking Laboratory Lecture 6: TCP and UDP Jong Yul Kim

advertisement
CSEE W4140
Networking Laboratory
Lecture 6: TCP and UDP
Jong Yul Kim
03.01.2010
Maximum Transmission Unit
 Maximum size of IP datagram is 65535, but the data link layer protocol generally
imposes a limit that is much smaller
 For example:
 Ethernet frames have a maximum payload of 1500 bytes
IP datagrams encapsulated in Ethernet frame cannot be longer than 1500 bytes
 The limit on the maximum IP datagram size, imposed by the data link protocol is
called maximum transmission unit (MTU)
 MTUs for various data link layers:
Ethernet:
802.3:
802.5:
1500
1492
4464
FDDI:
4352
ATM AAL5: 9180
PPP:
296
 What if the size of an IP datagram exceeds the MTU?
IP datagram is fragmented into smaller units.
 What if the route contains networks with different MTUs?
Maximum Transmission Unit
 Maximum size of IP datagram is 65535, but the data link
layer protocol generally imposes a limit that is much smaller
 Example:
 Ethernet frames have a maximum payload of 1500 bytes
 IP datagrams encapsulated in Ethernet frame cannot be
longer than 1500 bytes
 The limit on the maximum IP datagram size, imposed by the
data link protocol is called maximum transmission unit
(MTU)
MTUs for various data link protocols:
Ethernet: 1500
802.3:
1492
802.5:
4464
FDDI:
4352
ATM AAL5: 9180
PPP:
negotiated
IP Fragmentation
 What if the size of an IP datagram exceeds the MTU?
IP datagram is fragmented into smaller units.
 What if the route contains networks with different MTUs?
FDDI
Ring
Host A
MTUs:
FDDI: 4352
Ethernet
Router
Host B
Ethernet: 1500
• Fragmentation:
• IP router splits the datagram into several datagram
• Fragments are reassembled at receiver
Where is Fragmentation done?
 Fragmentation can be done at the sender
or at intermediate routers
 The same datagram can be fragmented
several times.
 Reassembly of original datagram is only
done at destination hosts !!
IP datagram
H
Fragment 2
Router
H2
Fragment 1
H1
What’s involved in
Fragmentation?
 The following fields in the IP header are
involved:
version
header
length
DS
Identification
time-to-live (TTL)
Identification
protocol
total length (in bytes)
ECN
0
DM
F F
Fragment offset
header checksum
When a datagram is fragmented, the
identification is the same in all fragments
Flags
DF bit is set: Datagram cannot be fragmented and must
be discarded if MTU is too small
MF bit set: This datagram is part of a fragment and an
additional fragment follows this one
What’s involved in
Fragmentation?
 The following fields in the IP header are
involved:
version
header
length
DS
Identification
time-to-live (TTL)
Fragment offset
Total length
protocol
total length (in bytes)
ECN
0
DM
F F
Fragment offset
header checksum
Offset of the payload of the current
fragment in the original datagram
Total length of the current fragment
Example of Fragmentation
 A datagram with size 2400 bytes must be
fragmented according to an MTU limit of
1000 bytes
Header length: 20
Total length:
2400
Identification:
0xa428
DF flag:
0
MF flag:
0
Fragment offset: 0
Header length: 20
Total length:
448
Identification:
0xa428
DF flag:
0
MF flag:
0
Fragment offset: 244
IP datagram
Header length: 20
Header length: 20
Total length:
996
Total length:
996
Identification:
0xa428 Identification:
0xa428
DF flag:
0
DF flag:
0
MF flag:
1
MF flag:
1
Fragment offset: 122
fragment offset: 0
Fragment 3
MTU: 4000
MTU: 1000
Router
Fragment 2
Fragment 1
Today’s topics
 We move one layer up and look at the transport layer.
User
Process
User
Process
User
Process
TCP
User
Process
Application
Layer
UDP
Transport
Layer
ICMP
IP
IGMP
Network
Layer
ARP
Hardware
Interface
RARP
Link Layer
Media
UDP vs TCP
UDP - User Datagram Protocol
 UDP supports unreliable transmissions of datagrams
 UDP merely extends the host-to-to-host delivery
service of IP datagram to an application-toapplication service
 The only thing that UDP adds is multiplexing and
demultiplexing
Applications
Applications
UDP
UDP
IP
IP
IP
IP
IP
UDP Format
IP header UDP header
20 bytes
UDP data
8 bytes
Source Port Number
Destination Port Number
UDP message length
Checksum
DATA
0
15 16
31
• Port numbers identify sending and receiving applications (processes).
Maximum port number is 216-1= 65,535
• Message Length is at least 8 bytes (I.e., Data field can be empty) and at
most 65,535
• Checksum is for header (of UDP and some of the IP header fields)
Port Numbers
 UDP (and TCP) use port numbers to identify
applications
 A globally unique address at the transport layer (for
both UDP and TCP) is a tuple <IP address, port
number>
 There are 65,535 UDP ports per host.
User
Process
User
Process
User
Process
User
Process
TCP
User
Process
UDP
IP
User
Process
Demultiplex
based on
port number
Demultiplex
based on
Protocol field in IP
header
TCP - Transmission Control Protocol
 Reliable and in-order byte-stream
service




TCP format
Connection establishment
Flow control
Reaction to congestion
Next Lecture
TCP Format
• TCP segments have a 20 byte header with >= 0 bytes of data.
IP header TCP header
20 bytes
TCP data
20 bytes
0
15 16
Source Port Number
31
Destination Port Number
Sequence number (32 bits)
header
length
0
Flags
TCP checksum
window size
urgent pointer
Options (if any)
DATA
20 bytes
Acknowledgement number (32 bits)
TCP header fields
Sequence Number (SeqNo):
 Sequence number is 32 bits long.
 So the range of SeqNo is
0 <= SeqNo <= 232 -1  4.3 Gbyte
 Each sequence number identifies a byte
in the byte stream
 Initial Sequence Number (ISN) of a
connection is set during connection
establishment
Q: What are possible requirements for ISN ?
TCP header fields
 Acknowledgement Number (AckNo):
 The AckNo contains the next SeqNo that a hosts wants to
receive
Example:
The acknowledgement for a segment with
sequence numbers 0-1500 is AckNo=1501
 A hosts uses the Acknowlegement Number field to send
acknowledgements. (If a host sends an AckNo in a segment it
sets the “ACK flag”)
 Acknowledgements are piggybacked, i.e.,
a segment from A -> B can contain an acknowledgement for
a data sent in the B -> A direction
Q: Why is piggybacking good ?
TCP header fields
Header Length ( 4bits):
 Length of header in 32-bit words
 Note that TCP header has variable length
(with minimum 20 bytes)
TCP header fields
 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 sender’s buffer
is empty
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
TCP header fields
 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 216-1= 65535 bytes
 TCP Checksum:
 TCP checksum covers over both TCP header and TCP
data (also covers some parts of the IP header)
 16-bit one’s complement
 Urgent Pointer:
 Only valid if URG flag is set
Three-Way Handshake
Why is two-way handshake not enough?
TCP States in “Normal” Connection
Lifetime
SYN_SENT
(active open)
SYN (SeqNo = x)
AckNo
,
y
=
o
N
q
e
(S
SYN
=x+1)
LISTEN
(passive open)
SYN_RCVD
(AckNo = y + 1 )
ESTABLISHED
ESTABLISHED
FIN_WAIT_1
(active close)
FIN_WAIT_2
TIME_WAIT
FIN (SeqNo = m)
(AckNo = m+ 1 )
CLOSE_WAIT
(passive close)
FIN (SeqNo = n )
(AckNo =
LAST_ACK
n+1)
CLOSED
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
Announcement
 Midterm next week
 Prelabs 1 ~ 5
 Lectures 1 ~ 6
 Labs 1 ~ 4
Main Points of Lab 5 Parts 1~4
 TCP and UDP
 Throughput
 IP Fragmentation
 TCP Connection Management
Homework
 No prelab due this Friday
 Lab report 5 part 1 due by next week
Download