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

# Transports and routing configuration

Each DPR instance (main and for redundancy) should specify configuration of Diameter `listeners` that accepts incoming Diameter requests and `relays` where incoming requests are forwarded based on destination realms and destination hosts.

### Routing configuration

Each DPR instance must have a unique `origin_host` configuration. All instances can share the same `origin_realm` but must have a unique `origin_host`.

For example:

```yaml
diameter_proxy:
  origin_host: "dpr-1.cennsonet"
  origin_realm: "dpr-1-instance"
```

To do the routing of Diameter messages, DPR should be able to select a peer where to forward each incoming message.

The `diameter_proxy.realms` configuration allows you to specify the mapping between destination realms and peers where requests are forwarded.

For example:

```yaml
diameter_proxy:
  realms:
    destination-realm-a:
      - "diameter-agent-host-a"
      - "diameter-agent-host-b"
    destination-realm-b:
      - "diameter-agent-host-c"
      - "diameter-agent-host-d"
```

The very first step when any Diameter request arrives to DPR, DPR fetches the value of the `Destination-Realm` AVP from the given request. DPR tries to find a route within the `diameter_proxy.realms` list. If such a route is not found, `3003` or `DIAMETER_REALM_NOT_SERVED` is immediately returned to the requester. Otherwise, the request is forwarded to one of the specified relays. If a matching realm is found but none of its peers are available, `3002` or `DIAMETER_UNABLE_TO_DELIVER` is returned instead.

In the example above, all requests with the `Destination-Realm = destination-realm-a` are forwarded to the one of the peers which has origin host - `diameter-agent-host-a` or `diameter-agent-host-b`. Any Diameter request with the `Destination-Realm = destination-realm-b` is forwarded to a peer with origin host `diameter-agent-host-c` or `diameter-agent-host-d`.

If a request in addition to the `Destination-Realm` contains `Destination-Host` AVP, the request is forwarded specially to the peer with which `Origin-Host` is matched with the given `Destination-Host` value. Otherwise, the request is forwarded only based on `Destination-Realm` to one of the specified relays.

If the sticky session setup is enabled through the `diameter_proxy.sticky_session_setup` configuration option, all the `initial` Diameter requests for the same `Session-ID` AVP are sent over the same peer with the given realm and destination host. The `initial` requests are:

- NASREQ AAR
- Gx CCR-I
- Gy CCR-I
- NASREQ Accounting-Start

### Transports configuration

To receive and forward requests, you should specify listener and client transports for DPR using the `diameter_proxy.transports` configuration option.

For example:

```yaml
diameter_proxy:
  transports:
    - listen: <<"aaa://0.0.0.0:3868;transport=tcp">>
      reuseaddr: true
      nodelay: true
      recbuf: "1048576"
      sndbuf: "1048576"
    - connect_to: <<"aaa://diameter-agent-host-a:3868;transport=tcp">>
      reuseaddr: true
      nodelay: true
      recbuf: "1048576"
      sndbuf: "1048576"
      transport_options:
        pool_size: 1
        connect_timer: 1000
        watchdog_timer: 6000
```

This example shows both types of transports. The first one specifies the listener transport on port `3868`. The second transport specifies the client transport towards `diameter-agent-host-a:3868`.

The URI format is specified by [RFC 6733, section 4.3.1, "DiameterURI"](https://www.rfc-editor.org/rfc/rfc6733.html#section-4.3.1).

Besides endpoints, each transport can specify transport options:

* `reuseaddr` - allows for the reuse of addresses (for example in the **TIME_WAIT** state)
* `sndbuf` - size of send buffer in bytes
* `recbuf` - size of receive buffer in bytes
* `nodelay` - sets **TCP_NODELAY**
* `transport_options.connect_timer` - value for the [RFC 6733 Tc timer](https://www.rfc-editor.org/rfc/rfc6733.html#section-12), in milliseconds
* `transport_options.watchdog_timer` - value for the [RFC 3539 TwInit initial watchdog timer value](https://www.rfc-editor.org/rfc/rfc3539#section-3.4), in milliseconds
* `transport_options.pool_size` - maximum number of connections to accept for listener transports, or the number of connections to use to connect to a remote agent for clients

> [!NOTE]
> For better resource consumption, it is recommended to set **transport_options.pool_size** to `1` or a low value in general.
