Commit 514c4613 authored by Mohammad Ismaeel's avatar Mohammad Ismaeel
Browse files

Bugs in optical controller fixed

parent ad24389f
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -269,15 +269,14 @@ class RSA():
        print(f"fib updated {fib}")    
        #print(fib)
        
    def update_link_2(self, fib, slots, band,link):
    def update_link_2(self, fib, slots, band):
        #print(fib)
        for i in slots:
            fib[band][str(i)] = 0
        if 'used' in fib:
            fib['used'] = True
      
        set_link_update(fib,link)  
        #print(fib)    
    

    def update_optical_band(self, optical_band_id, slots, band):
        for i in slots:
@@ -294,14 +293,13 @@ class RSA():
            fib['used'] = False
        #fib[band].sort()
        
    def restore_link_2(self, fib, slots, band,link):
        print("start restoring link")
    def restore_link_2(self, fib, slots, band):
       
        for i in slots:
            fib[band][str(i)] = 1
        if 'used' in fib:
            fib['used'] = False
        #fib[band].keys().sort()    
        set_link_update(fib,link,test="restoration") 
       

    def restore_optical_band(self, optical_band_id, slots, band):
        for i in slots:
@@ -512,7 +510,7 @@ class RSA():
                    if list_in_list(slots, str_list_to_int(fib[band].keys())):
                        #fiber_list[l] = fib["ID"]
                        #self.update_link(fib, slots, band)
                        self.update_link_2(fib,slots,band,link)
                        self.update_link_2(fib,slots,band)
                        break
        print("INFO: Path forward computation completed")
        return fiber_list
+1 −61
Original line number Diff line number Diff line
@@ -262,64 +262,4 @@ def handle_slot (slot_field, slot):



def update_optical_band (optical_bands,optical_band_id,band,link):
    key_list = optical_bands[optical_band_id][band].keys()
    corrected_slots=optical_bands[optical_band_id][band]
    print(f"band {band}")
    print(f"corrected_slots_before {corrected_slots}")
    if (len(key_list) < 20):
        corrected_slots=correct_slot(optical_bands[optical_band_id][band])
        
    fib={}
    print(f"corrected_slots_after {corrected_slots}")    
    fib['c_slots']=link['optical_details']['c_slots']
    fib['l_slots']=link['optical_details']['l_slots']
    fib['s_slots']=link['optical_details']['s_slots']
      
    fib[band]=corrected_slots
    fib["src_port"]=optical_bands[optical_band_id]['src_port']
    fib["dst_port"]=optical_bands[optical_band_id]['dst_port']
    fib["local_peer_port"]=link["optical_details"]["local_peer_port"]
    fib["remote_peer_port"]=link["optical_details"]["remote_peer_port"]
    set_link_update(fib,link,test=f"restoring_optical_band {link['link_id']}")
    
def set_link_update (fib:dict,link:dict,test="updating"):
    
    print(f"invoked from {test}")
    print(f"fib updated {fib}")  
    optical_link = OpticalLink()
    linkId = LinkId()
    linkId.link_uuid.uuid=link["link_id"]["link_uuid"]["uuid"]
    optical_details = OpticalLinkDetails()
    optical_link.optical_details.length=0
    if "src_port" in fib :
       optical_link.optical_details.src_port=fib["src_port"]
    if "dst_port" in fib :   
       optical_link.optical_details.dst_port=fib["dst_port"]
    if "local_peer_port" in fib :   
       optical_link.optical_details.local_peer_port=fib['local_peer_port']
    if "remote_peer_port" in fib:   
       optical_link.optical_details.remote_peer_port=fib['remote_peer_port']
       
    optical_link.optical_details.used=fib['used'] if 'used' in fib else False
    if "c_slots" in fib :
        
        handle_slot( optical_link.optical_details.c_slots,fib["c_slots"])
    if "s_slots" in fib :
             
       handle_slot( optical_link.optical_details.s_slots,fib["s_slots"])
    if "l_slots" in fib :
           
       handle_slot( optical_link.optical_details.l_slots,fib["l_slots"])

    
    optical_link.name=link['name']
  
    optical_link.link_id.CopyFrom(linkId)
    ctx_client = ContextClient()
    ctx_client.connect()
    try:
        ctx_client.SetOpticalLink(optical_link)
    except Exception as err:
        print (f"setOpticalLink {err}")