Nemo
    • 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
    • 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

    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
    # 111-2專題研究筆記Week9-10 ## tcpdump 繼上次使用大量封包測試效能因為設備問題受阻後,這次想要研究該paper另一種測試方式:測試latency。較為理想的狀態為使用timestamp,這個之前有做過類似的,但測試結果較為受限。 詳見 https://hackmd.io/@nemoz/HJ4J3RNG5 。 由於是在Sender端傳出時就打上timestamp,所以會吃到Sender端network stack、連線的狀況及品質等,因此想在"Reciever NIC接收到封包後"第一時間打上timestamp,也就是將latency指代的data path從 ![](https://i.imgur.com/c5EayxI.jpg) 轉變為 ![](https://i.imgur.com/dluvkxS.jpg) 因此第一時間就想到正仁學長在課堂時分享的bcc專案:[BPF Compiler Collection](https://github.com/iovisor/bcc),對照上面的圖找到了可以監聽封包的最底層的工具:tcpdump,此工具可以讀取driver送上kernel的封包資訊及timestamp。 ![](https://i.imgur.com/20xae4d.png) 但結果是若開啟了XDP類型的firewall,tcpdump就收不到封包了,原因為下圖: ![](https://i.imgur.com/so6W9zT.jpg) tcpdump是運用libpcap,將function hook在nwetwork stack的中段,因此是比XDP程式還要更上層的,必須要能夠在XDP進行過濾前先行打上timestamp。 **為了要比XDP早取得封包的資料並標上timestamp,必須也使用XDP來標記timestamp。** ## XDPdump https://github.com/xdp-project/xdp-tools 此專案之前正仁學長也有用過,他分為兩個主要我們會用到的部分: - XDPfilter,主要是command line類型的簡單filter,能過濾指定的port、IP。 - XDPdump,可以tracing"進出"上述XDPfilter的封包以及相對應的timestamp,因此我們終於能夠在有一個latency with "包含XDP及IPtables"的datapath了。 我們先透過 ``` $ sudo ./xdp-filter load enp0s3 -f ipv4 -m skb ``` 將xdpfilter程式load進driver,並標明透過ipv4來過濾封包。 再透過 ``` $ sudo ./xdp-filter ip 192.168.69.9 -m src ``` 告訴xdpfilter我們所要濾掉來自192.168.69.9的所有封包。 接著我們開啟xdpdump程式。 ``` $ sudo ./xdpdump -i enp0s3 --rx-capture entry ``` 透過--rx-capture來嗅出即將"進入"xdpfilter的封包資訊及timestamp。 這時候我們透過ip 192.168.69.9的機器來對其進行ping的動作: ![](https://i.imgur.com/dNo8yS0.png) 可以看到封包全部都被drop掉了,但我們觀察xdpdump的視窗: ![](https://i.imgur.com/Ri6ooYL.png) 可以看到xdpdump仍然有秀出封包,證明這條datapath是開始於xdpfilter之前的,因此我們可以開始進行latency的實驗了,以下為實驗的拓樸: ![](https://i.imgur.com/99hNp1K.jpg) 整個datapath除了最底層開始打上timestamp的xdpdump,userspace也撰寫了接收封包並秀出最終timestamp的udp socket program,sender一樣使用ostinato產生udp封包。 先測試在什麼rule都不加的情況下,此條datapath的基準latency。 | XDP timestamp | Userspace timestamp| Latency | | :-----:| :----: | :----: | | 1650830369.503261649 | 1650830369.6520882 | 149ms | | 1650830374.659241607 | 1650830374.8080854 | 149ms | | 1650830380.769574781 | 1650830380.918455 | 149ms | | 1650830384.386681104 | 1650830384.5355697 | 149ms | | 1650830387.134427942 | 1650830387.2833288 | 148.9ms | 因此基準值約為149ms。 ## Testing with iptables、XDPfilter 接著我們安裝iptables,為其插入32個無用rule進行測試: | XDP timestamp | Userspace timestamp| Latency | | :-----:| :----: | :----: | | 1650831160.560912882 | 1650831161.1921768 | 632ms | | 1650831164.396997172 | 1650831165.0282958 | 632ms | | 1650831167.654823612 | 1650831168.286106 | 632ms | | 1650831168.808675143 | 1650831169.4399452 | 631ms | | 1650831169.872805632 | 1650831170.5040414 | 632ms | 約為632ms,可見iptables對於效能的影響十分顯著。 接下來我們分別測試32、64...256、512個無用rule對效能的影響。 ![](https://i.imgur.com/rU1Qj1h.png) 可以看到,當rule數量上升對於latency的影響並不大。 再來我們測試xdpfilter對於latency的影響。先簡單開啟xdpfilter,將其load進driver,並加入一個簡單的ip rule。 | XDP timestamp | Userspace timestamp| Latency | | :-----:| :----: | :----: | | 1650832552.789719874 | 1650832552.9692104 | 180ms | | 1650832553.305622792 | 1650832553.4851184 | 179ms | | 1650832553.897888837 | 1650832554.0774055 | 179ms | | 1650832554.369722774 | 1650832554.5492766 | 180ms | | 1650832554.883567726 | 1650832555.0630856 | 179ms | latency約為179ms。接著試著同樣加入無用rule,測試xdpfilter的latency變化。 ![](https://i.imgur.com/NGuw5Rb.png) 這是最後測試的結果,可以看到在500個rule的級距下,xdpfilter在latency上與iptables相比有顯著的提升。

    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