Skip to content
Snippets Groups Projects
Commit c95dd557 authored by Andrea Sgambelluri's avatar Andrea Sgambelluri
Browse files

"temp system"

parent 6c633636
No related branches found
No related tags found
2 merge requests!294Release TeraFlowSDN 4.0,!284Resolve: "(CNIT) Multi-Granular Optical Nodes and Optical Transpoders management"
......@@ -6,6 +6,7 @@ from variables import *
from RSA import RSA
import time , logging
from common.proto.context_pb2 import TopologyId
import json
......@@ -200,21 +201,24 @@ class GetBand(Resource):
class GetFlows(Resource):
@staticmethod
def get():
global links_dict
#global links_dict
global rsa
links = rsa.links_dict
try:
if debug:
print(links_dict)
return links_dict, 200
print(links)
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')
class GetTopology(Resource):
@staticmethod
def get(context_id:str,topology_id:str):
global rsa
topog_id = TopologyId()
topog_id.topology_uuid.uuid=topology_id
topog_id.context_id.context_uuid.uuid=context_id
......@@ -222,26 +226,30 @@ class GetTopology(Resource):
try:
links_dict={"optical_links":[]}
node_dict = {}
i=0
nodes , topo = readTopologyDataFromContext(topog_id)
topo , nodes = readTopologyDataFromContext(topog_id)
for node in nodes :
links_dict["optical_links"].append(node)
for device in topo :
dic = {}
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-ROADM",
"driver": "OpticalOC"
}
node_dict[device.name]=dic
i+=1
print(f"refresh_opticacontroller optical_links_dict {links_dict}")
print(f"refresh_opticacontroller node_dict {node_dict}")
rsa = RSA(node_dict, links_dict)
return "Done"
for link in topo:
links_dict["optical_links"].append(link)
#print(link["optical_details"]["c_slots"])
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= {json.dump(links_dict)}")
print(f"refresh_optical controller node_dict {json.dump(node_dict)}")
rsa = RSA(node_dict, links_dict)
return rsa.links_dict
except Exception as e:
print(f"err {e}")
return "Error", 404
......@@ -252,7 +260,7 @@ class GetTopology(Resource):
if __name__ == '__main__':
nodes_dict, links_dict = readTopologyData(nodes_json, topology_json)
#nodes_dict, links_dict = readTopologyData(nodes_json, topology_json)
#rsa = RSA(nodes_dict, links_dict)
......
......@@ -18,6 +18,7 @@ class RSA():
self.s_slot_number = 0
self.optical_bands = {}
print(f"node_ctxt {nodes} links_ctxt {links}")
def init_link_slots(self, testing):
if not testing:
for l in self.links_dict["optical_links"]:
......
......@@ -143,9 +143,9 @@ def readTopologyData(nodes, topology):
nodes_file.close()
topo_file.close()
return nodes, topo
def readTopologyDataFromContext(topology_id:TopologyId):
def readTopologyDataFromContext(topology_id:TopologyId):
ctx_client = ContextClient()
ctx_client.connect()
topo_details = ctx_client.GetTopologyDetails(topology_id)
......@@ -153,7 +153,7 @@ def readTopologyDataFromContext(topology_id:TopologyId):
nodes = topo_details.devices
ctx_client.close()
return topo , nodes
def reverse_links(links):
temp_links = links.copy()
......@@ -167,7 +167,7 @@ def reverse_links(links):
def get_links_from_node(topology, node):
result = {}
for link in topology["links"]:
for link in topology["optical_links"]:
if "{}-".format(node) in link["name"]:
result[link["name"]] = link
return result
......@@ -175,7 +175,7 @@ def get_links_from_node(topology, node):
def get_links_to_node(topology, node):
result = {}
for link in topology["links"]:
for link in topology["optical_links"]:
if "-{}".format(node) in link["name"]:
result[link["name"]] = link
return result
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment