> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/tposs/6.14/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/components/tposs/6.14/use-cases/availability-cases/tposs-ha.md).

# High availability

For high availability (HA) in a production deployment, it is recommended to setup at least three TPOSS replicas to handle all incoming
requests and maintain sessions status during the upgrade procedure. It could be
configured using this configuration option:

```yaml
replicaCount: 3
```

The additional configuration options to maintain TPOSS for high availability (HA) are:

```yaml
podIP:
  enabled: true
  liveness:
    initialDelaySeconds: 15
    timeoutSeconds: 3
    periodSeconds: 10
    failureThreshold: 5
  readiness:
    initialDelaySeconds: 20
    timeoutSeconds: 3
    periodSeconds: 10
    failureThreshold: 5

probes:
  enabled: true

terminationGracePeriodSeconds: 30
```

- `podIP` enables special naming for TPOSS nodes so each TPOSS node
knows how to do service discovery for other TPOSS nodes and all of
the deployed TPOSS instances know how to build a cluster.
- `probes` enables liveness and readiness probes, which can be useful for
graceful termination during TPOSS cluster upgrade. For more information about probes, see the [official Kubernetes documentation](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#configure-probes).
- `terminationGracePeriodSeconds` specifies the number of seconds for a termination
grace period. As TPOSS node receives the `SIGTERM` signal, the TPOSS node
is marked as `not ready` and it waits the specified period of time
to finish handling of all requests.

>**NOTE:** The value of `terminationGracePeriodSeconds` should be at least `DNS TTL` configured within cluster + `5` seconds.

After all TPOSS instances are up and running, run the `Tposs.Utils.get_nodes` command to
make sure that each TPOSS instance is connected to the cluster. This
command returns the list of all known nodes, so in the case of 3 replicas
it looks like this:

```
iex(tposs_tisp@10.42.106.11)1> Tposs.Utils.get_nodes()

[:"tposs_tisp@10.42.106.11", :"tposs_tisp@10.42.175.137",
 :"tposs_tisp@10.42.6.130"]
```

For more information on how to execute commands within TPOSS and get into TPOSS
remote console, read the [Troubleshooting guide](https://docs.cennso.com/components/tposs/6.14/troubleshooting.md).

The upgrade procedure is executed using the `helm upgrade` command. For more information
see the [Installation guide](https://docs.cennso.com/components/tposs/6.14/installation.md).

>**NOTE:** It is worth to upgrade TPOSS cluster only when there is minimal number of active users.

## Database configuration

TPOSS should have the ability to connect to MySQL service from the start-up.
The main TPOSS configuration related to the database connection is:

```yaml
database:
  host: db-host
  user: db-user
  password: db-password
  ssl: false
  ssl_versions: tlsv2
  # Number of connections within the database connection pool
  connections: 50
  # Timeout in milliseconds to wait for a free connection from the database connection pool
  queue_target: 50
  # Size of TCP buffer used by client sockets
  recbuf: 87380
  # The time in milliseconds to wait for the query call to finish
  timeout: 30000
  # The values configure the upper limits for round trip time intervals of database queries.
  # The limits are translated into Prometheus histogram buckets. The values are provided in milliseconds.
  query_histogram_buckets: "5, 20, 50, 100, 250, 500, 1000"
  # The values configure the upper limits of time intervals that queries spent in the queue.
  # The limits are translated into Prometheus histogram buckets. The values are provided in milliseconds.
  queue_histogram_buckets: "1, 5, 20, 50, 100, 250, 500"
```

In addition, new versions of TPOSS may need database migrations. It should be enabled using this command:

```yaml
tposs_migrate_db_on_start: true
```

TPOSS may store PCS sessions in different databases. The currently supported databases are:

- Mnesia
- MySQL

The MySQL database is preferred for TPOSS HA as it leads to much easier and stable upgrades. The backend for the PCS sessions can be configured using this configuration option:

```yaml
sessions:
  backend: mysql
```

### Sessions behaviour configuration

TPOSS provides a couple of configurable parameters that may control different aspects of behavior of PCS sessions.

TPOSS uses a global lock across all the TPOSS instances within the cluster to avoid potential race conditions. In the new version of TPOSS we provide following new configuration option to disable the lock:

```yaml
sessions:
  global_lock_enabled: true
```

>**NOTE:** This configuration option is experimental and should be used with caution. Although the disabled lock may bring significant improvements in resource consumption, it also might be a reason for unexpected behavior if TPOSS receives two RADIUS or Diameter requests with the same identifier (`IMSI` or `Session-Id`).

All the PCS sessions (network and service sessions) are stored in MySQL database. There is an **experimental** feature that may allow to store PCS sessions in the in memory caches during session creation time. This behavior can be controlled with the following configuration options:

```yaml
sessions:
  cache: false
  cache_backend: ets
  redis:
    host: "localhost"
    port: 6379
    username: nil
    password: nil
    connections: 50
```

If the `sessions.cache` is enabled, TPOSS start to store intermediate representation of sessions in the in memory cache. Only when the session is fully established it is inserted in the database. The type of the in-memory cache depends on the value of the `sessions.cache_backend` configuration option. For this moment two following values are supported:

- `ets`
- `redis`

If the cache backend is set to **redis** all the other redis related configuration options should be configured with the respective values.

Besides caching of the PCS sessions, TPOSS provides support for caching of charging data like `charging accounts` and `balances`. To enable this feature you may use the following configuration option:

```yaml
ccs:
  cache:
    enabled: false
```

>**NOTE:** Both of these features are experimental and must be used with caution. If the **sessions.cache_backend** is set to `ets`, it can be used only with the Diameter Proxy `v1.1.0` version and the `sticky sessions` feature enabled.

### Idle session configuration

Each network and service session is usually stored in the database during the whole session lifetime. However, if TPOSS does not receive any updates for a given session from PGW or SCG, it may terminate the sessions as `idle sessions`.

This functionality is configured with the **keepalive_timeout** parameter. The following configuration options may control this behaviour:

```yaml
sessions
  ggsn:
    # How long network session is stored in database if interim
    # requests are not arrive. For some environments where TPOSS
    # can't notify PGW about session termination it should be set
    # to zero.
    keepalive_timeout: 5400
  scg:
    # How long network session is stored in database if interim
    # requests are not arrive.
    keepalive_timeout: 5400
  # Enables or disables idle timer for PCS sessions
  idle_timer_enabled: true
```

If the **keepalive_timeout** value is `0` or the **idle_timer_enabled** is `false`, the session's idle timer is disabled. If the idle timer functionality is enabled, TPOSS starts the idle timer process. The process checks the idle time of sessions every five seconds. If there is an idle service session, TPOSS terminates it without any notification and deletes it from the database. If there is an idle network session with an idle time higher than the **keepalive_timeout** value, TPOSS starts the process of terminating this session by sending the RADIUS `Disconnect` request to PGW. The further behaviour depends on the response:

- `Disconnect-ACK` - TPOSS expects a RADIUS `Accounting-Stop` request for the network session
- `Disconnect-NAK` - TPOSS immediately terminates the network session and deletes it from the database
- If there is no answer, the next try for a session termination is postponed for ten seconds.

After the session is terminated on the TPOSS side, the idle process keeps checking for idle sessions every five seconds.

The following diagram depicts the described procedures:

```mermaid
sequenceDiagram

participant PGW
participant RPR
participant TPOSS
participant MYSQL

note over TPOSS: Finds Sessions that are longer inactive then configured timeout
activate TPOSS
TPOSS --> MYSQL: Delete Service Session
TPOSS      ->>  RPR: RADIUS: Disconnect-Request
RPR        ->> PGW: RADIUS: Disconnect-Request

deactivate TPOSS
alt PGW answers with Disconnect-ACK
  activate TPOSS
  PGW   -->> RPR: RADIUS: Disconnect-ACK
  RPR     -->> TPOSS: RADIUS: Disconnect-ACK
  deactivate TPOSS
  PGW   -->> RPR: RADIUS: Accounting-Stop
  RPR     -->> TPOSS: RADIUS: Accounting-Stop
  activate TPOSS
  TPOSS --> MYSQL: Delete Network Session
  deactivate TPOSS
else PGW answers with Disconnect-NAK
  PGW   -->> RPR: RADIUS: Disconnect-NAK
  RPR     -->> TPOSS: RADIUS: Disconnect-NAK
  activate TPOSS
  TPOSS --> MYSQL: Delete Network Session
  deactivate TPOSS
else No answer or other errors
note over TPOSS: Try again in 10 seconds

end
```

## RADIUS configuration

TPOSS receives RADIUS requests from PGW to authorize sessions and maintain their state based on RADIUS accounting requests. For this case, specify RADIUS listeners. For example:

```yaml
radius:
  ## RADIUS Auth listener
  auth_listen: 0.0.0.0:1812

  ## RADIUS Acct listener
  acct_listen: 0.0.0.0:1813
```

Only RADIUS requests from the known source addresses are accepted by the TPOSS RADIUS servers. This behaviour can be configured via:

```yaml
radius:
  auth_source:
    ggsn: nas-identifier:secret@0.0.0.0
    scg:  nas-identifier:secret@0.0.0.0
  acct_source:
    ggsn: nas-identifier:secret@0.0.0.0
    scg:  nas-identifier:secret@0.0.0.0
```

- `ggsn` specifies source addresses for RADIUS requests from PGW
- `scg` specifies source addresses for RADIUS requests from `SCG`

>**CAUTION:** Most RADIUS metrics have labels that specify the NAS name and source IP of the incoming request. Setting wide IP ranges in the configuration of the accepted source addresses may lead to high resource consumption and performance degradation.

Both authorization and accounting listeners may track time of incoming requests handling. For this purpose, you can configure the histogram buckets using this option:

```yaml
radius:
  rtt_histogram_buckets: "10, 30, 50, 75, 100, 1000, 2000"
```

As TPOSS does not only receive RADIUS requests but also may send RADIUS `Disconnect` requests towards PGWs, provide the addresses of PGWs or RADIUS agents that are able to forward requests towards PGW.

```yaml
radius:
  connect_coa: secret@eradiusd-1-rpr:3799, secret@eradiusd-2-rpr:3799
```

## Diameter configuration

To receive incoming Diameter requests from LGW/SCG, specify Diameter listener along with other Diameter options within configuration.

The Diameter listener should be enabled via these configuration options:

```yaml
scg:
  diameter:
    enabled: true
    listener: "aaa://0.0.0.0:3868"
    # Enable NAT-binding on Diameter NASREQ-AAR requests
    enable_cgnat: true
    # Allow TPOSS to create service sessions based on Diameter NASREQ-AAR requests
    creation_on_nasreq: true
    # Return user data (like `IMSI`, `Called-Station-Id`, and `Calling-Station-Id`)
    # from TPOSS on Diameter NASREQ-ACR requests
    userdata_on_nasreq: true
```

To identify TPOSS as a Diameter agent, it should have own `Origin-Realm`:

```yaml
scg:
  diameter:
    realm: "tposs-realm"
```

Here are the additional Diameter configuration options that may control Diameter connections, timeouts
and behavior of other aspects of Diameter:

```yaml
scg:
  diameter:
    # Timeout in milliseconds for ASR requests
    asr_timeout: 5000
    # Timeout in milliseconds for RAR requests
    rar_timeout: 5000
    # Size of diameter receive buffer in bytes
    recbuf: "1048576"
    # Size of diameter send buffer in bytes
    sndbuf: "1048576"
    # Size of in memory buffer for diameter requests/responses
    buffer: "1048576"
    # Timeout in seconds how long wait Gy terminate requests
    wait_time_gy_terminate: 10
    # Amount of connections that could be accepted by Diameter server
    pool_size: 100
    # The values configure the upper limits for time intervals of handling incoming Diameter requests. 
    # The limits are translated into Prometheus histogram buckets. 
    # The values are provided in milliseconds.
    rtt_buckets: "10, 30, 50, 75, 100, 1000, 2000"
```

For more information, see the [TPOSS configuration](https://docs.cennso.com/components/tposs/6.14/configuration/configuration.md) document in the `TPOSS` component documentation.

## Charging rules configuration

You should specify the list of rating groups for TPOSS with respective names to allocate charging rules and handle charging reports:

```yaml
scg:
  adc_rules:
    online: "Online"
    portal: "Portal"
    non_whitelisted_imei: "FactoryTest"
    unlimited_streaming: "UnlimitedStreaming"
    unlimited_streaming_pd: "UnlimitedStreamingPD"
    online_redirection: "OnlineRedirection"
    b2binternet: "B2BInternet"

  rating_groups:
    online: 3220
    portal: 3221
    non_whitelisted_imei: 2100
    unlimited_streaming: 3000
    unlimited_streaming_pd: 3100
    online_redirection: 3224
    b2binternet: 3225

  rating_groups_validity_time:
    online: 180
    portal: 180
    b2binternet: 180
    non_whitelisted_imei: 180
    unlimited_streaming: 180
    unlimited_streaming_pd: 180
    online_redirection: 180
```

To disable the `unlimited_streaming` charging rule, use this configuration option:

```yaml
scg:
  unlimited_streaming:
    enabled: false
```

To configure the traffic quota that is allocated for the sessions with the `B2BInternet` charging rule, use this configuration option:

```yaml
scg:
  b2b_internet_quota: 1073741824
```

## IP pools configuration

To allocate `Framed-IP-Address`, TPOSS uses IP pools. They are specified via these configuration options:

```yaml
ippools:
  wan_ip_range:
    range: 10.192.0.0-10.193.255.254
    blocks: 20
    allow_to_decrease_number_of_blocks: false
    initial_active_blocks: 1
    reactivate: 95
    mark_inactive: 100
    packed: 75

ippools_selectors:
  wan_ip_range: "Called-Station-Id:apn.example.com"
```

- `wan_ip_range` - a name of the pool which defines certain IP range where IPs are allocated from.
- `blocks` - the number of sub-blocks into which the IP pool is split. The IP blocks are distributed over TPOSS instances within cluster.
- `allow_to_decrease_number_of_blocks` - the boolean value that provides the ability to decrease the number of blocks. TPOSS ignores the new number of blocks if the value of **allow_to_decrease_number_of_blocks** is set to `false` and the new number of blocks is lower than the previous one. In such a case, the original number of blocks is used.
- `mark_inactive` - the percentage of block usage after which the block is marked as `inactive`. After the block is marked as `inactive`, TPOSS does not allocate IPs from this block anymore but only populates it back when IPs are released.
- `packed` - the percentage of used IPs from a given block after which TPOSS tries to pre-fetch a new block of IP addresses.
- `reactivate` -  the percentage of busy IPs within the inactive block after which the IP block that previously was marked as `inactive` is marked as `active` again and TPOSS continues to use it.
- `ippools_selectors` - the mapping between pool names and their selectors based on the RADIUS attribute and its value.
- `initial_active_blocks` - the number of blocks to activate initially per instance (use this to spread ip-usage over the range).

If TPOSS allocates IP addresses, set this configuration option to `false` to handle RADIUS `Access-Request` requests from PGW properly:

```yaml
radius:
  ggsn_creation_on_accounting: false
```

By default, allocated Framed IP addresses are stored in the MySQL `ip` table. To reduce the number of database queries needed for allocation of the Framed IP address, the following configuration option can be used:

```yaml
sessions:
  store_ip_within_network_sessions: false
```

If the value of this option is set to **true**, the separate `ip` table is not used anymore and allocated IP addresses are stored only in the network session table.

>**NOTE:** The `sessions.store_ip_within_network_sessions` feature is experimental. The new behavior is disabled by default to preserve backward compatibility with the previous versions of TPOSS.

### Change IP pools block size and count

>**CAUTION:** Change the IP pool block count only when the system is not under heavy load as it may affect the production environment. The ability to decrease the number of blocks is disabled by default as it may lead to ineffective usage of blocks when TPOSS is under load. You can change this behaviour by setting the **ippools.{range-name}.allow_to_decrease_number_of_blocks** to `true`, although it is not recommended.

You can change the IP pool block count, for example, to have new blocks activated more frequently and spread the IP usage better over the range. You can also increase the block count to avoid bottlenecks that occur due to heavy usage.

There are two ways to change the IP pool block count. The first one is to adjust the TPOSS cluster configuration followed by a restart. To change the block count, adjust the **ippools.{range-name}.blocks** configuration option. As a result, the next starting TPOSS instance will migrate the existing blocks to the desired size and count.

The second way is to adjust the number of blocks for the given IP pool at runtime without TPOSS restart. To do so, use the following command in the TPOSS remote console:

```elixir
> :rpc.multicall(Tposs.Utils, :put_conf, [[:pcs, :ippools, :{range-name}, :blocks], {block-count}])
{[:ok, :ok, ...], []}
> Tposs.Pcs.IpPools.run_cache()
[nil]
```

* `range-name` is an Elixir atom defined in the TPOSS values file at the path `ippools.{range-name}`.
* `block-count` is an integer with a static value set in the TPOSS values file at the path `ippools.{range-name}.blocks`.

>**NOTE:** If you change the number of blocks at runtime, adjust this IP pool configuration also in the `values.yaml` file. Otherwise, TPOSS will continue to use the original number of blocks after the restart.

## Service profiles configuration

To allocate Framed-IP-Address(es), TPOSS must know which IP pool to use. For this case, TPOSS must check a service profile of a given subscriber. Service profiles are provisioned by TPOSS during startup. You can specify them with the following configuration:

```yaml
profiles:
 DE:
   zone_id: MOBILE
   nat_pool_id: pool-de
   ippools: wan_ip_range
   primary_dns: 8.8.8.8
   secondary_dns: 8.8.8.8
```

Each service profile may contain a set of IP pools separated by a comma. In such a case, the IP pool selector is used to find a proper pool. If there is no match, a random pool is used.

In the example above, **DE** specifies `homecountry` for the given service profile. These configuration keys must be unique across all service profiles. If you need to specify multiple service profiles with the same `homecountry`, provide the name of the `homecountry` in the **name** parameter:

```yaml
profiles:
  DE-1:
    name: "DE"
    zone_id: MOBILE
    nat_pool_id: pool-de-1
    ippools: wan_ip_range-1
    selector: "Called-Station-Id:apn1.example.com"
    precendence: 0
    subscriber_required: true
  DE-2:
    name: "DE"
    zone_id: MOBILE
    nat_pool_id: pool-de-2
    ippools: wan_ip_range-2
    selector: "Called-Station-Id:apn2.example.com"
    precendence: 0
    subscriber_required: true
```

In this case, the service profiles are identified by **DE-1** and **DE-2** parameters.

When TPOSS receives a RADIUS Access-Request request, it goes over all pre-configured service profiles and tries to find one to apply for the given user. The service profile selector is an optional configuration parameter that is represented by the **profiles.{NAME}.selector** field. The selector represents a set of key-value pairs split by a comma. Each key-value pair should be split by a colon `:`. The key represents the name of RADIUS AVP. The value is a regular expression that represents a value of this RADIUS AVP. TPOSS checks the selector of each service profile. If it is matched and the name of the home country is matched with the home country associated with the user, the service profile is applied.

The user may not have a provisioned subscriber or associated service profile in the TPOSS database. You may specify service profiles that are not required to have subscribers for users with the **profiles.{NAME}.subscriber_required** configuration parameter. Such service profiles should not specify IP pool configuration.

>**NOTE:** If the service profile do not specify an IP pool range, TPOSS will accept such users anyway but an IP address will not be allocated.

The **profiles.{NAME}.precedence** configuration parameter specifies the precedence of the service profile. If TPOSS finds two or more service profiles that can be applied for a user, the service profile with the highest precedence is selected and applied. You can change the precedence at runtime using the following API:

```elixir
Tposs.change_profile_precendence(profile_id, precedence)
```

- `profile_id` is the `{NAME}` of the service profile. The data type of `profile_id` is atom, so if the profile ID is `DE`, it should be passed as `:'DE'`.
- `precedence` is an integer number that represents the new value precedence for the given service profile

>**NOTE:** Don't set **precedence** to value other than `0`. It should be used only in the maintenance mode. If you change this value at runtime, TPOSS does not preserve it after a restart and uses the original value instead. To preserve this value, adjust the `values.yaml` configuration file.

## Tariffs configuration

The set of tariffs is provisioned by TPOSS during start-up of the TPOSS instance. For each tariff, a tenant should be configured via:

```yaml
tariff:
  tenant: tposs.cennso.net
```

To reprovision new tariffs, the following API exists:

```yaml
Tposs.init_tariffs("new-tenant-name")
```

After running this command, the following new tariffs are reprovisioned into the database:

- `online@tariff.new-tenant` - TPOSS allocates a quota from a valid balance if such exists. The balance is selected based on the carrier and `IMSI`.
- `blocked@tariff.new-tenant` - The RADIUS Access-Request request is rejected for a subscriber with this tariff.
- `home-country-change@tariff.new-tenant` - Only the `Portal` rating group is allocated for a subscriber with this tariff.
- `operator-swap@tariff.new-tenant` - Only the `Portal` rating group is allocated for a subscriber with this tariff.
- `default@tariff.new-tenant` - Only the `Portal` rating group is allocated for a subscriber with this tariff. TPOSS allocates a quota from a valid balance if such exists. The balance is selected based on the `IMSI`.
- `b2binternet@tariff.new-tenant` - The pre-configured quota is allocated at each `update` request. The amount of quota is taken from the value of the **scg.b2b_internet_quota** configuration option.

To get more information on how to execute TPOSS commands, see the [Troubleshooting guide](https://docs.cennso.com/components/tposs/6.14/troubleshooting.md).

## CDRs configuration

When SCG sessions is terminated or a balance is exhausted by validity time or by quota, TPOSS creates
a CDR record. TPOSS may write CDRs to multiple destinations. The regular targets are the file-based backend
and the database backend.

The following configuration is supported by TPOSS:

```yaml
cdr:
  controller:
    database:
      enabled: true
      partitions_enabled: true
      initial_partitions_amount: 8
      partitions_duration: 1-hour
      new_partitions_amount: 8
      cdr_cleanup_period: 4-days
      watcher_timeout: 300000
      cdr_cleanup_limit: 10000
      clean_up_partitions_at: ""
    file:
      enabled: true
      dir: /srv/data/cdrs
      time_window: 180
      max_count: 20000
      file_name_format: tposs_{start_at:ISO8601:UTC:STRIPPED}_{batch_id}_{sha256}.csv
```

- partitions_duration - how long partition is considered as active
- new_partitions_amount - how many partitions create when the currently active partition is last one
- cdr_cleanup_period - how long preserve CDR partitions

It is recommended to enable CDR table partitioning using the `cdr.controller.database.partitions_enabled`
option.

The `partitions_duration` and `cdr_cleanup_period` accept different time units:

- 14-days
- month
- 2-minutes

The supported amount part consists of a positive integer and time unit. The support time units are:

- second(s)
- minute(s)
- hour(s)
- day(s)
- week(s)
- month(s)
- year(s)

The `clean_up_partitions_at` is optional configuration option that may contain a string value in "HH:MM"
format. If the configuration value is not empty - TPOSS provisions event for deletion of outdated
CDR partitions that should be triggered once per-day in the given time. That could be useful to run deletion
of partitions in less busy time to not bring impact of operations related to partitions on other database
queries.  If this configuration option is set to empty string - `""` the event to delete outdated partitions
is triggered each `7` minutes. The time zone of the given time depends on the time zone configured at the
database server.

If deletion of partitions is triggered once per-day and it is failed by some reasons
or it should be triggered during maintenance time - the missed deletion of partitions
could be triggered manually with mysql client via calling this procedure:

```sql
CALL drop_partitions(14, 'day')
```

with suitable arguments where the second argument specifies unit of time and the first argument specifies
amount of such units after which a partition could be considered as outdated.

If partitions are disabled, the special process watches for CDR table and deleted `outdated` CDR
records. The following options control the behaviour of this process:

- `watcher_timeout` - timeout in milliseconds that specifies how often to check CDR table
- `cdr_cleanup_limit` - limit of how many CDRs should be removed at once. The supported values are any positive integer values or the string `all`.

To write CDRs on a disk, a PersistentVolume must be provided:

```yaml
persistence:
  enabled: false
  accessMode: ReadWriteOnce
  size: 20Gi
  storageClass: "storage-class"
```

In addition, you can enable an SFTP container so that CDRs can be fetched from an external system for further CDR processing:

```yaml
sftp:
  enabled: false
  image:
    repository: registry.cennso.com/tposs/tposs-cdr-exporter-sftp
    tag: v1.1.0
    pullPolicy: IfNotPresent
  service:
    type: LoadBalancer
    port: 2287
    loadBalancerIP: ""
  sftpConfig:
    password: "$1$RsBlW1hk$/ISHFEK0yrEX8M7x9.lbB1"
```

The `sftpConfig` must contain a password that was hashed using the `crypt` algorithm. For the example the configuration above has: `sftpConfig.password = "$1$RsBlW1hk$/ISHFEK0yrEX8M7x9.lbB1"` which is the value that was obtained by the result of the following command:

```
openssl passwd sftp-pass
```

The username of the sftp user is `sftp` and can not be changed.

## Hooks configuration

TPOSS supports a set of events. Each of them can be enabled or disabled. If an event is enabled, provide a pre-configured endpoint to TPOSS for sending events.

The following events are supported:

- `hook.balance.volume.threshold` - event is triggered on a volume threshold by the configurable level of consumption
- `hook.mccmnc.changed` - event is triggered on the change of Mobile Country Code and Mobile Network Code (MCCMNC)
- `hook.visited_country.changed` - event is triggered on the change of a visited country
- `hook.network_attachment.first` - event is triggered on the first attachment to the network
- `hook.charging_rules.changed` - event is triggered on the change of charging rules of a subscriber

The events can be configured via the following configuration options:

```yaml
hooks:
  visited_country_changed:
    enabled: false
    event: tposs/location/visitedCountry/updated
    attempts: 3
    delay: 300
    url: http://localhost:8086/test/consumer
    proxy:
      enabled: false
      addr: http://localhost:8086
  mccmnc_changed:
    enabled: false
    event: tposs/location/mccmnc/updated
    attempts: 3
    delay: 300
    url: http://localhost:8086/test/consumer
    proxy:
      enabled: false
      addr: http://localhost:8086
  balance_volume_threshold:
    enabled: false
    event: tposs/charging/balance/updated
    level: 0.8
    attempts: 3
    delay: 300
    url: http://localhost:8086/test/consumer
    proxy:
      enabled: false
      addr: http://localhost:8086
  network_attachment:
    first:
      enabled: false
      event: tposs/network/attachment/first
      url: http://localhost:8080/test/consumer
      attempts: 3
      delay: 300
      proxy:
        enabled: false
        addr: http://localhost:8086
  charging_rules_changed:
    enabled: false
    event: tposs/charging_rules/changed
    attempts: 3
    delay: 300
    url: http://localhost:8086/test/consumer
    mcc_whitelist: ""
```

For more information, see the [TPOSS configuration](https://docs.cennso.com/components/tposs/6.14/configuration/configuration.md) document in the `TPOSS` component documentation.

## HTTP API and TPOSS API gateway

To configure TPOSS HTTP API, adjust the following options:

```yaml
tposs_http_api:
  # TPOSS HTTP listener address
  host: 0.0.0.0
  # TPOSS HTTP listener port
  port: 8080
  # Number of listener processes that may accept connections
  acceptors: 100
  # List of secrets to access TPOSS HTTP API
  secret_keys: "client-1-secret, client-2-secret"
```

In addition, TPOSS HTTP API is usually accessed via TPOSS API Gateway.

See the example of TPOSS API Gateway configuration:

```yaml
tposs-api-gw:
  enabled: true
  service:
    externalPort: 1200
    internalPort: 1200
  api:
    listen_port: 1200
    timeout: 20000
  tposs:
    api_port: 8080
    timeout: 20000
  ingress:
    enabled: true
    host: localhost
    https: false
    annotations: {}
    className: "nginx"
  image:
    pullPolicy: IfNotPresent
  imagePullSecrets:
    secret: secret
```

In HA mode, it is usually enough to have a single TPOSS API Gateway even with multiple TPOSS
instances, because it does not handle requests constantly and rarely upgraded part.

## Logging configuration

TPOSS writes log messages into `stdout`. Use the following configuration options to control TPOSS logging:

```yaml
log:
  console:
    level: error
    format: json
```

These are the available RPR log levels:

- emergency
- alert
- critical
- error
- warning
- notice
- info
- debug

The supported formats are:

- default
- JSON

## IMEISV whitelist configuration

The whitelist feature allows you to apply the specific service profile for users with unknown IMEISV. The feature is disabled by default. You can enable it using the following configuration:

```yaml
whitelist:
  imei:
    enabled: true
    default:
      service_profile: DE
      access_class: FactoryTest
```

When TPOSS receives RADIUS Access-Request with the unknown IMEISV that does not exist in the TPOSS database, the pre-configured **whitelist.imei.default.service_profile** service profile is applied for this user. Besides the selected service profile, the service sessions of such users always have the pre-configured **whitelist.imei.default.access_class** charging rule.

>**NOTE:** The **whitelist.imei.default.service_profile** parameter must reference the existing service profile. The **profiles.{NAME}.name** (if multiple service profiles with the same home countries are configured) or **profile.{NAME}** of such profile must be unique across all configured profiles.
