summaryrefslogtreecommitdiff
path: root/esds/simulator.py
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-08-31 11:25:48 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2022-08-31 11:25:48 +0200
commitc63ae59a81c8ace0c243bfa2ab265eff61ea6cfe (patch)
treeb9e53731c869fdd07625ab2c87cd00444db4a99e /esds/simulator.py
parent5384940ca79bc49b2240a10337aa1c6f6031efa3 (diff)
Add manual and improve node plugins system
Diffstat (limited to 'esds/simulator.py')
-rw-r--r--esds/simulator.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/esds/simulator.py b/esds/simulator.py
index fee9331..57dda4e 100644
--- a/esds/simulator.py
+++ b/esds/simulator.py
@@ -123,7 +123,10 @@ class Simulator:
"""
sorted_indexes=np.lexsort((self.events[:,3],self.events[:,1]))
self.events=self.events[sorted_indexes]
-
+
+ def notify_node_plugin(self,node,function,args):
+ self.nodes[node]["plugin_notify"][function]=args
+
def sync_node_non_blocking(self,node, timeout_remove_only=False):
"""
Process all call request and wait for Node.sync() to return
@@ -196,11 +199,14 @@ class Simulator:
selector_wireless.append(False)
if event[2][9]: # Check if should be cancel on turn_off (receiver_required)
selector_wired.append(True)
+ self.notify_node_plugin(event[2][1],"on_communication_end",("eth0",0,0,0,0))
else:
selector_wired.append(False)
event[2][8]=False # So set delivery to False!!
+ # TODO: notify receiver plugins
else:
selector_wireless.append(True)
+ # TODO: notify receiver plugins
selector_wired.append(False)
else:
selector_wireless.append(False)
@@ -234,6 +240,7 @@ class Simulator:
selector.append(True)
if self.netmat[event[2][2]]["is_wired"]:
sharing_to_update.append((int(event[2][1]),event[2][2]))
+ # TODO: notify sender plugins
else:
selector.append(False)
self.events=self.events[~np.array(selector)]
@@ -427,11 +434,13 @@ class Simulator:
dst["state"]="running"
dst.rqueue.put(("receive",0))
self.sync_node_non_blocking(dst,timeout_remove_only=True)
+ # TODO: notify receiver plugins
self.update_sharing(dst.node_id,-1,interface)
src["state"]="running"
code=0 if perform_delivery else 1
src.rqueue.put(("send",code))
self.sync_node_non_blocking(src,timeout_remove_only=True)
+ # TODO: notify sender plugins
else:
if src.node_id != dst.node_id:
if perform_delivery:
@@ -444,10 +453,12 @@ class Simulator:
dst["state"]="running"
dst.rqueue.put(("receive",0))
self.sync_node_non_blocking(dst,timeout_remove_only=True)
+ # TODO: notify receiver plugins
else:
src["state"]="running"
src.rqueue.put(("send",0))
self.sync_node_non_blocking(src,timeout_remove_only=True)
+ # TODO: notify sender plugins
elif event_type == 1: # Timeout
node=self.nodes[int(event)]
node["state"]="running"