Make one sharing matrix per wired interface

This commit is contained in:
Loic Guegan 2022-06-10 21:58:15 +02:00
parent 3fef2bbf4b
commit d2a5ea6f53
26 changed files with 50 additions and 45 deletions

33
esds.py
View file

@ -195,12 +195,16 @@ class Simulator:
def __init__(self,netmat):
"""
Format of netmat: { "wlan0": (BW,L), "eth0": (BW,L) }
Where BW are the bandwidth matrices and L the latency matrices
Format of netmat: { "wlan0": (BW,L,IS_WIRED), "eth0": (BW,L,IS_WIRED) }
Where BW are the bandwidth matrices and L the latency matrices. IS_WIRED is a
boolean specifying if the interface is wired or wireless.
"""
self.netmat=netmat
self.nodes=list()
self.sharing=np.zeros(len(netmat["eth0"]["bandwidth"]))
self.sharing=dict()
for interface in netmat.keys():
if netmat[interface]["is_wired"]:
self.sharing[interface]=np.zeros(len(netmat[interface]["bandwidth"]))
self.events=np.empty((0,4),dtype=object)
self.events_dirty=True # For optimization reasons
self.startat=-1
@ -228,7 +232,7 @@ class Simulator:
if interface == "wlan0":
new_duration=new_datasize_remaining*8/new_bw+new_lat*latency_factor
else:
new_duration=new_datasize_remaining*8/(new_bw/self.sharing[int(dst_id)])+new_lat*latency_factor
new_duration=new_datasize_remaining*8/(new_bw/self.sharing[interface][int(dst_id)])+new_lat*latency_factor
event[1]=self.time+new_duration
event[2][6]=new_datasize_remaining
event[2][5]=new_duration
@ -250,8 +254,8 @@ class Simulator:
for node in self.nodes:
s=node["state"]
states[s]=states[s]+1 if s in states else 1
if self.sharing[node.node_id] > 0:
sharing["n"+str(node.node_id)]=str(int(self.sharing[node.node_id]))
if self.sharing["eth0"][node.node_id] > 0:
sharing["n"+str(node.node_id)]=str(int(self.sharing["eth0"][node.node_id]))
print("Node number per state: ",end="")
for key in states:
print(key+"="+str(states[key]), end=" ")
@ -355,7 +359,8 @@ class Simulator:
# Remove communications
if(len(self.events) != 0):
self.events=self.events[~(np.array(selector_wlan0)|np.array(selector_other))]
self.sharing[node.node_id]=0 # Sharing goes back to zero
for interface in self.sharing.keys():
self.sharing[interface][node.node_id]=0 # Sharing goes back to zero
node["state"]="running"
node.rqueue.put(("turn_off",0))
self.log("Turned off",node=node.node_id)
@ -365,7 +370,7 @@ class Simulator:
if event[0]==0 and int(event[2][0]) == node.node_id:
selector.append(True)
if event[2][2] != "wlan0":
self.update_sharing(int(event[2][1]),-1)
self.update_sharing(int(event[2][1]),-1,event[2][2])
else:
selector.append(False)
self.events=self.events[~np.array(selector)]
@ -373,11 +378,11 @@ class Simulator:
node.rqueue.put(("send_cancel",0))
node.sync()
def update_sharing(self, dst, amount):
def update_sharing(self, dst, amount,interface):
"""
Manage bandwidth sharing on wired interfaces
"""
sharing=self.sharing[dst]
sharing=self.sharing[interface][dst]
new_sharing=sharing+amount
for event in self.events:
if event[0] == 0 and event[2][2] != "wlan0" and int(event[2][1]) == dst:
@ -387,7 +392,7 @@ class Simulator:
remaining=remaining*new_sharing if new_sharing > 1 else remaining # Then apply new sharing
event[2][5]=remaining # Update duration
event[1]=self.time+remaining # Update timestamp
self.sharing[dst]=new_sharing
self.sharing[interface][dst]=new_sharing
self.sort_events()
def handle_interferences(self,sender,receiver):
@ -466,9 +471,9 @@ class Simulator:
else:
if self.nodes[dst]["turned_on"]:
self.log("Send "+str(datasize)+" bytes to n"+str(dst)+" on "+interface,node=src)
self.update_sharing(dst,1) # Update sharing first
self.update_sharing(dst,1,interface) # 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.netmat["eth0"]["bandwidth"][src,dst]/self.sharing[dst])+self.netmat["eth0"]["latency"][src,dst]
duration=datasize*8/(self.netmat["eth0"]["bandwidth"][src,dst]/self.sharing["eth0"][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
@ -559,7 +564,7 @@ class Simulator:
else:
dst["interfaces"][interface].put((data,start_at,self.time))
dst["interfaces_queue_size"][interface]+=1
self.update_sharing(dst.node_id,-1)
self.update_sharing(dst.node_id,-1,interface)
self.log("Receive "+str(datasize)+" bytes on "+interface,node=int(dst_id))
# If node is receiving makes it consume (this way if there is a timeout, it will be removed!)
if dst["state"] == "request" and dst["request"] == "receive":

View file

@ -26,7 +26,7 @@ B=np.full((n,n),5) # 5Mbps
L=np.full((n,n),0) # 0s
##### Create the simulator
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False},"eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
##### Instantiate nodes
uptime=180 # 180s uptime

View file

@ -13,7 +13,7 @@ B[0,2]=0
B[2,0]=0
L=np.full((3,3),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("sender")
s.create_node("receiver")

View file

@ -26,7 +26,7 @@ import numpy as np
B=np.full((2,2),8)
L=np.full((2,2),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("sender")
s.create_node("receiver")
@ -35,6 +35,6 @@ def callback(simulator):
simulator.log("Network update!")
new_bw_wlan0=simulator.netmat["wlan0"]["bandwidth"]*2
new_bw_eth0=simulator.netmat["eth0"]["bandwidth"]*2
simulator.update_network({"wlan0":{"bandwidth":new_bw_wlan0, "latency":L},"eth0":{"bandwidth":new_bw_eth0, "latency":L}})
simulator.update_network({"wlan0":{"bandwidth":new_bw_wlan0, "latency":L, "is_wired":False}, "eth0":{"bandwidth":new_bw_eth0, "latency":L, "is_wired":True}})
s.run(breakpoints_every=1/2,breakpoint_callback=callback)

View file

@ -28,7 +28,7 @@ import numpy as np
B=np.full((3,3),8)
L=np.full((3,3),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("sender")
s.create_node("sender")
@ -38,6 +38,6 @@ def callback(simulator):
simulator.log("Network update!")
new_bw_wlan0=simulator.netmat["wlan0"]["bandwidth"]*2
new_bw_eth0=simulator.netmat["eth0"]["bandwidth"]*2
simulator.update_network({"wlan0":{"bandwidth":new_bw_wlan0, "latency":L},"eth0":{"bandwidth":new_bw_eth0, "latency":L}})
simulator.update_network({"wlan0":{"bandwidth":new_bw_wlan0, "latency":L, "is_wired":False}, "eth0":{"bandwidth":new_bw_eth0, "latency":L, "is_wired":True}})
s.run(breakpoints_every=1,breakpoint_callback=callback,debug=True)

View file

@ -27,7 +27,7 @@ import numpy as np
B=np.full((2,2),8)
L=np.full((2,2),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("sender")
s.create_node("receiver")
@ -36,6 +36,6 @@ def callback(simulator):
simulator.log("Network update!")
new_lat_wlan0=simulator.netmat["wlan0"]["latency"]+1/2
new_lat_eth0=simulator.netmat["eth0"]["latency"]+1/2
simulator.update_network({"wlan0":{"bandwidth":B, "latency":new_lat_wlan0},"eth0":{"bandwidth":B, "latency":new_lat_eth0}})
simulator.update_network({"wlan0":{"bandwidth":B, "latency":new_lat_wlan0, "is_wired":False},"eth0":{"bandwidth":B, "latency":new_lat_eth0, "is_wired":True}})
s.run(breakpoints_every=1/2,breakpoint_callback=callback)

View file

@ -29,7 +29,7 @@ import numpy as np
B=np.full((3,3),8)
L=np.full((3,3),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("sender")
s.create_node("sender")
@ -39,6 +39,6 @@ def callback(simulator):
simulator.log("Network update!")
new_lat_wlan0=simulator.netmat["wlan0"]["latency"]+1/2
new_lat_eth0=simulator.netmat["eth0"]["latency"]+1/2
simulator.update_network({"wlan0":{"bandwidth":B, "latency":new_lat_wlan0},"eth0":{"bandwidth":B, "latency":new_lat_eth0}})
simulator.update_network({"wlan0":{"bandwidth":B, "latency":new_lat_wlan0, "is_wired":False},"eth0":{"bandwidth":B, "latency":new_lat_eth0, "is_wired":True}})
s.run(breakpoints_every=1,breakpoint_callback=callback,debug=True)

View file

@ -26,7 +26,7 @@ import numpy as np
B=np.full((2,2),8)
L=np.full((2,2),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("sender")
s.create_node("receiver")
@ -35,7 +35,7 @@ def callback(simulator):
simulator.log("Network update!")
new_bw_wlan0=simulator.netmat["wlan0"]["bandwidth"]*2
new_bw_eth0=simulator.netmat["eth0"]["bandwidth"]*2
simulator.update_network({"wlan0":{"bandwidth":new_bw_wlan0, "latency":L},"eth0":{"bandwidth":new_bw_eth0, "latency":L}})
simulator.update_network({"wlan0":{"bandwidth":new_bw_wlan0, "latency":L, "is_wired":False}, "eth0":{"bandwidth":new_bw_eth0, "latency":L, "is_wired":True}})
s.run(breakpoints_every=1/2,breakpoint_callback=callback)

View file

@ -27,7 +27,7 @@ import numpy as np
B=np.full((2,2),8)
L=np.full((2,2),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("sender")
s.create_node("receiver")
@ -36,7 +36,7 @@ def callback(simulator):
simulator.log("Network update!")
new_lat_wlan0=simulator.netmat["wlan0"]["latency"]+1/2
new_lat_eth0=simulator.netmat["eth0"]["latency"]+1/2
simulator.update_network({"wlan0":{"bandwidth":B, "latency":new_lat_wlan0},"eth0":{"bandwidth":B, "latency":new_lat_eth0}})
simulator.update_network({"wlan0":{"bandwidth":B, "latency":new_lat_wlan0, "is_wired":False},"eth0":{"bandwidth":B, "latency":new_lat_eth0, "is_wired":True}})
s.run(breakpoints_every=1/2,breakpoint_callback=callback)

View file

@ -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({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("node")
s.create_node("node")

View file

@ -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({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("node")
s.create_node("node")

View file

@ -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({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("node")
s.create_node("node")

View file

@ -8,7 +8,7 @@ import numpy as np
B=np.full((5,5),5)
L=np.full((5,5),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("node")
s.create_node("node")

View file

@ -8,7 +8,7 @@ import numpy as np
B=np.full((2,2),2)
L=np.full((2,2),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("node")
s.create_node("node")

View file

@ -8,7 +8,7 @@ import numpy as np
B=np.full((3,3),3)
L=np.full((3,3),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("sender")
s.create_node("sender")

View file

@ -8,7 +8,7 @@ import numpy as np
B=np.full((3,3),3)
L=np.full((3,3),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("sender")
s.create_node("sender")

View file

@ -8,7 +8,7 @@ import numpy as np
B=np.full((2,2),8)
L=np.full((2,2),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("sender")
s.create_node("receiver")

View file

@ -8,7 +8,7 @@ import numpy as np
B=np.full((2,2),8)
L=np.full((2,2),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("sender")
s.create_node("receiver")

View file

@ -8,7 +8,7 @@ import numpy as np
B=np.full((3,3),8)
L=np.full((3,3),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("sender")
s.create_node("sender")

View file

@ -8,7 +8,7 @@ import numpy as np
B=np.full((4,4),8)
L=np.full((4,4),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("sender")
s.create_node("sender")

View file

@ -8,7 +8,7 @@ import numpy as np
B=np.full((3,3),8)
L=np.full((3,3),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("sender")
s.create_node("receiver")

View file

@ -8,7 +8,7 @@ import numpy as np
B=np.full((3,3),8)
L=np.full((3,3),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("sender")
s.create_node("sender")

View file

@ -8,7 +8,7 @@ import numpy as np
B=np.full((2,2),8)
L=np.full((2,2),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("sender")
s.create_node("receiver")

View file

@ -8,7 +8,7 @@ import numpy as np
B=np.full((3,3),8)
L=np.full((3,3),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("sender")
s.create_node("receiver")

View file

@ -8,7 +8,7 @@ import numpy as np
B=np.full((2,2),2)
L=np.full((2,2),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("node")
s.create_node("node")

View file

@ -8,7 +8,7 @@ import numpy as np
B=np.full((3,3),2)
L=np.full((3,3),0)
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L},"eth0":{"bandwidth":B, "latency":L}})
s=esds.Simulator({"wlan0":{"bandwidth":B, "latency":L, "is_wired":False}, "eth0":{"bandwidth":B, "latency":L, "is_wired":True}})
s.create_node("node")
s.create_node("node")