Skip to content

Commit 7474d34

Browse files
committed
Add load tester script
1 parent 6cb7e59 commit 7474d34

File tree

5 files changed

+191
-0
lines changed

5 files changed

+191
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python2
2+
# -*- coding: utf -*-
3+
4+
5+
import socket
6+
import fcntl
7+
import struct
8+
9+
import uuid
10+
import sys
11+
12+
from httplib import HTTPConnection
13+
14+
PORT = "2060"
15+
16+
def main(targetIF, prefix, maxI):
17+
target = get_ip_address(targetIF)
18+
for i in xrange(int(maxI)):
19+
source = get_ip_address(prefix + str(i))
20+
# source_address requires python 2.7
21+
# urllib2 does not nicely expose source_address, so use
22+
# lower-level API
23+
conn = HTTPConnection(target, PORT, timeout=10, source_address=(source, 0))
24+
conn.connect()
25+
conn.request("GET", "/")
26+
try:
27+
resp = conn.getresponse()
28+
resp.read()
29+
except:
30+
pass
31+
conn = HTTPConnection(target, PORT, timeout=10, source_address=(source, 0))
32+
conn.connect()
33+
conn.request("GET", "/wifidog/auth?token=" + str(uuid.uuid4()))
34+
try:
35+
resp = conn.getresponse()
36+
# this causes wifidog to ask our mock auth server if the token is
37+
# correct
38+
resp.read()
39+
except:
40+
pass
41+
42+
43+
# http://code.activestate.com/recipes/439094-get-the-ip-address-associated-with-a-network-inter/
44+
def get_ip_address(ifname):
45+
print "ifname: %s" % ifname
46+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
47+
return socket.inet_ntoa(fcntl.ioctl(
48+
s.fileno(),
49+
0x8915, # SIOCGIFADDR
50+
struct.pack('256s', ifname[:15])
51+
)[20:24])
52+
53+
if __name__ == "__main__":
54+
while True:
55+
main(sys.argv[1], sys.argv[2], sys.argv[3])
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#/bin/bash
2+
3+
IF="eth0"
4+
# for whatever reason, if you use eth0.x as your virtual interface name,
5+
# dhclient will lose the carrier
6+
PREFIX="mac"
7+
# don't touch resolv.conf
8+
DHCP="dhcpcd --waitip -C resolv.conf"
9+
#DHCP="dhclient -v"
10+
11+
NET="10.0.10."
12+
13+
14+
function start() {
15+
echo "IP address HW type Flags HW address Mask Device" > /tmp/arp
16+
# Add internal address for GW
17+
sudo ip link add internal0 link $IF type macvlan mode bridge || exit 1
18+
sudo ip addr add ${NET}254 dev internal0
19+
sudo ip link set internal0 up || exit 2
20+
for i in `seq 0 9`; do
21+
echo "Add link $i"
22+
# sudo ip link add virtual0 link eth0 type macvlan mode bridge
23+
sudo ip link add ${PREFIX}${i} link $IF type macvlan mode bridge || exit 1
24+
echo "Assigning temporary IP address"
25+
# use link-local address. Ideally, we would check if the
26+
# address is already aissgned
27+
sudo ip addr add ${NET}$(($i + 1)) dev ${PREFIX}${i}
28+
MAC=`ip link show ${PREFIX}${i} | grep ether | sed -e 's,.*link/ether ,,' -e 's, brd.*,,'`
29+
echo "Marking link $i up"
30+
sudo ip link set ${PREFIX}${i} up || exit 2
31+
#echo "Acquiring IP for link $i"
32+
# when using DHCP, the interface would immediately
33+
# go down?
34+
#sudo $DHCP ${PREFIX}${i} || exit 3
35+
echo " ${NET}$(($i + 1)) 0x1 0x2 $MAC * ${PREFIX}${i}" >> /tmp/arp
36+
done
37+
}
38+
39+
function stop() {
40+
sudo ip link del internal0 2>/dev/null || true
41+
for i in `seq 0 9`; do
42+
echo "Deleting link $i"
43+
sudo ip link del ${PREFIX}${i} 2>/dev/null || true
44+
done
45+
}
46+
47+
48+
49+
if [[ x$1 == x"start" ]]; then
50+
stop
51+
start
52+
elif [[ x$1 == x"stop" ]]; then
53+
stop
54+
else
55+
echo "Unknown command"
56+
fi

contrib/load-tester/mock_auth.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf -*-
3+
4+
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
5+
6+
import random
7+
8+
def main():
9+
server = HTTPServer(('', 8080), AuthHandler)
10+
server.serve_forever()
11+
12+
13+
class AuthHandler(BaseHTTPRequestHandler):
14+
def do_GET(self):
15+
self.send_response(200)
16+
self.send_header('Content-type', 'text/html')
17+
self.end_headers()
18+
if "ping" in self.path:
19+
self.wfile.write("Pong\n")
20+
else:
21+
self.wfile.write("Auth: %s\n" % random.choice([0,1]))
22+
return
23+
24+
if __name__ == "__main__":
25+
main()

contrib/load-tester/run.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
4+
echo "Make sure to configure GatewayInterface in wifidog_mock.conf"
5+
6+
#./generate_interfaces.sh start || exit 1
7+
8+
./mock_auth.py &
9+
10+
# trace-children is necessary because of the libtool wrapper -.-
11+
sudo valgrind --leak-check=full --trace-children=yes --trace-children-skip=/bin/sh \
12+
--log-file=valgrind.log ../../src/wifidog -d 7 -f -c wifidog-mock.conf 2> wifidog.log &
13+
14+
IF=`grep GatewayInterface wifidog-mock.conf | cut -f 2 -d ' '`
15+
16+
echo "Waiting for wifidog to come up"
17+
18+
sleep 10
19+
./fire_requests.py $IF mac 9
20+
21+
#./generate_interfaces.sh stop
22+
23+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
ExternalInterface eth0
2+
GatewayInterface internal0
3+
4+
AuthServer {
5+
Hostname localhost
6+
HTTPPort 8080
7+
Path /
8+
}
9+
10+
ClientTimeout 5
11+
12+
FirewallRuleSet global {
13+
}
14+
15+
FirewallRuleSet validating-users {
16+
FirewallRule allow to 0.0.0.0/0
17+
}
18+
19+
FirewallRuleSet known-users {
20+
FirewallRule allow to 0.0.0.0/0
21+
}
22+
23+
FirewallRuleSet unknown-users {
24+
FirewallRule allow udp port 53
25+
FirewallRule allow tcp port 53
26+
FirewallRule allow udp port 67
27+
FirewallRule allow tcp port 67
28+
}
29+
30+
FirewallRuleSet locked-users {
31+
FirewallRule block to 0.0.0.0/0
32+
}

0 commit comments

Comments
 (0)