mirror of
https://github.com/Telecominfraproject/oopt-gnpy.git
synced 2025-11-01 02:28:05 +00:00
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 <esther.lerouzic@orange.com>
This commit is contained in:
@@ -30,7 +30,7 @@ from gnpy.core.network import load_network, build_network
|
|||||||
from gnpy.core.equipment import load_equipment
|
from gnpy.core.equipment import load_equipment
|
||||||
from gnpy.core.elements import Transceiver, Roadm, Edfa, Fused
|
from gnpy.core.elements import Transceiver, Roadm, Edfa, Fused
|
||||||
from gnpy.core.utils import db2lin, lin2db
|
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 gnpy.core.request import Path_request, Result_element
|
||||||
from copy import copy, deepcopy
|
from copy import copy, deepcopy
|
||||||
from numpy import log10
|
from numpy import log10
|
||||||
@@ -47,14 +47,9 @@ parser.add_argument('-v', '--verbose', action='count')
|
|||||||
parser.add_argument('-o', '--output', default=None)
|
parser.add_argument('-o', '--output', default=None)
|
||||||
|
|
||||||
|
|
||||||
def load_Transceiver(filename):
|
def requests_from_json(json_data,equipment):
|
||||||
with open(filename) as f:
|
|
||||||
json_data = loads(f.read())
|
|
||||||
return json_data['Transceiver']
|
|
||||||
|
|
||||||
def requests_from_json(json_data,eqpt_filename):
|
|
||||||
requests_list = []
|
requests_list = []
|
||||||
tspjsondata = load_Transceiver(eqpt_filename)
|
tsp_lib = equipment['Transceiver']
|
||||||
|
|
||||||
for req in json_data['path-request']:
|
for req in json_data['path-request']:
|
||||||
#print(f'{req}')
|
#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']
|
params['trx_mode'] = req['path-constraints']['te-bandwidth']['trx_mode']
|
||||||
try:
|
try:
|
||||||
extra_params = next(m
|
extra_params = next(m
|
||||||
for t in tspjsondata if t['type_variety'] == params['trx_type']
|
for m in tsp_lib[params['trx_type']].mode if m['format'] == params['trx_mode'])
|
||||||
for m in t['mode'] if m['format'] == params['trx_mode'])
|
|
||||||
except StopIteration :
|
except StopIteration :
|
||||||
msg = f'could not find tsp : {params} with mode: {params} in eqpt library'
|
msg = f'could not find tsp : {params} with mode: {params} in eqpt library'
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
@@ -103,7 +97,8 @@ def compute_path(network, pathreqlist):
|
|||||||
edfa = [n for n in network.nodes() if isinstance(n, Edfa)]
|
edfa = [n for n in network.nodes() if isinstance(n, Edfa)]
|
||||||
# TODO include also fused in the element check : too difficult because of direction
|
# TODO include also fused in the element check : too difficult because of direction
|
||||||
# fused = [n for n in network.nodes() if isinstance(n, Fused)]
|
# 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:
|
for pathreq in pathreqlist:
|
||||||
pathreq.nodes_list.append(pathreq.destination)
|
pathreq.nodes_list.append(pathreq.destination)
|
||||||
#we assume that the destination is a strict constraint
|
#we assume that the destination is a strict constraint
|
||||||
@@ -148,7 +143,7 @@ def compute_path(network, pathreqlist):
|
|||||||
# for debug
|
# for debug
|
||||||
# print(f'{pathreq.baudrate} {pathreq.power} {pathreq.spacing} {pathreq.nb_channel}')
|
# print(f'{pathreq.baudrate} {pathreq.power} {pathreq.spacing} {pathreq.nb_channel}')
|
||||||
si = create_input_spectral_information(
|
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)
|
pathreq.baudrate, pathreq.power, pathreq.spacing, pathreq.nb_channel)
|
||||||
for el in total_path:
|
for el in total_path:
|
||||||
si = el(si)
|
si = el(si)
|
||||||
@@ -182,7 +177,7 @@ if __name__ == '__main__':
|
|||||||
equipment = load_equipment(args.eqpt_filename)
|
equipment = load_equipment(args.eqpt_filename)
|
||||||
network = load_network(args.network_filename,equipment)
|
network = load_network(args.network_filename,equipment)
|
||||||
build_network(network, equipment=equipment)
|
build_network(network, equipment=equipment)
|
||||||
pths = requests_from_json(data, args.eqpt_filename)
|
pths = requests_from_json(data, equipment)
|
||||||
print(pths)
|
print(pths)
|
||||||
test = compute_path(network,pths)
|
test = compute_path(network,pths)
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ from networkx import (draw_networkx_nodes, draw_networkx_edges,
|
|||||||
|
|
||||||
from gnpy.core import load_network, build_network
|
from gnpy.core import load_network, build_network
|
||||||
from gnpy.core.elements import Transceiver, Fiber, Edfa, Roadm
|
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__)
|
logger = getLogger(__name__)
|
||||||
|
|
||||||
@@ -48,21 +49,29 @@ def plot_results(network, path, source, sink):
|
|||||||
show()
|
show()
|
||||||
|
|
||||||
|
|
||||||
def main(network, equipment, source, sink):
|
def main(network, equipment, source, sink, req = None):
|
||||||
build_network(network, equipment=equipment)
|
build_network(network, equipment=equipment)
|
||||||
|
|
||||||
|
sidata = equipment['SI']['default']
|
||||||
|
|
||||||
|
print(sidata)
|
||||||
|
print('\n\n\n')
|
||||||
path = dijkstra_path(network, source, sink)
|
path = dijkstra_path(network, source, sink)
|
||||||
spans = [s.length for s in path if isinstance(s, Fiber)]
|
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'\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}:')
|
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
|
for p in range(0, 1): #change range to sweep results across several powers in dBm
|
||||||
p=db2lin(p)*1e-3
|
p=db2lin(p)*1e-3
|
||||||
spacing = 0.05 # THz
|
spacing = 0.05 # THz
|
||||||
si = SpectralInformation() # SI units: W, Hz
|
# si = SpectralInformation() # SI units: W, Hz
|
||||||
si = si.update(carriers=[
|
si = create_input_spectral_information(
|
||||||
Channel(f, (191.3 + spacing * f) * 1e12, 32e9, 0.15, Power(p, 0, 0))
|
sidata.f_min, sidata.roll_off,
|
||||||
for f in range(1,97)
|
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 :')
|
print(f'\nPropagating with input power = {lin2db(p*1e3):.2f}dBm :')
|
||||||
for el in path:
|
for el in path:
|
||||||
si = el(si)
|
si = el(si)
|
||||||
@@ -135,7 +144,27 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
logger.info(f'source = {args.source!r}')
|
logger.info(f'source = {args.source!r}')
|
||||||
logger.info(f'sink = {args.sink!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:
|
if args.plot:
|
||||||
plot_results(network, path, source, sink)
|
plot_results(network, path, source, sink)
|
||||||
|
|||||||
@@ -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)))
|
baudrate, roll_off, Power(power, 0, 0)) for f in range(1,nb_channel+1)))
|
||||||
return si
|
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__':
|
if __name__ == '__main__':
|
||||||
si = SpectralInformation(
|
si = SpectralInformation(
|
||||||
Channel(1, 193.95e12, 32e9, 0.15, # 193.95 THz, 32 Gbaud
|
Channel(1, 193.95e12, 32e9, 0.15, # 193.95 THz, 32 Gbaud
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ from gnpy.core.network import load_network, build_network
|
|||||||
from gnpy.core.equipment import load_equipment
|
from gnpy.core.equipment import load_equipment
|
||||||
from gnpy.core.elements import Transceiver, Roadm, Edfa, Fused
|
from gnpy.core.elements import Transceiver, Roadm, Edfa, Fused
|
||||||
from gnpy.core.utils import db2lin, lin2db
|
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 copy import copy, deepcopy
|
||||||
from numpy import log10
|
from numpy import log10
|
||||||
|
|
||||||
@@ -54,12 +54,10 @@ class Path_request:
|
|||||||
self.spacing = params.spacing
|
self.spacing = params.spacing
|
||||||
self.power = params.power
|
self.power = params.power
|
||||||
self.nb_channel = params.nb_channel
|
self.nb_channel = params.nb_channel
|
||||||
|
self.format = params.format
|
||||||
# class Path_request(Request):
|
self.OSNR = params.OSNR
|
||||||
# def __init__(self,*args, params=None, **kwargs):
|
self.bit_rate = params.bit_rate
|
||||||
# if params is None:
|
|
||||||
# params = {}
|
|
||||||
# super().__init__(*args, params=RequestParams(**params), **kwargs)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '\n\t'.join([ f'{type(self).__name__} {self.request_id}',
|
return '\n\t'.join([ f'{type(self).__name__} {self.request_id}',
|
||||||
@@ -75,51 +73,6 @@ class Path_request:
|
|||||||
f'power: {self.power}'
|
f'power: {self.power}'
|
||||||
'\n'])
|
'\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):
|
class Result_element(Element):
|
||||||
def __init__(self,path_request,computed_path):
|
def __init__(self,path_request,computed_path):
|
||||||
self.path_id = int(path_request.request_id)
|
self.path_id = int(path_request.request_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user