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

```
diameter_proxy:
  origin_host: "dpr-1"
  origin_realm: "tposs.cennso.net"
```

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

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

For example:

```
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 `diameter_proxy.realms`
configuration. If such a route is not found, `3002` or `DIAMETER_UNABLE_TO_DELIVEVER` is immediately
returned to the requester. Otherwise, the request is forwarded.

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 which `Origin-Host` is matched with the given `Destination-Host` value.
Otherwise, the request is forwarded only based on `Destination-Realm`.

If the sticky session setup is enabled through the `diameter_proxy.sticky_session_setup` configuration option, all the `initial`
requests, such as:

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

will be sent over the same peer with the given realm for a given `Session-Id`.

### Transports configuration

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

For example:

```
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: 30
        connect_timer: 1000
        watchdog_timer: 6000
```

This example shows both types of transports. The first one specifies the listener transport
on the `3868` port. 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.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
* `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

### endpoints_watcher

DPR has a small additional container which is named `endpoints_watcher`. It does not play any role
in the Diameter communication, but exists for more graceful update of TPOSS. The main purpose of this
container is to notify DPR about TPOSS upgrade. As a result, DPR does not send any **new** Diameter requests
towards the TPOSS instance which is under upgrade but does not terminate connection towards
it.

You can enable the `endpoints_watcher` with the following configuration option:

```
endpoints_watcher:
  enabled: true
```
