Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datamodel new tag #247

Merged
merged 7 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = [
"prtpy",
"pydot",
"dataclasses-json",
"sdx-datamodel @ git+https://github.com/atlanticwave-sdx/[email protected].dev2",
"sdx-datamodel @ git+https://github.com/atlanticwave-sdx/[email protected].dev3",
]

[project.urls]
Expand Down
39 changes: 36 additions & 3 deletions src/sdx_pce/topology/temanager.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import logging
import re
import threading
import traceback
from itertools import chain
from typing import List, Optional

import networkx as nx
from networkx.algorithms import approximation as approx
from sdx_datamodel.models.port import Port
from sdx_datamodel.parsing.connectionhandler import ConnectionHandler
from sdx_datamodel.validation.connectionvalidator import ConnectionValidator

from sdx_pce.models import (
ConnectionPath,
Expand All @@ -21,7 +23,12 @@
)
from sdx_pce.topology.manager import TopologyManager
from sdx_pce.utils.constants import Constants
from sdx_pce.utils.exceptions import TEError, UnknownRequestError, ValidationError
from sdx_pce.utils.exceptions import (
RequestValidationError,
TEError,
UnknownRequestError,
ValidationError,
)

UNUSED_VLAN = None

Expand Down Expand Up @@ -259,6 +266,32 @@ def generate_traffic_matrix(self, connection_request: dict) -> TrafficMatrix:

request = ConnectionHandler().import_connection_data(connection_request)

try:
ConnectionValidator(request).is_valid()
except RequestValidationError as request_err:
self._logger.error(
f"Validation error: {request_err} for {connection_request}"
)
if "Strict QoS requirements" in str(request_err):
raise RequestValidationError(
f"Validation error: {request_err} for {connection_request}", 410
)
if "Scheduling" in str(request_err):
raise RequestValidationError(
f"Validation error: {request_err} for {connection_request}", 411
)
raise RequestValidationError(
f"Validation error: {request_err} for {connection_request}", 400
)
except Exception as e:
err = traceback.format_exc().replace("\n", ", ")
self._logger.error(
f"Error when generating/publishing breakdown: {e} - {err}"
)
raise RequestValidationError(
f"Validation error: {e} for {connection_request}", 400
)

self._logger.info(f"generate_traffic_matrix: decoded request: {request}")

ingress_port = request.ingress_port
Expand Down Expand Up @@ -655,13 +688,13 @@ def generate_connection_breakdown(
if tagged_breakdown is None:
raise TEError(
f"Can't find a valid vlan breakdown solution for: {connection_request}",
409,
410,
)

if not isinstance(tagged_breakdown, VlanTaggedBreakdowns):
raise TEError(
f"Validation error: {tagged_breakdown} is not the expected type",
409,
410,
)

# Now it is the time to update the bandwidth of the links after breakdowns are successfully generated
Expand Down
14 changes: 14 additions & 0 deletions src/sdx_pce/utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ def __init__(self, message: str, request_id: str):
self.request_id = request_id


class RequestValidationError(Exception):
"""
A custom exception to represent TE (Traffic Engineering) errors.
"""

def __init__(self, message: str, validation_code: int):
"""
:param message: a string containing the error message.
:param te_code: an integer representing the TE error code.
"""
super().__init__(f"{message} (Request Error Code: {validation_code})")
self.request_code = validation_code


class TEError(Exception):
"""
A custom exception to represent TE (Traffic Engineering) errors.
Expand Down
6 changes: 3 additions & 3 deletions tests/data/sax-2-request-invalid.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"state": "enabled",
"status": "up"
},
"end_time": "2000-01-23T04:56:07+00:00",
"end_time": "2030-01-23T04:56:07+00:00",
"id": "id",
"ingress_port": {
"id": "id",
Expand All @@ -20,8 +20,8 @@
},
"name": "name",
"quantity": 0,
"start_time": "2000-01-23T04:56:07+00:00",
"start_time": "2030-01-23T04:56:07+00:00",
"status": "success",
"timestamp": "2000-01-23T04:56:07+00:00",
"timestamp": "2030-01-23T04:56:07+00:00",
"version": 1
}
6 changes: 3 additions & 3 deletions tests/data/sax-2-request-valid.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"state": "enabled",
"status": "up"
},
"end_time": "2000-01-23T04:56:07+00:00",
"end_time": "2030-01-23T04:56:07+00:00",
"id": "id",
"ingress_port": {
"id": "urn:sdx:port:sax:B2:1",
Expand All @@ -20,8 +20,8 @@
},
"name": "name",
"quantity": 0,
"start_time": "2000-01-23T04:56:07+00:00",
"start_time": "2030-01-23T04:56:07+00:00",
"status": "success",
"timestamp": "2000-01-23T04:56:07+00:00",
"timestamp": "2030-01-23T04:56:07+00:00",
"version": 1
}
4 changes: 2 additions & 2 deletions tests/data/test_request_amlight.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "id",
"name": "AMLight",
"start_time": "2000-01-23T04:56:07.000Z",
"end_time": "2000-01-23T04:56:07.000Z",
"start_time": "2030-01-23T04:56:07.000",
"end_time": "2030-01-23T04:56:07.000",
"bandwidth_required": 100,
"latency_required": 20,
"egress_port":
Expand Down
4 changes: 2 additions & 2 deletions tests/data/test_request_amlight_user_port.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "id",
"name": "AMLight",
"start_time": "2000-01-23T04:56:07.000Z",
"end_time": "2000-01-23T04:56:07.000Z",
"start_time": "2030-01-23T04:56:07.000",
"end_time": "2030-01-23T04:56:07.000",
"bandwidth_required": 100,
"latency_required": 20,
"egress_port":
Expand Down
4 changes: 2 additions & 2 deletions tests/data/test_request_amlight_zaoxi_user_port.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "285eea4b-1e86-4d54-bd75-f14b8cb4a63a",
"name": "Test connection request",
"start_time": "2000-01-23T04:56:07.000Z",
"end_time": "2000-01-23T04:56:07.000Z",
"start_time": "2030-01-23T04:56:07.000",
"end_time": "2030-01-23T04:56:07.000",
"bandwidth_required": 10,
"latency_required": 300,
"egress_port": {
Expand Down
Loading