diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2023-06-29 09:37:27 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2023-06-29 09:37:27 +0200 |
| commit | e082a7b51983b4a277243f9bb02d3b5126b4b74a (patch) | |
| tree | 3c0d2751465e04f7621aa817f91a0548990fb184 /esds | |
| parent | 9a1578ae752075cbe4e0c658307d037cb18b56c9 (diff) | |
Interfaces are now assigned to specific nodes
Diffstat (limited to 'esds')
| -rw-r--r-- | esds/platform.py | 18 | ||||
| -rw-r--r-- | esds/simulator.py | 15 |
2 files changed, 26 insertions, 7 deletions
diff --git a/esds/platform.py b/esds/platform.py index 40f8301..b8b8b6e 100644 --- a/esds/platform.py +++ b/esds/platform.py @@ -58,7 +58,8 @@ class YAMLPlatformFile: "node_count": 0, "implementations": [], "arguments": [], - "groups": dict(), + "groups": dict(), # {node_id} => group + "nodes_interfaces": dict(), # {node_id} => [interfaces] "interfaces": dict() } @@ -103,6 +104,10 @@ class YAMLPlatformFile: def parse_interfaces(self): interfaces=self.platform["interfaces"] node_count=self.default["node_count"] + ##### Init nodes interfaces + for node in range(0,self.default["node_count"]): + self.default["nodes_interfaces"][node]=list() + ##### Parse interfaces for i in interfaces: if interfaces[i]["type"] not in ["wireless","wired"]: self.parsing_error("Invalid interface type \""+interfaces[i]["type"]+"\"") @@ -112,6 +117,13 @@ class YAMLPlatformFile: self.parsing_error("Invalide type of links in interface "+i) for link in interfaces[i]["links"]: links.append(self.parse_link(link)) + ##### Assign interfaces to nodes + if "nodes" in interfaces[i]: + r=UnitsParser.node_range(str(interfaces[i]["nodes"]),self.default["node_count"]) + for node in r: + self.default["nodes_interfaces"][node].append(i) + else: + self.parsing_error("missing nodes section on interface "+i) ##### Create network matrix BW=np.full((node_count,node_count),0) LAT=np.full((node_count,node_count),0) @@ -220,9 +232,9 @@ class YAMLPlatformFile: simulator=Simulator(self.default["interfaces"]) for node_id in range(0,self.default["node_count"]): if node_id in self.default["groups"]: - simulator.create_node(self.default["implementations"][node_id], args=self.default["arguments"][node_id],grp=self.default["groups"][node_id]) + simulator.create_node(self.default["implementations"][node_id],self.default["nodes_interfaces"][node_id], args=self.default["arguments"][node_id],grp=self.default["groups"][node_id]) else: - simulator.create_node(self.default["implementations"][node_id], args=self.default["arguments"][node_id]) + simulator.create_node(self.default["implementations"][node_id],self.default["nodes_interfaces"][node_id], args=self.default["arguments"][node_id]) ##### Run simulation simulator.run( breakpoints=self.default["breakpoints"], diff --git a/esds/simulator.py b/esds/simulator.py index 2253a49..30534de 100644 --- a/esds/simulator.py +++ b/esds/simulator.py @@ -75,11 +75,15 @@ class Simulator: event[2][5]=new_duration self.netmat=netmat - def create_node(self, src, args=None, grp="def"): + def create_node(self, src, interfaces=[], args=None, grp="def"): """ Create a node thread and run it """ - node=Node(src, self.netmat.keys(), grp) + for intf in interfaces: + if intf not in self.netmat.keys(): + self.log("Cannot create node "+str(Node.available_node_id)+": interface "+ intf + " unknown") + exit(1) + node=Node(src, interfaces, grp) self.nodes.append(node) thread=threading.Thread(target=node.run,args=[args]) # There must be "daemon=True" as a parameter, but we removed it to be compatible with older version of python thread.start() @@ -324,6 +328,9 @@ class Simulator: """ nsrc=self.nodes[src] if self.netmat[interface]["is_wired"]: + if interface not in self.nodes[dst]["interfaces"]: + self.log("Cannot create communication from node "+str(src)+ " to "+str(dst)+", interface "+interface+" not available on node "+str(dst)) + exit(1) self.log("Send "+str(datasize)+" bytes to n"+str(dst)+" on "+interface,node=nsrc) if not self.nodes[dst]["turned_on"] and receiver_required: return(False) @@ -334,7 +341,7 @@ class Simulator: else: self.log("Send "+str(datasize)+" bytes on "+interface,node=nsrc) for dst in self.list_receivers(nsrc,interface): - if self.nodes[dst]["turned_on"]: + if interface in self.nodes[dst]["interfaces"] and self.nodes[dst]["turned_on"]: duration=datasize*8/self.netmat[interface]["bandwidth"][src,dst]+self.netmat[interface]["latency"][src,dst] if src == dst: # This event (where src == dst) is used to notify the sender when data is received! @@ -347,7 +354,7 @@ class Simulator: return(True) def list_receivers(self,node,interface): """ - Deduce reachable receivers from the bandwidth matrix + Deduce reachable receivers from the bandwidth matrix (sender is included in the list!) """ selector = self.netmat[interface]["bandwidth"][node.node_id,] > 0 return np.arange(0,selector.shape[0])[selector] |
