mirror of
https://gitlab.com/manzerbredes/esds.git
synced 2025-04-06 01:56:27 +02:00
Refactoring
This commit is contained in:
parent
535eb79ad7
commit
838e48438c
2 changed files with 21 additions and 21 deletions
32
esds/node.py
32
esds/node.py
|
@ -50,7 +50,7 @@ class Node:
|
|||
def abort(self,reason):
|
||||
self.rargs=reason
|
||||
self["request"]="abort"
|
||||
self["state"]="call"
|
||||
self["state"]="call_non_blocking"
|
||||
while True: continue
|
||||
|
||||
def log(self,msg):
|
||||
|
@ -58,13 +58,13 @@ class Node:
|
|||
self.abort("log() called with a non-string argument")
|
||||
self.rargs=msg
|
||||
self["request"]="log"
|
||||
self["state"]="call"
|
||||
self["state"]="call_non_blocking"
|
||||
self.wait_ack(["log"])
|
||||
|
||||
def read(self, register):
|
||||
self["request"]="read"
|
||||
self.rargs=register
|
||||
self["state"]="call"
|
||||
self["state"]="call_non_blocking"
|
||||
ack=self.wait_ack(["read"])
|
||||
return ack[1]
|
||||
|
||||
|
@ -73,27 +73,27 @@ class Node:
|
|||
self.abort("wait() called with a non-number duration")
|
||||
self.rargs=duration
|
||||
self["request"]="timeout_add"
|
||||
self["state"]="call"
|
||||
self["state"]="call_non_blocking"
|
||||
self.wait_ack(["timeout_add"])
|
||||
self["state"]="pending"
|
||||
self.wait_ack(["timeout"])
|
||||
|
||||
def wait_end(self):
|
||||
self["request"]="wait_end"
|
||||
self["state"]="request"
|
||||
self["state"]="call_blocking"
|
||||
self.wait_ack(["wait_end"])
|
||||
self.wait_ack(["sim_end"])
|
||||
|
||||
def turn_off(self):
|
||||
self["turned_on"]=False
|
||||
self["request"]="turn_off"
|
||||
self["state"]="call"
|
||||
self["state"]="call_non_blocking"
|
||||
self.wait_ack(["turn_off"])
|
||||
|
||||
def turn_on(self):
|
||||
self["turned_on"]=True
|
||||
self["request"]="turn_on"
|
||||
self["state"]="call"
|
||||
self["state"]="call_non_blocking"
|
||||
self.wait_ack(["turn_on"])
|
||||
|
||||
def send(self, interface, data, datasize, dst):
|
||||
|
@ -106,7 +106,7 @@ class Node:
|
|||
self.plugin_notify("send_call",(interface,data,datasize,dst))
|
||||
self.rargs=(interface, data, datasize, dst)
|
||||
self["request"]="send"
|
||||
self["state"]="request"
|
||||
self["state"]="call_blocking"
|
||||
ack=self.wait_ack(["send","send_cancel"])
|
||||
self.plugin_notify("send_return",(interface,data,datasize,dst,ack[1]))
|
||||
return ack[1]
|
||||
|
@ -122,19 +122,19 @@ class Node:
|
|||
self.abort("send() called with a non-number dst (wired interfaces) or dst is not None (wireless interfaces)")
|
||||
self.rargs=timeout
|
||||
self["request"]="timeout_add"
|
||||
self["state"]="call"
|
||||
self["state"]="call_non_blocking"
|
||||
self.wait_ack(["timeout_add"])
|
||||
self.rargs=(interface, data, datasize, dst)
|
||||
self["request"]="send"
|
||||
self["state"]="request"
|
||||
self["state"]="call_blocking"
|
||||
ack=self.wait_ack(["send","timeout","send_cancel"])
|
||||
if ack[0] == "timeout":
|
||||
self["request"]="send_cancel"
|
||||
self["state"]="call"
|
||||
self["state"]="call_non_blocking"
|
||||
self.wait_ack(["send_cancel"])
|
||||
return -1
|
||||
self["request"]="timeout_remove"
|
||||
self["state"]="call"
|
||||
self["state"]="call_non_blocking"
|
||||
self.wait_ack(["timeout_remove"])
|
||||
return ack[1]
|
||||
|
||||
|
@ -143,7 +143,7 @@ class Node:
|
|||
self.abort("receive() called with an unknown interface \""+interface+"\"")
|
||||
self["request"]="receive"
|
||||
self.rargs=interface
|
||||
self["state"]="request"
|
||||
self["state"]="call_blocking"
|
||||
self.wait_ack(["receive"])
|
||||
data,start_at,end_at=self["interfaces"][interface].get()
|
||||
self.plugin_notify("receive_return",(interface,data,start_at,end_at))
|
||||
|
@ -156,16 +156,16 @@ class Node:
|
|||
self.abort("receivet() called with a non-number timeout")
|
||||
self.rargs=timeout
|
||||
self["request"]="timeout_add"
|
||||
self["state"]="call"
|
||||
self["state"]="call_non_blocking"
|
||||
self.wait_ack(["timeout_add"])
|
||||
self["request"]="receive"
|
||||
self.rargs=interface
|
||||
self["state"]="request"
|
||||
self["state"]="call_blocking"
|
||||
ack=self.wait_ack(["receive","timeout"])
|
||||
if ack[0] == "timeout":
|
||||
return (-1,None)
|
||||
self["request"]="timeout_remove"
|
||||
self["state"]="call"
|
||||
self["state"]="call_non_blocking"
|
||||
self.wait_ack(["timeout_remove"])
|
||||
data,start_at,end_at=self["interfaces"][interface].get()
|
||||
self.plugin_notify("receivet_return",(interface,data,start_at,end_at))
|
||||
|
|
|
@ -128,7 +128,7 @@ class Simulator:
|
|||
Process all call request and wait for Node.sync() to return
|
||||
"""
|
||||
node.sync()
|
||||
while node["state"] == "call":
|
||||
while node["state"] == "call_non_blocking":
|
||||
if node["request"] == "log":
|
||||
self.log(node.rargs,node=node.node_id)
|
||||
node["state"]="running"
|
||||
|
@ -267,7 +267,7 @@ class Simulator:
|
|||
"""
|
||||
Collect events from the nodes
|
||||
"""
|
||||
if node["state"] == "request":
|
||||
if node["state"] == "call_blocking":
|
||||
if node["request"] == "send":
|
||||
node["state"]="pending"
|
||||
interface, data, datasize, dst=node.rargs
|
||||
|
@ -303,7 +303,7 @@ class Simulator:
|
|||
duration=datasize*8/(self.netmat[interface]["bandwidth"][src,dst]/self.sharing[interface][dst])+self.netmat[interface]["latency"][src,dst]
|
||||
self.add_event(0,duration+self.time,(src,dst,interface,data,datasize,duration,datasize,self.time))
|
||||
else:
|
||||
nsrc["state"]="request" # Try later when node is on
|
||||
nsrc["state"]="call_blocking" # Try later when node is on
|
||||
else:
|
||||
self.log("Send "+str(datasize)+" bytes on "+interface,node=src)
|
||||
for dst in self.list_receivers(nsrc,interface):
|
||||
|
@ -392,7 +392,7 @@ class Simulator:
|
|||
self.update_sharing(dst.node_id,-1,interface)
|
||||
self.log("Receive "+str(datasize)+" bytes on "+interface,node=int(dst_id))
|
||||
# If node is receiving makes it consume (this way if there is a timeout, it will be removed!)
|
||||
if dst["state"] == "request" and dst["request"] == "receive":
|
||||
if dst["state"] == "call_blocking" and dst["request"] == "receive":
|
||||
dst["interfaces_queue_size"][interface]-=1
|
||||
dst["state"]="running"
|
||||
dst.rqueue.put(("receive",0))
|
||||
|
@ -405,7 +405,7 @@ class Simulator:
|
|||
dst["interfaces_queue_size"][interface]+=1
|
||||
self.log("Receive "+str(datasize)+" bytes on "+interface,node=int(dst_id))
|
||||
# If node is receiving makes it consume (this way if there is a timeout, it will be removed!)
|
||||
if dst["state"] == "request" and dst["request"] == "receive":
|
||||
if dst["state"] == "call_blocking" and dst["request"] == "receive":
|
||||
dst["interfaces_queue_size"][interface]-=1
|
||||
dst["state"]="running"
|
||||
dst.rqueue.put(("receive",0))
|
||||
|
|
Loading…
Add table
Reference in a new issue