Commit 4c479a1b authored by Shayan Hajipour's avatar Shayan Hajipour
Browse files

feat: constraints list retrieval added to QoSProfile component:

- test_crud.py refactored
- test_constraints.py added
- start_timestamp of Constraint_Schedule changed to double from float
parent 90d55e73
Loading
Loading
Loading
Loading
+29 −6
Original line number Diff line number Diff line
@@ -419,6 +419,12 @@ message QoSProfileValueUnitPair {
  string unit = 2;
}

message QoDConstraintsRequest {
  QoSProfileId qos_profile_id = 1;
  double start_timestamp = 2;
  float duration = 3;
}

message QoSProfile {
  QoSProfileId qos_profile_id = 1;
  string name = 2;
@@ -571,7 +577,7 @@ message Constraint_Custom {
}

message Constraint_Schedule {
  float start_timestamp = 1;
  double start_timestamp = 1;
  float duration_days = 2;
}

@@ -634,6 +640,22 @@ message Constraint_Exclusions {
  repeated LinkId link_ids = 4;
}

message Constraint_QoSProfile {
  QoSProfileValueUnitPair target_min_upstream_rate = 1;
  QoSProfileValueUnitPair max_upstream_rate = 2;
  QoSProfileValueUnitPair max_upstream_burst_rate = 3;
  QoSProfileValueUnitPair target_min_downstream_rate = 4;
  QoSProfileValueUnitPair max_downstream_rate = 5;
  QoSProfileValueUnitPair max_downstream_burst_rate = 6;
  QoSProfileValueUnitPair min_duration = 7;
  QoSProfileValueUnitPair max_duration = 8;
  int32 priority = 9;
  QoSProfileValueUnitPair packet_delay_budget = 10;
  QoSProfileValueUnitPair jitter = 11;
  int32 packet_error_loss_rate = 12;

}

message Constraint {
  ConstraintActionEnum action = 1;
  oneof constraint {
@@ -646,6 +668,7 @@ message Constraint {
    Constraint_SLA_Availability sla_availability = 8;
    Constraint_SLA_Isolation_level sla_isolation = 9;
    Constraint_Exclusions exclusions = 10;
    Constraint_QoSProfile qos_profile = 11;
  }
}

+6 −5
Original line number Diff line number Diff line
@@ -23,4 +23,5 @@ service QoSProfileService {
  rpc DeleteQoSProfile                (context.QoSProfileId         ) returns (context.Empty              ) {}
  rpc GetQoSProfile                   (context.QoSProfileId         ) returns (context.QoSProfile         ) {}
  rpc GetQoSProfiles                  (context.Empty                ) returns (stream context.QoSProfile  ) {}
  rpc GetConstraintListFromQoSProfile (context.QoDConstraintsRequest) returns (stream context.Constraint  ) {}
}
+8 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ from typing import Iterator
import grpc, logging
from common.Constants import ServiceNameEnum
from common.Settings import get_service_host, get_service_port_grpc
from common.proto.context_pb2 import Empty, QoSProfileId, QoSProfile
from common.proto.context_pb2 import Empty, QoSProfileId, QoSProfile, QoDConstraintsRequest, Constraint
from common.proto.qos_profile_pb2_grpc import QoSProfileServiceStub
from common.tools.client.RetryDecorator import retry, delay_exponential
from common.tools.grpc.Tools import grpc_message_to_json_string
@@ -80,3 +80,10 @@ class QoSProfileClient:
        response = self.stub.GetQoSProfiles(request)
        LOGGER.debug('GetQoSProfiles result: {:s}'.format(grpc_message_to_json_string(response)))
        return response

    @RETRY_DECORATOR
    def GetConstraintListFromQoSProfile(self, request: QoDConstraintsRequest) -> Iterator[Constraint]:
        LOGGER.debug('GetConstraintListFromQoSProfile request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.GetConstraintListFromQoSProfile(request)
        LOGGER.debug('GetConstraintListFromQoSProfile result: {:s}'.format(grpc_message_to_json_string(response)))
        return response
 No newline at end of file
+34 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ from typing import Iterator

import grpc._channel
from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method
from common.proto.context_pb2 import Empty, QoSProfileId, QoSProfile
from common.proto.context_pb2 import QoDConstraintsRequest, Constraint, ConstraintActionEnum, Constraint_QoSProfile, Constraint_Schedule, Empty, QoSProfileId, QoSProfile
from common.proto.qos_profile_pb2_grpc import QoSProfileServiceServicer
from context.client.ContextClient import ContextClient

@@ -87,3 +87,36 @@ class QoSProfileServiceServicerImpl(QoSProfileServiceServicer):
        context_client = ContextClient()
        yield from context_client.GetQoSProfiles(request)


    @safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
    def GetConstraintListFromQoSProfile(self, request: QoDConstraintsRequest, context: grpc.ServicerContext) -> Iterator[Constraint]:
        context_client = ContextClient()
        try:
            qos_profile = context_client.GetQoSProfile(request.qos_profile_id)
        except grpc._channel._InactiveRpcError as exc:
            if exc.code() == grpc.StatusCode.NOT_FOUND:
                context.set_details(f'QoSProfile {request.qos_profile_id.qos_profile_id.uuid} not found')
                context.set_code(grpc.StatusCode.NOT_FOUND)
                yield Constraint()

        qos_profile_constraint = Constraint_QoSProfile()
        qos_profile_constraint.target_min_upstream_rate.CopyFrom(qos_profile.targetMinUpstreamRate)
        qos_profile_constraint.max_upstream_rate.CopyFrom(qos_profile.maxUpstreamRate)
        qos_profile_constraint.max_upstream_burst_rate.CopyFrom(qos_profile.maxUpstreamBurstRate)
        qos_profile_constraint.target_min_downstream_rate.CopyFrom(qos_profile.targetMinDownstreamRate)
        qos_profile_constraint.max_downstream_rate.CopyFrom(qos_profile.maxDownstreamRate)
        qos_profile_constraint.max_downstream_burst_rate.CopyFrom(qos_profile.maxDownstreamBurstRate)
        qos_profile_constraint.min_duration.CopyFrom(qos_profile.minDuration)
        qos_profile_constraint.max_duration.CopyFrom(qos_profile.maxDuration)
        qos_profile_constraint.priority = qos_profile.priority
        qos_profile_constraint.packet_delay_budget.CopyFrom(qos_profile.packetDelayBudget)
        qos_profile_constraint.jitter.CopyFrom(qos_profile.jitter)
        qos_profile_constraint.packet_error_loss_rate =qos_profile.packetErrorLossRate
        constraint_qos = Constraint()
        constraint_qos.action = ConstraintActionEnum.CONSTRAINTACTION_SET
        constraint_qos.qos_profile.CopyFrom(qos_profile_constraint)
        yield constraint_qos
        constraint_schedule = Constraint()
        constraint_schedule.action = ConstraintActionEnum.CONSTRAINTACTION_SET
        constraint_schedule.schedule.CopyFrom(Constraint_Schedule(start_timestamp=request.start_timestamp, duration_days=request.duration/86400))
        yield constraint_schedule
+24 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@

import pytest
from qos_profile.client.QoSProfileClient import QoSProfileClient
from common.proto.context_pb2 import Uuid, QoSProfileValueUnitPair, QoSProfileId, QoSProfile

@pytest.fixture(scope='function')
def qos_profile_client():
@@ -21,3 +22,26 @@ def qos_profile_client():
    yield _client
    _client.close()



def create_qos_profile_from_json(qos_profile_data: dict) -> QoSProfile:
    def create_QoSProfileValueUnitPair(data) -> QoSProfileValueUnitPair:
        return QoSProfileValueUnitPair(value=data['value'], unit=data['unit'])
    qos_profile = QoSProfile()
    qos_profile.qos_profile_id.CopyFrom(QoSProfileId(qos_profile_id=Uuid(uuid=qos_profile_data['qos_profile_id'])))
    qos_profile.name = qos_profile_data['name']
    qos_profile.description = qos_profile_data['description']
    qos_profile.status = qos_profile_data['status']
    qos_profile.targetMinUpstreamRate.CopyFrom(create_QoSProfileValueUnitPair(qos_profile_data['targetMinUpstreamRate']))
    qos_profile.maxUpstreamRate.CopyFrom(create_QoSProfileValueUnitPair(qos_profile_data['maxUpstreamRate']))
    qos_profile.maxUpstreamBurstRate.CopyFrom(create_QoSProfileValueUnitPair(qos_profile_data['maxUpstreamBurstRate']))
    qos_profile.targetMinDownstreamRate.CopyFrom(create_QoSProfileValueUnitPair(qos_profile_data['targetMinDownstreamRate']))
    qos_profile.maxDownstreamRate.CopyFrom(create_QoSProfileValueUnitPair(qos_profile_data['maxDownstreamRate']))
    qos_profile.maxDownstreamBurstRate.CopyFrom(create_QoSProfileValueUnitPair(qos_profile_data['maxDownstreamBurstRate']))
    qos_profile.minDuration.CopyFrom(create_QoSProfileValueUnitPair(qos_profile_data['minDuration']))
    qos_profile.maxDuration.CopyFrom(create_QoSProfileValueUnitPair(qos_profile_data['maxDuration']))
    qos_profile.priority = qos_profile_data['priority']
    qos_profile.packetDelayBudget.CopyFrom(create_QoSProfileValueUnitPair(qos_profile_data['packetDelayBudget']))
    qos_profile.jitter.CopyFrom(create_QoSProfileValueUnitPair(qos_profile_data['jitter']))
    qos_profile.packetErrorLossRate = qos_profile_data['packetErrorLossRate']
    return qos_profile
 No newline at end of file
Loading