diff --git a/pytcp/stack/__init__.py b/pytcp/stack/__init__.py index 5a0ecbe6..2547fc59 100755 --- a/pytcp/stack/__init__.py +++ b/pytcp/stack/__init__.py @@ -39,10 +39,10 @@ from pytcp.stack.arp_cache import ArpCache from pytcp.stack.nd_cache import NdCache +from pytcp.stack.packet_handler import PacketHandler from pytcp.stack.rx_ring import RxRing from pytcp.stack.timer import Timer from pytcp.stack.tx_ring import TxRing -from pytcp.subsystems.packet_handler import PacketHandler if TYPE_CHECKING: from net_addr import Ip4Address diff --git a/pytcp/subsystems/packet_handler/__init__.py b/pytcp/stack/packet_handler/__init__.py similarity index 100% rename from pytcp/subsystems/packet_handler/__init__.py rename to pytcp/stack/packet_handler/__init__.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__arp__rx.py b/pytcp/stack/packet_handler/packet_handler__arp__rx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__arp__rx.py rename to pytcp/stack/packet_handler/packet_handler__arp__rx.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__arp__tx.py b/pytcp/stack/packet_handler/packet_handler__arp__tx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__arp__tx.py rename to pytcp/stack/packet_handler/packet_handler__arp__tx.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__ethernet_802_3__rx.py b/pytcp/stack/packet_handler/packet_handler__ethernet_802_3__rx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__ethernet_802_3__rx.py rename to pytcp/stack/packet_handler/packet_handler__ethernet_802_3__rx.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__ethernet_802_3__tx.py b/pytcp/stack/packet_handler/packet_handler__ethernet_802_3__tx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__ethernet_802_3__tx.py rename to pytcp/stack/packet_handler/packet_handler__ethernet_802_3__tx.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__ethernet__rx.py b/pytcp/stack/packet_handler/packet_handler__ethernet__rx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__ethernet__rx.py rename to pytcp/stack/packet_handler/packet_handler__ethernet__rx.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__ethernet__tx.py b/pytcp/stack/packet_handler/packet_handler__ethernet__tx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__ethernet__tx.py rename to pytcp/stack/packet_handler/packet_handler__ethernet__tx.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__icmp4__rx.py b/pytcp/stack/packet_handler/packet_handler__icmp4__rx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__icmp4__rx.py rename to pytcp/stack/packet_handler/packet_handler__icmp4__rx.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__icmp4__tx.py b/pytcp/stack/packet_handler/packet_handler__icmp4__tx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__icmp4__tx.py rename to pytcp/stack/packet_handler/packet_handler__icmp4__tx.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__icmp6__rx.py b/pytcp/stack/packet_handler/packet_handler__icmp6__rx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__icmp6__rx.py rename to pytcp/stack/packet_handler/packet_handler__icmp6__rx.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__icmp6__tx.py b/pytcp/stack/packet_handler/packet_handler__icmp6__tx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__icmp6__tx.py rename to pytcp/stack/packet_handler/packet_handler__icmp6__tx.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__ip4__rx.py b/pytcp/stack/packet_handler/packet_handler__ip4__rx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__ip4__rx.py rename to pytcp/stack/packet_handler/packet_handler__ip4__rx.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__ip4__tx.py b/pytcp/stack/packet_handler/packet_handler__ip4__tx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__ip4__tx.py rename to pytcp/stack/packet_handler/packet_handler__ip4__tx.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__ip6__rx.py b/pytcp/stack/packet_handler/packet_handler__ip6__rx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__ip6__rx.py rename to pytcp/stack/packet_handler/packet_handler__ip6__rx.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__ip6__tx.py b/pytcp/stack/packet_handler/packet_handler__ip6__tx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__ip6__tx.py rename to pytcp/stack/packet_handler/packet_handler__ip6__tx.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__ip6_frag__rx.py b/pytcp/stack/packet_handler/packet_handler__ip6_frag__rx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__ip6_frag__rx.py rename to pytcp/stack/packet_handler/packet_handler__ip6_frag__rx.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__ip6_frag__tx.py b/pytcp/stack/packet_handler/packet_handler__ip6_frag__tx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__ip6_frag__tx.py rename to pytcp/stack/packet_handler/packet_handler__ip6_frag__tx.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__tcp__rx.py b/pytcp/stack/packet_handler/packet_handler__tcp__rx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__tcp__rx.py rename to pytcp/stack/packet_handler/packet_handler__tcp__rx.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__tcp__tx.py b/pytcp/stack/packet_handler/packet_handler__tcp__tx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__tcp__tx.py rename to pytcp/stack/packet_handler/packet_handler__tcp__tx.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__udp__rx.py b/pytcp/stack/packet_handler/packet_handler__udp__rx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__udp__rx.py rename to pytcp/stack/packet_handler/packet_handler__udp__rx.py diff --git a/pytcp/subsystems/packet_handler/packet_handler__udp__tx.py b/pytcp/stack/packet_handler/packet_handler__udp__tx.py similarity index 100% rename from pytcp/subsystems/packet_handler/packet_handler__udp__tx.py rename to pytcp/stack/packet_handler/packet_handler__udp__tx.py diff --git a/tests__legacy/integration/packet_flows_rx.py b/tests__legacy/integration/packet_flows_rx.py index f8b31e5d..5887c7b6 100755 --- a/tests__legacy/integration/packet_flows_rx.py +++ b/tests__legacy/integration/packet_flows_rx.py @@ -35,30 +35,11 @@ from testslide import TestCase +from pytcp import config from net_addr import Ip4Address, Ip4Host, Ip6Address, Ip6Host, MacAddress from pytcp.lib.packet import PacketRx from pytcp.lib.packet_stats import PacketStatsRx, PacketStatsTx -from pytcp.subsystems.packet_handler import PacketHandler - -PACKET_HANDLER_MODULES = [ - "pytcp.subsystems.packet_handler", - "protocols.ether.phrx", - "protocols.ether.phtx", - "protocols.arp.phrx", - "protocols.arp.phtx", - "protocols.ip4.phrx", - "protocols.ip4.phtx", - "protocols.ip6.phrx", - "protocols.ip6.phtx", - "protocols.icmp4.phrx", - "protocols.icmp4.phtx", - "protocols.icmp6.phrx", - "protocols.icmp6.phtx", - "protocols.udp.phrx", - "protocols.udp.phtx", - "protocols.tcp.phrx", - "protocols.tcp.phtx", -] +from pytcp.stack.packet_handler import PacketHandler # Ensure critical configuration settings are set properly for the testing @@ -115,14 +96,8 @@ def _patch_config(self) -> None: """ Patch critical config setting for all packet handler modules. """ - for module in PACKET_HANDLER_MODULES: - for attribute, new_value in CONFIG_PATCHES.items(): - try: - self.patch_attribute( - f"{module}.config", attribute, new_value - ) - except ModuleNotFoundError: - continue + for attribute, new_value in CONFIG_PATCHES.items(): + config.__dict__[attribute] = new_value # Test name format: # 'test_name__protocol_tested__test_description__optional_condition' diff --git a/tests__legacy/integration/packet_flows_rx_tx.py b/tests__legacy/integration/packet_flows_rx_tx.py index 91ad52be..69250a89 100755 --- a/tests__legacy/integration/packet_flows_rx_tx.py +++ b/tests__legacy/integration/packet_flows_rx_tx.py @@ -37,34 +37,15 @@ from testslide import StrictMock, TestCase +from pytcp import config from net_addr import Ip4Address, Ip4Host, Ip6Address, Ip6Host, MacAddress from pytcp.lib.packet import PacketRx from pytcp.lib.packet_stats import PacketStatsRx, PacketStatsTx from pytcp.stack.arp_cache import ArpCache from pytcp.stack.nd_cache import NdCache -from pytcp.subsystems.packet_handler import PacketHandler +from pytcp.stack.packet_handler import PacketHandler from pytcp.stack.tx_ring import TxRing -PACKET_HANDLER_MODULES = [ - "pytcp.subsystems.packet_handler", - "protocols.ethernet.phrx", - "protocols.ethernet.phtx", - "protocols.arp.phrx", - "protocols.arp.phtx", - "protocols.ip4.phrx", - "protocols.ip4.phtx", - "protocols.ip6.phrx", - "protocols.ip6.phtx", - "protocols.icmp4.phrx", - "protocols.icmp4.phtx", - "protocols.icmp6.phrx", - "protocols.icmp6.phtx", - "protocols.udp.phrx", - "protocols.udp.phtx", - "protocols.tcp.phrx", - "protocols.tcp.phtx", -] - # Ensure critical configuration settings are set properly for # the testing regardless of actual configuration @@ -174,16 +155,8 @@ def _patch_config(self) -> None: """ Patch critical config setting for all packet handler modules. """ - for module in PACKET_HANDLER_MODULES: - for attribute, new_value in CONFIG_PATCHES.items(): - try: - self.patch_attribute( - target=f"{module}.config", - attribute=attribute, - new_value=new_value, - ) - except ModuleNotFoundError: - continue + for attribute, new_value in CONFIG_PATCHES.items(): + config.__dict__[attribute] = new_value # Test name format: # 'test_name__protocol_tested__test_description__optional_condition' diff --git a/tests__legacy/unit/mock_network.py b/tests__legacy/unit/mock_network.py index 55976b55..f224794d 100755 --- a/tests__legacy/unit/mock_network.py +++ b/tests__legacy/unit/mock_network.py @@ -35,11 +35,11 @@ from typing import no_type_check from testslide import StrictMock, TestCase - +from pytcp import config from net_addr import Ip4Address, Ip4Host, Ip6Address, Ip6Host, MacAddress from pytcp.stack.arp_cache import ArpCache from pytcp.stack.nd_cache import NdCache -from pytcp.subsystems.packet_handler import PacketHandler +from pytcp.stack.packet_handler import PacketHandler from pytcp.stack.tx_ring import TxRing # # # IPv4 @@ -115,27 +115,6 @@ def __init__(self) -> None: self.router_b_ip6_address = Ip6Address("fe80::2") -PACKET_HANDLER_MODULES = [ - "pytcp.subsystems.packet_handler", - "pytcp.protocols.ether.phrx", - "pytcp.protocols.ether.phtx", - "pytcp.protocols.arp.phrx", - "pytcp.protocols.arp.phtx", - "pytcp.protocols.ip4.phrx", - "pytcp.protocols.ip4.phtx", - "pytcp.protocols.ip6.phrx", - "pytcp.protocols.ip6.phtx", - "pytcp.protocols.icmp4.phrx", - "pytcp.protocols.icmp4.phtx", - "pytcp.protocols.icmp6.phrx", - "pytcp.protocols.icmp6.phtx", - "pytcp.protocols.udp.phrx", - "pytcp.protocols.udp.phtx", - "pytcp.protocols.tcp.phrx", - "pytcp.protocols.tcp.phtx", -] - - CONFIG_PATCHES = { "LOG__CHANNEL": set(), "IP6__SUPPORT_ENABLED": True, @@ -151,27 +130,8 @@ def patch_config(self: TestCase, *, enable_log: bool = False) -> None: """ Patch critical config setting for all packet handler modules. """ - for module in PACKET_HANDLER_MODULES: - for variable, value in CONFIG_PATCHES.items(): - if enable_log and variable == "LOG__CHANNEL": - value = { - "stack", - "arp-c", - "nd-c", - "ether", - "arp", - "ip4", - "ip6", - "icmp4", - "icmp6", - "udp", - "tcp", - "socket", - } - try: - self.patch_attribute(f"{module}.config", variable, value) - except ModuleNotFoundError: - continue + for attribute, new_value in CONFIG_PATCHES.items(): + config.__dict__[attribute] = new_value # Had to disable type checking in this function because it modifies variables diff --git a/tests__legacy/unit/protocols__arp__phtx.py b/tests__legacy/unit/protocols__arp__phtx.py index 19018680..5e4e49cb 100755 --- a/tests__legacy/unit/protocols__arp__phtx.py +++ b/tests__legacy/unit/protocols__arp__phtx.py @@ -42,7 +42,7 @@ from pytcp.lib.packet_stats import PacketStatsTx from pytcp.lib.tx_status import TxStatus from pytcp.protocols.arp.arp__header import ArpOperation -from pytcp.subsystems.packet_handler import PacketHandler +from pytcp.stack.packet_handler import PacketHandler class TestArpPhtx(TestCase): diff --git a/tests__legacy/unit/protocols__ethernet__phtx.py b/tests__legacy/unit/protocols__ethernet__phtx.py index ce76445c..db06ca8b 100755 --- a/tests__legacy/unit/protocols__ethernet__phtx.py +++ b/tests__legacy/unit/protocols__ethernet__phtx.py @@ -47,7 +47,7 @@ from pytcp.lib.packet_stats import PacketStatsTx from pytcp.lib.tx_status import TxStatus -from pytcp.subsystems.packet_handler import PacketHandler +from pytcp.stack.packet_handler import PacketHandler TEST_FRAME_DIR = "tests__legacy/unit/test_frames/ethernet_phtx/" diff --git a/tests__legacy/unit/protocols__icmp4__phtx.py b/tests__legacy/unit/protocols__icmp4__phtx.py index 633d47c1..b6556805 100755 --- a/tests__legacy/unit/protocols__icmp4__phtx.py +++ b/tests__legacy/unit/protocols__icmp4__phtx.py @@ -51,7 +51,7 @@ from pytcp.protocols.icmp4.message.icmp4_message__echo_request import ( Icmp4EchoRequestMessage, ) -from pytcp.subsystems.packet_handler import PacketHandler +from pytcp.stack.packet_handler import PacketHandler TEST_FRAME_DIR = "tests__legacy/unit/test_frames/icmp4_phtx/" diff --git a/tests__legacy/unit/protocols__icmp6__phtx.py b/tests__legacy/unit/protocols__icmp6__phtx.py index cda5906c..47d9245d 100755 --- a/tests__legacy/unit/protocols__icmp6__phtx.py +++ b/tests__legacy/unit/protocols__icmp6__phtx.py @@ -60,7 +60,7 @@ Icmp6NdOptions, Icmp6NdOptionSlla, ) -from pytcp.subsystems.packet_handler import PacketHandler +from pytcp.stack.packet_handler import PacketHandler TEST_FRAME_DIR = "tests__legacy/unit/test_frames/icmp6_phtx/" diff --git a/tests__legacy/unit/protocols__ip4__phtx.py b/tests__legacy/unit/protocols__ip4__phtx.py index 5af614e1..5b461b14 100755 --- a/tests__legacy/unit/protocols__ip4__phtx.py +++ b/tests__legacy/unit/protocols__ip4__phtx.py @@ -42,7 +42,7 @@ from pytcp.lib.packet_stats import PacketStatsTx from pytcp.lib.tx_status import TxStatus from pytcp.protocols.raw.raw__assembler import RawAssembler -from pytcp.subsystems.packet_handler import PacketHandler +from pytcp.stack.packet_handler import PacketHandler TEST_FRAME_DIR = "tests__legacy/unit/test_frames/ip4_phtx/" diff --git a/tests__legacy/unit/protocols__ip6__phtx.py b/tests__legacy/unit/protocols__ip6__phtx.py index a1d91363..b0524dca 100755 --- a/tests__legacy/unit/protocols__ip6__phtx.py +++ b/tests__legacy/unit/protocols__ip6__phtx.py @@ -42,7 +42,7 @@ from pytcp.lib.packet_stats import PacketStatsTx from pytcp.lib.tx_status import TxStatus from pytcp.protocols.raw.raw__assembler import RawAssembler -from pytcp.subsystems.packet_handler import PacketHandler +from pytcp.stack.packet_handler import PacketHandler TEST_FRAME_DIR = "tests__legacy/unit/test_frames/ip6_phtx/" diff --git a/tests__legacy/unit/protocols__tcp__phtx.py b/tests__legacy/unit/protocols__tcp__phtx.py index f1921ccc..3bac625d 100755 --- a/tests__legacy/unit/protocols__tcp__phtx.py +++ b/tests__legacy/unit/protocols__tcp__phtx.py @@ -41,7 +41,7 @@ from pytcp.lib.packet_stats import PacketStatsTx from pytcp.lib.tx_status import TxStatus -from pytcp.subsystems.packet_handler import PacketHandler +from pytcp.stack.packet_handler import PacketHandler TEST_FRAME_DIR = "tests__legacy/unit/test_frames/tcp_phtx/" diff --git a/tests__legacy/unit/protocols__udp__phtx.py b/tests__legacy/unit/protocols__udp__phtx.py index 9ac36701..fc141fd9 100755 --- a/tests__legacy/unit/protocols__udp__phtx.py +++ b/tests__legacy/unit/protocols__udp__phtx.py @@ -41,7 +41,7 @@ from pytcp.lib.packet_stats import PacketStatsTx from pytcp.lib.tx_status import TxStatus -from pytcp.subsystems.packet_handler import PacketHandler +from pytcp.stack.packet_handler import PacketHandler TEST_FRAME_DIR = "tests__legacy/unit/test_frames/udp_phtx/" diff --git a/tests__legacy/unreliable/subsystems__packet_handler.py b/tests__legacy/unreliable/subsystems__packet_handler.py index 95423f29..d1c01ac8 100755 --- a/tests__legacy/unreliable/subsystems__packet_handler.py +++ b/tests__legacy/unreliable/subsystems__packet_handler.py @@ -34,7 +34,7 @@ from testslide import TestCase -from pytcp.subsystems.packet_handler import PacketHandler +from pytcp.stack.packet_handler import PacketHandler class TestPacketHandler(TestCase):