# Border Router Multi AIL Detection

# Border Router Multi AIL Detection

This module includes functions for the OpenThread Multi-AIL Detection feature.

## Summary

All the functions in this module require both the `OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE` and `OPENTHREAD_CONFIG_BORDER_ROUTING_MULTI_AIL_DETECTION_ENABLE` to be enabled.

| ### Typedefs ||
|---|---|
| `https://openthread.io/reference/group/api-multi-ail-detection#group__api-multi-ail-detection_1ga4d0e0cb8ec8fd69a89f5217ddda47be6)(bool aDetected, void *aContext)` | typedef `void(*` A callback function pointer called when the multi-AIL detection state changes. |

| ### Functions ||
|---|---|
| `https://openthread.io/reference/group/api-multi-ail-detection#group__api-multi-ail-detection_1ga99470fa2a4af2669f19688fc36509fad(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance)` | `bool` Gets the current detected state regarding multiple Adjacent Infrastructure Links (AILs). |
| `https://openthread.io/reference/group/api-multi-ail-detection#group__api-multi-ail-detection_1ga004fb80afac542c6d5080a97c1261568(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance)` | `bool` Checks if the Multi-AIL Detector is enabled. |
| `https://openthread.io/reference/group/api-multi-ail-detection#group__api-multi-ail-detection_1ga18b87353ac4cf60255d1460d29b72b0f(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance)` | `bool` Checks if the Multi-AIL Detector is running. |
| `https://openthread.io/reference/group/api-multi-ail-detection#group__api-multi-ail-detection_1ga45a045c3282206447aaa20660a155d42(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/group/api-multi-ail-detection#group__api-multi-ail-detection_1ga4d0e0cb8ec8fd69a89f5217ddda47be6 aCallback, void *aContext)` | `void` Sets a callback function to be notified of changes in the multi-AIL detection state. |
| `https://openthread.io/reference/group/api-multi-ail-detection#group__api-multi-ail-detection_1ga0d5be3c53c35b4553fc84c067c5e92e9(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, bool aEnable)` | `void` Enables or disables the Multi-AIL Detector. |

## Typedefs

### otBorderRoutingMultiAilCallback

```
void(* otBorderRoutingMultiAilCallback)(bool aDetected, void *aContext)
```
A callback function pointer called when the multi-AIL detection state changes.

This callback function is invoked by the OpenThread stack whenever the detector determines a change in whether Border Routers on the Thread mesh might be connected to different Adjacent Infrastructure Links (AILs).

See `https://openthread.io/reference/group/api-multi-ail-detection#group__api-multi-ail-detection_1ga99470fa2a4af2669f19688fc36509fad` for more details.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aDetected` | `TRUE` if multiple AILs are now detected, `FALSE` otherwise. | | `[in] aContext` | A pointer to arbitrary context information provided when the callback was registered using `https://openthread.io/reference/group/api-multi-ail-detection#group__api-multi-ail-detection_1ga45a045c3282206447aaa20660a155d42`. | |

## Functions

### otBorderRoutingIsMultiAilDetected

```
bool otBorderRoutingIsMultiAilDetected(
  otInstance *aInstance
)
```
Gets the current detected state regarding multiple Adjacent Infrastructure Links (AILs).

It returns whether the detector currently believes that Border Routers (BRs) on the Thread mesh may be connected to different AILs.

The detection mechanism operates as follows: The detector monitors the number of peer BRs listed in the Thread Network Data (see `https://openthread.io/reference/group/api-border-routing#group__api-border-routing_1gaf6cd4292a95114f9ddabf15845f26865`) and compares this count with the number of peer BRs discovered by processing received Router Advertisement (RA) messages on its connected AIL. If the count derived from Network Data consistently exceeds the count derived from RAs for a detection duration of 10 minutes, it concludes that BRs are likely connected to different AILs. To clear state a shorter window of 1 minute is used.

The detection window of 10 minutes helps to avoid false positives due to transient changes. The detector uses 200 seconds for reachability checks of peer BRs (sending Neighbor Solicitation). Stale Network Data entries are also expected to age out within a few minutes. So a 10-minute detection time accommodates both cases.

While generally effective, this detection mechanism may get less reliable in scenarios with a large number of BRs, particularly exceeding ten. This is related to the "Network Data Publisher" mechanism, where BRs might refrain from publishing their external route information in the Network Data to conserve its limited size, potentially skewing the Network Data BR count.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to the OpenThread instance. | |
| Return Values | |---|---| | `TRUE` | Has detected that BRs are likely connected to multiple AILs. | | `FALSE` | Has not detected (or no longer detects) that BRs are connected to multiple AILs. | |

### otBorderRoutingIsMultiAilDetectionEnabled

```
bool otBorderRoutingIsMultiAilDetectionEnabled(
  otInstance *aInstance
)
```
Checks if the Multi-AIL Detector is enabled.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to the OpenThread instance. | |
| Return Values | |---|---| | `TRUE` | If the detector is enabled. | | `FALSE` | If the detector is disabled. | |

### otBorderRoutingIsMultiAilDetectionRunning

```
bool otBorderRoutingIsMultiAilDetectionRunning(
  otInstance *aInstance
)
```
Checks if the Multi-AIL Detector is running.

The detector runs when it is enabled and the infrastructure interface is also active.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to the OpenThread instance. | |
| Return Values | |---|---| | `TRUE` | If the detector is running. | | `FALSE` | If the detector is not running. | |

### otBorderRoutingSetMultiAilCallback

```
void otBorderRoutingSetMultiAilCallback(
  otInstance *aInstance,
  otBorderRoutingMultiAilCallback aCallback,
  void *aContext
)
```
Sets a callback function to be notified of changes in the multi-AIL detection state.

Subsequent calls to this function will overwrite the previous callback setting. Using `NULL` for `aCallback` will disable the callback.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to the OpenThread instance. | | `[in] aCallback` | A pointer to the function (`otBorderRoutingMultiAilCallback`) to be called upon state changes, or `NULL` to unregister a previously set callback. | | `[in] aContext` | A pointer to application-specific context that will be passed back in the `aCallback` function. This can be `NULL` if no context is needed. | |

### otBorderRoutingSetMultiAilDetectionEnabled

```
void otBorderRoutingSetMultiAilDetectionEnabled(
  otInstance *aInstance,
  bool aEnable
)
```
Enables or disables the Multi-AIL Detector.

If `OPENTHREAD_CONFIG_BORDER_ROUTING_MULTI_AIL_DETECTION_AUTO_ENABLE_MODE` is enabled, the detector is enabled by default and starts running when the infra-if network is initialized and becomes active (running).

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to the OpenThread instance. | | `[in] aEnable` | TRUE to enable the detector, FALSE to disable. | |

## Resources

OpenThread API Reference topics originate from the source code, available
on [GitHub](https://github.com/openthread/openthread/tree/main/include/openthread).
For more information, or to contribute to our documentation, refer to
[Resources](https://openthread.io/resources).