Kallzor
    • 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
    # Laboration report #1 By Carl Pryssgård and Max Agnesund ## Introduction The purpose of this laboratory exercise was to introduce us students to the simulator software that the teacher provided us with. In order for us to get a proper introduction to the structure of the program we were tasked with implementing a lossy link to extend the simulation with network impairments such as packet loss, delay and jitter. The first objective was to understand and use the simulator aswell as how to properly add and extend the necessary code. The second task was to introduce delay and jitter on the lossy link aswell as packet loss meaning it should also drop packets based on a random probabilty. ## Method I will provide both the simulator program aswell as the code used in order perform this lab below: [Link to the used simulator software](https://ltu.instructure.com/courses/16918/files/2821567?module_item_id=276237) (Requires access to LTU canvas page D0021E) ### Naive link ``` Java import sim.Event; import sim.Link; import sim.Message; import sim.SimEnt; import java.util.ArrayList; import java.util.Random; public class LossyLinkNaive extends Link { private static final int JITTER_CONSTANT = 10; private int delay_ms; private int jitter; private double dropProbability; /** * @param delay_ms How long to wait in ms * @param jitter The timeunit for jitter * @param dropProbability The probability of dropping a packet (specify me soon) */ public LossyLinkNaive(int delay_ms, int jitter, double dropProbability) { this.delay_ms = delay_ms; this.jitter = jitter; this.dropProbability = dropProbability; } // Computes jitter in a naive way. private float getJitter() { if (jitter == 0) { return 0; } return new Random().nextFloat(jitter) * JITTER_CONSTANT; } @Override public void recv(SimEnt src, Event ev) { System.out.println("Received on the lossy link"); int total_delay = delay_ms; // the jitter component can be computed as a random value multiplied by some constant, // this is pretty naive and is why this is the naive lossy link. // add the jitter component to `total_delay` total_delay += getJitter(); // randomly drops the packet. boolean should_drop = dropProbability != 0 && new Random().nextDouble(1) <= dropProbability; if (should_drop) { System.out.println("----- DROPPING PACKET -----"); return; } // sleep `total_delay` seconds by // letting the simulator wait `total_delay` // before treating the event. _now = total_delay; super.recv(src, ev); } } ``` This code extends the `Link` class provided in the simulator. This makes a lot of sense since we are *extending* the already provided `Link` class to now be lossy. The delay component was implemented by using the simulator's event engine, which in turn has a builtin delay for events. By using this delay (`_now`) we can *delay* before the simulator will fire off the specific event. The jitter was then implented by randomly computing a value to add to the delay. Implementing the packet loss is trivial after this since there should just be a random number generated and compared against the provided `dropProbability`. ### Dynamic link Alongside this naive link we theorized and tried to implement a more dynamic link. This new, dynamic link would use a `cur_jitter` variable added to the total delay as with the naive link, the difference is that `cur_jitter` would be set to a specified value (instead of being random like in the naive implementation). The exact value of `cur_jitter` can be argued about but we figured a good middleground to start from would be the given desired jitter (`target_jitter`) divided by `2`. The goal for the dynamic link was for `cur_jitter` to randomly adjust untill it reached a value sufficient for the link to reach a all-time jitter of `target_jitter`. ## Result Our result is a lossy link implemented by extending the given simulator utilizing the builtin systems of said simulator. This lossy link introduces a random amount of jitter as well as delays and random packet drops. ## Discussion During the process of thinking of a proper solution to the task at hand there were multiple choices we could make on how we wanted to implement our ``LossyLink``. There was the naive option which had an easier implementation phase and required us to only understand how to use the different components of the software and how `delay`, `jitter` and `packet loss` worked. The other option was a more dynamic approach where we could calculate the variation of delay per a specific link in order to achieve the target jitter given at initialization time for the `LossyLink`. ### The naive implementation We implemented the naive solution to a start by simply generating a random value to add to our `delay`. However, this naive solution does not account for negative jitter (packets arriving earlier than the delay specified). We considered and reasoned that the delay given to the lossy link should *always* be respected, e.g it should be treated as the minimum possible delay. It could however easily be reasoned that jitter should override this respect due to the stochastic nature of jitter in real networks. This negative jitter could easily be implemented by weighting the random number generation differently. There is also the mathematical aspect to consider when we calculated the amount of `delay` that we might want to have added. When considering calculating the `d_TOT` for our program specifically we came to the conclusion that the most probable of the variables that makes `d_TOT` is `propagation delay`. ### The dynamic implementation The dynamic implementation was not successfull, this is most likely due to bad starting numbers being chosen alongside bad limits for the random numbers meant to push `cur_jitter` towards the `target_jitter`. The dynamic version seemed to reach the targeted jitter value for each *individual* packet but failed to realize the `target_jitter` for the entire link when looking at it's jitter over it's entire lifetime. A reason that this might not have worked was that we did not account for the fact that to reach `target_jitter` over the links lifetime `cur_jitter` needed to average out to something a bit below that due to the start value. The lifetime jitter of the dynamic link can be calculated by taking all the delays that the link has experienced and taking the mean difference between them. ### The type of delay produced in the simulation Since we are working in a closed system with only a simulator running and no noise has been introduced to the program during the time of execution so the signal the only probable execution delay that was not specifially programmed by us therefore is most probable `propagation delay`. To make our simulation account for each type of delay we could introduce more events into the simulator which delay at different points in the program.

    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