mirror of
https://github.com/Telecominfraproject/oopt-gnpy.git
synced 2025-11-03 19:47:46 +00:00
changes for OFC demo
This commit is contained in:
7631
examples/CORONET_CONUS_Topology.json
Normal file
7631
examples/CORONET_CONUS_Topology.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -19,20 +19,42 @@ from json import loads
|
||||
from collections import Counter
|
||||
from logging import getLogger, basicConfig, INFO, ERROR, DEBUG
|
||||
from numpy import linspace, mean
|
||||
from matplotlib.pyplot import show, axis, figure, title
|
||||
from matplotlib.pyplot import show, axis, figure, title, text
|
||||
from networkx import (draw_networkx_nodes, draw_networkx_edges,
|
||||
draw_networkx_labels, dijkstra_path)
|
||||
from gnpy.core.network import load_network, build_network, save_network
|
||||
from gnpy.core.elements import Transceiver, Fiber, Edfa, Roadm
|
||||
from gnpy.core.info import create_input_spectral_information, SpectralInformation, Channel, Power, Pref
|
||||
from gnpy.core.request import Path_request, RequestParams, compute_constrained_path, propagate
|
||||
from gnpy.core.request import Path_request, RequestParams, compute_constrained_path, propagate2
|
||||
|
||||
logger = getLogger(__name__)
|
||||
|
||||
def plot_results(network, path, source, destination):
|
||||
def plot_baseline(network):
|
||||
edges = set(network.edges())
|
||||
pos = {n: (n.lng, n.lat) for n in network.nodes()}
|
||||
labels = {n: n.location.city for n in network.nodes() if isinstance(n, Transceiver)}
|
||||
city_labels = set(labels.values())
|
||||
for n in network.nodes():
|
||||
if n.location.city and n.location.city not in city_labels:
|
||||
labels[n] = n.location.city
|
||||
city_labels.add(n.location.city)
|
||||
label_pos = pos
|
||||
|
||||
fig = figure()
|
||||
kwargs = {'figure': fig, 'pos': pos}
|
||||
plot = draw_networkx_nodes(network, nodelist=network.nodes(), node_color='#ababab', **kwargs)
|
||||
draw_networkx_edges(network, edgelist=edges, edge_color='#ababab', **kwargs)
|
||||
draw_networkx_labels(network, labels=labels, font_size=14, **{**kwargs, 'pos': label_pos})
|
||||
axis('off')
|
||||
show()
|
||||
|
||||
def plot_results(network, path, source, destination, infos):
|
||||
path_edges = set(zip(path[:-1], path[1:]))
|
||||
edges = set(network.edges()) - path_edges
|
||||
pos = {n: (n.lng, n.lat) for n in network.nodes()}
|
||||
nodes = {}
|
||||
for k, (x, y) in pos.items():
|
||||
nodes.setdefault((round(x, 0), round(y, 0)), []).append(k)
|
||||
labels = {n: n.location.city for n in network.nodes() if isinstance(n, Transceiver)}
|
||||
city_labels = set(labels.values())
|
||||
for n in network.nodes():
|
||||
@@ -50,6 +72,24 @@ def plot_results(network, path, source, destination):
|
||||
draw_networkx_labels(network, labels=labels, font_size=14, **{**kwargs, 'pos': label_pos})
|
||||
title(f'Propagating from {source.loc.city} to {destination.loc.city}')
|
||||
axis('off')
|
||||
|
||||
textbox = text(0.85, 0.50, 'Spectral Information\n', fontsize=12, fontname='Ubuntu Mono',
|
||||
verticalalignment='top', transform=fig.axes[0].transAxes,
|
||||
bbox={'boxstyle': 'round', 'facecolor': 'wheat', 'alpha': 0.5})
|
||||
|
||||
def hover(event):
|
||||
if event.xdata is None or event.ydata is None:
|
||||
return
|
||||
if fig.contains(event):
|
||||
x, y = round(event.xdata, 0), round(event.ydata, 0)
|
||||
if (x, y) in nodes:
|
||||
disp = [n for n in nodes[x, y] if n in infos]
|
||||
msg = "\n\n".join(str(n) for n in disp)
|
||||
msg = f'Spectral Information\n\n{msg}'
|
||||
textbox.set_text(msg)
|
||||
fig.canvas.draw_idle()
|
||||
|
||||
fig.canvas.mpl_connect('motion_notify_event', hover)
|
||||
show()
|
||||
|
||||
|
||||
@@ -95,15 +135,15 @@ def main(network, equipment, source, destination, req = None):
|
||||
for dp_db in power_range:
|
||||
req.power = db2lin(pref_ch_db + dp_db)*1e-3
|
||||
print(f'\nPropagating with input power = {lin2db(req.power*1e3):.2f}dBm :')
|
||||
propagate(path, req, equipment, show=len(power_range)==1)
|
||||
infos = propagate2(path, req, equipment, show=len(power_range)==1)
|
||||
print(f'\nTransmission result for input power = {lin2db(req.power*1e3):.2f}dBm :')
|
||||
print(destination)
|
||||
|
||||
|
||||
#print(f'\n !!!!!!!!!!!!!!!!! TEST POINT !!!!!!!!!!!!!!!!!!!!!')
|
||||
#print(f'carriers ase output of {path[1]} =\n {list(path[1].carriers("out", "nli"))}')
|
||||
# => use "in" or "out" parameter
|
||||
# => use "nli" or "ase" or "signal" or "total" parameter
|
||||
|
||||
|
||||
simulation_data.append({
|
||||
'Pch_dBm' : pref_ch_db + dp_db,
|
||||
'OSNR_ASE_0.1nm' : round(mean(destination.osnr_ase_01nm),2),
|
||||
@@ -112,7 +152,7 @@ def main(network, equipment, source, destination, req = None):
|
||||
'SNR_total_signal_bw' : round(mean(destination.snr),2)
|
||||
})
|
||||
write_csv(result_dicts, 'simulation_result.csv')
|
||||
return path
|
||||
return path, infos
|
||||
|
||||
|
||||
parser = ArgumentParser()
|
||||
@@ -136,10 +176,9 @@ if __name__ == '__main__':
|
||||
basicConfig(level={0: ERROR, 1: INFO, 2: DEBUG}.get(args.verbose, DEBUG))
|
||||
|
||||
equipment = load_equipment(args.equipment)
|
||||
# logger.info(equipment)
|
||||
# print(args.filename)
|
||||
network = load_network(args.filename, equipment, args.names_matching)
|
||||
# print(network)
|
||||
|
||||
plot_baseline(network)
|
||||
|
||||
transceivers = {n.uid: n for n in network.nodes() if isinstance(n, Transceiver)}
|
||||
|
||||
@@ -152,7 +191,7 @@ if __name__ == '__main__':
|
||||
for uid in transceivers:
|
||||
print(uid)
|
||||
exit()
|
||||
|
||||
|
||||
#First try to find exact match if source/destination provided
|
||||
if args.source:
|
||||
source = transceivers.pop(args.source, None)
|
||||
@@ -160,30 +199,30 @@ if __name__ == '__main__':
|
||||
else:
|
||||
source = None
|
||||
logger.info('No source node specified: picking random transceiver')
|
||||
|
||||
|
||||
if args.destination:
|
||||
destination = transceivers.pop(args.destination, None)
|
||||
valid_destination = True if destination else False
|
||||
else:
|
||||
destination = None
|
||||
logger.info('No destination node specified: picking random transceiver')
|
||||
|
||||
|
||||
#If no exact match try to find partial match
|
||||
if args.source and not source:
|
||||
#TODO code a more advanced regex to find nodes match
|
||||
source = next((transceivers.pop(uid) for uid in transceivers \
|
||||
if args.source.lower() in uid.lower()), None)
|
||||
|
||||
|
||||
if args.destination and not destination:
|
||||
#TODO code a more advanced regex to find nodes match
|
||||
destination = next((transceivers.pop(uid) for uid in transceivers \
|
||||
if args.destination.lower() in uid.lower()), None)
|
||||
|
||||
|
||||
#If no partial match or no source/destination provided pick random
|
||||
if not source:
|
||||
source = list(transceivers.values())[0]
|
||||
del transceivers[source.uid]
|
||||
|
||||
|
||||
if not destination:
|
||||
destination = list(transceivers.values())[0]
|
||||
|
||||
@@ -205,18 +244,18 @@ if __name__ == '__main__':
|
||||
trx_params['power'] = db2lin(float(args.power))*1e-3
|
||||
params.update(trx_params)
|
||||
req = Path_request(**params)
|
||||
path = main(network, equipment, source, destination, req)
|
||||
path, infos = main(network, equipment, source, destination, req)
|
||||
save_network(args.filename, network)
|
||||
|
||||
if not args.source:
|
||||
print(f'\n(No source node specified: picked {source.uid})')
|
||||
elif not valid_source:
|
||||
print(f'\n(Invalid source node {args.source!r} replaced with {source.uid})')
|
||||
|
||||
|
||||
if not args.destination:
|
||||
print(f'\n(No destination node specified: picked {destination.uid})')
|
||||
elif not valid_destination:
|
||||
print(f'\n(Invalid destination node {args.destination!r} replaced with {destination.uid})')
|
||||
|
||||
|
||||
if args.plot:
|
||||
plot_results(network, path, source, destination)
|
||||
plot_results(network, path, source, destination, infos)
|
||||
|
||||
@@ -505,7 +505,7 @@ class Edfa(Node):
|
||||
|
||||
def __repr__(self):
|
||||
return (f'{type(self).__name__}(uid={self.uid!r}, '
|
||||
f'type_variety={self.params.type_variety!r}'
|
||||
f'type_variety={self.params.type_variety!r}, '
|
||||
f'interpol_dgt={self.interpol_dgt!r}, '
|
||||
f'interpol_gain_ripple={self.interpol_gain_ripple!r}, '
|
||||
f'interpol_nf_ripple={self.interpol_nf_ripple!r}, '
|
||||
|
||||
@@ -309,6 +309,14 @@ def add_egress_amplifier(network, node):
|
||||
amp = Edfa(
|
||||
uid = f'Edfa{i}_{node.uid}',
|
||||
params = {},
|
||||
metadata = {
|
||||
'location': {
|
||||
'latitude': (node.lat + next_node.lat) / 2,
|
||||
'longitude': (node.lng + next_node.lng) / 2,
|
||||
'city': node.loc.city,
|
||||
'region': node.loc.region,
|
||||
}
|
||||
},
|
||||
operational = {
|
||||
'gain_target': 0,
|
||||
'tilt_target': 0,
|
||||
|
||||
@@ -398,6 +398,22 @@ def propagate(path, req, equipment, show=False):
|
||||
path[-1].update_snr(req.tx_osnr, equipment['Roadms']['default'].add_drop_osnr)
|
||||
return path
|
||||
|
||||
def propagate2(path, req, equipment, show=False):
|
||||
#update roadm loss in case of power sweep (power mode only)
|
||||
set_roadm_loss(path, equipment, lin2db(req.power*1e3))
|
||||
si = create_input_spectral_information(
|
||||
req.f_min, req.f_max, req.roll_off, req.baud_rate,
|
||||
req.power, req.spacing)
|
||||
infos = {}
|
||||
for el in path:
|
||||
before_si = si
|
||||
after_si = si = el(si)
|
||||
infos[el] = before_si, after_si
|
||||
if show :
|
||||
print(el)
|
||||
path[-1].update_snr(req.tx_osnr, equipment['Roadms']['default'].add_drop_osnr)
|
||||
return infos
|
||||
|
||||
def propagate_and_optimize_mode(path, req, equipment):
|
||||
#update roadm loss in case of power sweep (power mode only)
|
||||
set_roadm_loss(path, equipment, lin2db(req.power*1e3))
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
alabaster==0.7.12
|
||||
appdirs==1.4.3
|
||||
atomicwrites==1.2.1
|
||||
attrs==18.2.0
|
||||
Babel==2.6.0
|
||||
black==18.9b0
|
||||
certifi==2018.10.15
|
||||
chardet==3.0.4
|
||||
Click==7.0
|
||||
cycler==0.10.0
|
||||
decorator==4.3.0
|
||||
docutils==0.14
|
||||
@@ -36,5 +39,6 @@ snowballstemmer==1.2.1
|
||||
Sphinx==1.8.1
|
||||
sphinxcontrib-bibtex==0.4.0
|
||||
sphinxcontrib-websupport==1.1.0
|
||||
toml==0.10.0
|
||||
urllib3==1.23
|
||||
xlrd==1.1.0
|
||||
|
||||
2
setup.py
2
setup.py
@@ -11,7 +11,7 @@ with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
|
||||
|
||||
setup(
|
||||
name='gnpy',
|
||||
version='0.1.3',
|
||||
version='1.2.0',
|
||||
description='route planning and optimization tool for mesh optical networks',
|
||||
long_description=long_description,
|
||||
long_description_content_type='text/x-rst; charset=UTF-8',
|
||||
|
||||
Reference in New Issue
Block a user