summaryrefslogtreecommitdiff
path: root/esds.py
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-06-10 21:58:15 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2022-06-10 21:58:15 +0200
commitd2a5ea6f539c5d6b737bd7bd37f45791220431a7 (patch)
treec809877ee14f76eb754c981a631940a2b47d2f0d /esds.py
parent3fef2bbf4ba898fc932d515b864f4d9351798ef9 (diff)
Make one sharing matrix per wired interface
Diffstat (limited to 'esds.py')
-rw-r--r--esds.py33
1 files changed, 19 insertions, 14 deletions
diff --git a/esds.py b/esds.py
index 20763b6..ad594c1 100644
--- a/esds.py
+++ b/esds.py
@@ -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":