Commit d68868c7 authored by Mohammad Ismaeel's avatar Mohammad Ismaeel
Browse files

OpticalController reading from context

parent c95dd557
Loading
Loading
Loading
Loading
+30 −29
Original line number Diff line number Diff line
@@ -5,11 +5,12 @@ from tools import *
from variables import *
from RSA import RSA
import time , logging
from common.proto.context_pb2 import TopologyId
from common.proto.context_pb2 import TopologyId , OpticalLink
import json



from google.protobuf.message import Message
from google.protobuf.json_format import MessageToDict
global rsa
global links_dict
rsa = None


@@ -201,8 +202,10 @@ class GetBand(Resource):
class GetFlows(Resource):
    @staticmethod
    def get():
        #global links_dict
        global rsa
        #global links_dict
        links = None
        if rsa is not None :
           links = rsa.links_dict
        try:
            if debug:
@@ -218,19 +221,22 @@ class GetFlows(Resource):
class GetTopology(Resource):
    @staticmethod
    def get(context_id:str,topology_id:str):
        logging.info("get the request")
        global rsa
        topog_id = TopologyId()
        topog_id.topology_uuid.uuid=topology_id
        topog_id.context_id.context_uuid.uuid=context_id
       
        print(f"topog_id {topog_id}")
        try: 
                links_dict={"optical_links":[]}
                node_dict = {}
                topo , nodes = readTopologyDataFromContext(topog_id)

                for link in topo: 
                links_dict["optical_links"].append(link)
                #print(link["optical_details"]["c_slots"])
                      link_dict_type = MessageToDict(link, preserving_proto_field_name=True)
                      links_dict["optical_links"].append(link_dict_type)
                    
                    
                
                for device in nodes :
                    dev_dic = {}
@@ -243,16 +249,16 @@ class GetTopology(Resource):
                        }
                    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)}") 
                    #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) 
            
            
            return rsa.links_dict
                return  "ok" ,200
        except Exception as e:
            print(f"err {e}")
            return "Error", 404
            return "Error", 400
        


@@ -260,10 +266,5 @@ class GetTopology(Resource):
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)
+3 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ class RSA():
        self.l_slot_number = 0
        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:
@@ -86,7 +86,9 @@ class RSA():
            self.g.printGraph()

    def initGraph2(self):
     
        self.g = dijsktra.Graph()
     
        for n in self.nodes_dict:
            self.g.add_vertex(n)
        for l in self.links_dict["optical_links"]:
+15 −11
Original line number Diff line number Diff line
@@ -83,15 +83,19 @@ def extract_value (xml_data):
      
    else:
       print(" element not found.")
def main () : 
        with manager.connect(**device) as m:
            # Perform operations on the remote machine using the 'm' object
            # For example, you can retrieve the running configuration:
            #result =m.edit_config(target='running',config=edit_config)
            running_config = m.get_config('running').data_xml
        
            #extract_roadm_ports(running_config)
        x,y= [1,3]
        print (x)    
            
if __name__ == '__main__':
        # with manager.connect(**device) as m:
        #     # Perform operations on the remote machine using the 'm' object
        #     # For example, you can retrieve the running configuration:
        #     #result =m.edit_config(target='running',config=edit_config)
        #     running_config = m.get_config('running').data_xml
        
        #     #extract_roadm_ports(running_config)
        # x,y= [1,3]
        # print (x)    
    nodes = { 
             "t13":{"name":"t1","value":1},
             "t2":{"name":"t2","value":2}
             }    
    for n in nodes :
        print (n)