summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--esds.py66
-rwxr-xr-xexample/simulator.py2
-rwxr-xr-xtests/hidden_node_2s1r/simulator.py2
-rwxr-xr-xtests/mobility_eth0_bandwidth_1s1r/simulator.py4
-rwxr-xr-xtests/mobility_eth0_bandwidth_2s1r/simulator.py4
-rwxr-xr-xtests/mobility_eth0_latency_1s1r/simulator.py4
-rwxr-xr-xtests/mobility_eth0_latency_2s1r/simulator.py4
-rwxr-xr-xtests/mobility_wlan0_bandwidth_1s1r/simulator.py4
-rwxr-xr-xtests/mobility_wlan0_latency_1s1r/simulator.py4
-rwxr-xr-xtests/simple_breakpoints_auto_1n/simulator.py2
-rwxr-xr-xtests/simple_breakpoints_manual_1n/simulator.py2
-rwxr-xr-xtests/simple_breakpoints_manual_no_callback_1n/simulator.py2
-rwxr-xr-xtests/simple_log_5n/simulator.py2
-rwxr-xr-xtests/simple_read_clock_2n/simulator.py2
-rwxr-xr-xtests/simple_read_eth0_ncom_2s1r/simulator.py2
-rwxr-xr-xtests/simple_read_wlan0_ncom_2s1r/simulator.py2
-rwxr-xr-xtests/simple_receivet_eth0_1s1r/simulator.py2
-rwxr-xr-xtests/simple_send_eth0_1s1r/simulator.py2
-rwxr-xr-xtests/simple_send_eth0_2s1r/simulator.py2
-rwxr-xr-xtests/simple_send_eth0_3s1r/simulator.py2
-rwxr-xr-xtests/simple_send_wlan0_1s2r/simulator.py2
-rwxr-xr-xtests/simple_send_wlan0_2s1r/simulator.py2
-rwxr-xr-xtests/simple_sendt_eth0_1s1r/simulator.py2
-rwxr-xr-xtests/simple_sendt_wlan0_1s2r/simulator.py2
-rwxr-xr-xtests/simple_wait_2n/simulator.py2
-rwxr-xr-xtests/simple_wait_end_3n/simulator.py2
26 files changed, 71 insertions, 57 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]
diff --git a/example/simulator.py b/example/simulator.py
index 9b00887..40a37a8 100755
--- a/example/simulator.py
+++ b/example/simulator.py
@@ -26,7 +26,7 @@ B=np.full((n,n),5) # 5Mbps
L=np.full((n,n),0) # 0s
##### Create the simulator
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
##### Instantiate nodes
uptime=180 # 180s uptime
diff --git a/tests/hidden_node_2s1r/simulator.py b/tests/hidden_node_2s1r/simulator.py
index 63ca502..bfe68ba 100755
--- a/tests/hidden_node_2s1r/simulator.py
+++ b/tests/hidden_node_2s1r/simulator.py
@@ -13,7 +13,7 @@ B[0,2]=0
B[2,0]=0
L=np.full((3,3),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("sender")
s.create_node("receiver")
diff --git a/tests/mobility_eth0_bandwidth_1s1r/simulator.py b/tests/mobility_eth0_bandwidth_1s1r/simulator.py
index f7a0072..6d9d5fc 100755
--- a/tests/mobility_eth0_bandwidth_1s1r/simulator.py
+++ b/tests/mobility_eth0_bandwidth_1s1r/simulator.py
@@ -26,13 +26,13 @@ import numpy as np
B=np.full((2,2),8)
L=np.full((2,2),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("sender")
s.create_node("receiver")
def callback(simulator):
simulator.log("Network update!")
- simulator.update_network(simulator.B*2,simulator.L)
+ simulator.update_network(simulator.B_wlan0*2,simulator.L_wlan0,simulator.B_eth0*2,simulator.L_eth0)
s.run(breakpoints_every=1/2,breakpoint_callback=callback)
diff --git a/tests/mobility_eth0_bandwidth_2s1r/simulator.py b/tests/mobility_eth0_bandwidth_2s1r/simulator.py
index ba876d8..bc0712d 100755
--- a/tests/mobility_eth0_bandwidth_2s1r/simulator.py
+++ b/tests/mobility_eth0_bandwidth_2s1r/simulator.py
@@ -28,7 +28,7 @@ import numpy as np
B=np.full((3,3),8)
L=np.full((3,3),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("sender")
s.create_node("sender")
@@ -36,6 +36,6 @@ s.create_node("receiver")
def callback(simulator):
simulator.log("Network update!")
- simulator.update_network(simulator.B*2,simulator.L)
+ simulator.update_network(simulator.B_wlan0*2,simulator.L_wlan0,simulator.B_eth0*2,simulator.L_eth0)
s.run(breakpoints_every=1,breakpoint_callback=callback,debug=True)
diff --git a/tests/mobility_eth0_latency_1s1r/simulator.py b/tests/mobility_eth0_latency_1s1r/simulator.py
index 525bb66..f25e231 100755
--- a/tests/mobility_eth0_latency_1s1r/simulator.py
+++ b/tests/mobility_eth0_latency_1s1r/simulator.py
@@ -27,13 +27,13 @@ import numpy as np
B=np.full((2,2),8)
L=np.full((2,2),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("sender")
s.create_node("receiver")
def callback(simulator):
simulator.log("Network update!")
- simulator.update_network(simulator.B,simulator.L+1/2)
+ simulator.update_network(simulator.B_wlan0,simulator.L_wlan0+1/2,simulator.B_eth0,simulator.L_eth0+1/2)
s.run(breakpoints_every=1/2,breakpoint_callback=callback)
diff --git a/tests/mobility_eth0_latency_2s1r/simulator.py b/tests/mobility_eth0_latency_2s1r/simulator.py
index 101004b..ccc2a63 100755
--- a/tests/mobility_eth0_latency_2s1r/simulator.py
+++ b/tests/mobility_eth0_latency_2s1r/simulator.py
@@ -29,7 +29,7 @@ import numpy as np
B=np.full((3,3),8)
L=np.full((3,3),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("sender")
s.create_node("sender")
@@ -37,6 +37,6 @@ s.create_node("receiver")
def callback(simulator):
simulator.log("Network update!")
- simulator.update_network(simulator.B,simulator.L+0.5)
+ simulator.update_network(simulator.B_wlan0,simulator.L_wlan0+0.5,simulator.B_eth0,simulator.L_eth0+0.5)
s.run(breakpoints_every=1,breakpoint_callback=callback,debug=True)
diff --git a/tests/mobility_wlan0_bandwidth_1s1r/simulator.py b/tests/mobility_wlan0_bandwidth_1s1r/simulator.py
index f7a0072..6d9d5fc 100755
--- a/tests/mobility_wlan0_bandwidth_1s1r/simulator.py
+++ b/tests/mobility_wlan0_bandwidth_1s1r/simulator.py
@@ -26,13 +26,13 @@ import numpy as np
B=np.full((2,2),8)
L=np.full((2,2),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("sender")
s.create_node("receiver")
def callback(simulator):
simulator.log("Network update!")
- simulator.update_network(simulator.B*2,simulator.L)
+ simulator.update_network(simulator.B_wlan0*2,simulator.L_wlan0,simulator.B_eth0*2,simulator.L_eth0)
s.run(breakpoints_every=1/2,breakpoint_callback=callback)
diff --git a/tests/mobility_wlan0_latency_1s1r/simulator.py b/tests/mobility_wlan0_latency_1s1r/simulator.py
index 525bb66..f25e231 100755
--- a/tests/mobility_wlan0_latency_1s1r/simulator.py
+++ b/tests/mobility_wlan0_latency_1s1r/simulator.py
@@ -27,13 +27,13 @@ import numpy as np
B=np.full((2,2),8)
L=np.full((2,2),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("sender")
s.create_node("receiver")
def callback(simulator):
simulator.log("Network update!")
- simulator.update_network(simulator.B,simulator.L+1/2)
+ simulator.update_network(simulator.B_wlan0,simulator.L_wlan0+1/2,simulator.B_eth0,simulator.L_eth0+1/2)
s.run(breakpoints_every=1/2,breakpoint_callback=callback)
diff --git a/tests/simple_breakpoints_auto_1n/simulator.py b/tests/simple_breakpoints_auto_1n/simulator.py
index c5e3b02..99cdafc 100755
--- a/tests/simple_breakpoints_auto_1n/simulator.py
+++ b/tests/simple_breakpoints_auto_1n/simulator.py
@@ -9,7 +9,7 @@ import numpy as np
n=2
B=np.full((2,2),n)
L=np.full((2,2),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("node")
s.create_node("node")
diff --git a/tests/simple_breakpoints_manual_1n/simulator.py b/tests/simple_breakpoints_manual_1n/simulator.py
index a0d0d2b..1b27c88 100755
--- a/tests/simple_breakpoints_manual_1n/simulator.py
+++ b/tests/simple_breakpoints_manual_1n/simulator.py
@@ -9,7 +9,7 @@ import numpy as np
n=2
B=np.full((n,n),n)
L=np.full((n,n),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("node")
s.create_node("node")
diff --git a/tests/simple_breakpoints_manual_no_callback_1n/simulator.py b/tests/simple_breakpoints_manual_no_callback_1n/simulator.py
index 93b1fef..85cfeb4 100755
--- a/tests/simple_breakpoints_manual_no_callback_1n/simulator.py
+++ b/tests/simple_breakpoints_manual_no_callback_1n/simulator.py
@@ -9,7 +9,7 @@ import numpy as np
n=2
B=np.full((n,n),n)
L=np.full((n,n),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("node")
s.create_node("node")
diff --git a/tests/simple_log_5n/simulator.py b/tests/simple_log_5n/simulator.py
index 184340a..3f7775b 100755
--- a/tests/simple_log_5n/simulator.py
+++ b/tests/simple_log_5n/simulator.py
@@ -8,7 +8,7 @@ import numpy as np
B=np.full((5,5),5)
L=np.full((5,5),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("node")
s.create_node("node")
diff --git a/tests/simple_read_clock_2n/simulator.py b/tests/simple_read_clock_2n/simulator.py
index b2c042c..9690b3f 100755
--- a/tests/simple_read_clock_2n/simulator.py
+++ b/tests/simple_read_clock_2n/simulator.py
@@ -8,7 +8,7 @@ import numpy as np
B=np.full((2,2),2)
L=np.full((2,2),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("node")
s.create_node("node")
diff --git a/tests/simple_read_eth0_ncom_2s1r/simulator.py b/tests/simple_read_eth0_ncom_2s1r/simulator.py
index 5294b9d..c5ee571 100755
--- a/tests/simple_read_eth0_ncom_2s1r/simulator.py
+++ b/tests/simple_read_eth0_ncom_2s1r/simulator.py
@@ -8,7 +8,7 @@ import numpy as np
B=np.full((3,3),3)
L=np.full((3,3),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("sender")
s.create_node("sender")
diff --git a/tests/simple_read_wlan0_ncom_2s1r/simulator.py b/tests/simple_read_wlan0_ncom_2s1r/simulator.py
index 5294b9d..c5ee571 100755
--- a/tests/simple_read_wlan0_ncom_2s1r/simulator.py
+++ b/tests/simple_read_wlan0_ncom_2s1r/simulator.py
@@ -8,7 +8,7 @@ import numpy as np
B=np.full((3,3),3)
L=np.full((3,3),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("sender")
s.create_node("sender")
diff --git a/tests/simple_receivet_eth0_1s1r/simulator.py b/tests/simple_receivet_eth0_1s1r/simulator.py
index 5ec9a25..e80e7a1 100755
--- a/tests/simple_receivet_eth0_1s1r/simulator.py
+++ b/tests/simple_receivet_eth0_1s1r/simulator.py
@@ -8,7 +8,7 @@ import numpy as np
B=np.full((2,2),8)
L=np.full((2,2),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("sender")
s.create_node("receiver")
diff --git a/tests/simple_send_eth0_1s1r/simulator.py b/tests/simple_send_eth0_1s1r/simulator.py
index f5f6ca6..39be96c 100755
--- a/tests/simple_send_eth0_1s1r/simulator.py
+++ b/tests/simple_send_eth0_1s1r/simulator.py
@@ -8,7 +8,7 @@ import numpy as np
B=np.full((2,2),8)
L=np.full((2,2),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("sender")
s.create_node("receiver")
diff --git a/tests/simple_send_eth0_2s1r/simulator.py b/tests/simple_send_eth0_2s1r/simulator.py
index 9faaf3d..9980b2a 100755
--- a/tests/simple_send_eth0_2s1r/simulator.py
+++ b/tests/simple_send_eth0_2s1r/simulator.py
@@ -8,7 +8,7 @@ import numpy as np
B=np.full((3,3),8)
L=np.full((3,3),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("sender")
s.create_node("sender")
diff --git a/tests/simple_send_eth0_3s1r/simulator.py b/tests/simple_send_eth0_3s1r/simulator.py
index 4a5aede..cc09486 100755
--- a/tests/simple_send_eth0_3s1r/simulator.py
+++ b/tests/simple_send_eth0_3s1r/simulator.py
@@ -8,7 +8,7 @@ import numpy as np
B=np.full((4,4),8)
L=np.full((4,4),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("sender")
s.create_node("sender")
diff --git a/tests/simple_send_wlan0_1s2r/simulator.py b/tests/simple_send_wlan0_1s2r/simulator.py
index 3f53e63..0778101 100755
--- a/tests/simple_send_wlan0_1s2r/simulator.py
+++ b/tests/simple_send_wlan0_1s2r/simulator.py
@@ -8,7 +8,7 @@ import numpy as np
B=np.full((3,3),8)
L=np.full((3,3),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("sender")
s.create_node("receiver")
diff --git a/tests/simple_send_wlan0_2s1r/simulator.py b/tests/simple_send_wlan0_2s1r/simulator.py
index 9faaf3d..9980b2a 100755
--- a/tests/simple_send_wlan0_2s1r/simulator.py
+++ b/tests/simple_send_wlan0_2s1r/simulator.py
@@ -8,7 +8,7 @@ import numpy as np
B=np.full((3,3),8)
L=np.full((3,3),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("sender")
s.create_node("sender")
diff --git a/tests/simple_sendt_eth0_1s1r/simulator.py b/tests/simple_sendt_eth0_1s1r/simulator.py
index f5f6ca6..39be96c 100755
--- a/tests/simple_sendt_eth0_1s1r/simulator.py
+++ b/tests/simple_sendt_eth0_1s1r/simulator.py
@@ -8,7 +8,7 @@ import numpy as np
B=np.full((2,2),8)
L=np.full((2,2),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("sender")
s.create_node("receiver")
diff --git a/tests/simple_sendt_wlan0_1s2r/simulator.py b/tests/simple_sendt_wlan0_1s2r/simulator.py
index 3f53e63..0778101 100755
--- a/tests/simple_sendt_wlan0_1s2r/simulator.py
+++ b/tests/simple_sendt_wlan0_1s2r/simulator.py
@@ -8,7 +8,7 @@ import numpy as np
B=np.full((3,3),8)
L=np.full((3,3),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("sender")
s.create_node("receiver")
diff --git a/tests/simple_wait_2n/simulator.py b/tests/simple_wait_2n/simulator.py
index b2c042c..9690b3f 100755
--- a/tests/simple_wait_2n/simulator.py
+++ b/tests/simple_wait_2n/simulator.py
@@ -8,7 +8,7 @@ import numpy as np
B=np.full((2,2),2)
L=np.full((2,2),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("node")
s.create_node("node")
diff --git a/tests/simple_wait_end_3n/simulator.py b/tests/simple_wait_end_3n/simulator.py
index d4c9ec4..6b68c46 100755
--- a/tests/simple_wait_end_3n/simulator.py
+++ b/tests/simple_wait_end_3n/simulator.py
@@ -8,7 +8,7 @@ import numpy as np
B=np.full((3,3),2)
L=np.full((3,3),0)
-s=esds.Simulator(B,L)
+s=esds.Simulator(B,L,B,L)
s.create_node("node")
s.create_node("node")