Resolve "(CTTC) Logical Resources Component"

Closes #143 (closed)

Merge request reports

Loading
+101 −0
Changes for manifests/logical_resourcesservice.yaml: 101 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Copyright 2022-2026 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.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: logical-resourcesservice
spec:
  selector:
    matchLabels:
      app: logical-resourcesservice
  #replicas: 1
  template:
    metadata:
      labels:
        app: logical-resourcesservice
    spec:
      terminationGracePeriodSeconds: 5
      containers:
        - name: server
          image: labs.etsi.org:5050/tfs/controller/logical_resources:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 30230
            - containerPort: 9192
          env:
            - name: LOG_LEVEL
              value: "INFO"
          startupProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:30230"]
            failureThreshold: 30
            periodSeconds: 1
          readinessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:30230"]
          livenessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:30230"]
          resources:
            requests:
              cpu: 250m
              memory: 128Mi
            limits:
              cpu: 1000m
              memory: 1024Mi
---
apiVersion: v1
kind: Service
metadata:
  name: logical-resourcesservice
  labels:
    app: logical-resourcesservice
spec:
  type: ClusterIP
  selector:
    app: logical-resourcesservice
  ports:
    - name: grpc
      protocol: TCP
      port: 30230
      targetPort: 30230
    - name: metrics
      protocol: TCP
      port: 9192
      targetPort: 9192

# TODO: Cannot be auto-scaled until a proper database is implemented.
#---
#apiVersion: autoscaling/v2
#kind: HorizontalPodAutoscaler
#metadata:
#  name: logical-resourcesservice-hpa
#spec:
#  scaleTargetRef:
#    apiVersion: apps/v1
#    kind: Deployment
#    name: logical-resourcesservice
#  minReplicas: 1
#  maxReplicas: 20
#  metrics:
#    - type: Resource
#      resource:
#        name: cpu
#        target:
#          type: Utilization
#          averageUtilization: 80
#  #behavior:
#  #  scaleDown:
#  #    stabilizationWindowSeconds: 30
+1 −1
Changes for manifests/pluggablesservice.yaml: 1 added line, 1 removed line.
Original line number Diff line number Diff line
# Copyright 2022-2025 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
# Copyright 2022-2026 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.
+102 −0
Changes for proto/logical_resources.proto: 102 added lines, 0 removed lines.
Original line number Diff line number Diff line
// Copyright 2022-2026 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.

syntax = "proto3";
package logical_resources;

service LogicalResources {
    rpc AddResources          (ConfigParameters   ) returns (Response         ) {}
    rpc GetAvailableResources (Empty              ) returns (ResourceList     ) {}
    rpc ReserveResource       (ResourceReservation) returns (Success          ) {}
    rpc ReleaseResource       (ResourceReservation) returns (Success          ) {}
    rpc DeleteResource        (ResourceReservation) returns (Success          ) {}
    rpc GetReservedResources  (Empty              ) returns (ResourceList     ) {}
    rpc GetResourceOwner      (Value              ) returns (FabricId         ) {}
    rpc GetResourcesByType    (ResourceTypeQuery  ) returns (TypedResourceList) {}
}

message Empty {}

message Value {
    string value = 1;
}

message FabricId {
    string fabric_id = 1;
}

message Tuple {
    string type = 1;
    string value = 2;
}

message Success {
    bool success = 1;
    string message = 2;
}

message ResourceReservation {
    Tuple tuple = 1;
    FabricId fabric_id = 2;
}

message ResourceTypeQuery {
    string resource_type = 1;
}

message ResourceEntry {
    string type = 1;
    string value = 2;
    string fabric_id = 3;
    bool allocated = 4;
}

message ResourceList {
    repeated ResourceEntry resources = 1;
}

message TypedResourceList {
    string resource_type = 1;
    repeated ResourceEntry resources = 2;
}

message ConfigParameters {
    string device_uuid = 1;
    string endpoint_uuid = 2;
    string ip_address = 3;
    uint32 vlan_tag = 4;
    string mac_address = 5;
    uint32 asn = 6;
    string router_id = 7;
    uint32 vni = 8;
    string local_address = 9;
    uint32 port = 10;
    string bridge = 11;
    string interface = 12;
    string remote_address = 13;
    uint32 remote_as = 14;
    string local_role = 15;
    string routing_table = 16;
    bool multihop = 17;
    string afi = 18;
    string name = 19;
    string interface_comment = 20;
    string link_target_device = 21;
    string link_target_interface = 22;
}

message Response {
    bool success = 1;
    string message = 2;
}
+27 −0
Changes for scripts/show_logs_logical_resources.sh: 27 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/bin/bash
# Copyright 2022-2026 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.

########################################################################################################################
# Define your deployment settings here
########################################################################################################################

# If not already set, set the name of the Kubernetes namespace to deploy to.
export TFS_K8S_NAMESPACE=${TFS_K8S_NAMESPACE:-"tfs"}

########################################################################################################################
# Automated steps start here
########################################################################################################################

kubectl --namespace $TFS_K8S_NAMESPACE logs deployment/logical-resourcesservice -c server
+111 −5
Changes for src/common/tools/descriptor/Loader.py: 111 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -40,12 +40,15 @@ from common.proto.context_pb2 import (
    Link, LinkId, Service, ServiceId, Slice, SliceId,
    Topology, TopologyId , OpticalLink
)
from common.proto.logical_resources_pb2 import ConfigParameters
from common.tools.object_factory.Context import json_context_id
from context.client.ContextClient import ContextClient
from device.client.DeviceClient import DeviceClient
from logical_resources.client.LogicalResourcesClient import LogicalResourcesClient
from service.client.ServiceClient import ServiceClient
from slice.client.SliceClient import SliceClient
from vnt_manager.client.VNTManagerClient import VNTManagerClient
from common.tools.context_queries.Slice import get_uuid_from_string
from .Tools import (
    format_device_custom_config_rules, format_service_custom_config_rules,
    format_slice_custom_config_rules, get_descriptors_add_contexts,
@@ -68,6 +71,7 @@ ENTITY_TO_TEXT = {
    'controller'       : ('Controller',       'Controllers'      ),
    'device'           : ('Device',           'Devices'          ),
    'link'             : ('Link',             'Links'            ),
    'logical_resource' : ('Logical Resource', 'Logical Resources'),
    'service'          : ('Service',          'Services'         ),
    'slice'            : ('Slice',            'Slices'           ),
    'connection'       : ('Connection',       'Connections'      ),
@@ -113,6 +117,7 @@ class DescriptorLoader:
        self, descriptors : Optional[Union[str, Dict]] = None, descriptors_file : Optional[str] = None,
        num_workers : int = 1,
        context_client : Optional[ContextClient] = None, device_client : Optional[DeviceClient] = None,
        logical_resources_client : Optional[LogicalResourcesClient] = None,
        service_client : Optional[ServiceClient] = None, slice_client : Optional[SliceClient] = None,
        vntm_client : Optional[VNTManagerClient] = None
    ) -> None:
@@ -136,6 +141,7 @@ class DescriptorLoader:
        self.__devices           = self.__descriptors.get('devices'    ,       [])
        self.__links             = self.__descriptors.get('links'      ,       [])
        self.__optical_links     = self.__descriptors.get('optical_links',     [])
        self.__logical_resources = self.__descriptors.get('logical_resources', [])
        self.__services          = self.__descriptors.get('services'   ,       [])
        self.__slices            = self.__descriptors.get('slices'     ,       [])
        self.__ietf_slices       = self.__descriptors.get('ietf-network-slice-service:network-slice-services', {})
@@ -192,11 +198,14 @@ class DescriptorLoader:
        self.__services_add   = None
        self.__slices_add     = None

        self.__ctx_cli = ContextClient()    if context_client is None else context_client
        self.__dev_cli = DeviceClient()     if device_client  is None else device_client
        self.__svc_cli = ServiceClient()    if service_client is None else service_client
        self.__slc_cli = SliceClient()      if slice_client   is None else slice_client
        self.__vnt_cli = VNTManagerClient() if vntm_client    is None else vntm_client
        self.__ctx_cli = context_client           or ContextClient()
        self.__dev_cli = device_client            or DeviceClient()
        self.__lrs_cli = logical_resources_client or LogicalResourcesClient()
        self.__svc_cli = service_client           or ServiceClient()
        self.__slc_cli = slice_client             or SliceClient()
        self.__vnt_cli = vntm_client              or VNTManagerClient()

        self.__fabric_name_to_id: Dict[str, str] = {}

        self.__results : TypeResults = list()

@@ -258,6 +267,12 @@ class DescriptorLoader:
    @property
    def num_optical_links(self) -> int: return len(self.__optical_links)

    @property
    def logical_resources(self) -> List[Dict]: return self.__logical_resources

    @property
    def num_logical_resources(self) -> int: return len(self.__logical_resources)

    @property
    def services(self) -> Dict[str, List[Dict]]:
        _services = {}
@@ -302,6 +317,8 @@ class DescriptorLoader:
        self.__services = [format_service_custom_config_rules(service) for service in self.__services]
        self.__slices   = [format_slice_custom_config_rules  (slice_ ) for slice_  in self.__slices  ]

        self._process_logical_resources()

        # Context and Topology require to create the entity first, and add devices, links, services,
        # slices, etc. in a second stage.
        self.__contexts_add = get_descriptors_add_contexts(self.__contexts)
@@ -403,6 +420,95 @@ class DescriptorLoader:
        #self.__dev_cli.close()
        #self.__ctx_cli.close()

    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', '')))
        fabric_name = str(allocation.get('fabric_name', allocation.get('fabric_id', '')))
        request_kwargs = {
            'device_uuid': device_uuid,
            'endpoint_uuid': endpoint_uuid,
            'name': fabric_name,
        }

        if resource_type == 'asn':
            request_kwargs['asn'] = int(allocation['value'])
        elif resource_type == 'router_id':
            request_kwargs['router_id'] = str(allocation['value'])
        elif resource_type == 'interface_ip_address':
            ip_val = allocation.get('value')
            if isinstance(ip_val, dict):
                request_kwargs['ip_address'] = str(ip_val.get('ip', ''))
                request_kwargs['interface_comment'] = str(ip_val.get('comment', ''))
                request_kwargs['link_target_device'] = str(ip_val.get('link_to_device', ''))
                request_kwargs['link_target_interface'] = str(ip_val.get('link_to_interface', ''))
            else:
                request_kwargs['ip_address'] = str(ip_val)
            request_kwargs['interface'] = endpoint_uuid
        elif resource_type == 'vlan':
            request_kwargs['vlan_tag'] = int(allocation['value'])
        elif resource_type == 'vni':
            request_kwargs['vni'] = int(allocation['value'])
        elif resource_type == 'ip':
            request_kwargs['ip_address'] = str(allocation['value'])
        elif resource_type == 'loopback':
            request_kwargs['router_id'] = str(allocation['value'])
        else:
            raise Exception(f'Unsupported logical resource type: {resource_type}')

        return ConfigParameters(**request_kwargs)

    def _process_logical_resources(self) -> None:
        if len(self.__logical_resources) == 0:
            return

        num_ok, error_list = 0, []
        for fabric in self.__logical_resources:
            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 ''
            try:
                self.__fabric_name_to_id[fabric_name] = str(fabric_id) if fabric_id else ''
            except Exception:
                self.__fabric_name_to_id = {fabric_name: (str(fabric_id) if fabric_id else '')}
            for resource_type, resource_descriptor in fabric.items():
                if resource_type in ('fabric_id', 'fabric_name'):
                    continue

                allocations = resource_descriptor.get('allocations', {})
                for allocation_key, allocation_value in allocations.items():
                    allocation = dict(allocation_value)
                    allocation['device_uuid'] = allocation_key

                    try:
                        if resource_type == 'interface_ip_address':
                            interface_allocations = allocation.get('interfaces', allocation.get('endpoints', {}))
                            for endpoint_uuid, ip_address in interface_allocations.items():
                                if isinstance(ip_address, dict):

                                    alloc = dict(allocation)
                                    alloc['device_uuid'] = allocation_key
                                    alloc['endpoint_uuid'] = endpoint_uuid
                                    alloc['value'] = ip_address
                                    alloc['fabric_name'] = fabric_name
                                    request = self._logical_resource_request('interface_ip_address', alloc)
                                else:
                                    request = ConfigParameters(
                                        device_uuid=str(allocation_key),
                                        endpoint_uuid=str(endpoint_uuid),
                                        ip_address=str(ip_address),
                                        interface=str(endpoint_uuid),
                                        name=fabric_name,
                                    )
                                self.__lrs_cli.AddResources(request)
                                num_ok += 1
                        else:
                            request = self._logical_resource_request(resource_type, allocation)
                            self.__lrs_cli.AddResources(request)
                            num_ok += 1
                    except Exception as e:  # pylint: disable=broad-except
                        error_list.append(f'{fabric_id}/{resource_type}/{allocation_key}: {str(e)}')

        self.__results.append(('logical_resource', 'add', num_ok, error_list))

    @staticmethod
    def worker(grpc_method, grpc_class, entity) -> Any:
        return grpc_method(grpc_class(**entity))
Loading
Loading