mirror of
https://github.com/espressif/openthread.git
synced 2026-08-16 15:47:46 +00:00
[cli] add commands for getting Border Router OMR and on-link prefix (#6878)
This commit adds the 'br omrprefix' and 'br onlinkprefix' for getting OMR and on-link prefix of current Border Router.
This commit is contained in:
@@ -86,6 +86,37 @@ otError otBorderRoutingInit(otInstance *aInstance, uint32_t aInfraIfIndex, bool
|
||||
*/
|
||||
otError otBorderRoutingSetEnabled(otInstance *aInstance, bool aEnabled);
|
||||
|
||||
/**
|
||||
* This method returns the off-mesh-routable (OMR) prefix.
|
||||
*
|
||||
* The randomly generated 64-bit prefix will be published
|
||||
* in the Thread network if there isn't already an OMR prefix.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[out] aPrefix A pointer to where the prefix will be output to.
|
||||
*
|
||||
* @retval OT_ERROR_INVALID_STATE The Border Routing Manager is not initialized yet.
|
||||
* @retval OT_ERROR_NONE Successfully retrieved the OMR prefix.
|
||||
*
|
||||
*/
|
||||
otError otBorderRoutingGetOmrPrefix(otInstance *aInstance, otIp6Prefix *aPrefix);
|
||||
|
||||
/**
|
||||
* This method returns the on-link prefix for the adjacent infrastructure link.
|
||||
*
|
||||
* The randomly generated 64-bit prefix will be advertised
|
||||
* on the infrastructure link if there isn't already a usable
|
||||
* on-link prefix being advertised on the link.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[out] aPrefix A pointer to where the prefix will be output to.
|
||||
*
|
||||
* @retval OT_ERROR_INVALID_STATE The Border Routing Manager is not initialized yet.
|
||||
* @retval OT_ERROR_NONE Successfully retrieved the on-link prefix.
|
||||
*
|
||||
*/
|
||||
otError otBorderRoutingGetOnLinkPrefix(otInstance *aInstance, otIp6Prefix *aPrefix);
|
||||
|
||||
/**
|
||||
* This method provides a full or stable copy of the local Thread Network Data.
|
||||
*
|
||||
|
||||
@@ -53,7 +53,7 @@ extern "C" {
|
||||
* @note This number versions both OpenThread platform and user APIs.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_API_VERSION (148)
|
||||
#define OPENTHREAD_API_VERSION (149)
|
||||
|
||||
/**
|
||||
* @addtogroup api-instance
|
||||
|
||||
@@ -356,6 +356,26 @@ Done
|
||||
Done
|
||||
```
|
||||
|
||||
### br omrprefix
|
||||
|
||||
Get the randomly generated off-mesh-routable prefix of the Border Router.
|
||||
|
||||
```bash
|
||||
> br omrprefix
|
||||
fdfc:1ff5:1512:5622::/64
|
||||
Done
|
||||
```
|
||||
|
||||
### br onlinkprefix
|
||||
|
||||
Get the randomly generated on-link prefix of the Border Router.
|
||||
|
||||
```bash
|
||||
> br onlinkprefix
|
||||
fd41:2650:a6f5:0::/64
|
||||
Done
|
||||
```
|
||||
|
||||
### bufferinfo
|
||||
|
||||
Show the current message buffer information.
|
||||
|
||||
+33
-2
@@ -370,8 +370,30 @@ otError Interpreter::ProcessBorderRouting(Arg aArgs[])
|
||||
otError error = OT_ERROR_NONE;
|
||||
bool enable;
|
||||
|
||||
SuccessOrExit(error = ParseEnableOrDisable(aArgs[0], enable));
|
||||
error = otBorderRoutingSetEnabled(mInstance, enable);
|
||||
if (ParseEnableOrDisable(aArgs[0], enable) == OT_ERROR_NONE)
|
||||
{
|
||||
SuccessOrExit(error = otBorderRoutingSetEnabled(mInstance, enable));
|
||||
}
|
||||
else if (aArgs[0] == "omrprefix")
|
||||
{
|
||||
otIp6Prefix omrPrefix;
|
||||
|
||||
SuccessOrExit(error = otBorderRoutingGetOmrPrefix(mInstance, &omrPrefix));
|
||||
OutputIp6Prefix(omrPrefix);
|
||||
OutputLine("");
|
||||
}
|
||||
else if (aArgs[0] == "onlinkprefix")
|
||||
{
|
||||
otIp6Prefix onLinkPrefix;
|
||||
|
||||
SuccessOrExit(error = otBorderRoutingGetOnLinkPrefix(mInstance, &onLinkPrefix));
|
||||
OutputIp6Prefix(onLinkPrefix);
|
||||
OutputLine("");
|
||||
}
|
||||
else
|
||||
{
|
||||
ExitNow(error = OT_ERROR_INVALID_COMMAND);
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
@@ -4643,6 +4665,15 @@ void Interpreter::OutputPrefix(const otMeshLocalPrefix &aPrefix)
|
||||
(aPrefix.m8[4] << 8) | aPrefix.m8[5], (aPrefix.m8[6] << 8) | aPrefix.m8[7]);
|
||||
}
|
||||
|
||||
void Interpreter::OutputIp6Prefix(const otIp6Prefix &aPrefix)
|
||||
{
|
||||
char string[OT_IP6_PREFIX_STRING_SIZE];
|
||||
|
||||
otIp6PrefixToString(&aPrefix, string, sizeof(string));
|
||||
|
||||
OutputFormat("%s", string);
|
||||
}
|
||||
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE
|
||||
otError Interpreter::ProcessNetworkDiagnostic(Arg aArgs[])
|
||||
{
|
||||
|
||||
@@ -555,6 +555,7 @@ private:
|
||||
otError ProcessNetworkDataRoute(void);
|
||||
otError ProcessNetworkDataService(void);
|
||||
void OutputPrefix(const otMeshLocalPrefix &aPrefix);
|
||||
void OutputIp6Prefix(const otIp6Prefix &aPrefix);
|
||||
|
||||
otError ProcessNetstat(Arg aArgs[]);
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
|
||||
@@ -63,7 +63,7 @@ void NetworkData::OutputPrefix(const otBorderRouterConfig &aConfig)
|
||||
char flagsString[kMaxFlagStringSize];
|
||||
char *flagsPtr = &flagsString[0];
|
||||
|
||||
OutputIp6Prefix(aConfig.mPrefix);
|
||||
mInterpreter.OutputIp6Prefix(aConfig.mPrefix);
|
||||
|
||||
if (aConfig.mPreferred)
|
||||
{
|
||||
@@ -135,7 +135,7 @@ void NetworkData::OutputRoute(const otExternalRouteConfig &aConfig)
|
||||
char flagsString[kMaxFlagStringSize];
|
||||
char *flagsPtr = &flagsString[0];
|
||||
|
||||
OutputIp6Prefix(aConfig.mPrefix);
|
||||
mInterpreter.OutputIp6Prefix(aConfig.mPrefix);
|
||||
|
||||
if (aConfig.mStable)
|
||||
{
|
||||
@@ -159,15 +159,6 @@ void NetworkData::OutputRoute(const otExternalRouteConfig &aConfig)
|
||||
mInterpreter.OutputLine(" %04x", aConfig.mRloc16);
|
||||
}
|
||||
|
||||
void NetworkData::OutputIp6Prefix(const otIp6Prefix &aPrefix)
|
||||
{
|
||||
char string[OT_IP6_PREFIX_STRING_SIZE];
|
||||
|
||||
otIp6PrefixToString(&aPrefix, string, sizeof(string));
|
||||
|
||||
mInterpreter.OutputFormat("%s", string);
|
||||
}
|
||||
|
||||
void NetworkData::OutputPreference(signed int aPreference)
|
||||
{
|
||||
switch (aPreference)
|
||||
|
||||
@@ -117,7 +117,6 @@ private:
|
||||
void OutputPrefixes(void);
|
||||
void OutputRoutes(void);
|
||||
void OutputServices(void);
|
||||
void OutputIp6Prefix(const otIp6Prefix &aPrefix);
|
||||
void OutputPreference(signed int aPreference);
|
||||
|
||||
static constexpr Command sCommands[] = {
|
||||
|
||||
@@ -57,6 +57,21 @@ otError otBorderRoutingSetEnabled(otInstance *aInstance, bool aEnabled)
|
||||
|
||||
return instance.Get<BorderRouter::RoutingManager>().SetEnabled(aEnabled);
|
||||
}
|
||||
|
||||
otError otBorderRoutingGetOmrPrefix(otInstance *aInstance, otIp6Prefix *aPrefix)
|
||||
{
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
return instance.Get<BorderRouter::RoutingManager>().GetOmrPrefix(static_cast<Ip6::Prefix &>(*aPrefix));
|
||||
}
|
||||
|
||||
otError otBorderRoutingGetOnLinkPrefix(otInstance *aInstance, otIp6Prefix *aPrefix)
|
||||
{
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
return instance.Get<BorderRouter::RoutingManager>().GetOnLinkPrefix(static_cast<Ip6::Prefix &>(*aPrefix));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
otError otBorderRouterGetNetData(otInstance *aInstance, bool aStable, uint8_t *aData, uint8_t *aDataLength)
|
||||
|
||||
@@ -116,6 +116,28 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error RoutingManager::GetOmrPrefix(Ip6::Prefix &aPrefix)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
|
||||
VerifyOrExit(IsInitialized(), error = kErrorInvalidState);
|
||||
aPrefix = mLocalOmrPrefix;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error RoutingManager::GetOnLinkPrefix(Ip6::Prefix &aPrefix)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
|
||||
VerifyOrExit(IsInitialized(), error = kErrorInvalidState);
|
||||
aPrefix = mLocalOnLinkPrefix;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error RoutingManager::LoadOrGenerateRandomOmrPrefix(void)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
|
||||
@@ -109,6 +109,35 @@ public:
|
||||
*/
|
||||
Error SetEnabled(bool aEnabled);
|
||||
|
||||
/**
|
||||
* This method returns the off-mesh-routable (OMR) prefix.
|
||||
*
|
||||
* The randomly generated 64-bit prefix will be published
|
||||
* in the Thread network if there isn't already a OMR prefix.
|
||||
*
|
||||
* @param[in] aPrefix A reference to where the prefix will be output to.
|
||||
*
|
||||
* @retval kErrorInvalidState The Border Routing Manager is not initialized yet.
|
||||
* @retval kErrorNone Successfully retrieved the OMR prefix.
|
||||
*
|
||||
*/
|
||||
Error GetOmrPrefix(Ip6::Prefix &aPrefix);
|
||||
|
||||
/**
|
||||
* This method returns the on-link prefix for the adjacent infrastructure link.
|
||||
*
|
||||
* The randomly generated 64-bit prefix will be advertised
|
||||
* on the infrastructure link if there isn't already a usable
|
||||
* on-link prefix being advertised on the link.
|
||||
*
|
||||
* @param[in] aPrefix A reference to where the prefix will be output to.
|
||||
*
|
||||
* @retval kErrorInvalidState The Border Routing Manager is not initialized yet.
|
||||
* @retval kErrorNone Successfully retrieved the on-link prefix.
|
||||
*
|
||||
*/
|
||||
Error GetOnLinkPrefix(Ip6::Prefix &aPrefix);
|
||||
|
||||
/**
|
||||
* This method receives an ICMPv6 message on the infrastructure interface.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user