---
tags: 大四
---
# 區域網路(Local Area Networks) Autumn 2021
[](https://hackmd.io/MAjWU1W0RRue0yl3HkKGRQ/info) 

<!---->
| # |Layer | protocol |
|--|-------------|----------------------|
| 5 |Application | http, stmp, ftp, ssh, DHCP |
| 4 |Transport | TCP, UDP |
| 3 |Network | IPv4, IPv6 |
| 2 |Link| IEEE802.3 Ethernet, IEEE802.11 Wi-Fi, ARP |
| 1 |Physical | 光纖、雙絞線、同軸電纜 |
[TOC]
## Review
### 1.1 網際網路
ISPs
: 網際網路服務供應商 (Internet Service Providers)
Protocol
: 終端系統、封包交換器以及網際網路的其他元件都會執行在網際網路中控制資訊傳送與接收**協定**
> 在人類的協定中,我們會送出特定的訊息,並且採取一些特定動作來回應所收到的回覆訊息或其它事件。
TCP
: 傳輸控制協定 (Transmission Control Protocol)
IP
: 網際網路協定 (Internet Protocol)
Internet standards
: 網際網路標準,係由「網際網
路工程工作小組 (IETF)」所開發 [IETF 2012]。
IETF
: 網際網路**工程**工作小組 (Internet Engineering Task Force)
> IRTF
> : 網際網路**研究**專門工作組(Internet Research Task Force)
RFC
: 建議需求(Requests for comments), IETF標準文件
> 你追 RFC 的速度永遠追不上他們制定的速度
> [name=Codomain]
<!-- 這是計網第一節課的慢速版吧 -->
### 1.2 網路邊際 (電腦、手機、Server)
:::spoiler
先從網路的邊際部分開始,檢視一些我們最熟悉的元件——亦即我們每天都會使用的電腦、智慧型手機和其他裝置。
在計算機網路的行話中,連結到網際網路上的電腦或其他裝置,通常被稱作終端系統。
:::
<!-- 4雞/5雞:4G/5G -->
家用連線:DSL、纜線、FTTH(光纖到府)、[撥接](https://www.youtube.com/watch?v=_6ZnzaG3Ppo)與衛星
+ DSL: 數位用戶線路 (Digital Subscriber Line)
+ FTTH: 光纖到府 (fiber to the home)
+ 主/被動式光纖網路:
> 主動式光纖網路 (AON)
> : active optical network,直連
>
> 被動式光纖網路 (PON)
> : passive optical network,過濾
>
+ 雙絞線: 減少訊號干擾
+ 同軸電纜線: 電視用的那種。是由一層層的絕緣線包裹著中央銅導體的電纜線。它的特點是**抗干擾能力**(2021有考)好,傳輸數據穩定
| 光纖網路 |雙絞線 |同軸電纜線 |
|--|--|--|
| | | |
實體媒介分成兩大類:
1. 導引式媒介 (guided media)
> 例: **雙絞銅線**、**同軸電纜**、**多模光纖電纜** (multimode fiber-optic cable)
2. 非導引式媒介 (unguided media)
> 例: 地表上的**無線電頻譜**和**衛星無線電頻譜**等。
### 1.3 網路核心
:::spoiler
網路的核心---也就是將網際網路終端系統相連在一起,由封包交換器與連結所構成的網絡。
:::
**儲存轉送傳輸機制 (store-and-forward transmission)**
> 交換器必須先**接收到整個封包**,才能夠開始將封包的第一個位元傳輸到外部連結。(是非題會考)

| 交換機制 | 優點| 缺點 |
| ------- |------| ----|
| 電路交換 | 保證頻寬 | 無法有效得到全部資源 |
| 封包交換 | 可應付{突發\|bursty}流量 | 封包丟失、延遲 |
:::spoiler 原文
1. circuit switching:
+ pros: dedicated resources, circuit-like(guaranteed) performance
+ cons: need call setup, circuit segment idle if not used by call
2. packet switching:
+ pros: no call setup, allows more user to use network
+ cons: sharing resources, excessive congestion possible: packet delay and loss
:::
### 電路交換

連結中的迴路可以利用
+ 分頻多工 (Frequency Division Multiplexing, FDM)
+ 分時多工 (Time Division Multiplexing, TDM)

### 網路們的網路

<!-- 所以 IXP 是三小 -->
IXP
: 網際網路互換點 (Internet Exchange Point)
<!--不然你想大家離散要怎麼被當 -->
### 1.4 封包交換網路的延遲、遺失與產出率
#### 延遲
當封包沿著這條路徑從一個節點主機或路由器移動到下一個節點 主機或路由器時它會在路徑上的各個節點遭遇到數種不同類型的延遲。
這些延遲之中 最重要的就是:
+ 節點處理延遲 (nodal processing delay)
+ 佇列延遲 (queuing delay)
+ 傳輸延遲 (transmission delay)
+ 傳播延遲 (propagation delay) 根傳輸的介質有關,一般線路距離傳輸為電磁波速率為光速,基本上可以忽略
+ 這些延遲總計為{**總節點延遲**|total nodal delay}。
### 1.5 協定層級與其服務模型
#### 分層式架構
OSI 模型
: 開放式系統互連 (Open Systems Interconnection)

#### 封裝

### 1.6 Network under attack
+ 病毒 (virus): 需要使用者以某種形式參與,才能感染使用者裝置的惡意軟體。
+ 蠕蟲 (Worms): 不需要使用者明顯的參與,就能夠進入使用者裝置內的惡意軟體。
+ 服務阻斷攻擊 (denial of service, DoS)
+ 分散式服務阻斷 (distributed DoS, DDoS)
### A day in the life
1. 透過 DHCP 廣播取得得到 IP
1. DHCP cover
2. DHCP offer
3. DHCP request
4. DHCP ack
2. 透過 ARP 取得 Gateway router 的 MAC Address
3. 後面不重要
## VLAN
> Definition: Virtual LAN is a logical network which connects stations just like they are physically connected.
### Draws of conventional switched LAN
+ Lack of traffic isolation: ARP, DHCP and management/employee separation.
+ Inefficient use of switches: 10 groups requires 10 traditional switches
+ Managing users: users may move or belong to multiple groups.
| without VLAN | with VLAN |
|--------------|-----------|
|| |
<!---->

+ Every LAN has an identifier (VLAN ID), which is a `12-bit` length ID.
### Feature of VLAN
1. More security
2. Ease of administration
3. Broadcast containment
4. Reduction in network traffic
## MPLS
多協定標籤交換(Multi-Protocol Label Switching),使用標記交換(Label Switching)可使封包傳送的延遲時間減短,增加網路傳輸的速度。主要優點是減少了網路複雜性,相容現有各種主流網路技術,能降低網路成本。
在 IETF 的規範中,MPLS 會在 Layer2 (硬體交換) 與 Layer3 (軟體交換) 封包間插入一個 `MPLS Header`,將傳統 IP Routing 隱合進 Layer 2 中提高封包在網路中傳遞的速度。

參考: https://www.dgbas.gov.tw/public/Data/821316592971.pdf
## IPv6
1. IPv4 地址佔 32bits, IPv6 則佔 128bits
2. IPv6 把一些欄位拔除,並改用選填的方式加在 header 後
3. IPv6 沒有 Checksum 也沒有 Fragment Offset
4. IPv4: 20bytes, IPv6:40bytes
5. TTL → Hop Limit
6. Separate optional headers between IPv6 header
and transport layer header


## IEEE 802.3 Ethernet

+ **preamble** (**8**bytes) (7 bytes with pattern 10101010 followed by one byte with pattern 10101011) used to synchronize receiver, sender clock rates
+ **dest. address** (MAC address **6**bytes)
+ **src. address** (MAC address **6**bytes)
+ **type** (**2**bytes) indicates higher layer protocol (mostly IP but others possible, e.g., Novell IPX, AppleTalk)
+ 0800: IP datagram
+ 0806: ARP
+ 8035: RARP
+ **CRC**: Cyclic Redundancy Check
> Ethernet frames must be at least 64 bytes long, not including the preamble, so, if the data field is shorter than 64 bytes, it must be compensated by the Pad field. (不足 64bytes 要補齊)(會考)
>
> Minimum length requirement is for the collision detect mechanism. In CSMA/CD a station must keep listening to determine whether there is a collision. (為了實作 CSMA/CD 所以 Ethernet 封包必需至少有 64 bytes)
>
> MAC Address: **Media Access Control Address**: 媒體存取控制位址,6bytes = 48bits
### ARP
**Address Resolution Protocol** 位址解析協定
A communication protocol used for discovering the link layer address, such as a MAC address, associated with a given internet layer address (IPv4).
#### ARP Proxy
邏輯概念上,是位於「來源主機」與「目的主機」之間的一個伺服器,可代為處理某些服務的功能,讓外部網路無法直接與內部網路聯絡。ARP Proxy 主要是用來增加安全性,因為 ARP 有一些安全性問題。
### RARP (Reverse ARP)

RARP 主要是應用於無磁碟機的電腦,由於無磁碟機的關係,也就是要靠開機時,透過網路向 RARP 的伺服器取得 IP 位址
+ RARP server sends the broadcasts query and back with an IP address.
+ RARP broadcast message can’t get through routers, an RARP server needs on each network.
### CSMA/CD
Carrier Sense Multiple Access with Collision Detection (載波檢測多重存取附碰撞偵測)
+ 傳輸速率:10Mbps(高速 Ethernet 可達 100 Mbps ~ 1 Gbps)
+ 訊框格式:IEEE 802.3 CSMA/CD格式 ,最大訊框為 1518 位元組,最小訊框為 64 位元組。
+ 傳輸媒介: 50 歐姆之同軸電纜(Coaxial Cable)、無遮蔽式雙絞線(UTP)或光纖(Optical Fiber)。
+ 網路拓樸圖:匯流排架構、廣播方式傳輸,最大網路範圍 2500 公尺。
+ **不提供保證傳送延遲服務**(2020有考):CSMA/CD 協定為競爭式,沒有優先權傳輸服務。所以不保證工作站是否能在某段時間內取得傳輸媒介的使用權。
+ 頻寬使用不保證公平:工作站的使用頻寬沒有平均分配,由競爭原則取得頻寬使用權。
+ 高負載時頻寬使用率低:高負載時工作站之間碰撞機率提昇,易造成頻寬使用率降低。
+ 較不適合多媒體資訊傳輸:因不保證傳輸延遲時間,而且基本協定規格的速率只有 10 Mbps,所以對即時傳輸的多媒體應用較不適合。
reference: http://www.tsnien.idv.tw/Network_WebBook/chap8/8-2%20CSMA_CD%20%E7%B6%B2%E8%B7%AF.html
### Loopback Interface
Allow client and server on the same host to communicate with each other using TCP/IP.
Packets sent to the loopback address will not leave the local host, they will never be sent onto any network.
> OSLab 課程透過 UDP 聯繫同一台電腦上的兩個程式。
### Internet Checksum

### CRC
Ethernet 封包中的一個欄位:**Cyclic redundancy check**

最後傳送: `10101010` `1100`
---
期中期末分水嶺
---
## SDN
Software-defined networking, 軟體定義網路,可以算是網路的作業系統
傳統網路必需由人類去定義路由器傳送的路徑
Control plane + data plane
### Open flow
OpenFlow runs on TCP (optionally using TSL) using port 6633 and is specified by c constructs

## IEEE 802.11
### History
1. IEEE 802.11
2. IEEE 802.11b WiFi2
3. IEEE 802.11a WiFi3
4. IEEE 802.11n WiFi4
5. IEEE 802.11ac WiFi5 (目前主流)
6. IEEE 802.11ax WiFi6
As 5G provides the access choice for outdoor networks, WiFi 6 is for indoor choice.
WiFi6 over WiFi5 in the following feature:
1. Scale improvement
2. Efficiency and capacity
3. Speed improvement
4. Range improvement
5. Future improvement
### Multiple Access Protocols (MAP)
MAP can be categorized into either **contention-based** or **conflict-free**.
+ FDMA, TDMA, CDMA, Token Ring are some examples of conflict-free protocols
+ ALOHA and CSMA are examples of random-access protocols
## IEEE 802.11 MAC Overview
### DCF and PCF
+ With **DCF** (Distribute Coordination Function), to avoid collisions, stations use a **random backoff after each frame**, with the first transmitter seizing the channel. In some circumstances, CTS/RTS may be used to further reduce the possibility of collisions.
+ **PCF** (Point Coordinated Function) provides **contention-free services**, and is restricted to infrastructure networks. To gain priority over standard contention-based services, the PCF allows stations to transmit frames after a shorter interval.
### Interframe Spacing
+ SIFS: **10μs**
+ PIFS: 19μs (short slot) 30μs (long slot)
+ DIFS: 28μs (short slot) 50μs (long slot)
+ EIFS: 8ACK + `PLCP-Preamble + PLCP-header` + DIFS
### Network Allocation Vector (NAV / 網路分配向量)
**NAV is a timer** that indicates the amount of time the medium will be reserved.
+ Atomicity of RTS/CTS sequence can be assure by using NAV.
+ NAV is carried on the frame header on the RTS and CTS frames.
**考題一 Fragmentation**

**考題二 RTS CTS**

### Slot time
Slot time is specific to the PHY implementation. Higher speed physical layers use shorter slot times.The 802.11 slot time is a basic time interval that supports media access mechanisms.
### Backoff Mechanism and Contention Window (CW)
+ If the station detects that the medium is busy before it transmits a message, **it wait until the medium is idle and a `DIFS` interval, and the station selects a random backoff time to start transmission.**
+ Backoff time = random() x a_slot_time
+ random is in the range of \[0, CW\]
+ CW is contention window. The maximum CW is 1023 slot times for direct sequence (DS) physical layer.
+ The CW is reset to its minimum size when frames are transmitted successfully.
<!--  -->

### NAV Timer vs Backoff Timer
+ Both NAV timer and backoff timer are two critical mechanisms to support collision avoidance.
### IEEE 802.11 PPDU Preview
Presentation Protocol Data Unit 表示協議數據單元
+ The 802.11 PPDU has 4 main components
1. PHY
+ long PLCP **192µs**
+ preamble (1-Mbps DBPSK)
+ 144 bits of long HR/DSSS preamble
+ header (1-Mbps DBPSK)
+ 48bits of long HR/DSSS preamble
+ short PLCP **96µs**
+ preamble (1-Mbps DBPSK)
+ 72 bits of **short** HR/DSSS preamble
+ header (2-Mbps DQBSK)
+ 48 bits of **short** HR/DSSS preamble
2. DataLink
+ MAC
+ 802.2 LLC
3. Payload (Optional)
4. FCS (4bytes 的 CRC)
```
PPDU = PLCP + PSDU
= PLCPpreamble + PLCPheader + PSDU
= PLCPpreamble + PLCPheader + MPDU
= PLCPpreamble + PLCPheader + MACheader + MSDU
```

<!--
1. PHY Preamble and Header (講議以 1-Mbps DBSK 舉例)
1. 144 bits of long HR/DSSS preamble
2. 72 bits of **short** HR/DSSS preamble (考試用這個算)
2. PLCP-Headers (講議以 1-Mbps DBSK 舉例,考古題有一題用 2-Mbps)
1. 48 bits of long HR/DSSS preamble
2. 24 bits of **short** HR/DSSS preamble (考試用這個算)
3. PSDE (考試時會給傳送速度,講議以 11Mbps 舉例)
+ Payload
+ FCS
-->
#### Long PPDU

#### Short PPDU

## IEEE 802.11 MAC Frame

Frame control
1. byte1
> protocal version (2 bits)
> type (2 bits)
> subtypes (2 bits)
2. byte2
>

Frame Format
1. Management frame (00)
2. Control frame (01)
3. Data frame (10)
Duration
1. Duration (NAV), bit 15 = `0`, represents the number of microseconds the medium is expected to by busy.
2. Contention-free periods frames (CFP frame), `10` in bit 15 and 14, for 36768 microseconds of contention free. All other bits are set to 0.
3. PS-poll frames, `11` in bit 15 and 14, for turning off antenna to save power.
※Fields are transmitted from left to right, and the most significant bits appear last. (big endian)
## 考古題討論傳送門
> 2020 fall 期中考解答討論 傳送門 → https://hackmd.io/@NCHU-CSE-111/rJSU-OvwK
> 2020 winter 期末考解答討論 傳送門 → https://hackmd.io/@NCHU-CSE-111/BkW8_vKnY
## Codomain 語錄 ─ OS 好難 9/23

我是從數學轉電腦,數學也OK、程式也OK,但作業系統不太OK,雖然我們念數學能懂很多抽像東西了,但那個什麼檔案系統...
你才會體會到這個說,數學很重要
當年數學全A的
打分數是A- 沒有A+拉哈哈
以前那個念碩士博士
我們碩士是考試 那個你可以畢業就畢業了不用像我們論文那麼多幾點的
拿到B+就很好了 常常是B- C C+
那我們當然也不死心阿 C當然不能再念阿
後面比較慢過去的 拿電腦碩士的那就很多了
電機 機械的什麼的都過去啦
他碰到OS 也死在那裏
花獻(台灣國語)說 ㄛGod那些數學畢業的、資工畢業的
根本沒有像他搞得那麼清楚 Unix kernel 的
他就很跩
薪水要更多那樣的 大概就知道他的能力
阿就真的給他欸!
我要講的素說,根本從 Kernel, Driver開始
所以我才(和曾學文討論)說我們這些 Unix 的課都不教寫 Kernel, driver,不是很奇怪嗎
(曾學文開計概 -> 計概消失在必修裡)
一直沒有真正 很用心 從 OS 的實習裡面
戶製(台灣國語)也可以啦!
阿這個大家要把握啦 跟大家提醒一下這個東C
吼 查一下!
## Codomain 語錄 ─ 求學態度 1/6
有個助教,他的養父母籌錢去上課,但他都沒去上課,他只去上他喜歡的。做人不要空轉,要有input,即使去工作也一樣。再辛苦也是要高高興興的,如果你去工作很難過,就去換工作。人生要有正正的態度。Steve Jobs他年紀跟我差不多,他說 "stay hungry stay foolish"。
做學生了不起就是考試沒過,在外面(工作)那個緊張程度,人際關係什麼的。有個物理系的老師比我年輕,他因為喜歡運動形的,所以他就去桌球場那邊找到他的太太。我們要有 2,3 個知心好友,什麼秘密都可以跟他講,如果你沒有,那要趕快去找,在學生階段最好要有,不一定要是男女朋友。我們班上同學,你應該要知道所有班上同學一些事情,比如他住那裡,什麼的。這樣你才算及格。
按:高伯伯的意思是要我們找到自己人生的目標,快樂、積極、正面的生活。另外,也要把人際關係搞好,要有知心好友。
<!--
## 廣告
[](http://fb.com/it.nchu/posts/5067227936626831)
-->
<!--iframe src="https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fit.nchu%2Fposts%2F5067227936626831&show_text=true&width=327" width="327" height="420" frameborder="0" clipboard-write; encrypted-media; picture-in-picture; web-share"></iframe>