Skip to content
Snippets Groups Projects

Resolve: "(CNIT) Multi-Granular Optical Nodes and Optical Transpoders management"

Merged Lluis Gifre Renom requested to merge cnit_related_activity into develop
4 files
+ 70
96
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -12,18 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import time
from flask import Flask
from flask import render_template
from flask_restplus import Resource, Api
from tools import *
from variables import *
from RSA import RSA
import time , logging
from common.proto.context_pb2 import TopologyId , OpticalLink
import json
from google.protobuf.message import Message
from common.proto.context_pb2 import TopologyId
from google.protobuf.json_format import MessageToDict
from common.tools.object_factory.OpticalLink import order_dict
global rsa
global links_dict
rsa = None
@@ -105,6 +104,8 @@ class AddFlexLightpath(Resource):
return rsa.optical_bands[optical_band_id], 200
else:
return "Error", 404
# @optical.route('/DelFlexLightpath/<string:src>/<string:dst>/<int:bitrate>/<int:o_band_id>')
@optical.route('/DelFlexLightpath/<string:src>/<string:dst>/<int:bitrate>/<int:o_band_id>')
@optical.route('/DelFlexLightpath/<string:src>/<string:dst>/<int:bitrate>/<int:o_band_id>/<int:flow_id>')
@@ -147,17 +148,12 @@ class DelFLightpath(Resource):
return "flow {} not matching".format(flow_id), 404
else:
if match1:
# if delete_band !=0 and ob_id is not None:
# print(f"delete_lightpath {delete_band} and ob_id {ob_id}")
# if len( rsa.optical_bands[ob_id]["served_lightpaths"]) != 0:
# return "DELETE_NOT_ALLOWED" ,400
rsa.del_flow(flow,flow_id,ob_id)
if debug:
print(f"vor ob_id {ob_id} rsa.optical_bands {rsa.optical_bands[ob_id]}")
print(f"rsa.links_dict {rsa.links_dict}")
@@ -166,9 +162,6 @@ class DelFLightpath(Resource):
return "flow {} not matching".format(flow_id), 404
else:
return "flow id {} does not exist".format(flow_id), 404
@optical.route('/DelOpticalBand/<string:src>/<string:dst>/<int:o_band_id>',methods=['DELETE'])
@@ -225,11 +218,6 @@ class DelOpticalBand(Resource):
return "flow for ob_id {} not found".format(ob_id),400
else:
return "ob_id {} does not exist".format(ob_id), 404
@optical.route('/DelLightpath/<int:flow_id>/<string:src>/<string:dst>/<int:bitrate>')
@@ -267,6 +255,7 @@ class GetFlows(Resource):
except:
return "Error", 404
@optical.route('/GetOpticalBands')
@optical.response(200, 'Success')
@optical.response(404, 'Error, not found')
@@ -312,8 +301,8 @@ class GetFlows(Resource):
return links, 200
except:
return "Error", 404
@optical.route('/GetTopology/<path:context_id>/<path:topology_id>',methods=['GET'])
@optical.response(200, 'Success')
@optical.response(404, 'Error, not found')
@@ -329,56 +318,45 @@ class GetTopology(Resource):
topog_id.topology_uuid.uuid=topology_id
topog_id.context_id.context_uuid.uuid=context_id
try:
links_dict={"optical_links":[]}
node_dict = {}
topo , nodes = readTopologyDataFromContext(topog_id)
for link in topo:
link_dict_type = MessageToDict(link, preserving_proto_field_name=True)
if "c_slots" in link_dict_type["optical_details"] :
link_dict_type["optical_details"]["c_slots"]=order_dict(link_dict_type["optical_details"]["c_slots"])
if "l_slots" in link_dict_type["optical_details"] :
link_dict_type["optical_details"]["l_slots"]=order_dict(link_dict_type["optical_details"]["l_slots"])
if "s_slots" in link_dict_type["optical_details"] :
link_dict_type["optical_details"]["s_slots"]=order_dict(link_dict_type["optical_details"]["s_slots"])
links_dict["optical_links"].append(link_dict_type)
for device in nodes :
dev_dic = {}
dev_dic = {
"id":device.device_id.device_uuid.uuid,
#"ip":f"10.30.2.{207+i}",
#"port":"50001",
"type":"OC-ROADM" if device.device_type =="optical-roadm" else "OC-TP",
"driver": "OpticalOC"
}
node_dict[device.name]=dev_dic
#i+=1
#print(f"refresh_optical controller optical_links_dict= {links_dict}")
#print(f"refresh_optical controller node_dict {node_dict}")
rsa = RSA(node_dict, links_dict)
if debug:
print(rsa.init_link_slots2(testing))
return "ok" ,200
try:
links_dict = {"optical_links": []}
node_dict = {}
topo, nodes = readTopologyDataFromContext(topog_id)
for link in topo:
link_dict_type = MessageToDict(link, preserving_proto_field_name=True)
if "c_slots" in link_dict_type["optical_details"]:
link_dict_type["optical_details"]["c_slots"] = link_dict_type["optical_details"]["c_slots"]
if "l_slots" in link_dict_type["optical_details"]:
link_dict_type["optical_details"]["l_slots"] = link_dict_type["optical_details"]["l_slots"]
if "s_slots" in link_dict_type["optical_details"]:
link_dict_type["optical_details"]["s_slots"] = link_dict_type["optical_details"]["s_slots"]
links_dict["optical_links"].append(link_dict_type)
for device in nodes :
dev_dic = {
"id":device.device_id.device_uuid.uuid,
#"ip":f"10.30.2.{207+i}",
#"port":"50001",
"type":"OC-ROADM" if device.device_type =="optical-roadm" else "OC-TP",
"driver": "OpticalOC"
}
node_dict[device.name] = dev_dic
#i+=1
#print(f"refresh_optical controller optical_links_dict= {links_dict}")
#print(f"refresh_optical controller node_dict {node_dict}")
rsa = RSA(node_dict, links_dict)
if debug:
print(rsa.init_link_slots2(testing))
return "ok", 200
except Exception as e:
print(f"err {e}")
return "Error", 400
if __name__ == '__main__':
app.run(host='0.0.0.0', port=10060)
Loading