Commit graph

63 commits

Author SHA1 Message Date
Felix Walter
62d563449f test: Remove the Unity wrappers for memory allocation functions
This adds a custom header that does explicitly not include the Unity
wrappers for malloc, free, etc. by defining the guard used by that header
file. This way we can remove the wrappers provided via the linker
altogether.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:39:29 +02:00
Felix Walter
adb80c8938 simple_queue: Remove queueItemsWaiting
We cannot easily support this on MacOS, but we do not use it except in
tests. Thus, remove it and make the tests only run on Linux and use
`sem_getvalue` directly.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:01:34 +02:00
Felix Walter
6112e9669c
Merge branch 'hotfix/parser-issues'
See !108
2023-05-15 10:43:20 +02:00
Felix Walter
6b88cbc673
Merge branch 'feature/add-bundle-unit-tests'
See !102
2023-05-15 10:43:02 +02:00
Oleksandr Nazymko
51fa02b77c Add unit tests for bundle operations
This adds unit tests for the functions in `components/ud3tn/bundle.c`.

Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
2023-05-15 08:46:46 +02:00
Felix Walter
62cadd3719 Move the node_prepare_and_verify to router_task
This removes the `hal_time` dependency of the `routing_table`, as it now
assumes that the provided `struct node` is ordered, free of conflicts,
and has valid contact timestamps. This is ensured by invoking
`node_prepare_and_verify` beforehand, in `router_process_command`.
The tests are updated accordingly.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-12 11:59:43 +02:00
Felix Walter
b4e3e5aae9 bundle7/parser: Add note why status is set to DONE even if CRC is invalid
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-12 09:14:37 +02:00
Felix Walter
d9bd711c9a bundle6: Allow for receiving CBHE-encoded bundles
This also adds a test for it, sending bundles from within ION to uD3TN
in the "minimal forwarding test".

Fixes: #7

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-12 08:07:42 +02:00
Felix Walter
379f09d7af hal_time, agents: Remove the function to set the system time
This should be a function offered by the operating system, not by a
userland process like uD3TN.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-11 16:59:13 +02:00
Felix Walter
97d520db34 node: Adapt contact interval DTN timestamp unit to milliseconds
This changes the "from" and "to" fields in the contact struct to
milliseconds-based timestamps and adapts all dependent code. The contact
data format is kept second-based for backward compatibility.

The commit also introduces a new function to work with millisecond
timestamps in the remaining capacity calculation and modifies the tests
related to the latter such that they do not need to change the timestamp.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-11 16:59:13 +02:00
Felix Walter
3cd89eb6a5 bundle, agents: Switch time unit to milliseconds
...to align with the general decision to make DTN timestamps
millisecond-based.

See: #53

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-11 16:59:13 +02:00
Felix Walter
7a3816ca42 node: Add unit suffix to contact interval fields
This clearly identifies that we are working with seconds here.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-11 16:59:13 +02:00
Felix Walter
67fe84a395 node: Identify unit for bitrate in field name
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-11 16:59:13 +02:00
Felix Walter
1237eaa2db Remove heap-allocated Task_t
`hal_task_create` returned a reference to the new task allocated on the
heap via `malloc`. We commonly used the pattern to `free` this reference
from the new thread which, however, could result in race conditions and
other synchronization issues. We added a fix using a semaphore in the
application agent, but this would have been needed in other places (CLA,
...) as well. As we do not make use of the task reference anywhere
besides in the CLA for error handling, we can remove the heap-allocated
value altogether and replace it with an `enum ud3tn_result` to simplify
things and circumvent the named synchronization issues.

In the case of the CLA function `cla_link_init`, logic is introduced to
request the RX task to exit immediately in case the TX task cannot be
launched.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 17:23:55 +02:00
Felix Walter
69e4095dcb Remove hal_random
The test was returning indeterministic errors and we did not even use
the function anymore.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 17:23:55 +02:00
Felix Walter
7678ba7feb test/unit: Remove test of system time
This test was prone to off-by-one errors if the time advanced between
calls. It is also unnecessary as we do not use a special clock
implementation anymore and !85 will fully remove the function to mock
the system time.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 17:23:27 +02:00
Felix Walter
dc7de610c2 test/unit: Relax requirements on indeterministic tests
We have two test cases that are randomly influenced by the system they
are running on. This makes the checks in these tests more forgiving to
random variations that may occur.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 17:23:27 +02:00
Felix Walter
be1f3ffd5a test: Remove malloc test
We do not need to test that `malloc()` works. It is not part of our
program.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 15:07:16 +02:00
Felix Walter
90fd0b4c33 routing_table: Explicitly free contact list upon deletion
There was a rare memory leak if the contact was not found in the target
list (e.g., already deleted earlier).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 15:07:16 +02:00
Felix Walter
a7e41d0e60 test/unit: Make uint32 to wchar_t unsigned-to-signed conversion explicit
Otherwise we may be warned of a value-changing conversion.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 14:32:47 +02:00
Felix Walter
acf4a675c5 test/unit: Use TEST_ASSERT_EQUAL_UINT8_ARRAY instead *_EQUAL_MEMORY
The latter may cause UB according to Clang's UB sanitizer.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 14:32:47 +02:00
Felix Walter
dd6d34d707 hal_time: Make time functions thread-safe
Do not return a reference to a non-thread-safe global variable:
ctime() is not thread safe. As we only use the function in logging, we
can directly print the return value, protected by a mutex.

This also adapts the tests and makes the initialization routine always
run. To use the system time again, UINT64_MAX can be passed.

Found by Clang's thread (data race) sanitizer.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 14:32:47 +02:00
Felix Walter
2fc9e11b7e bundle: Fix potential uint wrap-around in expiration time calculation
We were taking the current time value in milliseconds and sometimes
subtracting larger values from it. This cleans up the calculations to
always determine the expiration time as uint64_t and compare it against
the current uint64_t timestamp.

It further removes the unnecessary "current timestamp" parameter in
`bundle_get_expiration_time_s` (we now store the reception time with the
bundle, so, do not need this anymore) and avoids a integer wrap-around
case in the function.

Note that the current time cancels out in the age block-based
calculation as we can use the reception timestamp there and offset it by
the calculated relative remaining lifetime.

Found by Clang's UB sanitizer.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 14:31:17 +02:00
Felix Walter
c63eaa0cd0 routing_table: Merge overlapping contacts during configuration
Previously we would simply ignore any contact that was overlapping. This
changes the routing table's behavior such that overlapping contacts with
the same node are merged and overlapping contacts with multiple
different nodes are just allowed and added alongside each other. The
maximum number of contacts defined by `MAX_CONCURRENT_CONTACTS` now is
just a limitation of the Contact Manager which will not process more
than that number of contacts at the same time. (If one of them ends, a
concurrent contact that was not handled can be added.)

This change requires, however, that overlapping contacts are properly
rejected in router commands. This is achieved by a corresponding update
of the add/update/delete functions and an extension of the preliminary
checks.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 21:04:30 +01:00
Felix Walter
93a58ed387 Merge Bundle Processor and Router Task
This refactors the Router Task into synchronous functions called by the
BP, preventing the need of circular notifications between them.
The router queue is replaced by new signals in the BP queue.

This additionally removes the global state in the bundle processor.

Closes: #11

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 21:02:36 +01:00
Felix Walter
00ab1577ab Explicitly check the maximum bundle size (and nothing more) in parsers
For BPv6 we had a "bundle quota" check, which is not present for BPv7
anymore and not possible after the removal of the bundle storage manager.
The AAP parser had an equivalent function, which was, however, not used
by the Application Agent.

A more flexible implementation and a new "bundle quota" check are
tracked by issue #105.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 17:42:21 +01:00
Felix Walter
cd959647f8 Remove bundle ID and storage and replace the ID by the bundle pointer
This removes the unnecessary bundle storage manager that was built for
persistent storage but never used for that purpose. We will implement a
proper persistent storage in the new Rust version. For simplifying the
following adaptations this removes everything storage-related and
replaces the used bundle ID by the pointer.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 17:42:21 +01:00
Felix Walter
838c29496b
Merge branch 'hotfix/103-32-bit-ipn-eid-size'
See !84
2022-11-24 20:24:12 +01:00
Felix Walter
7d646c1e50 bundle7: Allow "\0" as representation of the null EID
This is the equivalent of the CBOR encoding of dtn:none and, thus,
should be parsed properly.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-11-22 08:09:48 +01:00
Felix Walter
4bf6888a03 bundle7: Calculate ipn EID size using 64 bit integers
The node and service number are 64 bit unsigned integers. This fixes the
validation and EID serialized size calculation and adds appropriate
tests to the serializer unit tests.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-11-21 09:41:03 +01:00
Felix Walter
915051b278 CLA: TCPSPP: Drop SPPs with unknown APID before parsing timecode
We do not need to parse the timecode to drop SPP frames that do not
belong to us. This makes the SPP parser return on every change of its
internal state (as it is called again by the CLA methods, this is a
totally valid mode of operation) and check the APID early in the CLA
methods.

By that we also support receiving SPPs that use different formats to
other APIDs (e.g., without any timecode in case we are expecting a
timecode).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-11-09 09:30:45 +01:00
Felix Walter
8bde2cad33 bundle7/eid: Fix ipn EID parsing for servicenum == 0
If the service number of a bundle7 EID was set to zero, this resulted in
an EID like "ipn:xxx." instead of "ipn:xxx.0", because the allocated
length was determined in the wrong manner for the special case of zero.

This also adds tests for the "zero" case and the case of UINT64_MAX.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-08-29 13:58:06 +02:00
Marius Feldmann
691b7c3172 Remove STM32/FreeRTOS support from uD3TN
Former releases of uD3TN have included support for STM32/FreeRTOS.
Having this support from the first moment on was a good thing in
order to optimize for platforms with limited resources. As this
platform is not used in current uD3TN setups and as it results in quite
some maintenance work, it is removed with this commit. The removed parts
cover the implementation itself, tests, tools, documentation, parts of
the build/make scripts as well as licensing information.

Signed-off-by: Marius Feldmann <marius.feldmann@d3tn.com>
2022-03-22 00:05:13 +01:00
Georg Alexander Murzik
298431c68f Insert SPDX license expression comments into our .c, .h, .py, and .sh code
ud3tn is available under multiple licenses and we want to reflect this in
our source code. But which license information should appear first and how
can we manage this efficiently in the future? The Linux Kernel uses SPDX
expressions instead of boilerplate sections. This seems to be a great
approach, so we do the same here.

Signed-off-by: Georg Alexander Murzik <georg.murzik@d3tn.com>
2022-02-20 16:24:38 +01:00
Felix Walter
54ffea87f1 test/unit: Add tests for non-singleton dtn-scheme EIDs
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-02-01 13:33:53 +01:00
Felix Walter
fdf8ef5af2 eid: Support processing dtn EIDs without demux having no trailing slash
Previously, we disallowed these EIDs completely, considering them not
valid. Though, this breaks interoperability with ION and seems like an
unnecessary restriction. Local EIDs (the ones uD3TN is initialized with)
still have to contain a trailing slash in any case, the requirements are
just relaxed for processing other EIDs (in the forwarding tables and in
bundle headers).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-28 10:55:38 +01:00
Felix Walter
5ab7ce00d7 bundle7: Fix parsing and serialization of ipn EIDs with large integers
The BPv7 implementation was still using uin32_t for the node and service
numbers in ipn EIDs in several places.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-26 21:05:42 +01:00
Felix Walter
a6d74ce69b aap: Revert EID validation in AAP messages
AAP does not care about the EID format, thus, we do not want to check it
there. Additionally, uD3TN can be easily made independent of EID schemes
for bundle forwarding (source, destination, forwarding table). We should
not add more logic than necessary and make it more inflexible in the
course.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-26 21:05:42 +01:00
Felix Walter
056a5aa005 Use proper node ID for dtn and ipn EIDs in routing
This adds a function for extracting the node ID from dtn as well as ipn
EIDs. The function replaces previous parsing of dtn EIDs in the router.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-26 21:05:42 +01:00
Felix Walter
3b2b9f3cec Use eid.h functions to determine scheme and validity of EID parts
We don't want raw memcmp if we have utility functions.

This further exposes the function to parse and validate ipn EID node and
service numbers to replace error-prone checks for those.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-26 21:05:41 +01:00
Felix Walter
37e39104aa Fix EID validation for dtn and ipn according to BPv7 draft 31
-> https://datatracker.ietf.org/doc/html/draft-ietf-dtn-bpbis-31#section-4.2.5

The previous validation methods were not sufficient to check validity of
dtn as well as ipn EIDs. This adds further functions to easily detect
the EID scheme and validate dtn plus ipn EIDs. Tests for the most common
cases where validity checks should be successful and where they might
fail are added as well.

Due to this change the default EID of uD3TN gets a slash appended, as
dtn EIDs always have to contain the name delimiter '/'.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-26 21:05:41 +01:00
Felix Walter
449d0bc17c Add proper support for the ipn EID scheme
Previously uD3TN implicitly assumed string EID in many places such as
the agent manager. This adds proper handling for ipn-scheme EIDs,
using numerical service numbers as agent IDs in case uD3TN is started
with an ipn-scheme EID. If the ipn scheme is used, uD3TN always has to
be configured with the service number 0. The config and management agent
IDs can be configured in config.h and are 9000 and 9001, respectively,
to keep the lower range of service numbers free. It is intentional that
agents can register with a service number of zero - uD3TN does not
provide specific functionality under this service number.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-26 21:05:41 +01:00
Felix Walter
0625c07cbb
Merge branch 'feature/39-implement-bibe'
See !43
2022-01-26 21:04:34 +01:00
Tobias Nöthlich
e5bdb4f208 Add unit tests covering BIBE parsing / validation
This commit adds unit tests covering the BIBE parser in bibe_proto.c
as well as the BIBE validator in bundle7/reports.c.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2022-01-26 21:04:02 +01:00
Tobias Nöthlich
bef00a0abf Fix BIBE encoder unit test
Due to changing the payload data of SENDBIBE messages from complete ARs
to BPDUs, the BIBE encoder unit test always failed.

This commit fixes this issue by changing the expected header length and
the valid header bytes to reflect the removal of the AR data from the
header.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2022-01-26 21:04:02 +01:00
Tobias Nöthlich
34b7cafe3c Free header data in BIBE encoder unit test
With this commit the bibe_header data gets freed after the test run.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2022-01-26 21:04:02 +01:00
Tobias Nöthlich
e411bfea10 Rename struct header to bibe_header
This commit renames the struct containing the BIBE header to bibe_header
to reduce ambiguousness.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2022-01-26 21:04:02 +01:00
Felix Walter
a976b02a04 Remove custom EID list implementation
The functionality is not used anymore.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-22 14:24:12 +01:00
Felix Walter
26580de896 Remove the hal_time dependencies in bundle6 and bundle7
Based on a contribution by @mnitsch, 351e1dae9.

This removes `hal_*` dependencies in the bundle processing components,
with the goal that these parts can be re-used without depending on the
uD3TN core functions and underlying system state. The required variables
are passed as function arguments from the uD3TN core components.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-22 11:12:32 +01:00
Tobias Nöthlich
fd7a4f7ce6 Add functional and unit tests
This commit adds two tests regarding Bundle-in-Bundle Encapsulation.
The first test starts four µD3TN instances and tests whether sending
and receiving BIBE messages works as expected, whereas the second
test specifically checks the encoding of BIBE messages by the
bibe_proto.c file.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2021-12-15 16:18:07 +01:00