-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(docker): moved connectivity helpers for docker compose scena…
…rios to bash helper lib
- Loading branch information
Showing
2 changed files
with
47 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
DOCKERCMD=docker | ||
# use podman if available | ||
if command -v podman &> /dev/null; then | ||
DOCKERCMD=podman | ||
fi | ||
|
||
set_on_all_interfaces() { | ||
for n in $NODES; do | ||
IFACES=$($DOCKERCMD exec $n cat /proc/net/dev | awk '{print $1}' | grep -E '^eth[0-9]+' | cut -d ':' -f1) | ||
CMDS="" | ||
for i in $IFACES; do | ||
CMDS="$CMDS echo \"[$1] Setting loss on $n ($i) to $2\" && tc qdisc $1 dev $i root netem loss $2 && " | ||
done | ||
$DOCKERCMD exec $n bash -c "${CMDS} true" | ||
done | ||
} | ||
|
||
set_on_all_interfaces add 0% | ||
|
||
|
||
set_loss () { | ||
echo "Setting loss on $1 to $2" | ||
$DOCKERCMD exec $1 tc qdisc change dev eth0 root netem loss $2 | ||
} | ||
|
||
loss_interval() { | ||
IFACE=eth0 | ||
if [ -n "$4" ]; then | ||
IFACE=$4 | ||
fi | ||
echo "Setting loss on $1 ($IFACE) to $2 for $3s" | ||
$DOCKERCMD exec $1 tc qdisc change dev $IFACE root netem loss $2 | ||
sleep $3 | ||
$DOCKERCMD exec $1 tc qdisc change dev $IFACE root netem loss 0% | ||
} | ||
|
||
cleanup () { | ||
echo "Cleaning up..." | ||
set_on_all_interfaces del 0% | ||
} | ||
|
||
trap cleanup EXIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,12 @@ | ||
#!/bin/bash | ||
|
||
DOCKERCMD=docker | ||
# use podman if available | ||
if command -v podman &> /dev/null; then | ||
DOCKERCMD=podman | ||
fi | ||
$DOCKERCMD exec line-3n-n1-1 tc qdisc add dev eth0 root netem loss 0% | ||
$DOCKERCMD exec line-3n-n2-1 tc qdisc add dev eth0 root netem loss 0% | ||
$DOCKERCMD exec line-3n-n3-1 tc qdisc add dev eth0 root netem loss 0% | ||
NODES="line-3n-n1-1 line-3n-n2-1 line-3n-n3-1" | ||
|
||
cleanup () { | ||
echo "Cleaning up..." | ||
$DOCKERCMD exec line-3n-n1-1 tc qdisc del dev eth0 root netem loss 0% | ||
$DOCKERCMD exec line-3n-n2-1 tc qdisc del dev eth0 root netem loss 0% | ||
$DOCKERCMD exec line-3n-n3-1 tc qdisc del dev eth0 root netem loss 0% | ||
} | ||
|
||
trap cleanup EXIT | ||
# Remember: define list of NODES before loading the helper functions | ||
. $(dirname $0)/libnetemhelper.sh | ||
|
||
|
||
while true; do | ||
echo "Setting loss on n3 to 100% for 30s" | ||
$DOCKERCMD exec line-3n-n3-1 tc qdisc change dev eth0 root netem loss 100% | ||
sleep 30 | ||
echo " n3 back to 0% loss." | ||
$DOCKERCMD exec line-3n-n3-1 tc qdisc change dev eth0 root netem loss 0% | ||
echo "Setting loss on n1 to 100% for 30s" | ||
$DOCKERCMD exec line-3n-n1-1 tc qdisc change dev eth0 root netem loss 100% | ||
sleep 30 | ||
echo " n1 back to 0% loss." | ||
$DOCKERCMD exec line-3n-n1-1 tc qdisc change dev eth0 root netem loss 0% | ||
loss_interval line-3n-n1-1 100% 30 | ||
loss_interval line-3n-n3-1 100% 30 | ||
done |