mirror of
https://github.com/espressif/openthread.git
synced 2026-09-12 04:00:10 +00:00
[routing-manager] add SetIfIndex in RoutingManager (#9305)
This commit adds `SetIfIndex` method to `RoutingManager` class. This method allows the infrastructure interface to be changed. The user may initialize multiple interfaces and choose one interface as infrastructure interface. During run time, there might be some networking congestion or other network issue. The user can change the infrastructure interface via this function. This commit also adds docs for the `init` command.
This commit is contained in:
@@ -133,6 +133,8 @@ typedef enum
|
||||
* Initializes the Border Routing Manager on given infrastructure interface.
|
||||
*
|
||||
* @note This method MUST be called before any other otBorderRouting* APIs.
|
||||
* @note This method can be re-called to change the infrastructure interface, but the Border Routing Manager should be
|
||||
* disabled first, and re-enabled after.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[in] aInfraIfIndex The infrastructure interface index.
|
||||
@@ -140,11 +142,12 @@ typedef enum
|
||||
* interface is running.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully started the Border Routing Manager on given infrastructure.
|
||||
* @retval OT_ERROR_INVALID_STATE The Border Routing Manager has already been initialized.
|
||||
* @retval OT_ERROR_INVALID_STATE The Border Routing Manager is in a state other than disabled or uninitialized.
|
||||
* @retval OT_ERROR_INVALID_ARGS The index of the infrastructure interface is not valid.
|
||||
* @retval OT_ERROR_FAILED Internal failure. Usually due to failure in generating random prefixes.
|
||||
*
|
||||
* @sa otPlatInfraIfStateChanged.
|
||||
* @sa otBorderRoutingSetEnabled.
|
||||
*
|
||||
*/
|
||||
otError otBorderRoutingInit(otInstance *aInstance, uint32_t aInfraIfIndex, bool aInfraIfIsRunning);
|
||||
|
||||
@@ -53,7 +53,7 @@ extern "C" {
|
||||
* @note This number versions both OpenThread platform and user APIs.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_API_VERSION (347)
|
||||
#define OPENTHREAD_API_VERSION (348)
|
||||
|
||||
/**
|
||||
* @addtogroup api-instance
|
||||
|
||||
@@ -8,6 +8,7 @@ Usage : `br [command] ...`
|
||||
- [disable](#disable)
|
||||
- [enable](#enable)
|
||||
- [help](#help)
|
||||
- [init](#init)
|
||||
- [nat64prefix](#nat64prefix)
|
||||
- [omrprefix](#omrprefix)
|
||||
- [onlinkprefix](#onlinkprefix)
|
||||
@@ -38,6 +39,17 @@ state
|
||||
Done
|
||||
```
|
||||
|
||||
### init
|
||||
|
||||
Usage: `br init <interface> <enabled>`
|
||||
|
||||
Initializes the Border Routing Manager on given infrastructure interface.
|
||||
|
||||
```bash
|
||||
> br init 2 1
|
||||
Done
|
||||
```
|
||||
|
||||
### enable
|
||||
|
||||
Usage: `br enable`
|
||||
|
||||
@@ -114,6 +114,14 @@ public:
|
||||
*/
|
||||
uint32_t GetIfIndex(void) const { return mIfIndex; }
|
||||
|
||||
/**
|
||||
* Sets the infrastructure interface index.
|
||||
*
|
||||
* @param[in] aIfIndex The infrastructure interface index.
|
||||
*
|
||||
*/
|
||||
void SetIfIndex(uint32_t aIfIndex) { mIfIndex = aIfIndex; }
|
||||
|
||||
/**
|
||||
* Indicates whether or not the infra interface has the given IPv6 address assigned.
|
||||
*
|
||||
|
||||
@@ -94,16 +94,24 @@ Error RoutingManager::Init(uint32_t aInfraIfIndex, bool aInfraIfIsRunning)
|
||||
{
|
||||
Error error;
|
||||
|
||||
LogInfo("Initializing - InfraIfIndex:%lu", ToUlong(aInfraIfIndex));
|
||||
VerifyOrExit(GetState() == kStateUninitialized || GetState() == kStateDisabled, error = kErrorInvalidState);
|
||||
|
||||
SuccessOrExit(error = mInfraIf.Init(aInfraIfIndex));
|
||||
|
||||
SuccessOrExit(error = LoadOrGenerateRandomBrUlaPrefix());
|
||||
mOmrPrefixManager.Init(mBrUlaPrefix);
|
||||
if (!mInfraIf.IsInitialized())
|
||||
{
|
||||
LogInfo("Initializing - InfraIfIndex:%lu", ToUlong(aInfraIfIndex));
|
||||
SuccessOrExit(error = mInfraIf.Init(aInfraIfIndex));
|
||||
SuccessOrExit(error = LoadOrGenerateRandomBrUlaPrefix());
|
||||
mOmrPrefixManager.Init(mBrUlaPrefix);
|
||||
#if OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE
|
||||
mNat64PrefixManager.GenerateLocalPrefix(mBrUlaPrefix);
|
||||
mNat64PrefixManager.GenerateLocalPrefix(mBrUlaPrefix);
|
||||
#endif
|
||||
mOnLinkPrefixManager.Init();
|
||||
mOnLinkPrefixManager.Init();
|
||||
}
|
||||
else if (aInfraIfIndex != mInfraIf.GetIfIndex())
|
||||
{
|
||||
LogInfo("Reinitializing - InfraIfIndex:%lu -> %lu", ToUlong(mInfraIf.GetIfIndex()), ToUlong(aInfraIfIndex));
|
||||
mInfraIf.SetIfIndex(aInfraIfIndex);
|
||||
}
|
||||
|
||||
error = mInfraIf.HandleStateChanged(mInfraIf.GetIfIndex(), aInfraIfIsRunning);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user