Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agrego cambios de configuración del tráfico en el workflow y el makefile #21

Merged
merged 4 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@ jobs:
#----------------------------------------------
- name: Run tests
run: |
./loss.sh up
source .venv/bin/activate
pytest tests
./loss.sh down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ FLAKE8=$(POETRY) run flake8
PYTEST=$(POETRY) run pytest
PACKAGE=src
TESTS=tests
LOSS=./loss.sh

install:
$(POETRY) install
Expand All @@ -20,4 +21,12 @@ lint: fmt
test:
$(PYTEST) ./${TESTS}

loss-up:
$(LOSS) up

loss-down:
$(LOSS) down

test-loss : loss-up test loss-down

all: lint test
65 changes: 65 additions & 0 deletions loss.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

usage() {
echo "Usage: loss [options] (up|down)"
echo " -d, --device"
echo " -l, --latency"
echo " -b, --bandwidth"
echo " -p, --packet-loss"
}

unknown() {
echo "Error: Unknown parameter: $1"
echo
usage $1
}

exe() {
echo $1
if ! $1; then
exit 1
fi
}


device=lo # interface
latency=100 # ms of latency
bandwidth=1000 # Kbps of bandwidth
packetloss=10 # percentage of packets to drop
up=0
down=0


while [[ "$#" -gt 0 ]]; do
case $1 in
-d|--device) device="$2"; shift ;;
-l|--latency) latency="$2" ; shift ;;
-b|--bandwidth) bandwidth="$2" ; shift ;;
-p|--packet-loss) packetloss="$2" ; shift ;;
up) up=1 ; shift ;;
down) down=1 ; shift ;;
*) unknown $1; exit 1 ;;
esac
shift
done


if [ $up == $down ]
then
usage
exit
fi


options="latency ${latency}ms rate ${bandwidth}kbit loss ${packetloss}"


if [ $up == 1 ]
then
exe "sudo tc qdisc add dev ${device} root netem ${options}"
exe "sudo tc qdisc show dev ${device}"
else
exe "sudo tc qdisc del dev ${device} root netem ${options}"
exe "sudo tc qdisc show dev ${device}"
fi

2 changes: 1 addition & 1 deletion tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ def test_download_medium():


def test_download_big():
assert download(10_000_000) == 0
assert download(2_000_000) == 0
2 changes: 1 addition & 1 deletion tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def test_upload_medium():


def test_upload_big():
assert upload(10_000_000) == 0
assert upload(2_000_000) == 0