Commit Graph

42 Commits

Author SHA1 Message Date
Pau Espin 38f80be73b MsTest: Set up tbf talloc destructor
This is right now not an issue, but it will be whenever talloc
destructor contains extra steps like freeing an FSM.

Change-Id: I096ff56321c8ae5e66634537aae8b95804282c65
2021-05-19 12:50:25 +02:00
Pau Espin 11f01105a0 gprs_ms: Use standarized logging on more messages
Change-Id: If7f471f4932c2347cd857cd59f761a36d9e735d1
2021-03-03 20:37:38 +01:00
Pau Espin 4fe090146f ms: clarify delayed MS release process related code and logging
Change-Id: Ieaea6ab07b4b2822bcf394f2d0e9298b9f3c5854
2021-03-03 20:28:51 +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 fc464935a4 Fix Dl EGPRS data blocks being generated occasionally on GPRS TBFs
Under some circumstances, it could happen that a DL TBF is created as a
GPRS TBF due to not yet having enough information of the MS, and only
after the TBF is created the PCU gains that information and upgrades the
MS mode to "EGPRS". Hence, there's the possibility to run into a
situation where a GPRS TBF is attached to a EGPRS MS.

It may also happen sometimes that despite the TBF and the MS be EGPRS,
there's need to further limit the DL MCS to use, eg. MCS1-4 (GMSK).

As a result, when asking for the current DL (M)CS to use, we must tell
the MS which kind of limitations we want to apply. The later reasoning
was already implemented when GPRS+EGPRS multiplexing was added, but the
former was not being checked. Hence, by further spreading through the
call stack the "req_kind_mode" we match both cases.

Related: OS#4973
Change-Id: Ic0276ce045660713129f0c72f1158a3321c5977f
2021-01-25 16:56:59 +01:00
Pau Espin 201da4e5b2 ms: Properly handle EGPRS_GMSK mode in ms_max_cs_dl/ul()
Change-Id: Ied3e02a12145112fafa12282ed7aefa5b0fa6eb6
2021-01-25 16:19:37 +01:00
Pau Espin 7bb8cd683c ms: Set proper initial MCS values setting mode EGPRS_GMSK
Before this patch, shared logic with EGPRS case would allow keeping
MCS>4.

Change-Id: I94cbf0c120fd37deb2dfd077d35b3811c7da0675
2021-01-25 16:19:37 +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 ad79b857cd Move cs_downgrade_threshold field from BTS to PCU
Change-Id: I3e1c65eb3cccff565d5d84588bdce93a47909a0f
2021-01-18 11:54:57 +01:00
Pau Espin e8dcf64881 Move cs_adj* fields from BTS to PCU
Change-Id: I2b00a83279dccd4feeeeb95e34878c4405e7972c
2021-01-18 11:54:57 +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 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 38de84cdc4 tests: ms: Pass correct pointer in constructor instead of NULL
The BTS field will be used in code paths after next patch changes,
otherwise the test fails accessing the NULL pointer.

Change-Id: I5098292bdafa9f4f70fef1a053b80a33deca722c
2020-10-26 13:46:33 +01:00
Pau Espin e9f77d377b tbf: Set MS during constructor time
This is another step forward towards a more clear data model where a TBF
always has a MS object (which may be lacking some information, and at a
later point when more information is found, it may actually be a
duplicated MS object and hence one duplicate removed and the TBF moved
to the object being kept).

This helps for instance in removing duplicated information stored in
the TBF which is really per MS, like ms_class, ta, etc. Since there's
always a MS object there's no need to keep a duplicate in both classes
in case there's no MS object.

It can already be seen looking at unit test logging that this kind of
data model already provides better information.
Some unit test parts were needed to adapt to the new model too.

Change-Id: I3cdf4d53e222777d5a2bf4c5aad3a7414105f14c
2020-10-24 22:14:42 +02:00
Pau Espin a0cbde700a tbf.cpp: Include c++ <new> header required for new operator's replacement type
Including the <new> header is required as explained by the c++ specs [1]

osmo-pcu/src/tbf.cpp: In function ‘gprs_rlcmac_ul_tbf* tbf_alloc_ul_tbf(gprs_rlcmac_bts*, GprsMs*, int8_t, uint8_t, uint8_t, bool)’:
osmo-pcu/src/tbf.cpp:1002:39: error: no matching function for call to ‘operator new(sizetype, gprs_rlcmac_ul_tbf*&)’
 1002 |  new (tbf) gprs_rlcmac_ul_tbf(bts->bts);
      |                                       ^

Most of the times this issue is not detected because other STL headers
are already including <new>.

[1] http://www.cplusplus.com/reference/new/operator%20new/

Change-Id: Ie5fb536ae29dcf40e2a0dbe67432bebd61b8c7aa
2020-03-27 15:06:41 +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 cd2ac56bd4 Remove undefined param passed to {logging,osmo_stats}_vty_add_cmds
Since March 15th 2017, libosmocore API logging_vty_add_cmds() had its
parameter removed (c65c5b4ea075ef6cef11fff9442ae0b15c1d6af7). However,
definition in C file doesn't contain "(void)", which means number of
parameters is undefined and thus compiler doesn't complain. Let's remove
parameters from all callers before enforcing "(void)" on it.
API osmo_stats_vty_add_cmds never had a param list but has seem problem
(no "void"), so some users decided to pass a parameter to it.

Related: OS#4138
Change-Id: Ic1ac815eafab49577ff883a5d700ecca5936d216
2019-08-05 14:30:47 +02:00
Max 41d6b35670 Add test for MS mode and (M)CS settings
Right now set_mode() on GprsMs behaves in pretty counter-intuitive way:
* it's possible to set current DL MCS higher than max value
* EGPRS and EGPRS_GMSK have the same max DL MCS
* setting EGPRS* mode drops current/max MCS values to unknown

Let's capture this in a unit-test before attempting any further
modifications.

Change-Id: Ibf917f4b49d927a21cbd467775806fa6ea06a6a6
2019-04-11 07:29:53 +00:00
Max 898dddb1d1 MCS: add Channel Coding Command encoder
Add function to encode MCS value as proper EDGE or GPRS Channel Coding
value according to 3GPP TS 44.060 and corresponding helpers.

Use it for everything except IA Rest Octet encoding which is done in a
follow-up patches to make sure that we distinguish between
encoding-related changes to test output and unrelated changes.

Change-Id: I127fb29f5aaf77a7f6c4c565dfeb3b711af9845d
2019-03-27 12:32:04 +00:00
Max f4d3973688 MS store: move test helper to unit test
It's confusing to have test-specific helper with the same name as tested
function directly inside the GprsMsStorage class. Let's convert it into
static function and move to the unit test.

Change-Id: Ia2a5b90779051af894fe15d957c1d26f0a142f33
2019-03-19 15:05:51 +00:00
Neels Hofmeyr 42f2d61ac9 use osmo_init_logging2() with proper talloc ctx
There is a duality of initialization: early_init() in bts.cpp wants to init
logging even before static instances get initialized. Make sure that
tall_pcu_ctx is initialized during early_init() as well. There is a build
context that does not seem to include bts.cpp (osmo-pcu-remote), so to be sure,
init tall_pcu_ctx as NULL and both in early_init() as well as pcu_main.cpp,
init both tall_pcu_ctx and logging if it is still NULL.

Change-Id: I2199b62d0270bd35dec2283e8f5b364b7c63915b
2018-04-01 16:57:42 +02:00
Neels Hofmeyr bdc55fad62 implement support for 3-digit MNC with leading zeros
Receive the mnc_3_digits flag from the PCU interface.

Bump the PCU interface to 9.
This is one part of the three identical pcuif_proto.h patches:
- I49cd762c3c9d7ee6a82451bdf3ffa2a060767947 (osmo-bts)
- I787fed84a7b613158a5618dd5cffafe4e4927234 (osmo-pcu)
- I78f30aef7aa224b2e9db54c3a844d8f520b3aee0 (osmo-bsc)

Add 3-digit flags and use the new RAI and LAI API from libosmocore throughout
the code base to be able to handle an MNC < 100 that has three digits (leading
zeros).

Depends: Id2240f7f518494c9df6c8bda52c0d5092f90f221 (libosmocore),
         Ib7176b1d65a03b76f41f94bc9d3293a8a07d24c6 (libosmocore)

Change-Id: I787fed84a7b613158a5618dd5cffafe4e4927234
2018-03-11 00:47:14 +01:00
Harald Welte ac0490ad2a tests: Don't use private version of log_info but global gprs_log_info
There's no need for each test case to carry their own log_info and
filter function.  They can simply use the global gprs_log_info and
configure the stderr log verbosity according to their needs.

Change-Id: I8706a624e5d06e062d1198711aa197fbd0860769
2017-10-29 11:02:34 +01:00
Neels Hofmeyr 78ce59137f main, tests: use msgb_talloc_ctx_init() (new)
msgb_set_talloc_ctx() is deprecated since libosmocore commit
f45334be29016a36594aacc07c90e262e4994525 / change-id
I747fbbf977c4d2c868c8dead64cfc5fd86eb8d4c

Change-Id: I8d40abec428b739460ed545c9983d1b63021bd08
2017-02-08 17:37:55 +01:00
Jacob Erlbeck cb7289094a edge: Replace integer cs by GprsCodingScheme
Currently the TBF and MS object use a plain integer value
(current_cs) to manage the coding scheme. This makes it difficult to
support the MCS schemes. GprsCodingScheme supports a partial ordering
of these values (CS and MCS) and provides safe increment and
decrement methods.

Use the GprsCodingScheme type instead of integer for cs fields and
variables. Add a 'mode' to GprsMs which can be set to either GPRS,
EGPRS, or EGPRS_GMSK which also set the initial values of
current_cs_ul/dl. Select the mode based on max_mcs_ul and max_mcs_dl.

Sponsored-by: On-Waves ehf
2016-02-01 13:58:14 +01:00
Jacob Erlbeck b6b3c7eb27 tbf: Use explicit initialisations in constructor (Coverity)
Currently when allocating tbf_alloc_ul_tbf or tbf_alloc_dl_tbf
objects, the allocated memory area is pre-initialised by talloc_zero
before the C++ constructors are called. This is not recognised by
Coverity, since there is no talloc model file yet. Thus Coverity
complains about missing initialisers.

On the other hand, it is still planned to convert the TBF classes
into real C++ ones. So instead of silencing Coverity directly, this
is an opportunity to do it the C++ way.

This commit adds initialisers and initialisation code for all
members that relied on talloc_zero. The corresponding calls to
talloc_zero are replaced by calls to talloc to give ASAN/valgrind
a chance to detect future initialisation errors. Some initialisation
code is also moved from setup_tbf to the constructors, notably the
initialisation of the bts pointer.

Fixes: Coverity CID 1320604, 1320605, 1320606

Sponsored-by: On-Waves ehf
2015-08-28 12:07:14 +02:00
Jacob Erlbeck 6835cead8c ms: Store references to replaced TBFs in the MS object
Currently when calling GprsMs::attach_tbf and a TBF of the same
direction already exists, the old TBF gets detached from the MS
object.

Therefore that TBF object loses access to that MS object including
for instance TLLI and IMSI.

This leads to failing DL TBF reuses, since the downlink assigment
cannot be sent on the PACCH later on because that must be sent on the
old DL TBF which ms() is NULL and the new DL TBF cannot be retrieved.

This commit fixes this bug by changing the GprsMs implementation to
keep a list of replaced (old) TBFs. TBFs are only removed when they
are being detached explicitely (see tbf_free and set_ms).

Addresses:
tbf.cpp:741 We have a schedule for downlink assignment at uplink
TBF(TFI=1 TLLI=0xf35a680e DIR=UL STATE=RELEASING), but there is no
downlink TBF

Sponsored-by: On-Waves ehf
2015-08-24 12:23:50 +02:00
Jacob Erlbeck 444bc82081 tbf: Use C++/talloc magic to support TBF constructors/destructors
The TBF object are currently created by using talloc_zero/talloc_free
directly from plain functions. Therefore C++ constructors and destructors
are not called. So the only initialisation that is done is setting
every member to 0. Non POD members do not have their constructors
called either, which makes it impossible to use the current LListHead
class for real members when the LListHead::m_back member has to be set.

This commit changes the TBF allocation functions to call the
corresponding C++ constructor after the call to talloc_zero and to
register the C++ destructor with the talloc context, so that is is
called before talloc_free actually frees the memory.

With this change, non-POD members and custom
constructors/desctructors can be used with gprs_rlcmac_tbf,
gprs_rlcmac_dl_tbf, and gprs_rlcmac_ul_tbf.

Note that this change is only a single step of the plan to turn the
TBF classes into real C++ classes.

Sponsored-by: On-Waves ehf
2015-08-24 12:23:50 +02:00
Jacob Erlbeck ac89a555fa ms: Add tbf() method to get the TBF based on the direction
To avoid the need for a switch or conditional statement when needing
a TBF from an MS object in direction independant code, this method
contains that case distinction. For additional flexibility, a
reverse() function is added to get the opposite direction.

Sponsored-by: On-Waves ehf
2015-07-03 13:17:22 +02:00
Jacob Erlbeck 70b96aa232 ms: Reduce DL CS level if only a few LLC bytes are left
If just a few bytes are left to send to the MS, it makes sense to
reduce the coding scheme level to increase the throughput. This
has been shown by Chen and Goodman in their paper "Theoretical
Analysis of GPRS Throughput and Delay". See their throughput over C/I
measurement graphs (figures 4 and 5 in the paper) for details.

This commit implements a simplified CS downgrade feature for the
downlink. The coding scheme will be downgraded if there are only a
few octets are left to be send over the TBF (see the
downgrade-threshold command below) and the NACK rate is not low (the
CS will not get degraded on a high quality RF link). As an exception,
CS-3 will be degraded to CS-1, since CS-2 does not improve the
throughput in general when a few small packets are sent and the
signal fades slowly (see Chen/Goodman).

The following VTY command is added to the config-pcu node:

- cs downgrade-threshold <1-10000>
- cs no downgrade-threshold

to set the threshold of the number of remaining bytes to be RLC/MAC
encoded. The CS will only be reduced, if the number is below the
threshold. The 'no' command disables this feature completely. The
default value is 200 octets.

Sponsored-by: On-Waves ehf
2015-06-22 10:39:06 +02:00
Jacob Erlbeck 17214bb06d ms: Add back pointer to BTS
Since more functionality will be moved to the GprsMs class, a pointer
to the current BTS object is added to allow access to configuration
data and other methods.

Sponsored-by: On-Waves ehf
2015-06-08 09:39:07 +02:00
Jacob Erlbeck d9e102472a ms: Add timer
Currently the MS object is immediately idle when all TBFs are
detached and if no guard is being used. Since the plan is to use the
MS objects to pass information from one TBF to the next one even
across the gap of some seconds of inactivity, a mechanism is needed
to keep the MS objects around for some time.

This commit extends the GprsMs class by a timer that keeps the MS
objects in non-idle state for some time after all TBFs have been
detached. The set_timeout method must be used with a non-zero value
to activate this feature.

Sponsored-by: On-Waves ehf
2015-05-28 16:38:16 +02:00
Jacob Erlbeck 7b9f825ae8 ms: Use the IMSI to retrieve the MS object
This commit extends get_ms() to really compare the IMSI if it has
been given. Matching by TLLI has a higher precedence than matching by
IMSI.

Ticket: #1674
Sponsored-by: On-Waves ehf
2015-05-28 12:29:40 +02:00
Jacob Erlbeck 0e50ce6145 tbf: Always call set_tlli/confirm_tlli in update_ms
Currently the m_tlli member in GprsMs is set by the constructor,
circumventing the TLLI confirmation mechanism.

This commit replaces the get_or_create_ms() method by a create_ms()
method which takes the TLLI and the direction (UL or DL) as
parameters to select either set_tlli() or confirm_tlli(). The MS
object is instantiated with TLLI = 0, and therefore GprsMs::tlli() is
extended to return the DL TLLI if both of the other TLLI are not set.

Note that create_ms() will not check whether an MS object with a
matching TLLI is already stored in the list, so it should only be
called after a corresponding get_ms() in general.

Sponsored-by: On-Waves ehf
2015-05-27 13:30:01 +02:00
Jacob Erlbeck 9399046729 ms: Support new and old TLLIs
According to the specification (GSM 04.08/24.008, 4.7.1.5) after a
new P-TMSI has been assigned, the old P-TMSI must be kept basically
until it has been used by both sides. Since the TLLI will be derived
from the P-TMSI, the old TLLI must also be kept until the new TLLI
has been used by both MS and SGSN.

This commit modifies the TLLI handling of GprsMs accordingly.
set_tlli() is only used with TLLIs derived from MS messages,
confirm_tlli() is used with TLLIs derived from messages received from
the SGSN. tlli() returns the value set by the MS. check_tlli()
matches each of the TLLI used by either MS or SGSN as well as the old
TLLI until it has been confirmed.

Sponsored-by: On-Waves ehf
2015-05-21 17:10:42 +02:00
Jacob Erlbeck 5367086175 ms: Add MS storage class
Currently the MS objects are contained in the TBF objects only. To
allow for an extended life time after the TBF objects have been freed
and to find them based on TLLI, a container for the MS objects is
needed.

This commit adds the container class and also adds the corresponding
m_list member to GprsMs. Further integration into the PCU code is not
yet done.

Ticket: #1674
Sponsored-by: On-Waves ehf
2015-05-20 11:36:12 +02:00
Jacob Erlbeck dfef28de88 llist: Add a C++ wrapper for linux_list
This commit adds the LListHead class which is a wrapper around the
linuxlist. It adds an additional member to refer to the container,
since the container_of macro doesn't work properly with C++ classes.
All functions and macros from linuxlist.h are support except for the
entry macros (e.g. llist_entry, llist_for_each_entry, ...). To access
the container (entry), an entry() method is provided instead:

  llist_for_each(pos, &elems) {
      pos->entry()->do_something();
  }

Sponsored-by: On-Waves ehf
2015-05-20 11:36:06 +02:00
Jacob Erlbeck e04e0b0a20 ms: Add GprsMs class to hold per-MS information
Currently only TBF objects are used to handle the data flow between
the MS and the SGSN. MS specific data (e.g. pending LLC frames, TLLI)
is copied between successive TBFs. If all TBFs (uplink and downlink)
are idle for some time, all information about the MS is discarded in
the PCU. This makes the implementation of some features more
difficult, e.g. proper TLLI and timing advance handling,
connection based CS selection, and proper management of multiple TBF.

This commit adds the GprsMs class that is intended to hold
information directly related to the MS and to keep references to the
active TBFs.

The class is not yet integrated with the other PCU code. A GprsMs
object container and MS specific fields (TA, CS) will be added in
later commits.

Note that calling detach_tbf() can possibly delete the MS object
depending on the callback implementation.

Ticket: #1674
Sponsored-by: On-Waves ehf
2015-05-20 11:30:41 +02:00