> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/smc/3.10/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/smc/3.10/config/charging.md).

# Charging

## AAA Transports

The first step when provisioning charging is to configure the network used for the different protocols, Rf and Ro. Ro can use a common interface, IPv4 address and MTU, or use specific per-protocol settings. The common settings are `networking.oss.{interface,ipv4.addr,mtu}`, whereas Ro uses `networking.ro.{interface,ipv4.addr,mtu}`.

Now the specific charging protocol settings can be configured. They are found under `aaa.rf` and `aaa.ro`. For both charging protocols, the following settings can be configured:

* `enabled`: whether signalling will be sent on this interface
* `standalone`: whether the common settings for OSS will be used, or rather the separate settings will be used

A value of `standalone: false` will mean the protocol will use the values under `aaa.oss` for `destinations`,`destinationRealm`, `originFqdn` and `originRealm`. Otherwise the values under `aaa.rf` or `aaa.ro` will be used.

Then the specific transport protocol (TCP or SCTP) and socket options options need to be configured, both under `aaa.rf` or `aaa.ro`:

* `transportType`: either `sctp` or `tcp`
* `transportOpts`: specific
  * `reuseaddr`: whether an existing socket in `TIME_WAIT` state is ignored when setting up the socket
  * `recbuf`: the buffer for incoming packets, in KB
  * `sndbuf`: the buffer for ougoing packets, in KB
  * `unordered`: *(only usable for SCTP)* whether messages can be sent unordered in the SCTP socket. Its recommended value is `true`.
  * `nodelay`: disables [Nagle's algorithm](https://en.wikipedia.org/wiki/Nagle%27s_algorithm); this may improve overhead in connections, but may cause latency for specific data to increase as they are not sent immediately

### Configuration of sender identity in the `Session-Id` AVP

In the Diameter interfaces (Gx, Gy, NASREQ), the `Session-Id` AVP starts with the sender's identity. This identity can be configured through the `aaa.originHost` parameter. If it is not set, the SMC identity will be retrieved from the operating system.

This can also be modified directly in the `ergw-config.json` file under the entry `"aaa"."apps"[0]."Origin-Host": "some.fqdn.name"`.

## RADIUS charging

The `aaa.radius.*` parameters specify how RADIUS charging will be performed. RADIUS needs to enabled with `aaa.radius.enabled` set to `true`. The different phases of RADIUS accounting can be separately enabled with the `aaa.radius.start.enabled`, `aaa.radius.interim.enabled` and `aaa.radius.stop.enabled` parameters. Additionally, specific AVPs can be filtered out using `aaa.radius.avp_filters` if needed.

Sample configuration:

```yaml
aaa:
  radius:
    enabled: true
    start:
      enabled: true
    stop:
      enabled: true
    server:
      addr: 172.22.14.1
      port: 1812
      type: IPv4 # ipv4` or `ipv6` or `fqdn`
      password: secret-tposs
```

Separate servers for authorization and accounting can be used by setting `aaa.radius.server.acct.standalone` to `true`, and using `aaa.radius.server.{acct,auth}.addr` and `aaa.radius.server.{acct,auth}.type`:

Example:

```yaml
aaa:
  radius:
    enabled: true
    start:
      enabled: true
    stop:
      enabled: true
    server:
      acct:
        standalone: true
        addr: 1.2.3.4
        port: 1812
        type: IPv4 # ipv4` or `ipv6` or `fqdn`
        password: secret-tposs
      auth:
        addr: 5.6.7.8
        port: 1812
        type: IPv4 # ipv4` or `ipv6` or `fqdn`
        password: secret-tposs
```

### RADIUS Accounting without Authentication

To enable RADIUS with only Accounting, without Authentication, and use `start`, `stop` and `interim`, use following configuration:

```yaml
aaa:
  acctInterimInterval: 60 # seconds
  radius:
    enabled: true
    authenticate:
      enabled: false
    interim:
      enabled: true
    start:
      enabled: true
    stop:
      enabled: true
    server:
      addr: 172.22.14.1
      port: 1812
      type: IPv4 # ipv4` or `ipv6` or `fqdn`
      password: secret-tposs
```

## NASREQ settings

By default, interim accounting is enabled so NASREQ requests will be sent at the default rate (1800 seconds). However, this creates additional traffic on the PFCP interface which may not be desirable. 

To disable interim messages in the NASREQ interface, it is possible to set the `aaa.acctInterimInterval` to `null` as in the following example:

```yaml
aaa:
  acctInterimInterval: null
```
>**NOTE** A `null` value cannot be used for `aaa.acctInterimInterval` if RADIUS stop or interim accounting are enabled.

## Charging parameters

The triggers enabled for charging in the SMC vary depending on its role:

* SMC as SMF:
  * charging containers updated at `cgi-sai-change`, `ecgi-change`, `qos-change`, `rai-change`, `tai-change`, `tariff-switch-change` and `user-location-info-change`
  * CDRs sent at `ms-time-zone-change`, `rat-change`, `sgsn-sgw-change` and `sgsn-sgw-plmn-id-change`
* SMC as TDF:
  * charging containers updated at `sgsn-sgw-plmn-id-change` and `tariff-switch-change`
  * CDRs sent at `ms-time-zone-change`

The location-dependent triggers (`cgi-sai-change`, `ecgi-change`, `rai-change`, `tai-change`, and `user-location-info-change`) enable sending a Change Reporting Action (CRA) IE in the Create Session Response messages sent through the GTPv2 interface. Whether the CRA IE is sent and what value is included in it depend on the values of the CRSI and ENBCRSI indications in the `Indication Flags` IE, the access network type in the `RAT Type` IE, and the configured triggers. These IEs are taken from the original Create Session Request message. The following table describes the CRA IE value sent depending on different combinations of the indications and triggers:

| Access network type | CRSI received | ENBCRSI received | Active triggers | CRA IE value |
| :-: | :-: | :-: | :-: | --- |
| any | `false` | any | any | No CRA sent |
| EUTRAN | `true` | `true` | `tai-change` AND `user-location-info-change` | Start Reporting TAI, Macro eNodeB ID and Extended Macro eNodeB ID: `8` |
| EUTRAN | `true` | `true` | `user-location-info-change` | Start Reporting Macro eNodeB ID and Extended Macro eNodeB ID: `7` |
| EUTRAN | `true` | any | `tai-change` AND `ecgi-change` | Start Reporting TAI and ECGI: `6` |
| EUTRAN | `true` | any | `tai-change` | Start reporting TAI: `3` |
| EUTRAN | `true` | any | `ecgi-change` | Start Reporting ECGI: `4` |
| EUTRAN | `true` | any | `cgi-sai-change` OR `rai-change` | No CRA sent |
| UTRAN | `true` | any | `user-location-info-change` | Start Reporting CGI/SAI and RAI: `5` |
| UTRAN | `true` | any | `cgi-sai-change` AND `rai-change` | Start Reporting CGI/SAI and RAI: `5` |
| UTRAN | `true` | any | `cgi-sai-change` | Start Reporting CGI/SAI: `1` |
| UTRAN | `true` | any | `rai-change` | Start Reporting RAI: `2` |
| UTRAN | `true` | any | `tai-change` OR `ecgi-change` | No CRA sent |

More information about charging triggers can be found in [TS 3GPP 32.251](https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=1898), sections 5.2.3.4 "Triggers for PGW-CDR charging information collection", 5.2.3.9 "Triggers for TDF-CDR charging information collection" and 5.2.3.10 "Triggers for PGW-CDR charging information collection when IP-CAN session charging is active".

Each `rules` definition under the `applicationDetection` section can include the corresponding policy items; any reference to AVP definitions can be checked in TS 3GPP 29.212, section 5.3 "Gx specific AVPs" (except as noted):

- `precedence` <br>
  The order in which this rule will be applied if the flow definitions in several rules match the same flow. Corresponds to the `Precedence` AVP.

- `permittedIPs` <br>
  Sets the IPv4 addresses for which flows with the specification `permit out ipv4 from <address> to assigned` will be added.

- `type` <br>
  Whether flow descriptions (`classic`) or an application name (`adf`) will be used to identify flows.

- `additionalSDF` (only applicable to `classic` type) <br>
  The flow specification corresponding to the `Flow-Description` AVP. The format for the flow description is described in RFC6733 (`IPFilterRule`). It is mapped to the `PDI.SDF_Filter.Flow_Description` field in PFCP. Both `UPLINK` and `DOWNLINK` directions are set up.

- `adf` type <br>
  The name of the rule is used as the value for the `TDF-Application-Identifier` AVP.

- `meteringMethod` <br>
  Describes what will be measured and reported in the flow specified in the element above. Each integer represents a different concept. In the packet switching domain, volume reporting is the usual setting.

    | Concept | Value |
    | --- | ---|
    | DURATION | 0 |
    | VOLUME | 1 |
    | DURATION_VOLUME | 2 |
    | EVENT | 3 |

- `offlineEnabled` <br>
  Set to 1 if offline charging is enabled.

- `onlineEnabled` <br>
  Set to 1 if online charging is enabled.

- `ratingGroup` <br>
  Rating Group applied to the flow. A description on the grouping of service usage can be found in RFC4006, section 5.1.2.

- `offlineRatingGroup` <br>
  The Rating Group defined for offline charging. Overrides the general `ratingGroup` setting.

- `onlineRatingGroup` <br>
  The Rating Group defined for offline charging. Overrides the general `ratingGroup` setting.

- `Redirect-Information`
  <TBD>

When several rules are sent to the UPG, the rule to apply depends on a combination of flow specification and precedence, so the UPG will activate the highest-precedence rule that applies to the current flow. A rulebase selects several such rules to be sent to the UPG.
