summaryrefslogtreecommitdiff
path: root/esds/helpers
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-09-10 18:04:06 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2022-09-10 18:04:06 +0200
commit11966e96ee386b1edf7e6e019a3e1715c6849055 (patch)
treec81cf987c3e7afbb62df8fd66fd1bd5302981bff /esds/helpers
parentda78abb61c81aba1cb714d85b9b622ae6f6283b1 (diff)
Cleaning
Diffstat (limited to 'esds/helpers')
-rw-r--r--esds/helpers/platform.py106
1 files changed, 56 insertions, 50 deletions
diff --git a/esds/helpers/platform.py b/esds/helpers/platform.py
index 3f50aa9..5367846 100644
--- a/esds/helpers/platform.py
+++ b/esds/helpers/platform.py
@@ -2,6 +2,43 @@
import yaml, os
import numpy as np
+class UnitsParser:
+ def range(r,limit):
+ if r == "all":
+ return(range(0,limit))
+ elt=r.replace("@",str(limit-1)).split("-")
+ if len(elt) == 2:
+ min = int(elt[0])
+ max = int(elt[1])
+ # TODO: Check min/max
+ return(range(min,max))
+ else:
+ return([int(elt[0])])
+
+ def bandwidth(bw):
+ for i,c in enumerate(bw):
+ if not c.isdigit() and c != ".":
+ break
+ number=float(bw[:i])
+ unit=bw[i:]
+ number=number*1000 if unit == "Mbps" else number
+ number=number*1000*8 if unit == "MBps" else number
+ number=number*100 if unit == "kbps" else number
+ number=number*100*8 if unit == "kBps" else number
+ number=number*8 if unit == "Bps" else number
+ return(number)
+
+ def latency(lat):
+ for i,c in enumerate(lat):
+ if not c.isdigit() and c != ".":
+ break
+ number=float(lat[:i])
+ unit=lat[i:]
+ number=number*60 if unit in ["m","M"] else number
+ number=number*3600 if unit in ["h","H"] else number
+ number=number/1000 if unit in ["ms","MS"] else number
+ return(number)
+
class YAMLPlatformFile:
def __init__(self, file_path):
@@ -26,66 +63,35 @@ class YAMLPlatformFile:
if "nodes" in self.platform:
self.parse_nodes()
else:
- self.parse_error("platform file has no nodes section")
+ self.parsing_error("platform file has no nodes section")
##### Interfaces
if "interfaces" in self.platform:
self.parse_interfaces()
else:
- self.parse_error("platform file has no interfaces section")
+ self.parsing_error("platform file has no interfaces section")
- def parse_error(self,msg):
+ def parsing_error(self,msg):
raise Exception("Fail to parse platform file \""+self.file_path+"\": "+msg)
- def parse_link_range(self,r):
- elt=r.split("-")
- if len(elt) == 2:
- return(range(int(elt[0]),int(elt[1])))
- else:
- return([int(elt[0])])
-
- def parse_bw(self,bw):
- for i,c in enumerate(bw):
- if not c.isdigit() and c != ".":
- break
- number=float(bw[:i])
- unit=bw[i:]
- number=number*1000 if unit == "Mbps" else number
- number=number*1000*8 if unit == "MBps" else number
- number=number*100 if unit == "kbps" else number
- number=number*100*8 if unit == "kBps" else number
- number=number*8 if unit == "Bps" else number
- return(number)
-
- def parse_lat(self,lat):
- for i,c in enumerate(lat):
- if not c.isdigit() and c != ".":
- break
- number=float(lat[:i])
- unit=lat[i:]
- number=number*60 if unit in ["m","M"] else number
- number=number*3600 if unit in ["h","H"] else number
- number=number/1000 if unit in ["ms","MS"] else number
- return(number)
-
def parse_link(self,link):
words=link.split()
if len(words) == 4:
return((
- self.parse_link_range(words[0]),
- self.parse_bw(words[1]),
- self.parse_lat(words[2]),
- self.parse_link_range(words[3])))
+ UnitsParser.range(words[0],self.default["node_count"]),
+ 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"]),
- self.parse_bw(words[0]),
- self.parse_lat(words[1]),
+ UnitsParser.bandwidth(words[0]),
+ UnitsParser.latency(words[1]),
range(0,self.default["node_count"])))
return(None)
def parse_txperf(self,txperf):
elts=txperf.split()
- return((self.parse_bw(elts[0]),self.parse_lat(elts[1])))
+ return((UnitsParser.bandwidth(elts[0]),UnitsParser.latency(elts[1])))
def parse_interfaces(self):
interfaces=self.platform["interfaces"]
@@ -126,38 +132,38 @@ class YAMLPlatformFile:
nodes=self.platform["nodes"]
if "count" in nodes:
if not str(nodes["count"]).isnumeric():
- self.parse_error("node count should be a number")
+ self.parsing_error("node count should be a number")
self.default["node_count"]=nodes["count"]
if "implementations" in nodes:
if type(nodes["implementations"]) != list:
- self.parse_error("nodes implementations should be a list of file path")
+ self.parsing_error("nodes implementations should be a list of file path")
for file in nodes["implementations"]:
if not os.path.exists(file):
- self.parse_error("File "+file+ " not found")
+ self.parsing_error("File "+file+ " not found")
path, extension = os.path.splitext(file)
if extension != ".py":
- self.parse_error("File "+file+" must be a python file")
+ self.parsing_error("File "+file+" must be a python file")
self.default["implementations"].append(path)
count = len(nodes["implementations"])
if count > 1 and count != self.default["node_count"]:
- self.parse_error("If more than one implementation is specified, each node implementation should be provided ("+str(self.default["node_count"])+" in total)")
+ self.parsing_error("If more than one implementation is specified, each node implementation should be provided ("+str(self.default["node_count"])+" in total)")
def parse_general(self):
general=self.platform["general"]
if "breakpoints" in general:
if type(general["breakpoints"]) != list:
- self.parse_error("breakpoints should be a list of number")
+ self.parsing_error("breakpoints should be a list of number")
self.default["breakpoints"]=general["breakpoints"]
if "breakpoints_every" in general:
if not str(general["breakpoints_every"]).isnumeric():
- self.parse_error("breakpoints_every should be a number")
+ self.parsing_error("breakpoints_every should be a number")
self.default["breakpoints_every"]=general["breakpoints_every"]
if "debug" in general:
if type(general["debug"]) != bool:
- self.parse_error("debug should be on or off")
+ self.parsing_error("debug should be on or off")
self.default["debug"]=general["debug"]
if "interferences" in general:
if type(general["interferences"]) != bool:
- self.parse_error("interferences should be on or off")
+ self.parsing_error("interferences should be on or off")
self.default["interferences"]=general["interferences"]