Permalink
Browse files

Add code to exercise wdctl

fire_wdctl.py randomly calls either 'wdctl status' or resets
a client based on either IP or MAC address.

Includes some refactoring and white space changes, but no
functional changes in fire_requests.py.
  • Loading branch information...
mhaas committed Apr 21, 2015
1 parent c59ab21 commit e19f58659717758943d4ef0117d189688c3c772e
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
import socket
import fcntl
import struct
import argparse
# http://stackoverflow.com/questions/159137/getting-mac-address
def get_mac_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', ifname[:15]))
return ':'.join(['%02x' % ord(char) for char in info[18:24]])
# http://code.activestate.com/recipes/439094-get-the-ip-address-associated-with-a-network-inter/
def get_ip_address(ifname):
print "ifname: %s" % ifname
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])
def get_argparser():
parser = argparse.ArgumentParser(description='Hammer a wifidog'
+ ' instance with requests')
parser.add_argument(
'--target-interface',
required=True,
help='Interface where Wifidog is listening')
parser.add_argument(
'--source-interface-prefix',
required=True,
help='Prefix of the virtual interfaces from which Wifidog' +
' is exercised.')
parser.add_argument(
'--source-interface-count',
required=True,
help='Number of virtual interfaces, where interface is prefix+index')
parser.add_argument(
'--process-count',
required=True,
help='How many processes to run')
return parser
@@ -2,97 +2,80 @@
# -*- coding: utf -*-
import socket
import fcntl
import struct
import uuid
import sys
import random
import argparse
import functools
from multiprocessing import Pool
from httplib import HTTPConnection
from httplib import BadStatusLine
import common
PORT = "2060"
def main(targetIF, prefix, maxI):
target = get_ip_address(targetIF)
target = common.get_ip_address(targetIF)
for i in xrange(int(maxI)):
main_single(target, prefix, i)
def main_single(target, prefix, i):
source = get_ip_address(prefix + str(i))
# source_address requires python 2.7
# urllib2 does not nicely expose source_address, so use
# lower-level API
conn = HTTPConnection(target, PORT, timeout=10, source_address=(source, 0))
conn.connect()
conn.request("GET", "/")
try:
resp = conn.getresponse()
resp.read()
conn.close()
except BadStatusLine as e:
print "Got BadStatusLine for /: %s" % e
conn = HTTPConnection(target, PORT, timeout=10, source_address=(source, 0))
source = common.get_ip_address(prefix + str(i))
# source_address requires python 2.7
# urllib2 does not nicely expose source_address, so use
# lower-level API
conn = HTTPConnection(target, PORT, timeout=10,
source_address=(source, 0))
conn.connect()
conn.request("GET", "/")
try:
resp = conn.getresponse()
resp.read()
conn.close()
except BadStatusLine as e:
print "Got BadStatusLine for /: %s" % e
conn = HTTPConnection(target, PORT, timeout=10,
source_address=(source, 0))
conn.connect()
token = str(uuid.uuid4())
conn.request("GET", "/wifidog/auth?token=" + token)
try:
resp = conn.getresponse()
# this causes wifidog to ask our mock auth server if the token is
# correct
resp.read()
conn.close()
except BadStatusLine as e:
print "Got BadStatusLine for login: %s" % e
# log out sometimes
if random.choice([True, False, False]):
conn = HTTPConnection(target, PORT, timeout=10,
source_address=(source, 0))
conn.connect()
token = str(uuid.uuid4())
conn.request("GET", "/wifidog/auth?token=" + token )
conn.request("GET", "/wifidog/auth?logout=1&token=" + token)
try:
resp = conn.getresponse()
# this causes wifidog to ask our mock auth server if the token is
# correct
resp.read()
conn.close()
except BadStatusLine as e:
print "Got BadStatusLine for login: %s" % e
# log out sometimes
if random.choice([True, False, False]):
conn = HTTPConnection(target, PORT, timeout=10, source_address=(source, 0))
conn.connect()
conn.request("GET", "/wifidog/auth?logout=1&token=" + token)
try:
resp = conn.getresponse()
resp.read()
conn.close()
except BadStatusLine as e:
print "Got BadStatusLine for logout: %s" % e
# http://code.activestate.com/recipes/439094-get-the-ip-address-associated-with-a-network-inter/
def get_ip_address(ifname):
print "ifname: %s" % ifname
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])
print "Got BadStatusLine for logout: %s" % e
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Hammer a wifidog instance with requests')
parser.add_argument('--target-interface', required=True,
help='Interface where Wifidog is listening')
parser.add_argument('--source-interface-prefix', required=True,
help='Prefix of the virtual interfaces from which Wifidog is exercised.')
parser.add_argument('--source-interface-count', required=True,
help='Number of virtual interfaces, where interface is prefix+index')
parser.add_argument('--process-count', required=True,
help='How many processes to run')
if __name__ == "__main__":
parser = common.get_argparser()
args = parser.parse_args()
target = get_ip_address(args.target_interface)
target = common.get_ip_address(args.target_interface)
p = Pool(int(args.process_count))
partial = functools.partial(main_single, target, args.source_interface_prefix)
partial = functools.partial(
main_single,
target,
args.source_interface_prefix)
while True:
p.map(partial, list(xrange(int(args.source_interface_count))))
@@ -0,0 +1,40 @@
#!/usr/bin/env python2
# -*- coding: utf -*-
import functools
from multiprocessing import Pool
import subprocess
import random
import common
def main_single(target, prefix, i):
"""
Either calls 'wdctl status' or
logs out the client specified by the interface prefix + i.
"""
binary = "../../src/wdctl"
ip = common.get_ip_address(prefix + str(i))
mac = common.get_mac_address(prefix + str(i))
args = [["status"], ["reset", ip], ["reset", mac]]
call = [binary]
call.extend(random.choice(args))
ret = subprocess.call(call)
print "fire_wdctl.py: Return code %s" % ret
if __name__ == "__main__":
parser = common.get_argparser()
args = parser.parse_args()
target = common.get_ip_address(args.target_interface)
p = Pool(int(args.process_count))
partial = functools.partial(
main_single,
target,
args.source_interface_prefix)
while True:
p.map(partial, list(xrange(int(args.source_interface_count))))
View
@@ -46,13 +46,20 @@ function main() {
sleep 10
./fire_wdctl.py \
--target-interface $IF \
--source-interface-prefix mac \
--source-interface-count $COUNT \
--process-count 3 &
WDCTL="$!"
sudo -u "$SUDO_USER" ./fire_requests.py \
--target-interface $IF \
--source-interface-prefix mac \
--source-interface-count $COUNT \
--process-count 3
REQUESTS="$!"
#./generate_interfaces.sh stop
}
@@ -61,6 +68,8 @@ function cleanup() {
kill $MA_PID
kill $WD_PID
kill $M_PID
kill $WDCTL
kill $REQUESTS
./generate_interfaces.sh stop $COUNT
}

This file was deleted.

Oops, something went wrong.

0 comments on commit e19f586

Please sign in to comment.