mirror of
https://github.com/espressif/openthread.git
synced 2026-08-29 21:39:54 +00:00
[cli] add ability to show local network data (#7316)
This commit is contained in:
@@ -244,7 +244,7 @@ Done
|
||||
|
||||
### show
|
||||
|
||||
Usage: `netdata show [-x]`
|
||||
Usage: `netdata show [local] [-x]`
|
||||
|
||||
Print Network Data received from the Leader.
|
||||
|
||||
@@ -257,7 +257,7 @@ Services:
|
||||
Done
|
||||
```
|
||||
|
||||
Print Network Data as hex-encoded TLVs.
|
||||
Print Network Data received from the Leader as hex-encoded TLVs.
|
||||
|
||||
```bash
|
||||
> netdata show -x
|
||||
@@ -265,6 +265,25 @@ Print Network Data as hex-encoded TLVs.
|
||||
Done
|
||||
```
|
||||
|
||||
Print local Network Data to sync with Leader.
|
||||
|
||||
```bash
|
||||
> netdata show local
|
||||
Prefixes:
|
||||
fd00:dead:beef:cafe::/64 paros med dc00
|
||||
Routes:
|
||||
Services:
|
||||
Done
|
||||
```
|
||||
|
||||
Print local Network Data to sync with Leader as hex-encoded TLVs.
|
||||
|
||||
```bash
|
||||
> netdata show local -x
|
||||
08040b02174703140040fd00deadbeefcafe0504dc00330007021140
|
||||
Done
|
||||
```
|
||||
|
||||
### netdata steeringdata check \<eui64\>|\<discerner\>
|
||||
|
||||
Check whether the steering data includes a joiner.
|
||||
|
||||
+109
-18
@@ -345,52 +345,124 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void NetworkData::OutputPrefixes(void)
|
||||
otError NetworkData::GetNextPrefix(otNetworkDataIterator *aIterator, otBorderRouterConfig *aConfig, bool aLocal)
|
||||
{
|
||||
otError error;
|
||||
|
||||
if (aLocal)
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
|
||||
error = otBorderRouterGetNextOnMeshPrefix(GetInstancePtr(), aIterator, aConfig);
|
||||
#else
|
||||
error = OT_ERROR_NOT_FOUND;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
error = otNetDataGetNextOnMeshPrefix(GetInstancePtr(), aIterator, aConfig);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
void NetworkData::OutputPrefixes(bool aLocal)
|
||||
{
|
||||
otNetworkDataIterator iterator = OT_NETWORK_DATA_ITERATOR_INIT;
|
||||
otBorderRouterConfig config;
|
||||
|
||||
OutputLine("Prefixes:");
|
||||
|
||||
while (otNetDataGetNextOnMeshPrefix(GetInstancePtr(), &iterator, &config) == OT_ERROR_NONE)
|
||||
while (GetNextPrefix(&iterator, &config, aLocal) == OT_ERROR_NONE)
|
||||
{
|
||||
OutputPrefix(config);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkData::OutputRoutes(void)
|
||||
otError NetworkData::GetNextRoute(otNetworkDataIterator *aIterator, otExternalRouteConfig *aConfig, bool aLocal)
|
||||
{
|
||||
otError error;
|
||||
|
||||
if (aLocal)
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
|
||||
error = otBorderRouterGetNextRoute(GetInstancePtr(), aIterator, aConfig);
|
||||
#else
|
||||
error = OT_ERROR_NOT_FOUND;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
error = otNetDataGetNextRoute(GetInstancePtr(), aIterator, aConfig);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
void NetworkData::OutputRoutes(bool aLocal)
|
||||
{
|
||||
otNetworkDataIterator iterator = OT_NETWORK_DATA_ITERATOR_INIT;
|
||||
otExternalRouteConfig config;
|
||||
|
||||
OutputLine("Routes:");
|
||||
|
||||
while (otNetDataGetNextRoute(GetInstancePtr(), &iterator, &config) == OT_ERROR_NONE)
|
||||
while (GetNextRoute(&iterator, &config, aLocal) == OT_ERROR_NONE)
|
||||
{
|
||||
OutputRoute(config);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkData::OutputServices(void)
|
||||
otError NetworkData::GetNextService(otNetworkDataIterator *aIterator, otServiceConfig *aConfig, bool aLocal)
|
||||
{
|
||||
otError error;
|
||||
|
||||
if (aLocal)
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
|
||||
error = otServerGetNextService(GetInstancePtr(), aIterator, aConfig);
|
||||
#else
|
||||
error = OT_ERROR_NOT_FOUND;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
error = otNetDataGetNextService(GetInstancePtr(), aIterator, aConfig);
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
void NetworkData::OutputServices(bool aLocal)
|
||||
{
|
||||
otNetworkDataIterator iterator = OT_NETWORK_DATA_ITERATOR_INIT;
|
||||
otServiceConfig config;
|
||||
|
||||
OutputLine("Services:");
|
||||
|
||||
while (otNetDataGetNextService(GetInstancePtr(), &iterator, &config) == OT_ERROR_NONE)
|
||||
while (GetNextService(&iterator, &config, aLocal) == OT_ERROR_NONE)
|
||||
{
|
||||
OutputService(config);
|
||||
}
|
||||
}
|
||||
|
||||
otError NetworkData::OutputBinary(void)
|
||||
otError NetworkData::OutputBinary(bool aLocal)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
otError error;
|
||||
uint8_t data[255];
|
||||
uint8_t len = sizeof(data);
|
||||
|
||||
SuccessOrExit(error = otNetDataGet(GetInstancePtr(), false, data, &len));
|
||||
if (aLocal)
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
|
||||
error = otBorderRouterGetNetData(GetInstancePtr(), false, data, &len);
|
||||
#else
|
||||
error = OT_ERROR_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
error = otNetDataGet(GetInstancePtr(), false, data, &len);
|
||||
}
|
||||
SuccessOrExit(error);
|
||||
|
||||
OutputBytesLine(data, static_cast<uint8_t>(len));
|
||||
|
||||
@@ -400,20 +472,39 @@ exit:
|
||||
|
||||
otError NetworkData::ProcessShow(Arg aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
otError error = OT_ERROR_INVALID_ARGS;
|
||||
bool local = false;
|
||||
bool binary = false;
|
||||
|
||||
if (aArgs[0].IsEmpty())
|
||||
for (uint8_t i = 0; !aArgs[i].IsEmpty(); i++)
|
||||
{
|
||||
OutputPrefixes();
|
||||
OutputRoutes();
|
||||
OutputServices();
|
||||
if (aArgs[i] == "local")
|
||||
{
|
||||
local = true;
|
||||
}
|
||||
else if (aArgs[i] == "-x")
|
||||
{
|
||||
binary = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ExitNow(error = OT_ERROR_INVALID_ARGS);
|
||||
}
|
||||
}
|
||||
|
||||
if (binary)
|
||||
{
|
||||
error = OutputBinary(local);
|
||||
}
|
||||
else
|
||||
{
|
||||
OutputPrefixes(local);
|
||||
OutputRoutes(local);
|
||||
OutputServices(local);
|
||||
error = OT_ERROR_NONE;
|
||||
}
|
||||
else if (aArgs[0] == "-x")
|
||||
{
|
||||
error = OutputBinary();
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
@@ -109,10 +109,14 @@ private:
|
||||
otError ProcessShow(Arg aArgs[]);
|
||||
otError ProcessSteeringData(Arg aArgs[]);
|
||||
|
||||
otError OutputBinary(void);
|
||||
void OutputPrefixes(void);
|
||||
void OutputRoutes(void);
|
||||
void OutputServices(void);
|
||||
otError GetNextPrefix(otNetworkDataIterator *aIterator, otBorderRouterConfig *aConfig, bool aLocal);
|
||||
otError GetNextRoute(otNetworkDataIterator *aIterator, otExternalRouteConfig *aConfig, bool aLocal);
|
||||
otError GetNextService(otNetworkDataIterator *aIterator, otServiceConfig *aConfig, bool aLocal);
|
||||
|
||||
otError OutputBinary(bool aLocal);
|
||||
void OutputPrefixes(bool aLocal);
|
||||
void OutputRoutes(bool aLocal);
|
||||
void OutputServices(bool aLocal);
|
||||
void OutputPreference(signed int aPreference);
|
||||
|
||||
static constexpr Command sCommands[] = {
|
||||
|
||||
Reference in New Issue
Block a user