Removing several ref to wlan0

This commit is contained in:
Loic Guegan 2022-06-11 09:40:40 +02:00
parent d2a5ea6f53
commit fa09187031

67
esds.py
View file

@ -195,9 +195,7 @@ class Simulator:
def __init__(self,netmat):
"""
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.
Format of netmat: { "interface": {"bandwidth": matrix, "latency": matrix, "is_wired":bool}}
"""
self.netmat=netmat
self.nodes=list()
@ -229,10 +227,10 @@ class Simulator:
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
else:
if self.netmat[interface]["is_wired"]:
new_duration=new_datasize_remaining*8/(new_bw/self.sharing[interface][int(dst_id)])+new_lat*latency_factor
else:
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
@ -369,7 +367,7 @@ class Simulator:
for event in self.events:
if event[0]==0 and int(event[2][0]) == node.node_id:
selector.append(True)
if event[2][2] != "wlan0":
if self.netmat[event[2][2]]["is_wired"]:
self.update_sharing(int(event[2][1]),-1,event[2][2])
else:
selector.append(False)
@ -385,7 +383,7 @@ class Simulator:
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:
if event[0] == 0 and self.netmat[event[2][2]]["is_wired"] and int(event[2][1]) == dst:
remaining=event[1]-self.time
if remaining > 0:
remaining=remaining/sharing if sharing>1 else remaining # First restore sharing
@ -457,28 +455,27 @@ class Simulator:
Create communication event between src and dst
"""
nsrc=self.nodes[src]
if interface=="wlan0":
if self.netmat[interface]["is_wired"]:
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,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[interface]["bandwidth"][src,dst]/self.sharing[interface][dst])+self.netmat[interface]["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
else:
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.netmat["wlan0"]["bandwidth"][src,dst]+self.netmat["wlan0"]["latency"][src,dst]
duration=datasize*8/self.netmat[interface]["bandwidth"][src,dst]+self.netmat[interface]["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:
self.add_event(0,duration+self.time,(src,dst,interface,data,datasize,duration,datasize,self.time))
elif not self.handle_interferences(src,dst):
self.add_event(0,duration+self.time,(src,dst,interface,data,datasize,duration,datasize,self.time))
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,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["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
def list_wireless_receivers(self,node):
"""
Deduce reachable receivers from the bandwidth matrix
@ -547,7 +544,20 @@ class Simulator:
src_id,dst_id,interface, data, datasize,duration,datasize_remaining,start_at=event
src=self.nodes[int(src_id)]
dst=self.nodes[int(dst_id)]
if interface == "wlan0":
if self.netmat[interface]["is_wired"]:
dst["interfaces"][interface].put((data,start_at,self.time))
dst["interfaces_queue_size"][interface]+=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":
dst["interfaces_queue_size"][interface]-=1
dst.rqueue.put(("receive",0))
dst["state"]="running"
self.sync_node(dst)
src["state"]="running"
src.rqueue.put(("send",0))
else:
if src.node_id != dst.node_id:
dst["interfaces"][interface].put((data,start_at,self.time))
dst["interfaces_queue_size"][interface]+=1
@ -561,19 +571,6 @@ class Simulator:
else:
src["state"]="running"
src.rqueue.put(("send",0))
else:
dst["interfaces"][interface].put((data,start_at,self.time))
dst["interfaces_queue_size"][interface]+=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":
dst["interfaces_queue_size"][interface]-=1
dst.rqueue.put(("receive",0))
dst["state"]="running"
self.sync_node(dst)
src["state"]="running"
src.rqueue.put(("send",0))
elif event_type == 1:
node=self.nodes[int(event)]
node["state"]="running"