|
libe3 0.6.1
C++ library for E3AP RAN vendor integration
|
For an engineer adding E2SM-DAPP to a RAN stack. OCUDU did it. OAI has it through its flexric submodule. A future stack may follow. This guide is about the codec and about proving that your stack produces and accepts the same bytes as the others. It is not part of the specification: the specification is the six numbered files in README.md. The code pointers, repository roots and the named per-implementation evidence for every chapter are in code-pointers.md.
What you do not need: the real E3 link and the Spectrum service-model codec. They are out of scope of the E2SM-DAPP codec. The codec packs and unpacks E2SM-DAPP elements and nothing else; the payloads inside (data, e3-control-outcome) are opaque octets to it.
| Route | You get | You need | Pick it when |
|---|---|---|---|
| A. Link libe3's codec | C++ and C APIs, already tested against the golden vectors | libe3 built with LIBE3_ENABLE_E2SM_DAPP (needs LIBE3_ENABLE_ASN1), and the asn1c fork it builds with | your stack can link a C++17 library, or call C |
| B. Generate your own asn1c code from the grammar | the asn1c C structs, nothing else | the grammar file and the pinned asn1c | you want only the ASN.1 layer and will write the glue yourself |
| C. Write a codec by hand (what OCUDU did) | full control, no asn1c | a bit-level APER library | your stack already has one and forbids a second ASN.1 runtime |
Whichever you choose, the golden vectors are the acceptance test (below).
LIBE3_ENABLE_E2SM_DAPP is ON by default and is forced OFF when LIBE3_ENABLE_ASN1 is OFF (cmake/libe3Options.cmake:26-30). The codec does not need the E3 agent, ZeroMQ or the E3AP grammar: it has its own private copy of the asn1c runtime, with the runtime symbols hidden, so it can sit next to another asn1c in the same process (messages/CMakeLists.txt:74-105).
libe3::e2sm_dapp (static) and libe3::e2sm_dapp_shared are the two targets. The component is "found" exactly when the install was built with the codec; without it, find_package(... REQUIRED COMPONENTS e2sm_dapp) fails with a message that says how to rebuild (cmake/libe3Config.cmake.in:30-50). The compile definition LIBE3_ENABLE_E2SM_DAPP comes with the target.
pkg-config: pkg-config --cflags --libs libe3_e2sm_dapp, and pkg-config --variable=asndir libe3_e2sm_dapp for the grammar directory (cmake/libe3_e2sm_dapp.pc.in). The out-of-tree consumer checks in tests/consume/ (e2sm_dapp.cpp, e2sm_dapp_c.c) show both routes against an install prefix.
The choice getters throw std::bad_variant_access when the other alternative is held. For the two-format elements (indication header and message) test type() first:
Leave e3_ctrl_outcome_present false for an acknowledge with nothing to say.
The C API is in <libe3/e2sm_dapp_c.h>. Every optional field has an explicit has_* flag, and 0 is a normal value.
Ownership rules (include/libe3/e2sm_dapp_c.h:10-20): inputs to encode_* stay yours. encode_* allocates out->data; release it with libe3_e2sm_dapp_bytes_free (plain free also works). decode_* allocates everything inside *out; release with the matching libe3_e2sm_dapp_free_*. On failure *out is zeroed and needs no freeing, and every free function zeroes its argument, so freeing twice is harmless. Errors are E3_INVALID_PARAM, E3_ENCODE_FAILED, E3_DECODE_FAILED and E3_SM_ERROR_MEMORY. Unlike flexric's C IR, nothing aborts.
The grammar is messages/asn1/e2sm_dapp/V1/e2sm_dapp-1.0.0.asn in the libe3 source, and share/libe3/e2sm_dapp/e2sm_dapp-1.0.0.asn in an install (cmake/libe3Install.cmake:160-161). It is a byte-identical copy of flexric's src/sm/dapp_sm/ie/asn/e2sm_dapp_v0_standard.asn. Do not edit it.
libe3 builds with the fork mouse07410/asn1c, pinned to commit e4ee5e4832b51e6284f0a8ebf6e78dd7260e1dfb (v1.5.3-124; function install_asn1c_from_source in build_libe3), installed under /opt/libe3/asn1c so that it does not replace an asn1c another project keeps in /opt/asn1c:
(build_libe3 does this for you when the pinned commit is not installed.) A different asn1c can produce a different APER encoding for the same grammar, in particular for extension handling and unconstrained integers. Check against the golden vectors if you use another. libe3's configure accepts asn1c from 1.5.1-44, warns below 1.5.3-124 and refuses anything older, which includes the asn1c of apt (0.9.29) and the commit libe3 pinned before (940dd5fa, which also prints v0.9.29): a developer who still has it in /opt/asn1c gets that error and has to run ./build_libe3 -I.
From libe3_asn1c_generate in cmake/libe3Asn1c.cmake:
flexric uses a slightly different line, with -no-gen-UPER and without -pdu=all (src/sm/dapp_sm/ie/asn/CMakeLists.txt). The APER rules are the same; confirm with the golden vectors.
libe3 passes -gen-JER instead of -no-gen-JER when it is built with JSON, which is the default of build_libe3, so that the codec and libe3's own runtime have one layout when both are linked statically into one executable. flexric's line has -no-gen-JER. The layout of the type descriptors depends on it, and the runtime symbols of two static archives merge, so a program that links the static codec next to flexric's own runtime has to use libe3::e2sm_dapp_shared, or libe3 has to be built with --disable-json.
Compile the generated *.c files and the asn1c runtime it emits (libe3 takes the files asn1c wrote; which files that is depends on the asn1c version) with -DASN_DISABLE_OER_SUPPORT. libe3 also compiles them -w and with hidden symbol visibility, so the runtime does not clash with another asn1c in the process. Encode with ATS_ALIGNED_BASIC_PER and decode with aper_decode.
Pitfalls when you call asn1c directly (all seen in flexric's code, see interop.md):
OCUDU writes the structs in the style of its other E2SM headers (ocudu/include/ocudu/asn1/e2sm/e2sm_dapp.h) and implements pack and unpack on its bit_ref and cbit_ref (ocudu/lib/asn1/e2sm/e2sm_dapp.cpp). Things it had to handle by hand, which any hand-written codec must:
libe3's include/libe3/e2sm_dapp.hpp deliberately copies OCUDU's asn1::e2sm_dapp: same type names, same field names, so a message-building function reads the same in both. The differences are small and mechanical.
| Item | OCUDU (asn1::e2sm_dapp) | libe3 (libe3::e2sm_dapp) |
|---|---|---|
| Namespace | asn1::e2sm_dapp | libe3::e2sm_dapp |
| Struct and field names | the same | the same |
| Constants | max_e2sm_dapp_ind_msg_size, maxnoof_dapps, ... (int64_t) | the same names (int64_t) |
| pack | on every struct: OCUDUASN_CODE pack(bit_ref&) const | only on the eight top-level types: asn_code pack(std::vector<uint8_t>&) const |
| unpack | OCUDUASN_CODE unpack(cbit_ref&) | asn_code unpack(const uint8_t* data, size_t len) |
| Result type | OCUDUASN_CODE: OCUDUASN_SUCCESS, OCUDUASN_ERROR_DECODE_FAIL, OCUDUASN_ERROR_ENCODE_FAIL | asn_code with the same values: ASN_SUCCESS (0), ASN_ERROR_DECODE_FAIL (-1), ASN_ERROR_ENCODE_FAIL (-2) |
| Top-level types | no distinction: every struct has pack and unpack. The eight below are the ones whose bytes go into an E2AP field | e2sm_dapp_event_trigger_s, e2sm_dapp_action_definition_s, e2sm_dapp_ind_hdr_s, e2sm_dapp_ind_msg_s, e2sm_dapp_ctrl_hdr_s, e2sm_dapp_ctrl_msg_s, e2sm_dapp_ctrl_outcome_s, e2sm_dapp_ran_function_definition_s |
| Octet-string helper | OCUDU's bounded_octstring, fixed_octstring, unbounded_octstring | thin wrappers: bounded_octstring is a std::vector<uint8_t>, fixed_octstring<N> a std::array<uint8_t, N>, unbounded_octstring a vector with from_bytes(ptr, len) (OCUDU's from_bytes takes a span) |
| String helper | printable_string<LB, UB, Ext, Aligned> | the same template over std::string, with from_string and to_string |
| Lists | dyn_array, bounded_array | the same names, deriving from std::vector |
| to_json | on every struct | not provided |
| operator== | not provided | provided on every type (the ext member is never compared; an absent optional field compares equal whatever its value) |
| Choice getters | assert_choice_type: a wrong alternative is an assertion | std::get: a wrong alternative throws std::bad_variant_access |
| Choice setters | set_ind_hdr_format1() and the like | the same |
| ext member | present; pack fails when it is true | present; ignored by pack, always written 0 |
A function written for one compiles for the other if it avoids to_json, the getters on an unchecked choice, and pack of a non-top-level struct. The shared test fixtures rely on exactly that.
tests/e2sm_dapp_golden.hpp holds the APER bytes of 31 inputs (04-encoding.md), generated by flexric's own encoder at the flexric commit named in the file. It is generated; do not edit it by hand. libe3 and OCUDU each carry the same table (ocudu/tests/unittests/e2/e2sm_dapp_golden.h). If your stack reproduces every vector and decodes every vector to an equal value, it is byte-compatible with flexric, libe3 and OCUDU.
The inputs are not described by hand in each repository. Each stack builds them through the same code:
| Macro | Meaning |
|---|---|
| E2SM_DAPP_NS | the namespace that holds the types |
| E2SM_DAPP_SET_STRING(dst, "text") | assign a PrintableString |
| E2SM_DAPP_SET_OCTETS(dst, ptr, n) | assign an unbounded OCTET STRING |
To add E2SM-DAPP to a new stack, copy e2sm_dapp_fixtures.inc and e2sm_dapp_golden.hpp, define the three macros, and write the two loops. If your stack's types differ from the shared names, add thin adapters. Do not change the fixtures.
What it does (header comment of regen.sh and tools/e2sm_dapp_golden/README.md): copies the parts of flexric's dapp_sm the codec needs into a scratch directory, deletes four unused includes (enc_cell_global_id.h, enc_ue_id.h, dec_ue_id.h, dec_cell_global_id.h) that pull in other service models, regenerates the asn1c code from flexric's grammar, compiles gen_golden.c against flexric's real dapp_enc_*_asn() and dapp_dec_*_asn(), runs it (it also checks flexric's decoder returns every input), and turns the GOLDEN and GOLDEN_HASH lines into the header with gen_header.py.
To check the committed header is reproducible: