Created
January 22, 2024 01:39
-
-
Save Yossi1114/b510e8a605f7eccc1bccf207a13e8e84 to your computer and use it in GitHub Desktop.
Linux Traffic Control Conditional Experiment
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
#!/bin/bash | |
# Interface | |
IFACE="eno1" | |
# Function to safely delete existing tc settings | |
safe_tc_delete() { | |
tc qdisc del dev $IFACE root &> /dev/null || true | |
} | |
# Function to apply tc settings | |
apply_tc() { | |
local loss=$1 | |
local rate=$2 | |
# Clear existing tc settings | |
safe_tc_delete | |
# Apply packet loss | |
tc qdisc add dev $IFACE root handle 1: netem loss $loss | |
# Apply bandwidth limit | |
tc qdisc add dev $IFACE parent 1:1 handle 10: tbf rate $rate buffer 1600 limit 3000 | |
} | |
# Array of bandwidth limits | |
BANDWIDTHS=("5.5mbps" "20mbps" "100mbps" "200mbps") | |
# Loop 10 times | |
for i in {1..10}; do | |
# Apply each combination of packet loss and bandwidth | |
for loss in {10..100..10}; do | |
for rate in "${BANDWIDTHS[@]}"; do | |
echo "Applying $loss% packet loss and $rate bandwidth..." | |
apply_tc "${loss}%" $rate | |
sleep 30s | |
done | |
done | |
done | |
# Clear tc settings at the end | |
safe_tc_delete | |
echo "Simulation completed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment