Lecture 3 - Transport Layer
-
Upload
constantra -
Category
Documents
-
view
10 -
download
0
description
Transcript of Lecture 3 - Transport Layer
![Page 1: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/1.jpg)
Transport layer
Tutor: Lưu Thanh Tràuto ưu a à
![Page 2: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/2.jpg)
Plan
![Page 3: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/3.jpg)
Client-Server model
Request
Response
Client Server
![Page 4: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/4.jpg)
Introduction
Transport layer locates on the layer network3Transport layer locates on the layer network3 Considering the Internet as a black boxDeploying ports for (de)multiplexDeploying ports for (de)multiplex
![Page 5: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/5.jpg)
Overview of TCP protocols
m routetcpdump ping traceroute applic applic traceroute pingm_routetcpdump ping traceroute applic applic traceroute ping
ICMP TCP UDP
IGMP IPv4 IPv6 ICMPv6
ARPRARP
32 bits 128 bits
RARP
BPFDLPI Data link
BSD packer filterDatalink provider interface
![Page 6: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/6.jpg)
Protocols
IPv4, IPv6IPv4, IPv6ARP/RARP (Address Resolution protocol/Reserve ARP)p )ICMP (Internet Control Message Protocol)BPF (BSD Packet filter)BPF (BSD Packet filter)DLPI (Datalink Provider Interface)
![Page 7: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/7.jpg)
TCP
• TCP is a true transport protocol, above IP• TCP “Features”:
• Flow control• Congestion control
TCP payload
• Congestion control• Connection setup• Connection state machine
IPhdr
TCPhdr
• Reliability, at the cost of some delay• Achieves reliability by:
• Retransmission of a segment after a timeout or duplicate ACK
• Sliding window with sequence #’sSliding window with sequence # s
![Page 8: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/8.jpg)
TCP Format• TCP segments have a 20 byte header with >= 0 bytes of data.
20 bytes
![Page 9: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/9.jpg)
TCP header
20 b t20 bytesSource port for TCP sending processD f TCP i iDest port for TCP receiving process32-bit Sequence # (host is sender)32-bit ACK # (host is receiver ACK’ing data sent by other endpoint)
![Page 10: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/10.jpg)
Port Number:A port number identifies the endpoint of a connection.A pair <IP address, port number> identifies one endpoint of a connectionendpoint of a connection. Two pairs <client IP address, server port number> and <server IP address, server port
b > identify a TCP connectionnumber> identify a TCP connection. Applications Applications
TCP
23 10480Ports:
TCP
7 1680 Ports:
IP IP
![Page 11: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/11.jpg)
TCP header fields
Sequence Number (SeqNo):Sequence Number (SeqNo):Sequence number is 32 bits long. So the range of SeqNo isSo the range of SeqNo is
0 <= SeqNo <= 232 -1 ≈ 4.3 Gbyte
Each sequence number identifies a byte in the byte streamInitial Sequence Number (ISN) of a connection is set during connection establishmentis set during connection establishment
Q: What are possible requirements for ISN ?
![Page 12: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/12.jpg)
TCP header fields
Acknowledgement Number (AckNo):Acknowledgements are piggybacked, I.e
a segment from A -> B can contain an acknowledgement for a data sent in the B -> A direction
A hosts uses the AckNo field to send acknowledgements. (If a host sends an AckNo in a segment it sets the “ACK flag”)g g )The AckNo contains the next SeqNo that a hosts wants to receiveExample: The acknowledgement for a segment with p g g
sequence numbers 0-1500 is AckNo=1501
![Page 13: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/13.jpg)
TCP header fieldsAcknowledge Number (cont’d)
TCP uses the sliding window flow protocol (seeTCP uses the sliding window flow protocol (see CS 457) to regulate the flow of traffic from sender to receiverTCP uses the following variation of sliding window:
no NACKs (Negative ACKnowledgement)only cumulative ACKsonly 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 theIn this case, the receiver cannot acknowledge the second packet. It can only send AckNo=1
![Page 14: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/14.jpg)
TCP header fields
Header Length ( 4bits):Header Length ( 4bits):Length of header in 32-bit wordsNote that TCP header has variable lengthNote that TCP header has variable length (with minimum 20 bytes)
![Page 15: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/15.jpg)
TCP header fields
Flag bits: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 validACK: Acknowledgement Number is validPSH: 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
![Page 16: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/16.jpg)
TCP header fields
Flag bits:Flag bits:RST: Reset the connection
The flag causes the receiver to reset the connectionReceiver of a RST terminates the connection and indicates higher layer application about the reset
SYN: Synchronize sequence numbersSYN: Synchronize sequence numbersSent in the first packet when initiating a connection
FIN: Sender is finished with sendingUsed for closing a connectionBoth sides of a connection must send a FIN
![Page 17: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/17.jpg)
TCP header fields
Window Size:Each side of the connection advertises the window size Window size is the maximum number of bytes that a
i treceiver can accept.Maximum window size is 216-1= 65535 bytes
TCP Checksum:TCP Checksum:TCP checksum covers over both TCP header and TCP data (also covers some parts of the IP header)
U t P i tUrgent Pointer:Only valid if URG flag is set
![Page 18: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/18.jpg)
TCP header fields
Options:
End ofOptions kind=0
1 byte
NOP(no operation) kind=1
1 byte
M i maximumMaximumSegment Size kind=2
1 byte
len=4
1 byte
maximumsegment size
2 bytes
Window Scale kind=3 len=3 shift countFactor kind=3
1 byte
len=3
1 byte
shift count
1 byte
Timestamp kind=8 len=10 timestamp value timestamp echo reply
1 byte 1 byte 4 bytes 4 bytes
![Page 19: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/19.jpg)
TCP header fieldsOptions:
NOP is used to pad TCP header to multiplesNOP is used to pad TCP header to multiples of 4 bytesMaximum Segment SizeMaximum Segment SizeWindow 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 p y g(first segment) during connection establishment time
Timestamp OptionTimestamp OptionCan be used for roundtrip measurements
![Page 20: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/20.jpg)
UDP - User Datagram Protocol
UDP extends the host-to-to-host delivery service of IP to an application process-to-application process delivery serviceIt does this by multiplexing and demultiplexing packets from multiple application-to-application communication sessions
![Page 21: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/21.jpg)
TCP vs UDP
• The Internet supports 2 transport protocols
UDP UDP -- User Datagram ProtocolUser Datagram Protocoldatagram oriented
TCP - Transmission Control Protocolg
unreliable, connectionlesssimpleunicast and multicast
stream orientedreliable, connection-orientedcomplex
useful for multimedia applicationsused for control protocols
only unicastused for data applications:
web (http), email (smtp), file network management (SNMP), routing (RIP), naming (DNS), etc.
transfer (ftp), SecureCRT, etc.
![Page 22: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/22.jpg)
UDP packet formatIP header UDP header UDP data (payload)
20 bytes 8 bytesy y
Source Port Number Destination Port Number
UDP message length Checksum0 15 16 31
• Port numbers identify sending and receiving applications (processes). Maximum port number is 216-1= 65,535
• 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
![Page 23: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/23.jpg)
IP header
![Page 24: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/24.jpg)
Header comparison0 15 16 31
vers hlen TOS total length
identification flags flag offset
Removed (6)• ID flags flag offset
20bytes
identification flags flag-offset
TTL protocol header checksum
source address
destination address
• ID, flags, flag offset• TOS, hlen• header checksum
Ch d (3)
IPv4
des o dd ess
options and paddingChanged (3)
• total length => payload• protocol => next header• TTL => hop limit
vers traffic class flow-label
payload length next header hop limitAdded (2)
• TTL => hop limit
• traffic class40
bytessource address
destination addressExpanded
• flow label
dd 32 128 biIPv6
• address 32 to 128 bits
![Page 25: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/25.jpg)
Three-Way Handshake
aida.poly.edu mng.poly.edu
SYN (SeqNo = x)
SYN (SeqNo = y, AckNo = x + 1 )
(SeqNo = x+1, AckNo = y + 1 )
![Page 26: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/26.jpg)
A Closer Look with tcpdumpaida issuesan "telnet mng"
1 aida.poly.edu.1121 > mng.poly.edu.telnet: S 1031880193:1031880193(0)aida.poly.edu mng.poly.edu
an telnet mng
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)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)4 aida.poly.edu.1121 > mng.poly.edu.telnet: P 1031880194:1031880218(24)
ack 172488587 win 175205 mng.poly.edu.telnet > aida.poly.edu.1121: P 172488587:172488590(3)
ack 1031880218 win 8736ack 1031880218 win 87366 aida.poly.edu.1121 > mng.poly.edu.telnet: P 1031880218:1031880221(3)
ack 172488590 win 17520
![Page 27: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/27.jpg)
Three-Way Handshake
aida.poly.edu mng.poly.edu
S 1031880193:1031880193(0)win 16384 <mss 1460mss 1460, ...>
S 172488586:172488586(0)
ack 1031880194 win 8760 <mss 1460>
ack 172488587 win 17520
![Page 28: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/28.jpg)
Why is a Two-Way Handshake not enough?
aida.poly.edu mng.poly.eduS 1031880193:1031880193(0)win 16384
The red
S 15322112354:15322112354(win 1638
80193(0)win 16384 <mss 1460, ...>
line is adelayedduplicatepacket.322112354(0)
win 16384 <mss 1460, ...>
172488586:172488586(0)
1460>
packet.
Will be discarded as a duplicate
S 1724885
win 8760 <mss 1460
When aida initiates the data transfer (starting with SeqNo=15322112355),
SYN
When aida initiates the data transfer (starting with SeqNo 15322112355), mng will reject all data.
![Page 29: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/29.jpg)
TCP Connection Termination
Each end of the data flow must be shut down independently (“half-close”)If one end is done it sends a FIN segment. This
th t d t ill b tmeans that no more data will be sent
Four steps involved: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(4) X ACKs the FIN.
![Page 30: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/30.jpg)
Connection termination with tcpdump
aida issuesan "telnet mng"
aida.poly.edu mng.poly.edu
an telnet mng
1 mng.poly.edu.telnet > aida.poly.edu.1121: F 172488734:172488734(0) ack 1031880221 win 8733ack 1031880221 win 8733
2 aida.poly.edu.1121 > mng.poly.edu.telnet: . ack 172488735 win 174843 aida.poly.edu.1121 > mng.poly.edu.telnet: F 1031880221:1031880221(0)
k 172488735 i 17520ack 172488735 win 175204 mng.poly.edu.telnet > aida.poly.edu.1121: . ack 1031880222 win 8733
![Page 31: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/31.jpg)
TCP Connection Termination
aida.poly.edu mng.poly.edu
F 172488734:172488734(0)ack 1031880221 win 8733
. ack 172488735 wi488735 win 17484
F 1031880221:1031880221(0)ack 172488735 i
. ack 1031880222 win 8733
(0)2488735 win 17520
![Page 32: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/32.jpg)
TCP StatesState Description
CLOSED No connection is active or pendingLISTEN The server is waiting for an incoming callSYN RCVD A connection request has arrived; wait for AckSYN RCVD A connection request has arrived; wait for AckSYN SENT The client has started to open a connectionESTABLISHED Normal data transfer stateFIN WAIT 1 Client has said it is finishedFIN WAIT 1 Client has said it is finishedFIN WAIT 2 Server has agreed to releaseTIMED WAIT Wait for pending packets (“2MSL wait state”)CLOSING B th Sid h t i d t l i lt lCLOSING Both Sides have tried to close simultanesouslyCLOSE WAIT Server has initiated a releaseLAST ACK Wait for pending packets
![Page 33: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/33.jpg)
TCP States in “Normal” Connection Lifetime
SYN (SeqNo = x)SYN_SENTLISTEN(passive open)
SYN (SeqNo = y, AckNo = x + 1 )
(AckNo = y + 1 )
(active open)
SYN_RCVD
ESTABLISHED
ESTABLISHED
FIN WAIT 1FIN (SeqNo = m)
FIN_WAIT_1(active close)
)
CLOSE_WAIT(passive close)
(AckNo = m+ 1 )
FIN (SeqNo = n )FIN_WAIT_2
(AckNo = n+1)LAST_ACK
TIME_WAIT
CLOSEDCLOSED
![Page 34: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/34.jpg)
TCP State Transition DiagramOpening A ConnectionOpening A Connection
CLOSEDactive openi
LISTEN
active opensend: SYN
A li ti d d t
close ortimeout
passive opensend: . / .
recv: SYNsend: SYN, ACK
recv:RST
Application sends datasend: SYN
SYN RCVD SYN SENT
recv: SYN, ACKrecvd: ACK
simultaneous openrecv: SYNsend: SYN ACK
ESTABLISHED
send: ACKec d C
send: . / .send: SYN, ACK
send:FIN
recvd: FIN send: FIN
![Page 35: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/35.jpg)
TCP State Transition DiagramClosing A ConnectionClosing A Connection
![Page 36: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/36.jpg)
2MSL Wait State
2MSL Wait State = TIME_WAITWhen TCP does an active close, and sends the final ACK, the connection must stay in in the TIME_WAIT state for twice the maximum segment lifetime.
2MSL= 2 * Maximum Segment Lifetime
Why?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 secondsThe MSL is set to 2 minutes or 1 minute or 30 seconds.
![Page 37: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/37.jpg)
Resetting Connections
Resetting connections is done by setting theResetting connections is done by setting the RST flag When is the RST flag set?g
Connection request arrives and no server process is waiting on the destination portAbort (Terminate) a connection Causes the receiver to throw away buffered d t R i d t k l d th RSTdata. Receiver does not acknowledge the RST segment
![Page 38: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/38.jpg)
TCP concurrent server
203.162.0.11
Server
203.162.0.12
3
listening
port 53
![Page 39: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/39.jpg)
203.162.0.11
Server
203.162.0.12
listening
192.1.2.3Connection request
Clientport 53 203.162.0.11 port 53
![Page 40: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/40.jpg)
203.162.0.11
Server
203.162.0.12
listening
192.1.2.3
Clientport 53
203.162.0.11203.162.0.12
Server
port 53Connected socket (connfd)
port 53
![Page 41: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/41.jpg)
203.162.0.11
Server
203.162.0.12
listening Client
192.5.6.7Connection request
port 53 203.162.0.11 port 53
203 162 0 11 port 53203.162.0.11 192.1.2.3
203.162.0.11 port 53Server
port 53Connected socket (connfd)
Client
port 53
![Page 42: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/42.jpg)
TCP outputApplication Application buffer (any size)
write User process
TCP Socket send buffer (SO-SNDBUF
write
kernel
User process
MSS size segmentMSS <= MTU-40 (IPv4) or MTU-60 (IPv6)
IP
MSS size
Output queuedatalink
![Page 43: Lecture 3 - Transport Layer](https://reader034.fdocuments.in/reader034/viewer/2022042618/5695d3511a28ab9b029d8196/html5/thumbnails/43.jpg)
UDP outputApplication Application buffer (any size)
write User process
UDP Socket send buffer (SO-SNDBUF
write
kernel
User process
UDP datagram
IP
MSS size
Output queuedatalink