Skip to content
Snippets Groups Projects
Commit d68868c7 authored by Mohammad Ismaeel's avatar Mohammad Ismaeel
Browse files

OpticalController reading from context

parent c95dd557
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"
...@@ -5,11 +5,12 @@ from tools import * ...@@ -5,11 +5,12 @@ from tools import *
from variables import * from variables import *
from RSA import RSA from RSA import RSA
import time , logging import time , logging
from common.proto.context_pb2 import TopologyId from common.proto.context_pb2 import TopologyId , OpticalLink
import json import json
from google.protobuf.message import Message
from google.protobuf.json_format import MessageToDict
global rsa
global links_dict
rsa = None rsa = None
...@@ -201,9 +202,11 @@ class GetBand(Resource): ...@@ -201,9 +202,11 @@ class GetBand(Resource):
class GetFlows(Resource): class GetFlows(Resource):
@staticmethod @staticmethod
def get(): def get():
#global links_dict
global rsa global rsa
links = rsa.links_dict #global links_dict
links = None
if rsa is not None :
links = rsa.links_dict
try: try:
if debug: if debug:
print(links) print(links)
...@@ -218,21 +221,24 @@ class GetFlows(Resource): ...@@ -218,21 +221,24 @@ class GetFlows(Resource):
class GetTopology(Resource): class GetTopology(Resource):
@staticmethod @staticmethod
def get(context_id:str,topology_id:str): def get(context_id:str,topology_id:str):
logging.info("get the request")
global rsa global rsa
topog_id = TopologyId() topog_id = TopologyId()
topog_id.topology_uuid.uuid=topology_id topog_id.topology_uuid.uuid=topology_id
topog_id.context_id.context_uuid.uuid=context_id topog_id.context_id.context_uuid.uuid=context_id
print(f"topog_id {topog_id}")
try: try:
links_dict={"optical_links":[]} links_dict={"optical_links":[]}
node_dict = {} node_dict = {}
topo , nodes = readTopologyDataFromContext(topog_id) topo , nodes = readTopologyDataFromContext(topog_id)
for link in topo: for link in topo:
links_dict["optical_links"].append(link) link_dict_type = MessageToDict(link, preserving_proto_field_name=True)
#print(link["optical_details"]["c_slots"]) links_dict["optical_links"].append(link_dict_type)
for device in nodes : for device in nodes :
dev_dic = {} dev_dic = {}
dev_dic = { dev_dic = {
"id":device.device_id.device_uuid.uuid, "id":device.device_id.device_uuid.uuid,
...@@ -243,27 +249,22 @@ class GetTopology(Resource): ...@@ -243,27 +249,22 @@ class GetTopology(Resource):
} }
node_dict[device.name]=dev_dic node_dict[device.name]=dev_dic
#i+=1 #i+=1
print(f"refresh_optical controller optical_links_dict= {json.dump(links_dict)}") #print(f"refresh_optical controller optical_links_dict= {links_dict}")
print(f"refresh_optical controller node_dict {json.dump(node_dict)}") #print(f"refresh_optical controller node_dict {node_dict}")
rsa = RSA(node_dict, links_dict)
rsa = RSA(node_dict, links_dict)
return "ok" ,200
return rsa.links_dict
except Exception as e: except Exception as e:
print(f"err {e}") print(f"err {e}")
return "Error", 404 return "Error", 400
if __name__ == '__main__': if __name__ == '__main__':
#nodes_dict, links_dict = readTopologyData(nodes_json, topology_json)
#rsa = RSA(nodes_dict, links_dict)
#print(rsa.init_link_slots2(testing))
app.run(host='0.0.0.0', port=10060) app.run(host='0.0.0.0', port=10060)
...@@ -17,7 +17,7 @@ class RSA(): ...@@ -17,7 +17,7 @@ class RSA():
self.l_slot_number = 0 self.l_slot_number = 0
self.s_slot_number = 0 self.s_slot_number = 0
self.optical_bands = {} self.optical_bands = {}
print(f"node_ctxt {nodes} links_ctxt {links}")
def init_link_slots(self, testing): def init_link_slots(self, testing):
if not testing: if not testing:
...@@ -86,7 +86,9 @@ class RSA(): ...@@ -86,7 +86,9 @@ class RSA():
self.g.printGraph() self.g.printGraph()
def initGraph2(self): def initGraph2(self):
self.g = dijsktra.Graph() self.g = dijsktra.Graph()
for n in self.nodes_dict: for n in self.nodes_dict:
self.g.add_vertex(n) self.g.add_vertex(n)
for l in self.links_dict["optical_links"]: for l in self.links_dict["optical_links"]:
......
...@@ -83,15 +83,19 @@ def extract_value (xml_data): ...@@ -83,15 +83,19 @@ def extract_value (xml_data):
else: else:
print(" element not found.") print(" element not found.")
def main () : if __name__ == '__main__':
with manager.connect(**device) as m: # with manager.connect(**device) as m:
# Perform operations on the remote machine using the 'm' object # # Perform operations on the remote machine using the 'm' object
# For example, you can retrieve the running configuration: # # For example, you can retrieve the running configuration:
#result =m.edit_config(target='running',config=edit_config) # #result =m.edit_config(target='running',config=edit_config)
running_config = m.get_config('running').data_xml # running_config = m.get_config('running').data_xml
#extract_roadm_ports(running_config) # #extract_roadm_ports(running_config)
x,y= [1,3] # x,y= [1,3]
print (x) # print (x)
nodes = {
"t13":{"name":"t1","value":1},
"t2":{"name":"t2","value":2}
}
for n in nodes :
print (n)
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