Source code for gwa.eperf.main
#!/usr/bin/python
#-*-coding:iso-8859-15-*-
import os,time,sys,signal
from server_udp import *
from client_udp import *
from server_tcp import *
from client_tcp import *
from function import *
def handler(signum,frame):
print "\nFin des servers"
server_udp.closeSocket()
server_tcp.shutdown()
exit(0)
[docs]class Eperf:
"""
This class allow to create server, client, in mode UPD or TCP
"""
def __init__(self,argv):
os.system('clear')
signal.signal(signal.SIGINT, handler)
#Test of the mandatory argument
if (not "-s" in argv) and (not "-UDP" in argv and not "-TCP" in argv):
helpEperf()
exit(1)
#Display the help of this function
if "-h" in argv or "--help" in argv:
helpEperf()
exit(1)
#Test if the mandatory arguement is present, and read the IP address
if "-UDP" in argv or "-TCP" in argv :
if "-net" in argv:
self.IP=argv[argv.index("-net")+1]
else:
helpEperf()
exit(1)
#Test if the port is indicate in the commande else the default port is 5000
if "-p" in argv:
self.port=int(argv[argv.index("-p")+1])
else :
self.port=5000
#Test if the interval is indicate in the commande else the default interval is 1
if "-i" in argv :
self.interval=int(argv[argv.index("-i")+1])
else:
self.interval=1
#Test if the duration is indicate in the commande else the default duration is 5
if "-d" in argv :
self.duration=int(argv[argv.index("-d")+1])
else:
self.duration=5
#Test if the number of connection is indicate in the commande else the default number of connection is 3 for the mode TCP only.
if "-c" in argv :
self.connection=int(argv[argv.index("-c")+1])
else:
self.connection=3
#Test if the number of limit bandwidth is indicate in the commande else the default number of limit bandwidth is 50 Mbit/s for the mode UDP only.
if "-bw" in argv :
self.bw=int(argv[argv.index("-bw")+1])
else:
self.bw=50*1024*1024
#Test if the mode of cummunicationis indicate in the commande.
if "-upload" in argv :
self.upload=True
else:
self.upload=False
if "-download" in argv :
self.download=True
else:
self.download=False
#Creation of the server if the option "-s" is indicate in the commande.
if "-s" in argv :
self.createServer()
#Creation of the Client if is necessary
if "-UDP" in argv :
self.UDPClient(argv)
if "-TCP" in argv:
self.TCPClient()
[docs] def createServer(self):
"""
This function create TCP and UDP server.
"""
addrTCP=('',self.port)
server = ServerThread(addrTCP, Connectionprocessing)
SRV_TCP = threading.Thread(target=server.serve_forever)
SRV_TCP.allow_reuse_address=True
SRV_TCP.deamon=False
SRV_TCP.start()
while 1:
print "server TCP port : "+str(self.port)
print "server UDP port : "+str(self.port+1)
address=('',self.port+1)
SRV_UDP = UDPServer(address)
if "True" in SRV_UDP.upload :
SRV_UDP.uploadUDP()
time.sleep(1)
if "True" in SRV_UDP.download :
SRV_UDP.downloadUDP()
SRV_UDP.closeSocket()
[docs] def UDPClient(self,argv):
"""
This function create UDP Client.
"""
address=(self.IP,self.port+1)
if not "-download" in argv and not "-upload" in argv :
helpEperf()
exit(1)
CLI_UDP = UDPClient(address,self.interval,self.duration,self.bw,self.upload,self.download)
if "-upload" in argv :
CLI_UDP.uploadUDP()
print "UDP Upload list"
print CLI_UDP.listFinalUp
time.sleep(1)
if "-download" in argv :
CLI_UDP.downloadUDP()
print "UDP Download list"
print CLI_UDP.listFinalDown
CLI_UDP.closeSocket()
[docs] def TCPClient(self):
"""
This function create TCP Client.
"""
address=(self.IP,self.port)
if not self.upload and not self.download:
helpEperf()
exit(1)
ClI_TCP=ClientTCP(address,self.connection,self.interval,self.duration,self.upload,self.download)
ClI_TCP.runClient()
if self.upload:
print "TCP Upload list"
print ClI_TCP.bwUpload
if self.download:
print "TCP Download list"
print ClI_TCP.bwDownload
if __name__ == "__main__":
"""
Start Point of the program
"""
app = Eperf(sys.argv)
sys.exit()