AndyChiang
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 計算機網路 Ch04 - Network Layer: The Data Plane ###### tags: `計網` ## 4.1 Overview of Network layer * forwarding: 透過routing提供的forwarding table控制封包方向,將input轉移至正確的output。 * routing: 利用路由演算法計算路經。 ### Network layer: data plane, control plane * Data plane -> forwarding * Control plane -> routing #### Per-Router control plane 預先在router中安裝routing algorithm,兩兩router間獨立。 ![](https://i.imgur.com/BpNvLrK.png) #### Software-Define Network (SDN) router內沒有routing algorithm,全部由remote controller分配。 ![](https://i.imgur.com/oWcvSra.png) #### Network layer service models ![](https://i.imgur.com/Eq0V3i0.png) ## 4.2 Whats inside a router ![](https://i.imgur.com/cfJSV6w.png) 路由器架構 ### Input port ![](https://i.imgur.com/HCdoiNQ.png) #### Longest prefix matching ![](https://i.imgur.com/Tr5baBr.png) router會將封包送給destination address中前置符號相同的Link。如果有兩個以上前置符號相同的話,則傳給最長的那個。 #### ternary content addressable memories (TCAMs) 存取所有的destination address在記憶體中,該元件有快速查詢之特性。 #### Input port queuing ![](https://i.imgur.com/ZNwiPr8.png) * **Head-of-the-Line (HOL) blocking**: 從input傳送到output時被前一個檔案卡住。 ### Switching fabric 有三種方式: ![](https://i.imgur.com/8wN2X5a.png) * **memory(記憶體)**: 需要兩次存取記憶體,速度最慢。 * **bus(匯流排)**: 速度快,但一次只能傳一個,可能會塞車。 * **crossbar(交叉匯流排)**: 速度快,可平行傳輸。還可以分割檔案交由不同的匯流排傳送。 ### Output port ![](https://i.imgur.com/wUnGNo8.png) * **buffering**: 傳輸進來的檔案如果太多時,link layer來不及處理,會先放在queue中等待。 * **scheduling**: 依照檔案類型,分配傳輸的優先度。像: 影音類的優先度要高,文字類的優先度低,但也會產生不公平的問題。 #### Output port queueing ![](https://i.imgur.com/k12fUJ4.png) 一樣會發生data loss。 buffer大小: ![](https://i.imgur.com/u5ahXSp.png =15%x) (C:link layer容量,N:資料量) #### Scheduling mechanisms ##### FIFO (first in first out) scheduling 就和一般的queue一樣,先進來的先處理。 當queue滿了的時候,對於遺失封包有三種刪除方式(discard policy): * **tail drop**: 刪除最後來的封包 * **priority**: 刪除優先度低的封包 * **random**: 刪除隨機的封包,這樣的好處是,傳越多封包的process,越容易被刪除。 ##### priority scheduling ![](https://i.imgur.com/Uye9Hqb.png) 一個高優先度queue(紅色),一個低優先度queue(綠色)。當高優先度還有封包時,絕對不會送低優先度的封包。但是低優先度封包在運送過程中,並不會被高優先的封包打斷。 ##### Round Robin (RR) scheduling ![](https://i.imgur.com/zkMQv3W.png) 兩個queue輪流送,紅綠紅綠紅綠...這樣,如果其中一邊沒了就只送另一邊的封包。 ##### Weighted Fair Queuing (WFQ) ![](https://i.imgur.com/JnZhuov.png) 通用版的RR。 對每個queue加上權重,權重大的一次可以傳較多封包,因此傳送量可以比較大。 ## 4.3 IP: Internet Protoco ### IP datagram format ![](https://i.imgur.com/EBAoKF9.png) > IP header = 20 bytes > TCP header = 20 bytes > 20 + 20 = 40 bytes(最小封包大小) ### IP fragmentation, reassembly **MTU(max transfer size)**:最大運輸量,每個連結的MTU都不一樣。 ![](https://i.imgur.com/n5j1TK7.png) 封包長度如果超過MTU,就會被切割成小封包。 只會在終端機重組(reassembly)。 ![](https://i.imgur.com/cbl8Nlw.png) 4000的封包被切分為1500、1500、1040 * **length**:封包總長度,length - 20 bytes(IP header)才是資料長度。 * **ID**:辨識碼,分辨是否來自同一份檔案。 * **fragflag**:最後一個封包時,fragflag等於0。 * **offset**:資料的第一個byte / 8 = offset。 ### IPv4 addressing #### Subnets 將router拿走後還是相連的就是subnet。 ![](https://i.imgur.com/hTnlLj3.png) 路由器和路由器間也是一個subnet。 ![](https://i.imgur.com/A6Tfwmg.png) #### CIDR: Classless Inter Domain Routing address format: a.b.c.d/x, where x is # bits in subnet portion of address. ![](https://i.imgur.com/Zb0ZNTB.png) 使用者可以更彈性的設定host IP所需要的長度。 * subnet part - high order bits(前面x個bits) * host part - low order bits(後面的32-x個bits) #### DHCP: Dynamic Host Configuration Protocol 讓新加入網路的client順利取得IP address。 * **DHCP discover (optional):** client廣播尋找附近的DHCP server。 * **DHCP offer (optional):** DHCP server指派IP給client。 * **DHCP request:** client廣播告知其他DHCP server已經取得IP的消息。 * **DHCP ack:** 其他DHCP server回收指派的IP,並傳送確認訊息。 如果client曾經連線過,因為有上次DHCP server的IP紀錄,所以前兩個步驟可省略。 ![](https://i.imgur.com/yotTW5y.png) ![](https://i.imgur.com/XijL8IX.png) ##### how to get one? ![](https://i.imgur.com/lTtov9N.png) ISP會把host part往下切更細,分配給底下的host。 例子: > ISP的host part = 32 - 20 = 12 bytes,可紀錄2^12^ > 因為底下有8個host,所以2^12^ / 2^3^ = 2^9^ > 每個Host的subnet part = 32 - 9 = 23 bytes ##### route aggregation ![](https://i.imgur.com/kWC5o3s.png) 為了避免訊息量過大,ISP只傳送自己的IP address作為代表,因為前20bit prefix每個host都一樣,所以網路上還是找的到。 如果有Host換ISP了,會出現兩個相關的IP address。這時router會優先選擇subnet part比較長的ISP(回想一下Longest prefix matching),找到正確的host。 ##### ICANN: Internet Corporation for Assigned 決定ISP IP address和DNS的組織。 ### NAT: network address translation ![](https://i.imgur.com/4Q4slm4.png) 1. **outgoing datagrams**:從內往外送的封包,經過NAT時將 **source IP&port** 轉成 **NAT IP&指定port**。 2. **remember (in NAT translation table)**:將內網IP和外網IP建立對應表。 3. **incoming datagrams**:從外往內送的封包,經過NAT時將 **destanation IP&port** 轉回 **內網 IP&port**。 #### 優點 * 節省IP * 內網和外部獨立,兩邊互不干擾 * NAT看到private IP就直接刪除封包,加強內網的安全性 #### 缺點 * 因為用port區分內網IP,最多只能有60,000個連線 * 修改傳輸層的header,違反網路層的規範 * 外網不容易對指定內網發出請求,難度反而提高 ### IPv6 #### 動機 * 32-bits IP不夠用 * router處理太多事情 #### IPv6 datagram format ![](https://i.imgur.com/g8jvvtL.png) * **priority**:優先度,相同flow才看優先度 * **flow label**:使用者自行定義 * **next header**:紀錄option資料位置 #### 和IPv4的差異 * source & destanation address -> 128 bits (非常多,有生之年應該是用不完的) * 刪除checkSum * 刪除option,改成 "Next Header" 欄位,不計入header中,在end terminal處理 -> 固定長度 (4+4+16(src IP)+16(des IP)) = 40 bytes * 不做fragmentation,如果檔案太大,改成在來源端切割 * 使用ICMPv6 #### Tunneling 為解決IPv4和IPv6的相容問題。 * v6->v4:將v6封包視為v4的data,以v4的協定傳送 * v4->v6:直接取出v4的data,以v6的協定傳送 ![](https://i.imgur.com/sWUXRYw.png)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully