CLI: Router and child table (#662)

* CLI: Add router and child table commands.

This commit fixes issue #626.

* CLI: Add documentation to router and child table.

This commit fixes issue #626.
This commit is contained in:
Łukasz Duda
2016-09-22 09:43:11 -07:00
committed by Jonathan Hui
parent 5fdc27f1f8
commit c1bffba7dc
2 changed files with 92 additions and 8 deletions
+29 -4
View File
@@ -1,7 +1,7 @@
# OpenThread CLI Reference
The OpenThread CLI exposes configuration and management APIs via a
command line interface. Use the CLI to play with OpenThread, which
command line interface. Use the CLI to play with OpenThread, which
can also be used with additional application code. The
OpenThread test scripts use the CLI to execute test cases.
@@ -133,7 +133,7 @@ Done
### child list
List attached Child IDs
List attached Child IDs.
```bash
> child list
@@ -141,6 +141,19 @@ List attached Child IDs
Done
```
### child table
Print table of attached children.
```bash
> child table
| ID | RLOC16 | Timeout | Age | LQI In | C_VN |R|S|D|N| Extended MAC |
+-----+--------+------------+------------+--------+------+-+-+-+-+------------------+
| 1 | 0xe001 | 240 | 44 | 3 | 237 |1|1|1|1| d28d7f875888fccb |
| 2 | 0xe002 | 240 | 27 | 3 | 237 |0|1|0|1| e2b3540590b0fd87 |
Done
```
### child \<id\>
Print diagnostic information for an attached Thread Child. The `id` may be a Child ID or an RLOC16.
@@ -1004,7 +1017,7 @@ Done
### router list
List allocated Router IDs
List allocated Router IDs.
```bash
> router list
@@ -1012,6 +1025,19 @@ List allocated Router IDs
Done
```
### router table
Print table of routers.
```bash
> router table
| ID | RLOC16 | Next Hop | Path Cost | LQI In | LQI Out | Age | Extended MAC |
+----+--------+----------+-----------+--------+---------+-----+------------------+
| 21 | 0x5400 | 21 | 0 | 3 | 3 | 5 | d28d7f875888fccb |
| 56 | 0xe000 | 56 | 0 | 0 | 0 | 182 | f2d92a82c8d8fe43 |
Done
```
### router \<id\>
Print diagnostic information for a Thread Router. The `id` may be a Router ID or an RLOC16.
@@ -1227,4 +1253,3 @@ Diagnostics module is enabled only when building OpenThread with --enable-diag o
Go [diagnostics module][1] for more information.
[1]:../diag/README.md
+63 -4
View File
@@ -323,11 +323,18 @@ void Interpreter::ProcessChild(int argc, char *argv[])
ThreadError error = kThreadError_None;
otChildInfo childInfo;
long value;
bool isTable = false;
VerifyOrExit(argc > 0, error = kThreadError_Parse);
if (strcmp(argv[0], "list") == 0)
if (strcmp(argv[0], "list") == 0 || (isTable = (strcmp(argv[0], "table") == 0)))
{
if (isTable)
{
sServer->OutputFormat("| ID | RLOC16 | Timeout | Age | LQI In | C_VN |R|S|D|N| Extended MAC |\r\n");
sServer->OutputFormat("+-----+--------+------------+------------+--------+------+-+-+-+-+------------------+\r\n");
}
for (uint8_t i = 0; ; i++)
{
if (otGetChildInfoByIndex(mInstance, i, &childInfo) != kThreadError_None)
@@ -338,7 +345,31 @@ void Interpreter::ProcessChild(int argc, char *argv[])
if (childInfo.mTimeout > 0)
{
sServer->OutputFormat("%d ", childInfo.mChildId);
if (isTable)
{
sServer->OutputFormat("| %3d ", childInfo.mChildId);
sServer->OutputFormat("| 0x%04x ", childInfo.mRloc16);
sServer->OutputFormat("| %10d ", childInfo.mTimeout);
sServer->OutputFormat("| %10d ", childInfo.mAge);
sServer->OutputFormat("| %6d ", childInfo.mLinkQualityIn);
sServer->OutputFormat("| %4d ", childInfo.mNetworkDataVersion);
sServer->OutputFormat("|%1d", childInfo.mRxOnWhenIdle);
sServer->OutputFormat("|%1d", childInfo.mSecureDataRequest);
sServer->OutputFormat("|%1d", childInfo.mFullFunction);
sServer->OutputFormat("|%1d", childInfo.mFullNetworkData);
sServer->OutputFormat("| ");
for (size_t j = 0; j < sizeof(childInfo.mExtAddress); j++)
{
sServer->OutputFormat("%02x", childInfo.mExtAddress.m8[j]);
}
sServer->OutputFormat(" |\r\n");
}
else
{
sServer->OutputFormat("%d ", childInfo.mChildId);
}
}
}
}
@@ -1621,11 +1652,18 @@ void Interpreter::ProcessRouter(int argc, char *argv[])
ThreadError error = kThreadError_None;
otRouterInfo routerInfo;
long value;
bool isTable = false;
VerifyOrExit(argc > 0, error = kThreadError_Parse);
if (strcmp(argv[0], "list") == 0)
if (strcmp(argv[0], "list") == 0 || (isTable = (strcmp(argv[0], "table") == 0)))
{
if (isTable)
{
sServer->OutputFormat("| ID | RLOC16 | Next Hop | Path Cost | LQI In | LQI Out | Age | Extended MAC |\r\n");
sServer->OutputFormat("+----+--------+----------+-----------+--------+---------+-----+------------------+\r\n");
}
for (uint8_t i = 0; ; i++)
{
if (otGetRouterInfo(mInstance, i, &routerInfo) != kThreadError_None)
@@ -1636,7 +1674,28 @@ void Interpreter::ProcessRouter(int argc, char *argv[])
if (routerInfo.mAllocated)
{
sServer->OutputFormat("%d ", i);
if (isTable)
{
sServer->OutputFormat("| %2d ", routerInfo.mRouterId);
sServer->OutputFormat("| 0x%04x ", routerInfo.mRloc16);
sServer->OutputFormat("| %8d ", routerInfo.mNextHop);
sServer->OutputFormat("| %9d ", routerInfo.mPathCost);
sServer->OutputFormat("| %6d ", routerInfo.mLinkQualityIn);
sServer->OutputFormat("| %7d ", routerInfo.mLinkQualityOut);
sServer->OutputFormat("| %3d ", routerInfo.mAge);
sServer->OutputFormat("| ");
for (size_t j = 0; j < sizeof(routerInfo.mExtAddress); j++)
{
sServer->OutputFormat("%02x", routerInfo.mExtAddress.m8[j]);
}
sServer->OutputFormat(" |\r\n");
}
else
{
sServer->OutputFormat("%d ", i);
}
}
}
}