Commit 82cb05bc authored by Mohamad Rahhal's avatar Mohamad Rahhal
Browse files

Merge branch 'feat/143-cttc-logical-resources-component' of...

Merge branch 'feat/143-cttc-logical-resources-component' of https://labs.etsi.org/rep/tfs/controller into feat/390-cttc-integration-of-spine-leaf-fabric-management
parents f13dbd87 843f98ed
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ from common.tools.object_factory.Context import json_context_id
from context.client.ContextClient import ContextClient
from device.client.DeviceClient import DeviceClient
from spine_leaf.client.SpineLeafClient import SpineLeafClient
from service.service.tools.object_uuid import get_uuid_from_string
from service.client.ServiceClient import ServiceClient
from slice.client.SliceClient import SliceClient
from vnt_manager.client.VNTManagerClient import VNTManagerClient
@@ -433,11 +434,11 @@ class DescriptorLoader:
    def _logical_resource_request(self, resource_type: str, allocation: Dict) -> Any:
        device_uuid = str(allocation.get('device_uuid', ''))
        endpoint_uuid = str(allocation.get('endpoint_uuid', allocation.get('interface', '')))
        device_name = str(allocation.get('device_name', ''))
        fabric_name = str(allocation.get('fabric_name', allocation.get('fabric_id', '')))
        request_kwargs = {
            'device_uuid': device_uuid,
            'endpoint_uuid': endpoint_uuid,
            'name': device_name,
            'name': fabric_name,
        }

        if resource_type == 'asn':
@@ -466,9 +467,10 @@ class DescriptorLoader:

        num_ok, error_list = 0, []
        for fabric in self.__logical_resources:
            fabric_id = str(fabric.get('fabric_id', ''))
            fabric_name = str(fabric.get('fabric_name', fabric.get('fabric_id', '')))
            fabric_id = get_uuid_from_string(fabric_name) if len(fabric_name) > 0 else ''
            for resource_type, resource_descriptor in fabric.items():
                if resource_type == 'fabric_id':
                if resource_type in ('fabric_id', 'fabric_name'):
                    continue

                allocations = resource_descriptor.get('allocations', {})
@@ -485,7 +487,7 @@ class DescriptorLoader:
                                    endpoint_uuid=str(endpoint_uuid),
                                    ip_address=str(ip_address),
                                    interface=str(endpoint_uuid),
                                    name=str(allocation.get('device_name', '')),
                                    name=fabric_name,
                                )
                                self.__lrs_cli.AddResources(request)
                                num_ok += 1
+72 −0
Original line number Diff line number Diff line
# Copyright 2022-2025 ETSI 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.

from typing import Dict, List, Optional, Tuple
from service.service.tools.object_uuid import get_uuid_from_string

class Database:
    def __init__(self):
        "Creating the database to store things"
        self.database = {}
        self.resources = {}
        self.fabrics = {}

    def _track_resource(self, resource_type, resource_value):
        if not resource_value:
            return
        self.resources.setdefault((resource_type, resource_value), '')

    def register_fabric(self, fabric_name: str) -> str:
        fabric_id = get_uuid_from_string(fabric_name)
        if fabric_id not in self.fabrics:
            self.fabrics[fabric_id] = {
                'fabric_name': fabric_name,
            }
        return fabric_id

    def get_fabric(self, fabric_id: str):
        return self.fabrics.get(fabric_id)

    def resolve_fabric_id(self, fabric_name: str) -> Optional[str]:
        if not fabric_name:
            return None
        fabric_id = get_uuid_from_string(fabric_name)
        if fabric_id in self.fabrics:
            return fabric_id
        return None

    def add_resources(self, device_uuid, endpoint_uuid, ip_address, vlan_tag, mac_address, ASN, RouterID,
                      vni=None, local_address=None, port=None, bridge=None, interface=None, remote_address=None,
                      remote_as=None, local_role=None, routing_table=None, multihop=None, afi=None, name=None):
        if device_uuid not in self.database:
            self.database[device_uuid] = {}

        if name:
            self.register_fabric(name)

        if endpoint_uuid not in self.database[device_uuid]:
            self.database[device_uuid][endpoint_uuid] = {
                "mac_address": mac_address,
@@ -35,6 +75,38 @@ class Database:
                "afi": afi,
                "name": name
            }
        else:
            endpoint = self.database[device_uuid][endpoint_uuid]
            if mac_address:
                endpoint["mac_address"] = mac_address
            if ASN:
                endpoint["asn"] = ASN
            if RouterID:
                endpoint["router_id"] = RouterID
            if vni:
                endpoint["vni"] = vni
            if local_address:
                endpoint["local_address"] = local_address
            if port:
                endpoint["port"] = port
            if bridge:
                endpoint["bridge"] = bridge
            if interface:
                endpoint["interface"] = interface
            if remote_address:
                endpoint["remote_address"] = remote_address
            if remote_as:
                endpoint["remote_as"] = remote_as
            if local_role:
                endpoint["local_role"] = local_role
            if routing_table:
                endpoint["routing_table"] = routing_table
            if multihop:
                endpoint["multihop"] = multihop
            if afi:
                endpoint["afi"] = afi
            if name:
                endpoint["name"] = name
        if ip_address:
            self.database[device_uuid][endpoint_uuid]["ip_addresses"].append(ip_address)
        if vlan_tag: