diff --git a/esds/helpers/platform.py b/esds/helpers/platform.py index 5367846..ec776ab 100644 --- a/esds/helpers/platform.py +++ b/esds/helpers/platform.py @@ -70,6 +70,8 @@ class YAMLPlatformFile: else: self.parsing_error("platform file has no interfaces section") + print(self.default) + def parsing_error(self,msg): raise Exception("Fail to parse platform file \""+self.file_path+"\": "+msg) @@ -81,17 +83,11 @@ class YAMLPlatformFile: UnitsParser.bandwidth(words[1]), UnitsParser.latency(words[2]), UnitsParser.range(words[3],self.default["node_count"]))) - elif len(words) == 2: - return(( - range(0,self.default["node_count"]), - UnitsParser.bandwidth(words[0]), - UnitsParser.latency(words[1]), - range(0,self.default["node_count"]))) - return(None) + self.parsing_error("Invalide link \""+link+"\"") def parse_txperf(self,txperf): elts=txperf.split() - return((UnitsParser.bandwidth(elts[0]),UnitsParser.latency(elts[1]))) + return((UnitsParser.range(elts[0],self.default["node_count"]),UnitsParser.bandwidth(elts[1]),UnitsParser.latency(elts[2]))) def parse_interfaces(self): interfaces=self.platform["interfaces"] @@ -116,11 +112,11 @@ class YAMLPlatformFile: ##### Set txperfs for wireless interfaces if not is_wired: txperfs=interfaces[i]["txperfs"] - for node in range(0,node_count): - txperf=txperfs[0] if len(txperfs) == 1 else txperfs[node] - bw,lat=self.parse_txperf(txperf) - BW[node][node]=bw - LAT[node][node]=lat + for txperf in txperfs: + p=self.parse_txperf(txperf) + for node in p[0]: + BW[node][node]=p[1] + LAT[node][node]=p[2] self.default["interfaces"][i]={ "is_wired": is_wired, @@ -137,13 +133,18 @@ class YAMLPlatformFile: if "implementations" in nodes: if type(nodes["implementations"]) != list: self.parsing_error("nodes implementations should be a list of file path") - for file in nodes["implementations"]: + self.default["implementations"]=[None]*self.default["node_count"] + for impl in nodes["implementations"]: + words=impl.split() + r=UnitsParser.range(words[0],self.default["node_count"]) + file="".join(words[1:]) if not os.path.exists(file): self.parsing_error("File "+file+ " not found") path, extension = os.path.splitext(file) if extension != ".py": self.parsing_error("File "+file+" must be a python file") - self.default["implementations"].append(path) + for node in r: + self.default["implementations"][node]=file count = len(nodes["implementations"]) if count > 1 and count != self.default["node_count"]: self.parsing_error("If more than one implementation is specified, each node implementation should be provided ("+str(self.default["node_count"])+" in total)") diff --git a/example/platform.yaml b/example/platform.yaml index e122317..62db585 100644 --- a/example/platform.yaml +++ b/example/platform.yaml @@ -7,7 +7,7 @@ general: nodes: count: 5 implementations: - - sender.py + - all sender.py interfaces: wlan0: @@ -15,7 +15,7 @@ interfaces: links: - 0 1Bps 10s 0 txperfs: - - 1Bps 10s + - all 1Bps 10s eth0: wireless: no - links: 5Mbps 10s \ No newline at end of file + links: all 5Mbps 10s all \ No newline at end of file