-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.py
95 lines (72 loc) · 2.01 KB
/
server.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import numpy as np
def start_1(p):
if p < 0.1:
return 1 # 10% send SYN
else:
return 0 # 90% do nothing x
def syn_received_3(p):
if p < 0.1:
return 0 # 10% do nothing x
else:
return 2 # 90% send ACK
def syn_sent_4(p):
if p < 0.1:
return 0 # 10% do nothing x
elif p < 0.2:
return 1 # 10% send SYN
else:
return 3 # 80% send SYN/ACK
def connection_established_6(p):
if p < 0.3:
return 4 # 30% send FIN
else:
return 0 # 70% do nothing x
def last_ack_9(p):
if p < 0.1:
return 0 # 10% do nothing x
else:
return 2 # 90% send ACK
def fin_wait_10(p):
if p < 0.1:
return 4 # 10% send FIN
elif p < 0.2:
return 0 # 10% do nothing x
else:
return 2 # 80% send ACK
def fin_wait_received_ack_11(p):
if p < 0.1:
return 0 # 10% do nothing x
else:
return 4 # 90% send FIN
def closing_15(p):
if p < 0.1:
return 0 # 10% do nothing x
else:
return 2 # 90% send ACK
class Server(object):
# server_actions = ["x", "SYN", "ACK", "SYN/ACK", "FIN"]
def server_action(self, current_state):
# state 0 is closed/listen, the last one
# state 1 is start state
prob = np.random.uniform(0, 1)
switcher = {
1: start_1(prob),
2: 0, # 100% do nothing x
3: syn_received_3(prob),
4: syn_sent_4(prob),
5: 0, # 100% do nothing x
6: connection_established_6(prob),
7: 0, # 100% do nothing x
8: 0, # 100% do nothing x
9: last_ack_9(prob),
10: fin_wait_10(prob),
11: fin_wait_received_ack_11(prob),
12: 0, # 100% do nothing x
13: 0, # 100% do nothing x
14: 0, # 100% do nothing x
15: closing_15(prob)
}
act = switcher.get(current_state)
if act is None:
act = -1
return act