Refactoring

This commit is contained in:
Loic Guegan 2022-06-28 11:45:25 +02:00
parent 838e48438c
commit 6b697fa14f

View file

@ -123,7 +123,7 @@ class Simulator:
sorted_indexes=np.lexsort((self.events[:,3],self.events[:,1]))
self.events=self.events[sorted_indexes]
def sync_node(self,node):
def sync_node_non_blocking(self,node):
"""
Process all call request and wait for Node.sync() to return
"""
@ -263,7 +263,7 @@ class Simulator:
self.log("Interferences on "+interface,node=node)
return status
def sync_event(self, node):
def sync_node_blocking(self, node):
"""
Collect events from the nodes
"""
@ -283,8 +283,8 @@ class Simulator:
node["state"]="running"
node.rqueue.put(("receive",0))
# Do not forget to collect the next event. This is the only request which is processed here
self.sync_node(node)
self.sync_event(node)
self.sync_node_non_blocking(node)
self.sync_node_blocking(node)
elif node["request"] == "wait_end":
node["state"]="pending"
node.rqueue.put(("wait_end",0))
@ -355,10 +355,10 @@ class Simulator:
while True:
# Synchronize every nodes
for node in self.nodes:
self.sync_node(node)
self.sync_node_non_blocking(node)
# Manage events
for node in self.nodes:
self.sync_event(node)
self.sync_node_blocking(node)
# Generate debug logs
if debug:
self.debug()
@ -369,7 +369,7 @@ class Simulator:
for node_id in self.wait_end_nodes:
self.nodes[node_id]["state"]="running"
self.nodes[node_id].rqueue.put(("sim_end",0))
self.sync_node(self.nodes[node_id]) # Allow them for make call requests (printing logs for example)
self.sync_node_non_blocking(self.nodes[node_id]) # Allow them for make call requests (printing logs for example)
break # End the event processing loop
# Update simulation time
@ -396,7 +396,7 @@ class Simulator:
dst["interfaces_queue_size"][interface]-=1
dst["state"]="running"
dst.rqueue.put(("receive",0))
self.sync_node(dst)
self.sync_node_non_blocking(dst)
src["state"]="running"
src.rqueue.put(("send",0))
else:
@ -409,7 +409,7 @@ class Simulator:
dst["interfaces_queue_size"][interface]-=1
dst["state"]="running"
dst.rqueue.put(("receive",0))
self.sync_node(dst)
self.sync_node_non_blocking(dst)
else:
src["state"]="running"
src.rqueue.put(("send",0))
@ -417,7 +417,7 @@ class Simulator:
node=self.nodes[int(event)]
node["state"]="running"
node.rqueue.put(("timeout",0))
self.sync_node(node)
self.sync_node_non_blocking(node)
elif event_type == 2 or event_type == 3:
breakpoint_callback(self)
if event_type == 3: