summaryrefslogtreecommitdiff
path: root/esds
diff options
context:
space:
mode:
Diffstat (limited to 'esds')
-rw-r--r--esds/node.py9
-rw-r--r--esds/plugins/node_plugin.py3
-rw-r--r--esds/simulator.py13
3 files changed, 23 insertions, 2 deletions
diff --git a/esds/node.py b/esds/node.py
index 6a2566d..59b6f96 100644
--- a/esds/node.py
+++ b/esds/node.py
@@ -13,7 +13,7 @@ class Node:
self.rargs=None # Store the requests arguments
self.plugins=list() # Contains all registered node plugins
self.rqueue=queue.Queue() # Receive simulator acknowledgments
- self.chest={"state":"running", "turned_on":True, "request": None, "interfaces":dict(), "interfaces_queue_size":dict()}
+ self.chest={"state":"running", "turned_on":True, "request": None, "interfaces":dict(), "interfaces_queue_size":dict(), "plugin_notify": dict()}
for interface in interfaces:
self.chest["interfaces"][interface]=queue.Queue()
self.chest["interfaces_queue_size"][interface]=0
@@ -22,6 +22,11 @@ class Node:
def plugin_register(self,plugin):
self.plugins.append(plugin)
+ def plugin_handle_requests(self):
+ # Take plugins notification into account
+ for key in list(self["plugin_notify"]):
+ self.plugin_notify(key,self["plugin_notify"].pop(key))
+
def plugin_notify(self,reason,args):
"""
This function strives to avoid using Python specific features
@@ -33,6 +38,8 @@ class Node:
p.on_send_call(args[0],args[1],args[2],args[3])
if reason == "send_return":
p.on_send_return(args[0],args[1],args[2],args[3],args[4])
+ if reason == "on_communication_end":
+ p.on_communication_end(args[0],args[1],args[2],args[3],args[4])
if reason == "terminated":
p.on_terminated()
diff --git a/esds/plugins/node_plugin.py b/esds/plugins/node_plugin.py
index 325ff8a..dc9302f 100644
--- a/esds/plugins/node_plugin.py
+++ b/esds/plugins/node_plugin.py
@@ -24,6 +24,9 @@ class NodePlugin:
def on_terminated(self):
pass
+ def on_communication_end(self,interface,data,start_at,end_at,aborted_at):
+ self.log("hello world")
+
def log(self,msg):
self.api.log(self.plugin_name+"(NP) "+msg)
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"