本文整理无线多重访问协议,重点介绍Wifi和蓝牙的MAP。(最近将The ONE仿真器改成支持广播,发现仿真器对于节点能否开始传输判断极不严格,所以决定花些时间深入了解无线的MAC协议)。
目录
1. 介质访问控制MAC
1.1 为什么需要MAC
如有只有两台设备进行全双工的通信,因为两台设备可以同时发送和接收数据,不会产生冲突,因此不需要介质访问控制[4]。但在多节点网络,就需要一些机制来控制通信,避免冲突,举例如下(哪台PC可以得到总线控制权?):
图1 总线网络(图片来源于:互动百科总线网络)
关于介质访问控制(media access control, MAC)的解释,摘抄维基百科OSI model和Media access control,如下:
Media Access Control (MAC) layer – responsible for controlling how devices in a network gain access to data and permission to transmit it.
The MAC sublayer provides addressing and channel access control mechanisms that make it possible for several terminals or network nodes to communicate within a multiple access network that incorporates a shared medium, e.g. Ethernet.
1.2 多路访问协议
多路访问协议(Multiple Access Protocols)提供一套方法来决定多节点如何共享信道。可以分为3类:
- 信道划分(Channel Partitioning):如时分TDMA、频分FDMA、码分CDMA
- 随机接入(Random Access):检测冲突、从冲突中恢复。如CSMA
- 轮流(Taking turns):如令牌环Token ring
2. Wifi MAC
2.1 IEEE 802.11与Wifi
(1)IEEE 802.11
IEEE(Institute of Electrical and Electronics Engineers, 电气电子工程师学会)是一个建立于1963年1月1日的国际性电子技术与电子工程师协会,是多个科学期刊和会议的组织者,也是世界领先的标准制定者(即IEEE标准协会, IEEE-SA, IEEE Standards Association)。IEEE 802的一系列标准(包括无线网络802.11、以太网802.3)是IEEE-SA最著名的标准之一。
IEEE 802是局域网和城域网(local area networks and metropolitan area networks)的一系列标准,这一系列标准中的每一个子标准(如IEEE 802.11)都由委员会中的一个专门工作组负责[5]。子标准有时还会细分成任务组(Task Group)。
图2 IEEE 802标准工作组(图片来源于这里)
(2)Wifi
IEEE 802.11是一个标准,实现该标准可以很多种。为了使实现IEEE 802.11设备具有互操作性(Interoperability),一些主要产商联手建立Wifi联盟(Wi-Fi Alliance),旨在基于802.11创建和运行标准,解决互操作性和兼容性。换句话说,Wifi相当于在产品端制定一些标准,使得设备具有互操作性。摘录维基百科词条Wi-Fi:
The Wi-Fi Alliance defines Wi-Fi as any “wireless local area network” (WLAN) product based on the Institute of Electrical and Electronics Engineers‘ (IEEE) 802.11 standards“.
产家生产的产品提交到Wifi联盟做wifi认证,通过之后,有权标明WiFi产品。关于wifi认证,摘抄一段英文(原文在这里):
To obtain Wi-Fi certification, a manufacturer must submit its product for testing against a set of “gold standard” Wi-Fi products. The Wi-Fi Alliance created its own test plan based on IEEE 802.11. Some features of IEEE 802.11 are not required for Wi-Fi certification. Conversely, there are some requirements that are additional to the standard. Where there is ambiguity in the standard, the correct behavior is defined by the way the gold standard products work. In this way interoperability is ensured. In summary, Wi-Fi defines a subset of IEEE 802.11 with some extensions, as shown in Figure 7.2.
Figure 7.2. Relationship of Wi-Fi to IEEE 802.11
2.2 Wi-Fi Access Protocol
关于Wi-Fi访问协议,直接看下面这段英文,简洁易懂(原文在这里):
IEEE 802.11 wireless LANs use a media access control protocol called Carrier Sense Multiple Access with Collision Avoidance (CSMA/CA). While the name is similar to Ethernet’s Carrier Sense Multiple Access with Collision Detection (CSMA/CD), the operating concept is totally different.
Wi-Fi systems are half duplex shared media configurations, where all stations transmit and receive on the same radio channel. The fundamental problem this creates in a radio system is that a station cannot hear while it is sending, and hence it impossible to detect a collision. Because of this, the developers of the 802.11 specifications came up with a collision avoidance mechanism called the Distributed Control Function (DCF).
According to DCF, A Wi-Fi station will transmit only if it thinks the channel is clear. All transmissions are acknowledged, so if a station does not receive an acknowledgement, it assumes a collision occurred and retries after a random waiting interval.
The incidence of collisions will increase as the traffic increases or in situations where mobile stations cannot hear each other.
关于CSMA/CA可以参考维基百科词条CSMA/CA,其中提到了为什么不能用以太网的CSMA/CD:
The collision detection of the alternative CSMA/CD is unreliable due to the hidden node problem.
(1)避免冲突
该词条有一张图,节点发送数据包的算法流程图:
图3 CSMA/CA算法流程图
无线避免冲突引入了DCF机制,在上图判断信道是否空闲,其实包含了DCF,即监听信道一段时间,如果这段时间是空闲的,就可以发送数据包了。维基百科原文如下:
Distributed coordination function (DCF) is the fundamental MAC technique of the IEEE 802.11 based WLAN standard. DCF employs aCSMA/CA with binary exponential backoff algorithm.
DCF requires a station wishing to transmit to listen for the channel status for a DIFS interval. If the channel is found busy during the DIFS interval, the station defers its transmission.
值得注意的是,DCF和RTS/CTS并没有完全解决隐藏终端和暴露终端问题,词条原文如下:
DCF does not solve the hidden terminal and/or exposed terminal problem completely, it only alleviates the problem through the use of RTS and CTS, and recommends the use of a larger carrier sensing range.
(2)检测冲突
上图其实不完整,发送数据包之后,如果冲突了,怎么办。看词条原文[6]:
A node sends the frame in its entirety. the node awaits receipt of an acknowledgement packet from the Access Point to indicate the packet was received and checksummed correctly.
If such acknowledgement does not arrive after a timely manner, it assumes the packet collided with some other transmission, causing the node to enter a period of binary exponential backoff prior to attempting to re-transmit.
3. Bluetooth
蓝牙(Bluetooth)是一种支持设备短距离通信(一般10m内)的无线电技术,无线个人局域网(WPAN, wireless personal area network)。蓝牙采用分散式网络结构以及快跳频和短包技术,支持点对点和点对多点通信,工作在全球通用的2.4GHz ISM(industrial, scientific and medical)频段,其数据速率为1Mbps,采用时分双工(Time-division duplexing, TDD)传输方案实现全双工传输[7]。(实际上速度和矩离取决于蓝牙的版本)
IEEE 802.15工作组负责无线个人局域网WPAN。802.15.1是基于蓝牙制定的标准,摘抄维基百科词条Bluetooth如下:
Task group one is based on Bluetooth technology. It defines physical layer (PHY) and Media Access Control (MAC) specification for wireless connectivity with fixed, portable and moving devices within or entering personal operating space. Standards were issued in 2002 and 2005.
蓝牙的协议栈示意图如下:
图4 蓝牙协议栈示意图(图片来源于这里)
4. ZigBee和6LoWPAN
IEEE 802.15.4任务组旨在为低功耗无线设备通讯建立一套标准,摘抄维基百科Low Rate WPAN如下:
IEEE 802.15.4-2003 (Low Rate WPAN) deals with low data rate but very long battery life (months or even years) and very low complexity. The standard defines both the physical (Layer 1) and data-link (Layer 2) layers of the OSI model. Several standardized and proprietary networks (or mesh) layer protocols run over 802.15.4-based networks, including IEEE 802.15.5, ZigBee,6LoWPAN, WirelessHART, and ISA100.11a.
ZigBee和6LoWPAN(IPv6 over Low power Wireless Personal Area Networks)物理层和数据链路层都遵循802.15.4的标准。两者的差异,我个人理解是,ZigBee比较早出现,更加流行,而6LoWPAN是后起之秀,考虑得更加全面(如IPv6,互操作性、安全性)。
References:
[1]LECTURE 11: Wireless Channel Access Protocols.pdf
[2]Multiple Access Protocols Link Layer Addressing.pdf (ppt)
[3]Multiple Access Protocols – Moshe Sidi.pdf (book)
[4]维基百科词条:介质访问控制
[5]Wikipedia: IEEE 802
[6]Wikipedia: Carrier sense multiple access with collision avoidance
[7]百度百科:蓝牙
微信赞赏
支付宝赞赏