Debug plugins

This commit is contained in:
Loic Guegan 2022-09-07 13:23:41 +02:00
parent 2fb979cfec
commit 057cb9c3ff
4 changed files with 13 additions and 12 deletions

View file

@ -34,7 +34,7 @@ class Node:
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])
p.on_communication_end(args[0],args[1])
if reason == "terminated":
p.on_terminated()

View file

@ -24,7 +24,7 @@ class NodePlugin:
def on_terminated(self):
pass
def on_communication_end(self,interface,data,start_at,end_at,aborted_at):
def on_communication_end(self,time,com_event):
pass
def log(self,msg):

View file

@ -122,6 +122,9 @@ class PowerStatesComms(NodePlugin):
def on_send_call(self,interface,data,datasize,dst):
self.tx_clock=self.api.read("clock")
def on_communication_end(self,time,com_event):
pass
def on_send_return(self,interface,data,datasize,dst,code):
clock=self.api.read("clock")
duration=(clock-float(self.tx_clock))

View file

@ -188,23 +188,21 @@ class Simulator:
self.log("Turned on",node=node.node_id)
elif node["request"] == "turn_off":
# Create communications selectors (True/False arrays)
selector_wireless=list() # Select all wireless events where node is involved
selector_wired=list() # Select all wired events where node is involved
selector_wireless=list() # Select all wireless events where node is receiver
selector_wired=list() # Select all wired events where node is receiver
for event in self.events:
if event[0]==0 and int(event[2][1])==node.node_id:
if self.netmat[event[2][2]]["is_wired"]:
selector_wireless.append(False)
if event[2][9]: # Check if should be cancel on turn_off (receiver_required)
selector_wired.append(True)
self.nodes[int(event[2][1])].rqueue.put(("plugin_notify","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)
self.notify_node_plugins(self.nodes[int(event[2][1])], "on_communication_end", (self.time,event))
else:
selector_wireless.append(False)
selector_wired.append(False)
@ -237,7 +235,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
self.notify_node_plugins(node, "on_communication_end", (self.time,event))
else:
selector.append(False)
self.events=self.events[~np.array(selector)]
@ -440,13 +438,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.notify_node_plugins(dst, "on_communication_end", (self.time,event))
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
self.notify_node_plugins(src, "on_communication_end", (self.time,event))
else:
if src.node_id != dst.node_id:
if perform_delivery:
@ -459,12 +457,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
self.notify_node_plugins(dst, "on_communication_end", (self.time,event))
else:
src["state"]="running"
src.rqueue.put(("send",0))
self.sync_node_non_blocking(src,timeout_remove_only=True)
# TODO: notify sender plugins
self.notify_node_plugins(src, "on_communication_end", (self.time,event))
elif event_type == 1: # Timeout
node=self.nodes[int(event)]
node["state"]="running"