Commit be92f747 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Pre-merge code cleanup

parent 7fc4cd83
Loading
Loading
Loading
Loading
+21 −29
Original line number Diff line number Diff line
@@ -137,12 +137,7 @@ class DescriptorLoader:
        self.__slices        = self.__descriptors.get('slices'     ,  [])
        self.__ietf_slices   = self.__descriptors.get('ietf-network-slice-service:network-slice-services', {})
        self.__connections   = self.__descriptors.get('connections',  [])
        
        #--------------- Experimental Optical Link --------------
        
        self.__optical_links = self.__descriptors.get("optical_links",[])
        
        
        self.__optical_links = self.__descriptors.get('optical_links',[])

        if len(self.__ietf_slices) > 0:
            for slice_service in self.__ietf_slices["slice-service"]:
@@ -292,7 +287,6 @@ class DescriptorLoader:
    @property
    def num_connections(self) -> int: return len(self.__connections)
    
    #------------- Experimental ---------------
    @property
    def optical_links(self) -> List[Dict]: return self.__optical_links

@@ -368,8 +362,6 @@ class DescriptorLoader:
        self._process_descr('service',    'update', self.__svc_cli.UpdateService,   Service,     self.__services      )
        self._process_descr('slice',      'add',    self.__slc_cli.CreateSlice,     Slice,       self.__slices_add    )
        self._process_descr('slice',      'update', self.__slc_cli.UpdateSlice,     Slice,       self.__slices        )
        
        #----------------------------------- Experimental ---------------------------------------
        self._process_descr('link',       'add',    self.__ctx_cli.SetOpticalLink,  OpticalLink, self.__optical_links )

        # By default the Context component automatically assigns devices and links to topologies based on their
+29 −64
Original line number Diff line number Diff line

# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import copy

def convert_to_dict(single_val:int)->dict:
    slot= dict()
@@ -8,68 +22,19 @@ def convert_to_dict (single_val:int)->dict:
        slot[str(i+1)]=int(sliced_num[i])
    return slot


def order_list (lst:list[tuple])->list:

    if (len(lst)<=1):
        return lst
    else :
        pivot,bit_val =lst[0]
        lst_smaller = []
        lst_greater = []
        for element in lst[1:]:
            key,val=element
            if (key <= pivot):
                lst_smaller.append(element)
            else :
                lst_greater.append(element)
        return order_list(lst_smaller) + [(pivot,bit_val)] + order_list(lst_greater)        
                
  
def list_to_dict (lst:list[tuple[int,int]])->dict:
    dct = dict()
    for ele in lst :
        key,value = ele
        dct[str(key)]=value
    return dct    
        
            
def order_dict (dct:dict)->dict:
   
    lst = list()  
    for key,value in sorted(dct.items()):
        lst.append((int(key),value))
    ordered_lst= order_list(lst)
    if (len(ordered_lst)>0):
        return list_to_dict (ordered_lst)    

def order_dict_v1 (dct:dict)->dict:
   
    lst = list()  
    for key,value in dct.items():
        lst.append((int(key),value))
    ordered_lst= order_list(lst)
    if (len(ordered_lst)>0):
        return list_to_dict (ordered_lst)        
      
def correct_slot (dic:dict):
    ordered_dict= order_dict_v1(dic)
    keys_list = list(ordered_dict.keys())
   
    if (len(keys_list) < 20):
        num_keys= []
        for i in keys_list:
            num_keys.append(int(i)) 
                 
def correct_slot(dic: dict) -> dict:
    _dict = copy.deepcopy(dic)
    keys_list = list(_dict.keys())
    if len(keys_list) < 20:
        num_keys = [int(i) for i in keys_list]
        if num_keys[-1] != 20:
            missed_keys = []
            diff = 20 - len(num_keys)
            print(f"diff {diff}")
            #print(f"diff {diff}")
            for i in range(diff+1):
                missed_keys.append(num_keys[-1]+i)
            print(f"missed_keys {missed_keys}")     
            #print(f"missed_keys {missed_keys}")
            for key in missed_keys :
                ordered_dict[key]=1
            print(f"result {ordered_dict}")    
    return order_dict_v1(ordered_dict)                
                
 No newline at end of file
                _dict[key]=1
            #print(f"result {_dict}")
    return _dict