Commit graph

148 commits

Author SHA1 Message Date
Felix Walter
6525a453ba Adjust all logging calls to include a log level
Rules that have been applied:

- ERROR: Anything that is or may be problematic for the program to
  continue running.
- WARN: Anything abnormal but definitely not critical for program
  continuation, especially issues encountered when interacting with
  clients (e.g. AAP).
- INFO: All state changes not corresponding to the "normal" processing of
  individual data or messages/bundles, as well as further informative and
  helpful messages. Includea errors that occur during normal data
  processing.
- DEBUG: Messages to trace what happens with individual bundles and
  other fine-grained information about internal processes.

At the moment, `LOG_ERRNO` always emits messages with the "ERROR" level.
We might want to change this in the future to better differentiate WARN
and ERROR in this regard also.

Closes: #140
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-24 14:50:25 +01:00
Felix Walter
7b7ff98a2d cmdline, config.mk.example: Make it clear that log level 4 is debug-only
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-16 14:20:04 +01:00
Felix Walter
8dbbb9d692 hal_io: Add LOG(F)_INFO to explicitly log with "INFO" level
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-16 14:20:04 +01:00
Felix Walter
1b1285c126 cmdline: Set default log level for release builds to 2 (WARNING)
This reduced unnecessary clutter by default if we do not want to debug
uD3TN. Should also slightly increase performance by issuing less
`printf` statements.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-16 14:20:04 +01:00
Felix Walter
f02fdc042d hal_io: Protect logging via mutex
This resolves the race condition documented in #139.
The log macros now each call only a single function which locks
a binary semaphore during execution.

Fixes: #139

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-16 14:20:04 +01:00
Felix Walter
485a06b381 AAP, AAP2: Move common socket handling parts to dedicated module
There is some common functionality that should not be copied.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-09 14:33:48 +01:00
Felix Walter
536aee55fd aap2: Check secret for new agent registrations
If there is already an agent registered for the other direction of
communication, registration will fail as long as the provided secrets do
not match.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Felix Walter
144233985a agent_manager: Pass agent as struct
This simplifies the function signatures and enables easy extension
without adapting them in the future.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Felix Walter
4b5a6e2da3 bundle_processor: Pass signal and agent via struct
This prevents the need for passing unset fields as NULL and removes the
need to change the function signature everytime the structs are
extended.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Felix Walter
a0b2fe8909 aap2: Receive response from bundle subscribers
We specify AAP 2.0 to be an RPC protocol whereas the direction of calls
can be switched during configuration. Each call needs to be answered.
This change adds the answer for bundle reception by a client.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Felix Walter
bef31704c5 aap2: Add an AAP2 implementation matching the current AAP feature set
This is a "meta-agent" based on the current AAPv1 implementation
(`application_agent.c`), which runs the new AAP2 protocol that is
implemented via Protobuf (using NanoPB). Please refer to the
corresponding design documents for further information on the protocol
itself.

Beside the on-wire encoding and future extension capabilities, the primary
difference from AAPv1 to AAP2 is that a connection is now a
unidirectional RPC-like channel. This ensures that acknowledgments
cannot be easily get out of order and makes client implementations
simpler. However, it also means that now a shared secret needs to be
passed by clients to enable registering for the same agent ID.

The following limitations of this first implementation are present:
- Only sending and receiving ADUs is supported.
- The shared secret is not checked - any app can register for the same
  agent ID as long as no other app has yet registered for the requested
  direction (subscribe or non-subscribe).
- Only one client per direction is supported at the moment. (It is at
  least planned to support multiplke subscribers for an agent ID.)
- The server does not expect acknowledgments from clients when they
  receive ADUs.
- The keepalive mechanism is not implemented.

In general, this reflects the feature set of AAPv1, but with massive
extension opportunities.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Felix Walter
569bd18e76 bundle: Add creation timestamp to ADU metadata
We would like to propagate timestamp and sequence number to AAP 2
clients.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Felix Walter
78def25108 agent_manager, bundle_processor: Support registering RPC-only agents
This adds a second type of agent registration for agents that do not
receive any bundles or events. It is the first step toward splitting all
agent registrations in two parts, depending on the direction of data
flow. In the future, a shared secret will need to be provided to ensure
that an agent is authorized for a given registered agent ID.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Felix Walter
7afe93447f eid: Add a function to obtain a pointer to the agent ID
All supported EID schemes currently have the "agent ID" (i.e., the `dtn`
demux part or the `ipn` service number) right at the end of the EID.
Thus, we can provide a function to return a pointer to it for quickly
and efficiently working with the agent ID.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Felix Walter
1dd5961bc4 Add AAP 2.0 component stub with Protobuf support via Nanopb
This adds the Nanopb library as submodule under `external/` and adds
corresponding build configuration to the Makefiles. Additionally, a
Protobuf stub for AAP 2.0 is included along with a `make` target to
build the corresponding C language files (`aap2-proto-headers`).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Felix Walter
c75c544a11
Merge branch 'feature/106-config-via-build-system'
See !129
2023-10-27 08:40:16 +02:00
Felix Walter
08b4a1d34f Move definition of _POSIX_C_SOURCE and _DEFAULT_SOURCE to posix.mk
We want to be able to use POSIX extensions such as `strdup` and should
not define this in every individual source file. It is similar to the
definition of which C standard to use and should thus be defined in the
makefiles.

We use the X/Open feature test macro to include all needed functionality
also under other platforms such as BSD.

See also: https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-10-25 15:56:57 +02:00
Felix Walter
c945da6bf6 hal_config.h: Allow for changing AAP and Linux-spefific defs
For two settings previously defined in `hal_config.h` it makes sense to
make them changeable via `config.mk`. The AAP setting is moved to the
appropriate header and the Linux-specific APU define gets a guard so it
can be changed at compile time.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-10-25 15:56:53 +02:00
Felix Walter
26e91ad69e Remove config.h: Move all definitions to individual headers
This moves all definitions from config.h to individual header files and
makes them configurable (i.e., does not define when already defined).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-09-29 14:43:21 +02:00
Felix Walter
ee6288aa4f eid, cmdline: Support local node IDs without slash (dtn) or dot (ipn)
This adds trailing parts to the "local EID" specified on the command line
when required, so the user interface is more tolerant to abbreviated
representations such as 'dtn://node.dtn' and 'ipn:1'.

Closes: #129

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-09-27 17:36:32 +02:00
Felix Walter
9b5d82401f eid: Consider EIDs longer than INT16_MAX-1 invalid
This is a safeguard against potential buffer/int overflows. Realistically,
we should never see such long EIDs.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-09-27 17:24:29 +02:00
Felix Walter
95b8a36fd2 hal_io: Do not reuse macro argument
This may lead to side effects (discovery by the style checker).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-07-28 15:04:50 +02:00
Felix Walter
7330c79b52 style: Spacing, indentation, long lines, continuations
This harmonizes several style issues found by `checkpatch.pl` when using
strict mode.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-07-25 13:15:05 +02:00
Felix Walter
63218344e0 include: Prevent side-effects in macros
Wrap arguments and do not use them multiple times.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-07-25 13:15:05 +02:00
Felix Walter
75987092d2 common: Remove macros to free list
It is better to do that explicitly and the macros were reusing the macro
arguments, which may lead to side effects. We were using this in only
one place which is substituted by an explicit loop to free the list.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-07-25 13:15:05 +02:00
Felix Walter
59b9988587
Merge branch 'feature/add-log-levels'
See !123
2023-07-25 12:07:43 +02:00
Oleksandr Nazymko
bfa565d420 Enable debug log statements in debug build only
This removes the `DEBUG` log statements when compiling with `type=release`
for better performance.

Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
2023-07-14 14:20:11 +02:00
Oleksandr Nazymko
da35fa6e6d Pass log level to init.c and adjust log message format
This adds log level to `ud3tn_cmdline_options` struct so that command line parser passes the value to `init.c` and has no side effects. Also adjusts log message format
for printing out current log level.

Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
2023-07-14 14:09:08 +02:00
Felix Walter
f2fc65c33f
Merge branch 'feature/fuzzer-binary'
See !91
2023-07-14 10:09:47 +02:00
Oleksandr Nazymko
b7bf3ef9a5 Add generic log function
This adds generic log function `LOGF_GENERIC` which accepts logging level as argument. Also adds different log messages for different logging levels.

Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
2023-07-10 11:23:55 +02:00
Oleksandr Nazymko
e0d5ae89a4 Add cli parameter for logging level
This adds cli parameter `-L` which can specify logging level for program.

Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
2023-07-10 11:04:33 +02:00
Felix Walter
99d3cf5ec1 cla_tcp_util: Include sys/socket.h for struct sockaddr
See !115, appears the include was missing.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-06-06 13:01:04 +02:00
Felix Walter
e16ec4c579 Enable building a BPv7 decoder binary
This adds a target `data-decoder` which builds a binary to decode a
specified binary file using uD3TN's parsing logic (based on the CLA RX
subsystem) and print details about it. In this first version only the
decoding of BPv7 bundles is implemented.

This binary can be used, e.g., for fuzz testing.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-16 11:34:14 +02:00
Felix Walter
6880b22b90 hal_semaphore/hal_queue: Accept 64-bit timestamps as delay
Previously the maximum waiting time was just over 24 days. In a DTN
setup we may want to wait longer, e.g., for contacts to occur. This
allows for waiting about 292 years. If the provided delay exceeds this
threshold, an infinite delay is assumed.

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
1e8d86548c hal: Add a hal_semaphore implementation that works on MacOS
Unnamed semaphores are unsupported there, which is why we were seeing
segfaults.

See also: https://stackoverflow.com/a/27847103

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:01:34 +02:00
Felix Walter
f07262b909 Rename fallthrough macro to fallthrough_ok to prevent conflict
There is the compiler attribute `fallthrough` already. This
re-definition makes checking for it using __has_attribute impossible.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:01:34 +02:00
Marius Feldmann
11b0d49796 Validate contact intervals in RoutingTable
So far the contact interval check was done in the
config parser. As this is a semantical and not
syntactical check it is moved to the RoutingTable.

Modified @ 2022-12-21 by Felix Walter to adapt to new state of codebase,
adding the check to `node_prepare_and_verify` in `node.c` instead.

Closes: #47

Signed-off-by: Marius Feldmann <marius.feldmann@d3tn.com>
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-12 10:43:43 +02:00
Felix Walter
00d5d2d050 external, hal: Remove unused crypto (HMAC, SHA2) and JSON functions
This removes all external functions currently unused in uD3TN.
We may re-introduce esp. JSON at a later point in time, but should
include updated libraries anyway.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-12 09:12:30 +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
a46fd3b53b node: Remove unused bundle count field
This was set but never read (anymore).

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
d9bd61fd63 bundle: Add function to get bundle expiration time in milliseconds
This introduces a function to work with milliseconds-based timestamps
also in case of the expiration time.

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
9e08c42ed3 Enable agents to send bundles via direct function invocation
This removes the need to send them via the queue which might result in a
deadlock as described in #115. The bundle processor context is passed as
an opaque pointer that can be used for calling BP functions from agent
callbacks (which run inside the BP thread).

Fixes: #115

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 17:23:55 +02:00
Felix Walter
85f20e8b25 config_agent: Do not send command via BP queue
This may cause a deadlock which we observed sometimes in the routing
integration test in CI as one slot in the BP queue is always needed to
finish processing the Bundle in the BP (that causes `agent_forward` in
this case).

This makes the config agent directly invoke the BP function.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 17:23:55 +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