Professional Documents
Culture Documents
Tutor: Lu Thanh Tr
Plan
Client-Server model
Request
Response
Client
Server
Introduction
Transport layer locates on the layer network3
ICMP
TCP
UDP
IGMP
IPv4
32 bits
IPv6
128 bits
ICMPv6
ARP RARP BPF DLPI BSD packer filter Datalink provider interface Data link
Protocols
IPv4, IPv6
protocol/Reserve ARP) ICMP (Internet Control Message Protocol) BPF (BSD Packet filter) DLPI (Datalink Provider Interface)
TCP
TCP is a true transport protocol, above IP TCP Features:
Flow control Congestion control IP TCP Connection setup hdr hdr Connection state machine Reliability, at the cost of some delay
TCP payload
Retransmission of a segment after a timeout or duplicate ACK Sliding window with sequence #s
TCP Format
TCP segments have a 20 byte header with >= 0 bytes of data.
IP header TCP header
20 bytes 0 Source Port Number 20 bytes 15 16 31
TCP data
Flags
TCP checksum
TCP header
20 bytes Source port for TCP sending process Dest port for TCP receiving process 32-bit Sequence # (host is sender) 32-bit ACK # (host is receiver ACKing data sent by other endpoint)
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
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 Q: What are possible requirements for ISN ?
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
TCP uses the sliding window flow protocol (see CS 457) to regulate the flow of traffic from sender to receiver TCP uses the following variation of sliding window:
no NACKs (Negative ACKnowledgement) only cumulative ACKs
Example:
Assume: Sender sends two segments with 1..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=1
Length of header in 32-bit words Note that TCP header has variable length (with minimum 20 bytes)
URG:
If the bit is set, the following bytes contain an urgent message in the range:
SeqNo <= urgent message <= SeqNo+urgent pointer
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
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
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
application process-to-application process delivery service It does this by multiplexing and demultiplexing packets from multiple application-to-application communication sessions
Applications Applications
UDP
UDP
IP
IP router
IP router
IP router
IP
TCP vs UDP
The Internet supports 2 transport protocols
UDP - User Datagram Protocol datagram oriented unreliable, connectionless simple unicast and multicast useful for multimedia applications used for control protocols network management (SNMP), routing (RIP), naming (DNS), etc.
TCP - Transmission Control Protocol stream oriented reliable, connection-oriented complex only unicast used for data applications: web (http), email (smtp), file transfer (ftp), SecureCRT, etc.
Checksum
31
Message Length is between 8 bytes (i.e., data field can be empty) and 65,535 bytes (length of UDP header and data in bytes)
Checksum is for UDP header and UDP data
IP header
Header comparison
0 vers hlen 15 16 TOS flags total length flag-offset 31
Removed (6)
ID, flags, flag offset TOS, hlen header checksum
header checksum
Changed (3)
total length => payload protocol => next header TTL => hop limit
IPv4
vers traffic class flow-label next header hop limit
Added (2)
traffic class flow label
payload length
40 bytes
source address
destination address
Expanded
address 32 to 128 bits
IPv6
Three-Way Handshake
aida.poly.edu
mng.poly.edu
SYN (Seq No = x)
AckNo N (SeqNo = y, SY
=x+1)
(SeqNo = x +
1, A c k N o =
y+1)
2 3 4 5 6
Three-Way Handshake
aida.poly.edu
S 103188 0193:1031 880193(0) win 16384 <mss 146 0 , .. .> 586(0) 88586:172488 S 1724 <mss 1460> 194 win 8760 ack 1031880
mng.poly.edu
ack 172488
20
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) ...> 6(0) 48858 172 8586: 1460> 48 S 172 0 <mss 76 w in 8
When aida initiates the data transfer (starting with SeqNo=15322112355), mng will reject all data.
independently (half-close) If one end is done it sends a FIN segment. This means that no more data will be sent
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.
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
aida.poly.edu
F 172488734:172488734(0) ack 1031880221 win 8733 . ack 1 7 2488735 win 174 84
mng.poly.edu
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 has 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 simultanesously Server has initiated a release Wait for pending packets
SYN (SeqNo = x)
LISTEN
(passive open)
y, AckN YN (SeqNo = 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
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
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
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.
Resetting Connections
Resetting connections is done by setting the
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
Server
192.1.2.3
Client
192.1.2.3
Client
203.162.0.11 203.162.0.12
Server
Connected socket (connfd) port 53
192.5.6.7
Client
192.1.2.3
Server
Connected socket (connfd) port 53
Client
TCP output
Application Application buffer (any size) write TCP Socket send buffer (SO-SNDBUF MSS size segment MSS <= MTU-40 (IPv4) or MTU-60 (IPv6) IP MSS size User process kernel
UDP output
Application Application buffer (any size) write UDP Socket send buffer (SO-SNDBUF UDP datagram IP MSS size User process kernel