Commit Graph

80 Commits

Author SHA1 Message Date
Pau Espin d76e3a3427 Make sure GprsMs free() also frees its tbfs
This fixes TBF objects leaking and ending up alive when the MS object is
explicitly freed through talloc_free (and sporadically
crashing TbfTest once a timeout for them occur).

This mostly affects unit tests, where most of the explicit free()
happens.
In osmo-pcu, in general, the GprsMs object only gets _free() called when
its resource count reaches 0, aka no more TBFs are attached to it. Hence
in general GprsMs object is freed() only when no TBFs (to be leaked) are
present.
However, in the unit tests it's usual that we want to wipe the entire
context by eg. feeing the PCU, the BTS or MS object, which should also
free the related TBFs.

When running osmo-pcu this may only be an issue when the MS object is
freed explicitly, which could happen for instance when a BTS is torn down,
ie. PCUIF going down, moment at which all GprsMs of that BTS are freed.
But in there actually it iterates over PDCHs to free all TBFs, so it's
fine.
If we iterated over MS, this could have ended up in a crash, like
it happened in TbfTest sporadically, but it's not a bit problem if we
crash + restart at that time since anyway the BTS is gone ore just
getting up around that time.

Related: OS#6359
Change-Id: Ibbdec94acb8132be20508d3178d88da44bfaf91d
2024-03-25 21:09:25 +01:00
Pau Espin 5f3177eb41 tbf_ul_fsm: Delay moving ul_tbf to FLOW
Otherwise the scheduler selects the UL TBF for USF during that time, and
of course no one has that USF assigned yet, so no answer and that ends
up triggering MAX_N3101 on the UL TBF.

This is specially important when PCU is connected to the BSC, since the
amount of time for the ImmAss to be scheduled on the BTS and reach the
MS can be bigger.

Change-Id: I48babd70ca44f11110240cbcfbab43d0e3a0fb59
2023-06-29 14:42:33 +02:00
Pau Espin 84011ef86a Improve logging in bts_snd_dl_ass()
Change macro to LOGPTBFDL since it's assigning a DL TBF. Clarify and
join log lines.

Change-Id: Ic5e01289f97bc113ba0a376a535e0cce5bccc5d1
2023-06-12 18:05:42 +02:00
Pau Espin 2549c1e696 Document pcu_lsb() function
While at it, fix a typo in the test output.

This function is nowadays only used in ms_current_pacch_slots(), which
is used only to print the PACCH TS (the first common UL & DL TS).

Change-Id: Id1d0b681f6866618f9f3a8c64d6a6c809ca50ea7
2023-06-03 12:46:26 +00:00
Pau Espin bd461e62b5 encoding: pass RFN to write_immediate_assignment(_reject)()
Those function don't really require the full FN, hence let's pass only
the required information.
This makes the implementation here less dependent on how/if we are able to calculate
full FNs based on RFN: We get an RFN, and we have to encode so that the RFN can be
derived again, so feels less cumbersome having to go through RFN->FN->RFN which may
only cause possible issues if there's some FN timing bug.

3GPP TS 44.018 10.5.2.30 Request Reference:
"The purpose of the Request Reference information element is to provide the random
access information used in the channel request and the frame number, FN modulo 42432"

3GPP TS 44.018 10.5.2.38 Starting Time:
"The purpose of the Starting Time information element is to provide the start TDMA
frame number, FN modulo 42432."

Change-Id: If9b758434c00f2a3868534d5be84946809c989a9
2023-06-02 14:36:57 +02:00
Pau Espin a9b844d346 tbf: Improve TBF name description in logs
Change format to print the state at the end, to resemble more the same
format used by FSMs.
Furthermore, by moving it at the end, print it only when "enclousure" is
requested, aka when not requested by FSM to update its internal name.
The consequence of this logc is that log lines printed from FSM don't
end up with the same state string printed twice in different places.

While at it, shorten the EGPRS/GPRS indicator to one character, which
should be understandable enough since it matches what's usually seen in
mobile phones to signal one or another.

Change-Id: I86b5f042fae77721b22fc026228677bd56768ba9
2023-05-31 12:54:14 +02:00
Philipp Maier 6ee8d136d3 pcu_l1_if_phy: fix API function names
The functions l1if_open_pdch and l1if_close_pdch have a misleading
naming since what they actually do is opening and closing the TRX since
they return and accept a context (obj) that is valid for a whole TRX.
This also explains why the other functions accept a timeslot as
parameter in addition to the context. Let's rename those functions so
that it is clear what they do.

Related: OS#6022
Change-Id: I395a60b2fba39bac4facec78989bac20f0cef0d3
2023-05-03 09:57:38 +02:00
Pau Espin 4d3639144d Move resource allocation outside of tbf allocation
This patch finally decouples TBF allocation from resource allocation.
This will allow in the future reserving resources without having to
require a TBF object to exist.

Change-Id: I2856c946cb62d6e5372a1099b60e5f3456eb8fd4
2023-04-26 13:29:03 +02:00
Pau Espin eae9147424 ms: Hold a reference during ms_alloc
Make the caller hold a reference to the MS object just allocated, so
that it hs to explicitly unref it and, in turn, if no new references
were added during its use, trigger release of the MS object.
This is useful to avoid leaking MS object if it was allocated and then
no TBF is attached to it because allocation of TBF failed.

Related: OS#6002
Change-Id: I2088a7ddd76fe9157b6626ef96ae4315e88779ea
2023-04-21 14:36:28 +02:00
Pau Espin 9da0686371 Merge bts_alloc_ms() and ms_alloc()
gprs_default_cb_ms_idle() is changed to have the same implementation as
previous bts_ms_idle_cb(), since that's the only one being used in
osmo-pcu code. It makes no sense to use different callback logic in unit
tests.

This is another step towards simplifying the code and getting rid of the
idle/active_cb().

Change-Id: I2a06d17588572a21dc5a14ddbde83766076b446d
2023-04-20 16:17:39 +02:00
Pau Espin bfc9756c2b ms: Drop setting (egprs_)ms_class during bts_alloc_ms()
That information is not required during allocation of the object, and
most times it is not known.
Defer setting it only to meaningul values in paths obtaining the
information from peers.

Change-Id: I36f07dc389f7abe205fc4bcddbde93735f5d5cfc
2023-04-20 16:17:38 +02:00
Philipp Maier 72ed33303a pcu_l1_if_phy: add new PHY API function to disconnect PDCH
There is a function l1if_connect_pdch, but no complementary function
like we have it with l1if_open_pdch and l1if_close_pdch. The reason for
this is that the PHY implementations that rely on a femtocell DSP do not
need to disconnect the pdch explcitly. However, the planned support for
the E1 based Ercisson RBS CCU will require an explicit disconnect. So
lets add a function call for this.

Change-Id: Ied88f3289bda87c48f5f9255c4591470633cc805
Related: OS#5198
2023-02-27 16:46:01 +01:00
Pau Espin e2ed40d02b Convert tbf->control_ts to be a gprs_rlcmac_pdch*
This allows having full information on the control TS easily reachable
(like TRX ofthe PDCH), and makes it easy to compare TS by simply
matching the pointer address.

Change-Id: I6a97b6528b2f9d78dfbca8fb97ab7c621f777fc7
2022-12-16 12:11:31 +01:00
Pau Espin ff7c581011 Rename gprs_rlcmac_ts_alloc.cpp -> alloc_algo.cpp & create own .h file
First commit towards trying to have alloc algorithm as isolated as
possible from others parts of the code trying to avoid state changes on
data structures.
Change name also because the alloc_algo not only allocated TS, but TFIs
and USFs.

Change-Id: I33a6c178c64a769f05d3880a69c38acb154afa62
2022-12-16 12:08:07 +01:00
Pau Espin 343c0ee8d9 Split tbf_fsm as tbf_{ul,dl}_fsm
The 2 types of TBF share some parts of the implementation, but actually
half of the code is specific to one direction or another.
Since FSM are becoming (and will become even) more complex, split the
FSM implementation into 2 separate FSMs, one for each direction.
The FSM interface is kept compatible (events and states), hence code can
still operate on the tbfs on events and states which are shared.

Test output changes are mainly due to:
* FSM instance now created in subclass constructor, so order of log
  lines during constructor of parent class and subclass slightly
  changes.
* osmo_fsm doesn't allow having 2 FSM types with same name registered,
  hence the "TBF" name has to be changed to "DL_TBF" and "UL_TBF" for
  each FSM class.
* FSM classes now use DTBFUL and DTBFDL instead of DTBF for logging. Some
  tests don't have those categories enabled, hence some log lines
  dissappear (it's actually fine we don't care about those in the test
  cases).

Change-Id: I879af3f4b3e330687d498cd59f5f4933d6ca56f0
2022-11-18 16:54:20 +01:00
Pau Espin 94f8258de7 Improve MS logging
Use same formatting similar to what's now used in TBF, which is far more
easy to grep and follow. This way one can easily follow what happens to
a given IMSI, a give TFI, a given TLLI, etc.

Change-Id: If9b325764c8fd540d60b6419f32223fd7f5a5898
2022-11-03 18:12:06 +01:00
Pau Espin 57843c571a Improve TBF logging
use a format in tbf::name() which is sanitized (osmo_sanitize) and hence
can be used both in regular log as well as for its internal FSM ids.
Until now, the FSMs contained a small amount of information with
different formatting than the regular LOGPTFB(), which made it difficult
to grep or follow a TBF through its lifetime looking at logs. The new
unified format makes that a lot easier.

Extra information is now printed if available, such as IMSI.
Furthermore, the TFI is updated to include BTS and TRX, since the TFI is
unique within the scope of a TRX.

Change-Id: I3ce1f53942a2f881d0adadd6e5643f5cdf6e31da
2022-11-03 13:58:57 +01:00
Pau Espin bda7bb7667 Rename tbf_alloc_ul_tbf -> ul_tbf_alloc
Use proper prefix according to the type being allocated.

Change-Id: Ic98c3c852c96c3f52f1c8f531b8d0fd28ce5aef5
2022-10-31 22:07:31 +01:00
Pau Espin 8757384aec Rename tbf_alloc_dl_tbf() -> dl_tbf_alloc()
Rename it so that it follows the usual prefix for the type it allocates.

Change-Id: I7d30a85fefaa61d100fbd51af4601a3cf7de2159
2022-10-27 13:53:03 +02:00
Pau Espin f510f5bc1f Use GSM48_MT_RR_IMM_ASS instead of hardcoded 0x3f value
Change-Id: Id966cbab403763d006bd5e59757c5bf57402bf9d
2022-10-16 22:13:48 +02:00
Pau Espin 4f8384bfbb llc: Convert to C
There's no real reason (other than historical) why code in llc should be
kept as c++ code. Let's rewrite it as C so that it can be included by
existing C code without having to add C->C++ shim, ifdefs all around,
etc.
This simplifies code and easies modification/improvement of the related
objects.

Change-Id: I250680ba581167d7398b2f734769c756cbb61c48
2022-03-31 19:42:15 +02:00
Pau Espin 0043005afb tbf_fsm: rename state NULL -> NEW
This helps distinguishing the case where a TBF is in the initial state
and the unexpected case where osmo_fsm_inst_state_name reports "NULL"
due to fi pointer being NULL.

Change-Id: Ieaabfc9fa0dedb299bcf4541783cf80e366a88c3
2021-10-12 11:01:07 +00:00
Pau Espin ea8dbddab1 Move tbf ul_ack_state to osmocom FSM
Related: OS#2709
Change-Id: Icf23bf5a4b85fbcbf1542cebceb76b9ba7185d30
2021-08-23 17:14:23 +02:00
Pau Espin afe189e802 Get rid of lots of code only used by tests
There are 2 methods "rcvd_dl_ack()" in osmo-pcu code. One is used by
osmo-pcu itself, and the other is only used in tests.
Changing the tests to use the same method as osmo-pcu allows removing
the second one, and with it, a lot of code and complexity out of
osmo-pcu.

Change-Id: I14d9312cb61534dc97fca83141b9c0cd933c9206
2021-08-23 17:14:23 +02:00
Pau Espin 49a2f404e8 replace dl_ass_state with osmocom FSM
Related: OS#2709
Change-Id: Ia33418478e17986a316ffda48b091030f53fa371
2021-08-23 17:14:22 +02:00
Pau Espin 6ad11a6990 Replace ul_ass_state with osmocom FSM
Related: OS#2709
Change-Id: Id414eafe9c04a9a8759c6fb1a483bf2ee093a4d2
2021-08-23 17:14:22 +02:00
Pau Espin dc2aaac29f tbf: Move existing tbf_state implementation to osmo_fsm
This is only an initial implementation, where all state changes are
still done outside the FSM itself.
The idea is to do the move in several commits so that they can be
digested better in logical steps and avoid major break up.

Related: OS#2709
Change-Id: I6bb4baea2dee191ba5bbcbec2ea9dcf681aa1237
2021-05-19 12:50:25 +02:00
Pau Espin 25ebf3c8f9 Make use of T3142 received from BTS
Related: OS#3928
Change-Id: I4e26f181db9693d3a267a879e2aebda12eab2a8c
2021-04-26 14:10:11 +02:00
Pau Espin 36177c6b58 tbf: Improve logging when TBF being allocated or no TBF avail
Change-Id: I68491fe2c643262e35b4d4f1ecac34afcf61848f
2021-02-26 11:50:15 +01:00
Pau Espin 00f52cc3d6 tests: Replace deprecated API log_set_print_filename
Change-Id: Idcc4875592c81f17ac98c4f6098492b3d9dd33d2
2021-02-19 16:24:11 +01:00
Pau Espin b18d2a5fd9 tests: Explicitly drop category from log
Let's disable category here since we don't care about its formatting here.

In any case, every test relying on logging output validation should
always explicitly state the config to avoid issues in the future if
default values change.

Change-Id: I7f9c56313cfaa74ebe666f44763a83d8102f5484
Related: OS#5034
2021-02-19 16:24:11 +01:00
Pau Espin d1049dc8cc Allow multiple bts objects in PCU
This patch doesn't really tests whether osmo-pcu can work on a multi-bts
environment, but it prepares the data structures to be able to do so at
any later point in time.

Change-Id: I6b10913f46c19d438c4e250a436a7446694b725a
2021-01-20 12:36:21 +01:00
Pau Espin 2182e627cd Unify BTS into a C usable structure
Previous work on BTS class started to get stuff out of the C++ struct
 into a C struct (BTS -> struct gprs_glcmac_bts) so that some parts of
it were accessible from C code. Doing so, however, ended up being messy
too, since all code needs to be switching from one object to another,
which actually refer to the same logical component.

Let's instead rejoin the structures and make sure the struct is
accessible and usable from both C and C++ code by rewriting all methods
to be C compatible and converting 3 allocated suboject as pointers.
This way BTS can internally still use those C++ objects while providing
a clean APi to both C and C++ code.

Change-Id: I7d12c896c5ded659ca9d3bff4cf3a3fc857db9dd
2021-01-19 16:28:10 +01:00
Pau Espin ac3fd12026 Split PCU global PCU object from BTS object
Currently the BTS object (and gprs_rlcmac_bts struct) are used to hold
both PCU global fields and BTS specific fields, all mangled together.
The BTS is even accessed in lots of places by means of a singleton.

This patch introduces a new struct gprs_pcu object aimed at holding all
global state, and several fields are already moved from BTS to it. The
new object can be accessed as global variable "the_pcu", reusing and
including an already exisitng "the_pcu" global variable only used for
bssgp related purposes so far.

This is only a first step towards having a complete split global pcu and
BTS, some fields are still kept in BTS and will be moved over follow-up
smaller patches in the future (since this patch is already quite big).
So far, the code still only supports one BTS, which can be accessed
using the_pcu->bts. In the future that field will be replaced with a
list, and the BTS singletons will be removed.

The cur_fn output changes in TbfTest are actually a side effect fix,
since the singleton main_bts() now points internally to the_pcu->bts,
hence the same we allocate and assign in the test. Beforehand, "the_bts"
was allocated in the stack while main_bts() still returned an unrelated
singleton BTS object instance.

Related: OS#4935
Change-Id: I88e3c6471b80245ce3798223f1a61190f14aa840
2021-01-18 10:37:05 +00:00
Pau Espin Pedrol da971ee502 Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).

GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.

Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.

For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.

Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2021-01-05 10:34:25 +00:00
Vadim Yanitskiy cb98894eb1 TLLI 0x00000000 is a valid TLLI, use 0xffffffff instead
The assumption that TLLI 0x00000000 is invalid and can be used
as the initializer is wrong.  Similar to TMSI, 0x00000000 is a
perfectly valid value, while 0xffffffff is reserved - use it.

According to 3GPP TS 23.003, section 2.4, a TMSI/P-TMSI with
all 32 bits equal to 1 is special and shall not be allocated by
the network.  The reason is that it must be stored on the SIM,
where 'ff'O represents the erased state.  According to section
2.6 of the same document, a local/foreign TLLI is derived from
P-TMSI, so the same rule applies to TLLI.

I manually checked and corrected all occurances of 'tlli' in the
code.  The test expectations have been adjusted with this command:

  $ find tests/ -name "*.err" | xargs sed -i "s/0x00000000/0xffffffff/g"

so there should be no behavior change.  The only exception is
the 'TypesTest', where TLLI 0xffffffff is being encoded and
expected in the hexdump, so I regenerated the test output.

Change-Id: Ie89fab75ecc1d8b5e238d3ff214ea7ac830b68b5
Related: OS#4844
2020-11-10 17:06:39 +00:00
Pau Espin 87eec1fd74 Get rid of bts->egprs_enabled
BTS simply notifies the PCU about the supported MCS, and PCU is
responsible for providing correct data formatting supported for the BTS
and the target MS.

Related: OS#4544
Change-Id: Ifcf23771bd23afc64ca6fea38948f98f2d134ecb
2020-11-04 21:39:43 +01:00
Pau Espin 8072e354cc Move EGPRS MS mode set to gprs_ms.cpp
Some tests were wrong (TypesTest) and required modification, since they
were setting a EGPRS MS but then expecting a GPRS assignment.

Change-Id: I9d3ee21c765054a36bd22352e48bde5ffca9225a
2020-11-04 21:39:42 +01:00
Pau Espin 46fd7a0316 Move BTS initial values inside bts.cpp
This way everytime any program or test initiates a BTS object, the
bts_data structure has the same values.

Change-Id: Iffd6eecb1f08bda0091f45e2ef7c9c63b42e10b3
2020-11-04 19:32:12 +00:00
Pau Espin b3f239785c tbf: Make window() available to tbf base class
Return an interface to the window base class so that the tbf base class
can access the common window methods, such as set_ws(). It will be used
in next commit to get rid of duplicated function enable_egprs in both
dl_tbf and ul_tbf subclasses.

The user of the function can then decide to access more specific
functionaltiites of the window class by static casting it to the
specific direction (which is known by the caller since it operates on a
ul_tbf or a dl_tbf).

Change-Id: Ia2e1decf91be1184668e28297c2126affb9c7ae4
2020-10-24 22:14:42 +02:00
Vadim Yanitskiy 1156776572 encoding: pass pdch slot directly to encoding functions
In order to be able to encode frequency hopping parameters, let's
pass a const pointer to 'gprs_rlcmac_pdch' (PDCH slot) directly,
instead of passing all related parameters separately.

Change-Id: I6bccad508f0fdccc4a763211008dd847a9111a8d
Related: SYS#4868, OS#4547
2020-08-24 10:53:08 +00:00
Pau Espin 5bb87b83d1 rlc: Move prepare() function out of gprs_rlc_data struct
Newer gcc 10.1.0 is erroring due to memset being applied on a complex
type, so let's start by removing this only function outside of the
struct.

Change-Id: I20426557d9b3049ab275fadb92e10ea8a860a119
2020-05-18 11:07:03 +02:00
Philipp Maier de0e558baf gprs_debug: Use only LOGL_NOTICE as default loglevel
The default loglevels of some log categories are configured to
LOGL_INFO. This is still to verbose, lets use LOGL_NOTICE here.

Change-Id: Ibb1cd1a94fb4fdd0147e073f8c1c82562c2c14ef
Related: OS#2577
2020-05-13 16:41:55 +00:00
Pau Espin 322456ed47 Expect ms object to exist before calling tbf_alloc_dl_tbf()
Same as previous commit, this time for the DL counterpart.

Change-Id: I87f6cdf8288a688466020bda0874e68b57aa71c4
2020-05-12 17:09:20 +00:00
Pau Espin 17402a5902 Expect ms object to exist before calling tbf_alloc_ul_tbf()
It's really non-sense from architectural point of view to pass an
optional pointer to the MS holding the TBF and creating it otherwise.
TBFs shouldn't be creating MS they belong too.

This simple change requiring so many code line changes really exhibits
how badly entangled the object relationship is.

Another commit will follow doing the same for dl tbf.

Change-Id: I010aa5877902816ae246e09ad5ad87946f96855c
2020-05-12 17:09:20 +00:00
Pau Espin 9d1cdb1f69 Move out tbf subclasses from tbf.h to their own headers
It's a good start towards clearing current mess between parent and the 2
children classes.

Change-Id: Ibc22ea2e02609af7ee058b8bc15df2115d4c6f60
2019-09-25 17:50:06 +02:00
Pau Espin 488aa29083 cosmetic: fix whitespace
Change-Id: I45bbe4d3c69d573aaff010d16f338c7ec3eaf08a
2019-09-25 17:50:06 +02:00
Alexander Couzens 2585451408 tests: test encoding of egprs ul ack/nacks
Test the encoding with uncompressed and compressed acknowledgements.

Change-Id: I35d6b5e312faeb116ddda6b33c550840da1496fe
2019-08-12 08:40:04 +00:00
Max e742cc0997 Use Timing Advance Index in UL assignments
Write TAI (if available) when generating Rest Octets for UL
Assignment. This should not affect actual PCU behavior because TAI is
not yet supported by upper layers but we have to adjust corresponding
tests anyway.

That's updated version of reverted commit.

Change-Id: I69407793bdb863be5fc42adadf75842d22f27335
Related: OS#3014
2019-03-27 12:32:04 +00:00
Max 3eb47363ad Rewrite Packet Uplink IA Rest Octets for SBA
Use bitvec_set_*() directly without external write pointer tracking to
simplify the code. This is part of IA Rest Octets (3GPP TS 44.018
§10.5.2.16) which is the last part of the message so it should not
interfere with the rest of encoding functions.

The difference in the expected test output is due to proper handling of
TAI which should not be transmitted for SBA according to the Note in
Table 10.5.2.16.1 in 3GPP TS 44.018.

The change was manually tested against real mobile phone using options
'gprs mode gprs' in osmo-bsc.cfg and 'two-phase-access' in osmo-pcu.cfg
to make sure appropriate code path is actually triggered.

That's partially based on reverted commit 93d947f5e8.

Change-Id: I97d53c27c1ca9e032d431b3aa7f915027d63ddc0
Related: OS#3014
2019-03-27 12:32:04 +00:00