1
0
Fork 0
tuned/systemtap/varnetload
Jan Vcelak a49f53e60f GPL headers only into executables and main module
GPL license does not require all files to have the copyright notice
and header. To save some space, I removed the headers from all files
except the executables and the main Python module.
2012-11-09 12:27:20 +01:00

96 lines
2.7 KiB
Python
Executable file

#!/usr/bin/python -Es
#
# varnetload: A python script to create reproducable sustained network traffic
# Copyright (C) 2008-2012 Red Hat, Inc.
# Authors: Phil Knirsch
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#
# Usage: varnetload [-d delay in milliseconds] [-t runtime in seconds] [-u URL]
#
# Howto use it:
# - In order to effectively use it you need to have a http server in your local
# LAN where you can put files.
# - Upload a large HTML (or any other kind of file) to the http server.
# - Use the -u option of the script to point to that URL
# - Play with the delay option to vary the load put on your network. Typical
# useful values range from 0 to 500.
#
import time, getopt, sys
from urllib2 import *
def usage():
print("Usage: varnetload [-d delay in milliseconds] [-t runtime in seconds] [-u URL]")
delay = 1000.0
rtime = 60.0
url = "http://myhost.mydomain/index.html"
try:
opts, args = getopt.getopt(sys.argv[1:], "d:t:u:")
except getopt.error, e:
print("Error parsing command-line arguments: %s" % e)
usage()
sys.exit(1)
for (opt, val) in opts:
if opt == '-d':
delay = float(val)
elif opt == '-t':
rtime = float(val)
elif opt == '-u':
url = val
else:
print("Unknown option: %s" % opt)
usage()
sys.exit(1)
endtime = time.time() + rtime
delay = float(delay)/1000.0
try:
count = 0
while(time.time() < endtime):
if (delay < 0.01):
urlopen(url).read(409600)
time.sleep(delay)
urlopen(url).read(409600)
time.sleep(delay)
urlopen(url).read(409600)
time.sleep(delay)
urlopen(url).read(409600)
time.sleep(delay)
urlopen(url).read(409600)
time.sleep(delay)
urlopen(url).read(409600)
time.sleep(delay)
urlopen(url).read(409600)
time.sleep(delay)
urlopen(url).read(409600)
time.sleep(delay)
urlopen(url).read(409600)
time.sleep(delay)
count += 9
urlopen(url).read(409600)
time.sleep(delay)
count += 1
except URLError, e:
print("Downloading failed: %s" % e.reason)
sys.exit(2)
print("Finished varnetload. Received %d pages in %d seconds" % (count, rtime))