《计算机网络概论》学习笔记整理之Reliable Transmission
/ / 点击 / 阅读耗时 11 分钟这篇笔记主要记录:
提供可靠传输的两种技术
- Acknowledgements
- Timeout
Stop-and-Wait Protocol
这种协议能提供可靠传输,但是效能堪忧:
- 有且仅有一个封包在外传输
- 可能会收到重复封包
Sliding Window Protocol
这种协议能提供可靠传输,且效能很好
- 每一个封包上都会添加一个sequence number,滑动窗口的工作方式建立在这个序号的基础上
- 同时可有多个封包在外传输(keeping pipefull)
- sender(window的滑动时机)
- Sending Window Size(SWS) = delay * bandwidth
- Last Acknowledgement Received(LAR)
- Last Frame Sent(LFS)
- Receiver(window的滑动时机)
- Receiving Window Size(RWS) = 1 or SWS
- Largest Acceptable Frame(LAF)
- Last Frame Received(LFR)
SWS和RWS可以不相等
如果RWS = SWS,最好让
SWS < (MaxSeqNum + 1) / 2
,否则,receiver可能会收到重复封包Acknowledgement机制的实现方式视具体实现而定,常用的有:
- NAK
- Cumulative acknowledgement
Sliding Window protocol 提供了三个特性
- 提供可靠传输
- Perserve order,虽然在传输过程是无序的,但是往上一层协议送的时候是有序的
- 流量控制,receiver determines the RWS
可靠传输
借助2个实现机制:
- Acknowledgements: An acknowledgement(ACK) is a small control frame(无data) that a protocol sends back to its peer saying that it has received the earlier frame
- Timeouts: The action of waiting a reasonable amount of time is called a timeout(超时后就要重送)
这两个又被称为 Automatic Repear reQuest(ARQ)
Stop And Wait Protocol
工作原理:
- After transmitting one frame, the sender waits for an acknowledgement before transmitting the next frame
- If the acknowledgement does not arrive after a certain period of time, the sender times out and retransmits the original frame
该协议可能出现四种情况:
- The ACK is reveived before the timer expires
- The original Frame is lost
- The ACK is lost(这种情况会导致Receiver重复收到相同的封包(duplicated frame))
- The timeout fires too soon or the ACK is delayed(这种情况也会导致Recaiver重复收到相同的封包)
Stop And Wait Protocol的问题
因为ACK丢失或延迟导致Receiver重复收到封包(duplicate copies of frames)
解决办法:使用1bit来给封包编号(0或1),重送的封包编号如果和前一个相同则会被丢弃
The sender has only one outstanding frame on the link at a time(这会导致链接的效率低下)
也就是说在1个RTT的时间里,只可能存在1个封包,这个问题没有办法解决,该协议的工作模式就是这样
Sliding Window Protocol
sender要给每一个封包添加一个SeqNum
SeqNum的大小盲猜是和具体实现有关
sender要维护三个变量
- Sending Window Size(SWS):表示同时可以送多少个封包出去而不用等ACK回来
- Last Acknowledgement Received(LAR):最新收到的连续的ACK的SeqNum
- Last Frame Sent(LFS):最后送的一个封包的SeqNum
sender还要维护下面这个不等式:
LFS - LAR <= SWS
下图反应了sender上的sliding window:
当1个ACK返回
The sender moves LAR to right, thereby allowing the sender to transmit another frame
sender也会给发出的每一个封包关联一个timer
It retransmits the frame if the timer expires(lost or delay) before the ACK is received
sender还需要buffer SWS个frame 以防重送
什么时候允许窗口滑动
当编号LAR+1的ACK收到时,就允许窗口滑动
上图中,2~6封包无序收到ACK,只有但2号收到ACK,形成一片连续ACK时,窗口才回移动,如果此时sender有封包要送,就可以使用9~13进行封包的发送
最好的涉及就是window一直在滑动
Receiver端也会维护3个变量
- Receiving Window Size(RWS): Upper bound on the number of out-of-order frames that the receiver is willing to accept
- Largest Acceptable Frame(LAF): Sequence number of the largest acceptable frame(可接收的最大值)
- Last Frame Received(LFR): Sequence number of the last frame received(连续收到的最近的一个)
Receiver端也会维护下面的不等式
LAF - LFR <= RWS
下图反应了receiver上的sliding window:
当一个带有SeqNum 序列号的封包到达Receiver时,Receiver是如何处理的
- if SeqNum <= LFR or SeqNum > LAF, discard it(the frame is outside the receiver window)
- if LFR < SeqNum <= LAF, accept it
Receiver端的窗口滑动时机
当编号LFR+1的ACK收到时,就允许窗口滑动
Cumulative Acknowledgement
- SeqNumToAck:还没有回复的Sequence number的最大值
- The receiver acknowledges the receipt of SeqNumToAck if high-numbered packets have been received
回复的这个ACK表示说Sequence number小于SeqNumToAck的封包通通都收到了
Sliding Window Protocol的问题
发生超时时,sender发送的数据量就会下降
ack没有回来,window就不能滑动
When the packet lost occurs, this scheme is no longer keeping the pipe full
The longer it takes to notice that a packet loass has occurred, the more severe the problem becomes
因为window会暂停,只要暂停就不会有新的sequence number用于发送新的封包,时间越长,throughout就越差
有三种方式用来改善上述情况:
- Negative Acknowledgement(NAK):封包错误返回ACK
- Additional Acknowledgement
- Selective Acknowledgement: receiver收到什么编号的封包就返回什么编号的ACK
如何选择window size
- SWS: delay * bandwidth
- RWS通常有两种选择方法
- RWS = 1:No buffer at hte receiver for frames that arrive out of order
- RWS = SWS:The receiver can buffer frames that the sender transmits
- RWS > SWS没有意义:因为sender 发送封包的最大量就是SWS个,RWS比SWS多出来的位置用不到
Sequence number是有限的,当封包数量很大时,可能遇到需要重复使用的情况
解决办法:- 可以用的sequence number的数量一定要大于在外面跑的封包的数量
- MaxSeqNum:当前可以使用的sequence number的上限值,sws + 1 <= MaxSeqNum
- 如果RWS = 1, 上面的方法能解决
如果RWS = SWS,上面的方法不足以解决
1
2
3
4
5
6
7
8
9
10sequence number: 0, 1, 2, 3, 4, 5, 6, 7
RWS = SWS = 7 = 8 - 1
1. Sender sends 0, 1, ..., 6
2. Receiver receives 0, 1, ..., 6
3. Receiver acknowledges 0, 1, ..., 6,但是ACK(0~6)丢失
4. Sender timeouts and retransmits 0~6
5. Receiver is expecting 7, 0, ..., 5
6. frames 0~5 will be accepted(duplicated)
7. frames 6 will be discarded(correct)为了解决上述的问题,当RWS = SWS时,需要设定SWS < (MaxSeqNum + 1) / 2, 也就是不能大于一半的数量
Sliding Window Protocol的特性
- 提供可靠传输
- Preserve order
- Each frame has a sequence numebr
- Out of order frames will be buffered
- Flow Control
- Receiver is able to throttle the sender by setting the values of RWS(sender可以送多快是由receiver决定的)
- Keeps the sender from overunning the receiver(不在Receiver窗口范围内的封包不收,会导致Sender方封包的timeout,重送把流量降下来)