-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserSim.py
More file actions
executable file
·71 lines (57 loc) · 1.72 KB
/
UserSim.py
File metadata and controls
executable file
·71 lines (57 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
__author__ = 'Sam Cappella'
import socket
import sys
import threading
from Logger import Logger
from WebSim import WebSim
from Pop3Sim import Pop3Sim
from FileShareSim import FileShareSim
# Define main function
def main(argv):
logger = Logger()
logger.log("Running main()")
# Create thread events
webSimThread = WebSim(logger)
pop3SimThread = Pop3Sim(logger)
fileShareThread = FileShareSim(logger)
# Start threads
webSimThread.start()
pop3SimThread.start()
fileShareThread.start()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
address = ('0.0.0.0', 55555)
s.bind(address)
s.listen(5)
run = True
result = ""
while run:
connection, clientAddress = s.accept()
command = connection.recv(1024)
if command == "WEB-TRAFFIC-SCORE":
result = webSimThread.score()
if command == "POP3-SCORE":
result = pop3SimThread.score()
if command == "FILE-SHARE-SCORE":
result = fileShareThread.score()
if command == "STOP":
webSimThread.stop()
pop3SimThread.stop()
fileShareThread.stop()
logs = logger.finish()
for log in logs:
connection.sendall(log)
run = False
connection.close()
continue
if result == True:
connection.sendall("SUCCESS")
else:
connection.sendall("FAIL")
connection.close()
# Join all the threads back
webSimThread.join()
pop3SimThread.join()
fileShareThread.join()
# Setup call to main function
if __name__ == "__main__":
main(sys.argv)