diff --git a/qns/entity/cchannel/cchannel_ex.py b/qns/entity/cchannel/cchannel_ex.py index b1c5e01..cc4bd9c 100644 --- a/qns/entity/cchannel/cchannel_ex.py +++ b/qns/entity/cchannel/cchannel_ex.py @@ -15,13 +15,15 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from typing import Any, List +from typing import List, Union from qns.simulator.ts import Time from qns.entity.node.node import QNode from qns.models.delay.delay import DelayModel from qns.simulator.simulator import Simulator -from qns.entity.cchannel.cchannel import * +from qns.utils.rnd import get_rand +import qns.utils.log as log +from qns.entity.cchannel.cchannel import ClassicPacket, ClassicChannel, RecvClassicPacket, NextHopNotConnectionException class ClassicChannelEx(ClassicChannel): @@ -35,8 +37,8 @@ def __init__( name: str = None, node_list: List[QNode] = [], bandwidth: int = 0, - delay: float | DelayModel = 0, - length: float | None = 0, + delay: Union[float, DelayModel] = 0, + length: Union[float, None] = 0, drop_rate: float = 0, max_buffer_size: int = 0, ): diff --git a/qns/simulator/stablepool.py b/qns/simulator/stablepool.py index 9f0e586..0e845fb 100644 --- a/qns/simulator/stablepool.py +++ b/qns/simulator/stablepool.py @@ -30,7 +30,7 @@ def __eq__(self, other) -> bool: return self.event == other.event and self.seq == other.seq def __lt__(self, other) -> bool: - return self.event < other.event or (@ + return self.event < other.event or ( self.event == other.event and self.seq < other.seq ) diff --git a/test/entity/test_cchannelex.py b/test/entity/test_cchannelex.py index f2ad33d..a8a1154 100644 --- a/test/entity/test_cchannelex.py +++ b/test/entity/test_cchannelex.py @@ -1,8 +1,10 @@ from qns.simulator.event import Event from qns.simulator import Simulator, func_to_event -from qns.utils.log import * from qns.simulator.stablepool import StableEventPool -from qns.entity import * +from qns.entity.node.node import QNode +from qns.entity.node.app import Application +from qns.utils.log import install +from qns.entity.cchannel.cchannel import ClassicChannel, ClassicPacket from qns.entity.cchannel.cchannel_ex import ClassicChannelEx @@ -48,16 +50,14 @@ def recv(self, node, event: Event): self.recved_time.append(self._simulator.tc) -def test(ex, tparam): +def _run_sim(is_used, tparam): sim = Simulator(0, 10, pool_cls=StableEventPool) - install(sim) n1 = QNode("n1") n2 = QNode("n2") - global c12 - if not ex: + if not is_used: c12 = ClassicChannel( bandwidth=tparam[0], drop_rate=tparam[1], @@ -94,27 +94,30 @@ def test(ex, tparam): s1.start() s2.start() - sim.run() - print(f"n1->n2: {r1.recved}") - print(f"time:{r1.recved_time}") - print(f"\nn2->n1: {r2.recved}") - print(f"time:{r2.recved_time}") - - -bidir = (2, 0, 0, 1) -print("============================") -print("bidir w/o Ex:") -test(False, bidir) -print("---------------") -print("bidir w/ Ex:") -test(True, bidir) - -reliable = (0, 0.5, 1, 0) -print("============================") -print("reliable w/o Ex:") -test(False, reliable) -print("---------------") -print("reliable w/ Ex:") -test(True, reliable) + print(f"\nn1->n2: {r1.recved}, time: {r1.recved_time}") + print(f"n2->n1: {r2.recved}, time: {r2.recved_time}") + + +def test_bidir_without_ex(): + print("\n--- bidir w/o Ex ---") + _run_sim(False, (2, 0, 0, 1)) + +def test_bidir_with_ex(): + print("\n--- bidir w/ Ex ---") + _run_sim(True, (2, 0, 0, 1)) + +def test_reliable_without_ex(): + print("\n--- reliable w/o Ex ---") + _run_sim(False, (0, 0.5, 1, 0)) + +def test_reliable_with_ex(): + print("\n--- reliable w/ Ex ---") + _run_sim(True, (0, 0.5, 1, 0)) + + +test_bidir_without_ex() +test_bidir_with_ex() +test_reliable_without_ex() +test_reliable_with_ex() \ No newline at end of file