-
Notifications
You must be signed in to change notification settings - Fork 9
/
netlink-events-l3.sh
executable file
·54 lines (43 loc) · 1.25 KB
/
netlink-events-l3.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
#
# Usage: $0 NUM_IF NUM_AD TIMEOUT
# NUM_IF: how many devices are used
# NUM_AD: how many addresses per device are used
# TIMEOUT: after how many seconds should the loop be breaked
# Clean up
cleanup () {
ip netns del ${NAME}ev
rm -f .tmp/${NAME}-events.pid
exit 0
}
if [ $# -eq 4 ]
then
NAME=$1
NUM_IF=$2
NUM_AD=$3
TIMEOUT=$4
else
cleanup
fi
# Set up
touch .tmp/${NAME}-events.pid || exit 1
echo $$ > .tmp/${NAME}-events.pid || exit 1
ip netns add ${NAME}ev
trap cleanup SIGTERM
for i in $(seq 0 $NUM_IF); do
echo "link add ${NAME}$i type veth peer NAME ${NAME}$i netns ${NAME}ev"
echo "link set ${NAME}$i up"
done | ip -b -
for i in $(seq 0 $NUM_IF); do
echo "link set ${NAME}$i up"
done | ip -n ${NAME}ev -b -
# Run loop
ADDR_ADD=$(for i in $(seq 0 $NUM_IF); do for j in $(seq 1 $NUM_AD); do echo "addr add dev ${NAME}$i 172.32.${i}.${j}/24"; done; done )
ADDR_DEL=$(for i in $(seq 0 $NUM_IF); do for j in $(seq 1 $NUM_AD); do echo "addr del dev ${NAME}$i 172.32.${i}.${j}/24"; done; done )
STARTTIME=$(date -u +%s)
ENDTIME=$(($STARTTIME + $TIMEOUT))
while [ $(date -u +%s) -le $ENDTIME ]; do
printf "$ADDR_ADD" | sort -R | ip -b -
printf "$ADDR_DEL" | sort -R | ip -b -
done
cleanup