nyovelt
    • 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
    • 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 Versions and GitHub Sync Note Insights 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # ST-CS120: Computer Network [![hackmd-github-sync-badge](https://hackmd.io/WKGXaV_ZSsSa5E43PDg9lQ/badge)](https://hackmd.io/WKGXaV_ZSsSa5E43PDg9lQ) ## OSI Model - https://www.forcepoint.com/zh-hans/cyber-edu/osi-model - ![osi](https://oss.aaaab3n.moe/uPic/s2djpM.png) ## Performance - Metrics (性能与指标) - Bandwidth (Throughput) - Unit: bps, kbps, Mbps, Gbps, where `b` stands for `bits` - Latency - RTT: Round-Trip Time: calc the time of send and recieve. Local because of the avoidance of time shift between devices. - 计算往返的时间,也就是本地从发出到收到的时间差。对应的,单程 (One-way Latency) = T2 - T1 or T3 -T2 - Latency = Transmit Delay + Propagation Delay + Queueing Delay - Transmit Delay = TransferSize/Bandwidth - Propagation Delay = Distance/SpeedofSignal - ![latency](https://oss.aaaab3n.moe/uPic/b7eGSs.png) - Effective Bandwidth (throyghput) = TransferSize/Latency - tools: iperf, ping (https://networktools.he.net/)(https://ping.sx) ## L1: Physical Layer 网线一类的东西 - 介质 - 需要调制与解调(以通过物理介质传输) ### Upper bound of throughout #### Shannon-Hartley Theorem The theoretical throughput upper bound: ![tkSs2p](https://oss.aaaab3n.moe/uPic/tkSs2p.png) ### Transmission Method #### Baseband Transmission (Line Coding) - 无载波 - 串行 #### Passband Modulation - 载波 - 并行 - $A \cdot \sin (2 \pi f t+\phi)$ - Amplitude - Frequency - Phase #### Frequency Shift Keying (FSK) ![QoPBcS](https://oss.aaaab3n.moe/uPic/QoPBcS.png) #### Phase Shift Keying (PSK) ![SAC4UP](https://oss.aaaab3n.moe/uPic/SAC4UP.png) #### Frequencty shift passing - 高频部分解码归零 - 低频部分保留 #### Amplitude shift passing - $A\cos(2\pi ft)\cos(2\pi ft)= \frac12A(cos(2 \pi ft)+1)$ - 乘以载波解码 - 信号不稳定时效果较差 #### Quadrature Amplitude Modulation - ASK + PSK - 传输更多的信息 (4 symbols) ![yBiS9I](https://oss.aaaab3n.moe/uPic/yBiS9I.png) 总结: Baseband * coherence wave = Passband ### 纠错与恢复 > analog goes wrong - Bit error rate (BER) = error bits/transmitted bits - High rate <-> Low reliability #### 2D Parity Check 是不是有偶数个 0 ![oIXqlp](https://oss.aaaab3n.moe/uPic/oIXqlp.png) - overhead $\frac 18$ - 1,2,3 bit wrong OK to recover - 4 bit may ERROR #### Check sum - TCP/IP header - sum all, check sum - 作为补码加起来 - 快但低能 #### CRC Performance 多项式 https://users.ece.cmu.edu/~koopman/crc/ #### 汉明码 #### 多路复用 - 分时复用 - 分频复用 Frequency-division multiplexing (FDM) - ![CKfjOU](https://oss.aaaab3n.moe/uPic/CKfjOU.png) - 分码复用 - 传输介质无法承载我们的传输 #### Rate Selection ![ZcRuco](https://oss.aaaab3n.moe/uPic/ZcRuco.png) ### ACK 🐱:喵 \ 😺:喵 \ 🐱:喵喵 \ 😺:喵喵 #### Stop and Wait http://www2.rad.com/networks/2004/sliding_window 规定时间内收不到就等,效率不高(利用 buffer 解决) https://en.wikipedia.org/wiki/Bandwidth-delay_product https://github.com/shadowsocks/shadowsocks/wiki/Optimizing-Shadowsocks #### NACK (Negative ACK) 接收方定时把所有未收到的包序号通过反馈报文通知到发送方进行重传。 #### Sliding Window - 不对等的传输 - Send buffer size: Delay $\cdot$ Bandwidth - Receive buffer size: Flow control - 拥塞控制: 控制 buffer 大小 ### 并行 #### Random Access *Transmit and Pray* #### Slotted ALOHA - For each slot, the probability of successful transmission is $\operatorname{Np}(1-\mathrm{p})^{\wedge}(\mathrm{N}-1)$ - $\mathrm{p}$ is the probability of transmission. It is determined by the number of nodes $N$ in the network, when $N$ is large, $p$ should be small. - The optimal p can be calculated by derivation - $f(p)=N p(1-p)^{\wedge}(N-1)$ - $f^{\prime}(p)=N(1-p)^{\wedge}(N-1)-N p(N-1)(1-p)^{\wedge}(N-2)$ - Thus the optimal $\mathrm{p}$ is $1 / \mathrm{N}$ - So when $p=1 / N$, the probability of successful transmission is $(1-1 / N)^{\wedge}(N-1)$, when $N$ is large, it is close to $1 / e$. Thus the utilization of the channel is about $30 \%$ - Efficiency: 1/e ## L2: 链路层,介质访问子层 ### Main function - 连接协议 (e.g. Hola) ### Ethernet ```bash ip addr show ``` ![891Kme](https://oss.aaaab3n.moe/uPic/891Kme.png) ### WIFI and Cecullar https://blog.csdn.net/qq_27847237/article/details/104098817 - 半双工 - 不对称 #### RTS/CTS 通过监听其它 client 之间的通讯来推测 server 与它的连接情况 - RTS/CTS does not solve hidden terminal and exposed terminal completely - Designing Wireless MAC is non-trivial - overhead too large #### IEEE 802.11 MAC ![](https://i.imgur.com/lALxS28.png) WIFI 包经过再打包走 Ethernet - 3-Addr: A -> AP -> C - 4-Addr: A -> B -> C -> D (mesh) See https://github.com/SpacehuhnTech/esp8266_deauther for a security issue for WIFI ### Switch #### learning Bridge - Switching method - Datagram / Connectionless - 转发表:记录下来这条链路上的所有主机和对应走哪个端口 - No Guarantee for - Success delivery - Performance - Delay, Throughput - Packet Order - 打电话给 ISP - ![MJ2x1D](https://oss.aaaab3n.moe/uPic/MJ2x1D.png) - Vitual Circuit/Connection - Procedure - 预留资源 (入口与 index) - 当链路上的所有 switch 都有足够的资源,destination 会发回一个 ack, 然后链路就建立起来了 - Source Routing - 带路由信息 - Learning Switch - 知道 A 从哪来 (port 1) - 广播 (X 收到包) - 其它节点也知道 A 在哪了 - 同一个冲突域内 drop - Cycle: - 成因: 错误的网络管理、冗余 - 结果: Storm - 占用网络资源 - 重复包 - Distributed Spanning Tree Algorithm - Each switch is a vertex - Each connection is an edge - 最小生成树 - 计算 hof, speed, rtt 将形成环路的节点断掉 ## L3: 网络层 ### Internet Protocal 多协议之间的网络通信 - Addressing Scalability - Network Heterogeneity #### IP Addressing ![](https://i.imgur.com/7AghcwW.png) #### IP Forward - Each router maintains a forwarding table - if IP.network == Connected network - forward to the host (How? ARP: IP->MAC) - if IP.network != Connected network - forward to some router #### IP jisuanqi ipjisuanqi.com #### IP Packet ![6YPgjX](https://oss.aaaab3n.moe/uPic/6YPgjX.png) #### Dynamic Host Configuration Protocol (DHCP) 分配 IP 地址并记录 ![ZSDw3U](https://oss.aaaab3n.moe/uPic/ZSDw3U.png) #### Address Resolution Protocol (ARP) - ARP table: each IP node (host, router) on LAN has table IP/MAC address mappings for some LAN nodes - < IP address; MAC address; TTL> - 200.155.11.3; 58-23-D7-FA-20-B0 200.155.11.5; - 1A-2F-BB-76-09-AD 200.155.11.2; - 0C-C4-11-6F-E3-98 #### Fragmentation and Reassembly 包会分割成 MTU 的大小传输,之后再重组 (There is Offset-bits in IP packet) ![oEu1c8](https://oss.aaaab3n.moe/uPic/oEu1c8.png) ### Routing The basic problem of routing is to find the lowest-cost path between any two nodes ![](https://i.imgur.com/oVplJ2f.png) #### RIP - Bellman-Ford Equation - $d_{A \to C} = min \{A \to B + B \to C \}$ foreach $B$ in $A \to C$ 松弛操作 - 每个节点不断的估计和其它节点的最短距离,并不断收敛 - distance to neighbour is known - and its neighbour can tell (not specific) the distance to destination y - 当一个节点收到新的值的时候,通知周围节点更新 - 优点:收敛块 - 缺点:缺少弹性 - 断连无法更新或者更新出错或者很慢 - 数字会一直变大 - 优化 - 限制最大跳数 - 限制每次更新的数目 #### Dijastra #### OSPF #### BGP [bgp.he.net](bgp.he.net) - iBGP: peers - eBGP: transits #### IPV6 ![PkIRtV](https://oss.aaaab3n.moe/uPic/PkIRtV.png) #### NAT 随机端口映射到主机 #### Mobile ## L4: 传输层 ### UDP ![XPfP6l](https://oss.aaaab3n.moe/uPic/XPfP6l.png) ### TCP ![dkfvXe](https://oss.aaaab3n.moe/uPic/dkfvXe.png) ![xkf1Fx](https://oss.aaaab3n.moe/uPic/xkf1Fx.png) ![CzCfNd](https://oss.aaaab3n.moe/uPic/CzCfNd.png) ### TCP Congestion in Network #### Additive Increase/Multiplicative Decrease (AIMD) - Additive Increase - Increment = 1/cwnd - cwnd += Increment - Multiplicative Decrease - cwnd = cwnd /2 ####

    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