From 6d49769df9994e68ba7b9f87d5baefebf5ca7ecf Mon Sep 17 00:00:00 2001 From: EstherLerouzic Date: Thu, 5 Jul 2018 18:33:04 +0100 Subject: [PATCH] Refactor path_request_run and integration of functions to transmission - use load_equipment instead of load_SI - integrate the pathrequest class into transmission main Signed-off-by: EstherLerouzic --- examples/path_requests_run.py | 21 ++++------ examples/transmission_main_example.py | 47 +++++++++++++++++----- gnpy/core/info.py | 5 --- gnpy/core/request.py | 57 +++------------------------ 4 files changed, 51 insertions(+), 79 deletions(-) diff --git a/examples/path_requests_run.py b/examples/path_requests_run.py index fb8961aa..9f6d4f59 100644 --- a/examples/path_requests_run.py +++ b/examples/path_requests_run.py @@ -30,7 +30,7 @@ from gnpy.core.network import load_network, build_network from gnpy.core.equipment import load_equipment from gnpy.core.elements import Transceiver, Roadm, Edfa, Fused from gnpy.core.utils import db2lin, lin2db -from gnpy.core.info import create_input_spectral_information, SpectralInformation, Channel, Power, load_SI +from gnpy.core.info import create_input_spectral_information, SpectralInformation, Channel, Power from gnpy.core.request import Path_request, Result_element from copy import copy, deepcopy from numpy import log10 @@ -47,14 +47,9 @@ parser.add_argument('-v', '--verbose', action='count') parser.add_argument('-o', '--output', default=None) -def load_Transceiver(filename): - with open(filename) as f: - json_data = loads(f.read()) - return json_data['Transceiver'] - -def requests_from_json(json_data,eqpt_filename): +def requests_from_json(json_data,equipment): requests_list = [] - tspjsondata = load_Transceiver(eqpt_filename) + tsp_lib = equipment['Transceiver'] for req in json_data['path-request']: #print(f'{req}') @@ -66,8 +61,7 @@ def requests_from_json(json_data,eqpt_filename): params['trx_mode'] = req['path-constraints']['te-bandwidth']['trx_mode'] try: extra_params = next(m - for t in tspjsondata if t['type_variety'] == params['trx_type'] - for m in t['mode'] if m['format'] == params['trx_mode']) + for m in tsp_lib[params['trx_type']].mode if m['format'] == params['trx_mode']) except StopIteration : msg = f'could not find tsp : {params} with mode: {params} in eqpt library' raise ValueError(msg) @@ -103,7 +97,8 @@ def compute_path(network, pathreqlist): edfa = [n for n in network.nodes() if isinstance(n, Edfa)] # TODO include also fused in the element check : too difficult because of direction # fused = [n for n in network.nodes() if isinstance(n, Fused)] - sidata = load_SI(args.eqpt_filename) + sidata = equipment['SI']['default'] + for pathreq in pathreqlist: pathreq.nodes_list.append(pathreq.destination) #we assume that the destination is a strict constraint @@ -148,7 +143,7 @@ def compute_path(network, pathreqlist): # for debug # print(f'{pathreq.baudrate} {pathreq.power} {pathreq.spacing} {pathreq.nb_channel}') si = create_input_spectral_information( - sidata['f_min'], sidata['roll_off'], + sidata.f_min, sidata.roll_off, pathreq.baudrate, pathreq.power, pathreq.spacing, pathreq.nb_channel) for el in total_path: si = el(si) @@ -182,7 +177,7 @@ if __name__ == '__main__': equipment = load_equipment(args.eqpt_filename) network = load_network(args.network_filename,equipment) build_network(network, equipment=equipment) - pths = requests_from_json(data, args.eqpt_filename) + pths = requests_from_json(data, equipment) print(pths) test = compute_path(network,pths) diff --git a/examples/transmission_main_example.py b/examples/transmission_main_example.py index 2b6ba111..b4eb6706 100755 --- a/examples/transmission_main_example.py +++ b/examples/transmission_main_example.py @@ -20,7 +20,8 @@ from networkx import (draw_networkx_nodes, draw_networkx_edges, from gnpy.core import load_network, build_network from gnpy.core.elements import Transceiver, Fiber, Edfa, Roadm -from gnpy.core.info import SpectralInformation, Channel, Power +from gnpy.core.info import create_input_spectral_information, SpectralInformation, Channel, Power +from gnpy.core.request import Path_request, RequestParams logger = getLogger(__name__) @@ -48,21 +49,29 @@ def plot_results(network, path, source, sink): show() -def main(network, equipment, source, sink): +def main(network, equipment, source, sink, req = None): build_network(network, equipment=equipment) + + sidata = equipment['SI']['default'] + + print(sidata) + print('\n\n\n') path = dijkstra_path(network, source, sink) spans = [s.length for s in path if isinstance(s, Fiber)] print(f'\nThere are {len(spans)} fiber spans over {sum(spans):.0f}m between {source.uid} and {sink.uid}') print(f'\nNow propagating between {source.uid} and {sink.uid}:') - + for p in range(0, 1): #change range to sweep results across several powers in dBm p=db2lin(p)*1e-3 spacing = 0.05 # THz - si = SpectralInformation() # SI units: W, Hz - si = si.update(carriers=[ - Channel(f, (191.3 + spacing * f) * 1e12, 32e9, 0.15, Power(p, 0, 0)) - for f in range(1,97) - ]) + # si = SpectralInformation() # SI units: W, Hz + si = create_input_spectral_information( + sidata.f_min, sidata.roll_off, + req.baudrate, p, req.spacing, req.nb_channel) + # si = si.update(carriers=[ + # Channel(f, (191.3 + spacing * f) * 1e12, 32e9, 0.15, Power(p, 0, 0)) + # for f in range(1,97) + # ]) print(f'\nPropagating with input power = {lin2db(p*1e3):.2f}dBm :') for el in path: si = el(si) @@ -135,7 +144,27 @@ if __name__ == '__main__': logger.info(f'source = {args.source!r}') logger.info(f'sink = {args.sink!r}') - path = main(network, equipment, source, sink) + + params = {} + params['request_id'] = 0 + params['source'] = args.source + params['destination'] = args.sink + params['trx_type'] = 'vendorA_trx-type1' + params['trx_mode'] = 'PS_SP64_1' + params['nodes_list'] = [] + params['loose_list'] = [] + params['spacing'] = 50e9 + params['power'] = -1 + params['nb_channel'] = 80 + try: + extra_params = next(m + for m in equipment['Transceiver'][params['trx_type']].mode if m['format'] == params['trx_mode']) + except StopIteration : + msg = f'could not find tsp : {params} with mode: {params} in eqpt library' + raise ValueError(msg) + params.update(extra_params) + req = Path_request(**params) + path = main(network, equipment, source, sink,req) if args.plot: plot_results(network, path, source, sink) diff --git a/gnpy/core/info.py b/gnpy/core/info.py index 167f9ebb..df8edea5 100644 --- a/gnpy/core/info.py +++ b/gnpy/core/info.py @@ -58,11 +58,6 @@ def create_input_spectral_information(f_min, roll_off, baudrate, power, spacing, baudrate, roll_off, Power(power, 0, 0)) for f in range(1,nb_channel+1))) return si -def load_SI(filename): - with open(filename) as f: - json_data = loads(f.read()) - return next(m for m in json_data['SI']) - if __name__ == '__main__': si = SpectralInformation( Channel(1, 193.95e12, 32e9, 0.15, # 193.95 THz, 32 Gbaud diff --git a/gnpy/core/request.py b/gnpy/core/request.py index dcd839fa..9b24d099 100644 --- a/gnpy/core/request.py +++ b/gnpy/core/request.py @@ -30,7 +30,7 @@ from gnpy.core.network import load_network, build_network from gnpy.core.equipment import load_equipment from gnpy.core.elements import Transceiver, Roadm, Edfa, Fused from gnpy.core.utils import db2lin, lin2db -from gnpy.core.info import create_input_spectral_information, SpectralInformation, Channel, Power, load_SI +from gnpy.core.info import create_input_spectral_information, SpectralInformation, Channel, Power from copy import copy, deepcopy from numpy import log10 @@ -54,12 +54,10 @@ class Path_request: self.spacing = params.spacing self.power = params.power self.nb_channel = params.nb_channel - -# class Path_request(Request): -# def __init__(self,*args, params=None, **kwargs): -# if params is None: -# params = {} -# super().__init__(*args, params=RequestParams(**params), **kwargs) + self.format = params.format + self.OSNR = params.OSNR + self.bit_rate = params.bit_rate + def __str__(self): return '\n\t'.join([ f'{type(self).__name__} {self.request_id}', @@ -75,51 +73,6 @@ class Path_request: f'power: {self.power}' '\n']) -# class Path_request(): -# def __init__(self,jsondata,tspjsondata): -# self.request_id = jsondata['request-id'] -# self.source = jsondata['src-tp-id'] -# self.destination = jsondata['dst-tp-id'] -# # retrieving baudrate out of transponder type and mode (format) -# self.tsp = jsondata['path-constraints']['te-bandwidth']['trx_type'] -# self.tsp_mode = jsondata['path-constraints']['te-bandwidth']['trx_mode'] -# # for debug -# # print(tsp) -# try: -# baudrate = next(m['baudrate'] -# for t in tspjsondata if t['type_variety'] == self.tsp -# for m in t['mode'] if m['format'] == self.tsp_mode) -# except StopIteration: -# 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 - -# nodes_list = jsondata['optimizations']['explicit-route-include-objects'] -# self.nodes_list = [n['unnumbered-hop']['node-id'] for n in nodes_list] -# # create a list for individual loose capability for each node ... -# # even if convert_service_sheet fills it with the same value -# self.loose_list = [n['unnumbered-hop']['hop-type'] for n in nodes_list] - -# self.spacing = jsondata['path-constraints']['te-bandwidth']['spacing'] -# self.power = jsondata['path-constraints']['te-bandwidth']['output-power'] -# self.nb_channel = jsondata['path-constraints']['te-bandwidth']['max-nb-of-channel'] - -# def __str__(self): -# return '\n\t'.join([ f'{type(self).__name__} {self.request_id}', -# f'source: {self.source}', -# f'destination: {self.destination}']) -# def __repr__(self): -# return '\n\t'.join([ f'{type(self).__name__} {self.request_id}', -# f'source: {self.source}', -# f'destination: {self.destination}', -# f'trx type: {self.tsp}', -# f'baudrate: {self.baudrate}', -# f'spacing: {self.spacing}', -# f'power: {self.power}' -# '\n']) - - class Result_element(Element): def __init__(self,path_request,computed_path): self.path_id = int(path_request.request_id)