Download Global Information Systems and Software Technology (GISST)

Document related concepts

Low-voltage differential signaling wikipedia , lookup

Asynchronous Transfer Mode wikipedia , lookup

RapidIO wikipedia , lookup

Network tap wikipedia , lookup

Airborne Networking wikipedia , lookup

Serial digital interface wikipedia , lookup

CAN bus wikipedia , lookup

Cracking of wireless networks wikipedia , lookup

Deep packet inspection wikipedia , lookup

Recursive InterNetwork Architecture (RINA) wikipedia , lookup

Internet protocol suite wikipedia , lookup

TCP congestion control wikipedia , lookup

IEEE 1355 wikipedia , lookup

UniPro protocol stack wikipedia , lookup

Transcript
University of British Columbia
CICS 515 (Part 1) Computer Networks
Lectures 3 – Transport Layer (TCP/UDP)
Principle of Reliable Data Transfer
Instructor: Dr. Son T. Vuong
Email: [email protected]
May 17 , 2012
The World Connected
Jump to first page
Lecture 3: Transport Layer
(Kurose Ch. 3)
Our goals:
understand principles behind
transport layer services:
 multiplexing/demultiplexing
 reliable data transfer
 flow control
 congestion control
CICS 515 – Summer 2012 © Dr. Son Vuong
learn about transport layer
protocols in the Internet:
 UDP: connectionless
transport
 TCP: connectionoriented transport
 TCP congestion control
2
Outline (Ch. 3)
3.1 Transport-layer services
3.2 Multiplexing and
demultiplexing
3.3 Connectionless transport:
UDP
3.4 Principles of reliable data
transfer (Sliding Window
Protocol)
CICS 515 – Summer 2012 © Dr. Son Vuong
3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
 connection management
3.6 Principles of congestion
control
3.7 TCP congestion control
3
Internet Architecture
Defined by Internet Engineering Task Force (IETF)
Hourglass Design
Application vs Application Protocol (FTP, HTTP)
FTP
HTTP
NV
TFTP
UDP
TCP
TCP
IP
NET1
NET2
Application
UDP
IP
…
CICS 515 – Summer 2012 © Dr. Son Vuong
NETn
Network
4
Network 1 (Ethernet)
Example TCP/IP internet
H7
H2
H1
R3
H8
H3
Network 4
(point-to-point)
Network 2 (Ethernet)
R1
R2
H4
Network 3 (FDDI)
H1
H8
H5
TCP
R1
R2
IP
IP
ETH
H6
ETH
IP
IP
FDDI
CICS 515 – Summer 2012 © Dr. Son Vuong
FDDI
R3
PPP
PPP
TCP
IP
ETH
ETH
5
Transport services and protocols
provide logical communication
between app processes
running on different hosts
transport protocols run in end
systems
 send side: breaks app
messages into segments,
passes to network layer
 rcv side: reassembles
segments into messages,
passes to app layer
more than one transport
protocol available to apps
 Internet: TCP and UDP
CICS 515 – Summer 2012 © Dr. Son Vuong
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
application
transport
network
data link
physical
6
Transport services and TCP Segments
TCP sends data in Segments (same concept as
Packets, just a different name).
Data is written by the application program into the
TCP buffers, and at some later time each Segment
will be transmitted.
Application process
Application process
…
…
Write
bytes
Read
bytes
TCP
TCP
Send buffer
Receive buffer
Segment
CICS 515 – Summer 2012 © Dr. Son Vuong
Segment … Segment
Transmit segments
7
Transport vs. network layer
network layer: logical
communication between
hosts
transport layer: logical
communication between
processes
 relies on, enhances,
network layer
services
CICS 515 – Summer 2012 © Dr. Son Vuong
Household analogy:
12 kids sending letters to 12 kids
processes = kids
app messages = letters in
envelopes
hosts = houses
transport protocol entities =
Ann and Bill
network-layer service = postal
service
8
Internet transport-layer protocols
reliable, in-order delivery (TCP)
application
 congestion control
transport
network
data
link
 flow control
physical
 connection setup
unreliable, unordered delivery:
UDP
 no-frills extension of “besteffort” IP
services not available:
 delay guarantees
 bandwidth guarantees
CICS 515 – Summer 2012 © Dr. Son Vuong
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
application
transport
network
data link
physical
9
Transport services and protocols
provide logical communication
between app processes
running on different hosts
transport protocols run in end
systems
 send side: breaks app
messages into segments,
passes to network layer
 rcv side: reassembles
segments into messages,
passes to app layer
more than one transport
protocol available to apps
 Internet: TCP and UDP
CICS 515 – Summer 2012 © Dr. Son Vuong
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
application
transport
network
data link
physical
10
Multiplexing and demultiplexing
Ch. 3
3.1 Transport-layer services
3.2 Multiplexing and
demultiplexing
3.3 Connectionless transport:
UDP
3.4 Principles of reliable data
transfer
CICS 515 – Summer 2012 © Dr. Son Vuong
3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
 connection management
3.6 Principles of congestion
control
3.7 TCP congestion control
11
Multiplexing/demultiplexing
Multiplexing at send host:
gathering data from multiple
sockets, enveloping data with
header (later used for
demultiplexing)
Demultiplexing at rcv host:
delivering received segments
to correct socket
= socket
application P3
= process
P1
P1 application P2
transport
network
link
transport
network
P4 application
transport
network
link
link
physical
host 1
CICS 515 – Summer 2012 © Dr. Son Vuong
physical
host 2
physical
host 3
12
Multiplexing/demultiplexing
Recall: segment - unit of
Demultiplexing: delivering
data exchanged between received segments to correct
transport layer entities
app layer processes
 aka TPDU: transport
Receiver
protocol data unit
application-layer
data
segment
header
segment
Ht M
Hn segment
P3
M
application
transport
network
CICS 515 – Summer 2012 © Dr. Son Vuong
P1
M
M
application
transport
network
P2
M
P4
application
transport
network
13
Multiplexing/demultiplexing: examples
host A
source port: x
dest. port: 23
server B
source port:23
dest. port: x
Source IP: C
Dest IP: B
source port: y
dest. port: 80
port use: simple telnet app
Web client
host A
CICS 515 – Summer 2012 © Dr. Son Vuong
Web client
host C
Source IP: A
Dest IP: B
source port: x
dest. port: 80
Source IP: C
Dest IP: B
source port: x
dest. port: 80
Web
server B
port use: Web server
14
3.1. Transport Mux Peer Instruction
Question 3.1
Through a specific port (e.g. port 80), an application process
(e.g. Web server) can communicate with multiple (the
following number of) remote (e.g. client) processes:
Answer:
(A) Exactly 1 (B) 2 (C) 3 (D) An arbitrary number
(E) None of the above
CICS 515 – Summer 2012 © Dr. Son Vuong
15
3.1b. Transport Mux Peer Instruction
Question 3.1b
Through a specific socket, an application process (e.g. Web
server process or client process) can communicate with
multiple (the following number of) remote (e.g. client or
server) processes:
Answer:
(A) Exactly 1 (B) 2 (C) 3 (D) An arbitrary number
(E) None of the above
CICS 515 – Summer 2012 © Dr. Son Vuong
16
Outline (Ch. 3)
3.1 Transport-layer services
3.2 Multiplexing and
demultiplexing
3.3 Connectionless transport:
UDP
3.4 Principles of reliable data
transfer
CICS 515 – Summer 2012 © Dr. Son Vuong
3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
 connection management
3.6 Principles of congestion
control
3.7 TCP congestion control
17
UDP: User Datagram Protocol [RFC 768]
“no frills,” “bare bones” Internet
transport protocol
Why is there a UDP?
“best effort” service, UDP
no connection
segments may be:
establishment (which can
add delay)
 lost
simple: no connection state
 delivered out of order to app
at sender, receiver
connectionless:
small segment header
 no handshaking between
no congestion control: UDP
UDP sender, receiver
can blast away as fast as
 each UDP segment handled
desired
independently of others
CICS 515 – Summer 2012 © Dr. Son Vuong
18
UDP: more
often used for streaming multimedia apps
 loss tolerant
 rate sensitive
other UDP uses
 DNS
 SNMP
reliable transfer over UDP: add reliability at
application layer
 application-specific error recovery!
CICS 515 – Summer 2012 © Dr. Son Vuong
19
UDP Header Format
0
16
31
SrcPort
DstPort
Checksum
Length
Data
Checksum computed over: Pseudoheader + UDP header + Data
Pseudoheader = src, dest IP addresses + Protocol no. (17) + UDP length
CICS 515 – Summer 2012 © Dr. Son Vuong
20
UDP Message Queue
Application
process
Application
process
Application
process
Ports
Queues
Packets
demultiplexed
UDP
CICS 515 – Summer 2012 © Dr. Son Vuong
Packets arrive
21
UDP checksum
Goal: detect “errors” (e.g., flipped bits) in transmitted segment
Sender:
treat segment contents
as sequence of 16-bit
integers
checksum: addition (1’s
complement sum) of
segment contents
sender puts checksum
value into UDP
checksum field
CICS 515 – Summer 2012 © Dr. Son Vuong
Receiver:
compute checksum of
received segment
check if computed
checksum equals checksum
field value:
 NO - error detected
 YES - no error detected.
But maybe errors
nonetheless? More later
….
22
Internet Checksum Example
Note
 When adding numbers, a carryout from the most
significant bit needs to be added to the result
Example: add two 16-bit integers
1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0
1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
wraparound 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1
sum
checksum
1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0
0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1
Checksum at Rec 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
CICS 515 – Summer 2012 © Dr. Son Vuong
23
Outline (Ch. 3)
3.1 Transport-layer services
3.2 Multiplexing and
demultiplexing
3.3 Connectionless transport:
UDP
3.4 Principles of reliable data
transfer
CICS 515 – Summer 2012 © Dr. Son Vuong
3.5 Connection-oriented
transport: TCP
 segment structure
 reliable data transfer
 flow control
 connection management
3.6 Principles of congestion
control
3.7 TCP congestion control
24
Principles of Reliable data transfer
important in app., transport, link layers
top-10 list of important networking topics!
characteristics of unreliable channel will determine
complexity of reliable data transfer protocol (rdt)
CICS 515 – Summer 2012 © Dr. Son Vuong
25
Reliable data transfer: getting started
rdt_send(): called from above,
(e.g., by app.). Passed data to
deliver to receiver upper layer
send
side
udt_send(): called by rdt,
to transfer packet over
unreliable channel to receiver
CICS 515 – Summer 2012 © Dr. Son Vuong
deliver_data(): called by
rdt to deliver data to upper
receive
side
rdt_rcv(): called when packet
arrives on rcv-side of channel
26
Reliable Data Link Protocols
Functions of data link protocols:
 Flow control
 Error control
 Sequencing
Stop-and-wait (alternating-bit) protocol
Sliding window protocol
CICS 515 – Summer 2012 © Dr. Son Vuong
27
Protocols
Used for communications between entities in a
distributed system
Must speak the same language
Key Elements:


data part (syntax): data format
control part (semantics): procedures
Formal Description Techniques (FDTs) e.g.
CFSM, Estelle, SDL, LOTOS
CICS 515 – Summer 2012 © Dr. Son Vuong
28
rdt1.0: reliable transfer over a reliable channel
underlying channel perfectly reliable
 no bit errors, no loss of packets
 no flow control
separate FSMs for sender, receiver:
 sender sends data into underlying channel
 receiver read data from underlying channel
Wait for
call from
above
rdt_send(data)
packet = make_pkt(data)
udt_send(packet)
sender
CICS 515 – Summer 2012 © Dr. Son Vuong
Wait for
call from
below
rdt_rcv(packet)
extract (packet,data)
deliver_data(data)
receiver
29
rdt2.0: Protocol for unreliable channel
Stop-And-Wait Protocol
sender
Error control
 Flow control
rdt_send(data)
sndpkt = make_pkt(data, checksum)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
isNAK(rcvpkt)
Wait for
Wait for
call from
ACK or
udt_send(sndpkt)
above
NAK
rdt_rcv(rcvpkt) && isACK(rcvpkt)
L
CICS 515 – Summer 2012 © Dr. Son Vuong
receiver
rdt_rcv(rcvpkt) &&
corrupt(rcvpkt)
udt_send(NAK)
Wait for
call from
below
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
30
rdt2.0: operation with no errors
rdt_send(data)
sndpkt = make_pkt(data, checksum)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
isNAK(rcvpkt)
Wait for
Wait for
call from
ACK or
udt_send(sndpkt)
above
NAK
rdt_rcv(rcvpkt) && isACK(rcvpkt)
L
rdt_rcv(rcvpkt) &&
corrupt(rcvpkt)
udt_send(NAK)
Wait for
call from
below
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
CICS 515 – Summer 2012 © Dr. Son Vuong
31
rdt2.0: error scenario
rdt_send(data)
snkpkt = make_pkt(data, checksum)
udt_send(sndpkt)
rdt_rcv(rcvpkt) &&
isNAK(rcvpkt)
Wait for
Wait for
call from
ACK or
udt_send(sndpkt)
above
NAK
rdt_rcv(rcvpkt) && isACK(rcvpkt)
L
rdt_rcv(rcvpkt) &&
corrupt(rcvpkt)
udt_send(NAK)
Wait for
call from
below
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
CICS 515 – Summer 2012 © Dr. Son Vuong
32
Peer Instruction 3.2 - Question
Is NAK necessary (T or F) and sufficient (T or F) ?
Answer:
(A):
(B):
(C):
(D):
(E):
F, F
F, T
T, F
T, T
B, C and D
CICS 515 – Summer 2012 © Dr. Son Vuong
33
Formal Specification of Protocols
Communicating Finite State Machines (CFSM)
SENDER
RECEIVER
+ DATA
- DATA
0
0
(a) Eutopia
+Error / -NAK
0
- DATA
0
+ ACK
+ DATA
1
[TimeOut] / - DATA
- ACK
1
+NAK / - DATA
(b) Stop-And-Wait Protocol
CICS 515 – Summer 2012 © Dr. Son Vuong
34
Alternating Bit Protocol
SENDER
+ ACK1
0
- DATA0
RECEIVER
+ DATA1
+ Error
+ ACK0
3
- ACK1
0
3
+ DATA0
[TimeOut]
- DATA1
1
2
+ DATA1
1
2
+ DATA0
+ Error
+ ACK1
+ ACK0
Init J=1
Init I=0
+ <DATA, I> [I==J]
+ Error
S0
S0
- <DATA, I>
- ACK0
(a) ABP with 4 states
[T]
S1
+ <DATA, I>
t1
+ <ACK,J>
[I!=J]
[I==J]
J=J+1
I=I+1
+ <ACK,J> [I!=J]
(b) ABP with 2 states
CICS 515 – Summer 2012 © Dr. Son Vuong
- <ACK, J>
S1
Trans
Label t1
From S0
To S1
When <DATA, I>
Provided I!= J
{ J=J+1
}
35
Alternating Bit Protocol (Correct Version?)
SENDER
RECEIVER
+ ACK1
+ ACK1
0
- DATA0
+ ACK0
- ACK1
+ Error
3
0
3
+ DATA1
+ DATA0
[TimeOut]
- DATA1
1
2
+ ACK1
1
+ ACK0
+ ACK0
+ DATA0
+ Error
(a) ABP with 4 states
+ DATA0
+ DATA1
2
+ Error
- ACK0
Init J=0
Init I=0
+ <ACK,J> [I=J]
S0
- <DATA, I>
+ DATA1
+ Error
[T]
S1
+ <ACK,J>
[I!=J]
I=I+1
+ <ACK,J> [I=J]
+ <DATA, I>
t1
[I==J]
J=J+1
+ Error*
S0
+ Error
*
- <ACK, J>
S1
* : + <DATA, I> [I!=J]
(b) ABP with 2 states
CICS 515 – Summer 2012 © Dr. Son Vuong
36
Alternating Bit Protocol (Correct Version)
SENDER
RECEIVER
+ ACK1
+ ACK1
+ ACK0
0
- DATA0
3
0
3
- DATA1
1
+ ACK1
+ ACK0
+ ACK0
2
1
+ ACK0
+ DATA0
+ Error
+ DATA0
+ DATA1
2
+ Error
- ACK0
(a) ABP with 4 states
Init J=0
Init I=0
+ <ACK,J> [I=J]
S0
- <DATA, I>
+ DATA1
+ Error
+ DATA1
+ DATA0
+ ACK1
[T]
- ACK1
+ Error
[T]
S1
+ <ACK,J>
[I!=J]
I=I+1
+ <ACK,J> [I=J]
+ <DATA, I>
t1
[I==J]
J=J+1
+ Error*
S0
+ Error
*
- <ACK, J>
S1
* : + <DATA, I> [I!=J]
(b) ABP with 2 states
CICS 515 – Summer 2012 © Dr. Son Vuong
37
How to Recover from Errors?
If a bad frame is detected, what do we do?

Forward Error Correction (FEC) - Using parity bits as a
guide to fixing single bit errors.

Respond to the sender by transmitting a message:
 NAK = Negative Acknowledgement
 ACK = Positive Acknowledgement (if no error)

Let the sender timeout and retransmit. Also called
Automatic Repeat reQuest (ARQ)
CICS 515 – Summer 2012 © Dr. Son Vuong
38
Sender
Receiver
Sender
Fram
e
Timeout
Timeout
ACK
Timeout
Time
Fram
e
Receiver
(a)
ACK
Fram
e
ACK
(c)
Timeout for frame loss recovery
Timeout
Timeout
Fram
e
Fram
e
Sender
Timeout
Receiver
Timeout
Sender
Receiver
Fram
e
ACK
Fram
e
ACK
ACK
(b)
CICS 515 – Summer 2012 © Dr. Son Vuong
(d)
39
Questions:
What should we set the sender’s timeout value
to be?
What is Piggybacking? How does it save us
from sending ACKs?
CICS 515 – Summer 2012 © Dr. Son Vuong
40
Efficiency: Stop-and-wait protocol
sender
receiver
first packet bit transmitted, t = 0
last packet bit transmitted, t = L / R
first packet bit arrives
last packet bit arrives, send ACK
RTT
ACK arrives, send next
packet, t = RTT + L / R
Example: 1 Gbps link, 15 ms e-e prop. delay, 1KB packet:
U
sender
=
L/R
RTT + L / R
CICS 515 – Summer 2012 © Dr. Son Vuong
=
.008
30.008
= 0.00027
microsec
onds
41
Stop-and-Wait Protocol
Efficiency
α =
CICS 515 – Summer 2012 © Dr. Son Vuong
42
Efficiency of Stop and Wait Protocol
U = D/(D+H+A+2CI) =~ 1/(1 + 2*Tp/Td)
U = 1/(1+2)
U = channel utilization (efficiency)
D = # bits in frame body
H = # bits in frame header
A = # bits in ACK
C = channel capacity (bits/sec)
I = Propagation Delay = Distance/Speed
(300, 200, 230 m/s for vacuum, fiber, copper)
CICS 515 – Summer 2012 © Dr. Son Vuong
43
Link Utilization (Efficiency)
Example
CICS 515 – Summer 2012 © Dr. Son Vuong
44
Maximizing Link Efficiency
Example: 1.5Mbps link x 45ms RTT = 67.5Kbits
(8KBytes) for the Delay x Bandwidth product.
Assuming frame size of 1KB, stop-and-wait uses
about one-eighth of the link's capacity.
Solution: Want the sender to be able to transmit up to
8+1 = 9 frames before having to wait for an ACK.
CICS 515 – Summer 2012 © Dr. Son Vuong
45
Sliding Windows Flow Control
Allow multiple frames to be in transit
Receiver has buffer W long
Transmitter can send up to W frames without ACK
Each frame is numbered
ACK includes number of next frame expected
Sequence number bounded by size of field (k)

Frames are numbered modulo 2k
CICS 515 – Summer 2012 © Dr. Son Vuong
46
Pipelined (sliding window) protocols
Pipelining: sender allows multiple, “in-flight”, yet-to-beacknowledged pkts
 range of sequence numbers must be increased
 buffering at sender and/or receiver
Two generic forms of pipelined protocols: go-Back-N,
selective repeat
CICS 515 – Summer 2012 © Dr. Son Vuong
47
Efficiency: Stop-and-wait protocol
sender
receiver
first packet bit transmitted, t = 0
last packet bit transmitted, t = L / R
first packet bit arrives
last packet bit arrives, send ACK
RTT
ACK arrives, send next
packet, t = RTT + L / R
Example: 1 Gbps link, 15 ms e-e prop. delay, 1KB packet:
U
sender
=
L/R
RTT + L / R
CICS 515 – Summer 2012 © Dr. Son Vuong
=
.008
30.008
= 0.00027
microsec
onds
48
Pipelining: increased utilization
sender
receiver
first packet bit transmitted, t = 0
last bit transmitted, t = L / R
first packet bit arrives
last packet bit arrives, send ACK
last bit of 2nd packet arrives, send ACK
last bit of 3rd packet arrives, send ACK
RTT
ACK arrives, send next
packet, t = RTT + L / R
Increase utilization
by a factor of 3!
U
sender
=
3*L/R
RTT + L / R
CICS 515 – Summer 2012 © Dr. Son Vuong
=
.024
30.008
= 0.0008
microsecon
ds
49
Sliding Window Protocol Efficiency
CICS 515 – Summer 2012 © Dr. Son Vuong
50
Efficiency: Stop-and-wait protocol
sender
receiver
first packet bit transmitted, t = 0
last packet bit transmitted, t = L / R
first packet bit arrives
last packet bit arrives, send ACK
RTT
ACK arrives, send next
packet, t = RTT + L / R
Example: 1 Gbps link, 15 ms e-e prop. delay, 1KB packet:
U
sender
=
L/R
RTT + L / R
CICS 515 – Summer 2012 © Dr. Son Vuong
=
.008
30.008
= 0.00027
microsec
onds
51
Peer Instruction 3.2: Questions
Consider the previous example:
 1 Gbps link,
 15 ms e-e propagation delay, e.g. RTT = 30 ms
 1KB packet
(1) What would be the window size to achieve 100% efficiency?
(A) 15 (B) 30
(C) 300
(D) 3751
(E) 4000
(F) None
(2) How many bits at minimum are needed for the sequence
number ?
(A) 4
(B) 6
(C) 12
CICS 515 – Summer 2012 © Dr. Son Vuong
(D) 13
(E) 15
(F) None
52
Sliding Window Diagram
CICS 515 – Summer 2012 © Dr. Son Vuong
53
Sliding Window Protocol Example
CICS 515 – Summer 2012 © Dr. Son Vuong
54
Dealing with Errors
What happens if a frame is lost, or is corrupted?
Solution 1: Go back N
 Receiver discards all subsequent frames
 Sender must retransmit all frames, starting at the
lost/corrupted frame.
 This implies that RWS = 1
 No buffering is needed at the receiver
 Ordering of frames is guaranteed
 A lot of bandwidth is wasted if error rate is high.
CICS 515 – Summer 2012 © Dr. Son Vuong
55
Dealing with Errors cont.
Solution 2: Selective Repeat
 Receiver sends a NAK, with a list of frames
that are missing/corrupted.
 Receiver stores subsequent frames.
 Sender retransmits the bad frame(s) only.
 Need to buffer up to RWS frames at the
receiver and order them correctly before
sending to a higher protocol layer.
CICS 515 – Summer 2012 © Dr. Son Vuong
56
Sender
LAR
0
1
LFS
SWS
2
3
4
5
6
7
8
Sender side:
SWS: send window size
LAR: last ACK received
LFS: last frame sent
Sender:
if more data to send (LFS-LAR < SWS)
then send data, LFS++
if recv’ed ACK for LAR+1
then LAR++
if timer expires
then send LAR+1
CICS 515 – Summer 2012 © Dr. Son Vuong
57
Receiver
LFR
0
1
LAF
RWS
2
3
4
Receiver side:
RWS: receive window size
LFR: last frame received
LAF: largest acceptable frame
5
6
7
8
Receiver:
if recv’ed K <= LFR, K > LAF
then discard
else
store
if K == LFR+1
then LFR++, LAF++ (slide window)
ACK, largest in-order received frame
CICS 515 – Summer 2012 © Dr. Son Vuong
58
Selective Repeat Example - Animated
SWS
0
1
2
3
4
5
6
7
8
4
RWS
0
CICS 515 – Summer 2012 © Dr. Son Vuong
1
2
3
ACK5
5
59
Selective Repeat Example
SWS
0
1
2
3
4
5
2
6
7
8
3
RWS
X
loss
0
1
Choice to keep 3
or discard
CICS 515 – Summer 2012 © Dr. Son Vuong
60
Selective Repeat Example
SWS
0
1
2
3
4
5
6
7
2
8
4
RWS
0
CICS 515 – Summer 2012 © Dr. Son Vuong
1
3
5
61
Selective Repeat Example - Animated
SWS
0
1
2
3
4
5
6
7
8
4
RWS
0
CICS 515 – Summer 2012 © Dr. Son Vuong
1
2
3
ACK5
5
62
Go-Back-N
Sender:
k-bit seq # in pkt header
“window” of up to N, consecutive unack’ed pkts allowed
ACK(n): ACKs all pkts up to, including seq # n - “cumulative ACK”
 may receive duplicate ACKs (see receiver)
timer for each in-flight pkt
timeout(n): retransmit pkt n and all higher seq # pkts in window
CICS 515 – Summer 2012 © Dr. Son Vuong
63
GBN in
action
M >= W + 1 or W =< M-1
CICS 515 – Summer 2012 © Dr. Son Vuong
64
GBN - Scenario 1 of Confusion
When W =< M-1 is violated
Window W = Modulus M = 8
What’s wrong ?
I, 0
lost
I, 1
I, 2
I, 3
ACK, 0
I, 4
I, 5
I, 6
I, 7
I, 0
CICS 515 – Summer 2012 © Dr. Son Vuong
ACK, 0
65
GBN - Scenario 1 of Confusion
When W =< M-1 is violated
Confusion when
Window W = Modulus M = 8
ACK,0 can mean Ack to request
for retransmission of I,0; ACK,
0 can also mean Ack for receipt
of all I frames 0 to 7, and to
request for new packet 0.
Thus, upon receiving ACK, 0
Sender is confused whether
Receiver has received all I
packets 0 to 7, or none at all.
CICS 515 – Summer 2012 © Dr. Son Vuong
I, 0
lost
I, 1
I, 2
I, 3
ACK, 0
I, 4
I, 5
I, 6
I, 7
I, 0
ACK, 0
66
GBN - Scenario 2 of Confusion
When W =< M-1 is violated
I, 0
I, 1 lost
ACK, 1
I, 2
ACK, 2
I, 3
ACK, 3
I, 4
ACK, 4
I, 5
ACK, 5
I, 6
ACK, 6
I, 7
ACK, 7
lost ACK, 0
I, 0
CICS 515 – Summer 2012 © Dr. Son Vuong
Window W = Modulus M = 8
What’s wrong ?
67
GBN - Scenario 2 of Confusion
When W =< M-1 is violated
I, 0
I, 1 lost
ACK, 1
I, 2
ACK, 2
I, 3
ACK, 3
I, 4
ACK, 4
I, 5
ACK, 5
I, 6
ACK, 6
I, 7
ACK, 7
lost ACK, 0
I, 0
CICS 515 – Summer 2012 © Dr. Son Vuong
If all ACKs got lost, Sender will timeout
and retransmit duplicate I frame 0
I, 0 which will unfortunately be treated
wrongly by the Receiver as the new fresh I
Frame 0.
68
Selective Repeat
receiver individually acknowledges all
correctly received pkts

buffers pkts, as needed, for eventual in-order
delivery to upper layer
sender only resends pkts for which ACK not
received

sender timer for each unACKed pkt
sender window


N consecutive seq #’s
again limits seq #s of sent, unACKed pkts
CICS 515 – Summer 2012 © Dr. Son Vuong
69
Selective repeat: sender, receiver windows
CICS 515 – Summer 2012 © Dr. Son Vuong
70
Selective repeat in action
CICS 515 – Summer 2012 © Dr. Son Vuong
71
Example: Go-back-N RWS = 1
SWS = 3
0
1
2
0
1
2
0
1
2
3 sequence numbers
SWS = 3
RWS = 1
Case 1: All 3 packets get lost
Case 2: All 3 packets received OK
Ack 2,
Expecting “0”
RWS = 1
2
Sender cannot tell which case (from ACK 2) !
Sequence space must be at least SWS+1
i.e.
SWS < Modulus
CICS 515 – Summer 2012 © Dr. Son Vuong
72
Selective repeat:
dilemma
Example:
seq #’s: 0, 1, 2, 3
window size=3
receiver sees no difference
in two scenarios!
incorrectly passes duplicate
data as new in (a)
Q: what relationship between
seq # size and window
size?
CICS 515 – Summer 2012 © Dr. Son Vuong
73
Example: Selective Repeat RWS = SWS
Modulus = 4
SWS = 3
0
1
2
3
0
1
2
3
0
Receiver: Did 3 just get lost
or delayed and I received a
new 0 or did all my ACKs get
lost and this is the old 0?
RWS = 3
0
1
2
3
0
1
2
Sequence space = Modulus >= SWS + RWS = 2SWS
i.e.
SWS =< Modulus/2
CICS 515 – Summer 2012 © Dr. Son Vuong
74
Example
SWS = 2
0
1
2
3
0
1
2
3
0
Receiver: No ambiguity!
If both of my ACKs got lost
duplicate 0 would be
received. Otherwise, a new
2 or 3 would be received.
RWS = 2
0
1
2
3
0
1
2
Modulus = 4 and SWS = 2
=> SWS =< Modulus/2 is satisfied
CICS 515 – Summer 2012 © Dr. Son Vuong
75
TCP vs GobackN vs Selective Repeat
GobackN
RWS =1, W =< M-1
Discard out-of-sequence
segments
Cumulative Ack
e.g. ACK n
Retransmit All outstanding
segments
e.g. segments n, n+1, …, N
Selective Repeat
• RWS = SWS >1, W =< M/2
• Store out-of-sequence
segments received
• Individual Ack
(Selective Ack is an option)
e.g. ACK n
•Retransmit only 1 (oldest
un-acked) segment,
e.g. segment n only
TCP is a hybrid compbined GobackN and Selective Repeat
(as shown in red)
CICS 515 – Summer 2012 © Dr. Son Vuong
76
Sliding Window Protocol
Summary
Used in dala link layer (node-to-node)
Provide reliable transfer, flow/error control, and
sequencing
Efficiency depends on =Tp/Td and window size
CICS 515 – Summer 2012 © Dr. Son Vuong
77