Professional Documents
Culture Documents
MSL c7 - Part 4 - Udp TCP
MSL c7 - Part 4 - Udp TCP
1
Lớp vận chuyển và giao thức UDP, TCP
2
Các kiểu chuyển tiếp dữ liệu
3
Lớp vận chuyển
Lớp vận chuyển – giám sát và chuyển tiếp dữ liệu của các tiến trình xử lý hoặc
Transport Layer các chương trình lớp ứng dụng trên máy tính này sang máy
tính khác trong mạng.
Mở rộng chức năng của tầng mạng và cho phép thiết lập
kênh tuyền thông logic giữa các tiến trình lớp ứng dụng
4
Các chức năng của lớp vận chuyển
(1) Đóng gói Với dữ liệu được phát sinh từ các chương trình lớp ứng dụng,
Packetizing lớp vận chuyển cần phải đáp ứng xử lý để chuyển tiếp gói tin.
1) Chia nhở các gói tin lớn thành các phần nhỏ để phân lớp mạng có thể
xử lý.
2) Thêm phần tiêu đề vào mỗi gói tin chứa các phần dữ liệu được chia
để phía thu có thể tái ghép lại.
(2) Điều khiển kết nối Hỗ trợ bởi một số giao thức trong họ giao thức TCP/IP
Connection Control
(3) Đảm bảo tính tin cậy Hai kiểu chuyển tiếp gói tin giữa các trình ứng dụng của
Reliability lớp vận chuyển:
1) Dịch vụ hướng kết nối - connection oriented (TCP)
Thiết lập kết nối
Điều khiển luồng
Chuyển tiếp và thu nhận gói tin theo đúng thứ tự
Điều khiển lỗi
Điều khiển tắc nghẽn
2) Dịch vụ không hướng kết nối - connectionless (UDP)
Không đảm bảo tính tin cậy, chuyển tiếp gói tin không theo thứ tự
Giới gian tính năng trong điều khiển lỗi 5
Các chức năng của lớp vận chuyển
(4) Addressing Địa chỉ lớp ứng dụng (địa chỉ cổng) dùng để phân biệt giữa các
tiến trình xử lý lớp trên đang thực hiện truyền thông dữ liệu.
Cơ chế đánh địa chỉ cổng cho phép ghép luồng và tách luồng dữ liệu cho các ứng dụng lớp trên 6
Ghép luồng và tách luồng dữ liệu cho
các ứng dụng lớp trên
7
Địa chỉ cổng
Địa chỉ cổng Giá trị nguyên 16-bit từ 0 đến 65,535 được dùng trong các giao thức
(chỉ số cổng) truyền thông TCP hoặc UDP để định danh về mặt logic cho các kết nối
Các địa chỉ phổ biến (0–1023) – được ấn định cho các ứng dụng mạng
phổ biến và được quản lý bởi ICANN (Internet Corporation for
Assigned Names and Numbers) –được sử dụng bởi hệ điều hành cho
ứng dụng chạy trên các máy chủ đáp ứng nhiều kết nối
(e.g. FTP = 21, TELNET = 23, HTTP = 80, etc.)
Các địa chỉ đã được đăng ký (1024 – 49,151) – chỉ định bởi ICANN –
thông thường được sử dụng cho các ứng dụng phía đầu cuối người
dung có kết nối với các máy chủ trên mạng;
Dải địa chỉ động (49,152 – 65,535) – dải giá trị địa chỉ cổng dự phòng,
có thể được sử dụng trong những giao thức hay chương trình truyền
thông riêng mà không cần đăng ký
8
Giao thức truyền thông UDP
UDP
message UDP
UDP segment
UDP
header
UDP
header
9
Giao thức truyền thông UDP
Giao thức vận chuyển Là giao thức lớp vận chuyển không hướng kết nối và không
UDP đảm bảo tính tin cậy (không điều khiển luồng và giới hạn
việc kiểm tra dữ liệu) . UDP không thêm bất cứ xử lý nào
với các dịch vụ ở lớp IP, ngoại trừ cho phép cơ chế xử lý
ghép/tách các luồng dữ liệu truyền thông
Các ưu điểm chính 1) Không cần thiết lập kết nối giữa các hệ thông đầu cuối.
Với giao thức TCP cần có xứ thiết lập kêt nối “bắt tay 3 bước” trước khi
truyền nhận các gói dữ liệu trễ thiết lập.
2) Không kiểm soát trạn thái kết nối – xử lý phần thông tiêu đề đơn giản.
Với giao thức TCP cần quản lý trạng thái kết nối ở mỗi hệ thông đầu cuối và
quản lý các thông tin khác như các chỉ số các gói dữ liệu truyền và nhận,
chỉ số các gói tin báo nhận ACK
3) Phần thông tin tiêu đề ngắn – chỉ có 8-byte.
So với giao thức TCP, phần thông tin tiêu đề là 20-bytes
4) Không điều khiển luồng và điều khiển tắc nghẽn – UDP có thể gửi các gói
nhanh nhất có thể.
ứng dụng tốt trong các dịch vụ truyền dữ liệu thời gian thực.
10
Cấu trúc gói tin UDP
Gói tin UDP 8 byte tiêu đề + dữ liệu lớp ứng dụng
header = 4 fields
only, each
consisting of 2
bytes
Chiều dài tổng Chỉ định kích thước của gói tin UDP bao gồm cả phần tiêu đề và tải
trong
16 bits ⇒ giá trị max có thể là 65,535 bytes; tuy nhiên do sự giới hạn về
tài nguyên bộ nhớ được phép cấp phát của hệ điều hành nên gói tin
UDP có kích thước tối đa là 8192
Chuỗi kiểm tra Chỉ dùng để xác định lỗi với dữ liệu trong gói tin UDP (header +
data)
Việc tính toán kiểm tra được tùy chọn! - Nếu không cần tính, dữ
liệu thết lập cho trường này là các bít 0
Nếu có lỗi được xác định, bản tin được bỏ qua và khong có xử nào
được thực hiện tiếp sau. 11
Tính Checksum cho phần tiêu đề của gói tin UDP
12
Giao thức truyền thông UDP
13
Địa chỉ cổng của các ứng dụng chạy trên giao thức UDP
14
Giao thức truyền thông TCP
Giao thức điều khiển truyền dẫn Là giao thức lớp vận chuyển có các thuộc tính sau:
TCP Định hướng kết nối: giữa các hệ thống đầu cuối phải bắt tay “handshake”
trước khi thực hiện truyền thông
Tính tin cậy = dữ liệu được sắp xếp + điều khiển lỗi: điều khiển lỗi
trong TCP bao gồm cả cơ chế xác định lỗi, xác định thứ tự và tinh sao chép
của các gói dữ liệu được xử lý.
Tính liên tục: Nếu dữ liệu bị chuyển tiếp sai và vượt quá thời gian cho phép
TCP sẽ cảnh báo với hệ thống và ngắt kết nối
Điều khiển tắc nghẽn: TCP giới hạn số lượng dữ liệu được chuyển tải
trong mạng nằm trong khả năng chuyển tải của mạng.
Kết nối điểm – điểm: kết nối TCP được thiết lập giữa hai phía phát và
phía thu theo tính chất một – một.
Truyền dẫn song công: xử lý phát và nhận độc lập, và dữ liệu truyển tải
theo hai hướng đồng thời. 15
Giao thức truyền thông TCP
Cấu trúc gói tin TCP
16
Cấu trúc gói tin TCP
Chỉ số phân đoạn dữ liệu Trường thông tin 32-bit, giúp cho xử lý phía thu xác định
Sequence Numbet được vị trí của byte đầu tiên trong mỗi bản tin (segment)
Chỉ số báo nhận Trường thông tin 32-bit – chỉ định vị trí của byte kế tiếp cần
được truyền đi ở phía phát
Chiều dài tiêu đề Trường thông tin 4-bit , là giá trị bội số của 4, chỉ định kích
thước (số byte) của phần thông tin tiêu đề
Reserved Trường thông tin 6-bit , trường thông tin dữ phòng (chứa
dùng)
Window Size Trường thông tin 16-bit , chỉ định kích thước của phần dữ
liệu trong bản tin TCP
17
Cấu trúc gói tin TCP
Chuỗi kiểm tra trường thông tin 16 bit – sử dụng để xác định lỗi thành phần dữ
liệu trong gói tin TCP bao gồm (header + data) + 96-bit để đảm
bảo tính chính xác cho các xử lý, tính toán tiếp theo.
phần giả tiêu đề chứa một số trường thông tin trong phần tiêu đề gói
tin IP gồm: địa chỉ nguồn và địa chỉ đích, giao thức và chiều dài phân đoạn
dữ liệu. Phần giả tiêu đề này sẽ giúp xử lý chuyển tiếp nhầm bởi phân lớp
IP.
phần tiêu đề giả ngẫu nhiên giúp tránh xử lý với gữ liệu bị chuyển tiếp
nhầm ở lớp IP
Urgent Pointer – trường thông tin 16 bit – chỉ định vị trí (thứ tự) của byte cuối cùng trong khối
dữ liệu cần được truyền.
Options – có thể mở rộng lên 40 byte để mang thêm các thông tin dùng cho các quá trình xử lý
điều khiển luồng/ điều khiển tắc nghẽn …
Padding – các bít chèn, cách ly giữa phần thông tin tiêu đề và dữ liệu, được thiết lập là các bít 0
18
Cấu trúc gói tin TCP
19
Các giá trị cờ điều khiển
Flag Miêu tả
Nếu bít được thiết lập, Xử lý thu nhận sẽ phân tích trường thông tin con trỏ
URG “urgent pointer”, để sử dụng khi dữ liệu cần đọc ra theo thứ tự trong chương
trình xử lý ở phía thu nhận
ACK Bít được thiết lập để báo nhận không lỗi với gói tin nhận được.
Nếu bít được thiết lập, phía nhận cần chuyển tiếp phân đoạn gói tin IP tới
PSH chương trình thu nhận phía thu ngay lập tức, không cần chờ cho đến khi bộ
đệm thu nhận được điền đầy
Nếu bít được thiết lập, sẽ báo hiệu phía thu bằng phía gửi đang thực hiện
RST ngắt kết nối và tất cả dữ liệu truyền thông đã được chuyển vào bộ đệm để xử
lý.
Khi bít được thiết lập, báo hiệu rằng phía phát đang thực hiện đồng bộ kết
SYN nối. Bít được sử dụng trong quá trình thiết lập kết nối giữa phía phát và phía
thu.
FIN Nếu thiết lập, báo hiệu phía thu rằng phía phát đã nhận được bít cuối cùng
của luồng dữ liệu TCP hiện tại.
20
Chuyển tiếp luồng theo giao thức TCP
– Không giống với UDP, TCP là giao thức “thiên hướng dòng dữ liệu”
(stream-oriented’ protocol)
• TCP cho phép xử lý chuyển tiếp dữ liệu như một “luồng” (dòng) byte (với cả
ở phía phát và phía thu nhận)
• TCP thiết lập môi trường để các xử lý/ứng dụng lớp trên kết nối truyền
thông dữ liệu với nhau qua một đối tượng ảo, được gọi là một “đường ống”
(tube); xử lý phát sẽ ghi (xuất) dữ liệu vào đường ống, còn phía thu sẽ đọc dữ
liệu từ đường ống
21
Các bộ đệm dữ liệu TCP
Xử lý TCP cần các bộ đệm để chứa dữ liệu – Xử lý phía phát và phía thu truyền và
thu nhận dữ liệu với tốc độ không giống nhau
Thiết lập kết nối Các tranh TCP phải thiết lập kết nối trước khi gửi đi dữ liệu của
mình, thông qua quá trình thiết lập kết nối bắt tay ba bước.
TCP
“Three-Way Handshake”:
(1) máy trạm gửi bản tin yêu cầu kết nối SYN cho server, kèm theo
các thông tin:
• Source and Destination Port – chỉ định địa chỉ cổng (chỉ số cổng)
truyền thông
• SYN = 1
• Sequence Number = client_seq – thiết lập giá trị ngẫu nhiên
• Không mang theo dữ liệu!!!
Cấp phát bộ
đệm dữ liệu
Cấp phát bộ
đệm dữ liệu
ACK = Client seq + Client TCP
Length
23
Điều khiển thiết lập kết nối theo giao thức TCP
(3) khi phía máy trạm nhận được bản tin SYNACK, nó cũng cấp phát bộ nhớ và
thiết lập các biến cho xử lý truyền thông, và gửi lại bản tin báo nhận (ACK)
• SYN = 0 – kết nối đã được thiết lập!
• Sequence Number = client_seq + 1
• ACK = server_seq + 1
24
Điều khiển thiết lập kết nối theo giao thức TCP
Máy trạm A (client) yêu cầu kết nối với A’s port B’s port
máy chủ B (server) …
A’s Initial Sequence Number
Acknowledgment
Options (variable)
Các cờ : SYN
FIN
RST
PSH
URG
ACK
25
Điều khiển thiết lập kết nối theo giao thức TCP
B chấp nhận yêu cầu kết nối từ A, và phản B’s port A’s port
hồi gói tin, chờ các gói dữ liệu tiếp theo…
B’s Initial Sequence Number
… A nhận gói tin phản hồi từ B, chuẩn bị A’s ISN plus 1
kết nối với B …
20 0 Flags Advertised window
Options (variable)
Các cờ : SYN
FIN
RST
PSH
URG
ACK
26
Điều khiển thiết lập kết nối theo giao thức TCP
A xác nhận lại với B bằng 1 gói dữ liệu A’s port B’s port
và bắt đầu truyền thông dữ liệu…
Sequence number
… Khi B nhận được xác nhận từ A, cũng
B’s ISN plus 1
bắt đầu quá trình truyền thông dữ liệu…
20 0 Flags Advertised window
Options (variable)
Các cờ : SYN
FIN
RST
PSH
URG
ACK
27
Điều khiển truyền thông theo giao thức TCP
LISTEN S Máy chủ chờ yêu cầu kết nối từ phía các máy trạm.
SYN-SENT C Một yêu cầu kết nối được gửi đi; chờ báo nhận.
ESTABLISHED Kết nối đã được thiết lập, tiến hành quá trình truyền thông.
FIN-WAIT-1 C Lớp úng dụng được yêu cầu đóng kết nối.
TIME-WAIT C Trạng thái chờ và truyền lại các bản tin để đóng kết nối hoàn toàn.
CLOSE-WAIT S Máy chủ chờ thông báo từ lớp ứng dụng để đóng kết nối.
LAST-ACK S Máy chủ đạng chờ bản tin báo nhận ACK cuối cùng để đóng kết nối.
29
Điều khiển truyền thông theo giao thức TCP
(2) Ở trạng thái này, máy trạm TCP có thể nhận một yêu cầu
mở “cổng truyền thông” từ các chương trình lớp trên để
thu nhận dữ liệu.
Ngay sau đó, bản tin (segment) SYN được
gửi tới máy chủ TCP và chuyển vào trạng
thái SYN-SENT.
(7)Khi ở trạn thái TIME-WAIT, Máy trạm TCP định thời đợi một khoảng thời gian.
Khoảng thời gian đợi “TIME-WAIT” được thiết lập gấp đôi so với thời gian sống dài nhất
của một gói tin trong mạng (maximum segment lifetime) (2MSL). Máy trạm vẫn ở trạng
thái này trước khi đóng hẳn kết nối để chắc chắn rằng bản tin ACK được gửi tới máy chủ.
nếu do một nguyên nhân nào bản tin FIN gửi từ phía máy chủ không được nhận ở máy trạm
thì các bản tin ACK sẽ được gửi lại, và việc thiết lập định thời sẽ thực hiện lại để đảm bảo
đảm bảo rằng tất cả các bản tin được trao đổi trước đó được xóa bởi mạng 31
Chuỗi xử lý của máy chủ TCP
Thông thường, máy chủ TCP có thể ở bất cứ trạng thái nào
Trong 11 trạng thái chỉ định. Tuy nhiên thông thường máy
chủ có thể ở tại một trạng thái trong chuỗi xử lý sau:
34
Truyền thông dữ liệu theo giao thức TCP
Chuỗi xử lý
truyền thông
theo giao thức
TCP
receiving buffer
deallocated
sending buffer
deallocated
receiving buffer
deallocated
sending buffer
deallocated
36
37
TCP “Stream of Bytes” Service
Byte 80
Byte 3
Byte 2
Byte 1
Byte 0
Byte 80
Byte 3
Byte 2
Byte 1
Byte 0
Host A
Host B
38
…Emulated Using TCP
“Segments”
Host A Byte 0
Byte 1
Byte 2
Byte 3
Byte 80
TCP Data
Host B
Byte 0
Byte 1
Byte 2
Byte 3
Byte 80
39
TCP Segment
IP Data
TCP Data (segment) TCP Hdr IP Hdr
• IP packet
– No bigger than Maximum Transmission Unit (MTU)
– E.g., up to 1500 bytes on an Ethernet
• TCP packet
– IP packet with a TCP header and data inside
– TCP header is typically 20 bytes long
• TCP segment
– No more than Maximum Segment Size (MSS) bytes
40
– E.g., up to 1460 consecutive bytes from the stream
Sequence Number
Host A
ISN (initial sequence number)
Byte 81
Sequence
TCP Data
number = 1st
byte
TCP Data
Host B
41
Initial Sequence Number (ISN)
• Sequence number for the very first byte
– E.g., Why not a de facto ISN of 0?
• Practical issue
– IP addresses and port #s uniquely identify a connection
– Eventually, though, these port #s do get used again
– … and there is a chance an old packet is still in flight
– … and might be associated with the new connection
• So, TCP requires changing the ISN over time
– Set from a 32-bit clock that ticks every 4 microseconds
– … which only wraps around once every 4.55 hours!
• But, this means the hosts need to exchange ISNs
42
Figure 23.22 Sliding window
What is the value of the receiver window (rwnd) for host A if the receiver, host B,
has a buffer size of 5000 bytes and 1000 bytes of received and unprocessed data?
Solution
The value of rwnd = 5000 − 1000 = 4000. Host B can receive only 4000 bytes of
data before overflowing its buffer. Host B advertises this value in its next
segment to A.
What is the size of the window for host A if the value of rwnd is 3000 bytes and
the value of cwnd is 3500 bytes?
Solution
The size of the window is the smaller of rwnd and cwnd, which is 3000 bytes.
23.44
Example 23.6
Figure 23.23 shows an unrealistic example of a sliding window. The sender has sent bytes
up to 202. We assume that cwnd is 20 (in reality this value is thousands of bytes). The
receiver has sent an acknowledgment number of 200 with an rwnd of 9 bytes (in reality
this value is thousands of bytes). The size of the sender window is the minimum of rwnd
and cwnd, or 9 bytes. Bytes 200 to 202 are sent, but not acknowledged. Bytes 203 to 208
can be sent without worrying about acknowledgment. Bytes 209 and above cannot be sent.
Note
23.47
Figure 23.25 Lost segment
23.48
Figure 23.26 Fast retransmission
23.49
23-4 SCTP
23.56
Data chunks are identified by three items: TSN, SI, and SSN.
TSN is a cumulative number identifying the association; SI defines the
stream; SSN defines the chunk in a stream.
23.60
Figure 23.35 Association termination
23.63
Figure 23.39 Error control, receiver site
K. Salah
Corrupted Segment
K. Salah
Lost Acknowledgement
K. Salah
•
Congestion Control
Remember flow control is between Sender and Receiver, and Congestion Control takes care of
congestion in the intermediate nodes (routers).
• To avoid congestion collapse (I.e., network throughput to be zero), receiver controls the window size.
• Allowed_Window =Min(receiver_advertisement, congestion_window)
– Host can inject into the network as many segments as the receiver_advertisement (I.e. window
size of the receiver) allows.
– Congestion_window is for controlling congestion at the intermediate router
– Initially congestion_window = receiver MSS
• Congestion Avoidance is a combination of:
– Slow-Start and Additive Increase:
• Whenever starting traffic on a new connection or increasing traffic after a period of
congestion, start the congestion window at the size of a single segment and
increase the congestion window by one segment each time an acknowledgement
arrives.
• In order to avoid increasing the window size too quickly (I.e. exponential increase)
and causing more congestion, apply additive increase, meaning only increase
window size by 1 after the size reaches the threshold. Initially threshold = ½
receiver_advertisement.
– Multiplicative Decrease
• Upon loss of a segment, reduce the congestion window down to one segment,
and threshold = ½ last allowed window size.
K. Salah
QoS Metrics
K. Salah
6
TCP Flow Control
Network Flow Control – regulates the amount of data a source can send
before receiving an acknowledgment from the
destination
• extreme case 1: send byte by byte ⇒ to slow
• extreme case 2: send all data ⇒ overwhelm
receiver
• solution: speed matching service – rate at which
sender application is sending is matched against
rate at which receiving application is receiving
7
TCP Flow Control (cont.)
TCP Flow Control – controls amount of buffer data that sender can send to
receiver at any particular time, using ‘sliding window’
principle
• SLIDING WINDOW – spans a portion of sending buffer
containing bytes that host can safely send to other side
without worrying that it might overwhelm receiver
• window’s left pointer moves as host sends more bytes
• window’s right pointer moves as host receives new
acknowledgment
sender buffer
8
TCP Flow Control (cont.)
Receive Window – variable used to give sender an idea of how much free
buffer space is available at the receiver
• during connection establishment receiver allocates a
receive buffer – buffer size = RcvBuffer (such allocation,
in fact, happens both on client and server side)
• as receiver receives bytes that are correct and in sequence,
it places them in receive buffer ⇒ spare room in buffer =
RcvWindow = RcvBuffer – [Last Byte Received – Last Byte
Read]
• receiver advertises available space in receive buffer by
placing RcvWindow in ‘window size’ field of TCP headers
• RcvWindow value can be changed at any point during
communication - ‘window size’ field is adjusted accordingly
receiver buffer
9
TCP Flow Control (cont.)
Sender Window – sliding window over sender buffer – must be of receive
window (RcvWindow) size!
• by keeping amount of unacknowledged data ≤ RcvWindow
sender is assured that it is not overflowing the receiver
sender buffer
sender buffer
10
TCP Flow Control (cont.)
sender buffer
Solution:
window size = 12
12
TCP Flow Control (cont.)
source: http://www.tcpipguide.com/free/t_TCPSillyWindowSyndromeandChangesTotheSlidingWindow.htm
14
TCP Flow Control (cont.)
SWS by Sender – occurs if sending application creates data slowly (e.g.
1 byte at a time), and TCP immediately sends data ⇒
considerable network overhead! (20 byte IP + 20 byte TCP)
TCP
TCPError
ErrorControl
Controlprovides
providesservice
servicefor
fordetecting
detectingcorrupted
corruptedsegments,
segments,lost
lost
segments, duplicated and out-of-order segments.
segments, duplicated and out-of-order segments.
Special Tools for (a) sequence numbers – enable detection of lost, out-of
TCP Error Control -order or duplicate segments on receiver side
(b) checksum – enables detection of corrupted segments
on receiver’s side
sender
receiver
19
TCP Error Control (cont.)
Detection of Lost, 1) receiver detects
(a) lost and out-of-order segments by receiving seg.
Out-Of-Order and with higher sequence numbers than expected
Corrupted Segments • action: discard out-of-order segments?
Rule 3
Rule 4
20
TCP Error Control (cont.)
Receiver Action on simply discard segments – ineffective
Detecting Lost and keep segments but do not send any ACK – ineffective
(must wait entire Time-out to receive missing segment)
Out-of-Order Segments: keep segment and reacknowledge last in-order byte
Fast Retransmit received ⇒ enables fast retransmit
Why should we wait for (atleast) 3 duplicate ACK before initiating‘fact recovery’?!
21
TCP Error Control (cont.)
Detection of Lost 1) receiver detects lost acknowledgments by receiving
Acknowledgments duplicate segments
• action: resend acknowledgement, discard duplicate
=100
ACK
time
time Cumulative ACK
lost ACK scenario scenario
Sender notices lost acknowledgments if its packets are sent
timeout (or more) time units apart.
23
24
TCP Error Control (cont.)
TCP Timers
estimated observed
K1 easier to calculate –
1) Simple Average 1 not necessary to
ARTT(K 1) ∑RTT(i)
K 1 i1
calculate entire
summation
K 1
ARTT(K 1) ARTT(K) RTT(K 1)
K 1 K 1
2. Suppose Host A sends two TCP segments back to back to Host B over a TCP
connection. The first segment has a sequence number 90, the second segment
has sequence number 110.
(a) How much data is in the first segment?
(b) Suppose that the first segment is lost but the second segment arrives at
B. In the ACK that Host B sends to Host A, what will be the ACK number?
1
How can you explain the exponential increase in delay as load approaches capacity
and the exponential decrease in throughput as load exceeds capacity?
Network load has a “positive feedback” effect on network delay increase and
network throughput decrease.
1) When a packet is delayed, the source, not receiving the acknowledgment, retransmits
the packet, which makes the queues longer and delays (i.e. congestion) worse!
2) When the load exceeds the capacity, the queues become full and the routers have to
discard some packets. More discarded packets ⇒ more retransmitted packets ⇒
less room for regular (non-retransmitted) packets in queues ⇒ lower throughput
4
Congestion Control (cont.)
Approaches Towards 1) network assisted congestion control – also known
Congestion Control as explicit congestion control
• network-layer components (e.g. routers) provide
explicit feedback to end systems about congestion
state in the network – feedback could be sent in
either direction:
(a) from a network router directly back to the sender
(b) a network router marks a field in a packet flowing
from the sender to the receiver; upon receipt of
the marked field the receiver notifies the sender …
• example: ATM rate-based congestion control
5
Congestion Control (cont.)
Approaches Towards 2) end-to-end congestion control – also known as
implicit congestion control
Congestion Control
(cont.) • network-layer provides NO explicit support for
congestion-control purposes
• end system infers congestion based on observed
network behavior (e.g. packet loss, delay, etc.)
• example: TCP window-based congestion control
(e.g. TCP packet loss is taken as an indication of
network congestion and TCP decreases its sending
window size accordingly)
TCP must use end-to-end congestion control, since the IP layer provides no explicit
feedback to the end systems regarding network congestion.
6
TCP Congestion Control
Causes of 1) receiver is overwhelmed with data and drops packets, or
receiver sends new RcvWindow – flow control problem
Packet Loss in
• solution: sender should decrease sending rate
TCP/IP Networks
2) a router on the path between sender and receiver is
congested and drops packets – congestion control problem
• solution: sender should decrease sending rate
flow and error control together determine senders behavior!!!
In TCP, the sender’s window size should be controlled not only by the receive
window size (RcvWindow) but also by congestion in the network.
This was ignored in our earlier discussion on TCP Flow Control.
CongWin
RcvWindow
Sending buffer
TCP Congestion – detailed algorithm that TCP sender uses to regulate its
sending rate – has 3 major components:
Control Algorithm
1) slow start
2) additive increase
congestion avoidance
3) multiplicative decrease
9
TCP Congestion Control (cont.)
Slowstart algorithm
initialize: Congwin = 1 [MSS]
until (loss event OR CongWin > threshold) {
for each segment ACKed Congwin++ }
Congestion Avoidance
/* slowstart is over */
/* CongWin > threshold */
until (loss event) { 1
for every CongWin segments ACKed CongWin++ }
threshold = Congwin/2
Congwin = 1 [MSS]
perform Slowstart
timeout
12
TCP Congestion Control (cont.)
Early-version TCP (Tahoe) • early TCP unconditionally cuts CongWin
vs. New-version TCP (Reno) to 1 MSS
• newer TCP cancels slow-start phase after
a 3-duplicate ACK – instead, does fast
retransmit, and fast recovery: set threshold
= CongWin/2, CongWin = threshold, and
continue with Additive Increase
(3-duplicate ACKs indicate that network is
Loss event: capable of delivering at least some packets)
3 dup ACKs
Timeout
14
12 Reno TCP
10 if (loss event = timeout) {
8 CongWin = 1 [MSS]
6
1
perform Slowstart }
(segments) if (loss event = 3-duplicate ACK) {
4 threshold CongWin = threshold
2 window size
congestion perform linear increase }
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Transmission round
13
TCP Congestion Control (cont.)
TCP connection 1
TCP bottleneck
router
connection 2
capacity R
D
B
CongWin 1
R
Connection 1 throughput
A: initially 2 connections consume throughput less than R ⇒ no packet loss; both connections
increase their CongWin by 1 [MSS] every RTT as a result of congestion avoidance
(note: joint throughput proceeds along a 45-degree line indicating equal increase for both conn.)
C: joint bandwidth use is again less than R ⇒ two connections increase their throughputs
along a 45-degree line
The two connections will converge to ‘equal bandwidth share line’
regardless of the initial position of point A.
16
TCP Congestion Control (cont.)
TCP Fairness – TCP connections with smaller RTT are able to grab available
and RTT bandwidth more quickly as it becomes free and thus enjoy
larger throughputs than connections with larger RTTs
TCP Fairness – nothing prevents TCP applications from opening parallel TCP
and Parallel connections between 2 hosts and thereby obtaining a larger
fraction of bandwidth in congested link
Connections
Retransmissions Not performed. Application must detect lost Delivery of all data is managed, and lost
data and retransmit if needed. data is retransmitted automatically.
Features Provided Flow control using sliding windows;
to Manage Flow of None window size adjustment heuristics;
Data congestion avoidance algorithms.
Overhead Very low Low, but higher than UDP
Transmission
Speed Very high High, but not as high as UDP
Data Quantity Small to moderate amounts of data (up to a Small to very large amounts of data (up
Suitability few hundred bytes) to gigabytes)
Types of Applications where data delivery speed Most protocols and applications
Applications That matters more than completeness, where sending data that must be received
Use The Protocol small amounts of data are sent; or where reliably, including most file and
multicast/broadcast are used. message transfer protocols.
Well-Known
FTP, Telnet, SMTP, DNS, HTTP, POP,
Applications and Multimedia applications, DNS, BOOTP, DHCP, NNTP, IMAP, BGP, IRC, NFS (later
Protocols TFTP, SNMP, RIP, NFS (early versions)
versions)
source: http://www.tcpipguide.com/free/t_SummaryComparisonofTCPIPTransportLayerProtocolsUDP.htm
Example [ TCP congestion control - Final Exam, Fall 2004] 18
Consider a TCP flow that sends 7 packets . Assume the TCP source experiences exactly one
packet loss before finishing the transmission. Let:
• Threshold = 10;
• d denote the one-way propagation delay between the source and the receiver;
• RTO denote the TCP retransmission timeout;
• T denote the total time it takes the source to transmit all packets.
Determine which packet has to be dropped to result in maximum T. Compute T in both cases
as a function of d and RTO.
Note: Assume the TCP connection has been fully established prior to sending the 7 packets
in question. Also, the TCP implements both fast recovery and fast retransmission.
cwnd = 1 1 cwnd = 1 1
Ack=2 1 1
Ack=2
cwnd = 2 2,3 cwnd = 2 2,3
1_3 123
RTO Ack=2
Ack=3,4
cwnd = 4
4,5,6,7
cwnd = 1 123_567
2 Ack=4,4,4
123 cwnd = 2
Ack=4 4
cwnd = 2 1234567
4,5 Ack=8
12345
cwnd = 4 Ack=5,6
6,7
1234567
Ack=7,8
T = 4*(2d) = 8d
23.113
TCP Connection-Oriented Demux
• TCP socket identified by 4-tuple:
– source IP address
– source port number
– dest IP address
– dest port number
IP IP IP
P1 P4 P5 P6 P2 P1P3
SP: x
DP: 25
S-IP: B
D-IP: S
SP: x SP: y
client DP: 25 DP: 25 Client
server
IP: A S-IP: A
IP: S S-IP: B IP:B
D-IP: S D-IP: S
116
Flow Control
• Buffer limitations & speed mismatch can
result in loss of data that arrives at
destination
• Receiver controls rate at which sender
transmits to prevent buffer overflow
Application
buffer
advertised buffer available = B
window size < B
Congestion Control
• Available bandwidth to destination varies with
activity of other users
• Transmitter dynamically adjusts transmission rate
according to network congestion as indicated by
RTT (round trip time) & ACKs
• Elastic utilization of network bandwidth
Application
Transport segments
Denying a connection ]
Aborting a connection ]
How Long Should Sender Wait?
• Sender sets a timeout to wait for an ACK
– Too short: wasted retransmissions
– Too long: excessive delays when packet lost
• TCP sets timeout as a function of the RTT
– Expect ACK to arrive after an “round-trip time”
– … plus a fudge factor to account for queuing
• But, how does the sender know the RTT?
– Can estimate the RTT by watching the ACKs
– Smooth estimate: keep a running average of the RTT
• EstimatedRTT = a * EstimatedRTT + (1 –a ) * SampleRTT
– Compute timeout: TimeOut = 2 * EstimatedRTT
121
A Flaw in This Approach
• An ACK doesn’t really acknowledge a transmission
– Rather, it acknowledges receipt of the data
• Consider a retransmission of a lost packet
– If you assume the ACK goes with the 1st transmission
– … the SampleRTT comes out way too large
• Consider a duplicate packet
– If you assume the ACK goes with the 2nd transmission
– … the Sample RTT comes out way too small
• Simple solution in the Karn/Partridge algorithm
– Only collect samples for segments sent one single time
122
Fast Retransmission
• Better solution possible under sliding window
– Although packet n might have been lost
– … packets n+1, n+2, and so on might get through
• Idea: have the receiver send ACK packets
– ACK says that receiver is still awaiting nth packet
• And repeated ACKs suggest later packets have arrived
– Sender can view the “duplicate ACKs” as an early hint
• … that the nth packet must have been lost
• … and perform the retransmission early
• Fast retransmission
– Sender retransmits data after the triple duplicate ACK
123
Effectiveness of Fast Retransmit
• When does Fast Retransmit work best?
– Long data transfers
• High likelihood of many packets in flight
– High window size
• High likelihood of many packets in flight
– Low burstiness in packet losses
• Higher likelihood that later packets arrive successfully
• Implications for Web traffic
– Most Web transfers are short (e.g., 10 packets)
• Short HTML files or small images
– So, often there aren’t many packets in flight
– … making fast retransmit less likely to “kick in”
– Forcing users to like “reload” more often…
124