> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/rpr/3.0/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/rpr/3.0/configuration/nats.md).

# Integration with NATS

>**CAUTION:** This feature is experimental. The state is alpha and not recommended for the production environment.

To allow for one-to-many communication, RADIUS Proxy (RPR) supports publishing incoming RADIUS messages to NATS.

If NATS exporters are specified in the RPR configuration, RPR receives RADIUS requests from other RADIUS relays and publishes them to NATS with the configured topic and in the configured format. The general workflow looks as follows:

```mermaid
graph TD
    RADIUS-server-1[RADIUS-server-1<br/>Nas-Identifier: RAD-1] -->|Access-Request| RPR(RPR)
    RADIUS-server-2[RADIUS-Server-2<br/>Nas-Identifier: RAD-2] -->|Accounting-Start| RPR(RPR)
    RPR --> |Access-Request| NATS-server[NATS-server]
    RPR --> |Accounting-Start| NATS-server[NATS-server]
```

1. RPR receives the RADIUS request from the external RADIUS relay `RADIUS-Server-1` or `RADIUS-Server-2` or both. 
2. As soon as the RADIUS request arrives to RPR, RPR tries to find a suitable NATS exporter. If a suitable NATS exporter is found, RPR publishes the incoming RADIUS request to the NATS server with the pre-configured topic.

## Configuration of NATS exporters

To configure NATS, specify a list of NATS exporters:

```yaml
nats:
  exporters:
    - name: radius_exporter
      radius:
        sources:
          - proxy_auth_1
          - proxy_acct_1
          - proxy_coa
       filter:
         - key: commandCode
           operator: In
           values: ['AccessRequest', 'AccountingStartRequest', 'AccountingInterimRequest', 'AccountingStopRequest', 'DisconnectRequest']
       topic: "cennso.radius.acct.start.apn.{apn}.imsi.{imsi}.framed-ip.{framedIP}.nsapi.{nsapi}"
       placeholderMapping:
         apn: "Called-Station-Id"
         framedIP: "Framed-IP-Address"
         imsi: "X_3GPP-IMSI"
         nsapi: "X_3GPP-NSAPI"
       additionalHeaders:
         header_key: "header_value"
         apn: "{apn}"
       exportEncoding: "json"
       natsServer: "localhost:4222"
```

Each NATS exporter must have the following configuration options:

| Parameter | Description |
|---|---|
| `name` | The name of the NATS exporter. Must be unique if multiple exporters are defined in the configuration.
| `radius.source` | The list of RADIUS servers from which the incoming RADIUS messages are published to NATS. The value of the `radius.source` is a RADIUS server name created by combining:    - `proxy_auth_` string and the value from `auth.{SERVER_NAME}` for authentication requests   - `proxy_acct_` string and the value from `acct.{SERVER_NAME}` for accounting requests   - `proxy_coa` for CoA/Disconnect requests
| `filter ` | The filter applied to each incoming RADIUS message to decide whether to publish it to NATS or not. The `filter` parameter lists `key`, `operator` and `values` options. The `key` parameter specifies filter criteria. For now, only `commandCode` is supported which specifies the type of the incoming RADIUS request. The supported values are `'AccessRequest'`, `'AccountingStartRequest'`, `'AccountingInterimRequest'`, `'AccountingStopRequest'`, and `'DisconnectRequest'`. The values for all operators are always provided in the form of a list. The possible operators are `In` or `Equal`.
| `topic` | The `NATS` subject for which messages are published. The `topic` is represented by a string that may contain placeholders in the format `{placeholder-name}`. The placeholder must be specified in  `placeholderMapping`. Since the placeholder values are RADIUS attributes, the placeholder is replaced with `-` if the given RADIUS attribute is missing in the incoming message.
| `placeholderMapping` | The list of placeholders. Each placeholder consists of a key and a value. The key is a placeholder name. The value should be a valid name of the RADIUS attribute.
| `additionalHeaders` | The list of [headers](https://docs.nats.io/nats-concepts/jetstream/headers) that are published with messages. The placeholder can be specified as a value of the header in the format `{placeholder-name}`. The placeholder must be specified in the `placeholderMapping`.
| `exportEncoding` | The format of RADIUS messages published to NATS. The following formats are supported:  `json`, `raw`, and `nil`. If `raw` is specified, RPR publishes RADIUS messages in the same binary format as arrived to RPR. If `nil` is specified, RPR does not publish a body but just headers that are specified in the `additionalHeaders`.
| `natsServer` | The address of the NATS server in the format of `host:port`.
