mirror of
https://github.com/espressif/openthread.git
synced 2026-08-18 08:29:52 +00:00
Add Minimal Thread Device to build. (#973)
This commit is contained in:
+4
-2
@@ -50,14 +50,16 @@ set -x
|
||||
[ $BUILD_TARGET != arm-gcc49 ] || {
|
||||
export PATH=/tmp/gcc-arm-none-eabi-4_9-2015q3/bin:$PATH || die
|
||||
COMMISSIONER=1 JOINER=1 DHCP6_CLIENT=1 DHCP6_SERVER=1 make -f examples/Makefile-cc2538 || die
|
||||
arm-none-eabi-size output/bin/arm-none-eabi-ot-cli || die
|
||||
arm-none-eabi-size output/bin/arm-none-eabi-ot-cli-ftd || die
|
||||
arm-none-eabi-size output/bin/arm-none-eabi-ot-cli-mtd || die
|
||||
arm-none-eabi-size output/bin/arm-none-eabi-ot-ncp || die
|
||||
}
|
||||
|
||||
[ $BUILD_TARGET != arm-gcc54 ] || {
|
||||
export PATH=/tmp/gcc-arm-none-eabi-5_4-2016q3/bin:$PATH || die
|
||||
COMMISSIONER=1 JOINER=1 DHCP6_CLIENT=1 DHCP6_SERVER=1 make -f examples/Makefile-cc2538 || die
|
||||
arm-none-eabi-size output/bin/arm-none-eabi-ot-cli || die
|
||||
arm-none-eabi-size output/bin/arm-none-eabi-ot-cli-ftd || die
|
||||
arm-none-eabi-size output/bin/arm-none-eabi-ot-cli-mtd || die
|
||||
arm-none-eabi-size output/bin/arm-none-eabi-ot-ncp || die
|
||||
}
|
||||
|
||||
|
||||
@@ -29,54 +29,88 @@
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
|
||||
|
||||
bin_PROGRAMS = \
|
||||
ot-cli \
|
||||
ot-cli-ftd \
|
||||
ot-cli-mtd \
|
||||
$(NULL)
|
||||
|
||||
ot_cli_CPPFLAGS = \
|
||||
CPPFLAGS_COMMON = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/src/core \
|
||||
-I$(top_srcdir)/examples/platforms \
|
||||
$(NULL)
|
||||
|
||||
ot_cli_LDADD = \
|
||||
LDADD_COMMON = \
|
||||
$(top_builddir)/src/cli/libopenthread-cli.a \
|
||||
$(top_builddir)/src/core/libopenthread.a \
|
||||
$(NULL)
|
||||
|
||||
ot_cli_LDFLAGS = \
|
||||
LDFLAGS_COMMON = \
|
||||
$(NULL)
|
||||
|
||||
SOURCES_COMMON = \
|
||||
main.c \
|
||||
$(NULL)
|
||||
|
||||
if OPENTHREAD_ENABLE_BUILTIN_MBEDTLS
|
||||
ot_cli_LDADD += \
|
||||
LDADD_COMMON += \
|
||||
$(top_builddir)/third_party/mbedtls/libmbedcrypto.a \
|
||||
$(NULL)
|
||||
endif # OPENTHREAD_ENABLE_BUILTIN_MBEDTLS
|
||||
|
||||
if OPENTHREAD_ENABLE_DIAG
|
||||
ot_cli_LDADD += \
|
||||
LDADD_COMMON += \
|
||||
$(top_builddir)/src/diag/libopenthread-diag.a \
|
||||
$(NULL)
|
||||
endif
|
||||
endif # OPENTHREAD_ENABLE_DIAG
|
||||
|
||||
if OPENTHREAD_EXAMPLES_POSIX
|
||||
ot_cli_LDADD += \
|
||||
LDADD_COMMON += \
|
||||
$(top_builddir)/examples/platforms/posix/libopenthread-posix.a \
|
||||
-lstdc++ \
|
||||
$(NULL)
|
||||
endif
|
||||
endif # OPENTHREAD_EXAMPLES_POSIX
|
||||
|
||||
if OPENTHREAD_EXAMPLES_CC2538
|
||||
ot_cli_LDADD += \
|
||||
LDADD_COMMON += \
|
||||
$(top_builddir)/examples/platforms/cc2538/libopenthread-cc2538.a \
|
||||
$(NULL)
|
||||
|
||||
ot_cli_LDFLAGS += \
|
||||
LDFLAGS_COMMON += \
|
||||
-T $(top_srcdir)/examples/platforms/cc2538/cc2538.ld \
|
||||
$(NULL)
|
||||
endif
|
||||
endif # OPENTHREAD_EXAMPLES_CC2538
|
||||
|
||||
ot_cli_SOURCES = \
|
||||
main.c \
|
||||
ot_cli_ftd_CPPFLAGS = \
|
||||
$(CPPFLAGS_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
ot_cli_ftd_LDADD = \
|
||||
$(top_builddir)/src/core/libopenthread-ftd.a \
|
||||
$(LDADD_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
ot_cli_ftd_LDFLAGS = \
|
||||
$(LDFLAGS_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
ot_cli_ftd_SOURCES = \
|
||||
$(SOURCES_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
ot_cli_mtd_CPPFLAGS = \
|
||||
$(CPPFLAGS_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
ot_cli_mtd_LDADD = \
|
||||
$(top_builddir)/src/core/libopenthread-mtd.a \
|
||||
$(LDADD_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
ot_cli_mtd_LDFLAGS = \
|
||||
$(LDFLAGS_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
ot_cli_mtd_SOURCES = \
|
||||
$(SOURCES_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
if OPENTHREAD_BUILD_COVERAGE
|
||||
|
||||
@@ -20,7 +20,7 @@ Spawn the process:
|
||||
|
||||
```bash
|
||||
$ cd <path-to-openthread>/output/<platform>/bin
|
||||
$ ./ot-cli 1
|
||||
$ ./ot-cli-ftd 1
|
||||
```
|
||||
|
||||
Set the PAN ID:
|
||||
@@ -67,7 +67,7 @@ Spawn the process:
|
||||
|
||||
```bash
|
||||
$ cd <path-to-openthread>/output/<platform>/bin
|
||||
$ ./ot-cli 2
|
||||
$ ./ot-cli-ftd 2
|
||||
```
|
||||
|
||||
Set the PAN ID:
|
||||
|
||||
@@ -39,7 +39,7 @@ ot_ncp_CPPFLAGS = \
|
||||
$(NULL)
|
||||
|
||||
ot_ncp_LDADD = \
|
||||
$(top_builddir)/src/core/libopenthread.a \
|
||||
$(top_builddir)/src/core/libopenthread-ftd.a \
|
||||
$(top_builddir)/src/ncp/libopenthread-ncp.a \
|
||||
$(NULL)
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ After a successful build, the `elf` files are found in
|
||||
`<path-to-openthread>/output/bin`. You can convert them to `bin`
|
||||
files using `arm-none-eabi-objcopy`:
|
||||
```bash
|
||||
$ arm-none-eabi-objcopy -O binary arm-none-eabi-ot-cli arm-none-eabi-ot-cli.bin
|
||||
$ arm-none-eabi-objcopy -O binary arm-none-eabi-ot-cli-ftd arm-none-eabi-ot-cli-ftd.bin
|
||||
```
|
||||
|
||||
## Flash Binaries
|
||||
|
||||
@@ -21,7 +21,7 @@ After a successful build, the `elf` files are found in
|
||||
|
||||
```bash
|
||||
$ cd <path-to-openthread>/output/<platform>/bin
|
||||
$ ./ot-cli 1
|
||||
$ ./ot-cli-ftd 1
|
||||
```
|
||||
|
||||
2. Type `help` for list of commands.
|
||||
|
||||
+45
-15
@@ -28,14 +28,17 @@
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
|
||||
|
||||
lib_LIBRARIES = libopenthread.a
|
||||
lib_LIBRARIES = \
|
||||
libopenthread-ftd.a \
|
||||
libopenthread-mtd.a \
|
||||
$(NULL)
|
||||
|
||||
libopenthread_a_CPPFLAGS = \
|
||||
CPPFLAGS_COMMON = \
|
||||
-I$(top_srcdir)/include \
|
||||
$(OPENTHREAD_TARGET_DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
libopenthread_a_SOURCES = \
|
||||
SOURCES_COMMON = \
|
||||
openthread.cpp \
|
||||
coap/coap_base.cpp \
|
||||
coap/coap_client.cpp \
|
||||
@@ -57,8 +60,6 @@ libopenthread_a_SOURCES = \
|
||||
mac/mac_frame.cpp \
|
||||
mac/mac_whitelist.cpp \
|
||||
mac/mac_blacklist.cpp \
|
||||
meshcop/joiner_router.cpp \
|
||||
meshcop/leader.cpp \
|
||||
net/icmp6.cpp \
|
||||
net/ip6.cpp \
|
||||
net/ip6_address.cpp \
|
||||
@@ -67,7 +68,6 @@ libopenthread_a_SOURCES = \
|
||||
net/ip6_routes.cpp \
|
||||
net/netif.cpp \
|
||||
net/udp6.cpp \
|
||||
thread/address_resolver.cpp \
|
||||
thread/announce_begin_server.cpp \
|
||||
thread/energy_scan_server.cpp \
|
||||
thread/key_manager.cpp \
|
||||
@@ -78,10 +78,8 @@ libopenthread_a_SOURCES = \
|
||||
thread/meshcop_tlvs.cpp \
|
||||
thread/mesh_forwarder.cpp \
|
||||
thread/mle.cpp \
|
||||
thread/mle_router.cpp \
|
||||
thread/mle_tlvs.cpp \
|
||||
thread/network_data.cpp \
|
||||
thread/network_data_local.cpp \
|
||||
thread/network_data_leader.cpp \
|
||||
thread/panid_query_server.cpp \
|
||||
thread/network_diag.cpp \
|
||||
@@ -92,7 +90,7 @@ libopenthread_a_SOURCES = \
|
||||
$(NULL)
|
||||
|
||||
if OPENTHREAD_ENABLE_COMMISSIONER
|
||||
libopenthread_a_SOURCES += \
|
||||
SOURCES_COMMON += \
|
||||
coap/secure_coap_server.cpp \
|
||||
meshcop/announce_begin_client.cpp \
|
||||
meshcop/commissioner.cpp \
|
||||
@@ -102,36 +100,58 @@ libopenthread_a_SOURCES += \
|
||||
endif # OPENTHREAD_ENABLE_COMMISSIONER
|
||||
|
||||
if OPENTHREAD_ENABLE_JOINER
|
||||
libopenthread_a_SOURCES += \
|
||||
SOURCES_COMMON += \
|
||||
coap/secure_coap_client.cpp \
|
||||
meshcop/joiner.cpp \
|
||||
$(NULL)
|
||||
endif # OPENTHREAD_ENABLE_JOINER
|
||||
|
||||
if OPENTHREAD_ENABLE_DTLS
|
||||
libopenthread_a_SOURCES += \
|
||||
coap/secure_coap_client.cpp \
|
||||
SOURCES_COMMON += \
|
||||
meshcop/dtls.cpp \
|
||||
$(NULL)
|
||||
endif # OPENTHREAD_ENABLE_DTLS
|
||||
|
||||
if OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
libopenthread_a_SOURCES += \
|
||||
SOURCES_COMMON += \
|
||||
net/dhcp6_client.cpp \
|
||||
$(NULL)
|
||||
endif # OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
|
||||
if OPENTHREAD_ENABLE_DHCP6_SERVER
|
||||
libopenthread_a_SOURCES += \
|
||||
SOURCES_COMMON += \
|
||||
net/dhcp6_server.cpp \
|
||||
$(NULL)
|
||||
endif # OPENTHREAD_ENABLE_DHCP6_SERVER
|
||||
|
||||
if OPENTHREAD_ENABLE_JAM_DETECTION
|
||||
libopenthread_a_SOURCES += \
|
||||
SOURCES_COMMON += \
|
||||
utils/jam_detector.cpp \
|
||||
$(NULL)
|
||||
endif # OPENTHREAD_ENABLE_DHCP6_SERVER
|
||||
|
||||
libopenthread_ftd_a_CPPFLAGS = \
|
||||
$(CPPFLAGS_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
libopenthread_ftd_a_SOURCES = \
|
||||
$(SOURCES_COMMON) \
|
||||
meshcop/joiner_router.cpp \
|
||||
meshcop/leader.cpp \
|
||||
thread/address_resolver.cpp \
|
||||
thread/mle_router.cpp \
|
||||
thread/network_data_local.cpp \
|
||||
$(NULL)
|
||||
|
||||
libopenthread_mtd_a_CPPFLAGS = \
|
||||
$(CPPFLAGS_COMMON) \
|
||||
-DOPENTHREAD_MTD \
|
||||
$(NULL)
|
||||
|
||||
libopenthread_mtd_a_SOURCES = \
|
||||
$(SOURCES_COMMON) \
|
||||
$(NULL)
|
||||
|
||||
noinst_HEADERS = \
|
||||
openthread-core-config.h \
|
||||
openthread-core-default-config.h \
|
||||
@@ -168,7 +188,11 @@ noinst_HEADERS = \
|
||||
meshcop/energy_scan_client.hpp \
|
||||
meshcop/joiner.hpp \
|
||||
meshcop/joiner_router.hpp \
|
||||
meshcop/joiner_router_ftd.hpp \
|
||||
meshcop/joiner_router_mtd.hpp \
|
||||
meshcop/leader.hpp \
|
||||
meshcop/leader_ftd.hpp \
|
||||
meshcop/leader_mtd.hpp \
|
||||
meshcop/panid_query_client.hpp \
|
||||
net/icmp6.hpp \
|
||||
net/ip6.hpp \
|
||||
@@ -185,6 +209,8 @@ noinst_HEADERS = \
|
||||
net/dhcp6_client.hpp \
|
||||
net/dhcp6_server.hpp \
|
||||
thread/address_resolver.hpp \
|
||||
thread/address_resolver_ftd.hpp \
|
||||
thread/address_resolver_mtd.hpp \
|
||||
thread/announce_begin_server.hpp \
|
||||
thread/energy_scan_server.hpp \
|
||||
thread/key_manager.hpp \
|
||||
@@ -198,10 +224,14 @@ noinst_HEADERS = \
|
||||
thread/mle.hpp \
|
||||
thread/mle_constants.hpp \
|
||||
thread/mle_router.hpp \
|
||||
thread/mle_router_ftd.hpp \
|
||||
thread/mle_router_mtd.hpp \
|
||||
thread/mle_tlvs.hpp \
|
||||
thread/network_data.hpp \
|
||||
thread/network_data_leader.hpp \
|
||||
thread/network_data_local.hpp \
|
||||
thread/network_data_local_ftd.hpp \
|
||||
thread/network_data_local_mtd.hpp \
|
||||
thread/network_data_tlvs.hpp \
|
||||
thread/panid_query_server.hpp \
|
||||
thread/network_diag.hpp \
|
||||
|
||||
@@ -26,85 +26,8 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes definitions for the Joiner Router role.
|
||||
*/
|
||||
|
||||
#ifndef JOINER_ROUTER_HPP_
|
||||
#define JOINER_ROUTER_HPP_
|
||||
|
||||
#include <openthread-types.h>
|
||||
|
||||
#include <coap/coap_header.hpp>
|
||||
#include <coap/coap_client.hpp>
|
||||
#include <coap/coap_server.hpp>
|
||||
#include <common/message.hpp>
|
||||
#include <mac/mac_frame.hpp>
|
||||
#include <net/udp6.hpp>
|
||||
|
||||
namespace Thread {
|
||||
|
||||
class ThreadNetif;
|
||||
|
||||
namespace MeshCoP {
|
||||
|
||||
class JoinerRouter
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This constructor initializes the Joiner Router object.
|
||||
*
|
||||
* @param[in] aThreadNetif A reference to the Thread network interface.
|
||||
*
|
||||
*/
|
||||
JoinerRouter(ThreadNetif &aNetif);
|
||||
|
||||
/**
|
||||
* This method returns the Joiner UDP Port.
|
||||
*
|
||||
* @returns The Joiner UDP Port number .
|
||||
*
|
||||
*/
|
||||
uint16_t GetJoinerUdpPort(void);
|
||||
|
||||
/**
|
||||
* This method sets the Joiner UDP Port.
|
||||
*
|
||||
* @param[in] The Joiner UDP Port number.
|
||||
*
|
||||
* @retval kThreadError_None Successfully set the Joiner UDP Port.
|
||||
*
|
||||
*/
|
||||
ThreadError SetJoinerUdpPort(uint16_t aJoinerUdpPort);
|
||||
|
||||
private:
|
||||
static void HandleNetifStateChanged(uint32_t aFlags, void *aContext);
|
||||
void HandleNetifStateChanged(uint32_t aFlags);
|
||||
|
||||
static void HandleUdpReceive(void *aContext, otMessage aMessage, const otMessageInfo *aMessageInfo);
|
||||
void HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
static void HandleRelayTransmit(void *aContext, otCoapHeader *aHeader, otMessage aMessage,
|
||||
const otMessageInfo *aMessageInfo);
|
||||
void HandleRelayTransmit(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
ThreadError SendJoinerEntrust(const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
ThreadError GetBorderAgentRloc(uint16_t &aRloc);
|
||||
|
||||
Ip6::NetifCallback mNetifCallback;
|
||||
|
||||
Ip6::UdpSocket mSocket;
|
||||
Coap::Resource mRelayTransmit;
|
||||
Coap::Client &mCoapClient;
|
||||
ThreadNetif &mNetif;
|
||||
|
||||
uint16_t mJoinerUdpPort;
|
||||
bool mIsJoinerPortConfigured;
|
||||
};
|
||||
|
||||
} // namespace MeshCoP
|
||||
} // namespace Thread
|
||||
|
||||
#endif // JOINER_ROUTER_HPP_
|
||||
#ifdef OPENTHREAD_MTD
|
||||
#include "joiner_router_mtd.hpp"
|
||||
#else
|
||||
#include "joiner_router_ftd.hpp"
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (c) 2016, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes definitions for the Joiner Router role.
|
||||
*/
|
||||
|
||||
#ifndef JOINER_ROUTER_HPP_
|
||||
#define JOINER_ROUTER_HPP_
|
||||
|
||||
#include <openthread-types.h>
|
||||
|
||||
#include <coap/coap_header.hpp>
|
||||
#include <coap/coap_client.hpp>
|
||||
#include <coap/coap_server.hpp>
|
||||
#include <common/message.hpp>
|
||||
#include <mac/mac_frame.hpp>
|
||||
#include <net/udp6.hpp>
|
||||
|
||||
namespace Thread {
|
||||
|
||||
class ThreadNetif;
|
||||
|
||||
namespace MeshCoP {
|
||||
|
||||
class JoinerRouter
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This constructor initializes the Joiner Router object.
|
||||
*
|
||||
* @param[in] aThreadNetif A reference to the Thread network interface.
|
||||
*
|
||||
*/
|
||||
JoinerRouter(ThreadNetif &aNetif);
|
||||
|
||||
/**
|
||||
* This method returns the Joiner UDP Port.
|
||||
*
|
||||
* @returns The Joiner UDP Port number .
|
||||
*
|
||||
*/
|
||||
uint16_t GetJoinerUdpPort(void);
|
||||
|
||||
/**
|
||||
* This method sets the Joiner UDP Port.
|
||||
*
|
||||
* @param[in] The Joiner UDP Port number.
|
||||
*
|
||||
* @retval kThreadError_None Successfully set the Joiner UDP Port.
|
||||
*
|
||||
*/
|
||||
ThreadError SetJoinerUdpPort(uint16_t aJoinerUdpPort);
|
||||
|
||||
private:
|
||||
static void HandleNetifStateChanged(uint32_t aFlags, void *aContext);
|
||||
void HandleNetifStateChanged(uint32_t aFlags);
|
||||
|
||||
static void HandleUdpReceive(void *aContext, otMessage aMessage, const otMessageInfo *aMessageInfo);
|
||||
void HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
static void HandleRelayTransmit(void *aContext, otCoapHeader *aHeader, otMessage aMessage,
|
||||
const otMessageInfo *aMessageInfo);
|
||||
void HandleRelayTransmit(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
ThreadError SendJoinerEntrust(const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
ThreadError GetBorderAgentRloc(uint16_t &aRloc);
|
||||
|
||||
Ip6::NetifCallback mNetifCallback;
|
||||
|
||||
Ip6::UdpSocket mSocket;
|
||||
Coap::Resource mRelayTransmit;
|
||||
Coap::Client &mCoapClient;
|
||||
ThreadNetif &mNetif;
|
||||
|
||||
uint16_t mJoinerUdpPort;
|
||||
bool mIsJoinerPortConfigured;
|
||||
};
|
||||
|
||||
} // namespace MeshCoP
|
||||
} // namespace Thread
|
||||
|
||||
#endif // JOINER_ROUTER_HPP_
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2016, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes definitions for the Joiner Router role.
|
||||
*/
|
||||
|
||||
#ifndef JOINER_ROUTER_HPP_
|
||||
#define JOINER_ROUTER_HPP_
|
||||
|
||||
namespace Thread {
|
||||
namespace MeshCoP {
|
||||
|
||||
class JoinerRouter
|
||||
{
|
||||
public:
|
||||
JoinerRouter(ThreadNetif &) { }
|
||||
uint16_t GetJoinerUdpPort(void) { return 0; }
|
||||
ThreadError SetJoinerUdpPort(uint16_t) { return kThreadError_NotImplemented; }
|
||||
};
|
||||
|
||||
} // namespace MeshCoP
|
||||
} // namespace Thread
|
||||
|
||||
#endif // JOINER_ROUTER_HPP_
|
||||
@@ -26,98 +26,8 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes definitions for a MeshCoP Leader.
|
||||
*/
|
||||
|
||||
#ifndef MESHCOP_LEADER_HPP_
|
||||
#define MESHCOP_LEADER_HPP_
|
||||
|
||||
#include <coap/coap_client.hpp>
|
||||
#include <coap/coap_server.hpp>
|
||||
#include <common/timer.hpp>
|
||||
#include <net/udp6.hpp>
|
||||
#include <thread/meshcop_tlvs.hpp>
|
||||
#include <thread/mle.hpp>
|
||||
|
||||
namespace Thread {
|
||||
namespace MeshCoP {
|
||||
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class CommissioningData
|
||||
{
|
||||
public:
|
||||
uint8_t GetLength(void) const {
|
||||
return sizeof(Tlv) + mBorderAgentLocator.GetLength() +
|
||||
sizeof(Tlv) + mCommissionerSessionId.GetLength() +
|
||||
sizeof(Tlv) + mSteeringData.GetLength();
|
||||
}
|
||||
|
||||
BorderAgentLocatorTlv mBorderAgentLocator;
|
||||
CommissionerSessionIdTlv mCommissionerSessionId;
|
||||
SteeringDataTlv mSteeringData;
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
class Leader
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This constructor initializes the Leader object.
|
||||
*
|
||||
* @param[in] aThreadNetif A reference to the Thread network interface.
|
||||
*
|
||||
*/
|
||||
Leader(ThreadNetif &aThreadNetif);
|
||||
|
||||
/**
|
||||
* This method sends a MGMT_DATASET_CHANGED message to commissioner.
|
||||
*
|
||||
* @param[in] aAddress The IPv6 address of destination.
|
||||
*
|
||||
* @retval kThreadError_None Successfully send MGMT_DATASET_CHANGED message.
|
||||
* @retval kThreadError_NoBufs Insufficient buffers to generate a MGMT_DATASET_CHANGED message.
|
||||
*
|
||||
*/
|
||||
ThreadError SendDatasetChanged(const Ip6::Address &aAddress);
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
kTimeoutLeaderPetition = 50, ///< TIMEOUT_LEAD_PET (seconds)
|
||||
};
|
||||
|
||||
static void HandleTimer(void *aContext);
|
||||
void HandleTimer(void);
|
||||
|
||||
static void HandlePetition(void *aContext, otCoapHeader *aHeader, otMessage aMessage,
|
||||
const otMessageInfo *aMessageInfo);
|
||||
void HandlePetition(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
ThreadError SendPetitionResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo,
|
||||
StateTlv::State aState);
|
||||
|
||||
static void HandleKeepAlive(void *aContext, otCoapHeader *aHeader, otMessage aMessage,
|
||||
const otMessageInfo *aMessageInfo);
|
||||
void HandleKeepAlive(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
ThreadError SendKeepAliveResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo,
|
||||
StateTlv::State aState);
|
||||
|
||||
static void HandleUdpReceive(void *aContext, otMessage aMessage, const otMessageInfo *aMessageInfo);
|
||||
|
||||
Coap::Resource mPetition;
|
||||
Coap::Resource mKeepAlive;
|
||||
Coap::Server &mCoapServer;
|
||||
Coap::Client &mCoapClient;
|
||||
NetworkData::Leader &mNetworkData;
|
||||
|
||||
Timer mTimer;
|
||||
|
||||
CommissionerIdTlv mCommissionerId;
|
||||
uint16_t mSessionId;
|
||||
ThreadNetif &mNetif;
|
||||
};
|
||||
|
||||
} // namespace MeshCoP
|
||||
} // namespace Thread
|
||||
|
||||
#endif // MESHCOP_LEADER_HPP_
|
||||
#ifdef OPENTHREAD_MTD
|
||||
#include "leader_mtd.hpp"
|
||||
#else
|
||||
#include "leader_ftd.hpp"
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (c) 2016, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes definitions for a MeshCoP Leader.
|
||||
*/
|
||||
|
||||
#ifndef MESHCOP_LEADER_HPP_
|
||||
#define MESHCOP_LEADER_HPP_
|
||||
|
||||
#include <coap/coap_client.hpp>
|
||||
#include <coap/coap_server.hpp>
|
||||
#include <common/timer.hpp>
|
||||
#include <net/udp6.hpp>
|
||||
#include <thread/meshcop_tlvs.hpp>
|
||||
#include <thread/mle.hpp>
|
||||
|
||||
namespace Thread {
|
||||
namespace MeshCoP {
|
||||
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class CommissioningData
|
||||
{
|
||||
public:
|
||||
uint8_t GetLength(void) const {
|
||||
return sizeof(Tlv) + mBorderAgentLocator.GetLength() +
|
||||
sizeof(Tlv) + mCommissionerSessionId.GetLength() +
|
||||
sizeof(Tlv) + mSteeringData.GetLength();
|
||||
}
|
||||
|
||||
BorderAgentLocatorTlv mBorderAgentLocator;
|
||||
CommissionerSessionIdTlv mCommissionerSessionId;
|
||||
SteeringDataTlv mSteeringData;
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
class Leader
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This constructor initializes the Leader object.
|
||||
*
|
||||
* @param[in] aThreadNetif A reference to the Thread network interface.
|
||||
*
|
||||
*/
|
||||
Leader(ThreadNetif &aThreadNetif);
|
||||
|
||||
/**
|
||||
* This method sends a MGMT_DATASET_CHANGED message to commissioner.
|
||||
*
|
||||
* @param[in] aAddress The IPv6 address of destination.
|
||||
*
|
||||
* @retval kThreadError_None Successfully send MGMT_DATASET_CHANGED message.
|
||||
* @retval kThreadError_NoBufs Insufficient buffers to generate a MGMT_DATASET_CHANGED message.
|
||||
*
|
||||
*/
|
||||
ThreadError SendDatasetChanged(const Ip6::Address &aAddress);
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
kTimeoutLeaderPetition = 50, ///< TIMEOUT_LEAD_PET (seconds)
|
||||
};
|
||||
|
||||
static void HandleTimer(void *aContext);
|
||||
void HandleTimer(void);
|
||||
|
||||
static void HandlePetition(void *aContext, otCoapHeader *aHeader, otMessage aMessage,
|
||||
const otMessageInfo *aMessageInfo);
|
||||
void HandlePetition(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
ThreadError SendPetitionResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo,
|
||||
StateTlv::State aState);
|
||||
|
||||
static void HandleKeepAlive(void *aContext, otCoapHeader *aHeader, otMessage aMessage,
|
||||
const otMessageInfo *aMessageInfo);
|
||||
void HandleKeepAlive(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
ThreadError SendKeepAliveResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo,
|
||||
StateTlv::State aState);
|
||||
|
||||
static void HandleUdpReceive(void *aContext, otMessage aMessage, const otMessageInfo *aMessageInfo);
|
||||
|
||||
Coap::Resource mPetition;
|
||||
Coap::Resource mKeepAlive;
|
||||
Coap::Server &mCoapServer;
|
||||
Coap::Client &mCoapClient;
|
||||
NetworkData::Leader &mNetworkData;
|
||||
|
||||
Timer mTimer;
|
||||
|
||||
CommissionerIdTlv mCommissionerId;
|
||||
uint16_t mSessionId;
|
||||
ThreadNetif &mNetif;
|
||||
};
|
||||
|
||||
} // namespace MeshCoP
|
||||
} // namespace Thread
|
||||
|
||||
#endif // MESHCOP_LEADER_HPP_
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2016, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes definitions for a MeshCoP Leader.
|
||||
*/
|
||||
|
||||
#ifndef MESHCOP_LEADER_HPP_
|
||||
#define MESHCOP_LEADER_HPP_
|
||||
|
||||
#include <net/ip6_address.hpp>
|
||||
|
||||
namespace Thread {
|
||||
namespace MeshCoP {
|
||||
|
||||
class Leader
|
||||
{
|
||||
public:
|
||||
Leader(ThreadNetif &) { }
|
||||
ThreadError SendDatasetChanged(const Ip6::Address &) { return kThreadError_NotImplemented; }
|
||||
};
|
||||
|
||||
} // namespace MeshCoP
|
||||
} // namespace Thread
|
||||
|
||||
#endif // MESHCOP_LEADER_HPP_
|
||||
@@ -26,176 +26,8 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes definitions for Thread EID-to-RLOC mapping and caching.
|
||||
*/
|
||||
|
||||
#ifndef ADDRESS_RESOLVER_HPP_
|
||||
#define ADDRESS_RESOLVER_HPP_
|
||||
|
||||
#include <openthread-core-config.h>
|
||||
#include <openthread-types.h>
|
||||
#include <coap/coap_client.hpp>
|
||||
#include <coap/coap_server.hpp>
|
||||
#include <common/timer.hpp>
|
||||
#include <mac/mac.hpp>
|
||||
#include <net/icmp6.hpp>
|
||||
#include <net/udp6.hpp>
|
||||
|
||||
namespace Thread {
|
||||
|
||||
class MeshForwarder;
|
||||
class ThreadLastTransactionTimeTlv;
|
||||
class ThreadMeshLocalEidTlv;
|
||||
class ThreadNetif;
|
||||
class ThreadTargetTlv;
|
||||
|
||||
/**
|
||||
* @addtogroup core-arp
|
||||
*
|
||||
* @brief
|
||||
* This module includes definitions for Thread EID-to-RLOC mapping and caching.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class implements the EID-to-RLOC mapping and caching.
|
||||
*
|
||||
*/
|
||||
class AddressResolver
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This constructor initializes the object.
|
||||
*
|
||||
*/
|
||||
explicit AddressResolver(ThreadNetif &aThreadNetif);
|
||||
|
||||
/**
|
||||
* This method clears the EID-to-RLOC cache.
|
||||
*
|
||||
*/
|
||||
void Clear(void);
|
||||
|
||||
/**
|
||||
* This method gets an EID cache entry.
|
||||
*
|
||||
* @param[in] aIndex An index into the EID cache table.
|
||||
* @param[out] aEntry A pointer to where the EID information is placed.
|
||||
*
|
||||
* @retval kThreadError_None Successfully retrieved the EID cache entry.
|
||||
* @retval kThreadError_InvalidArgs @p aIndex was out of bounds or @p aEntry was NULL.
|
||||
*
|
||||
*/
|
||||
ThreadError GetEntry(uint8_t aIndex, otEidCacheEntry &aEntry) const;
|
||||
|
||||
/**
|
||||
* This method removes a Router ID from the EID-to-RLOC cache.
|
||||
*
|
||||
* @param[in] aRouterId The Router ID.
|
||||
*
|
||||
*/
|
||||
void Remove(uint8_t aRouterId);
|
||||
|
||||
/**
|
||||
* This method returns the RLOC16 for a given EID, or initiates an Address Query if the mapping is not known.
|
||||
*
|
||||
* @param[in] aEid A reference to the EID.
|
||||
* @param[out] aRloc16 The RLOC16 corresponding to @p aEid.
|
||||
*
|
||||
* @retval kTheradError_None Successfully provided the RLOC16.
|
||||
* @retval kThreadError_AddressQuery Initiated an Address Query.
|
||||
*
|
||||
*/
|
||||
ThreadError Resolve(const Ip6::Address &aEid, Mac::ShortAddress &aRloc16);
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
kCacheEntries = OPENTHREAD_CONFIG_ADDRESS_CACHE_ENTRIES,
|
||||
kStateUpdatePeriod = 1000u, ///< State update period in milliseconds.
|
||||
};
|
||||
|
||||
/**
|
||||
* Thread Protocol Parameters and Constants
|
||||
*
|
||||
*/
|
||||
enum
|
||||
{
|
||||
kAddressQueryTimeout = 3, ///< ADDRESS_QUERY_TIMEOUT (seconds)
|
||||
kAddressQueryInitialRetryDelay = 15, ///< ADDRESS_QUERY_INITIAL_RETRY_DELAY (seconds)
|
||||
kAddressQueryMaxRetryDelay = 28800, ///< ADDRESS_QUERY_MAX_RETRY_DELAY (seconds)
|
||||
};
|
||||
|
||||
struct Cache
|
||||
{
|
||||
Ip6::Address mTarget;
|
||||
uint8_t mMeshLocalIid[Ip6::Address::kInterfaceIdentifierSize];
|
||||
uint32_t mLastTransactionTime;
|
||||
Mac::ShortAddress mRloc16;
|
||||
uint16_t mRetryTimeout;
|
||||
uint8_t mTimeout;
|
||||
uint8_t mFailures;
|
||||
|
||||
enum State
|
||||
{
|
||||
kStateInvalid,
|
||||
kStateQuery,
|
||||
kStateCached,
|
||||
};
|
||||
State mState;
|
||||
};
|
||||
|
||||
ThreadError SendAddressQuery(const Ip6::Address &aEid);
|
||||
ThreadError SendAddressError(const ThreadTargetTlv &aTarget, const ThreadMeshLocalEidTlv &aEid,
|
||||
const Ip6::Address *aDestination);
|
||||
void SendAddressQueryResponse(const ThreadTargetTlv &aTargetTlv, const ThreadMeshLocalEidTlv &aMlEidTlv,
|
||||
const ThreadLastTransactionTimeTlv *aLastTransactionTimeTlv,
|
||||
const Ip6::Address &aDestination);
|
||||
void SendAddressErrorResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aRequestInfo);
|
||||
void SendAddressNotificationResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aRequestInfo);
|
||||
|
||||
static void HandleUdpReceive(void *aContext, otMessage aMessage, const otMessageInfo *aMessageInfo);
|
||||
|
||||
static void HandleAddressError(void *aContext, otCoapHeader *aHeader, otMessage aMessage,
|
||||
const otMessageInfo *aMessageInfo);
|
||||
void HandleAddressError(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
static void HandleAddressQuery(void *aContext, otCoapHeader *aHeader, otMessage aMessage,
|
||||
const otMessageInfo *aMessageInfo);
|
||||
void HandleAddressQuery(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
static void HandleAddressNotification(void *aContext, otCoapHeader *aHeader, otMessage aMessage,
|
||||
const otMessageInfo *aMessageInfo);
|
||||
void HandleAddressNotification(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
static void HandleDstUnreach(void *aContext, Message &aMessage, const Ip6::MessageInfo &aMessageInfo,
|
||||
const Ip6::IcmpHeader &aIcmpHeader);
|
||||
void HandleDstUnreach(Message &aMessage, const Ip6::MessageInfo &aMessageInfo, const Ip6::IcmpHeader &aIcmpHeader);
|
||||
|
||||
static void HandleTimer(void *aContext);
|
||||
void HandleTimer(void);
|
||||
|
||||
Coap::Resource mAddressError;
|
||||
Coap::Resource mAddressQuery;
|
||||
Coap::Resource mAddressNotification;
|
||||
Cache mCache[kCacheEntries];
|
||||
Ip6::IcmpHandler mIcmpHandler;
|
||||
Timer mTimer;
|
||||
|
||||
MeshForwarder &mMeshForwarder;
|
||||
Coap::Server &mCoapServer;
|
||||
Coap::Client &mCoapClient;
|
||||
Mle::MleRouter &mMle;
|
||||
Ip6::Netif &mNetif;
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
} // namespace Thread
|
||||
|
||||
#endif // ADDRESS_RESOLVER_HPP_
|
||||
#ifdef OPENTHREAD_MTD
|
||||
#include "address_resolver_mtd.hpp"
|
||||
#else
|
||||
#include "address_resolver_ftd.hpp"
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* Copyright (c) 2016, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes definitions for Thread EID-to-RLOC mapping and caching.
|
||||
*/
|
||||
|
||||
#ifndef ADDRESS_RESOLVER_HPP_
|
||||
#define ADDRESS_RESOLVER_HPP_
|
||||
|
||||
#include <openthread-core-config.h>
|
||||
#include <openthread-types.h>
|
||||
#include <coap/coap_client.hpp>
|
||||
#include <coap/coap_server.hpp>
|
||||
#include <common/timer.hpp>
|
||||
#include <mac/mac.hpp>
|
||||
#include <net/icmp6.hpp>
|
||||
#include <net/udp6.hpp>
|
||||
|
||||
namespace Thread {
|
||||
|
||||
class MeshForwarder;
|
||||
class ThreadLastTransactionTimeTlv;
|
||||
class ThreadMeshLocalEidTlv;
|
||||
class ThreadNetif;
|
||||
class ThreadTargetTlv;
|
||||
|
||||
/**
|
||||
* @addtogroup core-arp
|
||||
*
|
||||
* @brief
|
||||
* This module includes definitions for Thread EID-to-RLOC mapping and caching.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class implements the EID-to-RLOC mapping and caching.
|
||||
*
|
||||
*/
|
||||
class AddressResolver
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This constructor initializes the object.
|
||||
*
|
||||
*/
|
||||
explicit AddressResolver(ThreadNetif &aThreadNetif);
|
||||
|
||||
/**
|
||||
* This method clears the EID-to-RLOC cache.
|
||||
*
|
||||
*/
|
||||
void Clear(void);
|
||||
|
||||
/**
|
||||
* This method gets an EID cache entry.
|
||||
*
|
||||
* @param[in] aIndex An index into the EID cache table.
|
||||
* @param[out] aEntry A pointer to where the EID information is placed.
|
||||
*
|
||||
* @retval kThreadError_None Successfully retrieved the EID cache entry.
|
||||
* @retval kThreadError_InvalidArgs @p aIndex was out of bounds or @p aEntry was NULL.
|
||||
*
|
||||
*/
|
||||
ThreadError GetEntry(uint8_t aIndex, otEidCacheEntry &aEntry) const;
|
||||
|
||||
/**
|
||||
* This method removes a Router ID from the EID-to-RLOC cache.
|
||||
*
|
||||
* @param[in] aRouterId The Router ID.
|
||||
*
|
||||
*/
|
||||
void Remove(uint8_t aRouterId);
|
||||
|
||||
/**
|
||||
* This method returns the RLOC16 for a given EID, or initiates an Address Query if the mapping is not known.
|
||||
*
|
||||
* @param[in] aEid A reference to the EID.
|
||||
* @param[out] aRloc16 The RLOC16 corresponding to @p aEid.
|
||||
*
|
||||
* @retval kTheradError_None Successfully provided the RLOC16.
|
||||
* @retval kThreadError_AddressQuery Initiated an Address Query.
|
||||
*
|
||||
*/
|
||||
ThreadError Resolve(const Ip6::Address &aEid, Mac::ShortAddress &aRloc16);
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
kCacheEntries = OPENTHREAD_CONFIG_ADDRESS_CACHE_ENTRIES,
|
||||
kStateUpdatePeriod = 1000u, ///< State update period in milliseconds.
|
||||
};
|
||||
|
||||
/**
|
||||
* Thread Protocol Parameters and Constants
|
||||
*
|
||||
*/
|
||||
enum
|
||||
{
|
||||
kAddressQueryTimeout = 3, ///< ADDRESS_QUERY_TIMEOUT (seconds)
|
||||
kAddressQueryInitialRetryDelay = 15, ///< ADDRESS_QUERY_INITIAL_RETRY_DELAY (seconds)
|
||||
kAddressQueryMaxRetryDelay = 28800, ///< ADDRESS_QUERY_MAX_RETRY_DELAY (seconds)
|
||||
};
|
||||
|
||||
struct Cache
|
||||
{
|
||||
Ip6::Address mTarget;
|
||||
uint8_t mMeshLocalIid[Ip6::Address::kInterfaceIdentifierSize];
|
||||
uint32_t mLastTransactionTime;
|
||||
Mac::ShortAddress mRloc16;
|
||||
uint16_t mRetryTimeout;
|
||||
uint8_t mTimeout;
|
||||
uint8_t mFailures;
|
||||
|
||||
enum State
|
||||
{
|
||||
kStateInvalid,
|
||||
kStateQuery,
|
||||
kStateCached,
|
||||
};
|
||||
State mState;
|
||||
};
|
||||
|
||||
ThreadError SendAddressQuery(const Ip6::Address &aEid);
|
||||
ThreadError SendAddressError(const ThreadTargetTlv &aTarget, const ThreadMeshLocalEidTlv &aEid,
|
||||
const Ip6::Address *aDestination);
|
||||
void SendAddressQueryResponse(const ThreadTargetTlv &aTargetTlv, const ThreadMeshLocalEidTlv &aMlEidTlv,
|
||||
const ThreadLastTransactionTimeTlv *aLastTransactionTimeTlv,
|
||||
const Ip6::Address &aDestination);
|
||||
void SendAddressErrorResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aRequestInfo);
|
||||
void SendAddressNotificationResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aRequestInfo);
|
||||
|
||||
static void HandleUdpReceive(void *aContext, otMessage aMessage, const otMessageInfo *aMessageInfo);
|
||||
|
||||
static void HandleAddressError(void *aContext, otCoapHeader *aHeader, otMessage aMessage,
|
||||
const otMessageInfo *aMessageInfo);
|
||||
void HandleAddressError(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
static void HandleAddressQuery(void *aContext, otCoapHeader *aHeader, otMessage aMessage,
|
||||
const otMessageInfo *aMessageInfo);
|
||||
void HandleAddressQuery(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
static void HandleAddressNotification(void *aContext, otCoapHeader *aHeader, otMessage aMessage,
|
||||
const otMessageInfo *aMessageInfo);
|
||||
void HandleAddressNotification(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
static void HandleDstUnreach(void *aContext, Message &aMessage, const Ip6::MessageInfo &aMessageInfo,
|
||||
const Ip6::IcmpHeader &aIcmpHeader);
|
||||
void HandleDstUnreach(Message &aMessage, const Ip6::MessageInfo &aMessageInfo, const Ip6::IcmpHeader &aIcmpHeader);
|
||||
|
||||
static void HandleTimer(void *aContext);
|
||||
void HandleTimer(void);
|
||||
|
||||
Coap::Resource mAddressError;
|
||||
Coap::Resource mAddressQuery;
|
||||
Coap::Resource mAddressNotification;
|
||||
Cache mCache[kCacheEntries];
|
||||
Ip6::IcmpHandler mIcmpHandler;
|
||||
Timer mTimer;
|
||||
|
||||
MeshForwarder &mMeshForwarder;
|
||||
Coap::Server &mCoapServer;
|
||||
Coap::Client &mCoapClient;
|
||||
Mle::MleRouter &mMle;
|
||||
Ip6::Netif &mNetif;
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
} // namespace Thread
|
||||
|
||||
#endif // ADDRESS_RESOLVER_HPP_
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2016, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes definitions for Thread EID-to-RLOC mapping and caching.
|
||||
*/
|
||||
|
||||
#ifndef ADDRESS_RESOLVER_HPP_
|
||||
#define ADDRESS_RESOLVER_HPP_
|
||||
|
||||
#include <openthread-types.h>
|
||||
|
||||
namespace Thread {
|
||||
|
||||
class AddressResolver
|
||||
{
|
||||
public:
|
||||
explicit AddressResolver(ThreadNetif &) { }
|
||||
void Clear(void) { }
|
||||
ThreadError GetEntry(uint8_t, otEidCacheEntry &) const { return kThreadError_NotImplemented; }
|
||||
void Remove(uint8_t) { }
|
||||
ThreadError Resolve(const Ip6::Address &, Mac::ShortAddress &) { return kThreadError_NotImplemented; }
|
||||
};
|
||||
|
||||
} // namespace Thread
|
||||
|
||||
#endif // ADDRESS_RESOLVER_HPP_
|
||||
@@ -26,747 +26,8 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes definitions for MLE functionality required by the Thread Router and Leader roles.
|
||||
*/
|
||||
|
||||
#ifndef MLE_ROUTER_HPP_
|
||||
#define MLE_ROUTER_HPP_
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <coap/coap_header.hpp>
|
||||
#include <coap/coap_server.hpp>
|
||||
#include <coap/coap_client.hpp>
|
||||
#include <common/timer.hpp>
|
||||
#include <common/trickle_timer.hpp>
|
||||
#include <mac/mac_frame.hpp>
|
||||
#include <net/icmp6.hpp>
|
||||
#include <net/udp6.hpp>
|
||||
#include <thread/mle.hpp>
|
||||
#include <thread/mle_tlvs.hpp>
|
||||
#include <thread/thread_tlvs.hpp>
|
||||
#include <thread/topology.hpp>
|
||||
|
||||
namespace Thread {
|
||||
namespace Mle {
|
||||
|
||||
class MeshForwarder;
|
||||
class NetworkDataLeader;
|
||||
|
||||
/**
|
||||
* @addtogroup core-mle-router
|
||||
*
|
||||
* @brief
|
||||
* This module includes definitions for MLE functionality required by the Thread Router and Leader roles.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class implements functionality required for delaying MLE responses.
|
||||
*
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class DelayedResponseHeader
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Default constructor for the object.
|
||||
*
|
||||
*/
|
||||
DelayedResponseHeader(void) { memset(this, 0, sizeof(*this)); };
|
||||
|
||||
/**
|
||||
* This constructor initializes the object with specific values.
|
||||
*
|
||||
* @param[in] aSendTime Time when the message shall be sent.
|
||||
* @param[in] aDestination IPv6 address of the message destination.
|
||||
*
|
||||
*/
|
||||
DelayedResponseHeader(uint32_t aSendTime, const Ip6::Address &aDestination) {
|
||||
mSendTime = aSendTime;
|
||||
mDestination = aDestination;
|
||||
};
|
||||
|
||||
/**
|
||||
* This method appends delayed response header to the message.
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
*
|
||||
* @retval kThreadError_None Successfully appended the bytes.
|
||||
* @retval kThreadError_NoBufs Insufficient available buffers to grow the message.
|
||||
*
|
||||
*/
|
||||
ThreadError AppendTo(Message &aMessage) {
|
||||
return aMessage.Append(this, sizeof(*this));
|
||||
};
|
||||
|
||||
/**
|
||||
* This method reads delayed response header from the message.
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
*
|
||||
* @returns The number of bytes read.
|
||||
*
|
||||
*/
|
||||
uint16_t ReadFrom(Message &aMessage) {
|
||||
return aMessage.Read(aMessage.GetLength() - sizeof(*this), sizeof(*this), this);
|
||||
};
|
||||
|
||||
/**
|
||||
* This method removes delayed response header from the message.
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
*
|
||||
* @retval kThreadError_None Successfully removed the header.
|
||||
*
|
||||
*/
|
||||
static ThreadError RemoveFrom(Message &aMessage) {
|
||||
return aMessage.SetLength(aMessage.GetLength() - sizeof(DelayedResponseHeader));
|
||||
};
|
||||
|
||||
/**
|
||||
* This method returns a time when the message shall be sent.
|
||||
*
|
||||
* @returns A time when the message shall be sent.
|
||||
*
|
||||
*/
|
||||
uint32_t GetSendTime(void) const { return mSendTime; };
|
||||
|
||||
/**
|
||||
* This method returns a destination of the delayed message.
|
||||
*
|
||||
* @returns A destination of the delayed message.
|
||||
*
|
||||
*/
|
||||
const Ip6::Address &GetDestination(void) const { return mDestination; };
|
||||
|
||||
/**
|
||||
* This method checks if the message shall be sent before the given time.
|
||||
*
|
||||
* @param[in] aTime A time to compare.
|
||||
*
|
||||
* @retval TRUE If the message shall be sent before the given time.
|
||||
* @retval FALSE Otherwise.
|
||||
*/
|
||||
bool IsEarlier(uint32_t aTime) { return (static_cast<int32_t>(aTime - mSendTime) > 0); };
|
||||
|
||||
/**
|
||||
* This method checks if the message shall be sent after the given time.
|
||||
*
|
||||
* @param[in] aTime A time to compare.
|
||||
*
|
||||
* @retval TRUE If the message shall be sent after the given time.
|
||||
* @retval FALSE Otherwise.
|
||||
*/
|
||||
bool IsLater(uint32_t aTime) { return (static_cast<int32_t>(aTime - mSendTime) < 0); };
|
||||
|
||||
private:
|
||||
Ip6::Address mDestination; ///< IPv6 address of the message destination.
|
||||
uint32_t mSendTime; ///< Time when the message shall be sent.
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
/**
|
||||
* This class implements MLE functionality required by the Thread Router and Leader roles.
|
||||
*
|
||||
*/
|
||||
class MleRouter: public Mle
|
||||
{
|
||||
friend class Mle;
|
||||
|
||||
public:
|
||||
/**
|
||||
* This constructor initializes the object.
|
||||
*
|
||||
* @param[in] aThreadNetif A reference to the Thread network interface.
|
||||
*
|
||||
*/
|
||||
explicit MleRouter(ThreadNetif &aThreadNetif);
|
||||
|
||||
/**
|
||||
* This method indicates whether or not the Router Role is enabled.
|
||||
*
|
||||
* @retval true If the Router Role is enabled.
|
||||
* @retval false If the Router Role is not enabled.
|
||||
*
|
||||
*/
|
||||
bool IsRouterRoleEnabled(void) const;
|
||||
|
||||
/**
|
||||
* This method sets whether or not the Router Role is enabled.
|
||||
*
|
||||
* If @p aEnable is false and the device is currently operating as a router, this call will cause the device to
|
||||
* detach and attempt to reattach as a child.
|
||||
*
|
||||
* @param[in] aEnabled TRUE to enable the Router Role, FALSE otherwise.
|
||||
*
|
||||
*/
|
||||
void SetRouterRoleEnabled(bool aEnabled);
|
||||
|
||||
/**
|
||||
* This method indicates whether a node is the only router on the network.
|
||||
*
|
||||
* @retval TRUE It is the only router in the network.
|
||||
* @retval FALSE It is a child or is not a single router in the network.
|
||||
*
|
||||
*/
|
||||
bool IsSingleton(void);
|
||||
|
||||
/**
|
||||
* This method generates an Address Solicit request for a Router ID.
|
||||
*
|
||||
* @param[in] aStatus The reason for requesting a Router ID.
|
||||
*
|
||||
* @retval kThreadError_None Successfully generated an Address Solicit message.
|
||||
* @retval kThreadError_NotCapable Device is not capable of becoming a router
|
||||
* @retval kThreadError_InvalidState Thread is not enabled
|
||||
*
|
||||
*/
|
||||
ThreadError BecomeRouter(ThreadStatusTlv::Status aStatus);
|
||||
|
||||
/**
|
||||
* This method causes the Thread interface to become a Leader and start a new partition.
|
||||
*
|
||||
* @retval kThreadError_None Successfully become a Leader and started a new partition.
|
||||
* @retval kThreadError_NotCapable Device is not capable of becoming a leader
|
||||
* @retval kThreadError_InvalidState Thread is not enabled
|
||||
*
|
||||
*/
|
||||
ThreadError BecomeLeader(void);
|
||||
|
||||
/**
|
||||
* This method returns the number of active routers.
|
||||
*
|
||||
* @returns The number of active routers.
|
||||
*
|
||||
*/
|
||||
uint8_t GetActiveRouterCount(void) const;
|
||||
|
||||
/**
|
||||
* This method returns the time in seconds since the last Router ID Sequence update.
|
||||
*
|
||||
* @returns The time in seconds since the last Router ID Sequence update.
|
||||
*
|
||||
*/
|
||||
uint32_t GetLeaderAge(void) const;
|
||||
|
||||
/**
|
||||
* This method returns the Leader Weighting value for this Thread interface.
|
||||
*
|
||||
* @returns The Leader Weighting value for this Thread interface.
|
||||
*
|
||||
*/
|
||||
uint8_t GetLeaderWeight(void) const;
|
||||
|
||||
/**
|
||||
* This method sets the Leader Weighting value for this Thread interface.
|
||||
*
|
||||
* @param[in] aWeight The Leader Weighting value.
|
||||
*
|
||||
*/
|
||||
void SetLeaderWeight(uint8_t aWeight);
|
||||
|
||||
/**
|
||||
* This method returns the fixed Partition Id of Thread network partition for certification testing.
|
||||
*
|
||||
* @returns The Partition Id for this Thread network partition.
|
||||
*
|
||||
*/
|
||||
uint32_t GetLeaderPartitionId(void) const;
|
||||
|
||||
/**
|
||||
* This method sets the fixed Partition Id for Thread network partition for certification testing.
|
||||
*
|
||||
* @param[in] aPartitionId The Leader Partition Id.
|
||||
*
|
||||
*/
|
||||
void SetLeaderPartitionId(uint32_t aPartitionId);
|
||||
|
||||
/**
|
||||
* This method sets the preferred Router Id. Upon becoming a router/leader the node
|
||||
* attempts to use this Router Id. If the preferred Router Id is not set or if it
|
||||
* can not be used, a randomly generated router Id is picked.
|
||||
* This property can be set when he device role is detached or disabled.
|
||||
*
|
||||
* @param[in] aRouterId The preferred Router Id.
|
||||
*
|
||||
* @retval kThreadError_None Successfully set the preferred Router Id.
|
||||
* @retval kThreadError_InvalidState Could not set (role is other than detached and disabled)
|
||||
*
|
||||
*/
|
||||
ThreadError SetPreferredRouterId(uint8_t aRouterId);
|
||||
|
||||
/**
|
||||
* This method returns the next hop towards an RLOC16 destination.
|
||||
*
|
||||
* @param[in] aDestination The RLOC16 of the destination.
|
||||
*
|
||||
* @returns A RLOC16 of the next hop if a route is known, kInvalidRloc16 otherwise.
|
||||
*
|
||||
*/
|
||||
uint16_t GetNextHop(uint16_t aDestination) const;
|
||||
|
||||
/**
|
||||
* This method returns the NETWORK_ID_TIMEOUT value.
|
||||
*
|
||||
* @returns The NETWORK_ID_TIMEOUT value.
|
||||
*
|
||||
*/
|
||||
uint8_t GetNetworkIdTimeout(void) const;
|
||||
|
||||
/**
|
||||
* This method sets the NETWORK_ID_TIMEOUT value.
|
||||
*
|
||||
* @param[in] aTimeout The NETWORK_ID_TIMEOUT value.
|
||||
*
|
||||
*/
|
||||
void SetNetworkIdTimeout(uint8_t aTimeout);
|
||||
|
||||
/**
|
||||
* This method returns the route cost to a RLOC16.
|
||||
*
|
||||
* @param[in] aRloc16 The RLOC16 of the destination.
|
||||
*
|
||||
* @returns The route cost to a RLOC16.
|
||||
*
|
||||
*/
|
||||
uint8_t GetRouteCost(uint16_t aRloc16) const;
|
||||
|
||||
/**
|
||||
* This method returns the current Router ID Sequence value.
|
||||
*
|
||||
* @returns The current Router ID Sequence value.
|
||||
*
|
||||
*/
|
||||
uint8_t GetRouterIdSequence(void) const;
|
||||
|
||||
/**
|
||||
* This method returns the ROUTER_UPGRADE_THRESHOLD value.
|
||||
*
|
||||
* @returns The ROUTER_UPGRADE_THRESHOLD value.
|
||||
*
|
||||
*/
|
||||
uint8_t GetRouterUpgradeThreshold(void) const;
|
||||
|
||||
/**
|
||||
* This method sets the ROUTER_UPGRADE_THRESHOLD value.
|
||||
*
|
||||
* @returns The ROUTER_UPGRADE_THRESHOLD value.
|
||||
*
|
||||
*/
|
||||
void SetRouterUpgradeThreshold(uint8_t aThreshold);
|
||||
|
||||
/**
|
||||
* This method returns the ROUTER_DOWNGRADE_THRESHOLD value.
|
||||
*
|
||||
* @returns The ROUTER_DOWNGRADE_THRESHOLD value.
|
||||
*
|
||||
*/
|
||||
uint8_t GetRouterDowngradeThreshold(void) const;
|
||||
|
||||
/**
|
||||
* This method sets the ROUTER_DOWNGRADE_THRESHOLD value.
|
||||
*
|
||||
* @returns The ROUTER_DOWNGRADE_THRESHOLD value.
|
||||
*
|
||||
*/
|
||||
void SetRouterDowngradeThreshold(uint8_t aThreshold);
|
||||
|
||||
/**
|
||||
* This method release a given Router ID.
|
||||
*
|
||||
* @param[in] aRouterId The Router ID to release.
|
||||
*
|
||||
* @retval kThreadError_None Successfully released the Router ID.
|
||||
* @retval kThreadError_InvalidState The Router ID was not allocated.
|
||||
*
|
||||
*/
|
||||
ThreadError ReleaseRouterId(uint8_t aRouterId);
|
||||
|
||||
/**
|
||||
* This method removes a link to a neighbor.
|
||||
*
|
||||
* @param[in] aAddress The link address of the neighbor.
|
||||
*
|
||||
* @retval kThreadError_None Successfully removed the neighbor.
|
||||
* @retval kThreadError_NotFound Could not find the neighbor.
|
||||
*
|
||||
*/
|
||||
ThreadError RemoveNeighbor(const Mac::Address &aAddress);
|
||||
|
||||
/**
|
||||
* This method removes a link to a neighbor.
|
||||
*
|
||||
* @param[in] aNeighbor A reference to the neighbor object.
|
||||
*
|
||||
* @retval kThreadError_None Successfully removed the neighbor.
|
||||
*
|
||||
*/
|
||||
ThreadError RemoveNeighbor(Neighbor &aNeighbor);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Child object.
|
||||
*
|
||||
* @param[in] aAddress The address of the Child.
|
||||
*
|
||||
* @returns A pointer to the Child object.
|
||||
*
|
||||
*/
|
||||
Child *GetChild(uint16_t aAddress);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Child object.
|
||||
*
|
||||
* @param[in] aAddress A reference to the address of the Child.
|
||||
*
|
||||
* @returns A pointer to the Child object.
|
||||
*
|
||||
*/
|
||||
Child *GetChild(const Mac::ExtAddress &aAddress);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Child object.
|
||||
*
|
||||
* @param[in] aAddress A reference to the address of the Child.
|
||||
*
|
||||
* @returns A pointer to the Child corresponding to @p aAddress, NULL otherwise.
|
||||
*
|
||||
*/
|
||||
Child *GetChild(const Mac::Address &aAddress);
|
||||
|
||||
/**
|
||||
* This method returns a child index for the Child object.
|
||||
*
|
||||
* @param[in] aChild A reference to the Child object.
|
||||
*
|
||||
* @returns The index for the Child corresponding to @p aChild.
|
||||
*
|
||||
*/
|
||||
uint8_t GetChildIndex(const Child &aChild);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Child array.
|
||||
*
|
||||
* @param[out] aNumChildren A pointer to output the number of children.
|
||||
*
|
||||
* @returns A pointer to the Child array.
|
||||
*
|
||||
*/
|
||||
Child *GetChildren(uint8_t *aNumChildren);
|
||||
|
||||
/**
|
||||
* This method sets the max children allowed value for this Thread interface.
|
||||
*
|
||||
* @param[in] aMaxChildren The max children allowed value.
|
||||
*
|
||||
* @retval kThreadErrorNone Successfully set the max.
|
||||
* @retval kThreadError_InvalidArgs If @p aMaxChildren is not in the range [1, kMaxChildren].
|
||||
* @retval kThreadError_InvalidState If MLE has already been started.
|
||||
*
|
||||
*/
|
||||
ThreadError SetMaxAllowedChildren(uint8_t aMaxChildren);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Neighbor object.
|
||||
*
|
||||
* @param[in] aAddress The address of the Neighbor.
|
||||
*
|
||||
* @returns A pointer to the Neighbor corresponding to @p aAddress, NULL otherwise.
|
||||
*
|
||||
*/
|
||||
Neighbor *GetNeighbor(uint16_t aAddress);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Neighbor object.
|
||||
*
|
||||
* @param[in] aAddress The address of the Neighbor.
|
||||
*
|
||||
* @returns A pointer to the Neighbor corresponding to @p aAddress, NULL otherwise.
|
||||
*
|
||||
*/
|
||||
Neighbor *GetNeighbor(const Mac::ExtAddress &aAddress);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Neighbor object.
|
||||
*
|
||||
* @param[in] aAddress The address of the Neighbor.
|
||||
*
|
||||
* @returns A pointer to the Neighbor corresponding to @p aAddress, NULL otherwise.
|
||||
*
|
||||
*/
|
||||
Neighbor *GetNeighbor(const Mac::Address &aAddress);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Neighbor object.
|
||||
*
|
||||
* @param[in] aAddress The address of the Neighbor.
|
||||
*
|
||||
* @returns A pointer to the Neighbor corresponding to @p aAddress, NULL otherwise.
|
||||
*
|
||||
*/
|
||||
Neighbor *GetNeighbor(const Ip6::Address &aAddress);
|
||||
|
||||
/**
|
||||
* This method retains diagnostic information for an attached child by Child ID or RLOC16.
|
||||
*
|
||||
* @param[in] aChildId The Child ID or RLOC16 for an attached child.
|
||||
* @param[out] aChildInfo The child information.
|
||||
*
|
||||
*/
|
||||
ThreadError GetChildInfoById(uint16_t aChildId, otChildInfo &aChildInfo);
|
||||
|
||||
/**
|
||||
* This method retains diagnostic information for an attached child by the internal table index.
|
||||
*
|
||||
* @param[in] aChildIndex The table index.
|
||||
* @param[out] aChildInfo The child information.
|
||||
*
|
||||
*/
|
||||
ThreadError GetChildInfoByIndex(uint8_t aChildIndex, otChildInfo &aChildInfo);
|
||||
|
||||
/**
|
||||
* This method gets the next neighbor information. It is used to iterate through the entries of
|
||||
* the neighbor table.
|
||||
*
|
||||
* @param[inout] aIterator A reference to the iterator context. To get the first neighbor entry
|
||||
it should be set to OT_NEIGHBOR_INFO_ITERATOR_INIT.
|
||||
* @param[out] aNeighInfo The neighbor information.
|
||||
*
|
||||
* @retval kThreadError_None Successfully found the next neighbor entry in table.
|
||||
* @retval kThreadError_NotFound No subsequent neighbor entry exists in the table.
|
||||
*
|
||||
*/
|
||||
ThreadError GetNextNeighborInfo(otNeighborInfoIterator &aIterator, otNeighborInfo &aNeighInfo);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Router array.
|
||||
*
|
||||
* @param[out] aNumRouters A pointer to output the number of routers.
|
||||
*
|
||||
* @returns A pointer to the Router array.
|
||||
*
|
||||
*/
|
||||
Router *GetRouters(uint8_t *aNumRouters);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Router entry.
|
||||
*
|
||||
* @param[in] aRouterId The Router ID.
|
||||
*
|
||||
* @returns A pointer to a Router entry or NULL if @p aRouterId is out-of-range.
|
||||
*
|
||||
*/
|
||||
Router *GetRouter(uint8_t aRouterId);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Router entry.
|
||||
*
|
||||
* @param[in] aRouterId The Router ID.
|
||||
*
|
||||
* @returns A pointer to a Router entry or NULL if @p aRouterId is out-of-range.
|
||||
*
|
||||
*/
|
||||
const Router *GetRouter(uint8_t aRouterId) const;
|
||||
|
||||
/**
|
||||
* This method retains diagnostic information for a given router.
|
||||
*
|
||||
* @param[in] aRouterId The router ID or RLOC16 for a given router.
|
||||
* @param[out] aRouterInfo The router information.
|
||||
*
|
||||
*/
|
||||
ThreadError GetRouterInfo(uint16_t aRouterId, otRouterInfo &aRouterInfo);
|
||||
|
||||
/**
|
||||
* This method indicates whether or not the given Thread partition attributes are preferred.
|
||||
*
|
||||
* @param[in] aSingletonA Whether or not the Thread Partition A has a single router.
|
||||
* @param[in] aLeaderDataA A reference to Thread Partition A's Leader Data.
|
||||
* @param[in] aSingletonB Whether or not the Thread Partition B has a single router.
|
||||
* @param[in] aLeaderDataB A reference to Thread Partition B's Leader Data.
|
||||
*
|
||||
* @retval 1 If partition A is preferred.
|
||||
* @retval 0 If partition A and B have equal preference.
|
||||
* @retval -1 If partition B is preferred.
|
||||
*
|
||||
*/
|
||||
static int ComparePartitions(bool aSingletonA, const LeaderDataTlv &aLeaderDataA,
|
||||
bool aSingletonB, const LeaderDataTlv &aleaderDataB);
|
||||
|
||||
/**
|
||||
* This method checks if the destination is reachable.
|
||||
*
|
||||
* @param[in] aMeshSource The RLOC16 of the source.
|
||||
* @param[in] aMeshDest The RLOC16 of the destination.
|
||||
* @param[in] aIp6Header A reference to the IPv6 header of the message.
|
||||
*
|
||||
* @retval kThreadError_None The destination is reachable.
|
||||
* @retval kThreadError_Drop The destination is not reachable and the message should be dropped.
|
||||
*
|
||||
*/
|
||||
ThreadError CheckReachability(uint16_t aMeshSource, uint16_t aMeshDest, Ip6::Header &aIp6Header);
|
||||
|
||||
/**
|
||||
* This method checks if a given Router ID has correct value.
|
||||
*
|
||||
* @param[in] aRouterId The Router ID value.
|
||||
*
|
||||
* @retval TRUE If @p aRouterId is in correct range [0..62].
|
||||
* @retval FALSE If @p aRouterId is not a valid Router ID.
|
||||
*
|
||||
*/
|
||||
static bool IsRouterIdValid(uint8_t aRouterId) { return aRouterId <= kMaxRouterId; }
|
||||
|
||||
/**
|
||||
* This method fills an ConnectivityTlv.
|
||||
*
|
||||
* @param[out] aTlv A reference to the tlv to be filled.
|
||||
*
|
||||
*/
|
||||
void FillConnectivityTlv(ConnectivityTlv &aTlv);
|
||||
|
||||
/**
|
||||
* This method fills an RouteTlv.
|
||||
*
|
||||
* @param[out] aTlv A reference to the tlv to be filled.
|
||||
*
|
||||
*/
|
||||
void FillRouteTlv(RouteTlv &aTlv);
|
||||
|
||||
/**
|
||||
* This method returns a reference to the send queue.
|
||||
*
|
||||
* @returns A reference to the send queue.
|
||||
*
|
||||
*/
|
||||
const MessageQueue &GetMessageQueue(void) const { return mDelayedResponses; }
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
kStateUpdatePeriod = 1000u, ///< State update period in milliseconds.
|
||||
};
|
||||
|
||||
ThreadError AppendConnectivity(Message &aMessage);
|
||||
ThreadError AppendChildAddresses(Message &aMessage, Child &aChild);
|
||||
ThreadError AppendRoute(Message &aMessage);
|
||||
ThreadError AppendActiveDataset(Message &aMessage);
|
||||
ThreadError AppendPendingDataset(Message &aMessage);
|
||||
uint8_t GetLinkCost(uint8_t aRouterId);
|
||||
void GetChildInfo(Child &aChild, otChildInfo &aChildInfo);
|
||||
ThreadError HandleDetachStart(void);
|
||||
ThreadError HandleChildStart(otMleAttachFilter aFilter);
|
||||
ThreadError HandleLinkRequest(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
ThreadError HandleLinkAccept(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, uint32_t aKeySequence);
|
||||
ThreadError HandleLinkAccept(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, uint32_t aKeySequence,
|
||||
bool request);
|
||||
ThreadError HandleLinkAcceptAndRequest(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo,
|
||||
uint32_t aKeySequence);
|
||||
ThreadError HandleAdvertisement(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
ThreadError HandleParentRequest(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
ThreadError HandleChildIdRequest(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo,
|
||||
uint32_t aKeySequence);
|
||||
ThreadError HandleChildUpdateRequest(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
ThreadError HandleDataRequest(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
ThreadError HandleNetworkDataUpdateRouter(void);
|
||||
|
||||
ThreadError ProcessRouteTlv(const RouteTlv &aRoute);
|
||||
void ResetAdvertiseInterval(void);
|
||||
ThreadError SendAddressSolicit(ThreadStatusTlv::Status aStatus);
|
||||
ThreadError SendAddressRelease(void);
|
||||
void SendAddressSolicitResponse(const Coap::Header &aRequest, uint8_t aRouterId,
|
||||
const Ip6::MessageInfo &aMessageInfo);
|
||||
void SendAddressReleaseResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo);
|
||||
ThreadError SendAdvertisement(void);
|
||||
ThreadError SendLinkRequest(Neighbor *aNeighbor);
|
||||
ThreadError SendLinkAccept(const Ip6::MessageInfo &aMessageInfo, Neighbor *aNeighbor,
|
||||
const TlvRequestTlv &aTlvRequest, const ChallengeTlv &aChallenge);
|
||||
ThreadError SendParentResponse(Child *aChild, const ChallengeTlv &aChallenge, bool aRoutersOnlyRequest);
|
||||
ThreadError SendChildIdResponse(Child *aChild);
|
||||
ThreadError SendChildUpdateResponse(Child *aChild, const Ip6::MessageInfo &aMessageInfo,
|
||||
const uint8_t *aTlvs, uint8_t aTlvsLength, const ChallengeTlv *challenge);
|
||||
ThreadError SendDataResponse(const Ip6::Address &aDestination, const uint8_t *aTlvs, uint8_t aTlvsLength);
|
||||
|
||||
ThreadError SetStateRouter(uint16_t aRloc16);
|
||||
ThreadError SetStateLeader(uint16_t aRloc16);
|
||||
void StopLeader(void);
|
||||
ThreadError UpdateChildAddresses(const AddressRegistrationTlv &aTlv, Child &aChild);
|
||||
void UpdateRoutes(const RouteTlv &aTlv, uint8_t aRouterId);
|
||||
|
||||
static void HandleAddressSolicitResponse(void *aContext, otCoapHeader *aHeader, otMessage aMessage,
|
||||
ThreadError result);
|
||||
void HandleAddressSolicitResponse(Coap::Header *aHeader, Message *aMessage, ThreadError result);
|
||||
static void HandleAddressRelease(void *aContext, otCoapHeader *aHeader, otMessage aMessage,
|
||||
const otMessageInfo *aMessageInfo);
|
||||
void HandleAddressRelease(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
static void HandleAddressSolicit(void *aContext, otCoapHeader *aHeader, otMessage aMessage,
|
||||
const otMessageInfo *aMessageInfo);
|
||||
void HandleAddressSolicit(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
static uint8_t LqiToCost(uint8_t aLqi);
|
||||
|
||||
Child *NewChild(void);
|
||||
Child *FindChild(uint16_t aChildId);
|
||||
Child *FindChild(const Mac::ExtAddress &aMacAddr);
|
||||
|
||||
bool HasMinDowngradeNeighborRouters(void);
|
||||
bool HasOneNeighborwithComparableConnectivity(const RouteTlv &aRoute, uint8_t aRouterId);
|
||||
bool HasSmallNumberOfChildren(void);
|
||||
uint8_t GetMinDowngradeNeighborRouters(void);
|
||||
|
||||
uint8_t AllocateRouterId(void);
|
||||
uint8_t AllocateRouterId(uint8_t aRouterId);
|
||||
bool InRouterIdMask(uint8_t aRouterId);
|
||||
|
||||
static bool HandleAdvertiseTimer(void *aContext);
|
||||
bool HandleAdvertiseTimer(void);
|
||||
static void HandleStateUpdateTimer(void *aContext);
|
||||
void HandleStateUpdateTimer(void);
|
||||
static void HandleDelayedResponseTimer(void *aContext);
|
||||
void HandleDelayedResponseTimer(void);
|
||||
|
||||
ThreadError AddDelayedResponse(Message &aMessage, const Ip6::Address &aDestination, uint16_t aDelay);
|
||||
|
||||
MessageQueue mDelayedResponses;
|
||||
|
||||
TrickleTimer mAdvertiseTimer;
|
||||
Timer mStateUpdateTimer;
|
||||
Timer mDelayedResponseTimer;
|
||||
|
||||
Coap::Resource mAddressSolicit;
|
||||
Coap::Resource mAddressRelease;
|
||||
|
||||
uint8_t mRouterIdSequence;
|
||||
uint32_t mRouterIdSequenceLastUpdated;
|
||||
Router mRouters[kMaxRouterId + 1];
|
||||
uint8_t mMaxChildrenAllowed;
|
||||
Child mChildren[kMaxChildren];
|
||||
|
||||
uint8_t mChallengeTimeout;
|
||||
uint8_t mChallenge[8];
|
||||
uint16_t mNextChildId;
|
||||
uint8_t mNetworkIdTimeout;
|
||||
uint8_t mRouterUpgradeThreshold;
|
||||
uint8_t mRouterDowngradeThreshold;
|
||||
uint8_t mLeaderWeight;
|
||||
uint32_t mFixedLeaderPartitionId; ///< only for certification testing
|
||||
bool mRouterRoleEnabled;
|
||||
|
||||
uint8_t mRouterId;
|
||||
uint8_t mPreviousRouterId;
|
||||
|
||||
Coap::Server &mCoapServer;
|
||||
Coap::Client &mCoapClient;
|
||||
};
|
||||
|
||||
} // namespace Mle
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
} // namespace Thread
|
||||
|
||||
#endif // MLE_ROUTER_HPP_
|
||||
#ifdef OPENTHREAD_MTD
|
||||
#include "mle_router_mtd.hpp"
|
||||
#else
|
||||
#include "mle_router_ftd.hpp"
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,772 @@
|
||||
/*
|
||||
* Copyright (c) 2016, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes definitions for MLE functionality required by the Thread Router and Leader roles.
|
||||
*/
|
||||
|
||||
#ifndef MLE_ROUTER_HPP_
|
||||
#define MLE_ROUTER_HPP_
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <coap/coap_header.hpp>
|
||||
#include <coap/coap_server.hpp>
|
||||
#include <coap/coap_client.hpp>
|
||||
#include <common/timer.hpp>
|
||||
#include <common/trickle_timer.hpp>
|
||||
#include <mac/mac_frame.hpp>
|
||||
#include <net/icmp6.hpp>
|
||||
#include <net/udp6.hpp>
|
||||
#include <thread/mle.hpp>
|
||||
#include <thread/mle_tlvs.hpp>
|
||||
#include <thread/thread_tlvs.hpp>
|
||||
#include <thread/topology.hpp>
|
||||
|
||||
namespace Thread {
|
||||
namespace Mle {
|
||||
|
||||
class MeshForwarder;
|
||||
class NetworkDataLeader;
|
||||
|
||||
/**
|
||||
* @addtogroup core-mle-router
|
||||
*
|
||||
* @brief
|
||||
* This module includes definitions for MLE functionality required by the Thread Router and Leader roles.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class implements functionality required for delaying MLE responses.
|
||||
*
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class DelayedResponseHeader
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Default constructor for the object.
|
||||
*
|
||||
*/
|
||||
DelayedResponseHeader(void) { memset(this, 0, sizeof(*this)); };
|
||||
|
||||
/**
|
||||
* This constructor initializes the object with specific values.
|
||||
*
|
||||
* @param[in] aSendTime Time when the message shall be sent.
|
||||
* @param[in] aDestination IPv6 address of the message destination.
|
||||
*
|
||||
*/
|
||||
DelayedResponseHeader(uint32_t aSendTime, const Ip6::Address &aDestination) {
|
||||
mSendTime = aSendTime;
|
||||
mDestination = aDestination;
|
||||
};
|
||||
|
||||
/**
|
||||
* This method appends delayed response header to the message.
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
*
|
||||
* @retval kThreadError_None Successfully appended the bytes.
|
||||
* @retval kThreadError_NoBufs Insufficient available buffers to grow the message.
|
||||
*
|
||||
*/
|
||||
ThreadError AppendTo(Message &aMessage) {
|
||||
return aMessage.Append(this, sizeof(*this));
|
||||
};
|
||||
|
||||
/**
|
||||
* This method reads delayed response header from the message.
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
*
|
||||
* @returns The number of bytes read.
|
||||
*
|
||||
*/
|
||||
uint16_t ReadFrom(Message &aMessage) {
|
||||
return aMessage.Read(aMessage.GetLength() - sizeof(*this), sizeof(*this), this);
|
||||
};
|
||||
|
||||
/**
|
||||
* This method removes delayed response header from the message.
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
*
|
||||
* @retval kThreadError_None Successfully removed the header.
|
||||
*
|
||||
*/
|
||||
static ThreadError RemoveFrom(Message &aMessage) {
|
||||
return aMessage.SetLength(aMessage.GetLength() - sizeof(DelayedResponseHeader));
|
||||
};
|
||||
|
||||
/**
|
||||
* This method returns a time when the message shall be sent.
|
||||
*
|
||||
* @returns A time when the message shall be sent.
|
||||
*
|
||||
*/
|
||||
uint32_t GetSendTime(void) const { return mSendTime; };
|
||||
|
||||
/**
|
||||
* This method returns a destination of the delayed message.
|
||||
*
|
||||
* @returns A destination of the delayed message.
|
||||
*
|
||||
*/
|
||||
const Ip6::Address &GetDestination(void) const { return mDestination; };
|
||||
|
||||
/**
|
||||
* This method checks if the message shall be sent before the given time.
|
||||
*
|
||||
* @param[in] aTime A time to compare.
|
||||
*
|
||||
* @retval TRUE If the message shall be sent before the given time.
|
||||
* @retval FALSE Otherwise.
|
||||
*/
|
||||
bool IsEarlier(uint32_t aTime) { return (static_cast<int32_t>(aTime - mSendTime) > 0); };
|
||||
|
||||
/**
|
||||
* This method checks if the message shall be sent after the given time.
|
||||
*
|
||||
* @param[in] aTime A time to compare.
|
||||
*
|
||||
* @retval TRUE If the message shall be sent after the given time.
|
||||
* @retval FALSE Otherwise.
|
||||
*/
|
||||
bool IsLater(uint32_t aTime) { return (static_cast<int32_t>(aTime - mSendTime) < 0); };
|
||||
|
||||
private:
|
||||
Ip6::Address mDestination; ///< IPv6 address of the message destination.
|
||||
uint32_t mSendTime; ///< Time when the message shall be sent.
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
/**
|
||||
* This class implements MLE functionality required by the Thread Router and Leader roles.
|
||||
*
|
||||
*/
|
||||
class MleRouter: public Mle
|
||||
{
|
||||
friend class Mle;
|
||||
|
||||
public:
|
||||
/**
|
||||
* This constructor initializes the object.
|
||||
*
|
||||
* @param[in] aThreadNetif A reference to the Thread network interface.
|
||||
*
|
||||
*/
|
||||
explicit MleRouter(ThreadNetif &aThreadNetif);
|
||||
|
||||
/**
|
||||
* This method indicates whether or not the Router Role is enabled.
|
||||
*
|
||||
* @retval true If the Router Role is enabled.
|
||||
* @retval false If the Router Role is not enabled.
|
||||
*
|
||||
*/
|
||||
bool IsRouterRoleEnabled(void) const;
|
||||
|
||||
/**
|
||||
* This method sets whether or not the Router Role is enabled.
|
||||
*
|
||||
* If @p aEnable is false and the device is currently operating as a router, this call will cause the device to
|
||||
* detach and attempt to reattach as a child.
|
||||
*
|
||||
* @param[in] aEnabled TRUE to enable the Router Role, FALSE otherwise.
|
||||
*
|
||||
*/
|
||||
void SetRouterRoleEnabled(bool aEnabled);
|
||||
|
||||
/**
|
||||
* This method indicates whether a node is the only router on the network.
|
||||
*
|
||||
* @retval TRUE It is the only router in the network.
|
||||
* @retval FALSE It is a child or is not a single router in the network.
|
||||
*
|
||||
*/
|
||||
bool IsSingleton(void);
|
||||
|
||||
/**
|
||||
* This method generates an Address Solicit request for a Router ID.
|
||||
*
|
||||
* @param[in] aStatus The reason for requesting a Router ID.
|
||||
*
|
||||
* @retval kThreadError_None Successfully generated an Address Solicit message.
|
||||
* @retval kThreadError_NotCapable Device is not capable of becoming a router
|
||||
* @retval kThreadError_InvalidState Thread is not enabled
|
||||
*
|
||||
*/
|
||||
ThreadError BecomeRouter(ThreadStatusTlv::Status aStatus);
|
||||
|
||||
/**
|
||||
* This method causes the Thread interface to become a Leader and start a new partition.
|
||||
*
|
||||
* @retval kThreadError_None Successfully become a Leader and started a new partition.
|
||||
* @retval kThreadError_NotCapable Device is not capable of becoming a leader
|
||||
* @retval kThreadError_InvalidState Thread is not enabled
|
||||
*
|
||||
*/
|
||||
ThreadError BecomeLeader(void);
|
||||
|
||||
/**
|
||||
* This method returns the number of active routers.
|
||||
*
|
||||
* @returns The number of active routers.
|
||||
*
|
||||
*/
|
||||
uint8_t GetActiveRouterCount(void) const;
|
||||
|
||||
/**
|
||||
* This method returns the time in seconds since the last Router ID Sequence update.
|
||||
*
|
||||
* @returns The time in seconds since the last Router ID Sequence update.
|
||||
*
|
||||
*/
|
||||
uint32_t GetLeaderAge(void) const;
|
||||
|
||||
/**
|
||||
* This method returns the Leader Weighting value for this Thread interface.
|
||||
*
|
||||
* @returns The Leader Weighting value for this Thread interface.
|
||||
*
|
||||
*/
|
||||
uint8_t GetLeaderWeight(void) const;
|
||||
|
||||
/**
|
||||
* This method sets the Leader Weighting value for this Thread interface.
|
||||
*
|
||||
* @param[in] aWeight The Leader Weighting value.
|
||||
*
|
||||
*/
|
||||
void SetLeaderWeight(uint8_t aWeight);
|
||||
|
||||
/**
|
||||
* This method returns the fixed Partition Id of Thread network partition for certification testing.
|
||||
*
|
||||
* @returns The Partition Id for this Thread network partition.
|
||||
*
|
||||
*/
|
||||
uint32_t GetLeaderPartitionId(void) const;
|
||||
|
||||
/**
|
||||
* This method sets the fixed Partition Id for Thread network partition for certification testing.
|
||||
*
|
||||
* @param[in] aPartitionId The Leader Partition Id.
|
||||
*
|
||||
*/
|
||||
void SetLeaderPartitionId(uint32_t aPartitionId);
|
||||
|
||||
/**
|
||||
* This method sets the preferred Router Id. Upon becoming a router/leader the node
|
||||
* attempts to use this Router Id. If the preferred Router Id is not set or if it
|
||||
* can not be used, a randomly generated router Id is picked.
|
||||
* This property can be set when he device role is detached or disabled.
|
||||
*
|
||||
* @param[in] aRouterId The preferred Router Id.
|
||||
*
|
||||
* @retval kThreadError_None Successfully set the preferred Router Id.
|
||||
* @retval kThreadError_InvalidState Could not set (role is other than detached and disabled)
|
||||
*
|
||||
*/
|
||||
ThreadError SetPreferredRouterId(uint8_t aRouterId);
|
||||
|
||||
/**
|
||||
* This method returns the next hop towards an RLOC16 destination.
|
||||
*
|
||||
* @param[in] aDestination The RLOC16 of the destination.
|
||||
*
|
||||
* @returns A RLOC16 of the next hop if a route is known, kInvalidRloc16 otherwise.
|
||||
*
|
||||
*/
|
||||
uint16_t GetNextHop(uint16_t aDestination) const;
|
||||
|
||||
/**
|
||||
* This method returns the NETWORK_ID_TIMEOUT value.
|
||||
*
|
||||
* @returns The NETWORK_ID_TIMEOUT value.
|
||||
*
|
||||
*/
|
||||
uint8_t GetNetworkIdTimeout(void) const;
|
||||
|
||||
/**
|
||||
* This method sets the NETWORK_ID_TIMEOUT value.
|
||||
*
|
||||
* @param[in] aTimeout The NETWORK_ID_TIMEOUT value.
|
||||
*
|
||||
*/
|
||||
void SetNetworkIdTimeout(uint8_t aTimeout);
|
||||
|
||||
/**
|
||||
* This method returns the route cost to a RLOC16.
|
||||
*
|
||||
* @param[in] aRloc16 The RLOC16 of the destination.
|
||||
*
|
||||
* @returns The route cost to a RLOC16.
|
||||
*
|
||||
*/
|
||||
uint8_t GetRouteCost(uint16_t aRloc16) const;
|
||||
|
||||
/**
|
||||
* This method returns the current Router ID Sequence value.
|
||||
*
|
||||
* @returns The current Router ID Sequence value.
|
||||
*
|
||||
*/
|
||||
uint8_t GetRouterIdSequence(void) const;
|
||||
|
||||
/**
|
||||
* This method returns the ROUTER_UPGRADE_THRESHOLD value.
|
||||
*
|
||||
* @returns The ROUTER_UPGRADE_THRESHOLD value.
|
||||
*
|
||||
*/
|
||||
uint8_t GetRouterUpgradeThreshold(void) const;
|
||||
|
||||
/**
|
||||
* This method sets the ROUTER_UPGRADE_THRESHOLD value.
|
||||
*
|
||||
* @returns The ROUTER_UPGRADE_THRESHOLD value.
|
||||
*
|
||||
*/
|
||||
void SetRouterUpgradeThreshold(uint8_t aThreshold);
|
||||
|
||||
/**
|
||||
* This method returns the ROUTER_DOWNGRADE_THRESHOLD value.
|
||||
*
|
||||
* @returns The ROUTER_DOWNGRADE_THRESHOLD value.
|
||||
*
|
||||
*/
|
||||
uint8_t GetRouterDowngradeThreshold(void) const;
|
||||
|
||||
/**
|
||||
* This method sets the ROUTER_DOWNGRADE_THRESHOLD value.
|
||||
*
|
||||
* @returns The ROUTER_DOWNGRADE_THRESHOLD value.
|
||||
*
|
||||
*/
|
||||
void SetRouterDowngradeThreshold(uint8_t aThreshold);
|
||||
|
||||
/**
|
||||
* This method release a given Router ID.
|
||||
*
|
||||
* @param[in] aRouterId The Router ID to release.
|
||||
*
|
||||
* @retval kThreadError_None Successfully released the Router ID.
|
||||
* @retval kThreadError_InvalidState The Router ID was not allocated.
|
||||
*
|
||||
*/
|
||||
ThreadError ReleaseRouterId(uint8_t aRouterId);
|
||||
|
||||
/**
|
||||
* This method removes a link to a neighbor.
|
||||
*
|
||||
* @param[in] aAddress The link address of the neighbor.
|
||||
*
|
||||
* @retval kThreadError_None Successfully removed the neighbor.
|
||||
* @retval kThreadError_NotFound Could not find the neighbor.
|
||||
*
|
||||
*/
|
||||
ThreadError RemoveNeighbor(const Mac::Address &aAddress);
|
||||
|
||||
/**
|
||||
* This method removes a link to a neighbor.
|
||||
*
|
||||
* @param[in] aNeighbor A reference to the neighbor object.
|
||||
*
|
||||
* @retval kThreadError_None Successfully removed the neighbor.
|
||||
*
|
||||
*/
|
||||
ThreadError RemoveNeighbor(Neighbor &aNeighbor);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Child object.
|
||||
*
|
||||
* @param[in] aAddress The address of the Child.
|
||||
*
|
||||
* @returns A pointer to the Child object.
|
||||
*
|
||||
*/
|
||||
Child *GetChild(uint16_t aAddress);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Child object.
|
||||
*
|
||||
* @param[in] aAddress A reference to the address of the Child.
|
||||
*
|
||||
* @returns A pointer to the Child object.
|
||||
*
|
||||
*/
|
||||
Child *GetChild(const Mac::ExtAddress &aAddress);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Child object.
|
||||
*
|
||||
* @param[in] aAddress A reference to the address of the Child.
|
||||
*
|
||||
* @returns A pointer to the Child corresponding to @p aAddress, NULL otherwise.
|
||||
*
|
||||
*/
|
||||
Child *GetChild(const Mac::Address &aAddress);
|
||||
|
||||
/**
|
||||
* This method returns a child index for the Child object.
|
||||
*
|
||||
* @param[in] aChild A reference to the Child object.
|
||||
*
|
||||
* @returns The index for the Child corresponding to @p aChild.
|
||||
*
|
||||
*/
|
||||
uint8_t GetChildIndex(const Child &aChild);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Child array.
|
||||
*
|
||||
* @param[out] aNumChildren A pointer to output the number of children.
|
||||
*
|
||||
* @returns A pointer to the Child array.
|
||||
*
|
||||
*/
|
||||
Child *GetChildren(uint8_t *aNumChildren);
|
||||
|
||||
/**
|
||||
* This method sets the max children allowed value for this Thread interface.
|
||||
*
|
||||
* @param[in] aMaxChildren The max children allowed value.
|
||||
*
|
||||
* @retval kThreadErrorNone Successfully set the max.
|
||||
* @retval kThreadError_InvalidArgs If @p aMaxChildren is not in the range [1, kMaxChildren].
|
||||
* @retval kThreadError_InvalidState If MLE has already been started.
|
||||
*
|
||||
*/
|
||||
ThreadError SetMaxAllowedChildren(uint8_t aMaxChildren);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Neighbor object.
|
||||
*
|
||||
* @param[in] aAddress The address of the Neighbor.
|
||||
*
|
||||
* @returns A pointer to the Neighbor corresponding to @p aAddress, NULL otherwise.
|
||||
*
|
||||
*/
|
||||
Neighbor *GetNeighbor(uint16_t aAddress);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Neighbor object.
|
||||
*
|
||||
* @param[in] aAddress The address of the Neighbor.
|
||||
*
|
||||
* @returns A pointer to the Neighbor corresponding to @p aAddress, NULL otherwise.
|
||||
*
|
||||
*/
|
||||
Neighbor *GetNeighbor(const Mac::ExtAddress &aAddress);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Neighbor object.
|
||||
*
|
||||
* @param[in] aAddress The address of the Neighbor.
|
||||
*
|
||||
* @returns A pointer to the Neighbor corresponding to @p aAddress, NULL otherwise.
|
||||
*
|
||||
*/
|
||||
Neighbor *GetNeighbor(const Mac::Address &aAddress);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Neighbor object.
|
||||
*
|
||||
* @param[in] aAddress The address of the Neighbor.
|
||||
*
|
||||
* @returns A pointer to the Neighbor corresponding to @p aAddress, NULL otherwise.
|
||||
*
|
||||
*/
|
||||
Neighbor *GetNeighbor(const Ip6::Address &aAddress);
|
||||
|
||||
/**
|
||||
* This method retains diagnostic information for an attached child by Child ID or RLOC16.
|
||||
*
|
||||
* @param[in] aChildId The Child ID or RLOC16 for an attached child.
|
||||
* @param[out] aChildInfo The child information.
|
||||
*
|
||||
*/
|
||||
ThreadError GetChildInfoById(uint16_t aChildId, otChildInfo &aChildInfo);
|
||||
|
||||
/**
|
||||
* This method retains diagnostic information for an attached child by the internal table index.
|
||||
*
|
||||
* @param[in] aChildIndex The table index.
|
||||
* @param[out] aChildInfo The child information.
|
||||
*
|
||||
*/
|
||||
ThreadError GetChildInfoByIndex(uint8_t aChildIndex, otChildInfo &aChildInfo);
|
||||
|
||||
/**
|
||||
* This method gets the next neighbor information. It is used to iterate through the entries of
|
||||
* the neighbor table.
|
||||
*
|
||||
* @param[inout] aIterator A reference to the iterator context. To get the first neighbor entry
|
||||
it should be set to OT_NEIGHBOR_INFO_ITERATOR_INIT.
|
||||
* @param[out] aNeighInfo The neighbor information.
|
||||
*
|
||||
* @retval kThreadError_None Successfully found the next neighbor entry in table.
|
||||
* @retval kThreadError_NotFound No subsequent neighbor entry exists in the table.
|
||||
*
|
||||
*/
|
||||
ThreadError GetNextNeighborInfo(otNeighborInfoIterator &aIterator, otNeighborInfo &aNeighInfo);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Router array.
|
||||
*
|
||||
* @param[out] aNumRouters A pointer to output the number of routers.
|
||||
*
|
||||
* @returns A pointer to the Router array.
|
||||
*
|
||||
*/
|
||||
Router *GetRouters(uint8_t *aNumRouters);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Router entry.
|
||||
*
|
||||
* @param[in] aRouterId The Router ID.
|
||||
*
|
||||
* @returns A pointer to a Router entry or NULL if @p aRouterId is out-of-range.
|
||||
*
|
||||
*/
|
||||
Router *GetRouter(uint8_t aRouterId);
|
||||
|
||||
/**
|
||||
* This method returns a pointer to a Router entry.
|
||||
*
|
||||
* @param[in] aRouterId The Router ID.
|
||||
*
|
||||
* @returns A pointer to a Router entry or NULL if @p aRouterId is out-of-range.
|
||||
*
|
||||
*/
|
||||
const Router *GetRouter(uint8_t aRouterId) const;
|
||||
|
||||
/**
|
||||
* This method retains diagnostic information for a given router.
|
||||
*
|
||||
* @param[in] aRouterId The router ID or RLOC16 for a given router.
|
||||
* @param[out] aRouterInfo The router information.
|
||||
*
|
||||
*/
|
||||
ThreadError GetRouterInfo(uint16_t aRouterId, otRouterInfo &aRouterInfo);
|
||||
|
||||
/**
|
||||
* This method indicates whether or not the given Thread partition attributes are preferred.
|
||||
*
|
||||
* @param[in] aSingletonA Whether or not the Thread Partition A has a single router.
|
||||
* @param[in] aLeaderDataA A reference to Thread Partition A's Leader Data.
|
||||
* @param[in] aSingletonB Whether or not the Thread Partition B has a single router.
|
||||
* @param[in] aLeaderDataB A reference to Thread Partition B's Leader Data.
|
||||
*
|
||||
* @retval 1 If partition A is preferred.
|
||||
* @retval 0 If partition A and B have equal preference.
|
||||
* @retval -1 If partition B is preferred.
|
||||
*
|
||||
*/
|
||||
static int ComparePartitions(bool aSingletonA, const LeaderDataTlv &aLeaderDataA,
|
||||
bool aSingletonB, const LeaderDataTlv &aleaderDataB);
|
||||
|
||||
/**
|
||||
* This method checks if the destination is reachable.
|
||||
*
|
||||
* @param[in] aMeshSource The RLOC16 of the source.
|
||||
* @param[in] aMeshDest The RLOC16 of the destination.
|
||||
* @param[in] aIp6Header A reference to the IPv6 header of the message.
|
||||
*
|
||||
* @retval kThreadError_None The destination is reachable.
|
||||
* @retval kThreadError_Drop The destination is not reachable and the message should be dropped.
|
||||
*
|
||||
*/
|
||||
ThreadError CheckReachability(uint16_t aMeshSource, uint16_t aMeshDest, Ip6::Header &aIp6Header);
|
||||
|
||||
/**
|
||||
* This method checks if a given Router ID has correct value.
|
||||
*
|
||||
* @param[in] aRouterId The Router ID value.
|
||||
*
|
||||
* @retval TRUE If @p aRouterId is in correct range [0..62].
|
||||
* @retval FALSE If @p aRouterId is not a valid Router ID.
|
||||
*
|
||||
*/
|
||||
static bool IsRouterIdValid(uint8_t aRouterId) { return aRouterId <= kMaxRouterId; }
|
||||
|
||||
/**
|
||||
* This method fills an ConnectivityTlv.
|
||||
*
|
||||
* @param[out] aTlv A reference to the tlv to be filled.
|
||||
*
|
||||
*/
|
||||
void FillConnectivityTlv(ConnectivityTlv &aTlv);
|
||||
|
||||
/**
|
||||
* This method fills an RouteTlv.
|
||||
*
|
||||
* @param[out] aTlv A reference to the tlv to be filled.
|
||||
*
|
||||
*/
|
||||
void FillRouteTlv(RouteTlv &aTlv);
|
||||
|
||||
/**
|
||||
* This method returns a reference to the send queue.
|
||||
*
|
||||
* @returns A reference to the send queue.
|
||||
*
|
||||
*/
|
||||
const MessageQueue &GetMessageQueue(void) const { return mDelayedResponses; }
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
kStateUpdatePeriod = 1000u, ///< State update period in milliseconds.
|
||||
};
|
||||
|
||||
ThreadError AppendConnectivity(Message &aMessage);
|
||||
ThreadError AppendChildAddresses(Message &aMessage, Child &aChild);
|
||||
ThreadError AppendRoute(Message &aMessage);
|
||||
ThreadError AppendActiveDataset(Message &aMessage);
|
||||
ThreadError AppendPendingDataset(Message &aMessage);
|
||||
uint8_t GetLinkCost(uint8_t aRouterId);
|
||||
void GetChildInfo(Child &aChild, otChildInfo &aChildInfo);
|
||||
ThreadError HandleDetachStart(void);
|
||||
ThreadError HandleChildStart(otMleAttachFilter aFilter);
|
||||
ThreadError HandleLinkRequest(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
ThreadError HandleLinkAccept(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, uint32_t aKeySequence);
|
||||
ThreadError HandleLinkAccept(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, uint32_t aKeySequence,
|
||||
bool request);
|
||||
ThreadError HandleLinkAcceptAndRequest(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo,
|
||||
uint32_t aKeySequence);
|
||||
ThreadError HandleAdvertisement(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
ThreadError HandleParentRequest(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
ThreadError HandleChildIdRequest(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo,
|
||||
uint32_t aKeySequence);
|
||||
ThreadError HandleChildUpdateRequest(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
ThreadError HandleDataRequest(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
ThreadError HandleNetworkDataUpdateRouter(void);
|
||||
|
||||
ThreadError ProcessRouteTlv(const RouteTlv &aRoute);
|
||||
void ResetAdvertiseInterval(void);
|
||||
ThreadError SendAddressSolicit(ThreadStatusTlv::Status aStatus);
|
||||
ThreadError SendAddressRelease(void);
|
||||
void SendAddressSolicitResponse(const Coap::Header &aRequest, uint8_t aRouterId,
|
||||
const Ip6::MessageInfo &aMessageInfo);
|
||||
void SendAddressReleaseResponse(const Coap::Header &aRequestHeader, const Ip6::MessageInfo &aMessageInfo);
|
||||
ThreadError SendAdvertisement(void);
|
||||
ThreadError SendLinkRequest(Neighbor *aNeighbor);
|
||||
ThreadError SendLinkAccept(const Ip6::MessageInfo &aMessageInfo, Neighbor *aNeighbor,
|
||||
const TlvRequestTlv &aTlvRequest, const ChallengeTlv &aChallenge);
|
||||
ThreadError SendParentResponse(Child *aChild, const ChallengeTlv &aChallenge, bool aRoutersOnlyRequest);
|
||||
ThreadError SendChildIdResponse(Child *aChild);
|
||||
ThreadError SendChildUpdateResponse(Child *aChild, const Ip6::MessageInfo &aMessageInfo,
|
||||
const uint8_t *aTlvs, uint8_t aTlvsLength, const ChallengeTlv *challenge);
|
||||
ThreadError SendDataResponse(const Ip6::Address &aDestination, const uint8_t *aTlvs, uint8_t aTlvsLength);
|
||||
|
||||
ThreadError SetStateRouter(uint16_t aRloc16);
|
||||
ThreadError SetStateLeader(uint16_t aRloc16);
|
||||
void StopLeader(void);
|
||||
ThreadError UpdateChildAddresses(const AddressRegistrationTlv &aTlv, Child &aChild);
|
||||
void UpdateRoutes(const RouteTlv &aTlv, uint8_t aRouterId);
|
||||
|
||||
static void HandleAddressSolicitResponse(void *aContext, otCoapHeader *aHeader, otMessage aMessage,
|
||||
ThreadError result);
|
||||
void HandleAddressSolicitResponse(Coap::Header *aHeader, Message *aMessage, ThreadError result);
|
||||
static void HandleAddressRelease(void *aContext, otCoapHeader *aHeader, otMessage aMessage,
|
||||
const otMessageInfo *aMessageInfo);
|
||||
void HandleAddressRelease(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
static void HandleAddressSolicit(void *aContext, otCoapHeader *aHeader, otMessage aMessage,
|
||||
const otMessageInfo *aMessageInfo);
|
||||
void HandleAddressSolicit(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
|
||||
static uint8_t LqiToCost(uint8_t aLqi);
|
||||
|
||||
Child *NewChild(void);
|
||||
Child *FindChild(uint16_t aChildId);
|
||||
Child *FindChild(const Mac::ExtAddress &aMacAddr);
|
||||
|
||||
bool HasMinDowngradeNeighborRouters(void);
|
||||
bool HasOneNeighborwithComparableConnectivity(const RouteTlv &aRoute, uint8_t aRouterId);
|
||||
bool HasSmallNumberOfChildren(void);
|
||||
uint8_t GetMinDowngradeNeighborRouters(void);
|
||||
|
||||
uint8_t AllocateRouterId(void);
|
||||
uint8_t AllocateRouterId(uint8_t aRouterId);
|
||||
bool InRouterIdMask(uint8_t aRouterId);
|
||||
|
||||
static bool HandleAdvertiseTimer(void *aContext);
|
||||
bool HandleAdvertiseTimer(void);
|
||||
static void HandleStateUpdateTimer(void *aContext);
|
||||
void HandleStateUpdateTimer(void);
|
||||
static void HandleDelayedResponseTimer(void *aContext);
|
||||
void HandleDelayedResponseTimer(void);
|
||||
|
||||
ThreadError AddDelayedResponse(Message &aMessage, const Ip6::Address &aDestination, uint16_t aDelay);
|
||||
|
||||
MessageQueue mDelayedResponses;
|
||||
|
||||
TrickleTimer mAdvertiseTimer;
|
||||
Timer mStateUpdateTimer;
|
||||
Timer mDelayedResponseTimer;
|
||||
|
||||
Coap::Resource mAddressSolicit;
|
||||
Coap::Resource mAddressRelease;
|
||||
|
||||
uint8_t mRouterIdSequence;
|
||||
uint32_t mRouterIdSequenceLastUpdated;
|
||||
Router mRouters[kMaxRouterId + 1];
|
||||
uint8_t mMaxChildrenAllowed;
|
||||
Child mChildren[kMaxChildren];
|
||||
|
||||
uint8_t mChallengeTimeout;
|
||||
uint8_t mChallenge[8];
|
||||
uint16_t mNextChildId;
|
||||
uint8_t mNetworkIdTimeout;
|
||||
uint8_t mRouterUpgradeThreshold;
|
||||
uint8_t mRouterDowngradeThreshold;
|
||||
uint8_t mLeaderWeight;
|
||||
uint32_t mFixedLeaderPartitionId; ///< only for certification testing
|
||||
bool mRouterRoleEnabled;
|
||||
|
||||
uint8_t mRouterId;
|
||||
uint8_t mPreviousRouterId;
|
||||
|
||||
Coap::Server &mCoapServer;
|
||||
Coap::Client &mCoapClient;
|
||||
};
|
||||
|
||||
} // namespace Mle
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
} // namespace Thread
|
||||
|
||||
#endif // MLE_ROUTER_HPP_
|
||||
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright (c) 2016, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes definitions for MLE functionality required by the Thread Router and Leader roles.
|
||||
*/
|
||||
|
||||
#ifndef MLE_ROUTER_HPP_
|
||||
#define MLE_ROUTER_HPP_
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <thread/mle.hpp>
|
||||
#include <thread/mle_tlvs.hpp>
|
||||
#include <thread/thread_tlvs.hpp>
|
||||
|
||||
namespace Thread {
|
||||
namespace Mle {
|
||||
|
||||
class MleRouter: public Mle
|
||||
{
|
||||
friend class Mle;
|
||||
|
||||
public:
|
||||
explicit MleRouter(ThreadNetif &aThreadNetif) : Mle(aThreadNetif) { }
|
||||
|
||||
bool IsRouterRoleEnabled(void) const { return false; }
|
||||
void SetRouterRoleEnabled(bool) { }
|
||||
|
||||
bool IsSingleton(void) { return false; }
|
||||
|
||||
ThreadError BecomeRouter(ThreadStatusTlv::Status) { return kThreadError_NotCapable; }
|
||||
ThreadError BecomeLeader(void) { return kThreadError_NotCapable; }
|
||||
|
||||
uint8_t GetActiveRouterCount(void) const { return 0; }
|
||||
|
||||
uint32_t GetLeaderAge(void) const { return 0; }
|
||||
|
||||
uint8_t GetLeaderWeight(void) const { return 0; }
|
||||
void SetLeaderWeight(uint8_t) { }
|
||||
|
||||
uint32_t GetLeaderPartitionId(void) const { return 0; }
|
||||
void SetLeaderPartitionId(uint32_t) { }
|
||||
|
||||
ThreadError SetPreferredRouterId(uint8_t) { return kThreadError_NotImplemented; }
|
||||
|
||||
uint16_t GetNextHop(uint16_t aDestination) const { return Mle::GetNextHop(aDestination); }
|
||||
|
||||
uint8_t GetNetworkIdTimeout(void) const { return 0; }
|
||||
void SetNetworkIdTimeout(uint8_t) { }
|
||||
|
||||
uint8_t GetRouteCost(uint16_t) const { return 0; }
|
||||
|
||||
uint8_t GetRouterIdSequence(void) const { return 0; }
|
||||
|
||||
uint8_t GetRouterUpgradeThreshold(void) const { return 0; }
|
||||
void SetRouterUpgradeThreshold(uint8_t) { }
|
||||
|
||||
uint8_t GetRouterDowngradeThreshold(void) const { return 0; }
|
||||
void SetRouterDowngradeThreshold(uint8_t) { }
|
||||
|
||||
ThreadError ReleaseRouterId(uint8_t) { return kThreadError_NotImplemented; }
|
||||
|
||||
ThreadError RemoveNeighbor(const Mac::Address &) { return BecomeDetached(); }
|
||||
ThreadError RemoveNeighbor(Neighbor &) { return BecomeDetached(); }
|
||||
|
||||
Child *GetChild(uint16_t) { return NULL; }
|
||||
Child *GetChild(const Mac::ExtAddress &) { return NULL; }
|
||||
Child *GetChild(const Mac::Address &) { return NULL; }
|
||||
|
||||
uint8_t GetChildIndex(const Child &) { return 0; }
|
||||
|
||||
Child *GetChildren(uint8_t *aNumChildren) {
|
||||
if (aNumChildren != NULL) {
|
||||
*aNumChildren = 0;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ThreadError SetMaxAllowedChildren(uint8_t) { return kThreadError_NotImplemented; }
|
||||
|
||||
Neighbor *GetNeighbor(uint16_t aAddress) { return Mle::GetNeighbor(aAddress); }
|
||||
Neighbor *GetNeighbor(const Mac::ExtAddress &aAddress) { return Mle::GetNeighbor(aAddress); }
|
||||
Neighbor *GetNeighbor(const Mac::Address &aAddress) { return Mle::GetNeighbor(aAddress); }
|
||||
Neighbor *GetNeighbor(const Ip6::Address &aAddress) { return Mle::GetNeighbor(aAddress); }
|
||||
|
||||
ThreadError GetChildInfoById(uint16_t, otChildInfo &) { return kThreadError_NotImplemented; }
|
||||
ThreadError GetChildInfoByIndex(uint8_t, otChildInfo &) { return kThreadError_NotImplemented; }
|
||||
|
||||
ThreadError GetNextNeighborInfo(otNeighborInfoIterator &, otNeighborInfo &) { return kThreadError_NotImplemented; }
|
||||
|
||||
Router *GetRouters(uint8_t *aNumRouters) {
|
||||
if (aNumRouters != NULL) {
|
||||
*aNumRouters = 0;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ThreadError GetRouterInfo(uint16_t, otRouterInfo &) { return kThreadError_NotImplemented; }
|
||||
|
||||
static int ComparePartitions(bool, const LeaderDataTlv &, bool, const LeaderDataTlv &) { return 0; }
|
||||
|
||||
ThreadError CheckReachability(uint16_t aMeshSource, uint16_t aMeshDest, Ip6::Header &aIp6Header) {
|
||||
return Mle::CheckReachability(aMeshSource, aMeshDest, aIp6Header);
|
||||
}
|
||||
|
||||
static bool IsRouterIdValid(uint8_t aRouterId) { return aRouterId <= kMaxRouterId; }
|
||||
|
||||
void FillConnectivityTlv(ConnectivityTlv &) { }
|
||||
void FillRouteTlv(RouteTlv &) { }
|
||||
const MessageQueue &GetMessageQueue(void) const { return mDelayedResponses; }
|
||||
|
||||
private:
|
||||
ThreadError HandleDetachStart(void) { return kThreadError_None; }
|
||||
ThreadError HandleChildStart(otMleAttachFilter) { return kThreadError_None; }
|
||||
ThreadError HandleLinkRequest(const Message &, const Ip6::MessageInfo &) { return kThreadError_Drop; }
|
||||
ThreadError HandleLinkAccept(const Message &, const Ip6::MessageInfo &, uint32_t) { return kThreadError_Drop; }
|
||||
ThreadError HandleLinkAccept(const Message &, const Ip6::MessageInfo &, uint32_t, bool) { return kThreadError_Drop; }
|
||||
ThreadError HandleLinkAcceptAndRequest(const Message &, const Ip6::MessageInfo &, uint32_t) { return kThreadError_Drop; }
|
||||
ThreadError HandleAdvertisement(const Message &, const Ip6::MessageInfo &) { return kThreadError_Drop; }
|
||||
ThreadError HandleParentRequest(const Message &, const Ip6::MessageInfo &) { return kThreadError_Drop; }
|
||||
ThreadError HandleChildIdRequest(const Message &, const Ip6::MessageInfo &, uint32_t) { return kThreadError_Drop; }
|
||||
ThreadError HandleChildUpdateRequest(const Message &, const Ip6::MessageInfo &) { return kThreadError_Drop; }
|
||||
ThreadError HandleDataRequest(const Message &, const Ip6::MessageInfo &) { return kThreadError_Drop; }
|
||||
ThreadError HandleNetworkDataUpdateRouter(void) { return kThreadError_None; }
|
||||
|
||||
ThreadError ProcessRouteTlv(const RouteTlv &aRoute) { (void)aRoute; return kThreadError_None; }
|
||||
|
||||
MessageQueue mDelayedResponses;
|
||||
};
|
||||
|
||||
} // namespace Mle
|
||||
} // namespace Thread
|
||||
|
||||
#endif // MLE_ROUTER_HPP_
|
||||
@@ -26,129 +26,8 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes definitions for manipulating local Thread Network Data.
|
||||
*/
|
||||
|
||||
#ifndef NETWORK_DATA_LOCAL_HPP_
|
||||
#define NETWORK_DATA_LOCAL_HPP_
|
||||
|
||||
#include <thread/network_data.hpp>
|
||||
|
||||
namespace Thread {
|
||||
|
||||
class ThreadNetif;
|
||||
|
||||
/**
|
||||
* @addtogroup core-netdata-local
|
||||
*
|
||||
* @brief
|
||||
* This module includes definitions for manipulating local Thread Network Data.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
namespace NetworkData {
|
||||
|
||||
/**
|
||||
* This class implements the Thread Network Data contributed by the local device.
|
||||
*
|
||||
*/
|
||||
class Local: public NetworkData
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This constructor initializes the local Network Data.
|
||||
*
|
||||
* @param[in] aNetif A reference to the Thread network interface.
|
||||
*
|
||||
*/
|
||||
explicit Local(ThreadNetif &aNetif);
|
||||
|
||||
/**
|
||||
* This method adds a Border Router entry to the Thread Network Data.
|
||||
*
|
||||
* @param[in] aPrefix A pointer to the prefix.
|
||||
* @param[in] aPrefixLength The length of @p aPrefix in bytes.
|
||||
* @param[in] aPrf The preference value.
|
||||
* @param[in] aFlags The Border Router Flags value.
|
||||
* @param[in] aStable The Stable value.
|
||||
*
|
||||
* @retval kThreadError_None Successfully added the Border Router entry.
|
||||
* @retval kThreadError_NoBufs Insufficient space to add the Border Router entry.
|
||||
*
|
||||
*/
|
||||
ThreadError AddOnMeshPrefix(const uint8_t *aPrefix, uint8_t aPrefixLength, int8_t aPrf, uint8_t aFlags,
|
||||
bool aStable);
|
||||
|
||||
/**
|
||||
* This method removes a Border Router entry from the Thread Network Data.
|
||||
*
|
||||
* @param[in] aPrefix A pointer to the prefix.
|
||||
* @param[in] aPrefixLength The length of @p aPrefix in bytes.
|
||||
*
|
||||
* @retval kThreadError_None Successfully removed the Border Router entry.
|
||||
* @retval kThreadError_NotFound Could not find the Border Router entry.
|
||||
*
|
||||
*/
|
||||
ThreadError RemoveOnMeshPrefix(const uint8_t *aPrefix, uint8_t aPrefixLength);
|
||||
|
||||
/**
|
||||
* This method adds a Has Route entry to the Thread Network data.
|
||||
*
|
||||
* @param[in] aPrefix A pointer to the prefix.
|
||||
* @param[in] aPrefixLength The length of @p aPrefix in bytes.
|
||||
* @param[in] aPrf The preference value.
|
||||
* @param[in] aStable The Stable value.
|
||||
*
|
||||
* @retval kThreadError_None Successfully added the Has Route entry.
|
||||
* @retval kThreadError_NoBufs Insufficient space to add the Has Route entry.
|
||||
*
|
||||
*/
|
||||
ThreadError AddHasRoutePrefix(const uint8_t *aPrefix, uint8_t aPrefixLength, int8_t aPrf, bool aStable);
|
||||
|
||||
/**
|
||||
* This method removes a Border Router entry from the Thread Network Data.
|
||||
*
|
||||
* @param[in] aPrefix A pointer to the prefix.
|
||||
* @param[in] aPrefixLength The length of @p aPrefix in bytes.
|
||||
*
|
||||
* @retval kThreadError_None Successfully removed the Border Router entry.
|
||||
* @retval kThreadError_NotFound Could not find the Border Router entry.
|
||||
*
|
||||
*/
|
||||
ThreadError RemoveHasRoutePrefix(const uint8_t *aPrefix, uint8_t aPrefixLength);
|
||||
|
||||
/**
|
||||
* This method sends a Server Data Notification message to the Leader.
|
||||
*
|
||||
* @retval kThreadError_None Successfully enqueued the notification message.
|
||||
* @retval kThreadError_NoBufs Insufficient message buffers to generate the notification message.
|
||||
*
|
||||
*/
|
||||
ThreadError SendServerDataNotification(void);
|
||||
|
||||
private:
|
||||
ThreadError UpdateRloc(void);
|
||||
ThreadError UpdateRloc(PrefixTlv &aPrefix);
|
||||
ThreadError UpdateRloc(HasRouteTlv &aHasRoute);
|
||||
ThreadError UpdateRloc(BorderRouterTlv &aBorderRouter);
|
||||
|
||||
bool IsOnMeshPrefixConsistent(void);
|
||||
bool IsExternalRouteConsistent(void);
|
||||
|
||||
uint16_t mOldRloc;
|
||||
|
||||
Leader &mLeader;
|
||||
};
|
||||
|
||||
} // namespace NetworkData
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
} // namespace Thread
|
||||
|
||||
#endif // NETWORK_DATA_LOCAL_HPP_
|
||||
#ifdef OPENTHREAD_MTD
|
||||
#include "network_data_local_mtd.hpp"
|
||||
#else
|
||||
#include "network_data_local_ftd.hpp"
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright (c) 2016, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes definitions for manipulating local Thread Network Data.
|
||||
*/
|
||||
|
||||
#ifndef NETWORK_DATA_LOCAL_HPP_
|
||||
#define NETWORK_DATA_LOCAL_HPP_
|
||||
|
||||
#include <thread/network_data.hpp>
|
||||
|
||||
namespace Thread {
|
||||
|
||||
class ThreadNetif;
|
||||
|
||||
/**
|
||||
* @addtogroup core-netdata-local
|
||||
*
|
||||
* @brief
|
||||
* This module includes definitions for manipulating local Thread Network Data.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
namespace NetworkData {
|
||||
|
||||
/**
|
||||
* This class implements the Thread Network Data contributed by the local device.
|
||||
*
|
||||
*/
|
||||
class Local: public NetworkData
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This constructor initializes the local Network Data.
|
||||
*
|
||||
* @param[in] aNetif A reference to the Thread network interface.
|
||||
*
|
||||
*/
|
||||
explicit Local(ThreadNetif &aNetif);
|
||||
|
||||
/**
|
||||
* This method adds a Border Router entry to the Thread Network Data.
|
||||
*
|
||||
* @param[in] aPrefix A pointer to the prefix.
|
||||
* @param[in] aPrefixLength The length of @p aPrefix in bytes.
|
||||
* @param[in] aPrf The preference value.
|
||||
* @param[in] aFlags The Border Router Flags value.
|
||||
* @param[in] aStable The Stable value.
|
||||
*
|
||||
* @retval kThreadError_None Successfully added the Border Router entry.
|
||||
* @retval kThreadError_NoBufs Insufficient space to add the Border Router entry.
|
||||
*
|
||||
*/
|
||||
ThreadError AddOnMeshPrefix(const uint8_t *aPrefix, uint8_t aPrefixLength, int8_t aPrf, uint8_t aFlags,
|
||||
bool aStable);
|
||||
|
||||
/**
|
||||
* This method removes a Border Router entry from the Thread Network Data.
|
||||
*
|
||||
* @param[in] aPrefix A pointer to the prefix.
|
||||
* @param[in] aPrefixLength The length of @p aPrefix in bytes.
|
||||
*
|
||||
* @retval kThreadError_None Successfully removed the Border Router entry.
|
||||
* @retval kThreadError_NotFound Could not find the Border Router entry.
|
||||
*
|
||||
*/
|
||||
ThreadError RemoveOnMeshPrefix(const uint8_t *aPrefix, uint8_t aPrefixLength);
|
||||
|
||||
/**
|
||||
* This method adds a Has Route entry to the Thread Network data.
|
||||
*
|
||||
* @param[in] aPrefix A pointer to the prefix.
|
||||
* @param[in] aPrefixLength The length of @p aPrefix in bytes.
|
||||
* @param[in] aPrf The preference value.
|
||||
* @param[in] aStable The Stable value.
|
||||
*
|
||||
* @retval kThreadError_None Successfully added the Has Route entry.
|
||||
* @retval kThreadError_NoBufs Insufficient space to add the Has Route entry.
|
||||
*
|
||||
*/
|
||||
ThreadError AddHasRoutePrefix(const uint8_t *aPrefix, uint8_t aPrefixLength, int8_t aPrf, bool aStable);
|
||||
|
||||
/**
|
||||
* This method removes a Border Router entry from the Thread Network Data.
|
||||
*
|
||||
* @param[in] aPrefix A pointer to the prefix.
|
||||
* @param[in] aPrefixLength The length of @p aPrefix in bytes.
|
||||
*
|
||||
* @retval kThreadError_None Successfully removed the Border Router entry.
|
||||
* @retval kThreadError_NotFound Could not find the Border Router entry.
|
||||
*
|
||||
*/
|
||||
ThreadError RemoveHasRoutePrefix(const uint8_t *aPrefix, uint8_t aPrefixLength);
|
||||
|
||||
/**
|
||||
* This method sends a Server Data Notification message to the Leader.
|
||||
*
|
||||
* @retval kThreadError_None Successfully enqueued the notification message.
|
||||
* @retval kThreadError_NoBufs Insufficient message buffers to generate the notification message.
|
||||
*
|
||||
*/
|
||||
ThreadError SendServerDataNotification(void);
|
||||
|
||||
private:
|
||||
ThreadError UpdateRloc(void);
|
||||
ThreadError UpdateRloc(PrefixTlv &aPrefix);
|
||||
ThreadError UpdateRloc(HasRouteTlv &aHasRoute);
|
||||
ThreadError UpdateRloc(BorderRouterTlv &aBorderRouter);
|
||||
|
||||
bool IsOnMeshPrefixConsistent(void);
|
||||
bool IsExternalRouteConsistent(void);
|
||||
|
||||
uint16_t mOldRloc;
|
||||
|
||||
Leader &mLeader;
|
||||
};
|
||||
|
||||
} // namespace NetworkData
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
} // namespace Thread
|
||||
|
||||
#endif // NETWORK_DATA_LOCAL_HPP_
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2016, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file includes definitions for manipulating local Thread Network Data.
|
||||
*/
|
||||
|
||||
#ifndef NETWORK_DATA_LOCAL_HPP_
|
||||
#define NETWORK_DATA_LOCAL_HPP_
|
||||
|
||||
#include <thread/network_data.hpp>
|
||||
|
||||
namespace Thread {
|
||||
|
||||
class ThreadNetif;
|
||||
|
||||
namespace NetworkData {
|
||||
|
||||
class Local
|
||||
{
|
||||
public:
|
||||
explicit Local(ThreadNetif &) { }
|
||||
|
||||
ThreadError AddOnMeshPrefix(const uint8_t *, uint8_t, int8_t, uint8_t, bool) { return kThreadError_NotImplemented; }
|
||||
ThreadError RemoveOnMeshPrefix(const uint8_t *, uint8_t) { return kThreadError_NotImplemented; }
|
||||
|
||||
ThreadError AddHasRoutePrefix(const uint8_t *, uint8_t, int8_t, bool) { return kThreadError_NotImplemented; }
|
||||
ThreadError RemoveHasRoutePrefix(const uint8_t *, uint8_t) { return kThreadError_NotImplemented; }
|
||||
|
||||
ThreadError SendServerDataNotification(void) { return kThreadError_NotImplemented; }
|
||||
|
||||
void GetNetworkData(bool, uint8_t *, uint8_t &aDataLength) { aDataLength = 0; }
|
||||
ThreadError GetNextOnMeshPrefix(otNetworkDataIterator *, otBorderRouterConfig *) { return kThreadError_NotFound; }
|
||||
void ClearResubmitDelayTimer(void) { }
|
||||
|
||||
};
|
||||
|
||||
} // namespace NetworkData
|
||||
} // namespace Thread
|
||||
|
||||
#endif // NETWORK_DATA_LOCAL_HPP_
|
||||
@@ -59,9 +59,9 @@ class Node:
|
||||
cmd = os.environ['OT_CLI_PATH']
|
||||
elif "top_builddir" in os.environ.keys():
|
||||
srcdir = os.environ['top_builddir']
|
||||
cmd = '%s/examples/apps/cli/ot-cli' % srcdir
|
||||
cmd = '%s/examples/apps/cli/ot-cli-ftd' % srcdir
|
||||
else:
|
||||
cmd = './ot-cli'
|
||||
cmd = './ot-cli-ftd'
|
||||
cmd += ' %d' % nodeid
|
||||
print ("%s" % cmd)
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ AM_CPPFLAGS = \
|
||||
$(NULL)
|
||||
|
||||
COMMON_LDADD = \
|
||||
$(top_builddir)/src/core/libopenthread.a \
|
||||
$(top_builddir)/src/core/libopenthread-ftd.a \
|
||||
-lpthread \
|
||||
$(NULL)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user