38 Commits

Author SHA1 Message Date
Abtin Keshavarzian 7eb59f71da [network-diag] introduce AnswerBuilder to manage answer messages (#12887)
This commit introduces `AnswerBuilder` class to track and manage
Network Diagnostic answer messages. This class is used when the
response to a query requires multiple CoAP answer messages. It
automatically manages the inclusion of the Query ID and the Answer
TLVs(providing message indexing and "more-to-follow" flags) in each
allocated answer message, while maintaining all answer messages in a
queue. The `NetworkDiagnostic::Server` is updated to use the
`AnswerBuilder`, simplifying the logic for preparing and sending
answers.

The `AnswerBuilder` class is added in a new header file
`network_diagnostic_types.hpp` to allow for its reuse by other
modules in the future.
2026-04-17 13:21:59 -05:00
Abtin Keshavarzian c55098af5e [message] change queues to use non-circular linked list (#11630)
This commit updates the `MessageQueue` and `PriorityQueue`
implementations to use non-circular doubly linked lists instead of
the previous circular ones. Using a non-circular list requires the
queue to track the head element, but it simplifies common operations
like getting the head and iterating over the messages.

Particularly, `Message::GetNext()` now simply returns the `mNext`
pointer. Previously, `Message` had to store a pointer to its `mQueue`
within its `Metadata` to identify the tail of the queue and stop the
iteration correctly.

This commit also updates the unit tests. In particular,
`test_priority_queue` is significantly enhanced to cover many
scenarios, such as multiple messages with the same priority, and
messages with different priorities being added and removed in various
orders.
2025-06-25 13:03:43 -07:00
Abtin Keshavarzian 23c0fc4d4b [test] define all unit tests in ot namespace (#9617)
This commit updates unit test modules to be defined under the `ot`
namespace. This aligns all the unit tests to follow the same
model, eliminating the need to use `ot::` prefix in unit test
code.
2023-11-19 18:40:20 -08:00
Abtin Keshavarzian 1528c8831d [core] define core/instance folder for instance modules (#9561)
This commit moves the `instance` module to a newly added folder
`core/instance` (from `core/common`.  Header file `extension.hpp`
and its example is also moved to the same folder.
2023-10-26 05:08:24 -07:00
Jonathan Hui 9c467a23ae [clang-format] apply v14 changes (#8490) 2022-12-07 16:23:20 -08:00
Abtin Keshavarzian 82f5ab298b [message] update and simplify otBufferInfo (#7596)
This commit updates the `otMessageGetBufferInfo()` and its related
types. In particular, this commit adds `otMessageQueueInfo` to
indicate number of messages, number of data buffers, and total
message length (number of bytes) for all messages in the queue.
2022-04-18 19:53:43 -07:00
Abtin Keshavarzian 237c91b939 [message] add range-based for loop for message/priority queue (#7481)
This commit adds support for range-based `for` loop iteration over
`MessageQueue` and `PriorityQueue`. It adds `ConstIterator` and
`Iterator` in `Message` class. The non-const `for` loop iteration
(which uses `Message::Iterator`) works properly and is safe to use
even when the entry is removed from the queue during iteration. This
commit updates other core modules to use the new `for` loop iteration
model which helps simplify the code. It also updates the unit tests
to validate the behavior of the newly added iteration mechanisms.
2022-03-21 09:28:12 -07:00
Abtin Keshavarzian 16798fdcc0 [message] simplify method for allocating new message from pool (#7210)
This commit removes different `MessagePool` methods that can be used
to allocate a new message  and combines them into one `Allocate()`
method which uses `Message::Settings`. The `Message::Settings` is
also updated to provide new constructor initializing it with a given
message priority only.
2021-11-29 13:46:07 -08:00
Abtin Keshavarzian 57d072d352 [test] enhance {Verify/Success}OrQuit() and their use in unit test (#6764)
This commit updates `VerifyOrQuit()` and `SuccessOrQuit()` macros to
include the failed condition in the error message that is printed on
a failure (in addition to function name and line number where the
error happened). This commit also changes the second parameter
(`aMessage`) to in these macros to be optional.

This commit also updates unit tests to remove the second `aMessage`
string in cases where the failure can be inferred from the condition
itself.
2021-06-28 11:38:10 -07:00
Simon Lin 5e9b2818eb [style] convert to C++11 for loops (#5263) 2020-07-21 09:41:40 -07:00
Jonathan Hui 1326d64a64 [style] replace NULL with nullptr (#5109) 2020-06-17 22:44:54 -07:00
Jonathan Hui cf57110c47 [message-queue] change Dequeue to return void (#4942) 2020-05-11 14:07:25 -07:00
Jonathan Hui 7540758076 [message-queue] change Enqueue() to return void (#4942) 2020-05-11 14:07:25 -07:00
Jonathan Hui 5b22b4d7c7 [utils] remove wrap_string.h (#4483) 2020-01-22 13:39:25 -08:00
Abtin Keshavarzian f10c6c36fd [unit-test] remove (unnecessary) ENABLE_TEST_MAIN definition (#4367) 2019-12-11 09:16:48 -08:00
Abtin Keshavarzian ab27fcd9e6 [unit-test] remove extra \n at end of error message (#4367)
This commit removes the extra `\n` at the end of error message strings
used in `VerifyOrQuit()` or `SuccessOrQuit()` macros in different unit
test modules. This help make the style (usage of macros) consistent
across all unit tests.
2019-12-11 09:16:48 -08:00
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
Zhanglong Xia f8909593a9 [api] update message API to create message with priority (#3199) 2018-11-05 12:48:39 -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 2578a7bf8c [message-queue] enable adding a message to head of queue (#2246)
This commit updates the `MessageQueue` implementation to allow
messages to be added to head/front of the queue. It adds new methods
to the `MessageQueue` class and a corresponding one in public
OpenThread APIs (`otMessageQueueEnqueueAtHead()`). This commit also
updates the `test_message_queue` unit test to add cases/scenarios for
testing the new methods and public APIs.
2017-10-11 15:15:53 -07:00
Buke Po 1ff8824d18 [message] decouple message and ip6 (#2028) 2017-07-25 08:46:53 -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
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
Abtin Keshavarzian 41b82d3a89 Fix typos in comments (#1688) 2017-05-01 14:46:30 -07:00
Jonathan Hui 1eabda6a08 Change top-level namespace from 'Thread' to 'ot'. (#1664) 2017-04-27 22:29:05 -07:00
DuaneEllis-TI d65418c12f Add support for wrap_string.h and others (#1642) 2017-04-27 10:17:09 -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 31b389fb4e Change otMessage type to not hide pointer. (#1416) 2017-03-02 12:43:59 -08:00
Jonathan Hui d0c687505b Move openthread.h to openthread/openthread.h. 2017-03-02 10:24:55 -08:00
Jonathan Hui 98da7f3166 IPv6 API cleanup. 2017-03-02 10:24:55 -08:00
Jonathan Hui 1455b612f9 Message API cleanup. 2017-03-02 10:24:55 -08:00
Jorge Vergara f3817e76cf Enable mbedTLS dynamic memory allocation in user mode on Windows (#1373)
* change user mode openthread to enable dynamic memory allocation in mbedtls

* complete merge by adding OPENTHREAD_MULTIPLE_INSTANCE to last file

* remove some extraneous changes that got pulled in accidentally

* fix spacing

* fix crash in existing tests due to this change

* fix x86 build
2017-02-23 22:01:59 -08:00
Abtin Keshavarzian 3fbba0eced Adding otMessageQueue OpenThread C APIs and their unit test (#1115) 2017-01-09 08:33:26 -08:00
Abtin Keshavarzian d0cf21e3ba PriorityQueue and MessagePool::Iterator and their unit-test (#1096)
This commit contains the following:

- It adds methods to `Message` to assign a priority level to messages.
  Currently there are four priority levels: High, Medium, Low, VeryLow
  but this is easily changeable.

- It introduces a new class `PriorityQueue` which implements a FIFO queue
  for storing messages based on their priority level in addition to oder
  in which they are added.
  If the priority level of an already queued message in a `PriorityQueue`
  is changed, the associated queue will automatically move the message
  within the queue based on its new priority level.
  Internally the implementation uses a circular doubly linked-list with
  an array of tail pointers associated with different priority levels.

- It adds new methods and an `Iterator` class  in `MessagePool` to access
  the priority queue where all allocated and queued messages from this
  pool are stored.  The `Iterator` class allows bi-directional iteration
  through the list (from highest priority to lowest or reverse).

- This commit also contain detailed unit-test for all the newly added
  features/methods.
2016-12-21 13:50:57 -08:00
Abtin Keshavarzian 9d3bd7802b Update the MessageQueue and add unit test for it. (#1089)
This commit makes the following changes:

- It adds a unit test for testing different `MessageQueue` operations.

- It modifies how the `MessageQueue` determines the lists (the `kListAll`
  is maintained by the message pool and the `kListInterface` is accessed
  from the `MessageQueue` associated with the list).

- It modifies the underlying list implementation to use a circular doubly
  linked-list.
2016-12-20 08:46:58 -08:00