Commit Graph

27 Commits

Author SHA1 Message Date
Abtin Keshavarzian 8f112eeb5a [locator] adding Get<Type> to InstanceLocator (#3714)
This commit changes how the objects in OpenThread access each other.
It adds a template `Get<Type>()` method in `InstanceLocator`. This
method returns a reference to a given `Type` object belonging to the
OpenThread instance (e.g. `Get<MeshForwarder>()` returns a reference
to `MeshForwarder` object on the OpenThread instance). The
`InstanceLocator` is used as base class of all OpenThread classes so
every class can easily access any other object. This commit also
changes how the main instance is retrieved in `InstanceLocator` for
the single-instance case. The method `GetInstance()` directly uses the
raw buffer `gInstanceRaw`. This change helps make the `GetInstance()`
and in turn all `Get<Type>()` methods in-line. This commit also
removes the existing getters across all classes to use the new
`Get<Type>()` model.
2019-04-02 09:07:25 -07:00
Jonathan Hui ac89fd5496 [style] return void where code always returns OT_ERROR_NONE (#3543) 2019-02-01 09:03:24 -08:00
Jonathan Hui 9d585edc46 [types] move types into specific headers (#2946) 2018-08-08 11:19:41 -07:00
Jonathan Hui 69d98d4a53 [code-style] apply clang-format 2018-02-09 21:43:42 +00:00
Abtin Keshavarzian 02c876ef62 [instance] define ot::Instance class (#2307)
This commit makes the following changes: It defines the public
`otInstance` as an empty opaque structure which is used by all public
C OpenThread APIs. It defines a new class `ot::Instance` (inheriting
from `otInstance) which is then used in core source files. The
functionality related to the instance is also moved/added into the
newly added `Instance` class (as class/static or member methods).
2017-11-13 08:27:57 -08:00
Abtin Keshavarzian 54fa0f1836 [ncp] enhance handling of outbound IP message over spinel (to host) (#2259)
This commit changes how the outbound datagram IPv6 messages (going
from NCP to host over spinel) are handled. If NCP spinel buffer is
full, new outbound messages are saved in a message queue and are
transfered later (as soon as buffer space becomes available). This
ensures that outbound IPv6 messages are never dropped due to spinel
NCP buffer being full.

To realize this, the following changes are made in this commit: (a)
The behavior of methods `NcpFrameBuffer::InFrameFeedMessage()` and
`SpinelEncoder::WriteMessage()` is changed so that the passed-in
message ownership changes to NCP buffer ONLY when the entire spinel
frame is written and the frame is successfully ended/finished. If the
spinel frame gets discarded (e.g. no buffer space) the caller continues
to own the message instance and should either free or save it. (b)
The unit test `test_ncp_buffer` is changed to address and check for
this change. (c) The `NcpBase::HandleDatagramFromStack()` is modified
to implement/use a message queue to save outbound messages and try again
to send the queued messages from `HandleFrameRemovedFromNcpBuffer()`
callback (when spinel buffer becomes available).
2017-10-13 09:29:18 -07:00
Buke Po 34f9c9a919 [message] change Message::Free() to return void (#2071) 2017-08-06 22:26:37 -07:00
Buke Po 818998e609 [ncp] split ncp_base and rearrange declarations (#2045)
* split handlers into general, mtd, ftd and radio-only.
* move ChangedPropsSet into separate file.
* add Ncp namespace.
2017-08-03 10:19:07 -07:00
Buke Po 1ff8824d18 [message] decouple message and ip6 (#2028) 2017-07-25 08:46:53 -07:00
Buke Po ffd28ebd4d [crypto] reduce memcpy() usage (#2018) 2017-07-20 22:15:44 -07:00
Abtin Keshavarzian fa1041f705 [ncp-buffer] support for saving write position and overwriting content (#2010)
This commit adds new `InFrame` related methods to `NcpFrameBuffer` to
allow user to get/save current write position in an input frame being
written to the buffer. The saved position can later be used to
overwrite the previously added content (using `InFrameOverwrite()`) or
discard a portion of written data and move the write pointer back to
the saved position (using `InFrameReset()`).

The unit test for NCP buffer is also updated to add new test-cases
specific for the newly added methods.
2017-07-19 09:06:14 -07:00
Abtin Keshavarzian 529c291f7a [ncp-buffer] Frame Priority Support (#1948)
This commit adds support for setting two levels of priority (high or
low) to frames stored in `NcpFrameBuffer`. High-priority frames are
read before any queued low-priority frames. Within the same priority
level FIFO order is preserved.

The `NcpBase` is updated to send/queue the spinel response frames (with
non- zero `tid`) as higher-priority frames. This ensures faster response
time for spinel commands.

This commit also adds/updates test cases for unit testing the NCP
buffer and its new priority feature.
2017-07-10 08:47:23 -07:00
Abtin Keshavarzian bbab3074ed [instance] single OpenThread instance optimizations (#1926)
This commit new configuration option `enable-multiple-instances` and
its corresponding option `OPENTHREAD_ENABLE_MULTIPLE_INSTANCES`. When
enabled OpenThread supports handling of multiple instances. By default
this is disabled.

This commit also adds two optimizations for single instance case to
simplify the code and also help reduce memory/RAM usage:

(1) OpenThread objects/classes typically keep a reference to a higher
level object (e.g., many classes keep track of owning `ThreadNetif`)
to be able to access other objects/methods within OpenThread class
hierarchy. In single instance mode, the reference member variables are
removed and instead global functions are used to access the singleton
objects from one class to the other. To implement this, a group of
`<Object>Locator` classes are defined (e.g., `ThreadNetifLocator`,
etc.) which are then used as base class of other OpenThread classes.

(2) OpenThread objects which provide a callback/handler (e.g.,
`Timer`, `Tasklet`, etc.) have `void *mContext` member variable which
is used to keep track of the owner of the object. In single instance
mode the `mConext` member variables are removed since the owner is
expected to be a singleton and can be uniquely determined from the
callback function.

To implement this, two changes are made: First the handler methods are
modified to provide a reference to the object (e.g., `Timer` handler
will provide a `Timer &aTimer` as a parameter of its handler
callback). Second, a new base class `Context` is introduced which
hides the implementation providing an arbitrary context information. A
new static method `GetOwner(aContext)` is added to classes which own a
callback providing objects. This method help convert a `Context` to
the reference of the owner class object.
2017-06-30 11:48:26 -07:00
Abtin Keshavarzian be218c4cc1 Update NcpFrameBuffer callbacks, add NCP frame tags, update unit test (#1799)
This commit contains the following changes to the `NcpFrameBuffer`
class:

It updates `NcpFrameBuffer` callbacks by adding `FrameAddedCallback`
and `FrameRemovedCallback` which are respectively invoked when a frame
is added/removed to/from the NCP buffer.

It also adds new concept of NCP frame tag which is a unique (within
the queued NCP frames) value associated with every successfully
queued/added frame in `NcpFrameBufffer`. The tags are passed in the
callbacks to indicate the frame that was added or removed.  New
methods are added to get the tag of the frame at front/top of the
queue and the tag associated with last (successfully) added frame. The
tags are used to track when a NCP frame is removed, which enable us to
detect when the reply to a specific spinel exchange is sent (e.g.,
this is used to track the reply to `SPINEL_HOST_POWER_STATE_ONLINE`
property).

The `NcpBase`, `NcpSpi`, and `NcpUart` implementation are modified to
use the new callbacks and tag related methods.

This commit also updates the `test_ncp_buffer` unit test:

- Additional checks are added to test the new callbacks behavior

- Tests are updated to verify the tag related methods and their
  functionality.

- A new fuzz test is added for NCP buffer where over many iteration, a
  random number of frame with random content and random length are
  added to the NCP frame buffer. It is then verified that frames with
  same content are read back.
2017-05-25 19:16:00 -07:00
Jonathan Hui 48b9299544 Clean up error names. (#1764) 2017-05-23 09:34:35 -07:00
Jonathan Hui fbfd76a990 Apply #include code style. (#1723) 2017-05-05 11:28:29 -07:00
Jonathan Hui 1eabda6a08 Change top-level namespace from 'Thread' to 'ot'. (#1664) 2017-04-27 22:29:05 -07:00
Nick Banks 2549d03f1f Add Dynamic Memory Support to otLwf.sys (#1414)
* Add Dynamic Memory Support

* Use single list for free buffers. Null mNext on return of new buffer.

* Use Paged memory for Buffers.
2017-03-06 13:39:56 -08:00
Jonathan Hui d0c687505b Move openthread.h to openthread/openthread.h. 2017-03-02 10:24:55 -08:00
Abtin Keshavarzian ab13e718c6 Update the NCP code to use otMessage and otMessageQueue APIs (#1151)
This change updates the NCP related files to use `otMessage` and
`otMessageQueue` APIs to replace the direct calls into OpenThread
internal `Message` and `MessageQueue` classes.
2017-01-18 22:03:42 -08:00
Nick Banks 25cea9414b Windows Unit Test Support (#629)
Window Unit Test Support
2016-09-20 18:11:19 -07:00
Jonathan Hui 44350178ad Change copyright to The OpenThread Authors. (#583)
- Add a top-level file named AUTHORS which identifies the copyright
holders of the project.
2016-09-13 15:57:11 -07:00
Nick Banks ffbe65c6dd otInstance Declarations (#473)
* Add otInstance type declaration and update ot APIs to take it as input.
2016-09-12 14:29:43 -07:00
Jonathan Hui e22c123904 Remove globals from message.cpp. 2016-09-07 13:30:22 -07:00
Jonathan Hui 6d958ba51b Fix compiler warnings in unit tests. (#488) 2016-08-29 11:41:59 -07:00
Shu Chen 7130798123 Add diagnostics module in OpenThread (#343)
* Add diagnostics module in OpenThread

  - provide the same diagnostics interface for both CLI and NCP usage
  - implement common diagnostics features based on existing platform interface defined in 'include/platform/'
  - other more platform specific diagnostics features will be processed under platform layer
  - update CLI interface to support diagnostics feature
  - update both Posix and CC2538 platform to support diagnostics feature

* Add diagnostics module unit test

   - move platform.h from "examples/platform" to "include/platform"
   - add test_diag.cpp to test diagnostics module

* Add a configuration option that would enable/disable diagnostics module

Add --enable-diag configuration option to enable/disable diagnostics module when building OpenThread.
2016-08-11 10:26:51 -07:00
Abtin Keshavarzian a46d258ce7 Ncp: Introducing NcpFrame Buffer class and its unit test. (#264)
This commit is part of ncp buffer redesign - issue #59.
2016-07-25 11:17:29 -07:00