-
Notifications
You must be signed in to change notification settings - Fork 0
/
WifiFull.py
156 lines (128 loc) · 4.32 KB
/
WifiFull.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import numpy as np
from numpy.random import seed
from numpy.random import randint
from decimal import *
import random as rn
#seed(1)
getcontext().prec = 8
Byt= Decimal(8) #Size of a Byte
DIFS = Decimal(40*Byt)
SIFS = 20*Byt
Datos = 1500*Byt
Ack = 40*Byt
Rbps = Decimal(1000) #1000kbps = 1Mbps
T_DIFS = DIFS/Rbps
#print T_DIFS
T_SIFS = SIFS/Rbps
#print T_SIFS
T_Datos = Datos/Rbps
#print T_Datos
T_Ack = Ack/Rbps
#print T_Ack
Transmisores = []
NumeroDeTxs= 10
SLargo = T_Datos + T_SIFS + T_Ack
SCorto = T_DIFS
Total_PKG = 0
Total_TIME = 0
def compare(a, b):
return not set(a).isdisjoint(b)
class Transmisor(object):
def __init__(self,index):
self.index = index
self.EBval = 0
#super(Transmisor, self).__init__()
def EB(self,times): #Exponential Backup function.
#self.CW = 0
maxx= np.power(2,times)
fullWindow = range(0, 8*maxx, 1)
CW =rn.choice(fullWindow)
#CW = rn.choice(range(0, 16*times, 1))
#CW = rn.randrange(0, 16*times,1)
#print fullWindow
#print CW
CW_inDIFS = CW*DIFS
#print CW_inDIFS
Times_CW_inDIFS = CW_inDIFS/Rbps
#print Times_CW_inDIFS
return Times_CW_inDIFS,CW
EB_values = []
indexOfColisions = []
for i in range (NumeroDeTxs):
Transmisores.append(Transmisor(i))
time,Transmisores[i].EBval = Transmisores[i].EB(1)
print time
print Transmisores[i].EBval
#print Transmisores[i].index
#print Transmisores[i].EB(1)
EB_values.append(Transmisores[i].EBval)
print EB_values
#print ReduceEB
#EB_values = ReduceEB(EB_values)
existioCol = False
memoria = []
intentosEB = 2
while Total_PKG <10000:
print "***********Start************"
get_indexes = lambda EB_values, xs : [i for (y,i) in zip(xs, range(len(xs))) if EB_values==y]
Colisiones = get_indexes(0, EB_values) #Obtiene indices de los transmisores que intentan transmitir con EB =0
Total_TIME += SCorto
if len(Colisiones)==1:
Total_TIME += SLargo
print "Transmision hecha por el nodo" , Colisiones[0]
print Total_TIME
EB_values=list(map(lambda x: x - 1, EB_values))
print EB_values
intentosEB = 2
if Colisiones[0] in memoria:
memoria.remove(Colisiones[0])
print "Restarting ventana de EB para el valor", Colisiones[0]
#memoria = []
print "memoria en tx ", memoria
time,value = Transmisores[Colisiones[0]].EB(intentosEB-1)
EB_values[Colisiones[0]] = value
Total_PKG += 1
elif len(Colisiones)==0:
print EB_values
EB_values=list(map(lambda x: x - 1, EB_values))
print EB_values
#memoria = []
print "memoria en Tiempo muerto ", memoria
else:
#for k in range(0,len(Colisiones)+1):
print EB_values
print "Colisiones en RB 0 entre los Tx de indices: "
print Colisiones
print "Exp Bck window on start", intentosEB
print "Loking in memory> " , memoria
existioCol= True
#print any(i in Colisiones for i in memoria)
#any_in = lambda Colisiones, memoria: any(i in memoria for i in Colisiones)
print compare(memoria,Colisiones)
for k in Colisiones:
print k
#print Colisiones[k]
if k in memoria:
#if compare(memoria,Colisiones)==True:
#if any(g in Colisiones for g in memoria):
intentosEB= intentosEB +1
print "Exp Bck window order", intentosEB
time,value = Transmisores[k].EB(intentosEB)
EB_values[k] = value
print "EB Values post colision------" , EB_values
else:
#print k
time,value = Transmisores[k].EB(2)
EB_values[k] = value
memoria.append(k)
print "Memoria", memoria
print "EB Values post colision-------", EB_values
#Transmisores[k]
print Colisiones
print EB_values
print "Paquetes enviados: ", Total_PKG
print "Tiempo tomado> ", Total_TIME
# for tries in range(10000000):
# if Total_PKG ==10000:
# break
# else: