== Channel allocation

Radio resource management is one of the main tasks of the Base Station Controller.
This involves selection, activation, and deactivation of logical channels, which
are maintained by connected Base Stations.  The number of usable logical channels
is limited by total number of radio carriers and may vary depending on the physical
channel combinations assigned to their timeslots.  Thus a major goal of the this
task is to manage all the available resources in an efficient way, shifting the
balance between service quality and the overall capacity.

=== Channel allocation parameters

OsmoBSC's channel allocator can be configured via the VTY interface.  All
relevant parameters are limited by the scope of a BTS node they belong to.
There is currently no way to define global configuration for all BTS.

All parameters with their respective default values are listed below:

----
network
 bts 0
  channel allocator mode chan-req ascending
  channel allocator mode assignment ascending
  channel allocator mode handover ascending
  channel allocator avoid-interference 0
  channel allocator tch-signalling-policy always
----

==== Channel allocation modes

Currently the following channel allocation modes are supported:

- ascending (default): allocates channels in ascending order,
starting from timeslot 0 of the first TRX (also called C0, the BCCH carrier);
- descending: allocates channels in descending order,
starting from timeslot 7 of the last TRX;
- dynamic (only for assignment): dynamically choose between ascending
and descending order depending on some additional parameters
(see <<chan_alloc_dyn_mode>>).

NOTE: Regardless of the chosen mode, logical channels (sub-slots) are always
selected in ascending order.  For example, if a timeslot is configured as SDCCH/8
and all 8 sub-slots are not in use, then the first SDCCH(0) sub-slot will be
selected in both ascending and descending modes.

The allocation mode to be used can be configured using the following VTY command:

----
OsmoBSC(config-net-bts)# channel allocator mode ? <1>
  set-all     Set a single mode for all variants
  chan-req    Channel allocation for CHANNEL REQUEST (RACH)
  assignment  Channel allocation for assignment
  handover    Channel allocation for handover

OsmoBSC(config-net-bts)# channel allocator mode set-all ? <2>
  ascending   Allocate Timeslots and Transceivers in ascending order
  descending  Allocate Timeslots and Transceivers in descending order

OsmoBSC(config-net-bts)# channel allocator mode assignment ? <3>
  ascending   Allocate Timeslots and Transceivers in ascending order
  descending  Allocate Timeslots and Transceivers in descending order
  dynamic     Dynamic lchan selection based on configured parameters <3>
----
<1> It's optionally possible to configure different allocation modes for
different allocation causes, e.g. `ascending` for `chan-req` and `descending`
for both `assignment` and `handover`.
<2> `set-all` is equivalent to the old (deprecated) command syntax:
`channel allocator (ascending|descending)`.
<3> The `dynamic` mode can be selected only for `assignment`.

[[chan_alloc_dyn_mode]]
===== Dynamic channel allocation mode

There exists an additional channel allocation mode, which can be employed
during a TCH channel allocation for assignment.  This mode selects between
ascending and descending order depending on pre-configured parameters:

- Uplink RxLev threshold and number of samples for averaging,
- C0 (BCCH carrier) channel load threshold.

This is useful in setups where Tx power of the RF carriers cannot be adjusted
dynamically at run-time and thus no BS Power Control can be performed.  In
such setups the BCCH carrier is transmitting at relatively higher power than
the other RF carriers.  The key idea is to allocate channels in a smarter way,
so that UEs with poor signal would get channels on carriers with high Tx power,
while UEs with good signal could use carriers with lower Tx power.

The configuration parameters for dynamic selection are listed below:

----
OsmoBSC(config-net-bts)# channel allocator dynamic-param ?
  sort-by-trx-power  Whether to sort TRX instances by their respective power levels
  ul-rxlev           Uplink RxLev
  c0-chan-load       C0 (BCCH carrier) channel load

channel allocator dynamic-param sort-by-trx-power ?
  0  Do not sort, use the same order as in the configuration file
  1  Sort TRX instances by their power levels in descending order

OsmoBSC(config-net-bts)# channel allocator dynamic-param ul-rxlev thresh ?
  <0-63>  Uplink RxLev threshold
OsmoBSC(config-net-bts)# channel allocator dynamic-param ul-rxlev thresh 50 avg-num ?
  <1-10>  Minimum number of RxLev samples for averaging
OsmoBSC(config-net-bts)# channel allocator dynamic-param c0-chan-load thresh ?
  <0-100>  Channel load threshold (in %)
----

The default values are:

----
network
 bts 0
  channel allocator dynamic-param sort-by-trx-power 0 <1>
  channel allocator dynamic-param ul-rxlev thresh 50 avg-num 2 <2>
  channel allocator dynamic-param c0-chan-load thresh 60 <3>
----
<1> Assume that RF carriers are listed in descending order sorted by Tx power.
<2> Use descending order if AVG of at least two Uplink RxLev samples >= 50 (-60 dBm).
<3> Use descending order if more than 60% logical channels of C0 are occupied.

NOTE: The final ascending/descending order decision is based on the two conditions.
The descending order will be used only if *both conditions are met*, otherwise the
allocator will use ascending order.

==== Interference aware channel allocation

The channel allocator can be configured to prefer logical channels with least
interference, based on interference measurements periodically sent by the BTSs
(see <<interf_rep>>).  This is an optional feature, which is disabled by default.

----
OsmoBSC(config-net-bts)# channel allocator avoid-interference ?
  0  Ignore interference levels (default). Always assign lchans
     in a deterministic order.
  1  In channel allocation, prefer lchans with less interference.
----

NOTE: Interference levels are compared within the scope of the whole BTS.  This
means that the selection logic may pick channels on the other TRXes, if they are
better according to the interference reports from the BTS.  This feature makes
the allocation order non-deterministic and therefore nullifies the meaning of
channel allocation modes described above.

==== TCH sigalling policy

By default, in a situation when all SDCCHs are exhausted, OsmoBSC will be using TCH
channels for signalling (e.g for Location Updating or call establishment).  This
behavior can be restricted to certain kinds of signalling or disabled completely.

----
OsmoBSC(config-net-bts)# channel allocator tch-signalling-policy ?
  never      Never allow TCH for signalling purposes
  emergency  Only allow TCH for signalling purposes when establishing an emergency call
  voice      Allow TCH for signalling purposes when establishing any voice call
  always     Always allow TCH for signalling purposes (default)
----
