lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

April 2025

  • 1 participants
  • 1186 discussions
[XS] Change in osmocom-bb[master]: trx_toolkit: Bring FakeTRX and Transceiver .handle_data_msg signature...
by kirr 17 Apr '25

17 Apr '25
kirr has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/40067?usp=email ) Change subject: trx_toolkit: Bring FakeTRX and Transceiver .handle_data_msg signatures in sync ...................................................................... trx_toolkit: Bring FakeTRX and Transceiver .handle_data_msg signatures in sync Currently .handle_data_msg has the following signature in those classes: FakeTRX.handle_data_msg(self, src_trx, src_msg, msg) Transceiver.handle_data_msg(self, msg) It works in Python but when we will switch both FakeTRX and Transceiver to cdef class Cython will complain about that. -> Bring .handle_data_msg signature to be the same for both those classes. Change-Id: Ic4a642b2e78a1c87450d0d866eb7e6511193b0d5 --- M src/target/trx_toolkit/_fake_trx.pyx M src/target/trx_toolkit/transceiver.pxd M src/target/trx_toolkit/transceiver.pyx 3 files changed, 7 insertions(+), 2 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/67/40067/1 diff --git a/src/target/trx_toolkit/_fake_trx.pyx b/src/target/trx_toolkit/_fake_trx.pyx index 8135913..e49d056 100644 --- a/src/target/trx_toolkit/_fake_trx.pyx +++ b/src/target/trx_toolkit/_fake_trx.pyx @@ -244,7 +244,7 @@ if src_trx.ta != 0: msg.toa256 -= src_trx.ta * 256 - Transceiver.handle_data_msg(self, msg) + Transceiver.send_data_msg(self, msg) # Simulation specific CTRL command handler def ctrl_cmd_handler(self, request): diff --git a/src/target/trx_toolkit/transceiver.pxd b/src/target/trx_toolkit/transceiver.pxd index 5fd6bc6..b76fa24 100644 --- a/src/target/trx_toolkit/transceiver.pxd +++ b/src/target/trx_toolkit/transceiver.pxd @@ -48,4 +48,6 @@ cpdef get_tx_freq(self, fn) cdef recv_data_msg(self) + cdef send_data_msg(self, msg) + cpdef handle_data_msg(self, Transceiver src_trx, src_msg, msg) cdef clck_tick(self, BurstForwarder fwd, fn) diff --git a/src/target/trx_toolkit/transceiver.pyx b/src/target/trx_toolkit/transceiver.pyx index cf67879..8f8c9c6 100644 --- a/src/target/trx_toolkit/transceiver.pyx +++ b/src/target/trx_toolkit/transceiver.pyx @@ -290,10 +290,13 @@ self._tx_queue.append(msg) return msg - def handle_data_msg(self, msg): + cdef send_data_msg(self, msg): # TODO: make legacy mode configurable (via argv?) self.data_if.send_msg(msg, legacy = True) + cpdef handle_data_msg(self, Transceiver src_trx, src_msg, msg): + self.send_data_msg(msg) + cdef clck_tick(self, BurstForwarder fwd, fn): if not self.running: return -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/40067?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: Ic4a642b2e78a1c87450d0d866eb7e6511193b0d5 Gerrit-Change-Number: 40067 Gerrit-PatchSet: 1 Gerrit-Owner: kirr <kirr(a)nexedi.com> Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-CC: osmith <osmith(a)sysmocom.de> Gerrit-CC: pespin <pespin(a)sysmocom.de>
1 0
0 0
[M] Change in osmocom-bb[master]: trx_toolkit/transceiver: Switch Transceiver to cdef class
by kirr 17 Apr '25

17 Apr '25
kirr has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/40066?usp=email ) Change subject: trx_toolkit/transceiver: Switch Transceiver to cdef class ...................................................................... trx_toolkit/transceiver: Switch Transceiver to cdef class - Put fields into the object struct; fields are now accessed directly via that C-level struct instead of via __dict__ lookup - cimport instead of import Transceiver at the users - switch to invoke several Transceiver function via C-level where appropriate. Add type annotations to trx variables correspondingly. Change-Id: Ic7039451136b04dacfaf839b21f11b300f579603 --- M src/target/trx_toolkit/_fake_trx.pyx M src/target/trx_toolkit/burst_fwd.pxd M src/target/trx_toolkit/burst_fwd.pyx A src/target/trx_toolkit/transceiver.pxd M src/target/trx_toolkit/transceiver.pyx 5 files changed, 76 insertions(+), 22 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/66/40066/1 diff --git a/src/target/trx_toolkit/_fake_trx.pyx b/src/target/trx_toolkit/_fake_trx.pyx index 102a8d1..8135913 100644 --- a/src/target/trx_toolkit/_fake_trx.pyx +++ b/src/target/trx_toolkit/_fake_trx.pyx @@ -23,7 +23,7 @@ from burst_fwd cimport BurstForwarder from _clck_gen cimport CLCKGen -from transceiver import Transceiver +from transceiver cimport Transceiver from data_msg import Modulation from udp_link cimport _raise_oserr from gsm_shared import * @@ -204,7 +204,7 @@ # Takes (partially initialized) TRXD Rx message, # simulates RF path parameters (such as RSSI), # and sends towards the L1 - def handle_data_msg(self, src_trx, src_msg, msg): + def handle_data_msg(self, Transceiver src_trx, src_msg, msg): if self.rf_muted: msg.nope_ind = True elif not msg.nope_ind: @@ -415,6 +415,7 @@ # This method will be called by the clock generator def clck_handler(self, fn): + cdef Transceiver trx # We assume that this list is immutable at run-time for trx in self.trx_list: trx.clck_tick(self.burst_fwd, fn) @@ -428,6 +429,7 @@ ee = _heventdef(_Handler(_RxTimer, None)) xepoll_ctl(epoll_fd, EPOLL_CTL_ADD, self.clck_gen._timerfd, &ee) + cdef Transceiver trx for trx in self.trx_list: ee = _heventdef(_Handler(_RxTRXCtrl, trx)) xepoll_ctl(epoll_fd, EPOLL_CTL_ADD, trx.ctrl_if.sock.fileno(), &ee) @@ -482,9 +484,9 @@ # _Handler represents how POLLIN event on an fd should be handled. cdef class _Handler: cdef _HandlerKind kind - cdef object trx # Tranceiver | None + cdef Transceiver trx # | None - def __cinit__(self, _HandlerKind kind, trx): + def __cinit__(self, _HandlerKind kind, Transceiver trx): self.kind = kind self.trx = trx _hkeepalive.append(self) # so that _heventdef works without special care diff --git a/src/target/trx_toolkit/burst_fwd.pxd b/src/target/trx_toolkit/burst_fwd.pxd index eb3d60b..43b788c 100644 --- a/src/target/trx_toolkit/burst_fwd.pxd +++ b/src/target/trx_toolkit/burst_fwd.pxd @@ -1,6 +1,8 @@ # cython: language_level=3 -cdef class BurstForwarder: - cdef list trx_list # [] of Transceiver +from transceiver cimport Transceiver - cdef forward_msg(self, src_trx, rx_msg) +cdef class BurstForwarder: + cdef list[Transceiver] trx_list + + cdef forward_msg(self, Transceiver src_trx, rx_msg) diff --git a/src/target/trx_toolkit/burst_fwd.pyx b/src/target/trx_toolkit/burst_fwd.pyx index 2c63187..4c8a0ef 100644 --- a/src/target/trx_toolkit/burst_fwd.pyx +++ b/src/target/trx_toolkit/burst_fwd.pyx @@ -43,7 +43,7 @@ def __cinit__(self, list trx_list): self.trx_list = trx_list - cdef forward_msg(self, src_trx, rx_msg): + cdef forward_msg(self, Transceiver src_trx, rx_msg): # Originating Transceiver may use frequency hopping, # so let's precalculate its Tx frequency in advance tx_freq = src_trx.get_tx_freq(rx_msg.fn) @@ -52,6 +52,7 @@ rx_msg.burst = None # burst bits are omited # Iterate over all known transceivers + cdef Transceiver trx for trx in self.trx_list: if trx is src_trx: continue diff --git a/src/target/trx_toolkit/transceiver.pxd b/src/target/trx_toolkit/transceiver.pxd new file mode 100644 index 0000000..5fd6bc6 --- /dev/null +++ b/src/target/trx_toolkit/transceiver.pxd @@ -0,0 +1,51 @@ +# cython: language_level=3 + +from data_if cimport DATAInterface +from burst_fwd cimport BurstForwarder +from _clck_gen cimport CLCKGen + + +cdef class Transceiver: + cdef public: + # Connection info + str remote_addr + str bind_addr + int base_port + int child_idx + bint child_mgt + + object name # str | None + + # CLCKGen we are running under + CLCKGen clck_gen # | None + + # List of child transceivers + object child_trx_list # TRXList + + # Actual RX / TX frequencies + object _rx_freq # None if unset + object _tx_freq # None if unset + + bint rf_muted + + # Optional Power Measurement interface + object pwr_meas # FakePM | None + + # Frequency hopping parameters (set by CTRL) + object fh # HoppingParams | None + + # Internal state + bint running + + DATAInterface data_if + object ctrl_if # CTRLInterfaceTRX + object clck_if # UDPLink + + list _tx_queue # [] of TxMsg + + + cdef get_rx_freq(self, fn) + cpdef get_tx_freq(self, fn) + + cdef recv_data_msg(self) + cdef clck_tick(self, BurstForwarder fwd, fn) diff --git a/src/target/trx_toolkit/transceiver.pyx b/src/target/trx_toolkit/transceiver.pyx index 2918d54..cf67879 100644 --- a/src/target/trx_toolkit/transceiver.pyx +++ b/src/target/trx_toolkit/transceiver.pyx @@ -22,14 +22,12 @@ import logging as log from ctrl_if_trx import CTRLInterfaceTRX -from data_if cimport DATAInterface -from burst_fwd cimport BurstForwarder from udp_link cimport UDPLink from trx_list import TRXList from gsm_shared import HoppingParams -class Transceiver: +cdef class Transceiver: """ Base transceiver implementation. Represents a single transceiver, that can be used as for the BTS side, @@ -144,6 +142,12 @@ """ + def __cinit__(self): + self._rx_freq = None + self._tx_freq = None + self.rf_muted = False + self.running = False + def __init__(self, bind_addr, remote_addr, base_port, **kwargs): # Connection info self.remote_addr = remote_addr @@ -181,13 +185,6 @@ # Optional Power Measurement interface self.pwr_meas = kwargs.get("pwr_meas", None) - # Internal state - self.running = False - - # Actual RX / TX frequencies - self._rx_freq = None - self._tx_freq = None - # Frequency hopping parameters (set by CTRL) self.fh = None @@ -216,7 +213,7 @@ return True - def get_rx_freq(self, fn): + cdef get_rx_freq(self, fn): if self.fh is None: return self._rx_freq @@ -224,7 +221,7 @@ (rx_freq, _) = self.fh.resolve(fn) return rx_freq - def get_tx_freq(self, fn): + cpdef get_tx_freq(self, fn): if self.fh is None: return self._tx_freq @@ -253,6 +250,7 @@ else: trx_list = [self] # Update self and optionally child transceivers + cdef Transceiver trx for trx in trx_list: trx.running = poweron if not poweron: @@ -276,7 +274,7 @@ log.info("Stopping clock generator") self.clck_gen.stop() - def recv_data_msg(self): + cdef recv_data_msg(self): # Read and parse data from socket msg = self.data_if.recv_tx_msg() if not msg: @@ -296,7 +294,7 @@ # TODO: make legacy mode configurable (via argv?) self.data_if.send_msg(msg, legacy = True) - def clck_tick(self, BurstForwarder fwd, fn): + cdef clck_tick(self, BurstForwarder fwd, fn): if not self.running: return -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/40066?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: Ic7039451136b04dacfaf839b21f11b300f579603 Gerrit-Change-Number: 40066 Gerrit-PatchSet: 1 Gerrit-Owner: kirr <kirr(a)nexedi.com> Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-CC: osmith <osmith(a)sysmocom.de> Gerrit-CC: pespin <pespin(a)sysmocom.de>
1 0
0 0
[S] Change in osmocom-bb[master]: trx_toolkit/data_if: Switch DATAInterface to cdef class
by kirr 17 Apr '25

17 Apr '25
kirr has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/40056?usp=email ) Change subject: trx_toolkit/data_if: Switch DATAInterface to cdef class ...................................................................... trx_toolkit/data_if: Switch DATAInterface to cdef class - Put fields into the object struct; fields are now accessed directly via that C-level struct instead of via __dict__ lookup - cimport instead of import DATAInterface at the users Change-Id: I7126dd1c2cb4583adee92e2db8786146236e3b13 --- A src/target/trx_toolkit/data_if.pxd M src/target/trx_toolkit/data_if.pyx M src/target/trx_toolkit/transceiver.pyx 3 files changed, 8 insertions(+), 3 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/56/40056/1 diff --git a/src/target/trx_toolkit/data_if.pxd b/src/target/trx_toolkit/data_if.pxd new file mode 100644 index 0000000..03a11c5 --- /dev/null +++ b/src/target/trx_toolkit/data_if.pxd @@ -0,0 +1,6 @@ +# cython: language_level=3 + +from udp_link cimport UDPLink + +cdef class DATAInterface(UDPLink): + cdef readonly int _hdr_ver diff --git a/src/target/trx_toolkit/data_if.pyx b/src/target/trx_toolkit/data_if.pyx index 8dcc4dc..5ae2bc1 100644 --- a/src/target/trx_toolkit/data_if.pyx +++ b/src/target/trx_toolkit/data_if.pyx @@ -20,10 +20,9 @@ import logging as log -from udp_link cimport UDPLink from data_msg import * -class DATAInterface(UDPLink): +cdef class DATAInterface(UDPLink): def __init__(self, *udp_link_args): # Default header version (legacy) self._hdr_ver = 0x00 diff --git a/src/target/trx_toolkit/transceiver.pyx b/src/target/trx_toolkit/transceiver.pyx index 519eb4b..a11a319 100644 --- a/src/target/trx_toolkit/transceiver.pyx +++ b/src/target/trx_toolkit/transceiver.pyx @@ -22,7 +22,7 @@ import logging as log from ctrl_if_trx import CTRLInterfaceTRX -from data_if import DATAInterface +from data_if cimport DATAInterface from udp_link cimport UDPLink from trx_list import TRXList -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/40056?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: I7126dd1c2cb4583adee92e2db8786146236e3b13 Gerrit-Change-Number: 40056 Gerrit-PatchSet: 1 Gerrit-Owner: kirr <kirr(a)nexedi.com> Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-CC: osmith <osmith(a)sysmocom.de> Gerrit-CC: pespin <pespin(a)sysmocom.de>
1 0
0 0
[S] Change in osmocom-bb[master]: trx_toolkit/*: Invoke UDPLink.send via C from data/clock plane
by kirr 17 Apr '25

17 Apr '25
kirr has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/40057?usp=email ) Change subject: trx_toolkit/*: Invoke UDPLink.send via C from data/clock plane ...................................................................... trx_toolkit/*: Invoke UDPLink.send via C from data/clock plane As can be seen from http://navytux.spb.ru/~kirr/osmo/fake_trx/pyx-base.html (DATAInterface_15send_msg) the system spends some time in py-overhead before reaching UDPLink.send -> Avoid that overhead via providing cdef UDPLink._send and use that from performance-sensitive places. Change-Id: I3774beebfd37e6b36d3d119ec19b0d3c2a88b10d --- M src/target/trx_toolkit/_clck_gen.pyx M src/target/trx_toolkit/data_if.pyx M src/target/trx_toolkit/udp_link.pxd M src/target/trx_toolkit/udp_link.pyx 4 files changed, 9 insertions(+), 2 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/57/40057/1 diff --git a/src/target/trx_toolkit/_clck_gen.pyx b/src/target/trx_toolkit/_clck_gen.pyx index 914b821..6eb5717 100644 --- a/src/target/trx_toolkit/_clck_gen.pyx +++ b/src/target/trx_toolkit/_clck_gen.pyx @@ -22,6 +22,7 @@ import os import sys +from udp_link cimport UDPLink from gsm_shared import * @@ -94,6 +95,8 @@ self.send_clck_ind() def send_clck_ind(self): + cdef UDPLink link + # We don't need to send so often if self.clck_src % self.ind_period == 0: # Create UDP payload @@ -101,7 +104,7 @@ # Send indication to all UDP links for link in self.clck_links: - link.send(payload) + link._send(payload) # Debug print log.debug(payload.rstrip("\0")) diff --git a/src/target/trx_toolkit/data_if.pyx b/src/target/trx_toolkit/data_if.pyx index 5ae2bc1..ca4d82d 100644 --- a/src/target/trx_toolkit/data_if.pyx +++ b/src/target/trx_toolkit/data_if.pyx @@ -111,4 +111,4 @@ return # Send message - self.send(payload) + self._send(payload) diff --git a/src/target/trx_toolkit/udp_link.pxd b/src/target/trx_toolkit/udp_link.pxd index d50fe5f..8698cab 100644 --- a/src/target/trx_toolkit/udp_link.pxd +++ b/src/target/trx_toolkit/udp_link.pxd @@ -17,5 +17,7 @@ cdef int sock_fd cdef sockaddr_in remote_addr + cdef _send(self, object data) # bytes|bytearray|str + cdef _raise_oserr() diff --git a/src/target/trx_toolkit/udp_link.pyx b/src/target/trx_toolkit/udp_link.pyx index d75e058..c54845b 100644 --- a/src/target/trx_toolkit/udp_link.pyx +++ b/src/target/trx_toolkit/udp_link.pyx @@ -66,6 +66,8 @@ return "L:%s <-> R:%s" % (self.desc_local(), self.desc_remote()) def send(self, data): + self._send(data) + cdef _send(self, object data): cdef const char *buf cdef Py_ssize_t buflen if type(data) is bytearray: -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/40057?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: I3774beebfd37e6b36d3d119ec19b0d3c2a88b10d Gerrit-Change-Number: 40057 Gerrit-PatchSet: 1 Gerrit-Owner: kirr <kirr(a)nexedi.com> Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-CC: osmith <osmith(a)sysmocom.de> Gerrit-CC: pespin <pespin(a)sysmocom.de>
1 0
0 0
[XS] Change in osmocom-bb[master]: trx_toolkit/data_if: No need to explicitly cast bytes to bytearray wh...
by kirr 17 Apr '25

17 Apr '25
kirr has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/40058?usp=email ) Change subject: trx_toolkit/data_if: No need to explicitly cast bytes to bytearray when doing RxMsg.parse_msg ...................................................................... trx_toolkit/data_if: No need to explicitly cast bytes to bytearray when doing RxMsg.parse_msg I already did similar change for TxMsg.parse_msg in 06456f11 (trx_toolkit/*: Try to avoid copying burst data where possible) but missed to do the symmetrical case for RxMsg. -> Do that. Change-Id: I54b8623a99b24da4ae1c4d379e9f45871f931554 --- M src/target/trx_toolkit/data_if.pyx 1 file changed, 1 insertion(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/58/40058/1 diff --git a/src/target/trx_toolkit/data_if.pyx b/src/target/trx_toolkit/data_if.pyx index ca4d82d..14b8808 100644 --- a/src/target/trx_toolkit/data_if.pyx +++ b/src/target/trx_toolkit/data_if.pyx @@ -87,7 +87,7 @@ # Attempt to parse a TRXD Rx message try: msg = RxMsg() - msg.parse_msg(bytearray(data)) + msg.parse_msg(data) except: log.error("Failed to parse a TRXD Rx message " "from R:%s" % self.desc_remote()) -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/40058?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: I54b8623a99b24da4ae1c4d379e9f45871f931554 Gerrit-Change-Number: 40058 Gerrit-PatchSet: 1 Gerrit-Owner: kirr <kirr(a)nexedi.com> Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-CC: osmith <osmith(a)sysmocom.de> Gerrit-CC: pespin <pespin(a)sysmocom.de>
1 0
0 0
[S] Change in osmocom-bb[master]: trx_toolkit/udp_link,data_if: Optimize socket receive
by kirr 17 Apr '25

17 Apr '25
kirr has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/40059?usp=email ) Change subject: trx_toolkit/udp_link,data_if: Optimize socket receive ...................................................................... trx_toolkit/udp_link,data_if: Optimize socket receive As can be seen from http://navytux.spb.ru/~kirr/osmo/fake_trx/pyx-base.html (recv_raw_data) the system is spending almost 2x time in wrapping py-overhead compared to actually doing recv syscall! As fake_trx invokes recv a lot of times it makes sense to cut that overhead. -> Do that: - add C-level UDPLink.recv which invokes recv syscall directly without doing any gil release/acquire and which constructs destination bytearray directly via py CAPI. - invoke that UDPLink via C and also invoke DATAInterface.recv_raw_data also via C because the only users of those functions are in DATAInterface. - we can be sure that returning bytearray instead of bytes is ok because those bytearrays are passed to Msg.parse_msg and it accepts bytearrays just fine. Using bytearrays instead of bytes will be convenient in the follow-up patches. Change-Id: I7e6c10071c31be5947f7c47d0ccbeee90dcb365b --- M src/target/trx_toolkit/data_if.pxd M src/target/trx_toolkit/data_if.pyx M src/target/trx_toolkit/udp_link.pxd M src/target/trx_toolkit/udp_link.pyx A src/target/trx_toolkit/xpy.pxd 5 files changed, 24 insertions(+), 3 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/59/40059/1 diff --git a/src/target/trx_toolkit/data_if.pxd b/src/target/trx_toolkit/data_if.pxd index 03a11c5..564a6cd 100644 --- a/src/target/trx_toolkit/data_if.pxd +++ b/src/target/trx_toolkit/data_if.pxd @@ -4,3 +4,5 @@ cdef class DATAInterface(UDPLink): cdef readonly int _hdr_ver + + cdef recv_raw_data(self) diff --git a/src/target/trx_toolkit/data_if.pyx b/src/target/trx_toolkit/data_if.pyx index 14b8808..d5e4910 100644 --- a/src/target/trx_toolkit/data_if.pyx +++ b/src/target/trx_toolkit/data_if.pyx @@ -56,9 +56,8 @@ msg.ver, self._hdr_ver)) return False - def recv_raw_data(self): - data, _ = self.sock.recvfrom(512) - return data + cdef recv_raw_data(self): + return self.recv(512) def recv_tx_msg(self): # Read raw data from socket diff --git a/src/target/trx_toolkit/udp_link.pxd b/src/target/trx_toolkit/udp_link.pxd index 8698cab..ba145ec 100644 --- a/src/target/trx_toolkit/udp_link.pxd +++ b/src/target/trx_toolkit/udp_link.pxd @@ -18,6 +18,7 @@ cdef sockaddr_in remote_addr cdef _send(self, object data) # bytes|bytearray|str + cdef bytearray recv(self, Py_ssize_t bufsize) cdef _raise_oserr() diff --git a/src/target/trx_toolkit/udp_link.pyx b/src/target/trx_toolkit/udp_link.pyx index c54845b..696f966 100644 --- a/src/target/trx_toolkit/udp_link.pyx +++ b/src/target/trx_toolkit/udp_link.pyx @@ -22,6 +22,7 @@ from cpython cimport PyBytes_AS_STRING, PyBytes_GET_SIZE, PyUnicode_AsUTF8AndSize from cpython.bytearray cimport PyByteArray_FromStringAndSize, PyByteArray_AS_STRING, PyByteArray_GET_SIZE +from xpy cimport PyByteArray_Resize from libc.errno cimport errno from libc.string cimport strerror @@ -33,6 +34,7 @@ cdef extern from "<sys/socket.h>": ssize_t sendto(int fd, const void *buf, size_t len, int flags, const sockaddr *dst_addr, int addrlen) + ssize_t recv(int fd, void *buf, size_t len, int flags) cdef class UDPLink: @@ -95,5 +97,18 @@ self.sock.sendto(data, remote) + cdef bytearray recv(self, Py_ssize_t bufsize): + buf = PyByteArray_FromStringAndSize(NULL, bufsize) + + # NOTE we do not release/reacquire gil to save us from gil ping-pong performance penalty + # we can do that because the socket is non-blocking + n = recv(self.sock_fd, PyByteArray_AS_STRING(buf), bufsize, 0) + if n == -1: + _raise_oserr() + if n != bufsize: + PyByteArray_Resize(buf, n) + return buf + + cdef _raise_oserr(): raise OSError(errno, strerror(errno)) diff --git a/src/target/trx_toolkit/xpy.pxd b/src/target/trx_toolkit/xpy.pxd new file mode 100644 index 0000000..3993dc7 --- /dev/null +++ b/src/target/trx_toolkit/xpy.pxd @@ -0,0 +1,4 @@ +cdef extern from "Python.h": + # PyByteArray_Resize is wrongly declared in cpython.bytearray + # https://github.com/cython/cython/pull/6787 + int PyByteArray_Resize(bytearray buf, Py_ssize_t len) except -1 -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/40059?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: I7e6c10071c31be5947f7c47d0ccbeee90dcb365b Gerrit-Change-Number: 40059 Gerrit-PatchSet: 1 Gerrit-Owner: kirr <kirr(a)nexedi.com> Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-CC: osmith <osmith(a)sysmocom.de> Gerrit-CC: pespin <pespin(a)sysmocom.de>
1 0
0 0
[XS] Change in osmocom-bb[master]: trx_toolkit/_fake_trx: Switch Runner to cdef class
by kirr 17 Apr '25

17 Apr '25
kirr has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/40060?usp=email ) Change subject: trx_toolkit/_fake_trx: Switch Runner to cdef class ...................................................................... trx_toolkit/_fake_trx: Switch Runner to cdef class - Put fields into the object struct; fields are now accessed directly via that C-level struct instead of via __dict__ lookup. Cannot properly type them though yet. This will be fixed in follow-up patches. - there are no pyx-level users of Runner so no need to change import -> cimport anywhere. Change-Id: I5c65c77f95de596b1aca62beaeb23d3cf5678996 --- M src/target/trx_toolkit/_fake_trx.pyx 1 file changed, 5 insertions(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/60/40060/1 diff --git a/src/target/trx_toolkit/_fake_trx.pyx b/src/target/trx_toolkit/_fake_trx.pyx index 92573f8..c17c16d 100644 --- a/src/target/trx_toolkit/_fake_trx.pyx +++ b/src/target/trx_toolkit/_fake_trx.pyx @@ -373,7 +373,11 @@ # Runner organizes execution of several FakeTRX instances with common clock. -class Runner: +cdef class Runner: + cdef object clck_gen # CLCKGen + cdef object burst_fwd # BurstForwarder + cdef list[Transceiver] trx_list + def __init__(self, clck_gen, trx_list): self.clck_gen = clck_gen self.trx_list = trx_list.trx_list -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/40060?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: I5c65c77f95de596b1aca62beaeb23d3cf5678996 Gerrit-Change-Number: 40060 Gerrit-PatchSet: 1 Gerrit-Owner: kirr <kirr(a)nexedi.com> Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-CC: osmith <osmith(a)sysmocom.de> Gerrit-CC: pespin <pespin(a)sysmocom.de>
1 0
0 0
[S] Change in osmocom-bb[master]: trx_toolkit/_clck_gen: Switch CLCKGen to cdef class
by kirr 17 Apr '25

17 Apr '25
kirr has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/40061?usp=email ) Change subject: trx_toolkit/_clck_gen: Switch CLCKGen to cdef class ...................................................................... trx_toolkit/_clck_gen: Switch CLCKGen to cdef class - Put fields into the object struct; fields are now accessed directly via that C-level struct instead of via __dict__ lookup - cimport instead of import CLCKGen at the users - switch to invoke CLCKGen.send_clck_ind via C-level as that function is used only by CLCKGen internally - switch globals to be also typed and looked up statically instead of from module __dict__. Change-Id: I2fb0219776b973c217348e34dab269aa804b2a04 --- A src/target/trx_toolkit/_clck_gen.pxd M src/target/trx_toolkit/_clck_gen.pyx M src/target/trx_toolkit/_fake_trx.pyx 3 files changed, 34 insertions(+), 7 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/61/40061/1 diff --git a/src/target/trx_toolkit/_clck_gen.pxd b/src/target/trx_toolkit/_clck_gen.pxd new file mode 100644 index 0000000..f4de595 --- /dev/null +++ b/src/target/trx_toolkit/_clck_gen.pxd @@ -0,0 +1,22 @@ +# cython: language_level=3 + +from libc.stdint cimport int64_t +from udp_link cimport UDPLink + + +cdef class CLCKGen: + cdef public: + list[UDPLink] clck_links + int64_t clck_start + int64_t ind_period + + double ctr_interval + int64_t clck_src + + object clck_handler + + cdef int _timerfd + cdef int _t_tick + + + cdef send_clck_ind(self) diff --git a/src/target/trx_toolkit/_clck_gen.pyx b/src/target/trx_toolkit/_clck_gen.pyx index 6eb5717..46e28c1 100644 --- a/src/target/trx_toolkit/_clck_gen.pyx +++ b/src/target/trx_toolkit/_clck_gen.pyx @@ -22,15 +22,19 @@ import os import sys -from udp_link cimport UDPLink -from gsm_shared import * +from cython cimport final -ns = 1e-9 -us = 1e-6 +import gsm_shared +cdef int GSM_HYPERFRAME = gsm_shared.GSM_HYPERFRAME -class CLCKGen: +cdef double ns = 1e-9 +cdef double us = 1e-6 + + +@final +cdef class CLCKGen: # GSM TDMA definitions SEC_DELAY_US = 1000 * 1000 GSM_FRAME_US = 4615.0 @@ -94,7 +98,7 @@ self.send_clck_ind() - def send_clck_ind(self): + cdef send_clck_ind(self): cdef UDPLink link # We don't need to send so often diff --git a/src/target/trx_toolkit/_fake_trx.pyx b/src/target/trx_toolkit/_fake_trx.pyx index c17c16d..8803b24 100644 --- a/src/target/trx_toolkit/_fake_trx.pyx +++ b/src/target/trx_toolkit/_fake_trx.pyx @@ -22,6 +22,7 @@ import select from burst_fwd import BurstForwarder +from _clck_gen cimport CLCKGen from transceiver import Transceiver from data_msg import Modulation from gsm_shared import * @@ -374,7 +375,7 @@ # Runner organizes execution of several FakeTRX instances with common clock. cdef class Runner: - cdef object clck_gen # CLCKGen + cdef CLCKGen clck_gen cdef object burst_fwd # BurstForwarder cdef list[Transceiver] trx_list -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/40061?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: I2fb0219776b973c217348e34dab269aa804b2a04 Gerrit-Change-Number: 40061 Gerrit-PatchSet: 1 Gerrit-Owner: kirr <kirr(a)nexedi.com> Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-CC: osmith <osmith(a)sysmocom.de> Gerrit-CC: pespin <pespin(a)sysmocom.de>
1 0
0 0
[M] Change in osmocom-bb[master]: trx_toolkit/fake_trx: Factor functionality to run IO loop out of Appl...
by kirr 17 Apr '25

17 Apr '25
kirr has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/40050?usp=email ) Change subject: trx_toolkit/fake_trx: Factor functionality to run IO loop out of Application ...................................................................... trx_toolkit/fake_trx: Factor functionality to run IO loop out of Application -> into Runner. We will need to move this functionality to pyx (Cython) domain soon, while Application will remain at py (Python) level. Preparatory refactoring step for that. Change-Id: I28613087f48c327763537b53b97cad1e67d91f1a --- M src/target/trx_toolkit/fake_trx.py 1 file changed, 47 insertions(+), 35 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/50/40050/1 diff --git a/src/target/trx_toolkit/fake_trx.py b/src/target/trx_toolkit/fake_trx.py index 12d5b77..9bf9efd 100755 --- a/src/target/trx_toolkit/fake_trx.py +++ b/src/target/trx_toolkit/fake_trx.py @@ -382,6 +382,51 @@ # Unhandled command return None + +# Runner organizes execution of several FakeTRX instances with common clock. +class Runner: + def __init__(self, clck_gen, trx_list): + self.clck_gen = clck_gen + self.trx_list = trx_list.trx_list + + # This method will be called on each TDMA frame + self.clck_gen.clck_handler = self.clck_handler + + self.burst_fwd = BurstForwarder(trx_list.trx_list) + + # This method will be called by the clock generator + def clck_handler(self, fn): + # We assume that this list is immutable at run-time + for trx in self.trx_list: + trx.clck_tick(self.burst_fwd, fn) + + # loops runs IO loop on specified CLCKGen and TRXes forever. + def loop(self): + sock_list = [self.clck_gen._timerfd] + for trx in self.trx_list: + sock_list.append(trx.ctrl_if.sock) + sock_list.append(trx.data_if.sock) + + # Enter main loop + while True: + # Wait until we get any data on any socket + r_event, _, _ = select.select(sock_list, [], []) + + # clock is priority + if self.clck_gen._timerfd in r_event: + self.clck_gen.tick() + + # Iterate over all transceivers + for trx in self.trx_list: + # DATA interface + if trx.data_if.sock in r_event: + trx.recv_data_msg() + + # CTRL interface + if trx.ctrl_if.sock in r_event: + trx.ctrl_if.handle_rx() + + class Application(ApplicationBase): def __init__(self): self.app_print_copyright(APP_CR_HOLDERS) @@ -398,8 +443,6 @@ # Init shared clock generator self.clck_gen = CLCKGen([]) - # This method will be called on each TDMA frame - self.clck_gen.clck_handler = self.clck_handler # Power measurement emulation # Noise: -120 .. -105 @@ -419,9 +462,6 @@ (name, addr, port, idx) = trx_def self.append_child_trx(addr, port, name = name, child_idx = idx) - # Burst forwarding between transceivers - self.burst_fwd = BurstForwarder(self.trx_list.trx_list) - log.info("Init complete") def append_trx(self, remote_addr, base_port, **kwargs): @@ -458,36 +498,8 @@ except OSError: log.error("Failed to set real time process scheduler to SCHED_RR, priority %u" % (self.argv.sched_rr_prio)) - # Compose list of to be monitored sockets - sock_list = [self.clck_gen._timerfd] - for trx in self.trx_list.trx_list: - sock_list.append(trx.ctrl_if.sock) - sock_list.append(trx.data_if.sock) - - # Enter main loop - while True: - # Wait until we get any data on any socket - r_event, _, _ = select.select(sock_list, [], []) - - # clock is priority - if self.clck_gen._timerfd in r_event: - self.clck_gen.tick() - - # Iterate over all transceivers - for trx in self.trx_list.trx_list: - # DATA interface - if trx.data_if.sock in r_event: - trx.recv_data_msg() - - # CTRL interface - if trx.ctrl_if.sock in r_event: - trx.ctrl_if.handle_rx() - - # This method will be called by the clock generator - def clck_handler(self, fn): - # We assume that this list is immutable at run-time - for trx in self.trx_list.trx_list: - trx.clck_tick(self.burst_fwd, fn) + runner = Runner(self.clck_gen, self.trx_list) + runner.loop() def shutdown(self): log.info("Shutting down...") -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/40050?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: I28613087f48c327763537b53b97cad1e67d91f1a Gerrit-Change-Number: 40050 Gerrit-PatchSet: 1 Gerrit-Owner: kirr <kirr(a)nexedi.com> Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-CC: osmith <osmith(a)sysmocom.de> Gerrit-CC: pespin <pespin(a)sysmocom.de>
1 0
0 0
[L] Change in osmocom-bb[master]: trx_toolkit/fake_trx: Split it into fake_trx and _fake_trx modules
by kirr 17 Apr '25

17 Apr '25
kirr has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/40051?usp=email ) Change subject: trx_toolkit/fake_trx: Split it into fake_trx and _fake_trx modules ...................................................................... trx_toolkit/fake_trx: Split it into fake_trx and _fake_trx modules fake_trx will remain at Python while _fake_trx will be later converted to Cython for speed to avoid py-related overhead. This patch does only plain code movement as a preparatory step for that. Change-Id: Iadffd49de8197564e57bfd9cb660b1d11136ffd4 --- A src/target/trx_toolkit/_fake_trx.py M src/target/trx_toolkit/fake_trx.py 2 files changed, 415 insertions(+), 395 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/51/40051/1 diff --git a/src/target/trx_toolkit/_fake_trx.py b/src/target/trx_toolkit/_fake_trx.py new file mode 100644 index 0000000..87a352b --- /dev/null +++ b/src/target/trx_toolkit/_fake_trx.py @@ -0,0 +1,414 @@ +# TRX Toolkit +# Virtual Um-interface (fake transceiver) +# +# (C) 2017-2019 by Vadim Yanitskiy <axilirator(a)gmail.com> +# +# All Rights Reserved +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +import logging as log +import random +import select + +from burst_fwd import BurstForwarder +from transceiver import Transceiver +from data_msg import Modulation +from gsm_shared import * + + +class FakeTRX(Transceiver): + """ Fake transceiver with RF path (burst loss, RSSI, TA, ToA) simulation. + + == ToA / RSSI measurement simulation + + Since this is a virtual environment, we can simulate different + parameters of the physical RF interface: + + - ToA (Timing of Arrival) - measured difference between expected + and actual time of burst arrival in units of 1/256 of GSM symbol + periods. A pair of both base and threshold values defines a range + of ToA value randomization: + + from (toa256_base - toa256_rand_threshold) + to (toa256_base + toa256_rand_threshold). + + - RSSI (Received Signal Strength Indication) - measured "power" of + the signal (per burst) in dBm. A pair of both base and threshold + values defines a range of RSSI value randomization: + + from (rssi_base - rssi_rand_threshold) + to (rssi_base + rssi_rand_threshold). + + - C/I (Carrier-to-Interference ratio) - value in cB (centiBels), + computed from the training sequence of each received burst, by + comparing the "ideal" training sequence with the actual one. + A pair of both base and threshold values defines a range of + C/I randomization: + + from (ci_base - ci_rand_threshold) + to (ci_base + ci_rand_threshold). + + Please note that the randomization is optional and disabled by default. + + == Timing Advance handling + + The BTS is using ToA measurements for UL bursts in order to calculate + Timing Advance value, that is then indicated to a MS, which in its turn + shall apply this value to the transmitted signal in order to compensate + the delay. Basically, every burst is transmitted in advance defined by + the indicated Timing Advance value. The valid range is 0..63, where + each unit means one GSM symbol advance. The actual Timing Advance value + is set using SETTA control command from MS. By default, it's set to 0. + + == Path loss simulation + + === Burst dropping + + In some cases, e.g. due to a weak signal or high interference, a burst + can be lost, i.e. not detected by the receiver. This can also be + simulated using FAKE_DROP command on the control interface: + + - burst_drop_amount - the amount of DL/UL bursts + to be dropped (i.e. not forwarded towards the MS/BTS), + + - burst_drop_period - drop a DL/UL burst if its (fn % period) == 0. + + == Configuration + + All simulation parameters mentioned above can be changed at runtime + using the commands with prefix 'FAKE_' on the control interface. + All of them are handled by our custom CTRL command handler. + + """ + + NOMINAL_TX_POWER_DEFAULT = 50 # dBm + TX_ATT_DEFAULT = 0 # dB + PATH_LOSS_DEFAULT = 110 # dB + + TOA256_BASE_DEFAULT = 0 + CI_BASE_DEFAULT = 90 + + # Default values for NOPE / IDLE indications + TOA256_NOISE_DEFAULT = 0 + RSSI_NOISE_DEFAULT = -110 + CI_NOISE_DEFAULT = -30 + + def __init__(self, *trx_args, **trx_kwargs): + Transceiver.__init__(self, *trx_args, **trx_kwargs) + + # fake RSSI is disabled by default, only enabled through TRXC FAKE_RSSI. + # When disabled, RSSI is calculated based on Tx power and Rx path loss + self.fake_rssi_enabled = False + + self.rf_muted = False + + # Actual ToA, RSSI, C/I, TA values + self.tx_power_base = self.NOMINAL_TX_POWER_DEFAULT + self.tx_att_base = self.TX_ATT_DEFAULT + self.toa256_base = self.TOA256_BASE_DEFAULT + self.rssi_base = self.NOMINAL_TX_POWER_DEFAULT - self.TX_ATT_DEFAULT - self.PATH_LOSS_DEFAULT + self.ci_base = self.CI_BASE_DEFAULT + self.ta = 0 + + # ToA, RSSI, C/I randomization thresholds + self.toa256_rand_threshold = 0 + self.rssi_rand_threshold = 0 + self.ci_rand_threshold = 0 + + # Path loss simulation (burst dropping) + self.burst_drop_amount = 0 + self.burst_drop_period = 1 + + @property + def toa256(self): + # Check if randomization is required + if self.toa256_rand_threshold == 0: + return self.toa256_base + + # Generate a random ToA value in required range + toa256_min = self.toa256_base - self.toa256_rand_threshold + toa256_max = self.toa256_base + self.toa256_rand_threshold + return random.randint(toa256_min, toa256_max) + + @property + def rssi(self): + # Check if randomization is required + if self.rssi_rand_threshold == 0: + return self.rssi_base + + # Generate a random RSSI value in required range + rssi_min = self.rssi_base - self.rssi_rand_threshold + rssi_max = self.rssi_base + self.rssi_rand_threshold + return random.randint(rssi_min, rssi_max) + + @property + def tx_power(self): + return self.tx_power_base - self.tx_att_base + + @property + def ci(self): + # Check if randomization is required + if self.ci_rand_threshold == 0: + return self.ci_base + + # Generate a random C/I value in required range + ci_min = self.ci_base - self.ci_rand_threshold + ci_max = self.ci_base + self.ci_rand_threshold + return random.randint(ci_min, ci_max) + + # Path loss simulation: burst dropping + # Returns: True - drop, False - keep + def sim_burst_drop(self, msg): + # Check if dropping is required + if self.burst_drop_amount == 0: + return False + + if msg.fn % self.burst_drop_period == 0: + log.info("(%s) Simulation: dropping burst (fn=%u %% %u == 0)" + % (self, msg.fn, self.burst_drop_period)) + self.burst_drop_amount -= 1 + return True + + return False + + def _handle_data_msg_v1(self, src_msg, msg): + # C/I (Carrier-to-Interference ratio) + msg.ci = self.ci + + # Pick modulation type by burst length + bl = len(src_msg.burst) + msg.mod_type = Modulation.pick_by_bl(bl) + + # Pick TSC (Training Sequence Code) and TSC set + if msg.mod_type is Modulation.ModGMSK: + ss = TrainingSeqGMSK.pick(src_msg.burst) + msg.tsc = ss.tsc if ss is not None else 0 + msg.tsc_set = ss.tsc_set if ss is not None else 0 + else: # TODO: other modulation types (at least 8-PSK) + msg.tsc_set = 0 + msg.tsc = 0 + + # Takes (partially initialized) TRXD Rx message, + # simulates RF path parameters (such as RSSI), + # and sends towards the L1 + def handle_data_msg(self, src_trx, src_msg, msg): + if self.rf_muted: + msg.nope_ind = True + elif not msg.nope_ind: + # Path loss simulation + msg.nope_ind = self.sim_burst_drop(msg) + if msg.nope_ind: + # Before TRXDv1, we simply drop the message + if msg.ver < 0x01: + del msg + return + + # Since TRXDv1, we should send a NOPE.ind + msg.burst = None # burst bits are omited + + # TODO: shoud we make these values configurable? + msg.toa256 = self.TOA256_NOISE_DEFAULT + msg.rssi = self.RSSI_NOISE_DEFAULT + msg.ci = self.CI_NOISE_DEFAULT + + self.data_if.send_msg(msg) + return + + # Complete message header + msg.toa256 = self.toa256 + + # Apply RSSI based on transmitter: + if not self.fake_rssi_enabled: + msg.rssi = src_trx.tx_power - src_msg.pwr - self.PATH_LOSS_DEFAULT + else: # Apply fake RSSI + msg.rssi = self.rssi + + # Version specific fields + if msg.ver >= 0x01: + self._handle_data_msg_v1(src_msg, msg) + + # Apply optional Timing Advance + if src_trx.ta != 0: + msg.toa256 -= src_trx.ta * 256 + + Transceiver.handle_data_msg(self, msg) + + # Simulation specific CTRL command handler + def ctrl_cmd_handler(self, request): + # Timing Advance + # Syntax: CMD SETTA <TA> + if self.ctrl_if.verify_cmd(request, "SETTA", 1): + log.debug("(%s) Recv SETTA cmd" % self) + + # Store indicated value + self.ta = int(request[1]) + return 0 + + # Timing of Arrival simulation + # Absolute form: CMD FAKE_TOA <BASE> <THRESH> + elif self.ctrl_if.verify_cmd(request, "FAKE_TOA", 2): + log.debug("(%s) Recv FAKE_TOA cmd" % self) + + # Parse and apply both base and threshold + self.toa256_base = int(request[1]) + self.toa256_rand_threshold = int(request[2]) + return 0 + + # Timing of Arrival simulation + # Relative form: CMD FAKE_TOA <+-BASE_DELTA> + elif self.ctrl_if.verify_cmd(request, "FAKE_TOA", 1): + log.debug("(%s) Recv FAKE_TOA cmd" % self) + + # Parse and apply delta + self.toa256_base += int(request[1]) + return 0 + + # RSSI simulation + # Absolute form: CMD FAKE_RSSI <BASE> <THRESH> + elif self.ctrl_if.verify_cmd(request, "FAKE_RSSI", 2): + log.debug("(%s) Recv FAKE_RSSI cmd" % self) + + # Use negative threshold to disable fake_rssi if previously enabled: + if int(request[2]) < 0: + self.fake_rssi_enabled = False + return 0 + + # Parse and apply both base and threshold + self.rssi_base = int(request[1]) + self.rssi_rand_threshold = int(request[2]) + self.fake_rssi_enabled = True + return 0 + + # RSSI simulation + # Relative form: CMD FAKE_RSSI <+-BASE_DELTA> + elif self.ctrl_if.verify_cmd(request, "FAKE_RSSI", 1): + log.debug("(%s) Recv FAKE_RSSI cmd" % self) + + # Parse and apply delta + self.rssi_base += int(request[1]) + return 0 + + # C/I simulation + # Absolute form: CMD FAKE_CI <BASE> <THRESH> + elif self.ctrl_if.verify_cmd(request, "FAKE_CI", 2): + log.debug("(%s) Recv FAKE_CI cmd" % self) + + # Parse and apply both base and threshold + self.ci_base = int(request[1]) + self.ci_rand_threshold = int(request[2]) + return 0 + + # C/I simulation + # Relative form: CMD FAKE_CI <+-BASE_DELTA> + elif self.ctrl_if.verify_cmd(request, "FAKE_CI", 1): + log.debug("(%s) Recv FAKE_CI cmd" % self) + + # Parse and apply delta + self.ci_base += int(request[1]) + return 0 + + # Path loss simulation: burst dropping + # Syntax: CMD FAKE_DROP <AMOUNT> + # Dropping pattern: fn % 1 == 0 + elif self.ctrl_if.verify_cmd(request, "FAKE_DROP", 1): + log.debug("(%s) Recv FAKE_DROP cmd" % self) + + # Parse / validate amount of bursts + num = int(request[1]) + if num < 0: + log.error("(%s) FAKE_DROP amount shall not " + "be negative" % self) + return -1 + + self.burst_drop_amount = num + self.burst_drop_period = 1 + return 0 + + # Path loss simulation: burst dropping + # Syntax: CMD FAKE_DROP <AMOUNT> <FN_PERIOD> + # Dropping pattern: fn % period == 0 + elif self.ctrl_if.verify_cmd(request, "FAKE_DROP", 2): + log.debug("(%s) Recv FAKE_DROP cmd" % self) + + # Parse / validate amount of bursts + num = int(request[1]) + if num < 0: + log.error("(%s) FAKE_DROP amount shall not " + "be negative" % self) + return -1 + + # Parse / validate period + period = int(request[2]) + if period <= 0: + log.error("(%s) FAKE_DROP period shall " + "be greater than zero" % self) + return -1 + + self.burst_drop_amount = num + self.burst_drop_period = period + return 0 + + # Artificial delay for the TRXC interface + # Syntax: CMD FAKE_TRXC_DELAY <DELAY_MS> + elif self.ctrl_if.verify_cmd(request, "FAKE_TRXC_DELAY", 1): + log.debug("(%s) Recv FAKE_TRXC_DELAY cmd", self) + + self.ctrl_if.rsp_delay_ms = int(request[1]) + log.info("(%s) Artificial TRXC delay set to %d", + self, self.ctrl_if.rsp_delay_ms) + + # Unhandled command + return None + + +# Runner organizes execution of several FakeTRX instances with common clock. +class Runner: + def __init__(self, clck_gen, trx_list): + self.clck_gen = clck_gen + self.trx_list = trx_list.trx_list + + # This method will be called on each TDMA frame + self.clck_gen.clck_handler = self.clck_handler + + self.burst_fwd = BurstForwarder(trx_list.trx_list) + + # This method will be called by the clock generator + def clck_handler(self, fn): + # We assume that this list is immutable at run-time + for trx in self.trx_list: + trx.clck_tick(self.burst_fwd, fn) + + # loops runs IO loop on specified CLCKGen and TRXes forever. + def loop(self): + sock_list = [self.clck_gen._timerfd] + for trx in self.trx_list: + sock_list.append(trx.ctrl_if.sock) + sock_list.append(trx.data_if.sock) + + # Enter main loop + while True: + # Wait until we get any data on any socket + r_event, _, _ = select.select(sock_list, [], []) + + # clock is priority + if self.clck_gen._timerfd in r_event: + self.clck_gen.tick() + + # Iterate over all transceivers + for trx in self.trx_list: + # DATA interface + if trx.data_if.sock in r_event: + trx.recv_data_msg() + + # CTRL interface + if trx.ctrl_if.sock in r_event: + trx.ctrl_if.handle_rx() diff --git a/src/target/trx_toolkit/fake_trx.py b/src/target/trx_toolkit/fake_trx.py index 9bf9efd..e72a52b 100755 --- a/src/target/trx_toolkit/fake_trx.py +++ b/src/target/trx_toolkit/fake_trx.py @@ -23,409 +23,15 @@ import logging as log import signal import argparse -import random -import select import sys import re import os from app_common import ApplicationBase -from burst_fwd import BurstForwarder -from transceiver import Transceiver -from data_msg import Modulation from clck_gen import CLCKGen from trx_list import TRXList from fake_pm import FakePM -from gsm_shared import * - -class FakeTRX(Transceiver): - """ Fake transceiver with RF path (burst loss, RSSI, TA, ToA) simulation. - - == ToA / RSSI measurement simulation - - Since this is a virtual environment, we can simulate different - parameters of the physical RF interface: - - - ToA (Timing of Arrival) - measured difference between expected - and actual time of burst arrival in units of 1/256 of GSM symbol - periods. A pair of both base and threshold values defines a range - of ToA value randomization: - - from (toa256_base - toa256_rand_threshold) - to (toa256_base + toa256_rand_threshold). - - - RSSI (Received Signal Strength Indication) - measured "power" of - the signal (per burst) in dBm. A pair of both base and threshold - values defines a range of RSSI value randomization: - - from (rssi_base - rssi_rand_threshold) - to (rssi_base + rssi_rand_threshold). - - - C/I (Carrier-to-Interference ratio) - value in cB (centiBels), - computed from the training sequence of each received burst, by - comparing the "ideal" training sequence with the actual one. - A pair of both base and threshold values defines a range of - C/I randomization: - - from (ci_base - ci_rand_threshold) - to (ci_base + ci_rand_threshold). - - Please note that the randomization is optional and disabled by default. - - == Timing Advance handling - - The BTS is using ToA measurements for UL bursts in order to calculate - Timing Advance value, that is then indicated to a MS, which in its turn - shall apply this value to the transmitted signal in order to compensate - the delay. Basically, every burst is transmitted in advance defined by - the indicated Timing Advance value. The valid range is 0..63, where - each unit means one GSM symbol advance. The actual Timing Advance value - is set using SETTA control command from MS. By default, it's set to 0. - - == Path loss simulation - - === Burst dropping - - In some cases, e.g. due to a weak signal or high interference, a burst - can be lost, i.e. not detected by the receiver. This can also be - simulated using FAKE_DROP command on the control interface: - - - burst_drop_amount - the amount of DL/UL bursts - to be dropped (i.e. not forwarded towards the MS/BTS), - - - burst_drop_period - drop a DL/UL burst if its (fn % period) == 0. - - == Configuration - - All simulation parameters mentioned above can be changed at runtime - using the commands with prefix 'FAKE_' on the control interface. - All of them are handled by our custom CTRL command handler. - - """ - - NOMINAL_TX_POWER_DEFAULT = 50 # dBm - TX_ATT_DEFAULT = 0 # dB - PATH_LOSS_DEFAULT = 110 # dB - - TOA256_BASE_DEFAULT = 0 - CI_BASE_DEFAULT = 90 - - # Default values for NOPE / IDLE indications - TOA256_NOISE_DEFAULT = 0 - RSSI_NOISE_DEFAULT = -110 - CI_NOISE_DEFAULT = -30 - - def __init__(self, *trx_args, **trx_kwargs): - Transceiver.__init__(self, *trx_args, **trx_kwargs) - - # fake RSSI is disabled by default, only enabled through TRXC FAKE_RSSI. - # When disabled, RSSI is calculated based on Tx power and Rx path loss - self.fake_rssi_enabled = False - - self.rf_muted = False - - # Actual ToA, RSSI, C/I, TA values - self.tx_power_base = self.NOMINAL_TX_POWER_DEFAULT - self.tx_att_base = self.TX_ATT_DEFAULT - self.toa256_base = self.TOA256_BASE_DEFAULT - self.rssi_base = self.NOMINAL_TX_POWER_DEFAULT - self.TX_ATT_DEFAULT - self.PATH_LOSS_DEFAULT - self.ci_base = self.CI_BASE_DEFAULT - self.ta = 0 - - # ToA, RSSI, C/I randomization thresholds - self.toa256_rand_threshold = 0 - self.rssi_rand_threshold = 0 - self.ci_rand_threshold = 0 - - # Path loss simulation (burst dropping) - self.burst_drop_amount = 0 - self.burst_drop_period = 1 - - @property - def toa256(self): - # Check if randomization is required - if self.toa256_rand_threshold == 0: - return self.toa256_base - - # Generate a random ToA value in required range - toa256_min = self.toa256_base - self.toa256_rand_threshold - toa256_max = self.toa256_base + self.toa256_rand_threshold - return random.randint(toa256_min, toa256_max) - - @property - def rssi(self): - # Check if randomization is required - if self.rssi_rand_threshold == 0: - return self.rssi_base - - # Generate a random RSSI value in required range - rssi_min = self.rssi_base - self.rssi_rand_threshold - rssi_max = self.rssi_base + self.rssi_rand_threshold - return random.randint(rssi_min, rssi_max) - - @property - def tx_power(self): - return self.tx_power_base - self.tx_att_base - - @property - def ci(self): - # Check if randomization is required - if self.ci_rand_threshold == 0: - return self.ci_base - - # Generate a random C/I value in required range - ci_min = self.ci_base - self.ci_rand_threshold - ci_max = self.ci_base + self.ci_rand_threshold - return random.randint(ci_min, ci_max) - - # Path loss simulation: burst dropping - # Returns: True - drop, False - keep - def sim_burst_drop(self, msg): - # Check if dropping is required - if self.burst_drop_amount == 0: - return False - - if msg.fn % self.burst_drop_period == 0: - log.info("(%s) Simulation: dropping burst (fn=%u %% %u == 0)" - % (self, msg.fn, self.burst_drop_period)) - self.burst_drop_amount -= 1 - return True - - return False - - def _handle_data_msg_v1(self, src_msg, msg): - # C/I (Carrier-to-Interference ratio) - msg.ci = self.ci - - # Pick modulation type by burst length - bl = len(src_msg.burst) - msg.mod_type = Modulation.pick_by_bl(bl) - - # Pick TSC (Training Sequence Code) and TSC set - if msg.mod_type is Modulation.ModGMSK: - ss = TrainingSeqGMSK.pick(src_msg.burst) - msg.tsc = ss.tsc if ss is not None else 0 - msg.tsc_set = ss.tsc_set if ss is not None else 0 - else: # TODO: other modulation types (at least 8-PSK) - msg.tsc_set = 0 - msg.tsc = 0 - - # Takes (partially initialized) TRXD Rx message, - # simulates RF path parameters (such as RSSI), - # and sends towards the L1 - def handle_data_msg(self, src_trx, src_msg, msg): - if self.rf_muted: - msg.nope_ind = True - elif not msg.nope_ind: - # Path loss simulation - msg.nope_ind = self.sim_burst_drop(msg) - if msg.nope_ind: - # Before TRXDv1, we simply drop the message - if msg.ver < 0x01: - del msg - return - - # Since TRXDv1, we should send a NOPE.ind - msg.burst = None # burst bits are omited - - # TODO: shoud we make these values configurable? - msg.toa256 = self.TOA256_NOISE_DEFAULT - msg.rssi = self.RSSI_NOISE_DEFAULT - msg.ci = self.CI_NOISE_DEFAULT - - self.data_if.send_msg(msg) - return - - # Complete message header - msg.toa256 = self.toa256 - - # Apply RSSI based on transmitter: - if not self.fake_rssi_enabled: - msg.rssi = src_trx.tx_power - src_msg.pwr - self.PATH_LOSS_DEFAULT - else: # Apply fake RSSI - msg.rssi = self.rssi - - # Version specific fields - if msg.ver >= 0x01: - self._handle_data_msg_v1(src_msg, msg) - - # Apply optional Timing Advance - if src_trx.ta != 0: - msg.toa256 -= src_trx.ta * 256 - - Transceiver.handle_data_msg(self, msg) - - # Simulation specific CTRL command handler - def ctrl_cmd_handler(self, request): - # Timing Advance - # Syntax: CMD SETTA <TA> - if self.ctrl_if.verify_cmd(request, "SETTA", 1): - log.debug("(%s) Recv SETTA cmd" % self) - - # Store indicated value - self.ta = int(request[1]) - return 0 - - # Timing of Arrival simulation - # Absolute form: CMD FAKE_TOA <BASE> <THRESH> - elif self.ctrl_if.verify_cmd(request, "FAKE_TOA", 2): - log.debug("(%s) Recv FAKE_TOA cmd" % self) - - # Parse and apply both base and threshold - self.toa256_base = int(request[1]) - self.toa256_rand_threshold = int(request[2]) - return 0 - - # Timing of Arrival simulation - # Relative form: CMD FAKE_TOA <+-BASE_DELTA> - elif self.ctrl_if.verify_cmd(request, "FAKE_TOA", 1): - log.debug("(%s) Recv FAKE_TOA cmd" % self) - - # Parse and apply delta - self.toa256_base += int(request[1]) - return 0 - - # RSSI simulation - # Absolute form: CMD FAKE_RSSI <BASE> <THRESH> - elif self.ctrl_if.verify_cmd(request, "FAKE_RSSI", 2): - log.debug("(%s) Recv FAKE_RSSI cmd" % self) - - # Use negative threshold to disable fake_rssi if previously enabled: - if int(request[2]) < 0: - self.fake_rssi_enabled = False - return 0 - - # Parse and apply both base and threshold - self.rssi_base = int(request[1]) - self.rssi_rand_threshold = int(request[2]) - self.fake_rssi_enabled = True - return 0 - - # RSSI simulation - # Relative form: CMD FAKE_RSSI <+-BASE_DELTA> - elif self.ctrl_if.verify_cmd(request, "FAKE_RSSI", 1): - log.debug("(%s) Recv FAKE_RSSI cmd" % self) - - # Parse and apply delta - self.rssi_base += int(request[1]) - return 0 - - # C/I simulation - # Absolute form: CMD FAKE_CI <BASE> <THRESH> - elif self.ctrl_if.verify_cmd(request, "FAKE_CI", 2): - log.debug("(%s) Recv FAKE_CI cmd" % self) - - # Parse and apply both base and threshold - self.ci_base = int(request[1]) - self.ci_rand_threshold = int(request[2]) - return 0 - - # C/I simulation - # Relative form: CMD FAKE_CI <+-BASE_DELTA> - elif self.ctrl_if.verify_cmd(request, "FAKE_CI", 1): - log.debug("(%s) Recv FAKE_CI cmd" % self) - - # Parse and apply delta - self.ci_base += int(request[1]) - return 0 - - # Path loss simulation: burst dropping - # Syntax: CMD FAKE_DROP <AMOUNT> - # Dropping pattern: fn % 1 == 0 - elif self.ctrl_if.verify_cmd(request, "FAKE_DROP", 1): - log.debug("(%s) Recv FAKE_DROP cmd" % self) - - # Parse / validate amount of bursts - num = int(request[1]) - if num < 0: - log.error("(%s) FAKE_DROP amount shall not " - "be negative" % self) - return -1 - - self.burst_drop_amount = num - self.burst_drop_period = 1 - return 0 - - # Path loss simulation: burst dropping - # Syntax: CMD FAKE_DROP <AMOUNT> <FN_PERIOD> - # Dropping pattern: fn % period == 0 - elif self.ctrl_if.verify_cmd(request, "FAKE_DROP", 2): - log.debug("(%s) Recv FAKE_DROP cmd" % self) - - # Parse / validate amount of bursts - num = int(request[1]) - if num < 0: - log.error("(%s) FAKE_DROP amount shall not " - "be negative" % self) - return -1 - - # Parse / validate period - period = int(request[2]) - if period <= 0: - log.error("(%s) FAKE_DROP period shall " - "be greater than zero" % self) - return -1 - - self.burst_drop_amount = num - self.burst_drop_period = period - return 0 - - # Artificial delay for the TRXC interface - # Syntax: CMD FAKE_TRXC_DELAY <DELAY_MS> - elif self.ctrl_if.verify_cmd(request, "FAKE_TRXC_DELAY", 1): - log.debug("(%s) Recv FAKE_TRXC_DELAY cmd", self) - - self.ctrl_if.rsp_delay_ms = int(request[1]) - log.info("(%s) Artificial TRXC delay set to %d", - self, self.ctrl_if.rsp_delay_ms) - - # Unhandled command - return None - - -# Runner organizes execution of several FakeTRX instances with common clock. -class Runner: - def __init__(self, clck_gen, trx_list): - self.clck_gen = clck_gen - self.trx_list = trx_list.trx_list - - # This method will be called on each TDMA frame - self.clck_gen.clck_handler = self.clck_handler - - self.burst_fwd = BurstForwarder(trx_list.trx_list) - - # This method will be called by the clock generator - def clck_handler(self, fn): - # We assume that this list is immutable at run-time - for trx in self.trx_list: - trx.clck_tick(self.burst_fwd, fn) - - # loops runs IO loop on specified CLCKGen and TRXes forever. - def loop(self): - sock_list = [self.clck_gen._timerfd] - for trx in self.trx_list: - sock_list.append(trx.ctrl_if.sock) - sock_list.append(trx.data_if.sock) - - # Enter main loop - while True: - # Wait until we get any data on any socket - r_event, _, _ = select.select(sock_list, [], []) - - # clock is priority - if self.clck_gen._timerfd in r_event: - self.clck_gen.tick() - - # Iterate over all transceivers - for trx in self.trx_list: - # DATA interface - if trx.data_if.sock in r_event: - trx.recv_data_msg() - - # CTRL interface - if trx.ctrl_if.sock in r_event: - trx.ctrl_if.handle_rx() - +from _fake_trx import FakeTRX, Runner class Application(ApplicationBase): def __init__(self): -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/40051?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: Iadffd49de8197564e57bfd9cb660b1d11136ffd4 Gerrit-Change-Number: 40051 Gerrit-PatchSet: 1 Gerrit-Owner: kirr <kirr(a)nexedi.com> Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-CC: osmith <osmith(a)sysmocom.de> Gerrit-CC: pespin <pespin(a)sysmocom.de>
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • ...
  • 119
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.