Commit 9e82a62e authored by Andrea Sgambelluri's avatar Andrea Sgambelluri
Browse files

OFC26: German optical access topology and cross-domain service fixes

Adds the TeraFlowSDN side of the four-controller German lab (Ryu, TFS,
TransportPCE, ONOS) and fixes the faults found while driving it from the
central orchestrator over MCP/REST.

Topology (src/tests/PMPv1/ofc26): 27 devices -- 5 edge ROADMs and 6
transceivers on NETCONF agents, 8 OLE and 2 OLA as open-line-system
devices, and 3 abstracted TransportPCE border ROADMs plus 3 emulated
far-end transponders. 34 optical links and 32 fibre links. The line
equipment is deliberately off the optical path: the optical controller
drops any device that is neither ROADM nor transponder from its RSA
graph, and every link touching it with it.

Descriptor loading:
- split_links_by_type routed every LINKTYPE_FIBER link to SetOpticalLink,
  but OpticalLink has no link_type or attributes field, so an ordinary
  fibre Link raised ValueError inside the loader's worker thread, before
  any RPC, leaving nothing in the context log. Discriminate on the
  payload (optical_details) and strip Link-only fields.

Optical controller:
- slot_selection had an unconditional first-fit block ahead of the
  reservation and preferred-band logic; since every branch returned,
  both were unreachable and a pinned service silently got first-fit.
  Its own tests were failing on this.
- Realign the C band on the ITU 50 GHz grid. frequency_converter reports
  a centre as a slot edge plus 6.25 GHz, so with Fc on the 12.5 GHz grid
  every centre landed 6.25 GHz off the ITU grid and a peer domain's
  196.00 THz could never be matched. Fc now sits 6.25 GHz below the grid
  (plus a guard slot) and Nc/C_Slot.width cover the whole C band.

Service component:
- One update left the service ACTIVE holding only its optical band, with
  no /settings and no lightpath; repeating it created a second band and
  orphaned the first. Request the lightpath inside the new band instead
  of returning early.
- DeleteService read config_rules[0] and expected flow_id there. Rule 0
  is routinely a /settings-ob_ rule, which has none, so nothing was
  released and the caller got a bare Empty(). Find /settings by key,
  release every band the service holds, remove the record, and raise
  when there is nothing to release.
- Refuse an unsupported line rate naming the supported ones, instead of
  letting rsa_fs_computation fall off the end of its last if and return
  a bare None, which surfaced as an unexplained HTTP 500.

WebUI: draw links that reach an emulated device dashed, so a peer
domain's boundary is not shown as ordinary fibre.

Co-Authored-By: default avatarClaude Opus 5 <noreply@anthropic.com>
parent 99c075fd
Loading
Loading
Loading
Loading
+79 −0
Changes for src/common/tests/test_descriptor_split_links_by_type.py: 79 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.

import pytest

from common.proto.context_pb2 import Link, LinkTypeEnum, OpticalLink
from common.tools.descriptor.Tools import split_links_by_type


def _link(name, link_type=None, optical_details=None, attributes=None):
    link = {
        'link_id': {'link_uuid': {'uuid': name}},
        'name': name,
        'link_endpoint_ids': [
            {'device_id': {'device_uuid': {'uuid': 'A'}}, 'endpoint_uuid': {'uuid': 'a'}},
            {'device_id': {'device_uuid': {'uuid': 'Z'}}, 'endpoint_uuid': {'uuid': 'z'}},
        ],
    }
    if link_type       is not None: link['link_type'      ] = link_type
    if optical_details is not None: link['optical_details'] = optical_details
    if attributes      is not None: link['attributes'     ] = attributes
    return link


def test_fiber_link_without_optical_details_is_normal():
    # An ordinary fibre Link -- an amplifier span, a patch into an OLE -- is honestly
    # LINKTYPE_FIBER but carries no spectrum of its own. It has to reach SetLink: the
    # loader builds OpticalLink(**link) for the optical bucket, and OpticalLink has no
    # link_type or attributes field, so routing it there raises ValueError in the
    # loader's worker thread and the link is silently dropped before any RPC.
    links = [_link('span', link_type=LinkTypeEnum.LINKTYPE_FIBER,
                   attributes={'is_bidirectional': True})]
    typed_links = split_links_by_type(links)
    assert len(typed_links['optical']) == 0
    assert len(typed_links['normal' ]) == 1
    Link(**typed_links['normal'][0])   # must be constructible as what it is routed to


def test_fiber_link_with_optical_details_is_optical():
    links = [_link('och', link_type=LinkTypeEnum.LINKTYPE_FIBER,
                   optical_details={'length': 42.0})]
    typed_links = split_links_by_type(links)
    assert len(typed_links['normal' ]) == 0
    assert len(typed_links['optical']) == 1
    OpticalLink(**typed_links['optical'][0])


@pytest.mark.parametrize('link_type', [
    None,
    LinkTypeEnum.LINKTYPE_UNKNOWN,
    LinkTypeEnum.LINKTYPE_COPPER,
    LinkTypeEnum.LINKTYPE_RADIO,
    LinkTypeEnum.LINKTYPE_MANAGEMENT,
])
def test_non_optical_types_stay_normal(link_type):
    typed_links = split_links_by_type([_link('l', link_type=link_type)])
    assert len(typed_links['normal']) == 1


def test_virtual_type_is_virtual():
    typed_links = split_links_by_type([_link('v', link_type=LinkTypeEnum.LINKTYPE_VIRTUAL)])
    assert len(typed_links['virtual']) == 1


def test_link_type_accepts_int_and_name():
    for link_type in (LinkTypeEnum.LINKTYPE_FIBER, 'LINKTYPE_FIBER'):
        typed_links = split_links_by_type([_link('span', link_type=link_type)])
        assert len(typed_links['normal']) == 1, link_type
+19 −1
Changes for src/common/tools/descriptor/Tools.py: 19 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -151,6 +151,11 @@ LINK_TYPES_VIRTUAL = {
    LinkTypeEnum.LINKTYPE_VIRTUAL,
}

# Fields a Link carries that an OpticalLink has no equivalent for. A link routed to the
# optical bucket is handed to OpticalLink(**link), which raises ValueError on any field
# the message does not declare, so these have to come off on the way.
LINK_ONLY_FIELDS = {'link_type', 'attributes'}

def split_links_by_type(links : List[Dict]) -> Dict[str, List[Dict]]:
    typed_links = collections.defaultdict(list)
    for link in links:
@@ -164,7 +169,20 @@ def split_links_by_type(links : List[Dict]) -> Dict[str, List[Dict]]:
        if link_type in LINK_TYPES_NORMAL:
            typed_links['normal'].append(link)
        elif link_type in LINK_TYPES_OPTICAL:
            typed_links['optical'].append(link)
            # LINKTYPE_FIBER is overloaded: it is the type of an OpticalLink, but it is also
            # the honest type of an ordinary fibre Link that carries no spectrum of its own
            # (a span between amplifiers, a patch into an OLE, ...). Only the former can go
            # to SetOpticalLink: OpticalLink has no link_type or attributes field, so
            # OpticalLink(**link) raises ValueError on the latter. That failure happens in
            # the loader's own worker thread, before any RPC, so it leaves nothing in the
            # context service log to explain the missing links. Discriminate on the payload
            # rather than the enum: what makes a link optical is optical_details.
            if 'optical_details' in link:
                typed_links['optical'].append({
                    k: v for k, v in link.items() if k not in LINK_ONLY_FIELDS
                })
            else:
                typed_links['normal'].append(link)
        elif link_type in LINK_TYPES_VIRTUAL:
            typed_links['virtual'].append(link)
        else:
+6 −1
Changes for src/context/service/database/models/Slot.py: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -68,8 +68,13 @@ class SlotType(TypeDecorator):


class C_Slot(SlotType):
    # 384 slots of 12.5 GHz from Fc = 191.34375 THz (opticalcontroller.variables) cover
    # the ITU C band, 191.35 .. 196.1375 THz. An earlier width of 320 put
    # the upper C-band ITU channels out of range: a link declaring such a slot was
    # rejected outright with 'Slot key N out of valid range'. Keep this in step with
    # Nc in opticalcontroller/variables.py.
    start_point = 0
    width = 320
    width = 384


class L_Slot(SlotType):
+13 −12
Changes for src/context/tests/test_optical_link_slots.py: 13 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -46,9 +46,9 @@ def build_sparse_slot_input(active_slots):
@pytest.mark.parametrize(
    'slot_type,active_slots',
    [
        (C_Slot(), [0, 17, 319]),
        (L_Slot(), [0, 101, 549]),
        (S_Slot(), [0, 205, 719]),
        (C_Slot(), [0, 17, C_Slot.width - 1]),
        (L_Slot(), [0, 101, L_Slot.width - 1]),
        (S_Slot(), [0, 205, S_Slot.width - 1]),
    ],
)
def test_slot_type_roundtrip_preserves_positions(slot_type, active_slots) -> None:
@@ -65,9 +65,9 @@ def test_slot_type_roundtrip_preserves_positions(slot_type, active_slots) -> Non
@pytest.mark.parametrize(
    'slot_type,invalid_key',
    [
        (C_Slot(), 320),
        (L_Slot(), 550),
        (S_Slot(), 720),
        (C_Slot(), C_Slot.width),
        (L_Slot(), L_Slot.width),
        (S_Slot(), S_Slot.width),
    ],
)
def test_slot_type_rejects_out_of_range_keys(slot_type, invalid_key: int) -> None:
@@ -78,9 +78,10 @@ def test_slot_type_rejects_out_of_range_keys(slot_type, invalid_key: int) -> Non
def _run_slot_smoke_test(engine: sqlalchemy.engine.Engine) -> None:
    Base.metadata.create_all(engine)
    try:
        c_slots = build_sparse_slot_input([0, 10, 319])
        l_slots = build_sparse_slot_input([0, 12, 549])
        s_slots = build_sparse_slot_input([0, 14, 719])
        c_top, l_top, s_top = C_Slot.width - 1, L_Slot.width - 1, S_Slot.width - 1
        c_slots = build_sparse_slot_input([0, 10, c_top])
        l_slots = build_sparse_slot_input([0, 12, l_top])
        s_slots = build_sparse_slot_input([0, 14, s_top])

        with Session(engine) as session:
            session.add(SlotSmokeModel(id=1, c_slots=c_slots, l_slots=l_slots, s_slots=s_slots))
@@ -88,9 +89,9 @@ def _run_slot_smoke_test(engine: sqlalchemy.engine.Engine) -> None:

        with Session(engine) as session:
            stored = session.query(SlotSmokeModel).filter_by(id=1).one()
            assert stored.c_slots == build_expected_slot_map(0, 320, [0, 10, 319])
            assert stored.l_slots == build_expected_slot_map(0, 550, [0, 12, 549])
            assert stored.s_slots == build_expected_slot_map(0, 720, [0, 14, 719])
            assert stored.c_slots == build_expected_slot_map(0, C_Slot.width, [0, 10, c_top])
            assert stored.l_slots == build_expected_slot_map(0, L_Slot.width, [0, 12, l_top])
            assert stored.s_slots == build_expected_slot_map(0, S_Slot.width, [0, 14, s_top])
    finally:
        Base.metadata.drop_all(engine)

+82 −0
Changes for src/opticalcontroller/tests/test_c_band_slot_range.py: 82 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.

import pytest

from context.service.database.models.Slot import C_Slot, L_Slot, S_Slot
from opticalcontroller.variables import Fc, Nc, Nl, Ns
from opticalcontroller.tools import frequency_converter

# The ITU-T G.694.1 50 GHz grid is anchored on 193.1 THz.
ITU_ANCHOR_GHZ = 193100.0
ITU_SPACING_GHZ = 50.0

# Channels the German lab's boundary links use: TransportPCE holds the far half of each
# on its fixed 50 GHz grid, so these have to be reachable exactly or the two halves of a
# lightpath cannot agree.
PLANNED_CHANNELS_THZ = [195.95, 196.00, 196.10]

SLOTS_PER_50GHZ_CHANNEL = 4


def _achievable_centre_ghz(n_mid):
    """What frequency_converter reports for a 4-slot channel whose midpoint slot is n_mid."""
    n_start = n_mid - 1
    slots = [n_start + offset for offset in range(SLOTS_PER_50GHZ_CHANNEL)]
    centre_khz, width_khz = frequency_converter('c_slots', slots)
    return centre_khz / 1e6, width_khz / 1e6      # kHz -> GHz


def test_band_widths_match_between_db_model_and_rsa():
    # The RSA hands slot indices straight to the context DB, whose SlotType rejects
    # anything outside [start_point, start_point + width). If these drift apart, a link
    # the RSA considers legal is refused on insert with 'Slot key N out of valid range'.
    assert (C_Slot.start_point, C_Slot.width) == (0, Nc)
    assert (L_Slot.start_point, L_Slot.width) == (0, Nl)
    assert (S_Slot.start_point, S_Slot.width) == (0, Ns)


@pytest.mark.parametrize('channel_thz', PLANNED_CHANNELS_THZ)
def test_planned_channel_is_on_the_itu_grid(channel_thz):
    offset = (channel_thz * 1000.0 - ITU_ANCHOR_GHZ) % ITU_SPACING_GHZ
    assert offset == pytest.approx(0.0), 'test data is not an ITU 50 GHz channel'


@pytest.mark.parametrize('channel_thz', PLANNED_CHANNELS_THZ)
def test_planned_channel_is_reachable_exactly(channel_thz):
    # frequency_converter reports a centre as a slot edge plus 6.25 GHz, so the reachable
    # centres are Fc + n*12.5 + 6.25. Fc has to sit 6.25 GHz below an ITU grid point or
    # every centre lands half a slot off it, and no slot pinning can recover.
    n_mid = (channel_thz * 1000.0 - Fc - 6.25) / 12.5
    assert float(n_mid).is_integer(), (
        '{:.2f} THz needs midpoint slot {:.1f}; Fc={:.2f} GHz is not 6.25 GHz below the '
        'ITU grid'.format(channel_thz, n_mid, Fc)
    )
    n_mid = int(n_mid)
    assert 1 <= n_mid - 1 and n_mid + 2 < C_Slot.width, (
        '{:.2f} THz needs slots {:d}..{:d}, outside [0, {:d})'.format(
            channel_thz, n_mid - 1, n_mid + 2, C_Slot.width
        )
    )
    centre_ghz, width_ghz = _achievable_centre_ghz(n_mid)
    assert centre_ghz == pytest.approx(channel_thz * 1000.0)
    assert width_ghz == pytest.approx(ITU_SPACING_GHZ)


def test_whole_itu_c_band_is_covered():
    # ITU C band: 191.35 .. 196.10 THz, both ends on the 50 GHz grid.
    lowest_mid = int((191350.0 - Fc - 6.25) / 12.5)
    highest_mid = int((196100.0 - Fc - 6.25) / 12.5)
    assert lowest_mid - 1 >= 0
    assert highest_mid + 2 < C_Slot.width
Loading