diff options
Diffstat (limited to 'ouroboros/qos.py')
| -rw-r--r-- | ouroboros/qos.py | 78 |
1 files changed, 13 insertions, 65 deletions
diff --git a/ouroboros/qos.py b/ouroboros/qos.py index a43d87d..bb4ecc4 100644 --- a/ouroboros/qos.py +++ b/ouroboros/qos.py @@ -1,7 +1,7 @@ # -# Ouroboros - Copyright (C) 2016 - 2020 +# Ouroboros - Copyright (C) 2016 - 2026 # -# Python API for applications - QoS +# Python API for Ouroboros - QoS # # Dimitri Staessens <dimitri@ouroboros.rocks> # @@ -19,36 +19,35 @@ # Foundation, Inc., http://www.fsf.org/about/contact/. # -from _ouroboros_cffi import ffi -from math import modf -from typing import Optional - # Some constants MILLION = 1000 * 1000 BILLION = 1000 * 1000 * 1000 +DEFAULT_PEER_TIMEOUT = 120000 +UINT32_MAX = 0xFFFFFFFF + class QoSSpec: """ - delay: In ms, default 1000s + delay: In ms, default UINT32_MAX bandwidth: In bits / s, default 0 availability: Class of 9s, default 0 - loss: Packet loss in ppm, default MILLION - ber: Bit error rate, errors per billion bits. default BILLION + loss: Packet loss, default 1 + ber: Bit error rate, errors per billion bits, default 1 in_order: In-order delivery, enables FRCT, default 0 - max_gap: Maximum interruption in ms, default MILLION + max_gap: Maximum interruption in ms, default UINT32_MAX timeout: Peer timeout (ms), default 120000 (2 minutes) """ def __init__(self, - delay: int = MILLION, + delay: int = UINT32_MAX, bandwidth: int = 0, availability: int = 0, loss: int = 1, - ber: int = MILLION, + ber: int = 1, in_order: int = 0, - max_gap: int = MILLION, - timeout: int = 120000): + max_gap: int = UINT32_MAX, + timeout: int = DEFAULT_PEER_TIMEOUT): self.delay = delay self.bandwidth = bandwidth self.availability = availability @@ -57,54 +56,3 @@ class QoSSpec: self.in_order = in_order self.max_gap = max_gap self.timeout = timeout - - -def _fl_to_timespec(timeo: float): - if timeo is None: - return ffi.NULL - elif timeo <= 0: - return ffi.new("struct timespec *", [0, 0]) - else: - frac, whole = modf(timeo) - _timeo = ffi.new("struct timespec *") - _timeo.tv_sec = whole - _timeo.tv_nsec = frac * BILLION - return _timeo - - -def _timespec_to_fl(_timeo) -> Optional[float]: - if _timeo is ffi.NULL: - return None - elif _timeo.tv_sec <= 0 and _timeo.tv_nsec == 0: - return 0 - else: - return _timeo.tv_sec + _timeo.tv_nsec / BILLION - - -def _qos_to_qosspec(qos: QoSSpec): - if qos is None: - return ffi.NULL - else: - return ffi.new("qosspec_t *", - [qos.delay, - qos.bandwidth, - qos.availability, - qos.loss, - qos.ber, - qos.in_order, - qos.max_gap, - qos.timeout]) - - -def _qosspec_to_qos(_qos) -> Optional[QoSSpec]: - if _qos is ffi.NULL: - return None - else: - return QoSSpec(delay=_qos.delay, - bandwidth=_qos.bandwidth, - availability=_qos.availability, - loss=_qos.loss, - ber=_qos.ber, - in_order=_qos.in_order, - max_gap=_qos.max_gap, - timeout=_qos.timeout) |
