Bài giảng Mạng máy tính - Chương 3: Tầng giao vận (Transport layer) - Trần Quang Diệu
Cung cấp phương tiện truyền thông logic (logical communication) giữa các applications.
PDUs
application: messages.
transport: segments (đoạn).
Các msg từ tầng application gửi xuống được chia nhỏ thành các đoạn (segments).
Transport protocol được thực thi tại các trạm cuối (end system).

Trang 1

Trang 2

Trang 3

Trang 4

Trang 5

Trang 6

Trang 7

Trang 8

Trang 9

Trang 10
Tải về để xem bản đầy đủ
Bạn đang xem 10 trang mẫu của tài liệu "Bài giảng Mạng máy tính - Chương 3: Tầng giao vận (Transport layer) - Trần Quang Diệu", để tải tài liệu gốc về máy hãy click vào nút Download ở trên
Tóm tắt nội dung tài liệu: Bài giảng Mạng máy tính - Chương 3: Tầng giao vận (Transport layer) - Trần Quang Diệu
Chương 3.Tầng giao vận (transport layer)
Quang Dieu Tran, PhD
Faculty of Information Technology
University of Communication and Transport ( Branch in Ho Chi Minh City)
Email : dieutq@gmail.com
Website: sites.google.com/sites/tranlectures
Chương 3. Giao thức tầng giao vận (transport layer)
2
Chương 3. Giao thức tầng giao vận (transport layer)
3
Ch3. The Transport Layer
Transport Layer Services & Principles.
Multiplexing/Demultiplexing.
Connectionless Transport (UDP).
Principles of Reliable Data Transfer (RDT).
Connection-oriented Transport (TCP).
Congestion Control.
Sử dụng TCP hay UDP
Chương 3. Giao thức tầng giao vận (transport layer)
4
Transport Layer Services & Principles
Cung cấp phương tiện truyền thông logic (logical communication) giữa các applications.
PDUs
application: messages.
transport: segments (đoạn).
Các msg từ tầng application gửi xuống được chia nhỏ thành các đoạn (segments).
Transport protocol được thực thi tại các trạm cuối (end system).
application
transport
network
data link
physical
application
transport
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
logical end-end transport
Chương 3. Giao thức tầng giao vận (transport layer)
5
Transport & Network layers
Network layer:
Truyền thông logic giữa các trạm làm việc (host).
PDUs = packets (gói).
IP (Internet Protocol) là giao thức truyền không tin cậy.
Transport layer:
Tạo phương thức truyền thông logic giữa các ứng dụng (application/process).
Nhận các gói tin từ tầng Network gửi lên.
Household analogy:
12 kids sending letters to 12 kids
processes = kids
app messages = letters in envelopes
hosts = houses
transport protocol = Ann and Bill
network-layer protocol = postal service
Chương 3. Giao thức tầng giao vận (transport layer)
6
Transport Protocols
TCP (Transmission Control Protocol)
Connection-oriented (có liên kết).
Flow control (điều khiển luồng).
Congestion control (điều khiển chống nghẽn mạng).
reliable transport protocol (tin cậy)
UDP (User Datagram Protocol)
Connectionless.
Không có kiểm soát luồng và kiểm soát nghẽn mạng.
unreliable transport protocol.
Chương 3. Giao thức tầng giao vận (transport layer)
7
Ch3. The Transport Layer
Transport Layer Services & Principles.
Multiplexing/Demultiplexing.
Connectionless Transport (UDP).
Principles of Reliable Data Transfer (RDT).
Connection-oriented Transport (TCP).
Congestion Control.
Sử dụng TCP hay UDP
Chương 3. Giao thức tầng giao vận (transport layer)
8
Multiplexing/demultiplexing (mux/demux)
Multiplexing (dồn kênh): Các msgs từ các apps (P1, P2) được chia nhỏ và đóng gói thành các segments (thêm header) dồn kênh diễn ra ở sending hosts
Demultiplexing (phân kênh): Các segments nhận được được gửi tới apps tương ứng (P3, P4) phân kênh diễn ra ở receiving hosts
application
transport
network
M
P2
application
transport
network
receiver
H
t
H
n
segment
segment
M
application
transport
network
P1
M
M
M
P3
P4
segment
header
application-layer
data
sender
sender
Chương 3. Giao thức tầng giao vận (transport layer)
9
Dồn và chia kênh thế nào?
source port number: ứng dụng gửi dữ liệu.
destination port number: ứng dụng nhận dữ liệu.
Port number:
0-1023: well-known port number (đã được giữ cho các apps phổ biến).
1024 – 65535.
source port #
dest port #
32 bits
application
data
(message)
other header fields
TCP/UDP segment format
Chương 3. Giao thức tầng giao vận (transport layer)
10
Mux/demux: Ví dụ
host A
server B
source port: x
dest. port: 23
source port:23
dest. port: x
port use: simple telnet app
Web client
host A
Web
server B
Web client
host C
Source IP: C
Dest IP: B
source port: x
dest. port: 80
Source IP: C
Dest IP: B
source port: y
dest. port: 80
port use: Web server
Source IP: A
Dest IP: B
source port: x
dest. port: 80
Chương 3. Giao thức tầng giao vận (transport layer)
11
Ch3. The Transport Layer
Transport Layer Services & Principles.
Multiplexing/Demultiplexing.
Connectionless Transport (UDP).
Principles of Reliable Data Transfer (RDT).
Connection-oriented Transport (TCP).
Congestion Control.
Sử dụng TCP hay UDP
Chương 3. Giao thức tầng giao vận (transport layer)
12
Connectionless Transport (UDP).
User Datagram Protocol [RFC 768]
“no frill”, “bare bones” Internet transport protocol.
chỉ cần những thủ tục cơ bản nhất.
thông tin điều khiển cũng chỉ cần cơ bản nhất.
“best effort” service: dữ liệu có thể mất mát, sai sót nhưng luôn “cố gắng hết sức” để giảm thiểu.
Connectionless:
Không có cơ chế bắt tay (handshaking): thiết lập truyền dữ liệu kết thúc .
Không nắm giữ trạng thái.
Các segments được xử lý độc lập với nhau.
Chương 3. Giao thức tầng giao vận (transport layer)
13
UDP: Segment structure
source port.
dest port.
length.
application data.
checksum: mã kiểm tra lỗi (phục vụ cho cơ chế nhận biết lỗi – error detection)
source port #
dest port #
32 bits
Application
data
(message)
UDP segment format
length
checksum
Length, in
bytes of UDP
segment,
including
header
Chương 3. Giao thức tầng giao vận (transport layer)
14
UDP segment - example
Receiver’s MAC address
Sender’s MAC address
Type of upper layer’s protocol
( 0x0800 = IP )
Chương 3. Giao thức tầng giao vận (transport layer)
15
UDP segment – example (cnt.)
IP’s Header
Chương 3. Giao thức tầng giao vận (transport layer)
16
UDP segment – example (cnt.)
UDP’s header
Chương 3. Giao thức tầng giao vận (transport layer)
17
UDP segment – example (cnt.)
Data of applicaton layer
Chương 3. Giao thức tầng giao vận (transport layer)
18
UDP checksu ... ng-byte của byte dữ liệu đầu tiên trong segment
khởi động bộ đếm t/g nếu nó chưa chạy (bộ đếm t/g cho segment chưa nhận ACK lâu nhất)
khoảng t/g hết hạn: TimeOutInterval
timeout:
gửi lại segment gây nên timeout
đặt lại timer
Ack rcvd:
Nếu đó là ACK cho các khúc trước đó chưa được ACK
Cập nhật danh sách các gói đã được ACK
chạy lại timer nếu như còn có các segment chưa ACK
Transport Layer
3- 64
Transport Layer
3- 65
TCP sender (Đơn giản hóa)
NextSeqNum = InitialSeqNum
SendBase = InitialSeqNum
loop (forever) {
switch (event)
event: Nhận được dữ liệu từ application tầng trên
tạo TCP segment có số thứ tự là NextSeqNum
if (timer không chạy)
khởi chạy timer
đẩy segment xuống cho tầng IP
NextSeqNum = NextSeqNum + length(data)
event: timer timeout
Gửi lại segment có stt nhỏ nhất mà chưa được ACK
khởi chạy timer
event: Nhận ACK, với giá trị trường ACK là y
if ( y > SendBase) {
SendBase = y
if (Còn sement chưa ACK)
khởi chạy timer
}
} /* end of loop forever */
Ghi chú:
SendBase-1: byte ACK được cộng dồn cuối cùng
Ví dụ:
SendBase-1 = 71;y=73, vậy bên nhận cần 73+ ;
y > SendBase, vì vậy có thêm dữ liệu được ACK
TCP: retransmission scenarios
Transport Layer
3- 66
Host A
Seq=100, 20 bytes data
ACK=100
time
premature timeout
Host B
Seq=92, 8 bytes data
ACK=120
Seq=92, 8 bytes data
Seq=92 timeout
ACK=120
Host A
Seq=92, 8 bytes data
ACK=100
loss
timeout
lost ACK scenario
Host B
X
Seq=92, 8 bytes data
ACK=100
time
Seq=92 timeout
SendBase= 100
SendBase= 120
SendBase= 120
Sendbase= 100
TCP retransmission scenarios (more)
Transport Layer
3- 67
Host A
Seq=92, 8 bytes data
ACK=100
loss
timeout
Cumulative ACK scenario
Host B
X
Seq=100, 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer
3- 68
Tạo ACK trong TCP [RFC 1122, RFC 2581]
Sự kiện tại Receiver
Nhận được segment đúng thứ tự
với STT hợp lí. Tất cả dữ liệu từ
STT về trước đã được ACK
Nhận được segment đúng thứ tựvới số STT hợp lý. Một segment
khác đang chờ ACK
Nhân được segment không đúngthứ tự (STT cao hơn STT mongđợi). Phát hiện thiếu hụt
Segment nhận được khỏa lấp 1
phân hoặc toàn bộ phần thiếu
hụt
Hành vi TCP tại Receiver
Trì hoãn chưa ACK vội. chờ segmentkế tiếp trong 500ms. nếu không có segment nào được gửi đến, gửi ACK
Ngay lập tức gửi 1 segment với ACK
cộng dồn xác nhận cả 2 segment đã đượcnhận thành công
Ngay lập tức gửi 1 ACK lặp , chỉ rõ bytemong đợi tiếp theo
Ngay lập tức gửi ACK
Transport Layer
3- 69
Fast Retransmit
Time-out thường tương đối dài:
trì hoãn lâu trước khi gửi lại gói bị mất
phát hiện mất segments thông qua ACK lặp.
Sender thường gửi nhiều segment liên tục
nếu có 1 segment bị mất thì sẽ có nhiều ACK lặp
Nếu sender nhận được 3 ACK yêu cầu cho cùng 1 segment → nó xác định segment đó đã bị mất:
fast retransmit: gửi lại segment bị mất ngay cả khi chưa tới thời điểm time-out
Fast Retransmit (cont.)
Chương 3. Giao thức tầng giao vận (transport layer)
70
Host A
ACK=2
Host B
X
Seq=1
time
Gửi liền 2 ACK
yêu cầu segment có seq# 2
ACK=2
ACK=2
Seq=2
Seq=3
Seq=2
Seq=2 timeout
Transport Layer
3- 71
event: Nhận ACK, với ACK# là y
if (y > SendBase) {
SendBase = y
if (Nếu còn segment đang đợi ACK)
start timer
}
else {
tăng bộ đếm duplicate ACKs nhận được cho y
if (nếu bộ đếm lặp của y = 3) {
gửi lại segment với sequence # = y
}
Fast retransmit algorithm:
a duplicate ACK for
already ACKed segment
Truyền lại nhanh
Chương 3. Giao thức tầng giao vận (transport layer)
72
TCP flow control
Các apps có thể xử lý dữ liệu chậm, các gói tin nhận về được đưa vào bộ đệm (receiver buffer).
Flow control: kiểm soát không để cho receiver buffer bị tràn vì sender gửi nhiều gói tin quá.
Receiver: Thông báo cho sender biết kích thước của RcvWidow (free buffer): trường rcv window size trong TCP segment headers.
Sender: Luôn nắm được kích thước tối đa của gói tin có thể truyền tiếp.
Chương 3. Giao thức tầng giao vận (transport layer)
73
TCP Connection management
TCP: Connection-oriented.
Khởi tạo các giá trị:
sequence number.
buffers, flow control information.
Client:Connection initiator (khởi tạo liên kết: socket).
Server: Chấp nhận kết nối.
Three way handshaking:
Bước 1: client gửi TCP SYN control segment tới server.
Bước 2: server nhận SYN segment rồi trả lời bằng SYNACK segment .
Bước 3: client nhận SYNACK segment và trả lời bằng ACK segment (có thể có dữ liệu đi kèm).
Chương 3. Giao thức tầng giao vận (transport layer)
74
Chương 3. Giao thức tầng giao vận (transport layer)
75
TCP Connection management: ngắt liên kết
Bước 1: client (phía muốn ngắt liên kết) gửi TCP FIN segment.
Bước 2: server (phía còn lại) nhận được FIN, gửi ACK, ngắt liên kết, gửi tiếp FIN segment.
Bước 3: client nhận FIN, trả lời bằng ACK. timed wait (chờ một lúc nữa cho tới khi liên kết đóng hẳn).
Bước 4: server nhận ACK, đóng liên kết.
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
timed wait
closed
Chương 3. Giao thức tầng giao vận (transport layer)
76
TCP client lifecycle
TCP server lifecycle
TCP Connection management (cont.)
Chương 3. Giao thức tầng giao vận (transport layer)
77
bangtqh@utc2.edu.vn
Ch3. The Transport Layer
Transport Layer Services & Principles.
Multiplexing/Demultiplexing.
Connectionless Transport (UDP).
Principles of Reliable Data Transfer (RDT).
Connection-oriented Transport (TCP).
Congestion Control.
Sử dụng TCP hay UDP
Chương 3. Giao thức tầng giao vận (transport layer)
78
Congestion control
Nghẽn mạng là điều khó tránh khỏi!!!
Khi mạng bị nghẽn, các gói tin có thể bị trễ hay bị mất.
Hai hướng tiếp cận:
End-end congestion control: Thông tin về mức độ nghẽn mạng được suy ra từ lượng tin bị mất mát trong quá trình truyền.
Network-assited congestion control: Routers cung cấp các thông tin phản hồi về tình trạng nghẽn mạng tới end systems.
Bit thông báo nghẽn mạng đừng gửi nữa hoăc xin chờ một lát.
Tốc độ tối đa cho phép gửi (maximum rate allowed).
TCP sử dụng phương pháp end-end congestion control.
Chương 3. Giao thức tầng giao vận (transport layer)
79
Causes/costs of congestion: scenario 1
2 senders, 2 receivers
01 router, buffers vô hạn
no retransmission
large delays when congested
maximum achievable throughput
unlimited shared output link buffers
Host A
l in : original data
Host B
l out
Chương 3. Giao thức tầng giao vận (transport layer)
80
Causes/costs of congestion: scenario 2
one router, buffers có hạn
sender gửi lại các packet bị mất
finite shared output link buffers
Host A
l in : original data
Host B
l out
l ' in : original data, plus retransmitted data
Chương 3. Giao thức tầng giao vận (transport layer)
81
always: (goodput)
“perfect” retransmission only when loss:
retransmission of delayed (not lost) packet makes larger (than perfect case) for same
l
in
l
out
=
l
in
l
out
>
l
in
l
out
“costs” of congestion:
more work (retrans) for given “goodput”
unneeded retransmissions: link carries multiple copies of pkt
Causes/costs of congestion: scenario 2
Chương 3. Giao thức tầng giao vận (transport layer)
82
Causes/costs of congestion: scenario 3
4 senders
multihop paths
timeout/retransmit
l
in
Q: what happens as and increase ?
l
in
finite shared output link buffers
Host A
l in : original data
Host B
l out
l ' in : original data, plus retransmitted data
Chương 3. Giao thức tầng giao vận (transport layer)
83
Causes/costs of congestion: scenario 3
Another “cost” of congestion:
Khi thực hiện drop các packet trên đường truyền dung lượng đường truyền đã sử dụng để gửi tin tới điểm bị drop là vô ích.
Host A
Host B
l out
Chương 3. Giao thức tầng giao vận (transport layer)
84
TCP Congestion Control
end-end control (no network assistance)
Sender điều khiển lượng dữ liệu gửi đi theo quy tắc:
LastByteSent-LastByteAcked
min {CongWin, ReceiverWnd}
Công thức xấp xỉ:
Giá trị CongWin luôn biến đổi và được tính toán theo khả năng truyền tải của mạng.
Làm thế nào sender đánh giá được tình trạng nghẽn?
loss event = timeout or 3 duplicate ACKs
TCP sender reduces rate ( CongWin ) after loss event
Cơ chế đánh giá nghẽn:
AIMD
Slow start
conservative after timeout events
rate =
CongWin
RTT
Bytes/sec
Chương 3. Giao thức tầng giao vận (transport layer)
85
multiplicative decrease: cut CongWin in half after loss event
additive increase: increase CongWin by 1 MSS every RTT in the absence of loss events: probing
Long-lived TCP connection
TCP AIMD (additive-increase, multiplicative-decrease)
Chương 3. Giao thức tầng giao vận (transport layer)
86
TCP Slow Start
When connection begins, CongWin = 1 MSS
Example: MSS = 500 bytes & RTT = 200 msec
initial rate = 20 kbps
Available bandwidth may be >> MSS/RTT
desirable to quickly ramp up to respectable rate
When connection begins, increase rate exponentially fast until first loss event
Chương 3. Giao thức tầng giao vận (transport layer)
87
TCP Slow Start (more)
When connection begins, increase rate exponentially until first loss event:
double CongWin every RTT
done by incrementing CongWin for every ACK received
Summary : initial rate is slow but ramps up exponentially fast
Host A
one segment
RTT
Host B
time
two segments
four segments
Chương 3. Giao thức tầng giao vận (transport layer)
88
Refinement
After 3 dup ACKs:
CongWin is cut in half
window then grows linearly
But after timeout event:
CongWin instead set to 1 MSS;
window then grows exponentially
to a threshold, then grows linearly
3 dup ACKs indicates network capable of delivering some segments
timeout before 3 dup ACKs is “more alarming”
Philosophy:
Chương 3. Giao thức tầng giao vận (transport layer)
89
Q: When should the exponential increase switch to linear?
A: When CongWin gets to 1/2 of its value before timeout.
Implementation:
Variable Threshold
At loss event, Threshold is set to 1/2 of CongWin just before loss event
Refinement (more)
Chương 3. Giao thức tầng giao vận (transport layer)
90
When CongWin is below Threshold , sender in slow-start phase, window grows exponentially.
When CongWin is above Threshold , sender is in congestion-avoidance phase, window grows linearly.
When a triple duplicate ACK occurs, Threshold set to CongWin/2 and CongWin set to Threshold .
When timeout occurs, Threshold set to CongWin/2 and CongWin is set to 1 MSS.
Summary: TCP Congestion Control
Chương 3. Giao thức tầng giao vận (transport layer)
91
TCP throughput (or transmission rate)
Gía trị throughout (số packet gửi đi / giây) của TCP tính theo Window size và RTT là bao nhiêu?
Không tính giai đoạn slowstart
Gọi W là giá trị window size khi xuất hiện mất gói.
Khi window size = W, throughput = W/RTT
Ngay sau khi có nghẽn (lost), window size giảm xuống = W/2 throughput = W/2RTT.
Throughout trung bình là: 0.75 W/RTT
Throughout TB = 3W/4RTT
Chương 3. Giao thức tầng giao vận (transport layer)
92
TCP Futures
Hỏi : Giả sử MSS = 1500 byte, RTT = 100 µ s , Cần gửi đi với tốc độ là 10 Gbps (throughput=10 9 bps). Vậy giá trị Windowsize phải là bao nhiêu ?
Trả lời : window size W = 83,333 in-flight segments
Throughput tính theo loss rate:
Trong đó L = loss rate
Chương 3. Giao thức tầng giao vận (transport layer)
93
Delay modeling
Q: How long does it take to receive an object from a Web server after sending a request?
Ignoring congestion, delay is influenced by:
TCP connection establishment
data transmission delay
slow start
Notation, assumptions:
Assume one link between client and server of rate R
S: MSS (bits)
O: object size (bits)
no retransmissions (no loss, no corruption)
Window size:
First assume: fixed congestion window, W segments
Then dynamic window, modeling slow start
Chương 3. Giao thức tầng giao vận (transport layer)
94
Fixed congestion window (1)
First case:
WS/R > RTT + S/R: ACK for first segment in window returns before window’s worth of data sent
delay = 2RTT + O/R
Chương 3. Giao thức tầng giao vận (transport layer)
95
Transport Layer
3- 95
Fixed congestion window (2)
Second case:
WS/R < RTT + S/R: wait for ACK after sending window’s worth of data sent
delay = 2RTT + O/R
+ (K-1)[S/R + RTT - WS/R]
Chương 3. Giao thức tầng giao vận (transport layer)
96
Ch3. The Transport Layer
Transport Layer Services & Principles.
Multiplexing/Demultiplexing.
Connectionless Transport (UDP).
Principles of Reliable Data Transfer (RDT).
Connection-oriented Transport (TCP).
Congestion Control.
Sử dụng TCP hay UDP
Chương 3. Giao thức tầng giao vận (transport layer)
97
Một số so sánh TCP/UDP
Có liên kết, lưu trữ trạng thái liên kết (quản lý liên kết).
Điểm-điểm
Có độ trễ (delay): thiết lập, quản lý liên kết, luồng, nghẽn
Segment header lớn (20 bytes)
Bị giới hạn tốc độ truyền (congestion control)
Không liên kết, không lưu trữ trạng thái.
Điểm-điểm, quảng bá.
Độ trễ thấp.
Segment header nhỏ (8 bytes)
Không giới hạn tốc độ truyền.
Chương 3. Giao thức tầng giao vận (transport layer)
98
Các app thực tế
Application
App protocol
Transport protocol
Electronic mail
SMTP
TCP
Remote terminal access
Telnet
TCP
Web
HTTP
TCP
File transfer
FTP
TCP
Remote file server
NFS
typically UDP
Streaming multimedia
proprietary
typically UDP
Internet telephony
proprietary
typically UDP
Network management
SNMP
typically UDP
Routing protocol
RIP
typically UDP
Name translation
DNS
typically UDP
File đính kèm:
bai_giang_mang_may_tinh_chuong_3_tang_giao_van_transport_lay.ppt

