summaryrefslogtreecommitdiff
path: root/esds.py
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-06-10 18:01:51 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2022-06-10 18:01:51 +0200
commit94b47ceab5c910a6f17b5a4b69d2e14161be073e (patch)
treee99d352f76c5a164e5284ca85f178a38e5dbe7df /esds.py
parenta8579777024964f40a484f7248d040d1147e6086 (diff)
Use different matrix for wlan0 and eth0
Diffstat (limited to 'esds.py')
-rw-r--r--esds.py66
1 files changed, 40 insertions, 26 deletions
diff --git a/esds.py b/esds.py
index cb81fc1..d297554 100644
--- a/esds.py
+++ b/esds.py
@@ -190,11 +190,13 @@ class Simulator:
one may not gives accurate results because of missing entries in the nodes received queues.
"""
- def __init__(self,B,L):
- self.B=B
- self.L=L
+ def __init__(self,B_wlan0,L_wlan0,B_eth0,L_eth0):
+ self.B_wlan0=B_wlan0
+ self.L_wlan0=L_wlan0
+ self.B_eth0=B_eth0
+ self.L_eth0=L_eth0
self.nodes=list()
- self.sharing=np.zeros(len(B))
+ self.sharing=np.zeros(len(B_eth0))
self.events=np.empty((0,4),dtype=object)
self.events_dirty=True # For optimization reasons
self.startat=-1
@@ -205,31 +207,43 @@ class Simulator:
self.wait_end_nodes=list() # Keep track of nodes that wait for the end of the simulation
self.time_truncated=format(self.time,self.precision) # Truncated version is used in log print
- def update_network(self,B,L):
+ def update_network(self,B_wlan0,L_wlan0,B_eth0,L_eth0):
for event in self.events:
if int(event[0]) == 0:
cur_event=event[2]
ts=float(event[1])
src_id,dst_id,interface, data, datasize,duration, datasize_remaining,start_at=cur_event
- new_bw=B[int(src_id),int(dst_id)]
- old_bw=self.B[int(src_id),int(dst_id)]
- new_lat=L[int(src_id),int(dst_id)]
- old_lat=self.L[int(src_id),int(dst_id)]
- if new_bw != old_bw or new_lat != old_lat:
- new_datasize_remaining=float(datasize_remaining)*((ts-self.time)/float(duration))
- if new_datasize_remaining > 0:
- latency_factor=new_datasize_remaining/float(datasize)
- if interface == "wlan0":
+ if interface == "wlan0":
+ new_bw=B_wlan0[int(src_id),int(dst_id)]
+ old_bw=self.B_wlan0[int(src_id),int(dst_id)]
+ new_lat=L_wlan0[int(src_id),int(dst_id)]
+ old_lat=self.L_wlan0[int(src_id),int(dst_id)]
+ if new_bw != old_bw or new_lat != old_lat:
+ new_datasize_remaining=float(datasize_remaining)*((ts-self.time)/float(duration))
+ if new_datasize_remaining > 0:
+ latency_factor=new_datasize_remaining/float(datasize)
new_duration=new_datasize_remaining*8/new_bw+new_lat*latency_factor
- else:
+ event[1]=self.time+new_duration
+ event[2][6]=new_datasize_remaining
+ event[2][5]=new_duration
+ else:
+ new_bw=B_eth0[int(src_id),int(dst_id)]
+ old_bw=self.B_eth0[int(src_id),int(dst_id)]
+ new_lat=L_eth0[int(src_id),int(dst_id)]
+ old_lat=self.L_eth0[int(src_id),int(dst_id)]
+ if new_bw != old_bw or new_lat != old_lat:
+ new_datasize_remaining=float(datasize_remaining)*((ts-self.time)/float(duration))
+ if new_datasize_remaining > 0:
+ latency_factor=new_datasize_remaining/float(datasize)
new_duration=new_datasize_remaining*8/(new_bw/self.sharing[int(dst_id)])+new_lat*latency_factor
+ event[1]=self.time+new_duration
+ event[2][6]=new_datasize_remaining
+ event[2][5]=new_duration
-# print("DataSize {}B | DataSize Remaining {}B | Old duration {}s | New duration {}s | Latency {}s".format(datasize,new_datasize_remaining,duration,new_duration,new_lat))
- event[1]=self.time+new_duration
- event[2][6]=new_datasize_remaining
- event[2][5]=new_duration
- self.B=B
- self.L=L
+ self.B_wlan0=B_wlan0
+ self.L_wlan0=L_wlan0
+ self.B_eth0=B_eth0
+ self.L_eth0=L_eth0
def debug(self):
"""
@@ -451,9 +465,9 @@ class Simulator:
nsrc=self.nodes[src]
if interface=="wlan0":
self.log("Send "+str(datasize)+" bytes on "+interface,node=src)
- for dst in self.list_receivers(nsrc):
+ for dst in self.list_wireless_receivers(nsrc):
if self.nodes[dst]["turned_on"]:
- duration=datasize*8/self.B[src,dst]+self.L[src,dst]
+ duration=datasize*8/self.B_wlan0[src,dst]+self.L_wlan0[src,dst]
if src == dst:
self.add_event(0,duration+self.time,(src,dst,interface,data,datasize,duration,datasize,self.time))
elif not self.interferences:
@@ -465,17 +479,17 @@ class Simulator:
self.log("Send "+str(datasize)+" bytes to n"+str(dst)+" on "+interface,node=src)
self.update_sharing(dst,1) # Update sharing first
# Note that in the following we send more data than expected to handle bandwidth sharing (datasize*8*sharing):
- duration=datasize*8/(self.B[src,dst]/self.sharing[dst])+self.L[src,dst]
+ duration=datasize*8/(self.B_eth0[src,dst]/self.sharing[dst])+self.L_eth0[src,dst]
self.add_event(0,duration+self.time,(src,dst,interface,data,datasize,duration,datasize,self.time))
else:
nsrc["state"]="request" # Try later when node is on
- def list_receivers(self,node):
+ def list_wireless_receivers(self,node):
"""
Deduce reachable receivers from the bandwidth matrix
"""
- selector = self.B[node.node_id,] > 0
+ selector = self.B_wlan0[node.node_id,] > 0
return np.arange(0,selector.shape[0])[selector]