summaryrefslogtreecommitdiff
path: root/esds/simulator.py
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-06-29 09:37:27 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2023-06-29 09:37:27 +0200
commite082a7b51983b4a277243f9bb02d3b5126b4b74a (patch)
tree3c0d2751465e04f7621aa817f91a0548990fb184 /esds/simulator.py
parent9a1578ae752075cbe4e0c658307d037cb18b56c9 (diff)
Interfaces are now assigned to specific nodes
Diffstat (limited to 'esds/simulator.py')
-rw-r--r--esds/simulator.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/esds/simulator.py b/esds/simulator.py
index 2253a49..30534de 100644
--- a/esds/simulator.py
+++ b/esds/simulator.py
@@ -75,11 +75,15 @@ class Simulator:
event[2][5]=new_duration
self.netmat=netmat
- def create_node(self, src, args=None, grp="def"):
+ def create_node(self, src, interfaces=[], args=None, grp="def"):
"""
Create a node thread and run it
"""
- node=Node(src, self.netmat.keys(), grp)
+ for intf in interfaces:
+ if intf not in self.netmat.keys():
+ self.log("Cannot create node "+str(Node.available_node_id)+": interface "+ intf + " unknown")
+ exit(1)
+ node=Node(src, interfaces, grp)
self.nodes.append(node)
thread=threading.Thread(target=node.run,args=[args]) # There must be "daemon=True" as a parameter, but we removed it to be compatible with older version of python
thread.start()
@@ -324,6 +328,9 @@ class Simulator:
"""
nsrc=self.nodes[src]
if self.netmat[interface]["is_wired"]:
+ if interface not in self.nodes[dst]["interfaces"]:
+ self.log("Cannot create communication from node "+str(src)+ " to "+str(dst)+", interface "+interface+" not available on node "+str(dst))
+ exit(1)
self.log("Send "+str(datasize)+" bytes to n"+str(dst)+" on "+interface,node=nsrc)
if not self.nodes[dst]["turned_on"] and receiver_required:
return(False)
@@ -334,7 +341,7 @@ class Simulator:
else:
self.log("Send "+str(datasize)+" bytes on "+interface,node=nsrc)
for dst in self.list_receivers(nsrc,interface):
- if self.nodes[dst]["turned_on"]:
+ if interface in self.nodes[dst]["interfaces"] and self.nodes[dst]["turned_on"]:
duration=datasize*8/self.netmat[interface]["bandwidth"][src,dst]+self.netmat[interface]["latency"][src,dst]
if src == dst:
# This event (where src == dst) is used to notify the sender when data is received!
@@ -347,7 +354,7 @@ class Simulator:
return(True)
def list_receivers(self,node,interface):
"""
- Deduce reachable receivers from the bandwidth matrix
+ Deduce reachable receivers from the bandwidth matrix (sender is included in the list!)
"""
selector = self.netmat[interface]["bandwidth"][node.node_id,] > 0
return np.arange(0,selector.shape[0])[selector]