Commit 7def79c1 authored by Pablo Armingol's avatar Pablo Armingol
Browse files

Slices with IETF format

parent b8249f37
Loading
Loading
Loading
Loading
+75 −22
Original line number Diff line number Diff line
@@ -105,9 +105,69 @@ class DescriptorLoader:
        self.__devices     = self.__descriptors.get('devices'    , [])
        self.__links       = self.__descriptors.get('links'      , [])
        self.__services    = self.__descriptors.get('services'   , [])
        self.__slices      = self.__descriptors.get('data', []) #Coge de la file el campo slices
        self.__slices      = self.__descriptors.get('slices'     , [])
        self.__slices = self.__descriptors.get('ietf-network-slice-service:network-slice-services', {})
        self.__connections = self.__descriptors.get('connections', [])

        if self.__slices: 
            json_out = {"slices": [
                {
                    "slice_id": {
                        "context_id": {"context_uuid": {"uuid": "admin"}},
                        "slice_uuid": {}
                    },
                    "name": {},
                    "slice_config": {"config_rules": [
                        {"action": 1, "custom": {"resource_key": "/settings", "resource_value": {
                        "address_families": ["IPV4"], "bgp_as": 65000, "bgp_route_target": "65000:333", "mtu": 1512
                        }}}
                    ]},
                    "slice_constraints": [
                        {"sla_capacity": {"capacity_gbps": 20.0}},
                        {"sla_availability": {"availability": 20.0, "num_disjoint_paths": 1, "all_active": True}},
                        {"sla_isolation": {"isolation_level": [0]}}
                    ],
                    "slice_endpoint_ids": [
            
                    ],
                    "slice_status": {"slice_status": 1}
                }
            ]}

            for slice_service in self.__slices["slice-service"]:
                for slice in json_out["slices"]:
                    slice["slice_id"]["slice_uuid"] = { "uuid": slice_service["id"]}
                    slice["name"] = slice_service["description"]
                    sdp = slice_service["sdps"]["sdp"]
                    for elemento in sdp:
                        attcircuits = elemento["attachment-circuits"]["attachment-circuit"]
                        for attcircuit in attcircuits:
                            resource_key = "/device[{sdp_id}]/endpoint[{endpoint_id}]/settings".format(sdp_id = elemento["id"], endpoint_id = attcircuit["ac-tp-id"])

                            for tag in attcircuit['ac-tags']['ac-tag']:
                                if tag.get('tag-type') == 'ietf-nss:vlan-id':
                                    vlan_id = tag.get('value')
                                else:
                                    vlan_id = 0

                            slice["slice_config"]["config_rules"].append( {"action": 1, "custom": {"resource_key": resource_key, "resource_value": {
                                "router_id": elemento.get("node-id",[]), "sub_interface_index": 0, "vlan_id": vlan_id
                            }}})
                            slice["slice_endpoint_ids"].append({
                                "device_id": {"device_uuid": {"uuid": elemento["id"]}},
                                "endpoint_uuid": {"uuid": attcircuit["ac-tp-id"]},
                                "topology_id": {"context_id": {"context_uuid": {"uuid": "admin"}}, 
                                "topology_uuid": {"uuid": "admin"}}
                            })
                            slice["slice_constraints"].append({"endpoint_location": {
                                "endpoint_id": {"device_id": {"device_uuid": {"uuid": elemento["id"]}}, "endpoint_uuid": {"uuid": attcircuit["ac-tp-id"]}},
                                "location": {"region": "4"}
                        }})

            # Convertir a JSON de salida
            #json_output = json.dumps(json_out, indent=2)
            self.__slices      = json_out.get('slices'     , [])

        self.__contexts_add   = None
        self.__topologies_add = None
        self.__devices_add    = None
@@ -216,7 +276,6 @@ class DescriptorLoader:
        # Format CustomConfigRules in Devices, Services and Slices provided in JSON format
        self.__devices  = [format_device_custom_config_rules (device ) for device  in self.__devices ]
        self.__services = [format_service_custom_config_rules(service) for service in self.__services]
        LOGGERS.INFO(self.__slices)
        self.__slices   = [format_slice_custom_config_rules  (slice_ ) for slice_  in self.__slices  ]

        # Context and Topology require to create the entity first, and add devices, links, services,
@@ -237,8 +296,7 @@ class DescriptorLoader:
        self.__ctx_cli.connect()
        self._process_descr('context',    'add',    self.__ctx_cli.SetContext,    Context,    self.__contexts_add  )
        self._process_descr('topology',   'add',    self.__ctx_cli.SetTopology,   Topology,   self.__topologies_add)
        self._process_descr('controller', 'add',    self.__ctx_cli.SetDevice,     Device,     controllers          )
        self._process_descr('device',     'add',    self.__ctx_cli.SetDevice,     Device,     network_devices      )
        self._process_descr('device',     'add',    self.__ctx_cli.SetDevice,     Device,     self.__devices       )
        self._process_descr('link',       'add',    self.__ctx_cli.SetLink,       Link,       self.__links         )
        self._process_descr('service',    'add',    self.__ctx_cli.SetService,    Service,    self.__services      )
        self._process_descr('slice',      'add',    self.__ctx_cli.SetSlice,      Slice,      self.__slices        )
@@ -266,8 +324,6 @@ class DescriptorLoader:
        self.__services_add = get_descriptors_add_services(self.__services)
        self.__slices_add = get_descriptors_add_slices(self.__slices)

        controllers_add, network_devices_add = split_controllers_and_network_devices(self.__devices_add)

        self.__ctx_cli.connect()
        self.__dev_cli.connect()
        self.__svc_cli.connect()
@@ -275,8 +331,7 @@ class DescriptorLoader:

        self._process_descr('context',  'add',    self.__ctx_cli.SetContext,      Context,  self.__contexts_add  )
        self._process_descr('topology', 'add',    self.__ctx_cli.SetTopology,     Topology, self.__topologies_add)
        self._process_descr('controller', 'add',    self.__dev_cli.AddDevice,       Device,   controllers_add      )
        self._process_descr('device',     'add',    self.__dev_cli.AddDevice,       Device,   network_devices_add  )
        self._process_descr('device',   'add',    self.__dev_cli.AddDevice,       Device,   self.__devices_add   )
        self._process_descr('device',   'config', self.__dev_cli.ConfigureDevice, Device,   self.__devices_config)
        self._process_descr('link',     'add',    self.__ctx_cli.SetLink,         Link,     self.__links         )
        self._process_descr('service',  'add',    self.__svc_cli.CreateService,   Service,  self.__services_add  )
@@ -284,11 +339,9 @@ class DescriptorLoader:
        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        )
        
        # By default the Context component automatically assigns devices and links to topologies based on their
        # endpoints, and assigns topologies, services, and slices to contexts based on their identifiers.

        # The following statement is useless; up to now, any use case requires assigning a topology, service, or
        # slice to a different context.
        # Update context and topology is useless:
        # - devices and links are assigned to topologies automatically by Context component
        # - topologies, services, and slices are assigned to contexts automatically by Context component
        #self._process_descr('context',  'update', self.__ctx_cli.SetContext,      Context,  self.__contexts      )

        # In some cases, it might be needed to assign devices and links to multiple topologies; the
+3 −10
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@ import copy, json
from typing import Dict, List, Optional, Tuple, Union
from common.DeviceTypes import DeviceTypeEnum

#context es la db, al inicio esta vacía
def get_descriptors_add_contexts(contexts : List[Dict]) -> List[Dict]:
    contexts_add = copy.deepcopy(contexts)
    for context in contexts_add:
@@ -54,13 +53,11 @@ def get_descriptors_add_slices(slices : List[Dict]) -> List[Dict]:
TypeResourceValue = Union[str, int, bool, float, dict, list]
def format_custom_config_rules(config_rules : List[Dict]) -> List[Dict]:
    for config_rule in config_rules:
       # if 'custom' not in config_rule: continue #suponemos que siempre son custom, quitamos esta linea
        if 'custom' not in config_rule: continue
        custom_resource_value : TypeResourceValue = config_rule['custom']['resource_value']
        if isinstance(custom_resource_value, (dict, list)):
            custom_resource_value = json.dumps(custom_resource_value, sort_keys=True, indent=0)
            config_rule['custom']['resource_value'] = custom_resource_value
        elif not isinstance(custom_resource_value, str):
            config_rule['custom']['resource_value'] = str(custom_resource_value)
    return config_rules

def format_device_custom_config_rules(device : Dict) -> Dict:
@@ -75,14 +72,10 @@ def format_service_custom_config_rules(service : Dict) -> Dict:
    service['service_config']['config_rules'] = config_rules
    return service

#UTILIZA LA FUNCION FORMAT_CUSTOM_CONFIG_RULES 
#cambio
def format_slice_custom_config_rules(slice_ : Dict) -> Dict:
    #donde cojo los config_rules
    #las config_rules parecen estar en ACs?
    config_rules = slice_.get('sdps', []) 
    config_rules = slice_.get('slice_config', {}).get('config_rules', [])
    config_rules = format_custom_config_rules(config_rules)
    slice_['sdps']['sdp']['attachment-circuits'] = config_rules
    slice_['slice_config']['config_rules'] = config_rules
    return slice_

def split_devices_by_rules(devices : List[Dict]) -> Tuple[List[Dict], List[Dict]]: