Debug synchronization + add return code

This commit is contained in:
Loic Guegan 2022-09-09 13:16:42 +02:00
parent 57f020e09d
commit cfa677a0c6
21 changed files with 107 additions and 71 deletions

View file

@ -1,4 +1,5 @@
__all__ = ["simulator", "node", "plugins", "helpers"] __all__ = ["simulator", "node", "plugins", "helpers", "rcode"]
from esds.simulator import Simulator from esds.simulator import Simulator
from esds.rcode import RCode

View file

@ -1,4 +1,5 @@
import threading,importlib,queue import threading,importlib,queue
from esds.rcode import RCode
class Node: class Node:
available_node_id=0 available_node_id=0
@ -22,7 +23,7 @@ class Node:
def plugin_register(self,plugin): def plugin_register(self,plugin):
self.plugins.append(plugin) self.plugins.append(plugin)
def plugin_notify(self,reason,args,time=None): def plugin_notify(self,reason,args=None,time=None):
""" """
This function strives to avoid using Python specific features This function strives to avoid using Python specific features
""" """
@ -35,6 +36,10 @@ class Node:
p.on_send_return(args[0],args[1],args[2],args[3],args[4]) p.on_send_return(args[0],args[1],args[2],args[3],args[4])
if reason == "on_communication_end": if reason == "on_communication_end":
p.on_communication_end(time,args) p.on_communication_end(time,args)
if reason == "turn_off_return":
p.on_turn_off()
if reason == "turn_on_return":
p.on_turn_on()
if reason == "terminated": if reason == "terminated":
p.on_terminated() p.on_terminated()
@ -96,12 +101,14 @@ class Node:
self["request"]="turn_off" self["request"]="turn_off"
self["state"]="call_non_blocking" self["state"]="call_non_blocking"
self.wait_ack(["turn_off"]) self.wait_ack(["turn_off"])
self.plugin_notify("turn_off_return")
def turn_on(self): def turn_on(self):
self["turned_on"]=True self["turned_on"]=True
self["request"]="turn_on" self["request"]="turn_on"
self["state"]="call_non_blocking" self["state"]="call_non_blocking"
self.wait_ack(["turn_on"]) self.wait_ack(["turn_on"])
self.plugin_notify("turn_on_return")
def send(self, interface, data, datasize, dst, receiver_required=False): def send(self, interface, data, datasize, dst, receiver_required=False):
if interface not in self["interfaces"]: if interface not in self["interfaces"]:
@ -141,7 +148,7 @@ class Node:
self["request"]="send" self["request"]="send"
self["state"]="call_blocking" self["state"]="call_blocking"
ack=self.wait_ack(["send","timeout","send_cancel"]) ack=self.wait_ack(["send","timeout","send_cancel"])
status=-1 status=RCode.TIMEOUT_EXPIRE
if ack[0] == "timeout": if ack[0] == "timeout":
self["request"]="send_cancel" self["request"]="send_cancel"
self["state"]="call_non_blocking" self["state"]="call_non_blocking"
@ -164,7 +171,7 @@ class Node:
self.wait_ack(["receive"]) self.wait_ack(["receive"])
data,start_at,end_at=self["interfaces"][interface].get() data,start_at,end_at=self["interfaces"][interface].get()
self.plugin_notify("receive_return",(interface,data,start_at,end_at)) self.plugin_notify("receive_return",(interface,data,start_at,end_at))
return (0,data) return (RCode.SUCCESS,data)
def receivet(self,interface, timeout): def receivet(self,interface, timeout):
if interface not in self["interfaces"]: if interface not in self["interfaces"]:
@ -183,14 +190,14 @@ class Node:
self.rargs=interface self.rargs=interface
self["state"]="call_blocking" self["state"]="call_blocking"
ack=self.wait_ack(["receive","timeout"]) ack=self.wait_ack(["receive","timeout"])
result=(-1,None) result=(RCode.TIMEOUT_EXPIRE,None)
if ack[0] != "timeout": if ack[0] != "timeout":
self["request"]="timeout_remove" self["request"]="timeout_remove"
self["state"]="call_non_blocking" self["state"]="call_non_blocking"
self.wait_ack(["timeout_remove"]) self.wait_ack(["timeout_remove"])
data,start_at,end_at=self["interfaces"][interface].get() data,start_at,end_at=self["interfaces"][interface].get()
self.plugin_notify("receivet_return",(interface,data,start_at,end_at)) self.plugin_notify("receivet_return",(interface,data,start_at,end_at))
result=(0,data) result=(RCode.SUCCESS,data)
return result return result
def wait_ack(self, ack_types): def wait_ack(self, ack_types):

View file

@ -26,6 +26,12 @@ class NodePlugin:
def on_communication_end(self,time,com_event): def on_communication_end(self,time,com_event):
pass pass
def on_turn_on(self):
pass
def on_turn_off(self):
pass
def log(self,msg): def log(self,msg):
self.api.log(self.plugin_name+"(NP) "+msg) self.api.log(self.plugin_name+"(NP) "+msg)

View file

@ -110,10 +110,7 @@ class PowerStatesComms(NodePlugin):
def __init__(self,api): def __init__(self,api):
super().__init__("PowerStatesComms",api) super().__init__("PowerStatesComms",api)
self.energy_dynamic=0.0 # Store the dynamic part of the energy consumption
self.power=dict() # Store the power states self.power=dict() # Store the power states
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_communication_end(self,time,com_event): def on_communication_end(self,time,com_event):
content=com_event[2] content=com_event[2]
@ -121,39 +118,39 @@ class PowerStatesComms(NodePlugin):
duration=time-content[7] duration=time-content[7]
interface=content[2] interface=content[2]
mode= "tx" if content[0] == self.api.node_id else "rx" mode= "tx" if content[0] == self.api.node_id else "rx"
self.energy_dynamic+=self.power[interface][mode]*duration self.power[interface]["consumption_dynamic"]+=self.power[interface][mode]*duration
if self.api.node_id==0:
print("called with +{}J".format(self.power[interface][mode]*duration))
def set_power(self,interface,idle,tx,rx): def set_power(self,interface,idle,tx,rx):
self.power[interface]=dict() self.power[interface]=dict()
self.power[interface]["idle"]=idle self.power[interface]["idle"]=idle
self.power[interface]["rx"]=rx self.power[interface]["rx"]=rx
self.power[interface]["tx"]=tx self.power[interface]["tx"]=tx
self.power[interface]["on_at"]=self.api.read("clock")
self.power[interface]["consumption_idle"]=0
self.power[interface]["consumption_dynamic"]=0
def get_idle(self): def on_turn_on(self):
clock=self.api.read("clock")
idle=0
for interface in self.power.keys(): for interface in self.power.keys():
idle+=(clock-self.idle_clock)*self.power[interface]["idle"] self.power[interface]["on_at"]=self.api.read("clock")
return idle
def on_turn_off(self):
self.sync_idle()
self.log("Consumes "+str(self.get_energy()))
def get_receive_queue_energy(self,interface): def sync_idle(self):
""" clock=self.api.read("clock")
Not that call to on_receive_return may not have happened yet (or never). for interface in self.power.keys():
Thus we should manually compute the energy consumption stored in each queues of the node. self.power[interface]["consumption_idle"]+=(clock-self.power[interface]["on_at"])*self.power[interface]["idle"]
""" self.power[interface]["on_at"]=clock
energy=0
# For each interface we should check if there is received data that has not been consumed
for data in list(self.api["interfaces"][interface].queue):
start_at=float(data[1])
end_at=float(data[2])
energy+=(end_at-start_at)*self.power[interface]["rx"]
return energy
def get_energy(self): def get_energy(self):
queue_energy=0 self.sync_idle()
consumption=0
for interface in self.power.keys(): for interface in self.power.keys():
queue_energy+=self.get_receive_queue_energy(interface) consumption+=self.power[interface]["consumption_idle"]+self.power[interface]["consumption_dynamic"]
return self.get_idle()+self.energy_dynamic+queue_energy return consumption
def report_energy(self): def report_energy(self):
self.log("Communications consumed "+str(round(self.get_energy(),2))+"J") self.log("Communications consumed "+str(round(self.get_energy(),2))+"J")

9
esds/rcode.py Normal file
View file

@ -0,0 +1,9 @@
from enum import Enum
class RCode(Enum):
SUCCESS = 0
FAIL = 1
TIMEOUT_EXPIRE = 2
RECEIVER_TURNED_OFF = 3
RECEIVER_UNAVAILABLE = 4

View file

@ -1,6 +1,7 @@
import numpy as np import numpy as np
import threading,sys,time import threading,sys,time
from esds.node import Node from esds.node import Node
from esds.rcode import RCode
class Simulator: class Simulator:
""" """
@ -139,22 +140,22 @@ class Simulator:
selector.append(False) selector.append(False)
self.events=self.events[~np.array(selector)] self.events=self.events[~np.array(selector)]
node["state"]="running" node["state"]="running"
node.rqueue.put(("timeout_remove",0)) node.rqueue.put(("timeout_remove",RCode.SUCCESS))
elif timeout_remove_only: elif timeout_remove_only:
break break
elif not timeout_remove_only: elif not timeout_remove_only:
if node["request"] == "log": if node["request"] == "log":
self.log(node.rargs,node=node.node_id) self.log(node.rargs,node=node.node_id)
node["state"]="running" node["state"]="running"
node.rqueue.put(("log",0)) node.rqueue.put(("log",RCode.SUCCESS))
elif node["request"] == "timeout_add": elif node["request"] == "timeout_add":
self.add_event(1,self.time+node.rargs,node.node_id,priority=3) self.add_event(1,self.time+node.rargs,node.node_id,priority=3)
node["state"]="running" node["state"]="running"
node.rqueue.put(("timeout_add",0)) node.rqueue.put(("timeout_add",RCode.SUCCESS))
elif node["request"] == "notify_add": elif node["request"] == "notify_add":
self.add_event(4,self.time+node.rargs,node.node_id,priority=0) self.add_event(4,self.time+node.rargs,node.node_id,priority=0)
node["state"]="running" node["state"]="running"
node.rqueue.put(("notify_add",0)) node.rqueue.put(("notify_add",RCode.SUCCESS))
elif node["request"] == "notify_remove": elif node["request"] == "notify_remove":
selector=list() selector=list()
for event in self.events: for event in self.events:
@ -164,7 +165,7 @@ class Simulator:
selector.append(False) selector.append(False)
self.events=self.events[~np.array(selector)] self.events=self.events[~np.array(selector)]
node["state"]="running" node["state"]="running"
node.rqueue.put(("notify_remove",0)) node.rqueue.put(("notify_remove",RCode.SUCCESS))
elif node["request"] == "abort": elif node["request"] == "abort":
self.log("Simulation aborted: "+node.rargs,node=node.node_id) self.log("Simulation aborted: "+node.rargs,node=node.node_id)
exit(1) exit(1)
@ -184,7 +185,7 @@ class Simulator:
node.rqueue.put(("read",0)) # Always return 0 if register is unknown node.rqueue.put(("read",0)) # Always return 0 if register is unknown
elif node["request"] == "turn_on": elif node["request"] == "turn_on":
node["state"]="running" node["state"]="running"
node.rqueue.put(("turn_on",0)) node.rqueue.put(("turn_on",RCode.SUCCESS))
self.log("Turned on",node=node.node_id) self.log("Turned on",node=node.node_id)
elif node["request"] == "turn_off": elif node["request"] == "turn_off":
# Create communications selectors (True/False arrays) # Create communications selectors (True/False arrays)
@ -209,7 +210,7 @@ class Simulator:
selector_wireless.append(False) selector_wireless.append(False)
selector_wired.append(False) selector_wired.append(False)
# Build the set of senders to notify (only in wired connections, # Build the set of senders to notify (only in wired connections,
# indeed IRL, in wireless communications sender would send all its data) # indeed IRL, in wireless communications, sender would send all its data)
senders_to_notify=set() senders_to_notify=set()
for event in self.events[selector_wired]: for event in self.events[selector_wired]:
senders_to_notify.add(int(event[2][0])) senders_to_notify.add(int(event[2][0]))
@ -218,14 +219,14 @@ class Simulator:
self.events=self.events[~(np.array(selector_wireless)|np.array(selector_wired))] self.events=self.events[~(np.array(selector_wireless)|np.array(selector_wired))]
# Update node state after turning off # Update node state after turning off
node["state"]="running" node["state"]="running"
node.rqueue.put(("turn_off",0)) node.rqueue.put(("turn_off",RCode.SUCCESS))
self.log("Turned off",node=node.node_id) self.log("Turned off",node=node.node_id)
# Informed senders of wired events that communication ended # Informed senders of wired events that communication ended
for sender_id in senders_to_notify: for sender_id in senders_to_notify:
# Notify sender (node that wired sharing is updated in the send_cancel request) # Notify sender (node that wired sharing is updated in the send_cancel request)
sender_node=self.nodes[sender_id] sender_node=self.nodes[sender_id]
sender_node["state"]="running" sender_node["state"]="running"
sender_node.rqueue.put(("send_cancel",2)) sender_node.rqueue.put(("send_cancel",RCode.RECEIVER_TURNED_OFF))
# The node should resume at current self.time. So, sync the sender now: # The node should resume at current self.time. So, sync the sender now:
self.sync_node_non_blocking(sender_node) self.sync_node_non_blocking(sender_node)
self.sync_node_blocking(sender_node) self.sync_node_blocking(sender_node)
@ -247,7 +248,7 @@ class Simulator:
for com in sharing_to_update: for com in sharing_to_update:
self.update_sharing(com[0],-1,com[1]) self.update_sharing(com[0],-1,com[1])
node["state"]="running" node["state"]="running"
node.rqueue.put(("send_cancel",0)) node.rqueue.put(("send_cancel",RCode.SUCCESS))
node.sync() node.sync()
def update_sharing(self, dst, amount,interface): def update_sharing(self, dst, amount,interface):
@ -316,20 +317,23 @@ class Simulator:
exit(1) exit(1)
if not 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["state"]="running"
node.rqueue.put(("send",4)) node.rqueue.put(("send",RCode.RECEIVER_UNAVAILABLE))
self.sync_node_non_blocking(node,timeout_remove_only=True) # Do not forget to collect the next event (since current event did not happend)
# Be careful in node implementation to have no infinite loop when receiver_required=True
self.sync_node_non_blocking(node)
self.sync_node_blocking(node)
elif node["request"] == "receive": elif node["request"] == "receive":
interface=node.rargs interface=node.rargs
if node["interfaces_queue_size"][interface] > 0: if node["interfaces_queue_size"][interface] > 0:
node["interfaces_queue_size"][interface]-=1 node["interfaces_queue_size"][interface]-=1
node["state"]="running" node["state"]="running"
node.rqueue.put(("receive",0)) node.rqueue.put(("receive",RCode.SUCCESS))
# Do not forget to collect the next event. This is the only request which is processed here # Do not forget to collect the next event. This is the only request which is processed here
self.sync_node_non_blocking(node) self.sync_node_non_blocking(node)
self.sync_node_blocking(node) self.sync_node_blocking(node)
elif node["request"] == "wait_end": elif node["request"] == "wait_end":
node["state"]="pending" node["state"]="pending"
node.rqueue.put(("wait_end",0)) node.rqueue.put(("wait_end",RCode.SUCCESS))
self.wait_end_nodes.append(node.node_id) self.wait_end_nodes.append(node.node_id)
def communicate(self, interface, src, dst, data, datasize,receiver_required): def communicate(self, interface, src, dst, data, datasize,receiver_required):
@ -413,10 +417,10 @@ class Simulator:
for node in self.nodes: for node in self.nodes:
if node["state"] != "terminated": if node["state"] != "terminated":
node["state"]="running" node["state"]="running"
node.rqueue.put(("sim_end",0)) node.rqueue.put(("sim_end",RCode.SUCCESS))
self.sync_node_non_blocking(node) # Allow them for make non-blocking call requests (printing logs for example) self.sync_node_non_blocking(node) # Allow them for make non-blocking call requests (printing logs for example)
else: else:
node.rqueue.put(("sim_end",0)) node.rqueue.put(("sim_end",RCode.SUCCESS))
break # End the event processing loop break # End the event processing loop
# Update simulation time # Update simulation time
@ -442,12 +446,12 @@ class Simulator:
if dst["state"] == "call_blocking" and dst["request"] == "receive": if dst["state"] == "call_blocking" and dst["request"] == "receive":
dst["interfaces_queue_size"][interface]-=1 dst["interfaces_queue_size"][interface]-=1
dst["state"]="running" dst["state"]="running"
dst.rqueue.put(("receive",0)) dst.rqueue.put(("receive",RCode.SUCCESS))
self.sync_node_non_blocking(dst,timeout_remove_only=True) self.sync_node_non_blocking(dst,timeout_remove_only=True)
self.notify_node_plugins(dst, "on_communication_end", event) self.notify_node_plugins(dst, "on_communication_end", event)
self.update_sharing(dst.node_id,-1,interface) self.update_sharing(dst.node_id,-1,interface)
src["state"]="running" src["state"]="running"
code=0 if perform_delivery else 1 code=RCode.SUCCESS if perform_delivery else RCode.FAIL
src.rqueue.put(("send",code)) src.rqueue.put(("send",code))
self.sync_node_non_blocking(src,timeout_remove_only=True) self.sync_node_non_blocking(src,timeout_remove_only=True)
self.notify_node_plugins(src, "on_communication_end", event) self.notify_node_plugins(src, "on_communication_end", event)
@ -461,23 +465,23 @@ class Simulator:
if dst["state"] == "call_blocking" and dst["request"] == "receive": if dst["state"] == "call_blocking" and dst["request"] == "receive":
dst["interfaces_queue_size"][interface]-=1 dst["interfaces_queue_size"][interface]-=1
dst["state"]="running" dst["state"]="running"
dst.rqueue.put(("receive",0)) dst.rqueue.put(("receive",RCode.SUCCESS))
self.sync_node_non_blocking(dst,timeout_remove_only=True) self.sync_node_non_blocking(dst,timeout_remove_only=True)
self.notify_node_plugins(dst, "on_communication_end", event) self.notify_node_plugins(dst, "on_communication_end", event)
else: else:
src["state"]="running" src["state"]="running"
src.rqueue.put(("send",0)) src.rqueue.put(("send",RCode.SUCCESS))
self.sync_node_non_blocking(src,timeout_remove_only=True) self.sync_node_non_blocking(src,timeout_remove_only=True)
self.notify_node_plugins(src, "on_communication_end", event) self.notify_node_plugins(src, "on_communication_end", event)
elif event_type == 1: # Timeout elif event_type == 1: # Timeout
node=self.nodes[int(event)] node=self.nodes[int(event)]
node["state"]="running" node["state"]="running"
node.rqueue.put(("timeout",0)) node.rqueue.put(("timeout",RCode.SUCCESS))
self.sync_node_non_blocking(node,timeout_remove_only=True) self.sync_node_non_blocking(node,timeout_remove_only=True)
elif event_type == 4: elif event_type == 4:
node=self.nodes[int(event)] node=self.nodes[int(event)]
node["state"]="running" node["state"]="running"
node.rqueue.put(("notify",0)) node.rqueue.put(("notify",RCode.SUCCESS))
self.sync_node_non_blocking(node,timeout_remove_only=True) self.sync_node_non_blocking(node,timeout_remove_only=True)
elif event_type == 2 or event_type == 3: elif event_type == 2 or event_type == 3:
breakpoint_callback(self) breakpoint_callback(self)

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys, random, time import sys, random, time
from esds import RCode
lr=random.Random(6) lr=random.Random(6)
@ -17,7 +18,7 @@ def execute(api):
# Receive until uptime seconds if elapsed # Receive until uptime seconds if elapsed
while api.read("clock") < wakeuntil: while api.read("clock") < wakeuntil:
code, data=api.receivet("wlan0",wakeuntil-api.read("clock")) code, data=api.receivet("wlan0",wakeuntil-api.read("clock"))
if code == 0: if code == RCode.SUCCESS:
api.log("Receive "+data) api.log("Receive "+data)
api.log("Was up for {}s".format(api.read("clock")-wakeat)) api.log("Was up for {}s".format(api.read("clock")-wakeat))
endoff=3600*(i+1)-api.read("clock") endoff=3600*(i+1)-api.read("clock")

View file

@ -136,6 +136,7 @@ called by the orchestrator to execute the code of your node. The api parameter p
#!/usr/bin/env python #!/usr/bin/env python
import sys, random, time import sys, random, time
from esds import RCode
lr=random.Random(6) lr=random.Random(6)
@ -152,7 +153,7 @@ called by the orchestrator to execute the code of your node. The api parameter p
# Receive until uptime seconds if elapsed # Receive until uptime seconds if elapsed
while api.read("clock") < wakeuntil: while api.read("clock") < wakeuntil:
code, data=api.receivet("wlan0",wakeuntil-api.read("clock")) code, data=api.receivet("wlan0",wakeuntil-api.read("clock"))
if code == 0: if code == RCode.SUCCESS:
api.log("Receive "+data) api.log("Receive "+data)
api.log("Was up for {}s".format(api.read("clock")-wakeat)) api.log("Was up for {}s".format(api.read("clock")-wakeat))
endoff=3600*(i+1)-api.read("clock") endoff=3600*(i+1)-api.read("clock")

View file

@ -1,5 +1,5 @@
[t=0.000,src=n0] Send 1 bytes to n1 on eth0 [t=0.000,src=n0] Send 1 bytes to n1 on eth0
[t=0.000,src=n1] Receive failed code=-1 [t=0.000,src=n1] Receive failed code=RCode.TIMEOUT_EXPIRE
[t=1.000,src=n1] Receive 1 bytes on eth0 [t=1.000,src=n1] Receive 1 bytes on eth0
[t=1.000,src=n1] Received: Hello World! [t=1.000,src=n1] Received: Hello World!
[t=1.000,src=esds] Simulation ends [t=1.000,src=esds] Simulation ends

View file

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
from esds import RCode
def receivet(node,timeout): def receivet(node,timeout):
##### Simple receive ##### Simple receive
code, data=node.receivet("eth0",timeout) code, data=node.receivet("eth0",timeout)
msg="Received: "+data if code == 0 else "Receive failed code="+str(code) msg="Received: "+data if code == RCode.SUCCESS else "Receive failed code="+str(code)
node.log(msg) node.log(msg)
def execute(api): def execute(api):

View file

@ -2,7 +2,7 @@
[t=1.000,src=n1] Receive 1 bytes on eth0 [t=1.000,src=n1] Receive 1 bytes on eth0
[t=1.000,src=n1] Received: Hello World! [t=1.000,src=n1] Received: Hello World!
[t=1.000,src=n0] Send 1 bytes to n1 on eth0 [t=1.000,src=n0] Send 1 bytes to n1 on eth0
[t=1.500,src=n1] Receive failed code=-1 [t=1.500,src=n1] Receive failed code=RCode.TIMEOUT_EXPIRE
[t=2.000,src=n1] Receive 1 bytes on eth0 [t=2.000,src=n1] Receive 1 bytes on eth0
[t=2.000,src=n1] Received: Hello World! [t=2.000,src=n1] Received: Hello World!
[t=2.000,src=esds] Simulation ends [t=2.000,src=esds] Simulation ends

View file

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
from esds import RCode
def receivet(node,timeout): def receivet(node,timeout):
##### Simple receive ##### Simple receive
code, data=node.receivet("eth0",timeout) code, data=node.receivet("eth0",timeout)
msg="Received: "+data if code == 0 else "Receive failed code="+str(code) msg="Received: "+data if code == RCode.SUCCESS else "Receive failed code="+str(code)
node.log(msg) node.log(msg)
def execute(api): def execute(api):

View file

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
from esds import RCode
def receive(api): def receive(api):
##### Simple receive ##### Simple receive
code, data=api.receive("eth0") code, data=api.receive("eth0")
msg="Received: "+data if code == 0 else "Receive failed code="+str(code) msg="Received: "+data if code == RCode.SUCCESS else "Receive failed code="+str(code)
api.log(msg) api.log(msg)
def execute(api): def execute(api):
@ -16,7 +17,7 @@ def execute(api):
receive(api) receive(api)
# Simulated time t=3s here # Simulated time t=3s here
code, data=api.receivet("eth0",0) code, data=api.receivet("eth0",0)
msg="Received: "+data if code == 0 else "Receive failed code="+str(code) msg="Received: "+data if code == RCode.SUCCESS else "Receive failed code="+str(code)
api.log(msg) api.log(msg)
# Simulated time t=3s here # Simulated time t=3s here

View file

@ -7,7 +7,7 @@
[t=3.000,src=n1] Received: Hello World! [t=3.000,src=n1] Received: Hello World!
[t=3.000,src=n1] Turned off [t=3.000,src=n1] Turned off
[t=4.000,src=n1] Turned on [t=4.000,src=n1] Turned on
[t=5.000,src=n1] Receive failed code=-1 [t=5.000,src=n1] Receive failed code=RCode.TIMEOUT_EXPIRE
[t=18.000,src=n0] End transmission [t=18.000,src=n0] End transmission
[t=18.000,src=n0] Send 15 bytes to n1 on eth0 [t=18.000,src=n0] Send 15 bytes to n1 on eth0
[t=33.000,src=n1] Receive 15 bytes on eth0 [t=33.000,src=n1] Receive 15 bytes on eth0

View file

@ -1,21 +1,22 @@
#!/usr/bin/env python #!/usr/bin/env python
from esds import RCode
def execute(api): def execute(api):
##### Simple receive ##### Simple receive
code, data=api.receive("eth0") code, data=api.receive("eth0")
msg="Received: "+data if code == 0 else "Receive failed code="+str(code) msg="Received: "+data if code == RCode.SUCCESS else "Receive failed code="+str(code)
api.log(msg) api.log(msg)
##### Test if we still receive the data when we are not receiving ##### Test if we still receive the data when we are not receiving
api.wait(2) api.wait(2)
code, data=api.receive("eth0") code, data=api.receive("eth0")
msg="Received: "+data if code == 0 else "Receive failed code="+str(code) msg="Received: "+data if code == RCode.SUCCESS else "Receive failed code="+str(code)
api.log(msg) api.log(msg)
##### Ensure data is not receive when turned off but communication must still be ongoing ##### Ensure data is not receive when turned off but communication must still be ongoing
api.turn_off() api.turn_off()
api.wait(1) api.wait(1)
api.turn_on() api.turn_on()
code, data=api.receivet("eth0",1) code, data=api.receivet("eth0",1)
msg="Received: "+data if code == 0 else "Receive failed code="+str(code) msg="Received: "+data if code == RCode.SUCCESS else "Receive failed code="+str(code)
api.log(msg) api.log(msg)
##### Ensure communication get aborted on turned off for the sender ##### Ensure communication get aborted on turned off for the sender
api.wait(28) # Goto t=33s api.wait(28) # Goto t=33s

View file

@ -1,13 +1,14 @@
#!/usr/bin/env python #!/usr/bin/env python
from esds import RCode
def execute(api): def execute(api):
##### Simple receive from node 0 ##### Simple receive from node 0
code, data=api.receive("eth0") code, data=api.receive("eth0")
msg="Received: "+data if code == 0 else "Receive failed code="+str(code) msg="Received: "+data if code == RCode.SUCCESS else "Receive failed code="+str(code)
api.log(msg) api.log(msg)
##### Simple receive from node 1 ##### Simple receive from node 1
code, data=api.receive("eth0") code, data=api.receive("eth0")
msg="Received: "+data if code == 0 else "Receive failed code="+str(code) msg="Received: "+data if code == RCode.SUCCESS else "Receive failed code="+str(code)
api.log(msg) api.log(msg)

View file

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
from esds import RCode
def receive(node, n): def receive(node, n):
for i in range(0,n): for i in range(0,n):
code, data=node.receive("eth0") code, data=node.receive("eth0")
msg="Received: "+data if code == 0 else "Receive failed code="+str(code) msg="Received: "+data if code == RCode.SUCCESS else "Receive failed code="+str(code)
node.log(msg) node.log(msg)
def execute(api): def execute(api):

View file

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
from esds import RCode
def receive(node): def receive(node):
##### Simple receive ##### Simple receive
code, data=node.receive("wlan0") code, data=node.receive("wlan0")
msg="Received: "+data if code == 0 else "Receive failed code="+str(code) msg="Received: "+data if code == RCode.SUCCESS else "Receive failed code="+str(code)
node.log(msg) node.log(msg)

View file

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
from esds import RCode
def receive(node): def receive(node):
##### Simple receive ##### Simple receive
code, data=node.receive("eth0") code, data=node.receive("eth0")
msg="Received: "+data if code == 0 else "Receive failed code="+str(code) msg="Received: "+data if code == RCode.SUCCESS else "Receive failed code="+str(code)
node.log(msg) node.log(msg)
def execute(api): def execute(api):

View file

@ -1,8 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
from esds import RCode
def sendt(node,timeout): def sendt(node,timeout):
code=node.sendt("eth0","Hello World!",1,1,timeout) code=node.sendt("eth0","Hello World!",1,1,timeout)
msg="Send worked!" if code == 0 else "Send failed" msg="Send worked!" if code == RCode.SUCCESS else "Send failed"
node.log(msg) node.log(msg)
def execute(api): def execute(api):

View file

@ -1,9 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
from esds import RCode
def receive(node): def receive(node):
##### Simple receive ##### Simple receive
code, data=node.receive("wlan0") code, data=node.receive("wlan0")
msg="Received: "+data if code == 0 else "Receive failed code="+str(code) msg="Received: "+data if code == RCode.SUCCESS else "Receive failed code="+str(code)
node.log(msg) node.log(msg)