From 57f020e09d738e283520e8cfc88b4cdd1aeaa551 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Thu, 8 Sep 2022 16:53:21 +0200 Subject: [PATCH] Debug plugins callbacks and synchronization --- esds/plugins/power_states.py | 20 ++++++-------------- esds/simulator.py | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/esds/plugins/power_states.py b/esds/plugins/power_states.py index b5349fd..e5a0e19 100644 --- a/esds/plugins/power_states.py +++ b/esds/plugins/power_states.py @@ -115,21 +115,13 @@ class PowerStatesComms(NodePlugin): self.tx_clock=0 # Dynamic clock (store the time at which a the last tx starts self.idle_clock=api.read("clock") # Store the start time (to compute the idle part of the energy consumption) - def on_receive_return(self,interface,data,start_at,end_at): - duration=float(end_at)-float(start_at) - self.energy_dynamic+=self.power[interface]["rx"]*duration - - def on_send_call(self,interface,data,datasize,dst): - self.tx_clock=self.api.read("clock") - def on_communication_end(self,time,com_event): - print(com_event) - - def on_send_return(self,interface,data,datasize,dst,code): - clock=self.api.read("clock") - duration=(clock-float(self.tx_clock)) - self.energy_dynamic+=self.power[interface]["tx"]*duration - self.tx_clock=clock # Any value could be use here + content=com_event[2] + dataSize=content[4] + duration=time-content[7] + interface=content[2] + mode= "tx" if content[0] == self.api.node_id else "rx" + self.energy_dynamic+=self.power[interface][mode]*duration def set_power(self,interface,idle,tx,rx): self.power[interface]=dict() diff --git a/esds/simulator.py b/esds/simulator.py index 4f2eb71..b774468 100644 --- a/esds/simulator.py +++ b/esds/simulator.py @@ -202,7 +202,9 @@ class Simulator: else: selector_wireless.append(True) selector_wired.append(False) + # Call the sender/receiver callbacks self.notify_node_plugins(self.nodes[int(event[2][1])], "on_communication_end", event) + self.notify_node_plugins(self.nodes[int(event[2][0])], "on_communication_end", event) else: selector_wireless.append(False) selector_wired.append(False) @@ -235,7 +237,9 @@ class Simulator: selector.append(True) if self.netmat[event[2][2]]["is_wired"]: sharing_to_update.append((int(event[2][1]),event[2][2])) - self.notify_node_plugins(node, "on_communication_end", event) + self.notify_node_plugins(node, "on_communication_end", event) + elif int(event[2][0]) == int(event[2][1]): # If it is the sender event of a wireless communication (when sender_id==receiver_id) + self.notify_node_plugins(node, "on_communication_end", event) else: selector.append(False) self.events=self.events[~np.array(selector)] @@ -310,7 +314,10 @@ class Simulator: if not (dst >=0 and dst <=len(self.nodes)): self.log("Invalid dst used in send() or sendt(), node "+str(dst)+" not found", node=node.node_id) exit(1) - self.communicate(interface, node.node_id, dst, data, datasize,receiver_required) + if not self.communicate(interface, node.node_id, dst, data, datasize,receiver_required): + node["state"]="running" + node.rqueue.put(("send",4)) + self.sync_node_non_blocking(node,timeout_remove_only=True) elif node["request"] == "receive": interface=node.rargs if node["interfaces_queue_size"][interface] > 0: @@ -332,6 +339,8 @@ class Simulator: nsrc=self.nodes[src] if self.netmat[interface]["is_wired"]: self.log("Send "+str(datasize)+" bytes to n"+str(dst)+" on "+interface,node=src) + if not self.nodes[dst]["turned_on"] and receiver_required: + return(False) 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[interface]["bandwidth"][src,dst]/self.sharing[interface][dst])+self.netmat[interface]["latency"][src,dst] @@ -349,7 +358,7 @@ class Simulator: self.add_event(0,duration+self.time,(src,dst,interface,data,datasize,duration,datasize,self.time,True,False)) elif not self.handle_interferences(src,dst, interface): self.add_event(0,duration+self.time,(src,dst,interface,data,datasize,duration,datasize,self.time,True,False)) - + return(True) def list_receivers(self,node,interface): """ Deduce reachable receivers from the bandwidth matrix