Update platform parser

This commit is contained in:
Loic Guegan 2022-09-10 16:53:39 +02:00
parent 6a2319e07c
commit da78abb61c
2 changed files with 25 additions and 9 deletions

View file

@ -43,7 +43,7 @@ class YAMLPlatformFile:
else:
return([int(elt[0])])
def parse_link_bw(self,bw):
def parse_bw(self,bw):
for i,c in enumerate(bw):
if not c.isdigit() and c != ".":
break
@ -56,7 +56,7 @@ class YAMLPlatformFile:
number=number*8 if unit == "Bps" else number
return(number)
def parse_link_lat(self,lat):
def parse_lat(self,lat):
for i,c in enumerate(lat):
if not c.isdigit() and c != ".":
break
@ -72,22 +72,26 @@ class YAMLPlatformFile:
if len(words) == 4:
return((
self.parse_link_range(words[0]),
self.parse_link_bw(words[1]),
self.parse_link_lat(words[2]),
self.parse_bw(words[1]),
self.parse_lat(words[2]),
self.parse_link_range(words[3])))
elif len(words) == 2:
return((
range(0,self.default["node_count"]),
self.parse_link_bw(words[0]),
self.parse_link_lat(words[1]),
self.parse_bw(words[0]),
self.parse_lat(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])))
def parse_interfaces(self):
interfaces=self.platform["interfaces"]
node_count=self.default["node_count"]
for i in interfaces:
is_wired=interfaces[i]["wireless"]
is_wired=not interfaces[i]["wireless"]
links=list()
if type(interfaces[i]["links"]) == list:
for link in interfaces[i]["links"]:
@ -95,13 +99,23 @@ class YAMLPlatformFile:
else:
links.append(self.parse_link(interfaces[i]["links"]))
##### Create network matrix
BW=np.full((node_count,node_count),0)
LAT=np.full((node_count,node_count),0)
for link in links:
BW=np.full((node_count,node_count),0)
LAT=np.full((node_count,node_count),0)
for n1 in link[0]:
for n2 in link[3]:
BW[n1][n2]=link[1]
LAT[n1][n2]=link[2]
##### 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
self.default["interfaces"][i]={
"is_wired": is_wired,
"bandwidth": BW,

View file

@ -14,6 +14,8 @@ interfaces:
wireless: yes
links:
- 0 1Bps 10s 0
txperfs:
- 1Bps 10s
eth0:
wireless: no
links: 5Mbps 10s