Commit Graph

116 Commits

Author SHA1 Message Date
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 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 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 3a7af57d03 rcv_resource_request(): Update meas before allocating and assigning new UL TBF
Those power params are applied in the Pkt Ul Ass sent to the
MS.
In practice it doesn't matter much because the Pkt Ul Ass message is
created later asynchronously by the scheduler (event CREATE_RLCMAC_MSG).
Still it's much cleaner applying the information before allocating the
UL-TBF, since that's an extra independent step.

Change-Id: I63133aa42dcf27a86437b1bc8dc83c30d6718028
2022-10-28 16:17:54 +02:00
Pau Espin 1e81b2e0a4 rcv_resource_request(): Validate expected message before MS lookup & allocation
There's no sense if doing the lookup and allocation if the message is
not expected, it will be unrefed (freed) afterwards anyway.
Moreover, this way we avoid doing stuff for the WIP code paths which act
on different request ID than TLLI.

Change-Id: I4be8858230a2eebdb33260093d082a005cb9fcd4
2022-10-28 15:39:37 +02:00
Pau Espin 36ada89373 pdch: Use helper function tbf_as_ul_tbf()
Change-Id: Ie2a0af7928578823e944b85781ce284722547661
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 0dcbc07682 bts: Add counter availablePDCHAllocatedTime
We basically want to probe whether it's possible to allocate TBFs, or
whether we know it will fail due to all main resources being already in
use (TFI, USF).

Having bts_all_pdch_allocated() return false doesn't mean though that an
MS will be able to allocate a TBF for sure. That's because further
restrictions are applied based on MS: whether it was already attached to
a specific TRX, whether the ms_class allows for a certain multislot
combination, etc. However, it should provide a general idea on whether
for sure the PCU is unable to provide more allocations. More fine
grained state about failures can still be followed by looking at
tbf:alloc:failed:* rate counters.

Related: SYS#4878
Depends: Iabb17a08e6e1a86f168cdb008fba05ecd4776bdd (libosmocore)
Change-Id: Ie0f0c451558817bddc3fe1a0f0df531f14c9f1d3
2021-11-15 11:40:07 +01:00
Pau Espin 715aeb4ebc pdch: Increase log level of line informing about TS control change
This way it's the same log level as the one used in all other paths
using tbf_assign_control_ts() to assign tbf->control_ts =
tbf->first_common_ts, and this specific event is not lost from logs.

Change-Id: Ia32d835ee4c14d7d48391452b5e3d05ed88e0483
2021-11-10 17:21:43 +01:00
Pau Espin ace3b1bdc1 pdch: Drop previous UL TBF from MS who sent PktResReq through SBA
If the MS has a pending UL TBF but we just received a PktResReq on an
allocated SBA from it (same TLLI, hence same MS), then it means it
allocated the SBA through RACH req and hence it was on CCCH. That means
it was not active on any PDCH, hence for sure the previous UL TBF can be
dropped.

Related: OS#5293

Change-Id: I1f20dba56f46ea15cbb9b03bdc5b79d923491a3c
2021-11-10 16:11:19 +01:00
Pau Espin 54a126f6d4 pdch: Update ms_reserved_slots in GprsMS when TS becomes disabled
Otherwise, after the TS is disabled, a new TBF created for that MS may
end up in alloc_algorithm assigning the disabled TS, since it will be in
the mask of reserved PDCH TS for that MS.

Related: OS#5265
Change-Id: Ifc59ac37fa6b0ad9ecc8f76326928611e748b11c
2021-11-10 11:36:55 +01:00
Pau Espin fb904fbbd9 pdch: Log DL TBF originating the new UL TBF
Change-Id: Ie4257a2468d589464d0d56882e4408e4bcfe340f
2021-11-09 14:01:40 +01:00
Pau Espin 304b10a8b5 pdch: Log TS enable/disable transitions
Change-Id: I6780634de4791382ccd25bf7b74f5286420e2c52
2021-11-09 12:22:48 +01:00
Pau Espin 20dfa54508 pdch: Log line detaching TBF at start of the function
Log before the action is done ("Detaching", not "Detached"). This way,
if something crashes we see that last line.

Change-Id: I6811d3772e2ac850741d3db5ec32be5c0812e81a
2021-11-09 12:15:23 +01:00
Pau Espin ba5683194a Add counter for successful contention resolution procedures
This counter is related to succPDTCHSeizures,
(3GPP TS 52.402 B.2.1.51 Successful PDTCH seizures).

The relevant event when the first RLC block on the PDCH from the MS is
received is the fact that contention resolution is considered as done in
the network side. Hence, name the counter that way to ease
interpretation.

Related: SYS#4878
Change-Id: I3d67e3e68907921b43f2ca4398ad9578c0b2618c
2021-11-08 18:33:04 +00:00
Pau Espin 10b29153b7 pdch::rcv_resource_request(): Use local var to store bts pointer
Change-Id: Ica727c4b70cecc0ddb5d2a235bfc416735754b61
2021-11-08 18:33:04 +00:00
Pau Espin 92cbe4aee0 pdch: Improve log line and increase log level
Change-Id: Ie593331a69f6b8ec3b21e2b274a1aa060b2dc439
2021-11-08 13:24:19 +01:00
Pau Espin 196f36b75a pdch: Log reason of expected POLL when receiving unexpected UL data
Change-Id: I914e38154029f57cbf38120495220cd860877c45
2021-10-18 12:37:51 +02:00
Pau Espin 592239630b pdch: Simplify code path allocating UL TBF
There's no real need to pass a tlli per separate, the information is
already contained in the MS. Furthermore, when doing so, it becomes
clear the TLLI was only passed to set it again on the MS, so actually
that ms_update() can be totally dropped since it will act as a no-op.

Change-Id: Ie761c3c7c222458ab0514117ae637ad3267139a0
2021-10-18 12:24:42 +02:00
Pau Espin ffa2918bc5 pdch: rcv_data_block: Avoid releasing ULC entry if expecting something else on UL
Let's only release PDCH ULC entry if it was indeed what we expected.
In other case, time it out.

Change-Id: I1537587f5ee801c633784691b576ebb1ed521e95
2021-10-12 20:07:19 +02:00
Pau Espin ffe998ce9d tbf: Document temporary change of control_ts and move code assigning it back to FSM
Change-Id: I1b7eb7802060778487e5729ee789b2323b6636f8
2021-10-12 19:32:28 +02:00
Pau Espin 7a2b65ed2c Handle Final UL ACK/NACK Confirmation in tbf_fsm
Pass the event over the FSM for better understading of the entire
lifecycle of the TBF.

Change-Id: If30d881037209d33b2b41ecf8bb8419caf36e367
2021-10-12 12:41:53 +02:00
Pau Espin 201dbe04f7 pdch: PktResReq: Avoid releasing ULC entry if expecting something else on UL
Let's only release PDCH ULC entry if it was indeed what we expected.
In other case, time it out.

Move the case in the switch statement to the start to easy function
readibility (early return style).

Change-Id: I3d8749acca8e7859295d73cce556b2083169f726
2021-10-12 12:41:18 +02:00
Pau Espin 8318d9c25d pdch: Validate poll reason matches in rcv_control_(egprs)_dl_ack_nack()
If we didn't expect this kind of UL messages according to pdch ULC, then
we shouldn't allow going forward and releasing the ULC entry: let it
time out instead so that TBF runs whatever appopiate action is needed in
this case, be it retransamission, releasing itself, etc.

Change-Id: I8ab3f5e4f2f802944269453db13a80c9ede67714
2021-10-11 18:22:01 +02:00
Pau Espin 0dbf6f2a54 pdch: Only release ULC entry if rx ul block matches the expected one
If it doesn't match out expectancies, it means we early return and hence
don't push forward / update whatever state was requested upon receival
of the UL message for the expected TBF. Hence, we shall not remove the
allocated ULC entry: in this scenario we need to keep it so that timeout
procedure times out and the tbf applies whatever measures are required,
be it retransmission, releasing itself, etc.

Change-Id: Ia69a7d92c4b5c98ec71a75605c8dc3a755e63a35
2021-10-11 18:14:32 +02:00
Pau Espin e9db5c7387 assert if tbf pointer for POLL event is NULL
The tbf pointer should always point to a valid TBF.

Change-Id: Ib607a38459802f780826f46c20a1696ec98408fb
2021-09-28 16:38:30 +02:00
Pau Espin a27fb3fce3 cosmetic: Fix missing space
Change-Id: Ib64cbf1d95dd0a881f6ace0cf9a4f517eb58ae0f
2021-09-28 16:38:30 +02:00
Pau Espin c8d2166b86 pdch: refactor rcv_control_ack() with a switch statement
This clarifies the different paths and uniforms them. Makes code far
easier to read and debug.

New improved verification already found some misehavior in some tests.

Change-Id: I7e4a88d6e004bbb7974595320ed73742162c7ad7
2021-09-28 16:05:27 +02:00
Pau Espin c276e4996d nacc: Introduce helper function nacc_fsm_exp_ctrl_ack()
Move FSM internal state checks to its own file. Re-use the helper
function in the 2 places where same stuff is checked.

Change-Id: I9ded6e1c80e6cd7bcf6883bc2e853b6dafb33f7c
2021-09-28 12:53:37 +02:00
Oliver Smith fce67bc7fa pdch: has_gprs_only_tb_attached: use m_num_tbfs
Make use of the separate GPRS counters added in previous patch
I0c0a1121b4ae5f031782e7e63a0c28eb0b6c8b42 to shorten
has_gprs_only_tb_attached.

Related: SYS#4878
Change-Id: I1dd7df2c740ea604f07c65bebcb7c0051aebf9ae
2021-09-21 10:28:52 +00:00
Oliver Smith 402451b308 Add stats: pcu.bts.N.pdch.occupied.gprs/egprs
Add stats needed for performance measurements in
3GPP TS 52.402 § B.2.1.54-55.

Split m_num_tbfs to count GPRS and EGPRS TBFs separately. Move the code
that updates m_num_tbfs and sets the PDCH_OCCUPIED stats to a separate
function, as it's mostly the same in the TBF attach and detach.

Related: SYS#4878
Change-Id: I0c0a1121b4ae5f031782e7e63a0c28eb0b6c8b42
2021-09-17 17:28:03 +02:00
Oliver Smith 35d51ca4e3 Add stats: pcu.bts.N.pdch.available/occupied
Count available PDCHs (3GPP TS 52.402 § B.2.1.38) as well as occupied
PDCHs (§ B.2.1.42-44).

Related: SYS#4878
Change-Id: I74760a68ee055510a79e80854ec7bf1521669119
2021-09-06 09:11:47 +00:00
Pau Espin 1d663d9277 pdch: Make sure pending ImmAssRej scheduled for disabled pdch are dropped
When a PDCH TS becomes disabled (eg due to dyn TS being used for a
call), we are currently freeing all attached PDCHs in order to avoid
further use of it. However, pdch_free_all_tbf() was only freeing TBFs
attached to the PDCH, that is, TBFs having a valid TFI assigned.
There are some cases where temporary dummy TBFs are created which have
no TFI assigned, such as when creating an ImmAssReject. Let's take those
into account too, and make sure they are freed.

Related: OS#5226
Change-Id: Ibfe78448ebdedc8b049c80664711e166d910f9b7
2021-09-03 16:01:37 +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 3225290d77 Move timer X2002 to tbf_fsm
Related: OS#2709
Change-Id: I94b71c60ed49d51ebdf6d6b428056b4b94354676
2021-08-23 17:14:23 +02:00
Pau Espin fbc1baa139 tbf: Merge handle_ack_nack() into rcvd_dl_ack()
There's no real use in having those 2 methods separately, and only adds
complexity. Let's merge it to have 1 TBF code path handling DL ACK/NACK.

Change-Id: I546d2e46bda96a2f551b28673464e57831c71828
2021-08-23 17:14:23 +02:00
Pau Espin 5bc6560efc tbf: Drop unuseful flag GPRS_RLCMAC_FLAG_TO_DL_ASS
The flag is only used to print some non interesting stuff, let's drop it
in order to simplify code. We can add later whatever we want in the new
shiny FSM.

Change-Id: I13f92f058c219f230d57b3c00b8ae1d187603813
2021-08-23 17:14:22 +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 432d4f3b89 tbf: Drop unuseful flag GPRS_RLCMAC_FLAG_TO_UL_ASS
The flag is only used to print some uninteresting stuff, let's drop it
in order to simplify code. We can add later whatever we want in the new
shiny FSM.

Change-Id: I20aa7f83cc4f32de129e64c74a91745b983a7b16
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 720e19e7f3 Move FLOW tbf_state transition to tbf_fsm.
Related: OS#2709
Change-Id: Ia8c7de759c195d09263fb1f083fbf6cfa3087f8d
2021-08-23 17:14:21 +02:00
Pau Espin 33e8007100 Move NULL and ASSIGN tbf_state transition to tbf_fsm
At some point later in time the state_flags will most probably be split
into different variables, one ending up in a different FSM. It is moved
so far to the exsiting FSM from the C++ class since it's easier to
access it from C and C++ code, and anyway that kind of information
belongs to the FSM.

Related: OS#2709
Change-Id: I3c62e9e83965cb28065338733f182863e54d7474
2021-08-23 17:14:21 +02:00
Pau Espin b5fece959f Revert "fix: handle NULL return of as_dl_tbf() and as_ul_tbf()"
This reverts commit d8e8ea9c8f.

Change-Id: I8000e78515b25b9be5c28a249bde330dac915dcb
2021-08-23 17:14:17 +02:00
Neels Hofmeyr d8e8ea9c8f fix: handle NULL return of as_dl_tbf() and as_ul_tbf()
Go through all callers of as_dl_tbf() and as_ul_tbf(), and make sure
they can handle the possible NULL return value.

OS#5205 reports a NULL deref crash of osmo-pcu at pdch.cpp:525. The
immediate cause is that as_dl_tbf() may well return NULL, which this
caller does not handle and instead dereferences immediately.
This is a code path that apparently assumes that a DL-TBF should always
be present. The higher level cause for the NULL DL-TBF has not been
identified.

Related: OS#5205 SYS#5561
Change-Id: I8ce21be6836549b47a606c00b793d6f005964c5c
2021-08-17 12:17:13 +00:00
Pau Espin 4f67a9bf46 pdch: Fix heap-use-after-free in pdch->ulc
In existing previous code, pdch->ulc would be freed in
gprs_rlcmac_pdch::free_resources() when  it became disabled as per PCUIF
info_ind (for instance, when a DYN TS is switched PDCH->SDCCH8).
However, pdch->ulc was so far only allocated during pdch_init, which is
only called during bts_alloc() time.
Hence, after first info_ind disabling it, if it became again enabled
(again by info_ind re-enabling it after SDCCH8 was not longer in use),
the pdch->ulc would be used again but it would point to freed memory.

Let's rearrange how/when resources are freed to make it more logical.
With this patch, pdch internal resources are freed upon ->disable(), and
re-allocated upon ->enable().

Change-Id: Id51f5f6a54ac9f24b784c17bc360ac38f5726fc7
2021-07-01 13:09:10 +02:00
Pau Espin ab178903d4 pdch: Fix null MS access gprs_rlcmac_pdch::rcv_control_ack
If bts_ms_by_tlli() at the start of the function fails, ms could be
NULL. As a result "ms->nacc" access at the end of the function would
crash.
Solution:
In the function, we get the related expected TBF from pdch_ulc, and we only
continue if a TBF is found. Since tbf objects are always expected to
have a GprsMs, simply gather it from there.

Change-Id: I666ed5d157f42e74956fa49fc9eea85d27e63d44
2021-06-23 13:50:35 +02:00
Pau Espin c6e911cf22 pdch: Log pdch_ulc reason upon rx of pkt ctrl ack
Change-Id: I7c7a421b1e9189e2814e9a28698d66655fc9ba60
2021-06-07 18:16:55 +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 c48d27b57b pdch: Use llist_first_entry() API
Change-Id: I96e7188ecf7d2cfc54598975f8d538e7aa94401a
2021-05-13 15:58:55 +02:00