'''
Traffic Generator Script:
Here I have used IP Aliasing to create multiple clients on single vm machine.
Same I have done on server side to create multiple servers. I have around 50 clients and 10 servers
'''importmultiprocessingimporturllib2importrandomimportmyurllist#list of all destination urls for all 10 serversimporttimeimportsocbindtry#script that binds various virtual/aliased client ips to the scriptresponse_time=[]#some shared variableserror_count=multiprocessing.Value('i',0)defsend_request3():#function to send requests from alias client ip 1opener=urllib2.build_opener(socbindtry.BindableHTTPHandler3)#bind to alias client ip1try:tstart=time.time()foriinrange(myurllist.url):x=random.choice(myurllist.url[i])opener.open(x).read()print"file downloaded:",x
response_time.append(time.time()-tstart)excepturllib2.URLError,e:error_count.value=error_count.value+1defsend_request4():#function to send requests from alias client ip 2opener=urllib2.build_opener(socbindtry.BindableHTTPHandler4)#bind to alias client ip2try:tstart=time.time()foriinrange(myurllist.url):x=random.choice(myurllist.url[i])opener.open(x).read()print"file downloaded:",x
response_time.append(time.time()-tstart)excepturllib2.URLError,e:error_count.value=error_count.value+1#50 such functions are defined here for 50 clientsprocess=[]deffunc():globalprocess
process.append(multiprocessing.Process(target=send_request3))process.append(multiprocessing.Process(target=send_request4))process.append(multiprocessing.Process(target=send_request5))process.append(multiprocessing.Process(target=send_request6))#append 50 functions hereforiinrange(len(process)):process[i].start()foriinrange(len(process)):process[i].join()print"All work Done..!!"returnstart=float(time.time())func()end=float(time.time())-startprintend