From 0f0d08cabaeb7135a6a45ad239dfba2562715cb6 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sat, 11 Jun 2022 10:50:54 +0200 Subject: [PATCH] Now no ref to eth0 and wlan0 anymore. Each node can have an arbitrary number of wired and wireless interfaces --- esds.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/esds.py b/esds.py index a685c84..408f4da 100644 --- a/esds.py +++ b/esds.py @@ -334,29 +334,32 @@ class Simulator: node.rqueue.put(("turn_on",0)) self.log("Turned on",node=node.node_id) elif node["request"] == "turn_off": - selector_wlan0=list() - selector_other=list() + # 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 for event in self.events: if event[0]==0 and int(event[2][1])==node.node_id: - if event[2][2] == "wlan0": - selector_wlan0.append(True) - selector_other.append(False) + if self.netmat[event[2][2]]["is_wired"]: + selector_wireless.append(False) + selector_wired.append(True) else: - selector_wlan0.append(False) - selector_other.append(True) + selector_wireless.append(True) + selector_wired.append(False) else: - selector_wlan0.append(False) - selector_other.append(False) - # Informed sender to cancel send - for event in self.events[selector_other]: + selector_wireless.append(False) + selector_wired.append(False) + # Informed senders of wired events to cancel send + for event in self.events[selector_wired]: sender=self.nodes[int(event[2][0])] sender["state"]="running" sender.rqueue.put(("send_cancel",2)) - # Remove communications + # Remove communications from the event list if(len(self.events) != 0): - self.events=self.events[~(np.array(selector_wlan0)|np.array(selector_other))] + self.events=self.events[~(np.array(selector_wireless)|np.array(selector_wired))] + # Refresh wired sharing for interface in self.sharing.keys(): self.sharing[interface][node.node_id]=0 # Sharing goes back to zero + # Update node state after turning off node["state"]="running" node.rqueue.put(("turn_off",0)) self.log("Turned off",node=node.node_id)