mirror of
https://github.com/Telecominfraproject/oopt-gnpy.git
synced 2025-11-01 18:47:48 +00:00
path_requests_run now generates a json file if -o is used
the format of path results follows the yang model of ietf Signed-off-by: EstherLerouzic <esther.lerouzic@orange.com>
This commit is contained in:
@@ -24,7 +24,7 @@ from json import dumps, loads
|
||||
from networkx import (draw_networkx_nodes, draw_networkx_edges,
|
||||
draw_networkx_labels, dijkstra_path, NetworkXNoPath)
|
||||
from numpy import mean
|
||||
from examples.convert_service_sheet import convert_service_sheet, Request_element
|
||||
from examples.convert_service_sheet import convert_service_sheet, Request_element, Element
|
||||
from gnpy.core.utils import load_json
|
||||
from gnpy.core import network_from_json, build_network
|
||||
from gnpy.core.equipment import read_eqpt_library
|
||||
@@ -53,8 +53,8 @@ class Path_request():
|
||||
self.source = jsondata['src-tp-id']
|
||||
self.destination = jsondata['dst-tp-id']
|
||||
# retrieving baudrate out of transponder type and mode (format)
|
||||
tsp = jsondata['path-constraints']['te-bandwidth']['trx_type']
|
||||
tsp_mode = jsondata['path-constraints']['te-bandwidth']['trx_mode']
|
||||
self.tsp = jsondata['path-constraints']['te-bandwidth']['trx_type']
|
||||
self.tsp_mode = jsondata['path-constraints']['te-bandwidth']['trx_mode']
|
||||
# for debug
|
||||
# print(tsp)
|
||||
# refactoring into a simple expression
|
||||
@@ -73,12 +73,12 @@ class Path_request():
|
||||
# self.baudrate = b
|
||||
try:
|
||||
baudrate = [m['baudrate']
|
||||
for t in tspjsondata if t['type_variety']== tsp
|
||||
for m in t['mode'] if m['format']==tsp_mode][0]
|
||||
for t in tspjsondata if t['type_variety']== self.tsp
|
||||
for m in t['mode'] if m['format']==self.tsp_mode][0]
|
||||
# for debug
|
||||
# print(f'coucou {baudrate}')
|
||||
except IndexError:
|
||||
msg = f'could not find tsp : {tsp} with mode: {tsp_mode} in eqpt library'
|
||||
msg = f'could not find tsp : {self.tsp} with mode: {self.tsp_mode} in eqpt library'
|
||||
logger.critical(msg)
|
||||
raise ValueError(msg)
|
||||
self.baudrate = baudrate
|
||||
@@ -100,6 +100,64 @@ class Path_request():
|
||||
f'{self.destination}',
|
||||
'\n'])
|
||||
|
||||
class Result_element(Element):
|
||||
def __init__(self,path_request,computed_path):
|
||||
self.path_id = int(path_request.request_id)
|
||||
self.path_request = path_request
|
||||
self.computed_path = computed_path
|
||||
hop_type = []
|
||||
for e in computed_path :
|
||||
if isinstance(e, Transceiver) :
|
||||
hop_type.append(' - '.join([path_request.tsp,path_request.tsp_mode]))
|
||||
else:
|
||||
hop_type.append('not recorded')
|
||||
self.hop_type = hop_type
|
||||
uid = property(lambda self: repr(self))
|
||||
@property
|
||||
def pathresult(self):
|
||||
return {
|
||||
'path-id': self.path_id,
|
||||
'path-properties':{
|
||||
'path-metric': [
|
||||
{
|
||||
'metric-type': 'SNR@bandwidth',
|
||||
'accumulative-value': round(mean(self.computed_path[-1].snr),2)
|
||||
},
|
||||
{
|
||||
'metric-type': 'SNR@0.1nm',
|
||||
'accumulative-value': round(mean(self.computed_path[-1].snr+10*log10(self.path_request.baudrate/12.5)),2)
|
||||
}
|
||||
],
|
||||
'path-srlgs': {
|
||||
'usage': 'not used yet',
|
||||
'values': 'not used yet'
|
||||
},
|
||||
'path-route-objects': [
|
||||
{
|
||||
'path-route-object': {
|
||||
'index': self.computed_path.index(n),
|
||||
'unnumbered-hop': {
|
||||
'node-id': n.uid,
|
||||
'link-tp-id': n.uid,
|
||||
'hop-type': self.hop_type[self.computed_path.index(n)],
|
||||
'direction': 'not used'
|
||||
},
|
||||
'label-hop': {
|
||||
'te-label': {
|
||||
'generic': 'not used yet',
|
||||
'direction': 'not used yet'
|
||||
}
|
||||
}
|
||||
}
|
||||
} for n in self.computed_path
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@property
|
||||
def json(self):
|
||||
return self.pathresult
|
||||
|
||||
def load_SI(filename):
|
||||
with open(filename) as f:
|
||||
json_data = loads(f.read())
|
||||
@@ -245,14 +303,22 @@ def compute_path(network, pathreqlist):
|
||||
# overwritten
|
||||
|
||||
# path_res_list.append(deepcopy(destination))
|
||||
path_res_list.append(deepcopy(total_path[-1]))
|
||||
path_res_list.append(deepcopy(total_path))
|
||||
return path_res_list
|
||||
|
||||
def path_result_json(pathresult):
|
||||
data = {
|
||||
'path': [n.json for n in pathresult]
|
||||
}
|
||||
return data
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = parser.parse_args()
|
||||
basicConfig(level={2: DEBUG, 1: INFO, 0: CRITICAL}.get(args.verbose, CRITICAL))
|
||||
logger.info(f'Computing path requests {args.service_filename} into JSON format')
|
||||
print( args.eqpt_filename)
|
||||
# for debug
|
||||
# print( args.eqpt_filename)
|
||||
data = load_requests(args.service_filename,args.eqpt_filename)
|
||||
network = load_network(args.network_filename,args.eqpt_filename)
|
||||
pths = requests_from_json(data, args.eqpt_filename)
|
||||
@@ -262,9 +328,14 @@ if __name__ == '__main__':
|
||||
print("todo write results")
|
||||
print("demand\t\t\t\tsnr@bandwidth\tsnr@0.1nm")
|
||||
i = 0
|
||||
|
||||
for p in test:
|
||||
print(f'{pths[i].source} to {pths[i].destination} : {round(mean(p.snr),2)} , {round(mean(p.snr+10*log10(pths[i].baudrate/12.5)),2)}')
|
||||
print(f'{pths[i].source} to {pths[i].destination} : {round(mean(p[-1].snr),2)} ,\
|
||||
{round(mean(p[-1].snr+10*log10(pths[i].baudrate/12.5)),2)}')
|
||||
i = i+1
|
||||
else:
|
||||
result = []
|
||||
for p in test:
|
||||
result.append(Result_element(pths[test.index(p)],p))
|
||||
with open(args.output, 'w') as f:
|
||||
f.write(test)
|
||||
f.write(dumps(path_result_json(result), indent=2))
|
||||
Reference in New Issue
Block a user