Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cnp3/Linksimulator
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2016
Choose a base ref
...
head repository: cnp3/Linksimulator
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 18 commits
  • 2 files changed
  • 9 contributors

Commits on Oct 3, 2017

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5275c00 View commit details

Commits on Oct 4, 2017

  1. Merge pull request #7 from qdeconinck/project-2017

    updating proxy for academic year 2017-2018
    oliviertilmans authored Oct 4, 2017
    Copy the full SHA
    d82fa45 View commit details

Commits on Nov 4, 2017

  1. update several log outputs

    Maxmawt committed Nov 4, 2017
    Copy the full SHA
    a62990d View commit details

Commits on Nov 6, 2017

  1. Merge pull request #8 from Maxmawt/master

    update several log outputs
    oliviertilmans authored Nov 6, 2017
    Copy the full SHA
    d228e7f View commit details

Commits on Oct 18, 2018

  1. Copy the full SHA
    fe92a54 View commit details
  2. tabs instead of spaces

    cymarechal authored Oct 18, 2018
    Copy the full SHA
    b8396c6 View commit details

Commits on Oct 19, 2018

  1. Merge pull request #9 from cymarechal/master

    [fix] integer underflow when jitter > delay
    qdeconinck authored Oct 19, 2018
    Copy the full SHA
    ccf48ca View commit details

Commits on Oct 26, 2018

  1. [fix] types (#10)

    * [fix] memory leak
    
    - memory leak
    - types
    
    * revert useless free
    cymarechal authored and qdeconinck committed Oct 26, 2018
    Copy the full SHA
    8cd02a1 View commit details

Commits on Sep 17, 2019

  1. Copy the full SHA
    72e478f View commit details

Commits on Sep 25, 2019

  1. Merge pull request #11 from cnp3/project_2019

    update linksym for project 2019
    francoismichel authored Sep 25, 2019
    Copy the full SHA
    2f0fbfd View commit details

Commits on Sep 30, 2019

  1. Fixes SEQ logging

    mpiraux committed Sep 30, 2019
    Copy the full SHA
    f64ae7f View commit details
  2. Copy the full SHA
    f45c930 View commit details

Commits on Oct 21, 2019

  1. Copy the full SHA
    062891b View commit details

Commits on Oct 28, 2019

  1. Copy the full SHA
    aaef06e View commit details

Commits on Feb 9, 2021

  1. update for project 2021

    qdeconinck committed Feb 9, 2021
    Copy the full SHA
    3f725c2 View commit details

Commits on Feb 16, 2022

  1. Updates linksim for FEC

    mpiraux committed Feb 16, 2022
    Copy the full SHA
    7d530bc View commit details

Commits on Mar 22, 2022

  1. Copy the full SHA
    510b553 View commit details
  2. Merge pull request #12 from TheTarados/master

    Fixed a bug where packets would not be truncated if window size wasn't 0.
    mpiraux authored Mar 22, 2022
    Copy the full SHA
    75c1d1e View commit details
Showing with 47 additions and 18 deletions.
  1. +2 −2 README.md
  2. +45 −16 link_sim.c
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# LINGI1341-linksim
A link simulator for the first networking project (LINGI1341)

This program will proxy UDP traffic (datagrams of max 524 bytes), between
This program will proxy UDP traffic (datagrams of max 528 bytes), between
two hosts, simulating the behavior of a lossy link.

Using it is a simple as choosing two UDP ports, one for the proxy, and one for the receiver of the protocol.
@@ -21,6 +21,6 @@ Server machine:
You can control the direction (i.e. forward, reverse or both ways) of the
traffic which is affected by the program.

Use this to test your programs in the events of losses, delays, ...
Use this to test your programs in the events of losses, delays, truncation, ...

Feel free to hack it and submit pull request for bug fixes, ...
61 changes: 45 additions & 16 deletions link_sim.c
Original file line number Diff line number Diff line change
@@ -43,9 +43,17 @@ SOFTWARE.
#include "min_queue.h" /* minq_x */

/* Min packet length in the protocol */
#define MIN_PKT_LEN 12
/* Max packet length in the protocol */
#define MAX_PKT_LEN 524
#define MIN_PKT_LEN 10
/* Min packet length of a data packet in the protocol */
#define MIN_PKT_PDATA_LEN 12
/* Position of the length bit in the header */
#define LENGTH_FIELD_LENGTH_BIT_POS 8

/*
* Max packet length in the protocol (packet with max header size +
* max payload size + CRC2 size
*/
#define MAX_PKT_LEN (MIN_PKT_LEN + 2 + 512 + 4)
/* Random number between 0 and 100 */
#define RAND_PERCENT ((unsigned int)(rand() % 101))

@@ -69,6 +77,7 @@ int port = 1341;
unsigned int delay = 0;
unsigned int jitter = 0;
unsigned int err_rate = 0;
unsigned int cut_rate = 0;
unsigned int loss_rate = 0;
int link_direction = LINK_FORWARD;
int sfd = -1; /* socket file des. */
@@ -118,7 +127,7 @@ static void timeval_diff(const struct timeval *a,

/* Log an action on a processed packet */
#define LOG_PKT_FMT(buf, fmt, ...) \
printf("[SEQ %3u] " fmt, (uint8_t)buf[1], ##__VA_ARGS__)
fprintf(stderr,"[%s %3hhu] " fmt, ((uint8_t)buf[0] & 0xC0) == 0x00 ? "FEC" : "SEQ" , (((uint8_t)buf[0] & 0xC0) <= 0x40) ? buf[3] : buf[1], ##__VA_ARGS__)
#define LOG_PKT(buf, msg) LOG_PKT_FMT(buf, msg "\n")

/* Send a packet to the host we're proxying */
@@ -176,6 +185,13 @@ static inline int simulate_link(char *buf, int len, int direction)
if (loss_rate && RAND_PERCENT < loss_rate) {
LOG_PKT(buf, "Dropping packet");
return EXIT_SUCCESS;
}
/* Do we cut it after the header? (only if packet is elligible) */
if (cut_rate && RAND_PERCENT < cut_rate && len > MIN_PKT_PDATA_LEN && ((uint8_t) buf[0])>>6 == 1) {
LOG_PKT(buf, "Truncating packet");
len = MIN_PKT_PDATA_LEN;
/* ... and don't forget to mark it as truncated */
buf[0] |= 0x20;
/* or do we corrupt it? */
} else if (err_rate && RAND_PERCENT < err_rate) {
int idx = rand() % len;
@@ -185,11 +201,16 @@ static inline int simulate_link(char *buf, int len, int direction)
/* Do we want to simulate delay? */
if (delay) {
/* Random delay to add is capped to 10s */
unsigned int applied_delay = jitter ?
(RAND_PERCENT > 49 ?
delay + rand() % jitter :
delay - rand() % jitter) :
delay;
unsigned int applied_delay;
if (jitter) {
if (jitter > delay) {
applied_delay = rand() % (delay + jitter);
} else {
applied_delay = (delay + rand() % (2 * jitter)) - jitter;
}
} else {
applied_delay = delay;
}
applied_delay %= 10000;
LOG_PKT_FMT(buf, "Delayed packet by %u ms\n", applied_delay);
/* Create a slot for the packet queue */
@@ -242,8 +263,8 @@ static int process_incoming_pkt()
}
/* Check packet consistency */
if (len < MIN_PKT_LEN) {
printf("Received malformed data, dropping. "
"(len < %u)\n", MIN_PKT_LEN);
fprintf(stderr,"Received malformed data, dropping. "
"(len < %d)\n", MIN_PKT_LEN);
return EXIT_SUCCESS;
}
/* We need to track who is sending us data, so that we can send him the
@@ -465,7 +486,7 @@ static void usage(const char *prog_name)
"random losses, transmission errors, ...\n"
"\n"
"Usage: %s [-p port] [-P forward_port] [-d delay] [-j jitter]\n"
" %*s [-e err_rate] [-l loss_rate] [-s seed] [-h]\n"
" %*s [-e err_rate] [-c cut_rate] [-l loss_rate] [-s seed] [-h]\n"
"-p port The UDP port on which the link simulator operates.\n"
" Defaults to: 1341\n"
"-P forward_port The UDP port on localhost on which the incoming traffic\n"
@@ -481,6 +502,10 @@ static void usage(const char *prog_name)
"-e err_rate The rate of packet corruption occurrence (in packet/100).\n"
" Defaults to: 0\n"
" A packet that has been corrupted will NOT be cut.\n"
"-c cut_rate The rate of packet being cut after the header to simulate\n"
" router truncation due to high network load (in packet/100).\n"
" Defaults to: 0\n"
" A packet that has been cut will NOT be corrupted.\n"
"-l loss_rate The rate of packets loss (in packet/100).\n"
" Defaults to 0\n"
"-s seed The seed for the random generator, to replay a previous\n"
@@ -508,7 +533,7 @@ int main(int argc, char **argv)
int opt;
long seed = -1L;
/* parse option values */
while ((opt = getopt(argc, argv, "p:P:d:j:e:s:l:hrR")) != -1) {
while ((opt = getopt(argc, argv, "p:P:d:j:e:c:s:l:hrR")) != -1) {
switch (opt) {
case 'p':
port = parse_number(optarg) & ((1 << 16) - 1);
@@ -525,6 +550,9 @@ int main(int argc, char **argv)
case 'e':
err_rate = parse_number(optarg) % 101;
break;
case 'c':
cut_rate = parse_number(optarg) % 101;
break;
case 'l':
loss_rate = parse_number(optarg) % 101;
break;
@@ -557,15 +585,16 @@ int main(int argc, char **argv)
}
srand((int)seed);
fprintf(stderr, "@@ Using parameters:\n"
".. port: %u\n"
".. forward_port: %u\n"
".. port: %d\n"
".. forward_port: %d\n"
".. delay: %u\n"
".. jitter: %u\n"
".. err_rate: %u\n"
".. cut_rate: %u\n"
".. loss_rate: %u\n"
".. seed: %d\n"
".. link_direction: %s\n",
port, forward_port, delay, jitter, err_rate,
port, forward_port, delay, jitter, err_rate, cut_rate,
loss_rate, (int)seed, get_link_direction(link_direction));
/* Start proxying UDP traffic according to the specified options */
return proxy_traffic();