Resolve "(CTTC) Define fields to specify type of link"

Closes #245 (closed)

Merge request reports

Loading
+11 −11
Changes for proto/context.proto: 11 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -258,6 +258,14 @@ message LinkId {
  Uuid link_uuid = 1;
}

enum LinkTypeEnum {
  LINKTYPE_UNKNOWN = 0;
  LINKTYPE_COPPER  = 1;
  LINKTYPE_FIBER   = 2;
  LINKTYPE_RADIO   = 3;
  LINKTYPE_VIRTUAL = 4;
}

message LinkAttributes {
  float total_capacity_gbps = 1;
  float used_capacity_gbps  = 2;
@@ -266,9 +274,9 @@ message LinkAttributes {
message Link {
  LinkId link_id = 1;
  string name = 2;
  repeated EndPointId link_endpoint_ids = 3;
  LinkAttributes attributes = 4;
  LinkTypeEnum link_type = 5;
  LinkTypeEnum link_type = 3;
  repeated EndPointId link_endpoint_ids = 4;
  LinkAttributes attributes = 5;
}

message LinkIdList {
@@ -284,14 +292,6 @@ message LinkEvent {
  LinkId link_id = 2;
}

enum LinkTypeEnum {
  LINKTYPE_UNKNOWN = 0;
  LINKTYPE_COPPER = 1;
  LINKTYPE_VIRTUAL_COPPER = 2;
  LINKTYPE_OPTICAL = 3;
  LINKTYPE_VIRTUAL_OPTICAL = 4;
}

// ----- Service -------------------------------------------------------------------------------------------------------
message ServiceId {
  ContextId context_id = 1;
+33 −0
Changes for src/context/service/database/models/enums/LinkType.py: 33 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Copyright 2022-2024 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.

import enum, functools
from common.proto.context_pb2 import LinkTypeEnum
from ._GrpcToEnum import grpc_to_enum

# IMPORTANT: Entries of enum class ORM_LinkTypeEnum should be named as in
#            the proto files removing the prefixes. For example, proto item
#            LinkTypeEnum.DEVICEDRIVER_COPPER should be included as COPPER.
#            If item name does not match, automatic mapping of proto enums
#            to database enums will fail.
class ORM_LinkTypeEnum(enum.Enum):
    UNKNOWN = LinkTypeEnum.LINKTYPE_UNKNOWN
    COPPER  = LinkTypeEnum.LINKTYPE_COPPER
    FIBER   = LinkTypeEnum.LINKTYPE_FIBER
    RADIO   = LinkTypeEnum.LINKTYPE_RADIO
    VIRTUAL = LinkTypeEnum.LINKTYPE_VIRTUAL

grpc_to_enum__link_type_enum = functools.partial(
    grpc_to_enum, LinkTypeEnum, ORM_LinkTypeEnum
)
+9 −1
Changes for src/context/service/database/models/LinkModel.py: 9 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -13,17 +13,22 @@
# limitations under the License.

import operator
from sqlalchemy import CheckConstraint, Column, DateTime, Float, ForeignKey, Integer, String
from sqlalchemy import (
    CheckConstraint, Column, DateTime, Enum, Float, ForeignKey, Integer, String
)
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
from typing import Dict
from common.proto.context_pb2 import LinkTypeEnum
from ._Base import _Base
from .enums.LinkType import ORM_LinkTypeEnum

class LinkModel(_Base):
    __tablename__ = 'link'

    link_uuid           = Column(UUID(as_uuid=False), primary_key=True)
    link_name           = Column(String, nullable=False)
    link_type           = Column(Enum(ORM_LinkTypeEnum), nullable=False)
    total_capacity_gbps = Column(Float, nullable=True)
    used_capacity_gbps  = Column(Float, nullable=True)
    created_at          = Column(DateTime, nullable=False)
@@ -44,11 +49,14 @@ class LinkModel(_Base):
        result = {
            'link_id'          : self.dump_id(),
            'name'             : self.link_name,
            'link_type'        : self.link_type.value,
            'link_endpoint_ids': [
                link_endpoint.endpoint.dump_id()
                for link_endpoint in sorted(self.link_endpoints, key=operator.attrgetter('position'))
            ],
        }
        if self.link_type is None:
            self.link_type = LinkTypeEnum.LINKTYPE_UNKNOWN
        if self.total_capacity_gbps is not None:
            attributes : Dict = result.setdefault('attributes', dict())
            attributes.setdefault('total_capacity_gbps', self.total_capacity_gbps)
+1 −1
Changes for src/context/service/database/Connection.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ def connection_set(db_engine : Engine, messagebroker : MessageBroker, request :
    _,service_uuid = service_get_uuid(request.service_id, allow_random=False)
    settings = grpc_message_to_json_string(request.settings),

    now = datetime.datetime.utcnow()
    now = datetime.datetime.now(datetime.timezone.utc)

    connection_data = [{
        'connection_uuid': connection_uuid,
+2 −1
Changes for src/context/service/database/Context.py: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -82,7 +82,8 @@ def context_set(db_engine : Engine, messagebroker : MessageBroker, request : Con
    if len(request.slice_ids) > 0:      # pragma: no cover
        LOGGER.warning('Items in field "slice_ids" ignored. This field is used for retrieval purposes only.')

    now = datetime.datetime.utcnow()
    now = datetime.datetime.now(datetime.timezone.utc)

    context_data = [{
        'context_uuid': context_uuid,
        'context_name': context_name,
Loading
Loading