-
Notifications
You must be signed in to change notification settings - Fork 1
/
simulator_sun_roundrobin.py
94 lines (73 loc) · 2.47 KB
/
simulator_sun_roundrobin.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
import random
import sys
number_of_retries = int(sys.argv[1])
current_mod = [1,2]
modulations = {1:"FSK", 2:"OQPSK", 3:"OFDM"}
packet_counter = 0
retry = 0
rx_counter = 0
retry_counter = 0
prev_packet = -1
cont_window = 0
cont_trial = 0
acc_trial = 0
verbose = False
round_robin = 0
try:
random.seed()
current_config = 0
while (True):
#the the PDR to transmit the next packet
if(retry == 0):
if(cont_window == 0):
ent = input().split('\t')
cont_window = int(ent[1])
if(cont_window > 75):
continue
pdr_fsk = float(ent[2])
pdr_oqpsk = float(ent[3])
pdr_ofdm = float(ent[4])
if(verbose):
print("PDR FSK: ",pdr_fsk)
print("PDR OQPSK: ",pdr_oqpsk)
print("PDR OFDM",pdr_ofdm)
cont_window -= 1
retry_counter += 1
round_robin = (round_robin + 1)%3
trial = random.random()
if(verbose):
print("Transmitting packet {} retry {} modulation {}".format(packet_counter, retry, round_robin))
pdr_phy = float(ent[round_robin + 2])
#packet delivered
if(trial <= pdr_phy):
if(verbose):
print("Receiving packet {} retry {}".format(packet_counter, retry))
if(packet_counter != prev_packet):
rx_counter += 1
prev_packet = packet_counter
#sending ACK
trial = random.random()
if(trial <= pdr_phy):
if(verbose):
print("Receiving ACK {} retry {}".format(packet_counter, retry))
packet_counter += 1
retry = 0
else:
if(verbose):
print("ACK not received {} retry {}".format(packet_counter, retry))
#transmit again?
if(retry < number_of_retries):
retry += 1
else:
packet_counter += 1
retry = 0
#transmission failed
else:
#transmit again?
if(retry < number_of_retries):
retry += 1
else:
packet_counter += 1
retry = 0
except EOFError as e:
print("{},{}".format(rx_counter/packet_counter,retry_counter/packet_counter))