Skip to content
This repository was archived by the owner on Feb 27, 2025. It is now read-only.
Merged
92 changes: 92 additions & 0 deletions tests/test_clis/test_port_number_is_changed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from __future__ import annotations
from xoa_driver.enums import MediaConfigurationType
from xoa_driver.functions.mgmt import (
get_module_supported_media,
set_module_media_config,
)

import timeit
import pstats
import cProfile

import asyncio
import os
import sys
import logging
from typing import Coroutine, List, Any

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from loguru import logger # noqa: E402
from xoa_driver.testers import L23Tester # noqa: E402
from xoa_driver.internals.utils.managers.exceptions import NoSuchPortError # noqa: E402


async def test_using_a_outdated_port():
# Module 7 of destination chassis is supposed to have two modes: BASE-T1(7 ports), BASE-T1S(2 ports), switch to BASE-T1 to start this test.
t = await L23Tester("192.168.1.198", "Ron", enable_logging=False)

m1 = t.modules.obtain(7)
p1 = m1.ports.obtain(3)
print(await p1.interface.get())
print('success1')
await set_module_media_config(m1, MediaConfigurationType.BASE_T1S)
try:
print(await p1.interface.get())
print('success2')
except ConnectionRefusedError as e:
print(e)
try:
p2 = m1.ports.obtain(3)
print(await p2.interface.get())
print('success3')
except NoSuchPortError as e:
print(e)


async def test_getting_a_removed_port():
# Module 7 of destination chassis is supposed to have two modes: BASE-T1(7 ports), BASE-T1S(2 ports), switch to BASE-T1 to start this test.
t = await L23Tester("192.168.1.198", "Ron", enable_logging=False)
m1 = t.modules.obtain(7)
print(len(m1.ports))

p1 = m1.ports.obtain(1)
print('success1', await p1.interface.get())

await set_module_media_config(m1, MediaConfigurationType.BASE_T1S)

print(len(m1.ports))
try:
print('success2', await p1.interface.get())
except ConnectionRefusedError as e:
print(e)
# This will raise Exceptions.

p2 = m1.ports.obtain(1)
print('success3', await p2.interface.get())
# This line should do fine.


async def test_getting_stream_under_a_removed_port():
# Module 7 of destination chassis is supposed to have two modes: BASE-T1(7 ports), BASE-T1S(2 ports), switch to BASE-T1 to start this test.
t = await L23Tester("192.168.1.198", "Ron", enable_logging=False)
m1 = t.modules.obtain(7)
p1 = m1.ports.obtain(3)
await p1.reservation.set_reserve()
s = await p1.streams.create()
b = s.comment
await set_module_media_config(m1, MediaConfigurationType.BASE_T1S)

print(await b.get())


def run(method: Coroutine) -> None:
import platform

if platform.system() == "Windows":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(method)


if __name__ == "__main__":
run(test_getting_stream_under_a_removed_port())
2 changes: 1 addition & 1 deletion xoa_driver/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "2.0.2"
__version__ = "2.1.0"
__short_version__ = "2.0"
2 changes: 1 addition & 1 deletion xoa_driver/functions/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, serdes: list[int]) -> None:
class NotSupportMedia(ConfigError):
def __init__(self, module: GenericAnyModule) -> None:
module_id = module.module_id
self.msg = f"This module {module_id} does not support the media configuration!"
self.msg = f"This module {module_id} does not support this media configuration!"


class NotSupportPortSpeed(ConfigError):
Expand Down
91 changes: 84 additions & 7 deletions xoa_driver/internals/commands/enums.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from enum import IntEnum
from enum import IntEnum, IntFlag


# region L23 enums
Expand Down Expand Up @@ -522,10 +522,74 @@ class ProtocolOption(IntEnum):
"""EtherType"""

# Generate RAW form 1...64 bytes
_ignore_ = "ProtocolOption i"
ProtocolOption = vars()
for i in range(1, 65):
ProtocolOption["RAW_%d" % i] = 256 - i # type: ignore
# _ignore_ = "ProtocolOption i"
# ProtocolOption = vars()
# for i in range(1, 65):
# ProtocolOption["RAW_%d" % i] = 256 - i # type: ignore
RAW_1 = 255
RAW_2 = 254
RAW_3 = 253
RAW_4 = 252
RAW_5 = 251
RAW_6 = 250
RAW_7 = 249
RAW_8 = 248
RAW_9 = 247
RAW_10 = 246
RAW_11 = 245
RAW_12 = 244
RAW_13 = 243
RAW_14 = 242
RAW_15 = 241
RAW_16 = 240
RAW_17 = 239
RAW_18 = 238
RAW_19 = 237
RAW_20 = 236
RAW_21 = 235
RAW_22 = 234
RAW_23 = 233
RAW_24 = 232
RAW_25 = 231
RAW_26 = 230
RAW_27 = 229
RAW_28 = 228
RAW_29 = 227
RAW_30 = 226
RAW_31 = 225
RAW_32 = 224
RAW_33 = 223
RAW_34 = 222
RAW_35 = 221
RAW_36 = 220
RAW_37 = 219
RAW_38 = 218
RAW_39 = 217
RAW_40 = 216
RAW_41 = 215
RAW_42 = 214
RAW_43 = 213
RAW_44 = 212
RAW_45 = 211
RAW_46 = 210
RAW_47 = 209
RAW_48 = 208
RAW_49 = 207
RAW_50 = 206
RAW_51 = 205
RAW_52 = 204
RAW_53 = 203
RAW_54 = 202
RAW_55 = 201
RAW_56 = 200
RAW_57 = 199
RAW_58 = 198
RAW_59 = 197
RAW_60 = 196
RAW_61 = 195
RAW_62 = 194
RAW_63 = 193
RAW_64 = 192


class ModifierAction(IntEnum):
Expand Down Expand Up @@ -910,6 +974,15 @@ class MediaConfigurationType(IntEnum):
OSFP800 = 112
"""OSFP800"""

QSFPDD800_ANLT = 113
"""QSFPDD800 ANLT"""

QSFP112_ANLT = 114
"""QSFP112 ANLT"""

OSFP800_ANLT = 115
"""OSFP800 ANLT"""

UNKNOWN = 255


Expand Down Expand Up @@ -1908,7 +1981,7 @@ class AutoNegTecAbility(IntEnum):
"""BAM 400G CR8 KR8"""


class AutoNegFECOption(IntEnum):
class AutoNegFECOption(IntFlag):
"""Auto Neg FEC Options"""

DEFAULT_FEC = 0
Expand All @@ -1925,6 +1998,8 @@ class AutoNegFECOption(IntEnum):
"""RS 544"""
RS272 = 1024
"""RS 272"""
RSFEC_CL161 = 8
"""RS CL 161"""


class AutoNegFECType(IntEnum):
Expand Down Expand Up @@ -1963,7 +2038,7 @@ class AutoNegStatus(IntEnum):
"""AN Good"""


class AutoNegFECStatus(IntEnum):
class AutoNegFECStatus(IntFlag):
"""Auto Neg FEC Status"""

DEFAULT_FEC = 0
Expand All @@ -1980,6 +2055,8 @@ class AutoNegFECStatus(IntEnum):
"""RS 544"""
RS272 = 1024
"""RS 272"""
RSFEC_CL161 = 8
"""RS CL 161"""


class LinkTrainingMode(IntEnum):
Expand Down
12 changes: 6 additions & 6 deletions xoa_driver/internals/commands/pp_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1873,9 +1873,9 @@ class GetDataAttr(ResponseBodyStruct):
"""coded integer, mode"""
tec_ability: AutoNegTecAbility = field(XmpInt())
"""coded integer, technical ability."""
fec_capable: AutoNegFECOption = field(XmpInt())
fec_capable: int = field(XmpInt())
"""coded integer, FEC capable."""
fec_requested: AutoNegFECOption = field(XmpInt())
fec_requested: int = field(XmpInt())
"""coded integer, FEC requested."""
pause_mode: PauseMode = field(XmpInt())
"""coded integer, pause mode."""
Expand All @@ -1885,9 +1885,9 @@ class SetDataAttr(RequestBodyStruct):
"""coded integer, mode"""
tec_ability: AutoNegTecAbility = field(XmpInt())
"""coded integer, technical ability."""
fec_capable: AutoNegFECOption = field(XmpInt())
fec_capable: int = field(XmpInt())
"""coded integer, FEC capable."""
fec_requested: AutoNegFECOption = field(XmpInt())
fec_requested: int = field(XmpInt())
"""coded integer, FEC requested."""
pause_mode: PauseMode = field(XmpInt())
"""coded integer, pause mode."""
Expand Down Expand Up @@ -1954,9 +1954,9 @@ class GetDataAttr(ResponseBodyStruct):
"""coded integer, auto-negotiation state."""
tec_ability: AutoNegTecAbility = field(XmpInt())
"""coded integer, technical ability."""
fec_capable: AutoNegFECStatus = field(XmpInt())
fec_capable: int = field(XmpInt())
"""coded integer, FEC capable partner."""
fec_requested: AutoNegFECStatus = field(XmpInt())
fec_requested: int = field(XmpInt())
"""coded integer, FEC requested partner."""
pause_mode: PauseMode = field(XmpInt())
"""coded integer, pause mode."""
Expand Down
3 changes: 3 additions & 0 deletions xoa_driver/internals/core/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ def subscribe(self, xmc_cls: "ICommand", callback: "t.Callable") -> None:

def on_disconnected(self, callback: "t.Callable") -> None:
...

def set_outdated(self) -> None:
...
3 changes: 3 additions & 0 deletions xoa_driver/internals/core/transporter/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,6 @@ def subscribe(self, xmc_cls: ICommand, callback: Callable) -> None:
def on_disconnected(self, callback: Callable) -> None:
"""Regiser users callback which will be called after connection was terminated."""
self.__resp_publisher.subscribe_connection_lost(callback)

def set_outdated(self) -> None:
pass
20 changes: 11 additions & 9 deletions xoa_driver/internals/hli_v1/modules/module_chimera.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import typing
import asyncio
import functools
from typing import TYPE_CHECKING
from typing_extensions import Self
from xoa_driver.internals.commands import (
M_STATUS,
Expand Down Expand Up @@ -29,9 +28,12 @@
from xoa_driver.internals.utils import attributes as utils
from xoa_driver.internals.state_storage import modules_state
from xoa_driver import ports
from xoa_driver.internals.hli_v1.modules.modules_l23.module_l23_base import MediaModule, CfpModule
from . import base_module as bm
if TYPE_CHECKING:

if typing.TYPE_CHECKING:
from xoa_driver.internals.core import interfaces as itf
from xoa_driver.internals.hli_v1.modules.modules_l23.module_l23_base import ModuleL23
from . import __interfaces as m_itf


Expand Down Expand Up @@ -60,18 +62,18 @@ class ChCFP:
CFP test module (Chimera).
"""

def __init__(self, conn: "itf.IConnection", module_id: int) -> None:
self.type = M_CFPTYPE(conn, module_id)
def __init__(self, conn: "itf.IConnection", module: typing.Union["ModuleL23", "ModuleChimera"]) -> None:
self.type = M_CFPTYPE(conn, module.module_id)
"""
The transceiver's CFP type currently inserted.

:type: M_CFPTYPE
"""
self.config = M_CFPCONFIGEXT(conn, module_id)
self.config = CfpModule(conn, module)
"""
The CFP configuration of the test module.

:type: M_CFPCONFIGEXT
:type: CfpModule
"""


Expand Down Expand Up @@ -142,7 +144,7 @@ def __init__(self, conn: "itf.IConnection", init_data: "m_itf.ModuleInitData") -
:type: ChTiming
"""

self.cfp = ChCFP(conn, self.module_id)
self.cfp = ChCFP(conn, self)
"""
CFP test module (Chimera).

Expand Down Expand Up @@ -204,10 +206,10 @@ def __init__(self, conn: "itf.IConnection", init_data: "m_itf.ModuleInitData") -
:type: M_REVISION
"""

self.media = M_MEDIA(conn, self.module_id)
self.media = MediaModule(conn, self)
"""Test module's media type.

:type: M_MEDIA
:type: MediaModule
"""

self.available_speeds = M_MEDIASUPPORT(conn, self.module_id)
Expand Down
Loading