[cli] add childip max command (#4759)

Thread 1.2 test harness requires the ability to set the number of IP
address the parent could store per child to test the reaction of the
Child DUT. The value intentionally may not conform to the Conformance
Specification. Since it is only used for reference device, this commit
wraps relevant APIs in the OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
macro.
This commit is contained in:
Rongli Sun
2020-03-31 22:58:51 +08:00
committed by GitHub
parent d85c0007a1
commit 77ea86302e
6 changed files with 186 additions and 25 deletions
+46 -21
View File
@@ -864,37 +864,62 @@ exit:
void Interpreter::ProcessChildIp(uint8_t aArgsLength, char *aArgs[])
{
otError error = OT_ERROR_NONE;
uint16_t maxChildren;
OT_UNUSED_VARIABLE(aArgs);
otError error = OT_ERROR_NONE;
VerifyOrExit(aArgsLength == 0, error = OT_ERROR_INVALID_ARGS);
maxChildren = otThreadGetMaxAllowedChildren(mInstance);
for (uint16_t childIndex = 0; childIndex < maxChildren; childIndex++)
if (aArgsLength == 0)
{
otChildIp6AddressIterator iterator = OT_CHILD_IP6_ADDRESS_ITERATOR_INIT;
otIp6Address ip6Address;
otChildInfo childInfo;
uint16_t maxChildren = otThreadGetMaxAllowedChildren(mInstance);
if ((otThreadGetChildInfoByIndex(mInstance, childIndex, &childInfo) != OT_ERROR_NONE) ||
childInfo.mIsStateRestoring)
for (uint16_t childIndex = 0; childIndex < maxChildren; childIndex++)
{
continue;
}
otChildIp6AddressIterator iterator = OT_CHILD_IP6_ADDRESS_ITERATOR_INIT;
otIp6Address ip6Address;
otChildInfo childInfo;
iterator = OT_CHILD_IP6_ADDRESS_ITERATOR_INIT;
if ((otThreadGetChildInfoByIndex(mInstance, childIndex, &childInfo) != OT_ERROR_NONE) ||
childInfo.mIsStateRestoring)
{
continue;
}
while (otThreadGetChildNextIp6Address(mInstance, childIndex, &iterator, &ip6Address) == OT_ERROR_NONE)
{
mServer->OutputFormat("%04x: ", childInfo.mRloc16);
OutputIp6Address(ip6Address);
mServer->OutputFormat("\r\n");
iterator = OT_CHILD_IP6_ADDRESS_ITERATOR_INIT;
while (otThreadGetChildNextIp6Address(mInstance, childIndex, &iterator, &ip6Address) == OT_ERROR_NONE)
{
mServer->OutputFormat("%04x: ", childInfo.mRloc16);
OutputIp6Address(ip6Address);
mServer->OutputFormat("\r\n");
}
}
}
else if (strcmp(aArgs[0], "max") == 0)
{
if (aArgsLength == 1)
{
mServer->OutputFormat("%d\r\n", otThreadGetMaxChildIpAddresses(mInstance));
}
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
else if (aArgsLength == 2)
{
unsigned long value;
SuccessOrExit(error = ParseUnsignedLong(aArgs[1], value));
SuccessOrExit(error = otThreadSetMaxChildIpAddresses(mInstance, static_cast<uint8_t>(value)));
}
#endif
else
{
error = OT_ERROR_INVALID_ARGS;
}
}
else
{
error = OT_ERROR_INVALID_COMMAND;
}
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
exit:
OT_UNUSED_VARIABLE(aArgs);
#endif
AppendResult(error);
}