summaryrefslogtreecommitdiff
path: root/esds.py
diff options
context:
space:
mode:
Diffstat (limited to 'esds.py')
-rw-r--r--esds.py66
1 files changed, 26 insertions, 40 deletions
diff --git a/esds.py b/esds.py
index d297554..c28aa28 100644
--- a/esds.py
+++ b/esds.py
@@ -190,13 +190,14 @@ class Simulator:
one may not gives accurate results because of missing entries in the nodes received queues.
"""
- 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
+ def __init__(self,netmat):
+ """
+ Format of netmat: { "wlan0": (BW,L), "eth0": (BW,L) }
+ Where BW are the bandwidth matrices and L the latency matrices
+ """
+ self.netmat=netmat
self.nodes=list()
- self.sharing=np.zeros(len(B_eth0))
+ self.sharing=np.zeros(len(netmat["eth0"]["bandwidth"]))
self.events=np.empty((0,4),dtype=object)
self.events_dirty=True # For optimization reasons
self.startat=-1
@@ -207,44 +208,29 @@ 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_wlan0,L_wlan0,B_eth0,L_eth0):
+ def update_network(self,netmat):
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
- 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_bw=netmat[interface]["bandwidth"][int(src_id),int(dst_id)]
+ old_bw=self.netmat[interface]["bandwidth"][int(src_id),int(dst_id)]
+ new_lat=netmat[interface]["latency"][int(src_id),int(dst_id)]
+ old_lat=self.netmat[interface]["latency"][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":
new_duration=new_datasize_remaining*8/new_bw+new_lat*latency_factor
- 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)
+ else:
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
-
- self.B_wlan0=B_wlan0
- self.L_wlan0=L_wlan0
- self.B_eth0=B_eth0
- self.L_eth0=L_eth0
-
+ event[1]=self.time+new_duration
+ event[2][6]=new_datasize_remaining
+ event[2][5]=new_duration
+ self.netmat=netmat
+
def debug(self):
"""
Log all the informations for debugging
@@ -467,7 +453,7 @@ class Simulator:
self.log("Send "+str(datasize)+" bytes on "+interface,node=src)
for dst in self.list_wireless_receivers(nsrc):
if self.nodes[dst]["turned_on"]:
- duration=datasize*8/self.B_wlan0[src,dst]+self.L_wlan0[src,dst]
+ duration=datasize*8/self.netmat["wlan0"]["bandwidth"][src,dst]+self.netmat["wlan0"]["latency"][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:
@@ -479,7 +465,7 @@ 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_eth0[src,dst]/self.sharing[dst])+self.L_eth0[src,dst]
+ duration=datasize*8/(self.netmat["eth0"]["bandwidth"][src,dst]/self.sharing[dst])+self.netmat["eth0"]["latency"][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
@@ -489,7 +475,7 @@ class Simulator:
"""
Deduce reachable receivers from the bandwidth matrix
"""
- selector = self.B_wlan0[node.node_id,] > 0
+ selector = self.netmat["wlan0"]["bandwidth"][node.node_id,] > 0
return np.arange(0,selector.shape[0])[selector]