Skip to content

Commit

Permalink
Merge pull request #45 from xenanetworks/fix-bugs
Browse files Browse the repository at this point in the history
Fix bugs
  • Loading branch information
Leonard Yu authored Jul 10, 2023
2 parents eb39b1c + a1bcabf commit 3554d65
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
6 changes: 5 additions & 1 deletion plugin2544/plugin/arp_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ..utils.packet import Ether, IPV4Packet, IPV6Packet
from ..utils.traffic_definitions import EtherType
from ..utils.constants import DELAY_LEARNING_ARP
from ..utils.exceptions import ARPRequestError


if TYPE_CHECKING:
Expand Down Expand Up @@ -92,7 +93,10 @@ async def send_arp_request(
stream.enable.set(enums.OnOffWithSuppress.ON),
)
await asyncio.sleep(DELAY_LEARNING_ARP)
result, *_ = await utils.apply(stream.request.arp.get())
try:
result, *_ = await utils.apply(stream.request.arp.get())
except:
raise ARPRequestError()
peer_mac_address = MacAddress(result.mac_address)
await stream.delete()
return peer_mac_address
6 changes: 4 additions & 2 deletions plugin2544/plugin/tc_back_to_back.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(
self._port_should_continue: bool = True
self._port_test_passed: bool = False
self._port_struct.clear_counter()
self._is_less_than_resolution = False

@property
def port_should_continue(self) -> bool:
Expand All @@ -46,7 +47,7 @@ def update_boundaries(self, result: Optional["FinalStatistic"]) -> None:
else:
self.update_right_bound()
if self.compare_search_pointer():
if no_frame_loss:
if not self._is_less_than_resolution and no_frame_loss:
self._port_test_passed = True
else:
self._port_test_passed = False
Expand All @@ -71,7 +72,8 @@ def update_right_bound(self) -> None:
def compare_search_pointer(self) -> bool:
res = self._test_type_conf.burst_resolution
# logger.debug(f"{self.next} - {self.current}")
if abs(self.next - self.current) > res: # End Searching
self._is_less_than_resolution = abs(self.next - self.current) <= res
if not self._is_less_than_resolution:
# logger.debug('Continue Searching')
return False
# End Searching
Expand Down
26 changes: 15 additions & 11 deletions plugin2544/plugin/tc_throughput.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from .structure import PortStruct
from .test_type_config import ThroughputConfig

from loguru import logger

class ThroughputBoutEntry:
def __init__(self, throughput_conf: "ThroughputConfig", port_struct: "PortStruct"):
Expand All @@ -18,6 +18,8 @@ def __init__(self, throughput_conf: "ThroughputConfig", port_struct: "PortStruct
self.best_final_result: Optional[FinalStatistic] = None
self._port_test_passed = False
self._port_should_continue = True
self._is_less_than_resolution = False


@property
def port_should_continue(self) -> bool:
Expand All @@ -30,23 +32,21 @@ def port_test_passed(self) -> bool:
def update_left_bound(self):
self.left_bound = self.current
self._last_move = -1
if (
abs((self.left_bound + self.right_bound) / 2 - self.left_bound)
< self._throughput_conf.value_resolution_pct
):
# logger.debug(f"{self.left_bound} {self.right_bound} -> {abs((self.left_bound + self.right_bound) / 2 - self.right_bound)}")
self._is_less_than_resolution = abs((self.left_bound + self.right_bound) / 2 - self.left_bound) < self._throughput_conf.value_resolution_pct
if self._is_less_than_resolution:
self.next = self.right_bound
self.left_bound = self.right_bound
else:
self.next = (self.left_bound + self.right_bound) / 2
# logger.debug(f"update left bound -> {self.left_bound}")

def update_right_bound(self, loss_ratio: float):
self.right_bound = self.current
self._last_move = 1

if (
abs((self.left_bound + self.right_bound) / 2 - self.right_bound)
< self._throughput_conf.value_resolution_pct
):
self._is_less_than_resolution = abs((self.left_bound + self.right_bound) / 2 - self.right_bound) < self._throughput_conf.value_resolution_pct
# logger.debug(f"{self.left_bound} {self.right_bound} -> {abs((self.left_bound + self.right_bound) / 2 - self.right_bound)}")
if self._is_less_than_resolution:
self.next = self.left_bound
self.right_bound = self.left_bound
if self._throughput_conf.search_type.is_fast:
Expand All @@ -56,6 +56,7 @@ def update_right_bound(self, loss_ratio: float):
)
else:
self.next = (self.left_bound + self.right_bound) / 2
# logger.debug(f"update right bound -> {self.right_bound}")

def compare_search_pointer(self) -> bool:
return self.next == self.current
Expand All @@ -70,6 +71,7 @@ def pass_threshold(self) -> bool:
def update_rate(self):
self.current = self.next
self.rate_percent = self.next
# logger.debug(f"running rate: {self.current}")

def update_boundary(self, result: Optional["FinalStatistic"]) -> None:
self._port_should_continue = self._port_test_passed = False
Expand All @@ -81,6 +83,7 @@ def update_boundary(self, result: Optional["FinalStatistic"]) -> None:
else:
loss_ratio = result.total.rx_loss_percent
loss_ratio_pct = loss_ratio * 100.0
# logger.debug(f"{loss_ratio_pct} - {self._throughput_conf.acceptable_loss_pct}")
if loss_ratio_pct <= self._throughput_conf.acceptable_loss_pct:
if self._throughput_conf.is_per_source_port:
for stream in self._port_struct.stream_structs:
Expand All @@ -92,8 +95,9 @@ def update_boundary(self, result: Optional["FinalStatistic"]) -> None:
self.update_left_bound()
else:
self.update_right_bound(loss_ratio)
# logger.debug(f"next: {self.next}")
if self.compare_search_pointer():
self._port_test_passed = self.pass_threshold()
self._port_test_passed = not self._is_less_than_resolution and self.pass_threshold()
else:
self._port_should_continue = True

Expand Down
2 changes: 1 addition & 1 deletion plugin2544/plugin/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ async def set_gap_monitor(
port_struct.set_gap_monitor(
gap_monitor_start_microsec, gap_monitor_stop_frames
)
for port_struct in self.tx_ports
for port_struct in self.rx_ports
]
)

Expand Down
9 changes: 9 additions & 0 deletions plugin2544/utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,12 @@ class PSPMissing(Exception):
def __init__(self) -> None:
self.msg = f"Protocol Segment Profile selected is missing."
super().__init__(self.msg)


class ARPRequestError(Exception):
def __init__(self) -> None:
self.msg = f"Test aborted: ARP Failure - Unable to resolve all gateway MAC addresses."
super().__init__(self.msg)



0 comments on commit 3554d65

Please sign in to comment.