Commit graph

42 commits

Author SHA1 Message Date
Felix Walter
42d312d958 Merge branch '15-207-improve-contact-plan-handling-in-bdm' into 'master'
Improve contact plan handling in DFCF BDM and tools

Closes #207, #15, and #238

See merge request d3tn/ud3tn!199
2025-06-06 10:11:05 +02:00
Felix Walter
20eff9058b test/integration: Pin same version of jsonschema as in utils
Otherwise, we may get dependency conflicts, depending on the order in
which we install the modules and requirements file with pip.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-06-06 09:46:32 +02:00
Felix Walter
f657efd1fa test/integration: Use parentheses instead of backslash for continuation
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-06-06 09:01:41 +02:00
Felix Walter
2c4a8b9f71 test/integration: Add a test for bundle status reports
As discussed in #215.

Note: The basis of this code has been AI-generated using Claude Sonnet 4,
but it was reviewed line-by-line and heavily refactored.

Prompts:

- "Create a new integration test in `test/integration` that tests the
  newly-introduced status report feature. The test should send a bundle with
  a set report-to EID, which may be the (local) sender. The created status
  report should then be received and checked that it contains the
  correct data."
- There is an issue in `_wait_for_status_report`: `sub_client.receive_msg`
  can block indefinitely and there is no possibility to specify a timeout.
  However, you could make the test async which allows aborting the receive
  function. There is an async AAP2 client and an example for a test based
  on it in `test_aap2_async_client.py`.
- I updated the test file. Adapt it so it passes the flake8 check which
  gives the following errors: (pasted line-length issues)
- Extend the check of the received status report in the test by parsing it
  as valid BPv7 (RFC 9171) status report. An implementation that can be
  used for serializing status reports can be found in lines 525-566 of
  `pyd3tn/bundle7.py`. The status report is in CBOR format. We use the
  `cbor2` library in the project. The BPv7 spec can be found here:
  https://www.rfc-editor.org/rfc/rfc9171.html#name-bundle-status-reports

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-06-05 17:14:03 +02:00
Felix Walter
229f884a57 python-ud3tn-utils: Introduce JSON configuration format
This introduces a JSON contact configuration format for the
deterministic first-contact forwarding (DFCF) implementation as a modern
alternative to our homebrewn configuration messages. For now, it is only
supported in the external DFCF BDM, but integration into the "router
agent" is planned.

Example JSON configuration string (from our tests):

```
{

    "command": "ADD",
    "node_id": "dtn://ud3tn2.dtn/",
    "cla_addr": "mtcp:127.0.0.1:4223",
    "reachable_eids": [
        "ipn:1.0"
    ],
    "contact_list": [
        {
            "start": 1401519306972,
            "end": 1401519316972,
            "data_rate": 2400,
            "reachable_eids": [
                "dtn://66553/",
                "dtn://89326/"
            ]
        },
        {
            "start": 1401519506972,
            "end": 1401519516972,
            "data_rate": 1200,
            "reachable_eids": [
                "dtn://12349/",
                "dtn://89326/"
            ]
        }
    ]
}
```

Closes: #15

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-06-05 17:03:39 +02:00
Felix Walter
4d39b9ccfa test/integration: Minor comment adjustments
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-06-05 17:03:39 +02:00
Felix Walter
9446988ed3 test/integration: Add contact configuration and query test
This adds a test for the new JSON-based query feature of the BDM. The
test is only enabled in the debug integration test for the external
dispatcher and does not run by default, as it does not specify an AAP
2.0 secret and also does not work with the built-in DFCF forwarding
module.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-06-05 17:03:39 +02:00
Felix Walter
d28545ff5e python-ud3tn-utils: Remove deprecated ManagementCommand
This had been removed from µD3TN for a long time.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-06-05 17:03:39 +02:00
Felix Walter
0107627f76 test/integration: Add a test for the "must not fragment" bit
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-08-30 11:59:13 +02:00
Felix Walter
87be9749af Re-integrate v0.13.0 routing code as "integrated default BDM"
This makes µD3TN behave the same as v0.13.0 when executed without an
additional commandline argument. A new commandline argument `-d` /
`--external-dispatch` is added, which enables the use of external BDMs.
The default forwarding implementation is now again provided using the
v0.13 code, extracted from e1621765a4 and
adapted to the new agent-based forwarding implementation.

Central changes to the old code include:

- A new "Routing Agent" that handles incoming configuration commands,
  FIB updates, and BDM dispatch requests.
- The use of the BDM authorization flag to authorize contact
  configuration commands.
- The Contact Manager now only triggers the creation and removal of
  links / FIB entries; bundle dispatch is triggered through the FIB and
  BDM callback functions of the Routing Agent.
- The fragmentation logic is adapted to store the original bundle along
  with an offset and length value, instead of pre-creating and storing
  the fragments.
- The bundle re-scheduling logic integrated into the Routing Agent is
  simplified and does not support changing the fragmentation parameters.
  A new function is added to the Router that searches for a new route
  for such fragments that were already scheduled at some point,
  considering them as un-fragmentable bundle with overridden fragment
  offset and length.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-07-15 00:46:14 +02:00
Felix Walter
a76c06998f
Merge branch 'feature/aap2-maximum-bundle-size'
See !176
2024-07-05 12:39:11 +02:00
Felix Walter
234787d69f cmdline: Do not launch TCPSPP CLA by default
The main reason here is to not initialize a CLA that has a hard limit on
the maximum bundle size (TCPSPP) by default. TCPSPP is rarely used anyway,
so we can disable it and save some memory in the default configuration.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-07-04 16:01:42 +02:00
Maximilian Nitsch
9902fd072d python: Use cbor2 instead of the deprecated cbor library
Since the last update of the cbor[^1] library was in 2016 and the
repository no longer even exists, the cbor2[^2] python library is now
used instead.

[^1]: https://pypi.org/project/cbor/
[^2]: https://pypi.org/project/cbor2/

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-07-02 17:17:57 +02:00
Felix Walter
b627eb1f24 python: Join nested with statements with comma
Instead of

with a:
    with b:
        ...

we can use:

with a, b:
    ...

This makes the code more compact.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 11:16:07 +02:00
Felix Walter
d54bde72d7 test/integration: Add tests for re-scheduling and fragment forwarding
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 10:36:30 +02:00
Felix Walter
9a91e9f27a test/integration: Relax AAP2 disconnection delay check
There is some variation, leading to random failures otherwise.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 10:36:30 +02:00
Felix Walter
9ecb36a27c test/integration: Remove pseudo-addresses for CLAs without addressing
CLAs such as SMTCP and TCPSPP do not support any addresses, however, we
were providing some identification after the CLA string. This can
confuse BDMs that evaluate the CLA address in FIB updates to properly
schedule bundles. As there is only one link for these CLAs, we use the
same address (only containing the CLA name and a colon) now.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 10:36:30 +02:00
Felix Walter
4f37f8b558 test/integration: Add a test for AAP2 closing on missing keepalive
We tested this, but just for subscriber sockets. RPC sockets should be
closed by uD3TN if a keepalive value is configured and the client sends
nothing for twice the configured time.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 10:36:30 +02:00
Felix Walter
72d3806066 aap2_agent: Switch to simple_queue to enforce clean termination
This enables a clean termination of all agent connections on program
exit without memory leaks that might previously occur due to the "pipe
queue" still holding some data (pointer to allocated memory) when
close() is called on the pipe. For that purpose, the "pipe queue" is
replaced by our standard hal_queue implementation, which also has a
higher performance as it does not require a syscall on every read/write
operation.

As hal_queue does not support poll() (it does not provide a fd), we
cannot check whether the socket has been closed by a subscribing AAP2
client while concurrently waiting for the internal queue. As an
alternative, this implements a liveliness check, which checks the sub.
connection opportunistically from the agent manager: When a new
registration is requested, existing registrations are first
"health-checked" and removed if down, so the new connection can take
over if an old one is down and this was not detected previously.

Based on the new infrastructure, a clean termination routine is
implemented that terminates all tasks transitively by terminating the
listener.

An AAP2 connection handler ("comm task") can terminate in two ways:
1. During runtime, when the connection is closed, it must clean up its own
   resources.
2. On program termination, all connections must be cleanly closed and
   all outstanding mesages handled.

For 1., we keep using detached threads and allow them to release all the
resources. This commit mainly introduces a mechanism for 2.: A list
tracking all comm. tasks is added that can be used to terminate and wait
for all of them on program termination. A "termination flag" indicates
whether tasks should clean up by themselves or the listener task takes
it over. Everything needs to be protected by mutexes for safe
concurrency.

There is specific handling for macOS, which does not signal other
threads clocking on a socket that the socket has been closed when
calling shutdown() but only when calling close() - thus, close() is
executed earlier on macOS. Also, macOS does not unblock poll() when the
socket is close()d, so we do not use it anymore to wait for data on an
RPC connection, but rather set SO_RCVTIMEO for active-client (RPC)
connections to enforce the keepalive timeout.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 10:36:30 +02:00
Felix Walter
62cd97ba2f test/integration: Improve log output of routing test
Show the payload size that was determined.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 10:36:30 +02:00
Felix Walter
7e2e713e97 test/integration: Validate that the correct bundle payload is received
This generates a payload randomly and checks it upon reception so we
ensure we got the correct bundle.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 10:36:30 +02:00
Felix Walter
9c14798997 python-ud3tn-utils: Add asyncio AAP 2.0 client
This adds an asynchronous implementation of the AAP 2.0 client classes
so they can be used with asyncio.

Note that only some functions are concurrency-safe:
If we access the AAP2AsyncClient from multiple places concurrently, the
calls to `send()` and `receive_response()` may overlap. When it is not
intended to use multiple connections, an `asyncio.Lock` together with
functions to send and receive the response directly in sequence now ensure
that this cannot happen. The new `_rpc` functions are provided for that
purpose. Which functions are concurrency-safe is also indicated in the
docstrings.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 10:36:30 +02:00
Felix Walter
271ff4aa4f agent_manager: Extend by FIB and BDM mgmt., simplify, make testable
- Implement management of FIB and BDM agents:
  * add administrative secret which is required for registering FIB and
    BDM agents
  * allow registering reverse-direction agents for TX/RX of ADUs when
    passing the admin secret
  * add cmdline option to pass the admin secret via an env variable
  * make administrative secret optional in debug builds
- Register agents by number, as FIB and BDM agents may not have a sink
  ID. Numbers are allocated by the agent_register function.
- Remove global state, add function to de-allocate everything.
- Add comprehensive unit tests.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-17 13:33:31 +02:00
Felix Walter
65921033b8 test/integration: Add a test for AAPv2 agent behavior
This tests various expectations around the AAPv2 connection handling,
e.g., enforcement of acknowledgments and the keepalive mechanism.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Felix Walter
3f7579932d aap2: Fix delivering bundle metadata to client
This cares for properly delivering the metadata of the created bundle to
the AAPv2 client and adds a test for it.

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
d157e8ae89 test/integration: Add a test for AAP 2.0
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Oleksandr Nazymko
70e752664e Adjust time in integration test
This increases time limit to 100sm at `test_aap_send_receive.py` so that integration test doesn't fail during execution under valgrind which slows down the program.

Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
2023-07-14 10:36:33 +02:00
Felix Walter
fe0404671d test/integration: Apply suggestion to make usage of TCP default socket easier
See https://gitlab.com/d3tn/ud3tn/-/merge_requests/109#note_1389996506

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:42:39 +02:00
Felix Walter
c641197313 test/integration: Also test AAP bundle ID encoding
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:40:47 +02:00
Felix Walter
fd4fe60fe4 test/integration: Add test for aap send/recv with bundle ID check
This is basically an extended `aap_test.py` as part of the integration
tests, which verifies the received AAP messages and also checks the
returned bundle ID if it contains a well-formed timestamp and sequence
number.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:40:47 +02:00
Felix Walter
995f0db342 test/integration: Fix indeterministic failure in bundle age int. test
This adds some tolerance for the bundle age check, such that it does not
have to be within a fractional millisecond bound.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 17:23:27 +02:00
Felix Walter
a42a7dfa26 test/integration: Wait for uD3TN to process node deletion on test end
This ensures the next test's config is not received (via another CLA)
before the deletion has been processed.

Unfortunately, we have no way to determine whether a command has been
processed by uD3TN (there is no operation to query it), so we have to
rely on a simple timeout. This will change with the new forwarding
interface, see the corresponding Milestone.

Fixes: #110

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 15:07:16 +02:00
Felix Walter
e03a362500 test/integration: Fix Python stylecheck complaint
New versions of flake8 complain about a missing space here

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-08-26 09:23:51 +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
68d73cfd2c test & tools: Fixup used EID format
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-26 21:05:42 +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
Maximilian Nitsch
f9006c3bad Add bundle age integration test
In order to verify the correctness of bundle-age block processing, an
integration test between pyd3tn and ud3tn is added.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2021-07-22 16:33:55 +02:00
Maximilian Nitsch
45bbccebb6 Prepare PyPi packages
To distribute the pyD3TN DTN protocol implementations as well as the
uD3TN python utilities on PyPi, the Python code is organized in separate
directories and the PyPi packaging guideline is applied. The
restructuring also requires an adjustment of the imports in the scripts
in tools/ and test/.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2020-11-19 12:38:39 +01:00
Felix Walter
bc271aa444 Rename binary, main component, and config defaults "ud3tn"
This changes the core component name as well as the output binary names
(including the library and test binaries) from "upcn" to "ud3tn".
Additionally, the default configuration for the created socket and the
used EID is adapted.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2020-11-17 15:51:10 +01:00
Felix Walter
0ce4bee910
Initial import of uPCN v0.8.0 source code
This is the initial commit for uD3TN. uD3TN is a fork of uPCN v0.8.0,
which will be developed and maintained in a public Git repository.

For questions concerning the history of and code provided with uPCN,
please get in touch with us via: contact <at> d3tn <dot> com

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2020-11-14 11:56:40 +01:00