Download presentation
Presentation is loading. Please wait.
1
Chapter 3 The Data Link Layer
2
Function: The data link layer deals with the algorithm for achieving reliable, efficient communication between two adjacent machines. 研究两个相邻机器在数据链路层进行可靠、有效的通信 Describes how a shared communication channel can be accessed, and how a data frame can be reliably transmitted. We’ll just concentrate on transmission issues. Channel access is discussed in Chapter 4
3
Topics Design Issues Framing Reliable Transmission PPP Error Control
Flow Control Six Protocols PPP
4
3.1 Data Link Layer Design Issues
Services Provided to the Network Layer Framing(成帧) Error Control(差错控制) Flow Control(流量控制)
5
Functions of the Data Link Layer
Provide a well-defined service interface to the network layer Dealing with transmission errors Regulating data flow Slow receivers not swamped by fast senders
6
3.1.1 Services Provided to Network Layer
7
DLL Services The Data Link Layer can offer many different services.
These services can vary from system to system. Common services: Unacknowledged connectionless service.(无确认的无连接服务)LANs Acknowledged connectionless service.(有确认的无连接服务) Wireless systems Acknowledged connection-oriented service.(有确认的面向连接服务) WANs
8
Framing The Physical Layer is only able to put a raw bit stream on the transmission media. We have to be able to break up this bit stream into frames. 要解决的两个问题 帧的边界问题(boundary) 帧的透明传输(填充)问题(stuffing)
9
Framing method character count(字符计数法 )
Flag bytes with byte stuffing(带字符填 充的首尾界符法 ) Starting and ending with character stuffing Starting and ending flags, with bit stuffing(带位填充的首尾界符法 ) Physical layer coding violation (物理层编 码违例法)
10
1、Character Count We use a field in the header to specify the number of characters in the frame. (在帧头部用一个字段来标明帧内字符数) This method can cause problems if the count is garbled in transit.(可能出现由于传输差错而被篡改) The receiver will not know where to pick up and the sender will not know how much to resend. This method is rarely used anymore.
11
A character stream. (a) Without errors. (b) With one error.
12
2、Flag Bytes (with byte stuffing!)
Frames begin and end with special bytes(Flag Byte). Often used are the same start/end flag. If the receiver gets “lost”, it just looks for a pair of flag bytes to denote the end of one frame and the start of the next. What happens if the “flag” byte is accidentally transmitted in the message?
13
“Byte stuffing” is the process of putting an “ESC” character in front of any accidentally occurring FLAG in a message. What happens if an ESC accidentally occurs in a message? We ESC that too! This is sometimes referred to as character stuffing.(字符填充)
15
3、Starting and ending flags, with bit stuffing
Each frame begins and ends with a special bit pattern, (in fact, a flag byte) Bit stuffing: Whenever the sender's data link layer encounters five consecutive 1s in the data, it automatically stuffs a 0 bit into the outgoing bit stream.
16
在连续的5个“1”位后,插入一个 “0”位 Bit stuffing (a) The original data.
(b) The data as they appear on the line. (c) The data as they are stored in receiver’s memory after destuffing.
17
4、Physical layer coding violation 物理层编码违例法
Bit “1” 高-低电平对, Bit “0” 低-高电平对, 帧的边界(高-高,低-低)
18
3.1.3 Error Control How to make sure all frames are eventually delivered to the network layer at the destination and in the proper order? Suppose something went wrong during frame transmission. How do we actually notice that something’s wrong, and can it be corrected by the receiver? Acknowledgment, Error Detection and Error Correction
19
Suppose the packet was lost on the way. How do the sender notice it?
Timers and Retransmission What if a frame was transmitted multiple times? Sequence Numbers for every frame.
20
3.1.4 Flow Control To solve the problem that a sender wants to transmit frames faster than the receiver can accept them. Feedback-based flow control feedback is used to tell the sender how the receiver is doing or to send another frame Used in Data Link Layer Rate-based flow control the transfer rate is fixed by the sender this is not used often in the DLL
21
3.2 Error Detection and Correction
Error Detection and Retransmission: to include only enough redundancy to allow the receiver to deduce that an error occurred, but not which error (error-detecting codes), and have it request a retransmission. Forward Error Correction: to include enough redundant information along with each block of data sent (error-correcting codes), to enable the receiver to deduce what the transmitted data must have been
22
3.2.1Error Correction --- Hamming Code 1、Hamming Distance
Consider the data and check bits from a frame as a codeword(码字). Given two codewords, we can determine the “difference” between the two codewords based on the number of bit difference. We can just XOR the two codewords and then count the number of 1 bits in the result. The Hamming distance between two frames a and b is the number of bits at the same position that differ.
23
-------------------------
Example The Hamming Distance is 3. This means 3 bits would have to “flip”(翻转) before we would be unable to detect an error.两个等长字符串之间的汉明距离是两个字符串对应位置的不同字符的个数。换句话说,它就是将一个字符串变换成另外一个字符串所需要替换的字符个数
24
We do not make use of all of the possible codewords due to the use of check bits.
This means we can compute all of the legal codewords and determine the minimum Hamming distance for the set. In order to detect d errors, we need a distance of d+1. In order to correct d errors, we need a distance of 2d+1.
25
2、The Parity Bit(奇偶位) Consider the parity bit that tells us if the parity of the data is even or odd. 保证码字中“1”的数目是偶数或奇数。 Example: Since it is only one bit, then it is able to identify single errors (if one bit has flipped). If two bits have flipped, then the parity bit will report the correct parity for the data. (偶校验)
26
设码长为n,信息位为m比特,校验位为r比特。
3、Hamming Code Using Parity bits as check bits, Hamming codes can correct single errors 汉明码是一种线性分组码。线性分组码是指将信息序列划分为长度为k位的信息码和r位的校验码,且信息码和校验码之间构成线性关系。即信息码和校验码之间可由线性方程组来联系。 设码长为n,信息位为m比特,校验位为r比特。 若用r比特校验码来纠正一位错误,则有
27
Every bit at position (k>=0) is used as a parity bit for those positions to which it contributes (To see which check bits the data bit in position k contributes to, rewrite k as a sum of powers of 2 ) Each check bit forces the parity of some collection of bits, including itself, to be even (or odd).
28
以m=4为例,则r>=3,取 r=3。 Check bit 若无错 注:此处为模2加法
29
若收到码字为 0000011,则S1=0, S2=1, S3=1. a3位出错,正确码字为0000111
30
Error Detection--CRC Based on the use for polynomial codes(多项式代码). The sender and the receiver agree on a generator polynomial(生成多项式) before the data is sent. A checksum (校验和)is generated for the message. The checksum, when divided by the generator polynomial, will have no remainder(余数). If a remainder exists, then there has been an error in transmission.
32
Sender: Receiver:
33
Example1:
34
Example2: Sender: try to send 110011
Receiver:By using CRC,to detect data
35
Three International Standards Generator Polynomials
CRC-16 =X16+X15+X2+1 CRC-CCITT =X16+X12+X5+1 CRC-32=X32+X26+X23+ X22+ X16+X12+X11+ X10+ X8+ X7+X5+X4+ X2 +X+1
36
3.3 Elementary Data Link Protocols
An Unrestricted Simplex(单工) Protocol (一种无限制的单工协议) A Simplex Stop-and-Wait Protocol (一种单工的停-等协议) A Simplex Protocol for a Noisy Channel (有噪声信道的单工协议)
37
Some Basic Assumptions
We assume that the three layers (physical, data link and network) are independent and communicate through a well-define interface. We will assume that the library for this interface will contain routines such as to_physical_layer and from_physical_layer to send and receive data.
38
A Simple Frame Structure
typedef struct{ frame_kind kind; /*what kind of frame?*/ seq_nr seq; /*sequence number */ seq_nr ack; /*acknowledgement number */ packet info; /*the network layer packet*/ } frame;
39
3.3.1 An Unrestricted Simplex Protocol (一种无限制的单工协议)
Suppose: Data are transmitted in one direction only (数据只能单向传输) Infinite buffer space is avaliable. (缓冲区空间无穷大 ) The communication channel between the data link layers never damages or loses frames. (数据链路层之间的通信信道永远不会损坏或者丢失帧)
40
Algorithem Sender: Receiver: From network layer Make frame
To physical layer To network layer Receiver: From physical layer Get frame
41
4343 X
42
3.3.2 Simplex Stop-and-Wait Protocol (一种单工的停-等协议)
Now we will drop the most unrealistic restriction used in protocol 1. i.e. Infinite buffer space is avaliable. (去掉缓冲区空间无穷大的条件 ) Suppose Data are transmitted in one direction only (数据只能单向传输) The communication channel between the data link layers never damages or loses frames. (数据链路层之间的通信信道永远不会损坏或者丢失帧)
43
How to prevent the sender from flooding the receiver with data faster than the latter is able to process them? A general solution to it is to have the receiver provide feedback(反馈) to the sender. Protocol in which the sender sends one frame and then waits for an acknowledgement(确认) before proceeding are called stop-and-wait(停等协议).
44
4343 X
45
3.3.3 A Simplex Protocol for a Noisy Channel 有噪声信道的停等协议
Now let us consider the normal situation of a communication channel that makes errors. Frames may be either damaged or lost completely. However, we assume that if a frame is damaged in transit, the receiver will detect it.
46
1.How to judge the info is right or not?
3 kinds of wrong information with positive acknowledgement Frame wrong CRC + timer Frame lost timer ACK lost sequence number
47
A sender doesn’t know whether a frame has made it (correctly) to the receiver. Solution: let the receiver acknowledge undamaged frames. Frame (acknowledgments) may get lost. Solution: let the sender use a timer by which it simply retransmits unacknowledged frames after some time. The receiver cannot distinguish duplicate transmissions. Solution: use sequence numbers.
48
Simplex: Stop-and-Wait Protocol with Positive Acknowledgement
Time A B DATA0 ACK1 Drop (d) ACK Lost tout Lost ACK 1 DATA1 To host ACK 0 (a) Nomal (c) Frame Lost (b) Frame Wrong retransmit Wrong
49
Sequence Number The sender remembers the sequence number of the next frame to send in next-frame-to send. 发送方要记录要发出的下一帧的编号 接收方要记录期待接收的下一帧序号 The receiver remembers the sequence number of the next frame expected in frame-expected.
50
Sender: next_frame_to_send
New Frame: invert sequence number Duplicate Frame:Do not change sequence number Receiver: frame_expected r.seq==frame_expected to_network_layer Change frame_expected Otherwise: Drop the duplicate frame
51
The selection of sequence number
m m m+2 The only ambiguity is between a frame and its immediate predecessor or successor. we need only two (0 & 1). 混淆帧只出现在相邻两帧之间,只需两个序号,即1bit
52
//1位的序号,0、1 //下一个要发 送的帧的序号
53
//下一个期望接收的序列号
54
Protocols in which the sender waits for a positive acknowledgement before advancing to the next data item are often called PAR (Positive Acknowledgement Retransmission) or ARQ (Automatic Repeater Request) 发送方在发送下一个数据项之前,等待一个肯定的确认帧的协议,称为 PAR协议或ARQ协议!
55
3.4 Sliding Window Protocols (滑动窗口协议)
A One-Bit Sliding Window Protocol A Protocol Using Go Back N A Protocol Using Selective Repeat
56
From Simplex to Duplex Problem: We want to allow symmetric frame transmission between two communicating parties, rather than transmission in one direction. Don’t waste channels, so use the same channel for duplex communication. Principle: Just transmit frames, but distinguish between data, acknowledgments (acks), and possibly negative acks(nacks) in the frame’s type field. piggybacking: The technique of temporarily delaying outgoing acknowledgements so that they can be hooked onto the next outgoing data frame
57
Sliding Windows Problem1: How to improve the channel utilization ?
Principle: Rather than just sending a single frame at a time, permit the sender to transmit a set of frames Problem 2: How to keep a fast sender from swamping a slower receiver with data? Principle 2: Flow control--taking use of sliding window to limit frame send
58
Sending Window: The sequence number within the sending windows represent frames that have been sent or can be sent but as yet not acknowledged.允许发送帧的序号(在没有收到对方确认信息时,发送端最多允许发送多少帧) Receiving Window:The receiving window corresponds to the frames it may accept. Any frame falling outside the window is discarded without comment. 接收窗口:期待接收的帧序号(只有发送序号落在接收窗口内才允许接收)
59
3.4.1 A One-Bit Sliding Window Protocol (一个1位滑动窗口协议)
A sliding window of size 1, with a 3-bit sequence number. (a)Initially. (b)After the first frame has been sent. (c)After the first frame has been received. (d)After the first acknowledgement has been received.
60
//双工,一个函数,收和发 Continued
62
3.4.2 A Protocol Using Go Back N and Selective repeat protocol
1、Pipelining(管道化技术) The rule requiring a sender to wait for an acknowledgement before sending another frame could lead to low bandwidth efficiency for long round-trip communications Pipelining: allowing the sender to transmit a bits of frames continuously before the first acknowledgement arrives
63
Pipelining and a Bad Frame
Problem: What happens when we get a bad frame? Go back n – Ask the sender to go back and start retransmitting from the lost frame. this should be easy as they should still be buffered. Selective repeat – Ask the sender to repeat the particular frames that were lost. this should be easy as that particular frame should still be buffered. is often combined with having the receiver senda Negative Acknowledgement (NAK) when it detects an error.
64
Pipelining and error recovery. Effect on an error when
(a) Receiver’s window size is 1. go back N (b) Receiver’s window size is large. Selective repeat protocol
65
2、 Sliding Window Characters of Sending Window
Sending window represent a set of sequence numbers which sender can send before getting ack . 发送窗口为未收到对方确认情况下,允许发方发 送的帧; Once a frame has been send, the sequence number which can be send will reduce. But, the sending window does not slide.每发送一帧,允许 发送帧的数目减1;发送窗口的位置不变。 Until an ACK is received by the sender, its sending windows will rotate by one.每收到一个确 认,窗口向前滑动一位。
66
WT 1 2 3 4 5 6 7 Do not allow to send Allow to send 5 frames (a) WT
1 2 3 4 5 6 7 Do not allow to send Allow to send 5 frames (a) Still allow to send 4 frames WT Has been send (b) Have been send (c) 1 2 3 4 5 6 7 Do not allow to send Still allow WT Have been send Got ACK (d)
67
Characters of receiving Window
只有当收到帧的序号落在窗口内时,才允许接 收,否则丢弃; 收到一个接收窗口内的帧,窗口滑动,同时发 送确认; 接收方可以使用捎带(piggybacking)确认; 可以收到多个帧发回1个确认. 对于连续ARQ协议,接收方必须按序的接收帧, 因此有WR =1。
68
WR (a) 1 2 3 4 5 6 7 1 2 Do not allow to receive Ready to accept 0 1 2
1 2 3 4 5 6 7 1 2 Do not allow to receive Ready to accept 0 1 2 3 4 5 6 7 WR Ready to accept 1 received (b) Do not allow to receive 1 2 3 4 5 6 7 WR received (c) Do not allow to receive Ready to accept 4
69
Relationship between Sending and Receiving Window
Receiver Control: Until the receiving window move and send back ACK, the sending window can rotate 只有在接收窗口向前滑动时(与此同时也发送了确认),发送窗口才有可能向前滑动 Window size: if Sequence number is n WT WR ≤ 2n
70
当发送窗口和接收窗口的大小都等于 1时,就是停止等待协议
The maximum window size(receiving window is 1, that is go back N protocl)发送窗口的最大值(接收窗口的大小为1时): WT 2n 1 Stop-and-Wait: WT = WR =1 当发送窗口和接收窗口的大小都等于 1时,就是停止等待协议 Example:当采用 3 bit 编码时,发送窗口的最大值是 7 而不是 8 一般陆地链路:3bit编码,发送窗口最大值7 卫星链路: 7bit编码,发送窗口最大值127
71
3、 GO Back N protocol Principle
Using Pipelining to allow the sender transmit and a bits of frames continuously until it reach the sending window limits. After sending each frame, a timer will alter and frame is buffered. When time out , the frame will be resend. Receiver refuses any frame except the next one it will give to network layer. Only receive sequential frames and give ack, discard all subsequence frames and sending no acknowledgements for the discarded frame.
72
Working Principle of GO back N
sender receiver A B DATA0 ACK1 确认 DATA0 DATA1 送交主机 ACK1 ACK2 确认 DATA1 DATA2 ?? ACK2 DATA2 出错,丢弃 DATA3 tout DATA3 不按序,丢弃,重传 ACK2 DATA4 ACK2 DATA4 不按序,丢弃,重传 ACK2 DATA5 ACK2 DATA5 不按序,丢弃,重传 ACK2 重传 DATA2 ACK2 ACK3 确认 DATA2 重传 DATA3 ACK3 ACK4 确认 DATA3 重传 DATA4 送交主机 ACK4 重传 DATA5 …
73
Simulation of multiple timers in software.
74
4、 A protocol Using Selective Repeat
Principle Go back N protocol works well if errors are rare, but if the line is poor, it wastes a lot of bandwidth on retransmitted frames Both sender and receiver maintain a window of acceptable sequence number. Sender only retransmit the wrong frame. Receiver buffers the right but disordered frames, and send Nak. 只重传出错的帧:加大接收窗口,先收下发送序号不连续但仍处在接收窗口中的那些数据帧。等到所缺序号的数据帧收到后再一并送交主机 代价:在接收端要设置具有相当容量的缓存空间
76
重叠问题 (a) Initial situation with a window size seven.
(b) After seven frames sent and received, but not acknowledged. (c) Initial situation with a window size of four. (d) After four frames sent and received, but not acknowledged.
77
To avoid overlapping, the maximum window size should be at most half the range of the sequence numbers WT和 WR的设置: WT = WR = ,仍满足 WT WR ≤ ,n为序号的位数。
78
3.5 Example Data Link Protocols
Packet over SONET ADSL (Asymmetric Digital Subscriber Loop) pppoE
79
Recall the Data Link Layer Protocols
The data link layer is responsible for transmitting frames from sender to receiver. The DLL has to take into account that transmission errors may occur=>error control (ACKs, NACKs, checksums, etc.) The DLL has to take into account that sender and receiver may operate at different speeds =>flow control (windows, frame numbers, etc.)
80
MAC:allocation of multi access channel 处理有关媒体的访问控制;
Network Layer Logical Link control 逻辑链路控制子层 Medium Access Control sublayer 媒体访问子层 Data Link Layer Physical Layer MAC:allocation of multi access channel 处理有关媒体的访问控制; LLC:the typical functions in Data link Layer执行通常的数据链路功能。
81
IEEE 802.2: Logical Link Control
LLC:run on top of Ethernet and the other 802 protocols, provide error control and flow control, and provide a single format and interface to the network layer. The format, interface, and protocol of LLC are all closely based on the HDLC protocol. The LLC header contains three fields: a destination access point, a source access point, and a control field.
82
常见的链路层规程(协议) 通信网络的链路层规程 (电信线路) Internet 的链路层协议 LAN的链路层协议 面向字符的规程: BSC
面向比特的规程:HDLC Internet 的链路层协议 SLIP PPP LAN的链路层协议 CSMA/CD---以太网协议 令牌协议
83
The Data Link Layer in the Internet
We will look at LANs later, so let’s take a look at the protocol for point to point connections within the Internet. The protocol is known as PPP or Point to Point Protocol. PPP is used to connect LANs to backbones. The PPP (Point-to-Point Protocol) is used in the Internet for a variety of purposes, including router-to-router traffic and home user-to-ISP traffic.
84
Packet over SONET. (a) A protocol stack. (b) Frame relationships
85
用户到 ISP 的链路使用 PPP 协议 已向因特网管理机构 申请到一批 IP 地址 用 户 接入网 至因特网 ISP PPP 协议
86
1、PPP provides three features
A framing method that unambiguously delineates the end of one frame and the start of the next one. A Link Control Protocol (LCP) for bringing lines up, testing them, negotiating options, and bringing them down again gracefully when they are no longer needed. The different NCP (Network Control Protocol) for each network layer supported to negotiate network- layer options in a way that is independent of the network layer protocol to be used.
87
2、PPP Framing meathod 1) Asynchronous Communication 异步通信,按字节传输
标志位为0X7E(即 ) 填充方法: 0X7E变为: 增加0x7D,0X7E与0X20异或; 如果0X7D出现在帧中,则0X7D与0X20异或 解码方法: 去掉0X7D,下一个字节同时与0X20异或
88
将信息字段中出现的每一个 0x7E 字节转变成为 2 字节序列(0x7D, 0x5E)。
例如: 将信息字段中出现的每一个 0x7E 字节转变成为 2 字节序列(0x7D, 0x5E)。 若信息字段中出现一个 0x7D 的字节, 则将其转变成为 2 字节序列(0x7D, 0x5D)。 若信息字段中出现 ASCII 码的控制字符(即数值小于 0x20 的字符),则在该字符前面要加入一个 0x7D 字节,同时将该字符的编码加以改变。 0x7E= 0x7D= x5E=
89
2、PPP Framing meathod 2) synchronous Communication 同步通信,按比特传输
标志位为 填充方法: 零比特填充方法
90
零比特填充 信息字段中出现了和 0 1 0 0 1 1 1 1 1 1 0 0 0 1 0 1 0 标志字段 F 完全一样 的 8 比特组合
发送端在 5 个连 1 之后 填入 0 比特再发送出去 发送端填入 0 比特 在接收端把 5 个连 1 之后的 0 比特删除 接收端删除填入的 0 比特
91
3、Frame Format Flag: 01111110 Address: always 11111111
Control: default (unnumbered mode) Protocol: default size is 2 bytes, tell what kind of packet is in the Playload field protocols starting with a 0 bit are network lay protocols such as IP, IPX,OSL CLNP, XNS; Those starting with a 1 bit are used to negotiate other protocols: LCP or other NCP Payload: variable length, up to some negotiated maximum; default length of 1500 bytes is used for LCP line setup Checksum: 2 or 4 bytes
92
PPP没有使用序号和确认机制 在差错率低时,协议简单,效率高; IP是不可靠的,所以不必保证数据链路曾非常可靠; PPP保证无差错接收。
93
A simplified phase diagram
LCPandNCP
94
3.5.2 ADSL (Asymmetric Digital Subscriber Loop)
ADSL protocol stacks.
95
补充:PPPoE PPPoE(PPP over Ethernet)是在以太网上建立PPP连接。
96
PPPoE 作用 解决在广播式网络中以点对点的方式进行宽带上网通信的问题。 实现方式 把PPP协议报文通过以太网帧进行封装。
97
补充: High-Level Data Link Control
SDLC(IBM’SNA)ADCCP(ANSI) HDLC(ISO)LAP(CCITT)LAPB(X.25) bit-oriented protocol 面向比特的规程SDLC(synchronous data link control) ---IBM的SNA,1974。提交给ANSI和ISO ADCCP(advanced data communication control procedure) ---美国标准(ANSI修改SDLC)。 HDLC(high level data link control ) ---国际标准(ISO修改SDLC )。 LAPB(link access procedure) ---CCITT标准修改HDLC 。
98
Frame Format(帧格式) flag sequence(标志序列) (01111110) 0X7E
bit oriented:Starting and ending flags, with bit stuffing
99
The address field is used to identify the terminal on lines with multiple terminals.
The control field is used for sequence numbers, acks & other stuff. The data field contains *gasp* - data. The checksum field is for the checksum. The frame is delimited by 8 bits on either end.
100
Three kinds of frames identified by different control field
Information(信息帧)、 Supervisory(监控帧) Unnumbered(无序号帧) Control field of (a)An information frame. (b)A supervisory frame. (c)An unnumbered frame.
101
1、Information frame(信息帧) ——Use to transmit frame
The protocol uses a sliding window, with a 3-bit sequence number. The Seq field is the frame sequence number. The Next field is a piggybacked acknowledgement. P/F(Poll/Final) P:the computer is inviting the terminal to send data F:the final frame.
102
2、Supervisory frame(监控帧) ——Use to control data stream
10 Type P/F Next (1) Type 0 is an acknowledgement 00, RR(Receive Ready),接收准备就绪 ,确认帧。 Next:期望接收的下一帧的顺序号 (2)Type 1 is a negative acknowledgement 01,拒绝(reject)Next :指明了第一个未被正确接收的帧序号。要求重传的帧序号, 从Next以后的帧都要重传。 (3)Type 2 is RECEIVE NOT READY 10, REJECTRNR (Receive Not Ready) 接收未准备就绪。 (4) Type 3 is the SELECTIVE REJECT. 11,Selective reject 选择性拒绝。Next: 指定帧重传,重传Next帧。
103
3、Unnumbered frame (无序号帧) ——Use to control link
11 Type P/F Modifier 由Type和Modifier可定义32种帧,其中15种已经定义,主要用来呼叫封闭并报告链路控制的状态。
104
Homework 2,3,6,16,17 谢希仁《计算机网络》2,5,9 2019/1/17
Similar presentations