Commit graph

62 commits

Author SHA1 Message Date
Felix Walter
03aaf723c4 application_agent: Conditionally enable _DARWIN_C_SOURCE on Apple
We use `MSG_DONTWAIT` in the app. agent, see #126.

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
2eeea30285 Remove str(n)cpy from codebase
This function is dangerous: if the resulting string is longer than the
buffer, no null-termination is added to it. Also, it always fills the
remaining buffer length with zeroes.
snprintf is fast and can always be used as replacement (and sometimes
there are better substitutes).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-12 09:11:11 +02:00
Felix Walter
fcd0fbe49c
application_agent: Fix usage of wrong variable name
Commit b07a653389 was not properly
rebased, so it still used the old variable name `time`, not `time_ms`
that was introduced in 3cd89eb6a5.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-12 08:44:22 +02:00
Felix Walter
ce7900c93f
Merge branch 'feature/60-return-creation-timestamp'
See !90
2023-05-12 08:28:14 +02:00
Felix Walter
b07a653389 AAP: Return bundle creation timestamp and sequence number in bundle ID
See the added description in the AAP documentation - this adds an
internal format to the 64 bit integer value returned as "bundle ID" in
the `SENDCONFIRM` AAP message to uniquely identify the created bundle in
conformance to RFC 9171.

Closes: #60

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-11 17:03:29 +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
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
Felix Walter
e8b20fa236 application_agent: Guard task field with semaphore
The `task` field in the communication task config was set by the main
task _after_ the creation of the comm. task. This may lead to
synchronization issues as the comm. task needs to access the field to
de-allocate it upon termination.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 17:23:55 +02:00
Felix Walter
b335f6c655 application_agent: Use the proper function to delete the thread handle
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 15:37:02 +02:00
Felix Walter
65d7582a88 Provide LOGERROR() macro for errno logging and remove strerror
`strerror()` is not thread-safe, thus, we have to use an alternative. If
we want to prevent allocating a temporary buffer (e.g., for
`strerror_r`), we need to use `perror()`. To allow writing stored
`errno` values, the function sets `errno` from an argument passed to it,
which should be safe according to the manual.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 15:37:02 +02:00
Felix Walter
ed7dc86cba config_parser: Do not print buffer on error
It might not be properly null-terminated.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 15:07:16 +02:00
Felix Walter
93239cbebe application_agent: Prevent leak of task and task config
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 14:37:11 +02:00
Felix Walter
ac362f2ba8 application_agent: Prevent memleak by properly deallocating parser
Found by ASAN.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 14:37:11 +02:00
Felix Walter
2b3a76c409 cla_bibe: Fix out-of-bound write
The BIBE CLA allocated a buffer the size of sizeof(struct aap_message)
but then serialized an AAP message into it. It should have used
aap_get_serialized_size(), though, this change directly removes the
unnecessary buffer in between and directly writes out the data.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 11:10:24 +02:00
Felix Walter
94257ff4de application_agent: Fix potential use-after-free on task creation failure
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 11:10:24 +02: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
f8395e8d94 router: Remove probabilities and struct routed_bundle
The probability-based routing was never used productively. It implied
that we store all the contacts for which a bundle was scheduled (as
there may be more than one) and keep it, doing reference counting before
we drop the data structure, and so on. This change removes everything
probability-related. The field in the config commands is kept to ensure
backwards compatibility if this is specified.

The removal of struct routed_bundle allows for a major simplification of
all routing-related code.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 20:59:43 +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
6c5f0eda2e Fix type conversion errors on 32-bit ARM platforms
Use the proper types for conversion of ssize_t and the bundle pointer so
we ensure that there are no issues with their range.

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
0b274560b1
Merge remote-tracking branch 'origin/feature/echo-agent'
See !61
2022-08-26 12:42:24 +02:00
Felix Walter
be59cc30eb agents: Implement echo functionality as agent in uD3TN
This implements what we have as aap_echo.py tool in an agent that runs
within uD3TN itself. This makes it easier to check availability of uD3TN
also if the runtime environment does not provide a Python implementation.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-08-26 09:30:43 +02:00
Felix Walter
f47ec21618 application_agent: Add missing header
We use HAL time functions but did only include this header transitively.
This makes it explicit.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-08-26 09:29:55 +02:00
Felix Walter
0d04a6ff2f agents: Move bundle creation functions to utility module
This moves the functions to create bundles from within agents from the
application agent to a dedicated utility module, ready to be re-used by
other agents.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-08-26 09:29:36 +02:00
Felix Walter
cb321024df management_agent: Pass correct param variable
We adapted this to also provide the `allow_remote_configuration` flag,
but did not adapt the variable that is passed.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-08-25 09:54:31 +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
5577463693 config_parser: Canonicalize configured node IDs
Our current router implementation searches for the EID returned by
get_node_id(destination). This might differ, e.g., by a slash added
at the end of a `dtn` scheme EID. Thus, we want to ensure that this
value is added to the routing table if we can determine it.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-02-01 13:22:05 +01:00
Felix Walter
89bcbdf4be agents: Perform "local EID" check on node ID of bundle source
This matches bundles with ipn source EIDs properly against the local
node ID by retrieving the node ID first.

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
Felix Walter
ce023993f5 application_agent: Combine SENDBUNDLE and SENDBIBE handling
This removes some code duplication in handling the two types of AAP
messages by performing the additional processing for BIBE BPDUs
optionally before proceeding to process the bundle ADU.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-26 21:04:02 +01:00
Felix Walter
ae8c6c9d11 AAP: Minor formatting adaptations
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-26 21:04:02 +01:00
Tobias Nöthlich
cfb3ed526c Move BIBE AR creation from bibe_proto to AppAgent
In order to have SENDBIBE and RECVBIBE messages have the same kind of
payload data (BPDUs) the creation of the administrative record needed
for BIBE bundles was moved from the bibe_proto.c file to the application
agent.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2022-01-26 21:04:02 +01:00
Tobias Nöthlich
c1645cde91 Modify BIBE log messages in application_agent.c
Log messages pertaining to BIBE bundles are now clearly labeling
these bundles as BIBE bundles.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2022-01-26 21:04:02 +01:00
Felix Walter
cf93a41d8f application_agent: Consistently prefix log messages with "AppAgent:"
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-22 14:26:29 +01:00
Felix Walter
4f93b699c6 management_agent: Fix language in log output
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-22 14:24:12 +01:00
Tobias Nöthlich
aceae42cdc Add BIBE interoperability test with ION
This commit adds an automated interoperability test between µD3TN and
ION. In this test a BIBE bundle is sent to a µD3TN BIBE node which
processes and forwards the encapsulated bundle to an ION instance.
This ION instance discards the encapsulating bundle, encapsulates the
inner bundle again and forwards it to a second µD3TN BIBE node, on which
the receiving bundlesink is running.

This commit also adds "-" to the characters permitted in the CLA string
used to inform the BIBE CLA which node the encapsulating bundle should
be addressed to. This is necessary, as ION uses the "hostname" command
when establishing the administrative endpoint of a node thus creating
an endpoint using the hostname of the machine the node's running on as
EID. This hostname could naturally contain a dash.

Before running the test pyd3tn/bundle7.py has to be modified, as ION uses
administrative record type code 7 to identify BIBE bundles, whereas µD3TN
uses the more recently specified type code 3. In order for the test to
work, the RecordType BIBE_PROTOCOL_DATA_UNIT on line 83 in bundle7.py has
thus to be changed to 7 instead of 3.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2021-12-20 16:50:37 +01:00
Tobias Nöthlich
c82008a2b8 Add serialize_pl switch to aap_serializer
In case of a SENDBIBE message generated by the BIBE CLA, the payload
must not be serialized when the rest of the message is serialized.

To make this possible, the serialize_pl parameter was added to the
aap_serializer. If serialize_pl is false, the serializer will skip the
payload and just serialize the rest of the AAP message.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2021-11-29 11:41:40 +01:00
Tobias Nöthlich
7b96c05dcb Modify config_parser to work with BIBE CLA address
Due to adding the next hop EID directly to the CLA address passed
to the BIBE CLA, the config_parser needs to work with the symbols
'#' and '/'.

This commit adds support for these symbols to the config_parser.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2021-11-29 11:21:45 +01:00
Felix Walter
3ab90dcffb Make the remote configuration capability a command line flag
Previously, we had a build-time flag for enabling configuration via
bundles received from other nodes. Thus, changing the flag required a
re-build. As we are depending on it also for our integration tests and
it is often handy in further setups, this change makes it a command
line argument "--allow-remote-config".

As the STM32 platform does not support command line arguments, remote
configuration is enabled by default there via config.h.

See also: !13, #32

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2021-11-11 23:00:09 +01:00