ud3tn/test/unit/bundle7Data.c
Felix Walter 3a9928df93 Make EID a data structure
- A new `struct eid` is introduced, which can represent EIDs in a
  scheme-based  manner; specifically, this means that `ipn` EIDs are
  now represented as tuples of two 64-bit integers and the `dtn` null
  endpoint is now represented as a `NULL` pointer (similar to the CBOR
  representation in RFC 9171).
- We assume that any `struct eid` instance has been validated before,
  e.g. by decoding a string via `eid_from_string`.
- Note that the FIB is still using the (normalized) string format of
  node IDs. It performs a lookup in a hash table anyway and, later, we
  plan to support EID patterns (current IETF draft).
- Changes to parsers and serializers:
  - The BPv7 parser validates EIDs separately from `eid_from_string`.
    This is intentional: No full normalizationis performed for incoming
    bundles; as long as the EID is valid, it is passed through, to
    prevent changes to the immutable (as per RFC9171) primary block.
    This means that, e.g., there are two representations of the null
    endpoint (`dtn:none` and `ipn:0.0`), which are kept as such now.
  - The BPv6 parser and serializer will rewrite the primary block of
    passing bundles -- they do this anyway as the "dictionary" is
    re-constructed by the serializer.
  - Dedicated string representations of the EIDs (`source_str`, etc.)
    are added to the bundle struct on reception (`cla_contact_tx_task`)
    and creation -- this is done for convenience when processing the
    bundle further (especially to still be able to print log messages
    referring to the EIDs in the BP and so on). We may remove it in the
    future to reduce the number of EID-to-string conversions.
- Other changes:
  - Some terminology is cleaned up in the process: e.g., variables
    referring to the local administrative endpoint identifier are
    renamed as such. The previously-used terms "local node ID" or,
    worse, "local EID" are inaccurate -- according to the standards,
    any locally registered singleton EID is a node ID of the local
    bundle node.
  - In some places, log messages are harmonized (e.g. by always using
    quotes around EIDs and no quotes for agent sink IDs). Sometimes,
    EIDs were printed in logs which have been removed now to prevent
    an unnecessary EID-to-string conversion.
  - `aap2_agent`: the manual deallocation of string parts of the AAP2
    message is now replaced by a less fragile `pb_release` in most
    cases.
  - `bundle.h`: `struct endpoint_list` is replaced in BPv6 by a
    `struct eid_list` containing the new `struct eid`; the DFCF
    ("compat") router still uses the old variant with strings
  - `init`: `preprocess_local_eid` is simplified and moved to
    `cmdline.c`. It now uses `eid_from_string`, which tolerates missing
    trailing slashes for `dtn`. Also, we do not support `ipn:x` without
    service number anymore on the command line, as it is an invalid
    format and only makes the coe more complex.

It is recommended to review the changes to `ud3tn/eid.[c|h]` and the
associated unit tests (`test_eid.c`) first, to get an overall idea of
the added and adapted functionality plus the expected behaviors. Before
reviewing the individual changes to all functions dealing with EIDs, it
is also advisable to take a quick look at the other associated
(following) commits.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-02-03 09:22:53 +01:00

170 lines
5.5 KiB
C

// SPDX-License-Identifier: BSD-3-Clause OR Apache-2.0
#include <inttypes.h>
#include <stddef.h>
// -------------------
// Simple BPbis bundle
// -------------------
//
// A CBOR-encoded BPbis bundle with all extension blocks specified in BPbis.
const uint8_t cbor_simple_bundle[] = {
0x9f, // CBOR indefinite array
// Primary block
//
// [
// 7, # Protocol version
// 131076, # Bundle Processing Flags:
// # - REPORT_DELIVERY
// # - MUST_NOT_BE_FRAGMENTED
// 0, # CRC Type (None)
// [1, "GS2"], # Destination EID "dtn://GS2/"
// [2, [243, 350]], # Source EID "ipn:243.350"
// [1, 0], # Report-to EID "dtn:none"
// [658489863000, 0],# DTN Time "2020-11-12T09:51:03", sequence number
// 86400 # Lifetime
// ]
0x88, 0x07, 0x1a, 0x00, 0x02, 0x00, 0x04, 0x00,
0x82, 0x01, 0x66, 0x2f, 0x2f, 0x47, 0x53, 0x32, 0x2f,
0x82, 0x02, 0x82, 0x18, 0xf3, 0x19, 0x01, 0x5e,
0x82, 0x01, 0x00,
0x82, 0x1b, 0x00, 0x00, 0x00, 0x99, 0x51, 0x0d, 0xeb, 0x58, 0x00,
0x1a, 0x00, 0x01, 0x51, 0x80,
// Previous Node Block
//
// [7, 2, 0, 0, cbor_serialize([1, "GS4"])]
0x85, 0x06, 0x02, 0x00, 0x00, 0x46,
0x82, 0x01, 0x63, 0x47, 0x53, 0x34,
// Hop Count Block
//
// [9, 3, 0, 0, cbor_serialize([30, 0])]
0x85, 0x0a, 0x03, 0x00, 0x00, 0x44,
0x82, 0x18, 0x1e, 0x00,
// Bundle Age Block
//
// [8, 4, 0, 0, b"\0"]
0x85, 0x07, 0x04, 0x00, 0x00, 0x41,
0x00,
// Payload Block
//
// [1, 1, 0, 0, b'Hello world!']
0x85, 0x01, 0x01, 0x00, 0x00, 0x4c,
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21,
0xff, // CBOR "STOP"
};
const size_t len_simple_bundle = sizeof(cbor_simple_bundle);
// ------------
// CRC 16 AX.25
// ------------
//
// Bundle with CRC-16 checksum for the primary block
//
// - no bundle processing flags
// - no extension blocks
// - payload block with empty byte string and no block processing flags
//
// CBOR structure:
// [
// [7, 0, 1, [1, "//GS2/"], [1, 0], [1, 0], [0, 0], 86400, b"\xb1\x96"],
// [1, 0, 0, 0, 1, b""]
// ]
const uint8_t cbor_crc16_primary_block[] = {
0x9f, 0x89, 0x07, 0x00, 0x01, 0x82, 0x01, 0x66, 0x2f, 0x2f, 0x47, 0x53, 0x32, 0x2f, 0x82,
0x01, 0x00, 0x82, 0x01, 0x00, 0x82, 0x00, 0x00, 0x1a, 0x00, 0x01, 0x51,
0x80, 0x42, 0xb1, 0x96, 0x85, 0x01, 0x00, 0x00, 0x00, 0x40, 0xff,
};
const size_t len_crc16_primary_block = sizeof(cbor_crc16_primary_block);
// Bundle with CRC-16 checksum for the payload block
//
// - no bundle processing flags
// - no extension blocks
// - payload block with "Hello world" byte string and CRC 16 checksum and no
// block processing flags
//
// CBOR structure:
// [
// [7, 0, 0, [1, "//GS2/"], [1, 0], [1, 0], [0, 0], 86400],
// [1, 0, 0, 1, b"Hello world!", b"\x60\xd7"]
// ]
const uint8_t cbor_crc16_payload_block[] = {
0x9f, 0x88, 0x07, 0x00, 0x00, 0x82, 0x01, 0x66, 0x2f, 0x2f, 0x47, 0x53, 0x32, 0x2f, 0x82,
0x01, 0x00, 0x82, 0x01, 0x00, 0x82, 0x00, 0x00, 0x1a, 0x00, 0x01, 0x51,
0x80, 0x86, 0x01, 0x00, 0x00, 0x01, 0x4c, 0x48, 0x65, 0x6c, 0x6c, 0x6f,
0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x42, 0x60, 0xd7, 0xff,
};
const size_t len_crc16_payload_block = sizeof(cbor_crc16_payload_block);
// ------------------------------
// CRC 32 Castagnoli Verification
// ------------------------------
//
// Bundle with CRC-32-C checksum for the primary block
//
// - no bundle processing flags
// - no extension blocks
// - payload block with empty byte string and no block processing flags
//
// CBOR structure:
// [
// [
// 7, 0, 2, [1, "//GS2/"], [1, 0], [1, 0], [0, 0], 86400,
// b"\xb0\x5c\x7c\x1e"
// ],
// [1, 0, 0, 0, 1, b""]
// ]
const uint8_t cbor_crc32_primary_block[] = {
0x9f, 0x89, 0x07, 0x00, 0x02, 0x82, 0x01, 0x66, 0x2f, 0x2f, 0x47, 0x53, 0x32, 0x2f, 0x82,
0x01, 0x00, 0x82, 0x01, 0x00, 0x82, 0x00, 0x00, 0x1a, 0x00, 0x01, 0x51,
0x80, 0x44, 0xb0, 0x5c, 0x7c, 0x1e, 0x85, 0x01, 0x00, 0x00, 0x00, 0x40,
0xff,
};
const size_t len_crc32_primary_block = sizeof(cbor_crc32_primary_block);
// Bundle with CRC-32 checksum for the payload block
//
// - no bundle processing flags
// - no extension blocks
// - payload block with "Hello world" byte string and CRC 32 checksum and no
// block processing flags
//
// CBOR structure:
// [
// [7, 0, 0, [1, "//GS2/"], [1, 0], [1, 0], [0, 0], 86400],
// [1, 0, 0, 2, b"Hello world!", b"\xc3\xae\xc5\x52"]
// ]
const uint8_t cbor_crc32_payload_block[] = {
0x9f, 0x88, 0x07, 0x00, 0x00, 0x82, 0x01, 0x66, 0x2f, 0x2f, 0x47, 0x53, 0x32, 0x2f, 0x82,
0x01, 0x00, 0x82, 0x01, 0x00, 0x82, 0x00, 0x00, 0x1a, 0x00, 0x01, 0x51,
0x80, 0x86, 0x01, 0x00, 0x00, 0x02, 0x4c, 0x48, 0x65, 0x6c, 0x6c, 0x6f,
0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x44, 0xc3, 0xae, 0xc5, 0x52,
0xff,
};
const size_t len_crc32_payload_block = sizeof(cbor_crc32_payload_block);
// Bundle with invalid CRC-16 X.25 checksum for the primary block
//
// - no bundle processing flags
// - no extension blocks
// - payload block with empty byte string and no block processing flags
//
// CBOR structure:
// [
// [7, 0, 1, [1, "//GS2/"], [1, 0], [1, 0], [0, 0], 86400, b"\x00\x00"],
// [1, 0, 0, 0, b""]
// ]
const uint8_t cbor_invalid_crc16[] = {
0x9f, 0x89, 0x07, 0x00, 0x01, 0x82, 0x01, 0x66, 0x2f, 0x2f, 0x47, 0x53, 0x32, 0x2f, 0x82,
0x01, 0x00, 0x82, 0x01, 0x00, 0x82, 0x00, 0x00, 0x1a, 0x00, 0x01, 0x51,
0x80, 0x42, 0x00, 0x00, 0x85, 0x01, 0x00, 0x00, 0x00, 0x40, 0xff,
};
const size_t len_invalid_crc16 = sizeof(cbor_invalid_crc16);