Skip to content

Commit

Permalink
[ncp] add support for new Spinel property THREAD_ROUTER_TABLE (openth…
Browse files Browse the repository at this point in the history
…read#2303)

This commit adds a new property `SPINEL_PROP_THREAD_ROUTER_TABLE` and
its corresponding get handler to `NcpBase`. The spinel documentation
is also updated. Some of the documentations for the related APIs are
also updated.
  • Loading branch information
abtink authored and jwhui committed Oct 31, 2017
1 parent 4329c0d commit 07647ab
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 2 deletions.
17 changes: 17 additions & 0 deletions doc/spinel-protocol-src/spinel-tech-thread.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,20 @@ Response messages.
* All zeros to clear the steering data (indicating no steering data).
* All 0xFFs to set the steering data (bloom filter) to accept/allow all.
* A specific EUI64 which is then added to steering data/bloom filter.

### PROP 5399: SPINEL_PROP_THREAD_ROUTER_TABLE {#prop-thread-router-table}

* Type: Read-Only
* Packed-Encoding: `A(t(ESCCCCCCb)`

Data per item is:

* `E`: IEEE 802.15.4 Extended Address
* `S`: RLOC16
* `C`: Router ID
* `C`: Next hop to router
* `C`: Path cost to router
* `C`: Link Quality In
* `C`: Link Quality Out
* `C`: Age (seconds since last heard)
* `b`: Link established with Router ID or not.
15 changes: 15 additions & 0 deletions include/openthread/thread_ftd.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,31 @@ OTAPI otError OTCALL otThreadGetChildInfoByIndex(otInstance *aInstance, uint8_t
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @returns The Router ID Sequence.
*
*/
OTAPI uint8_t OTCALL otThreadGetRouterIdSequence(otInstance *aInstance);

/**
* The function returns the maximum allowed router ID
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @returns The maximum allowed router ID.
*
*/
uint8_t otThreadGetMaxRouterId(otInstance *aInstance);

/**
* The function retains diagnostic information for a given Thread Router.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aRouterId The router ID or RLOC16 for a given router.
* @param[out] aRouterInfo A pointer to where the router information is placed.
*
* @retval OT_ERROR_NONE Successfully retrieved the router info for given id.
* @retval OT_ERROR_NOT_FOUND No router entry with the given id.
* @retval OT_ERROR_INVALID_ARGS @p aRouterInfo is NULL.
*
*/
OTAPI otError OTCALL otThreadGetRouterInfo(otInstance *aInstance, uint16_t aRouterId, otRouterInfo *aRouterInfo);

Expand Down
8 changes: 7 additions & 1 deletion src/core/api/thread_ftd_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
#if OPENTHREAD_FTD

#include <openthread/thread_ftd.h>
#include "openthread-core-config.h"
#include "openthread-instance.h"
#include "thread/mle_constants.hpp"

using namespace ot;

Expand Down Expand Up @@ -214,6 +214,12 @@ uint8_t otThreadGetRouterIdSequence(otInstance *aInstance)
return aInstance->mThreadNetif.GetMle().GetRouterIdSequence();
}

uint8_t otThreadGetMaxRouterId(otInstance *aInstance)
{
OT_UNUSED_VARIABLE(aInstance);
return Mle::kMaxRouterId;
}

otError otThreadGetRouterInfo(otInstance *aInstance, uint16_t aRouterId, otRouterInfo *aRouterInfo)
{
otError error = OT_ERROR_NONE;
Expand Down
2 changes: 1 addition & 1 deletion src/core/thread/mle_router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3773,7 +3773,7 @@ otError MleRouter::GetRouterInfo(uint16_t aRouterId, otRouterInfo &aRouterInfo)
}

router = GetRouter(routerId);
VerifyOrExit(router != NULL, error = OT_ERROR_INVALID_ARGS);
VerifyOrExit(router != NULL, error = OT_ERROR_NOT_FOUND);

memcpy(&aRouterInfo.mExtAddress, &router->GetExtAddress(), sizeof(aRouterInfo.mExtAddress));

Expand Down
3 changes: 3 additions & 0 deletions src/core/thread/mle_router_ftd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ class MleRouter: public Mle
* @param[in] aRouterId The router ID or RLOC16 for a given router.
* @param[out] aRouterInfo The router information.
*
* @retval OT_ERROR_NONE Successfully retrieved the router info for given id.
* @retval OT_ERROR_NOT_FOUND No router entry with the given id.
*
*/
otError GetRouterInfo(uint16_t aRouterId, otRouterInfo &aRouterInfo);

Expand Down
1 change: 1 addition & 0 deletions src/ncp/ncp_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ const NcpBase::PropertyHandlerEntry NcpBase::mGetPropertyHandlerTable[] =
NCP_GET_PROP_HANDLER_ENTRY(NET_PSKC),
NCP_GET_PROP_HANDLER_ENTRY(THREAD_LEADER_WEIGHT),
NCP_GET_PROP_HANDLER_ENTRY(THREAD_CHILD_TABLE),
NCP_GET_PROP_HANDLER_ENTRY(THREAD_ROUTER_TABLE),
NCP_GET_PROP_HANDLER_ENTRY(THREAD_LOCAL_LEADER_WEIGHT),
NCP_GET_PROP_HANDLER_ENTRY(THREAD_ROUTER_ROLE_ENABLED),
NCP_GET_PROP_HANDLER_ENTRY(THREAD_CHILD_COUNT_MAX),
Expand Down
1 change: 1 addition & 0 deletions src/ncp/ncp_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ class NcpBase
NCP_SET_PROP_HANDLER(NET_PSKC);

NCP_GET_PROP_HANDLER(THREAD_CHILD_TABLE);
NCP_GET_PROP_HANDLER(THREAD_ROUTER_TABLE);
NCP_GET_PROP_HANDLER(THREAD_CHILD_COUNT_MAX);
NCP_SET_PROP_HANDLER(THREAD_CHILD_COUNT_MAX);
NCP_SET_PROP_HANDLER(THREAD_CHILD_TIMEOUT);
Expand Down
34 changes: 34 additions & 0 deletions src/ncp/ncp_base_ftd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,40 @@ otError NcpBase::GetPropertyHandler_THREAD_CHILD_TABLE(void)
return error;
}

otError NcpBase::GetPropertyHandler_THREAD_ROUTER_TABLE(void)
{
otError error = OT_ERROR_NONE;
otRouterInfo routerInfo;
uint8_t maxRouterId;

maxRouterId = otThreadGetMaxRouterId(mInstance);

for (uint8_t routerId = 0; routerId <= maxRouterId; routerId++)
{
if ((otThreadGetRouterInfo(mInstance, routerId, &routerInfo) != OT_ERROR_NONE) || !routerInfo.mAllocated)
{
continue;
}

SuccessOrExit(error = mEncoder.OpenStruct());

SuccessOrExit(error = mEncoder.WriteEui64(routerInfo.mExtAddress));
SuccessOrExit(error = mEncoder.WriteUint16(routerInfo.mRloc16));
SuccessOrExit(error = mEncoder.WriteUint8(routerInfo.mRouterId));
SuccessOrExit(error = mEncoder.WriteUint8(routerInfo.mNextHop));
SuccessOrExit(error = mEncoder.WriteUint8(routerInfo.mPathCost));
SuccessOrExit(error = mEncoder.WriteUint8(routerInfo.mLinkQualityIn));
SuccessOrExit(error = mEncoder.WriteUint8(routerInfo.mLinkQualityOut));
SuccessOrExit(error = mEncoder.WriteUint8(routerInfo.mAge));
SuccessOrExit(error = mEncoder.WriteBool(routerInfo.mLinkEstablished));

SuccessOrExit(error = mEncoder.CloseStruct());
}

exit:
return error;
}

otError NcpBase::GetPropertyHandler_THREAD_ROUTER_ROLE_ENABLED(void)
{
return mEncoder.WriteBool(otThreadIsRouterRoleEnabled(mInstance));
Expand Down
4 changes: 4 additions & 0 deletions src/ncp/spinel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,10 @@ spinel_prop_key_to_cstr(spinel_prop_key_t prop_key)
ret = "PROP_THREAD_STEERING_DATA";
break;

case SPINEL_PROP_THREAD_ROUTER_TABLE:
ret = "PROP_THREAD_ROUTER_TABLE";
break;

case SPINEL_PROP_IPV6_LL_ADDR:
ret = "PROP_IPV6_LL_ADDR";
break;
Expand Down
18 changes: 18 additions & 0 deletions src/ncp/spinel.h
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,24 @@ typedef enum
*/
SPINEL_PROP_THREAD_STEERING_DATA = SPINEL_PROP_THREAD_EXT__BEGIN + 22,

/// Thread Router Table.
/** Format: `A(t(ESCCCCCCb)`.
*
* Data per item is:
*
* `E`: IEEE 802.15.4 Extended Address
* `S`: RLOC16
* `C`: Router ID
* `C`: Next hop to router
* `C`: Path cost to router
* `C`: Link Quality In
* `C`: Link Quality Out
* `C`: Age (seconds since last heard)
* `b`: Link established with Router ID or not.
*
*/
SPINEL_PROP_THREAD_ROUTER_TABLE = SPINEL_PROP_THREAD_EXT__BEGIN + 23,

SPINEL_PROP_THREAD_EXT__END = 0x1600,

SPINEL_PROP_IPV6__BEGIN = 0x60,
Expand Down

0 comments on commit 07647ab

Please sign in to comment.