5.數(shù)據(jù)鏈路層
鏈路層的特點和功能
data-link layer has responsibility of transferring datagram from one node to physically adjacent node over a link
結(jié)點(node)和鏈路(link)的定義
two types of “l(fā)inks”:
- point-to-point
- broadcast (shared wire or medium)
奇偶校驗
循環(huán)冗余校驗
校驗和
求下面三組數(shù)據(jù)的校驗和:
首先將三組數(shù)據(jù)求和,如果最高位溢出則還要在結(jié)果上加1
0110011001100000
0101010101010101
1000111100001100
The sum of first two of these 16-bit words is
0110011001100000
0101010101010101
1011101110110101
Adding the third word to the above sum gives
1011101110110101
1000111100001100
0100101011000010
最后求反碼
1011010100111101
At the receiver, all four 16-bit words are added,
including the checksum. If no errors are introduced into the packet, then clearly the
sum at the receiver will be 1111111111111111.
CSMA CSMA/CD 指數(shù)回退
用于以太網(wǎng)上多點接入技術(shù)
CSMA (carrier sense multiple access) :
每個站在發(fā)送數(shù)據(jù)之前置逻,先檢測信道是否空閑桃煎,空閑則發(fā)送數(shù)據(jù),不空閑則等待放棄碰撞的傳輸场刑,減少信道浪費。
CSMA/CD (collision detection) :
如果碰撞紧卒,使用二進制指數(shù)退避算法等待一段時間在發(fā)送蔬啡,在短時間內(nèi)檢測到碰撞。
CSMA/CD 碰撞檢測圖:
二進制指數(shù)回退法:
Let’s look at an example. Suppose that a node attempts to transmit a frame for the first time and while transmitting it detects a collision. The node then chooses K 0 with probability 0.5 or chooses K 1 with probability 0.5. If the node chooses K0, then it immediately begins sensing the channel. If the node chooses K 1, it waits 512 bit times (e.g., 0.01 microseconds for a 100 Mbps Ethernet) before beginning
the sense-and-transmit-when-idle cycle. After a second collision, K is chosen with equal probability from {0,1,2,3}. After three collisions, K is chosen with equal probability from {0,1,2,3,4,5,6,7}. After 10 or more collisions, K is chosen with equal probability from {0,1,2, . . . , 1023}. Thus, the size of the sets from which K is chosen grows exponentially with the number of collisions; for this reason this algorithm is referred to as binary exponential backoff.
MAC地址 ARP
32-bit IP地址:
網(wǎng)絡(luò)層地址
用于使數(shù)據(jù)報到達目的IP子網(wǎng)
MAC地址:
48 bit诵肛,用于使數(shù)據(jù)報從一個接口到達另一個物理連接的接口屹培。
ARP: 地址解析協(xié)議:
- ARP為在同一個子網(wǎng)上的主機和路由器接口解析IP地址
- LAN上的每個IP節(jié)點(主機、路由器)都有ARP表
- ARP表: 對某些LAN節(jié)點的IP/MAC地址映射
<IP地址; MAC地址; TTL> - TTL (壽命): 地址映射將被忘記的時間長度(通常20分鐘)
- ARP的查詢報文是在廣播幀中發(fā)送的怔檩,即發(fā)送給(FF-FF-FF-FF-FF-FF)
- ARP協(xié)議不需要管理員配制
- 將數(shù)據(jù)報發(fā)送到子網(wǎng)外時褪秀,幀中儲存的MAC地址為下一跳路由器的地址
以太網(wǎng)
以太網(wǎng)是無連接不可靠的,MAC協(xié)議為unslotted CSMA/CD wth binary backoff
以太網(wǎng)幀結(jié)構(gòu):
前導(dǎo)碼:
前同步碼一共有8個字節(jié)薛训,前7個字節(jié)都是10101010 媒吗,第8個字節(jié)是10101011,用于同步接收方乙埃,發(fā)送方時鐘速率蝴猪。地址: 6字節(jié)
如果適配器接收具有匹配的目的地址或廣播地址(如ARP分組)的幀, 它將幀中的數(shù)據(jù)提交給網(wǎng)絡(luò)層協(xié)議否則, 適配器丟棄幀。類型: 指示較高層協(xié)議 (大多數(shù)為IP但也可以支持其他類型如 Novell IPX和AppleTalk)膊爪。
CRC: 在接收方核對自阱,如果檢測到差錯,該幀就被丟棄米酬。
交換機原理
交換機表:
- 交換機是不需要管理員配制的(自學(xué)習(xí)沛豌、一段固定時間后無信號則丟棄某表項)
- 交換機可以消除碰撞、隔離不同的物理鏈路