# 第02講 IEEE 802.3 Ethernet 計算機網路概論 黃能富教授 Ethernet --- * 第一個被廣泛使用的LAN * 傳輸速度約10 Mbps – 100 Gbps * DEC 與 Intel 加入 Xerox 共同定義了 10-Mbps Ethernet 標準, 此標準由 **IEEE standard 802.3** 所組成 * **Ethernet的特性:** 1. **Connectionless**:傳送封包前不需建立連線 2. **Unreliable**(不可靠傳輸):receiving NIC doesn’t send ACKs(確認訊息) or NACKs(未確認訊息) to sending NIC 3. Ethernet’s MAC protocol:**Carrier Sense Multiple Access with *Collision Detection* (CSMA/*CD*)** Bus Topology --- ![13](https://hackmd.io/_uploads/Hy6E0ZmcA.jpg) * all nodes in same collision domain (同時傳送會相互碰撞) Cable Signaling (Manchester Encoding) --- ![15](https://hackmd.io/_uploads/HkHomfm5C.jpg) * Coaxial Cable:同軸電纜 * Each bit has a transition(如同 clocks) * 只要有訊息傳輸,就會有電位的變化 -> low變high 或 high變low =>因此可**同步**傳送端及接收端 Ethernet第一代 - **10Base5** --- 1. 最長可達 500 公尺 2. **transceiver**(transmitter + receiver):用以偵測鏈結是否閒置,並在主機傳送時負責drives signal,並且也負責接收傳入的訊號 3. The transceiver is connected to an Ethernet adaptor 且adaptor插在主機上 4. CSMA/CD is implemented on the adaptor(介面卡) ![14](https://hackmd.io/_uploads/rJMFgG7c0.jpg) 5. Multiple Ethernet segments可以藉由 **repeater** 來連接 6. repeater :是一個裝置用於傳送 digital signals 7. between any pair of hosts**不能有超過四台**repeater ->代表Ethernet最大可達範圍長度僅為 2500公尺 ![16](https://hackmd.io/_uploads/r12QLMQ50.jpg) * 因為有半訊號增益器間電纜,因此Ethernet最大才可達範圍長度僅為 2500公尺 => 3段Coaxial Cable(500*3)+1000=2500 Ethernet第二代 - **10Base2** --- 1. 非使用coax cable,而是用較細的纜線來實作,稱之為10Base2 * 10 表示該網路以10 Mbps運作 * Base 表示被用於baseband system * 2 表示最長為 200 公尺 Ethernet第N代 - **10BaseT** --- 1. 更新的纜線技術稱作10BaseT * T 代表 twisted pair(雙絞線) * 長度限制在100公尺以下 2. 10BaseT而言,是許多point to point segments集中至multiway repeater,稱作**Hub**(集線器) 3. 運作方式還是broadcast Star Topology --- 1. **switch** 於Star Topology最中間 2. 分散式的Ethernet protocol(主機和主機之間的訊息**不會collide**) ![17](https://hackmd.io/_uploads/r19pj8X9A.jpg) * Switch:**每個port(乙太網路接口)都可同時傳輸** * ***Ethernet Switch ASIC example*** ![18](https://hackmd.io/_uploads/rJBIyP75A.jpg) * 24+4 代表 => 24個port和4個Gigabit Ethernet * Address Table用來記錄網卡位置和要到哪個port,且可同時查詢 ## Ethernet Frame Format ![19](https://hackmd.io/_uploads/rJ30eDm50.jpg) * Preamble (64bits):使得接收端得以進行訊號同步 => 一系列交錯的 0 與 1 訊號 * SFD -> Start Frame Delimiter (10101011) * DA -> Source and Destination MAC Addresses(48bits each) => 來源及目的端主機的網卡位址 * SA -> Source MAC Address * TYPE -> Packet type(16bits) => 指出此訊框應被送到哪個higher level protocol * Data(up to 1500 bytes) -> 綠色部分 - LLC-Frame(Up to 1500 bytes) + PAD(Padding when LLC-Frame < 46 bytes) => 最少要有 46 bytes,才能夠偵測傳輸是否發生碰撞 * FCS(Frame Check Sequence): CRC (32bit) --- * **Min *64* bytes 用來確定封包傳送是否碰撞** * **Max *1518* bytes 用來避免佔用大量頻寬** ### Ethernet Addresses * Each host on an Ethernet has a **unique Ethernet Address** * address 屬於adaptor而不是 host * 被燒錄在adaptor的ROM中 * 以冒號隔開的六個數字所組成的序列 * 每一個透過Ethernet傳輸的資訊,會被所有連接此Ethernet的主機接收 - broadcast * summarize: => Ethernet adaptor收到網路線上所有的frames and accepts * **unicast address** * **broadcast address** -> 所有位元均為 1 * **multicast address** -> 第一個位元為 1 但不全為1 ## Ethernet MAC protocol * any signal placed on the Ethernet 會廣播到整個網路上 * Terminators:會將訊號吸收, 以避免訊號反彈回網段上 ### CSMA (Carrier Sense Multiple Access) * CSMA(傳輸前先聽): * If channel sensed idle:傳輸整個frame * If channel sensed busy:延後傳輸時間 ### CSMA collisions * collisions can still occur: 1. propagation delay(傳輸延遲): => 代表兩點可能不會聽到相互正在傳輸資料 ![20](https://hackmd.io/_uploads/B1oQvtVq0.jpg) * t0 -> B開始傳送(黃色部分) * t1 -> D開始傳送(紅色部分) * t1 傳輸訊號時,因t0未抵達C,故認為此時為idle,但實際上會發生collision * collision:會浪費整個傳輸時間 ### CSMA/CD (Collision Detection) * CSMA/CD: 1. collisions detected within short time 2. 碰撞發生立即中斷傳輸,降低頻道的浪費 * Collision detection: 測量訊號的強度,比較傳送的訊號與接收的訊號 ![21](https://hackmd.io/_uploads/HywEYK490.jpg) * Carrier Sense Multiple Access with Collision Detection (CSMA/CD) 1. Carrier sense:代表所有的node可以分辨link的狀態是idle或busy 2. Collision detection:代表一個node在傳輸時會持續偵測是否其傳輸與其他node的傳輸訊號發生碰撞 * **1-persistent protocol**:每當link狀態由busy變至idle時,adaptor傳送frame的機率為 1 (100%) * **p-persistent**:每當link狀態由busy變至idle時,adaptor傳送frame的機率為 p (0 <= p <= 1) * 因為此協議沒有centralized control所以有可能發生同一時間有兩個(或多個)adaptors同時傳送 * 同時偵測到link為idle * 同時等到link由busy變至idle * 當以上狀況發生時,會發生collision * 當adaptor偵測到frame和別人發生collision時,首先會傳送一段 32-位元 的**jamming sequence**(擾亂訊號)並且停止傳送frame * 因此,在發生collision時, transmitter送出的訊框最少為 96 bits => 64-bit preamble + 32-bit jamming sequence * jamming sequence:避免誤判 * 有 96 bit的frame(此種訊框稱為 **runt frame**) 的情形之一是**兩個hosts距離非常近** Collision Window --- * The worst case scenario 發生在兩個主機分別**在Ethernet的兩端** * 為了確認frame在傳送時沒有和其他frame發生collision,transmitter可能需要傳送長度達 **512 bits** (64 bytes)的frame => 14 bytes of header + 46 bytes of data + 4 bytes of CRC * Collision Window = round-trip delay (來回延遲)(2a) --- ![22](https://hackmd.io/_uploads/ry1Gc5N5A.jpg) * 假設 A 開始傳送frame的時間點 **t** * **a** 代表 one link latency 1. A 所傳送frame的第一個位元到達 B 的時間為 **t + a** 2. 在A的frame到達 B 前,B 已開始傳送frame 3. A 和 B發生collision,B 偵測到 4. B 會送32-bit jamming sequence 5. A 不會偵測到collision,直到收到 B 的frame,此時間點為 t + 2a => 所以A 必須持續傳送 2a 的時間,才能確認所有可能發生的collision --- * 訊號往返最遠兩端的 round trip delay被設定為 51.2µs * 10 Mbps乙太網路, 此時間可以傳送 512 位元的資料 => 10 Mbps x 51.2 µs = 512 bits(64 bytes) * ***Collision Window (Slot time)***:IEEE 802.3 將一個Collision Window的時間定為 ***51.2μs*** Exponential Backoff Algorithm --- * Exponential Backoff: * 等一段時間後再來重新嘗試傳送 * **失敗後**,就會**加倍等待的時間**後再來重新嘗試傳送 1. first delays -> 不是 0 就是 51.2µs 2. second delays -> 0,51.2µs, 102.4µs, 或 153.6µs (隨機選一個) * 此為 k * 51.2 for **k = 0, 1, 2, 3** 3. third collision之後 => k * 51.2 for k =0 ~ 2^3 – 1(隨機選一個) 4. 此演算法隨機在 0 到 2^n – 1 之間選擇一個 k 值,然後等候 k * 51.2 µs * 連續collisions次數最多為16 * 2^n (n≦10) CSMA/CD Collision Handling --- * Collision Signal is generated by **Physical layer** * **Jam signal (強制衝撞)**:確認所有參與衝撞的工作站能確實偵測碰撞 -> 長度為 32 bits的訊號 * Collision backoff and retransmission method: -> **Truncated Binary Exponential Backoff Algorithm, BEBA** * 連續collisions衝撞的次數,最多16次 * 2^n (n<=10) * r : Random delay time (unit: slot time), 0 <= r < 2^n * Slot time = 51.2 µs * BEBA的缺點 -> Last-in-First-out effect Ethernet Performance --- * 在lightly loaded下運作較佳 * 在heavy load清況下,因容易collision,所以會有太多的網路頻寬資源浪費 ![23](https://hackmd.io/_uploads/HkWlg0N9R.jpg) ## 802.3 Ethernet Standards ### Link & Physical Layers * Many different Ethernet standards * 均用CSMA/CD和相同的frame format * 不同網速: 2 Mbps, 10 Mbps, 100 Mbps, 1Gbps, 10Gbps,100Gbps * different physical layer media:fiber(光纖), cable(同軸電纜) --- Full-duplex transmission in Switch topology (point-to-point) * No collisions * Excellent performance (wired speed)