ji3g4al
    • 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 No publishing access yet

      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.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      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
    • Make a copy
    • 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 Make a copy 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 No publishing access yet

    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.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    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
    4
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ###### tags: `資工系課程` `CSnote` `電腦網路概論` # 電腦網路概論 ## CH1 ## Introduction ### What's a protocol? 『Protocol』是指在網路上一種可以彼此溝通的模式,雙方都要依照某些規則進行溝通 通訊協定又稱通信規程,是指通信雙方對資料傳送控制的一種約定。約定中包括對資料格式,同步方式,傳送速度,傳送步驟,檢糾錯方式以及控制字元定義等問題做出統一規定,通信雙方必須共同遵守,它也叫做鏈路控制規程。 ### Internet structure **Network edge** - hosts: clients and servers - servers often in data centers <font size=3>**Access networks(接取網路), physical media (傳輸媒介)**</font> - wired, wireless communication links - ![](https://i.imgur.com/OrwGGhz.png) **Network core** - interconnected routers - network of networks ![](https://i.imgur.com/m8u3fmv.png) ### Access networks: cable-based access(透過網路線or電纜) **HFC:混合光纖同軸網路** ### Access networks: digital subscriber line (DSL) 數位用戶線路 是通過銅線或者本地電話網提供數位連接的一種技術 use existing telephone line to central office DSLAM - data over DSL phone line goes to Internet - voice over DSL phone line goes to telephone net ## Network core: packet/circuit switching, internet structure ### Packet-switching: store-and-forward ![](https://i.imgur.com/S0P954d.png) - Transmission delay: takes L/R seconds to transmit (push out) L-bit packet into link at R bps - Store and forward: entire packet must arrive at router before it can be transmitted on next link - End-end delay: 2L/R ### Packet-switching: queueing delay, loss 若抵達速率大於傳輸速率: - packets will queue, waiting to be transmitted on output link - packets can be dropped (lost) if memory (buffer) in router fills up ### Two key network-core functions #### Routing: 主要是透過路由器彼此的互動,來修改路由器內的路由表,可以看成路由器內部有兩個程式,一個負責修改正確的路由表,提供 routing 服務 #### Forwarding: 就是路由器將封包對照路由表轉送到對應的網路界面的功能。 ### Alternative to packet switching: circuit switching 在兩通信端之間建立一條專用的 (dedicated) 實際路徑。此路徑由發送端開始,一站一站往目的端串聯起來,一旦建立兩端之間的連線後,它一直維持專用狀態 (即他人無法使用)。直到通信結束之後,這條專用路徑才停止使用,並讓出供他人繼續使用。目前的電話與電報交換系統就是使用這種技術 ### Circuit switching: FDM and TDM #### FDM(Frequency Division Multiplexing): FDM是依頻率來切割link區段,而使用者同時在同一個切割區域裡面做傳輸,不同於TDM是一個一個將使用者塞到slot裡面去做動作,FDM是一起將user丟到一個pool的感覺。 ![](https://i.imgur.com/rhiqyxQ.png) #### TDM(Time Division Multiplexing) TDM是將一個connection的duration切成frame,每個frame中在切出time slot,User開始傳遞資訊時便會被塞到time slot,也就是在一個固定的時間內切割頻寬,同時允許多個使用者傳遞資料,time slot越多,相對地速率也會趨緩。 ![](https://i.imgur.com/T0lrABv.png) ### Packet switching 封包(Packet)在節點間單獨路由,不需要在傳輸前先建立通訊路徑 packet switching不會保留頻寬,所有用戶共享頻寬,可以讓更多用戶使用網路,因為通常所有用戶要同時一起大量上下載流量的機率非常低。 只要有空位使用者便進來使用而且傳輸,今天若同時有十個人進到餐廳裡面,但有五個人還沒開始用餐的話,packet switching則會先把五個座位安排給可以馬上用餐的人,所以相對circuit switching來說,就不會有被佔住位置的問題。 **壞處** 如果封包突然過多超過可負載量,可能會造成封包遺失;或是同時多個用戶 上下載會有網路壅塞的問題,使用者上網品質可能無法受到良好的保證。 ## Performance: loss, delay, throughput ### Packet delay: four sources ![](https://i.imgur.com/Gravnbn.png) #### nodal processing 路由器處理封包表頭(packet header)、檢查位元資料錯誤與尋找配送路徑等所花費的時間。 #### queueing delay 路由器因為某些因素無法立刻將封包傳送到網路上,造成封包暫存在佇列(queue)中等待的時間。 #### transmission delay 網路卡將資料傳送到網路線上(或從網路線上接收)所花的時間,與網路設備的傳送速度有關(如高速乙太網路傳送速度為 100Mbps)。假設頻寬為 L(bits),數據傳輸速率為 R(bits/sec),這樣產生的 transmission delay 就是 L/R。 #### propagation delay 封包在網路線上傳輸所花費的時間,與網路線上電子訊號跑的速度有關,這個時間就是距離除以訊號傳送速度所得到的數值。假設傳送距離為 d ,傳輸的速率為 s ,那麼 propagation delay 就是 d/s。 ### Throughput(吞吐量) 是指系統可以在指定的時間內處理的單元的數量。像是 internet 之類的通訊網路的環境中,吞吐量是訊息成功傳遞的速率。 - 網路吞吐量通常表示為平均值,以每秒位數(bps)為單位,或者在某些情況下以每秒 data packets 為單位。 - 吞吐量表示從網路上的一個點到另一個點的成功數據包傳送的級別。 ## Security ### Denial of Service (DoS) 亦稱洪水攻擊,是一種網路攻擊手法,其目的在於使目標電腦的網路或系統資源耗盡,使服務暫時中斷或停止,導致其正常使用者無法存取。 ### packet sniffing(封包監聽) Sniffing簡單來說,就是基本「資料攔截」技術,它的目的是要擷取密碼(電子郵件、Web網頁、SMB、檔案傳輸、ftp、SQL與telnet等)、或是網路傳遞資料的內容,甚至是檔案本身。 ### IP spoofing send packet with false source address ## Protocol layers, service models ![](https://i.imgur.com/z0QrGkg.png) --- ## CH2 ## Application Layer ### Peer-peer architecture 對等式網路(英語:peer-to-peer, 簡稱P2P),又稱對等技術,是無中心伺服器、依靠使用者群(peers)交換資訊的網際網路體系,它的作用在於,減低以往網路傳輸中的節點,以降低資料遺失的風險。與有中心伺服器的中央網路系統不同,對等網路的每個使用者端既是一個節點,也有伺服器的功能,任何一個節點無法直接找到其他節點,必須依靠其戶群進行資訊交流。 ### Sockets 網路上的 Socket 也如同電話的插座一樣,任何一個 Socket 都給予一個特殊號碼(IP number + TCP port),使用者之間只要記住對方的 Socket 號碼,便可以直接通訊,而不用考慮到底是經過何種網路、或主機放在什麼地方,這些尋找主機的工作是網路提供者所必須負責的。 **Socket 就是一個網路上的通訊端點,使用者或應用程式只要連接到 Socket 便可以和網路上任何一個通訊端點連線,Socket 之間通訊就如同作業系統內程序(Process)之間通訊一樣。** ### TCP service 傳輸控制協定 是一種連接導向的、可靠的、基於位元組流的傳輸層通信協定 ### UDP service 使用者資料包協定 由於UDP缺乏可靠性且屬於無連接協定,所以應用程式通常必須容許一些遺失、錯誤或重複的封包。 * unreliable data transfer 不保證一定完成傳輸,因為缺少一些機制 * does not provide 頻寬、時間無法保證 ### Securing TCP * Transport Layer Security (TLS) 傳輸層安全性協定 --- ## Web and HTTP ### HTTP(hypertext transfer protocol)超文本傳輸協定 是一種用於分佈式、協作式和超媒體訊息系統的應用層協定 * client initiates TCP connection (creates socket) to server, port 80 通常使用TCP協定,客戶端發起一個HTTP請求到伺服器上指定埠(預設埠為80) * HTTP is “stateless” server maintains no information about past client requests 不會記得過去的狀態 ### Persistent HTTP 較有效率 #### Nonpersistent HTTP - 當每傳送一個物件,TCP connection就必須做一次,假設client跟server要求多個檔案,當第一個檔案傳輸後 會關閉連線,要下載第二個檔案的時候 必須再對server做一次要求(要求->回應->接收 整個步驟都會重新做) - 這種模式主要為HTTP1.0使用 #### Persistent HTTP - 接收多個物件時,client只需要向server建立一次連線即可,較省時。 - 主要為HTTP1.1使用。 ### Other HTTP request messages #### HEAD method 與 GET 方法相同,但 Server 只傳輸狀態行以及表頭部分。 HEAD 與 GET 方法相同,但 Server 不得於回應中,傳輸訊息主體 (message body)。 該方法可被用在不傳送表示的實際資料的情況下, 獲得關於所選擇的表示 (representation) 的元資料 (metadata) #### PUT method PUT 比較正確的定義是 Replace (Create or Update),例如PUT /items/1的意思是替換/items/1,如果已經存在就替換,沒有就新增。 #### POST method 將要處理的資料提交給指定的資源,類似於更新操作。 較POST安全,實際上傳遞的參數皆可以在封包(Request-line和 Message-body)上看到。 ### HTTP response status codes - 200 OK 請求成功 - 301 Moved Permanently 可以簡單地理解為該資源已經被永久改變了位置,通常會傳送HTTP Location來重新導向到正確的新位置。 - 400 Bad Request 此回應意味伺服器因為收到無效語法,而無法理解請求。 - 404 Not Found 用戶端錯誤回應碼,表明了伺服器找不到請求的資源。 - 505 HTTP Version Not Supported 請求使用的 HTTP 版本不被伺服器支援。 ### Cookies 很多網站在你瀏覽網頁之後,會在你的電腦系統中留下一些小小的檔案,也就是所謂的 Cookie。當你再去瀏覽這些網站時,系統便會去讀取這些 Cookie 再更新儲存一遍。 ### Web caches(proxy servers) Web快取(或HTTP快取)是用於臨時儲存(快取)Web文件(如HTML頁面和圖像),以減少伺服器延遲的一種資訊科技。Web快取系統會儲存下通過這套系統的文件的副本;如果滿足某些條件,則可以由快取滿足後續請求。 - **proxy servers(代理伺服器)** 提高存取速度:通常代理伺服器都設定一個較大的緩衝區,當有外界的資訊通過時,同時也將其儲存到緩衝區中,當其他使用者再存取相同的資訊時, 則直接由緩衝區中取出資訊,傳給使用者,以提高存取速度。 ### HTTP/2 新增的效能改進不僅包括HTTP/1.1中已有的多路復用,修復隊頭阻塞問題,允許設定請求優先級,還包含了一個頭部壓縮演算法(HPACK)。此外, HTTP/2 採用了二進位而非明文來打包、傳輸 客戶端<——>伺服器 間的資料。 - 多路復用 多路複用通常表示在一個頻道上傳輸多路訊號或數據流的過程和技術。因為多路複用能夠將多個低速頻道整合到一個高速頻道進行傳輸,從而有效地利用了高速頻道。通過使用多路複用,通訊運營商可以避免維護多條線路,從而有效地節約運營成本。 - 隊頭阻塞: 它的原因是一列的第一個數據包(隊頭)受阻而導致整列數據包受阻。例如它有可能在緩存式輸入的交換機中出現,有可能因為傳輸順序錯亂而出現,亦有可能在HTTP流水線中有多個請求的情況下出現。 例如:是隻有單行道的高速公路。在這條路上發生一起車禍,可能會使整個通道堵塞很長一段時間。因此,即使是在頭部(head)一個單一的問題可以阻塞(block)整條線(line)。 ![HTTP1.1](https://i.imgur.com/HO5WOaj.png) ![HTTP/2](https://i.imgur.com/9Sg85Tb.png) 有別於HTTP/1.1在連接中的明文請求,HTTP/2與SPDY一樣,將一個TCP連接分為若干個流(Stream),每個流中可以傳輸若干訊息(Message),每個訊息由若干最小的二進位影格(Frame)組成。這也是HTTP/1.1與HTTP/2最大的區別所在。 ### HTTP/3 在HTTP/3中,將棄用TCP協定,改為使用基於UDP協定的QUIC協定實現 ## E-mail, SMTP, IMAP ![](https://i.imgur.com/Q58yKKg.png) ### Email Three major components - user agents - mail servers - simple mail transfer protocol: SMTP (簡單郵件傳輸協定) ### E-mail: mail servers - **mailbox contains** incoming messages for user - **message queue** of outgoing (to be sent) mail messages - **SMTP protocol** between mail servers to send email messages ### E-mail: the RFC(5321) - uses TCP to reliably transfer email message from client (mail server initiating connection) to server, port 25 使用port25進行傳輸 - **direct transfer** sending server (acting like client) to receiving server直接傳送 - command/response interaction (like HTTP) commands: ASCII text response: status code and phrase - messages must be in 7-bit ASCII ![email傳輸](https://i.imgur.com/Zo8ecyi.png) ## The Domain Name System DNS ### DNS: Domain Name System 網域名稱系統 - **域名解析** DNS是網際網路上作為域名和IP地址相互對映的一個分散式資料庫。 DNS能夠使使用者更方便的訪問網路和應用,而不用去記憶雜亂、繁瑣的IP數串。 通過域名,最終得到該域名對應的IP地址的過程叫做域名解析。 - 舉一個例子,zh.wikipedia.org作為一個域名就和IP位址198.35.26.96 相對應。DNS就像是一個自動的電話號碼簿,我們可以直接撥打198.35.26.96 的名字zh.wikipedia.org來代替電話號碼(IP位址)。 DNS在我們直接呼叫網站的名字以後就會將像zh.wikipedia.org一樣便於人類使用的名字轉化成像198.35.26.96 一樣便於機器辨識的IP位址。 - **distributed database** DNS通過允許一個名稱伺服器把它的一部分名稱服務(眾所周知的zone)「委託」給子伺服器而實現了一種階層的名稱空間。任何一個使用IP的電腦網路可以使用DNS來實現它自己的私有名稱系統。 ### DNS架構 ![](https://i.imgur.com/StRj3jO.png) ### TLD: authoritative servers #### Top-Level Domain (TLD) servers頂級域 - 通用頂級域:是指由 ICANN 旗下的網際網路號碼管理局 (IANA) 直接管理的頂級域e.g. .com .edu .gov .net .org - 國家頂級域:以國家名稱做為頂級域名,常見.tw就是其中一種 - 地區頂級域:以地理位置或地緣關係做為頂級域名,目前有 .london .paris .africa 等。 - 新通用頂級域:由於網路上的內容越來越多元,原本的通用頂級域已經沒辦法辨識網站內容或內容來源的責任,因此 ICANN 開放更多的頂級域名來完善。 #### Authoritative DNS servers 最接近我們的DNS server,通常一個企業可以自己組一台DNS server保存紀錄,或者付錢給特定企業儲存,通常公司都會擁有自己的主要以及備分的DNS server ### DNS Caching DNS 快取(DNS cache) 是儲存近期瀏覽、連接過的網站伺服器的 IP 位址用的一個快取系統。有時候儲存的內容可能為錯誤或是過時資訊,所以透過清除快取來更新資訊以改善與伺服器間的連線。 ### DNS records - type=A RFC 1035定義,A記錄是用於名稱解析的重要記錄,它將特定的主機名對映到對應主機的IP位址上。 - type=NS 用來指定該域名由哪個DNS伺服器來進行解析。 您註冊域名時,總有預設的DNS伺服器,每個註冊的域名都是由一個DNS域名伺服器來進行解析的,DNS伺服器NS記錄位址一般以以下的形式出現:ns1.domain.com、ns2.domain.com等。 簡單的說,NS記錄是指定由哪個DNS伺服器解析你的域名。 - type=CNAME RFC 1035定義,CNAME記錄用於將某個別名指向到某個A記錄上,這樣就不需要再為某個新名字另外建立一條新的A記錄。 - type=MX MX,郵件交換記錄,凡是收發internet信件的主機,都需要設定MX紀錄,才可以正常地收發internet信件。 ## P2P applications ### File distribution time ![](https://i.imgur.com/z5B6XXs.png) ![](https://i.imgur.com/Hfh2v2V.png) ### P2P file distribution: BitTorrent - Tracker:收集下載者資訊的伺服器,並將此資訊提供給其他下載者,使下載者們相互連接起來,傳輸資料。 - 種子:指一個下載任務中所有檔案都被某下載者完整的下載,此時下載者成為一個種子。發布者本身發布的檔案就是原始種子。 - torrent:種子文件 - peer:可供連結的用戶數 - 做種:發布者提供下載任務的全部內容的行為;下載者下載完成後繼續提供給他人下載的行為。 ![](https://i.imgur.com/Jzpj1m9.png) ## video streaming and content distribution networks ### Content distribution networks (CDNs) ![](https://i.imgur.com/cmZqDDb.png) ## socket programming with UDP and TCP ### Client/server socket interaction: UDP 建立在 UDP 協定上的『電報傳輸』(Datagram)模式 ![](https://i.imgur.com/GwCS5o4.png) ### Client/server socket interaction: TCP 『虛擬電路』(Virtual Circuit)模式表示通訊雙方傳輸資料之前,必須先建立通訊鏈路,因此所採用的傳輸層為連接導向的 TCP 協定。 ![](https://i.imgur.com/hrENYx9.png) --- ## CH3 ## Connectionless demultiplexing ### UDP socket 以兩組資料識別 - dest IP address - dest port number #### TCP socket 以四組資料加以識別 - source IP address 來源端 IP 位址 - source port number 來源端埠號 - dest IP address 目的端 IP 位址 - dest port number 目的端埠號 ## Connectionless transport: UDP ### UDP: User Datagram Protocol(RFC 768) - 由於UDP缺乏可靠性且屬於無連接協定,所以應用程式通常必須容許一些遺失、錯誤或重複的封包。 - UDP 不需要唯一識別碼和序號就能完成相同的工作。這種協定以串流方式傳送資料,發送端不會等待接收端的確認信號,會繼續不斷發送封包資料。(connectionless) - 每一個 UDP 資料分段的處理和其它資料分段是獨立的 - 可能發生:不按順序傳送給應用程式、遺失 #### 為何還需要UDP? 1. small header size 2. no congestion control(無壅塞控制,UDP 可以盡可能地快速傳送資料) 3. 在傳送端和接收端不需維持連線狀態 4. 不需建立連線 (會增加延遲) #### UDP用於 - streaming multimedia apps loss tolerant可以容忍遺失,rate sensitive易受速率影響 - DNS - SNMP簡單網路管理協定 - HTTP/3 ![](https://i.imgur.com/z3eflwX.png) - 來源埠口(Source Port):發送端之傳輸埠口。 - 目的埠口(Destination Port):接收端之傳輸埠口。 - 長度(Length):該封包所承載資料(Data)的長度。 - 檢查集(Checksum):該封包之錯誤檢查的檢查集。 ### UDP checksum **目標: 偵測傳送的資料分段中的「錯誤」(例如:被翻轉的位元)** #### Sender: - 將資料分段的內容視為一列16位元的整數 - segment contents檢查和:資料分段內容的加法 (1的補數和) - field傳送端將檢查和的值放入UDP的檢查和欄位 #### Receiver: - 計算收到的資料分段的檢查和 - 確認計算出來的檢查和是否和檢查和欄位中的相等 ## Principles of reliable data transfer ### rdt1.0 ![](https://i.imgur.com/utUuV7Q.png) ### rdt2.0 ![](https://i.imgur.com/IM1gRQE.png) ### rdt2.1 #### 為了解決ACK 或 NAK 存在 corruption ![](https://i.imgur.com/9kFnOok.png) ### rdt2.2 ![](https://i.imgur.com/73ns46L.png) ### rdt3.0 ![](https://i.imgur.com/QohjYyb.png) ![](https://i.imgur.com/FwQcUuz.png) ![](https://i.imgur.com/fkvljMH.png) ![](https://i.imgur.com/oKYiPCP.png) ![](https://i.imgur.com/cD8p4ar.png) ### rdt3.0: pipelined protocols operation #### Pipelining 傳送端允許多個、 “飛行中的”、 還沒有被確認的封包 - 序號的範圍必須增加 - 傳送端 和/或 接收端需要暫存器 ![](https://i.imgur.com/IuHMfBg.png) ### Go-Back-N: sender ![](https://i.imgur.com/SI01IqY.png) 大小最多為N的“視窗” 、允許連續的未被確認的封包 - ACK(n): 確認小於或等於序號 n 的所有封包 - “累積式確認” 可能會收到重複的確認 (見接收端) - 某個傳送中的封包都使用一個計時器 - timeout(n):重傳封包 n 以及在視窗中序號高於 n 的全部封包 #### 只使用ACK: 只為接收順序正確的封包傳送 ACK - 可能會產生重複的ACK - 只需要記住 expectedseqnum #### 順序不正確的封包 - 刪除 (不會暫存) -> 接收端沒有暫存器 - 重新回應最高的順序正確封包 ![](https://i.imgur.com/sMaKaQT.png) ![](https://i.imgur.com/WUQagOt.png) ### Selective repeat: sender and receiver ![](https://i.imgur.com/OtLNqcu.png) ![](https://i.imgur.com/pdoebAH.png) ![](https://i.imgur.com/ZeFwJLu.png) ### Selective repeat: dilemma(困境) #### example:0 1 2 3 0 1 2 3 - 接收端無法分辨兩種情況的差別 - 不正確地重新傳送重複的資料 ![](https://i.imgur.com/rkrRD45.png) ![](https://i.imgur.com/uobD5dL.png) ![](https://i.imgur.com/9HLkzD6.png) ![](https://i.imgur.com/9NPD1YP.png) ## Connection-oriented transport: TCP - **Point-to-point:點對點,一個傳送端、 一個接收端** - **可靠的、 有順序的位元組串流** 沒有 “訊息界線” - **Pipelined:管線化** TCP壅塞控制和流量控制設定視窗大小 - **Send & receive buffers傳送端和接收端暫存器** - **Full duplex data:全雙工資料傳輸** 同一個連結中、雙向的資料流 MSS: maximum segment size最大資料分段大小 - **Connection-oriented:連線導向** Handshaking(控制訊息的交換) 在資料開始交換之前、設定傳送端和接收端的狀態 - **Flow controlled:流量控制** 傳送端不會超過接收端 ### TCP sequence numbers, ACKs #### Sequence numbers * 資料分段中、第一個位元的位元組串流 “編號” #### Acknowledgements * 另一端期待的下一個位元組序號 * 累積式確認 #### 接收端如何處理順序不正確的資料分段? TCP 規格中未限制、取決於程式開發者 ![](https://i.imgur.com/wBORq6U.png) ### TCP: retransmission scenarios ![](https://i.imgur.com/VgVZAuu.png) ![](https://i.imgur.com/7YBHcZ7.png) ![](https://i.imgur.com/yZzHg4j.png) ### TCP:Flow control ![](https://i.imgur.com/d8mKih7.png) 傳送端不會傳送太多太快的資料超過接收端的緩衝區 - TCP連線的接收端有一個接收緩衝區,應用程式的行程也許會以較慢的速度從緩衝區讀取資料 - 速度調整服務: 調整傳送端的速度與接收端應用程式能負擔的速度相符 ### Flow control work **TCP 的 發送視窗大小,主要由 接收端 來維護, 每次回報確認時,皆會告知傳送端 接收視窗 (rwnd) 大小。** - 接收端將RcvWindow值包含在資料分段裡、以告知剩餘的空間 - 傳送端限制未確認的資料在 RcvWindow之下 保證接收端緩衝區不會溢出 - 緩衝區內的剩餘空間= RcvWindow= RcvBuffer-[LastByteRcvd -LastByteRead] [第三章中文投影片](https://www.csie.ntu.edu.tw/~b95105/CN/project3/CN_ch03.pdf) **第一次期中考範圍結束** --- ### TCP 3-way handshake ![](https://i.imgur.com/5ghTWif.png) #### 步驟一:用戶端主機傳送 TCP SYN 資料分段到伺服器 - 指定初始的序號 - 沒有資料 #### 步驟二:伺服端主機收到SYN、以SYNACK資料分段回應 - 伺服端配置緩衝區 - 指定伺服端的初始序號 #### 步驟三:用戶端收到SYNACK、回應 ACK 資料分段、可能含有資料 ### Closing a TCP connection #### 用戶端及伺服器要關閉自己的連線 - send TCP segment with FIN bit = 1 #### 使用ACK回應接收到FIN - on receiving FIN, ACK can be combined with own FIN #### 可以同時進行FIN交換 ## Principles of congestion control ### Congestion 太多的來源端傳送太多的資料、對網路來說太快、超過能處理的速度 #### 表現形式 - 封包遺失 (路由器緩衝區溢出) - 長的延遲 (在路由器緩衝區佇列中等待) ### Causes/costs of congestion: scenario 1 ![](https://i.imgur.com/E3jlPdV.png) 條件 ![](https://i.imgur.com/kdIrFhJ.png) ### Causes/costs of congestion: scenario 2 ![](https://i.imgur.com/4heXnXO.png) 條件 ![](https://i.imgur.com/GS40Hqp.png) ##### cost of congestion - 對給定實際產量(goodput),因為重新傳輸導致工作變多 - 不必要的重新傳輸:連接攜帶多餘的封包副本 - 導致throughput的最高可達成數下降 ### Causes/costs of congestion: scenario 3 ![](https://i.imgur.com/o6krvgT.png) 條件 #### another cost of congestion - 當封包被丟掉時、此封包所使用到的任何upstream傳送容量就被浪費掉了 ### Causes/costs of congestion: insights ![](https://i.imgur.com/upJBiGp.png) ### Approaches towards congestion control #### 端點對端點的壅塞控制 - 網路層並沒有提供明顯的協助 - 根據中端系統觀察到的遺失及延遲來判斷壅塞 - 藉由TCP控制 #### 網路協助的壅塞控制 - 路由器通過擁塞的路由器向流發送/接收主機提供直接反饋 - TCP ECN, ATM, DECbit protocols - 可指示擁塞級別或明確設置的發送速率 ## TCP congestion control ### TCP congestion control: AIMD **AIMD(Additive Increase Multiplicative Decrease)** Additive increase累積遞增:每個 RTT將 CongWin加1、直到發生遺失 Multiplicative decrease倍數遞減:在發生遺失之後、將 CongWin 減為一半 #### Approach: senders can increase sending rate until packet loss (congestion) occurs, then decrease sending rate on loss event 懶得翻譯ㄌ ![](https://i.imgur.com/Wq6nAX0.png) 綠箭頭為:Additive Increase 紅箭頭為:Multiplicative Decrease ### TCP slow start 當連線開始,以指數型增加速率直到第一次遺失事件發生 - 初始cwnd=1MSS - 每個RTT都加倍cwnd - 通過為每個收到的ACK遞增cwnd來完成 **總結:初始速率很慢,但呈指數級增長** ![](https://i.imgur.com/7rIyuU8.png) ### 慢啟動門檻 (Slow Start Threshold, ssthresh) 慢啟動 不能無止盡的增加壅塞視窗 (cwnd) 大小,否則失去了壅塞「控制」的意義。 慢啟動門檻 (ssthresh),為 TCP 另一狀態變數。 當 cwnd 到達此門檻,或觀察到壅塞時,即停止指數成長的慢啟動,進入線性成長的壅塞避免。 在遺失事件發生時、 ssthresh會被設為遺失事件發生之前的cwnd的1/2。 ![](https://i.imgur.com/w9pEig6.png) ![](https://i.imgur.com/tZjN6Q1.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
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    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