Commit Graph

72 Commits

Author SHA1 Message Date
Pau Espin 40a297f3b0 Differentiate between T3192 and T3193
T3192 on the MS side (boadcasted by the network on SI13) is used for the
MS to stay monitoring the PDCH of a DL TBF after sending PKT DL ACK/NACK
for the last DL data block (FinalAck=1).
T3193 is the counterpart in the network, defined as >T3192, which is
used to make sure the TFI is no longer used by the MS and hence can be
reused/re-assigned again.

Hence, we want to differentiate between those 2 timers, since the first
one gives us information on how late can we still tx PktDlAss on PACCH
on that DL TBF, while the later only provides info on when to free the
DL TBF in order to reuse the TFI.

Change-Id: I7421342461bf159d945651037e6fe690f88c6fae
2023-06-20 12:07:45 +02:00
Pau Espin e1a8915936 cosmetic: ms: fix formatting of function comment
Change-Id: I717c0ebd6e9af5388e94482842f5638777758b32
2023-04-28 14:46:32 +02:00
Pau Espin 7a491b9d5f ms: Fix unsafe iterating freeing items in list
Change-Id: I35cba6d617b3356515769405c7d05ba28cd5132b
2023-04-28 14:45:39 +02:00
Pau Espin 5faedf3432 ms: Mark ms_reset() as static
Change-Id: Idc42be62f9911b7e2fad3dade884e72e5c2965f4
2023-04-28 14:29:40 +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 4673eb0b76 ms: Log MS active/idle state in 'show ms' VTY commands
Change-Id: Ibcd34055c9ae390510c5c3ba26621fd96d2368fd
2023-04-21 14:36:28 +02:00
Pau Espin f086fede93 ms: Rename field timer -> release_timer
Rename it so that it becomes clear what the timer is used for.

Change-Id: Id4738ea196b232858e1ec9cdc439f9b81839058f
2023-04-21 14:36:28 +02:00
Pau Espin b53230acec ms: Get rid of ms->delay field
Simply apply the content of the configured timer when the MS goes idle.
Having that field is convenient to do tricky stuff in unit tests, but
makes the main osmo-pcu app more complex for no good enough reason.

Change-Id: I8d44318b37b6605afd84db8ccec0d75e6db293b9
2023-04-21 14:36:28 +02:00
Pau Espin 4fdf79e0b3 ms: Increase log level when scheduling release timer
Change-Id: Ie470b5b0c7b01d91f4ad693e52afd51860d6da2d
2023-04-21 14:36:28 +02:00
Pau Espin fe4d2f7dca Add new log category 'ms'
This is useful to track the lifecycle of MS objects. The RLCMAC cateogry
used so far in those log messages is too broad.

Change-Id: Ib4ce88d0f7309ac77c064a94bb0d667e8dbc33dd
2023-04-21 14:36:28 +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 84b0ebc902 cosmetic: Fix indentation in comment
Change-Id: I15063346e4ff0367c0bf04f6b48ac62b9bdf2929
2023-04-21 14:36:28 +02:00
Pau Espin ac4d4a6d41 ms: Rewrite MS release lifecycle
This commit changes lots of stuff in the MS release lifecycle, but
there's no really good way to split this into patches which make sense,
since all the chaos is intensively entangled.

Get rid of the ms_callback complex mess, it is not needed at all.

Previous MS release was strange due to the existance of previous
ms_callback.idle concept and MS storage: the MS signalled when it went
idle (no TBFs attached) and waited for somebody outside to free it,
while then arming itself the release timer to release itself if it was
not released by whoever.

The new lifecycle follows an easier (expected) approach: Whenever all
TBFs become detached from the MS and it becomes idle (use_count becomes
0), then it frees its reserved resources (TFI, etc.) and either:
* frees itself immediatelly under certain conditions (release timeout
  configured = 0 or MS garbage with TLLI=GSM_RESERVED_TMSI)
* Arms release_timer and frees itself when it triggers.

If during release_timer the MS is required again (for instance because a
new TBF with TLLI/IMSI of the MS is observed), then a TBF is attached to
the MS and it is considered to become active again, hence the release_timer
is stopped.

OS#6002
Change-Id: Ibe5115bc15bb4d76026918adc1be79469c2f4839
2023-04-20 20:40:52 +02:00
Pau Espin df6684fe50 ms: Log detaching tbf log line in proper place
It is interesting to log that a tbf is being detached *before* it
actually happens, so that the reader can see which TBF is being
detached.

Change-Id: I2008beb9ab8f97f7ea5ed7b45cfb3f23dfe7b27f
2023-04-20 20:40:52 +02:00
Pau Espin 6efa381248 ms: Make ms_{attach,detach}_tbf expectancies more robust
* Make sure that the tbf being attached has already the MS assigned.
* Check no re-attaching of alredy attached TBF ever happens.
* Document and early skip case where a non-attached TBF detach is
  attempted.
* Avoid recursive call mess to tbf_set_ms(tbf, NULL); during detach.
* MsTest needs to be modified since it uses fake TBF objects which use
  different set of calls than the regular TBFs in osmo-pcu. Since the
ul_tbf object is reused, it needs to be assigned ul_tbf->ms again before
re-assigning it, as per what happens usually in tbf_set_ms() in
osmo-pcu.

Change-Id: Ia18fe2de1fb3bf72f530157e5f30de64f2b11e12
2023-04-20 20:40:44 +02:00
Pau Espin 3ea467d104 ms: Make sure tbf!=NULL in ms_attach_{ul,dl}_tbf()
It makes no sense to pass "NULL" to attach function. There's a detach
function to be used if a given TBF has to be detached.

Change-Id: I0c5df195c080b21e5516aebfb46db22bdc55f2a2
2023-04-20 16:17:39 +02:00
Pau Espin 403e048ac0 ms: Use osmo_use_count to track references
Change-Id: Ib65629224e6bd5683bb9192ba4354e965e8d39ec
2023-04-20 16:17:39 +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 fe7aee9302 ms: store in bts->ms_list during alloc/destroy of ms object
With this change the MS no longer is removed from the llist without
potentially skipping free() if not idle in bts_ms_idle_cb().
As a result, some unit tests now can free it during bts tear down
instead of having them leaked.
The tests int MsTest need changes because the tbfs created are fake and
cannot be freed using tbf_free(), and hence cannot be detached from MS
using regular code paths. Instead first call explicit talloc_free(ms)
like other unit tests in the file already do.

Change-Id: Id53f8dfb9963366dd4b19a324615bbc83c4f23e7
2023-04-20 16:17:39 +02:00
Pau Espin eb0a0527e0 ms: Merge ms_storage into bts.cpp
That class is mostly a C++ class holding a llist plus some callbacks.
Having that in a separate class makes code more complex for no good
reason. This patch moves the llist into bts and allocates stuff directly
from within bts.
This will allow further cleanup of MS lieficyle in future patches.

Change-Id: I627f5db5073189c23ddf2b7f09c90abb24846f62
2023-04-20 16:17:38 +02:00
Pau Espin cde18c5632 bts: Rename bts_ms_by_{tlli,imsi} -> bts_get_ms_by_{tlli,imsi}
While at it, put them together and mark bts param as const.
This is a preparation for next patch.

Change-Id: Iad8aec4424f1f23cd4d02a14c4f9ec1b9fdb1f75
2023-04-20 16:17:38 +02:00
Pau Espin f80cc5b9c8 ms: Drop setting tlli during ms_alloc()
Inside osmo-pcu code, the code path is to always call ms_alloc with
tlli=GSM_RESERVED_TMSI; a different value is only passed during unit
tests.
It makes no sense to have unit tests using differnet code paths than
ther app itself, since in the app it always desired to go through the
ms_set_tlli() and ms_confirm_tlli() which does more stuff.
Hence, drop the tlli param in ms_alloc and change the unit tests to use
the available APIs used by the application.

Change-Id: I730ec911a43b0f4e78faee4eeffb3ca8601564f8
2023-04-17 20:46:41 +02:00
Pau Espin 14379ef901 ms: Fix MS without PTMSI not freed immediatelly
This check (tlli != 0) was added in 2015 in
6d86628e5b, with the rationale below:

"""
To avoid dangling entries without a TLLI there (which cannnot be
retrieved anyway), the timer in the MS objects is not started after
all TBF have been detached, so that they get deleted immediately in
that case.
"""

The rationale makes sense, but through time the MS class was fixed to
return GSM_RESERVED_TMSI (0xFFFFFFFF) when no TMSI was available.
Hence, the check was wrong, and as a result, free() of MS containing
GSM_RESERVED_TMSI would be delayed over time by release timer.

Related: OS#6002
Change-Id: I7a694a30f8709c00af774846d7c4925cef253a71
2023-04-17 20:46:14 +02:00
Philipp Maier 41e38475ed pcu_l1_if: get rid of strange paging group calculation
The PCU uses a 16 bit integer value as paging group which does in fact
not really resamble the paging group. Instead it encodes the last three
digits of the IMSI from which the paging group can be calculated. The
value is then eventually converted back to Ascii-digits and then sent
over the PCU-IF interface. Lets get rid of this weird conversion and
use the IMSI directly.

Change-Id: I40d7fc14c9591b3de091e425faaf325421c70a0e
2023-03-20 10:54:28 +01:00
Pau Espin d1058b9445 Avoid moving DL-TBF from old_msg to new_ms during ms_merge
The DL-TBF assigned to another MS object may have a totally different
set of reserved resources (TS set, TRX, etc.), so one cannot simply move
those to the new MS. To start with, if the 2 MS are on different TRX it
is clear that one of them will not be really in operation. That's most
probably the DL-TBF being in ASSIGN state on CCCH waiting for PCUIF_CNF
and later X2002 to trigger to start sending DL blocks, but without
confirmation whether the MS is really there. Since the other new MS
object probably has a UL-TBF, that's the one probably operative, and
hence a new DL-TBF can be created at that same time and assigned through
UL-TBF's PACCH.

Unit test test_ms_merge_dl_tbf_different_trx showcases the above
scenario.

Related: SYS#6231
Related: OS#5700
Related: 677bebbe5c
Change-Id: Ie8cb49d5492cfc4cbf8340f3f376b0e6105e8c82
2022-12-19 12:32:44 +01:00
Pau Espin 9935d0d21d Convert ms_first_common_ts to struct gprs_rlcmac_pdch
This way it contains full information about the TS, not only the TN.

Change-Id: I19373939ec104d371e3e91422f018a8175cb0f89
2022-12-16 12:08:07 +01:00
Pau Espin a621d59ea8 Refactor code rejecting UL-TBF upon rx of PktResourceReq
* Make it similar to the already existing TBF allocation procedures
* Pass pdch pointer instead of trx and ts numbers

Change-Id: I04b3b65942732cc652adeaa507529b849292ff61
2022-12-16 11:05:46 +00:00
Pau Espin 345d9ad1b3 Move first_common_ts from gprs_rlcmac_tbf to GprsMs
The field contains a common value between the 2 active TBFs of the MS,
so it makes no sense to have them duplicated on each TBF. It can be
sanely stored in the MS object.

Change-Id: I8df01a99ccbfaf7a442ade5000ee282bd638fbba
2022-12-16 11:05:46 +00:00
Pau Espin 5ba3ef9a2b sched: Pass pdch to *_create_rlcmac_msg() functions
The pdch pointer contains more info than just timeslot number. For
instance, it contains information about the TRX owning the TS.

Change-Id: Ic31a7360a29e61f70bb1338ddab6f5f31aa8b26e
2022-12-13 12:20:02 +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 677bebbe5c Avoid losing DL-TBF during MS merge
It is desired to free pending DL-TBF under some scenarios, which somehow
are related to those where we call the ms_merge() procedure since it's at
time an MS can be identified when coming from packet-idle state.

Until now, the freeing of those DL-TBFs happen because the ms_merge()
procedure doesn't migrate DL-TBF from "old_ms" to "ms". This was done
manually under the cases where it was deemed necessary before calling
the ms_merge() procedure 8because old_ms and its tbfs are gone after
returning from it).
This logic, though convinient for the specific cases at hand, is quite
confusing for readers and program execution since one would expect the
ms merge to, well, merge everything.

Therefore, this patch changes the ms_merge() logic to always merge the
DL-TBF, and only under the specific cases where it makes sense to free
it, do so explicitly after MS merge, where all the info has been updated
and united.
2 code paths are now explicitly freeing the existing DL-TBF when needed:
- TBF_EV_FIRST_UL_DATA_RECVD: 1st data (containing TLLI) is
  received from MS, hence identifyng the MS and potentially having been
  merged with some old MS which used to have a DL-TBF, most probably in
  process of being assigned through CCCH (PCH). This event is triggered
  during MS using 1phase-access, and we should drop the exsitng DL-TBF
  because MS just came from packet-idle mode (CCCH).
- rcv_resource_request(): PktResourceRequest is received at an scheduled
  SBA, meaning the MS is doing 2phase-access, meaning MS also came from
  packet-idle mode (CCCH), so previous DL-TBF can be dropped.

Related: OS#5700
Change-Id: I29f4ffa904d79d58275c6596cc5ef6790b6e68c6
2022-10-31 22:07:31 +01:00
Pau Espin 8abe13cf75 Rework tbf::update_ms()
That function was pretty confusing since it used a "enum
gprs_rlcmac_tbf_direction dir" param (whose type is expected to describe
the data direction of a TBF) to describe the direction of the the packet
which triggered its call.
The parameter was actually always called with "GPRS_RLCMAC_UL_TBF" which
in this case meant "uplink direction" which meant "TLLI was updated from
the MS, not the SGSN".
The DL direction was only used in unit tests, which can hence be simply
replaced by ms_confirm_tlli(), which this commit does.
So this update_ms() function was actually used in practice in osmo-pcu
to trigger update of TLLI and find duplicates only when an RLCMAC block
(control or data) was received from the MS. Therefore, this function is
renamed in this patch and moved to the gprs_ms class, since it really
does nothing with the TBF.

Related: OS#5700
Change-Id: I1b7c0fde15b9bb8a973068994dbe972285ad0aff
2022-10-31 22:07:31 +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 b8ff74b37a gprs_ms: Add comment warning the user that a ptr may be freed after call to func
Change-Id: Ifa3d6b38fca89500ef02c9b972f514ceaf8fe83b
2022-10-31 22:07:31 +01:00
Pau Espin 32416fdcde Join ms_merge_and_clear_ms() and ms_merge_old_ms()
While at it, improve logging of the merge action

Change-Id: I39d9eac159448fc3c3a4db9e1b9c5364e906a78f
2022-10-31 22:07:31 +01:00
Pau Espin 9438613792 Move UL allocation&assign functions to gprs_ms.c
Similar structure as what we have with DL-TBF.

Change-Id: I256aeede2a2678c9738539fb6ec4db9766fa85e4
2022-10-31 22:07:31 +01:00
Pau Espin 091642a8f5 Replace tbf->establish_dl_tbf_on_pacch() refactoring GprsMs functions
ms_new_dl_tbf_assignment() is split into 2 functions, one to
allocate+assign on PACCH and another one for PCH.
This makes a lot clearer the aim of each caller of the function.
Once this is done, it becomes obvious tbf->establish_dl_tbf_on_pacch()
is basically doing the same as ms_new_dl_tbf_assigned_on_pacch() so drop
it.

Change-Id: I610210e3120c962d91ce8ff94c66161e086761ba
2022-10-28 18:13:41 +02:00
Pau Espin 8fa3e063f5 Rename function tbf_dl_request_dl_ack() -> dl_tbf_request_dl_ack()
Use the dl_tbf prefix which is usually used to easily distinguish from
"ul_tbf" specific APIs and "tbf" generic (parent class) APIs.

Change-Id: Ibf6ae20da99866af5f2b6e12184f3145d1fc0bbf
2022-10-28 17:40:29 +02:00
Pau Espin ee35008037 Refactor and clarify tbf->triger_ass() code
Split the function into 2 functions, one for assignment on PACCH and one
for assignment on PCH. This makes code calling this API far more clearer
on what is the exact aim when assigning the TBF.

Change-Id: Ic92867e55337b0bd6b5bfc97f13b7982eedb1cb7
2022-10-28 17:35:06 +02:00
Pau Espin 22b26d8a1c Delay ImmAss(PCH, PktDlAss) if waiting for PKT_CTRL_ACK answering UL_ACK_NACK (FinACK=1)
In that state (ul_tbf=TBF_ST_FINISHED), we are unable to reach the MS to
assign a new DL TBF.
* MS Is not available in CCCH because it's attached the PDCH.
* MS won't be able to PKT_CTRL_ACK a PktDlAss on PACCH, because next
  thing it will do is to PKT_CTRL_ACK the UL_ACK_NACK(FINACK=1) we
  already polled it for, and immediatelly after that it will release the
  UL TBF on its side and go back to packet idle mode.

Hence, we must wait for MS to send the PKT_CTRL_ACK to us in order to be
able to assign the DL TBF in PCH (CCCH).

Related: OS#5700
Change-Id: I7a30db9cc7dae70e04054f1a4dba004bd1780d4a
2022-10-28 16:33:45 +02:00
Pau Espin 1e16e1dc92 use new {dl,ul}_tbf_as_tbf(_const) helper functions
Change-Id: I223d9d5823c90ff31089420d35a7bf0fe1ebf870
2022-10-28 15:14:44 +02:00
Pau Espin cc30b052db Rename as_{dl,ul}_tbf -> tbf_as_{dl,ul}_tbf
Prefix the function accordingly to specify the input object.

Change-Id: I225568fe2cb5236817cdd9609354c24c66723606
2022-10-28 15:14:44 +02:00
Pau Espin bd1f01fd27 Fix mess with struct tbf types passed to LOGPTBF macro
It is quite common in all osmo-pcu code to have to convert between
parent class "tbf" and children "dl_tbf"/"ul_tbf", or other way around.
This commit adds new helper static inline functions to cast between
those while doing type checks.
This is used by new LOGPTBFDL and LOGPTBFUL macros to now expect the
proper subclass and cast securely inside the macro itself, hence sparing
all code calling those macros to have to cast explicitly the pointer to
the parent "tbf" class.

Change-Id: I7e4489ad4b93c9c8442213947e53c10b61fdc5e9
2022-10-28 15:14:44 +02:00
Pau Espin 14beef6cfe Move LLC enqueuing and retransmit timer to MS object
The LLC queue is already in the MS object. The LLC timer and most
of the logic to enqueue its data is independent from the TBF.

Change-Id: I56b89fcac838d8eb732b629734d5e458e9c806d1
2022-10-27 13:52:59 +02:00
Pau Espin 3547d64061 gprs_ms: Move creating string name of object to a function
This way it can be used outside of LOGPMS().

Change-Id: I8ab713154c8f308878f3e85b6f7e8afc5c4be249
2022-10-21 19:09:23 +02:00
Pau Espin 0b5997e8f7 gprs_ms: Document functions setting/updating TLLI
Based on information from original commit introducing the functions
(9399046729) and looking at the current
code.

Change-Id: Ia440c672a8d2e11169b41f787239bfbba0989231
2022-10-21 14:10:43 +02:00
Vadim Yanitskiy e33c236db0 {ms,gprs_pcu}_talloc_destructor(): call osmo_timer_del() unconditionally
osmo_timer_del() does check if a timer is active internally.

Change-Id: I062c7636b59714860fa6b49a2d59c6528ebd57e3
2022-08-08 20:22:41 +00:00
Pau Espin c7802d9fc1 gprs_ms: Use osmo_timer_setup() API
Change-Id: I261f4dcee15942bdce82c6b8a8a558a38bedd6fe
2022-05-09 16:08:42 +02:00
Pau Espin 6b1e9515c9 llc_queue: Refactor to handle codel_state per prio queue internally
A CoDel state per prio queue is needed, otherwise the sojourn time state
is not properly reset when a high prio packet is dequeued.

If we have a global codel state shared for all prio queues of an MS, then
basically high prio (GMM) packets will "never" be dropped because they are
handled/dequeued way quicker, so it's sojourn time will be below the
threshold most probably, stopping the "dropping" state for the rest of
lower prio packets.

The handling of different codel states is moved from MS object to the
llc_queue, also offloading already loaded dl_tbf.cpp in the process.
This will also allow in the future setting different CoDel parameters
for different priority queues if needed.

Tests need to be adapted since now the CoDel and PDU lifetime are
incorporated into the llc_queue_dequeue(). Also because dequeue now also
accesses related MS fields.

Related: OS#5508
Change-Id: I2bce2e82ab6389d8a70130a5c26a966a316b0fa4
2022-04-05 11:16:17 +00:00