Mediation¶
Mediation is the platform's single entry point for all CDRs — home and roaming alike. It receives usage files in any supported format, and routes each record to the right rating pipeline:
- Home (non-roaming) usage is normalized to a
billing.CDRwithis_roaming = 0and fed to the CDR loader, which rates it on the home path (price-plan prices, bundle free units, price-plan cutover). - Roaming usage (the operator's own subscribers on visited networks) is normalized with
is_roaming = 1and handed to the Roaming service for rating at the roaming tariff. - A file already in the platform's internal format (a serialized
billing.CDR) is moved as-is into the loader feed — no decode, no re-normalization.
It runs as the independent mediation role of the server binary, alongside the existing modules.
Mediation formalises the upstream "Mediation" producer already referenced by Postpaid Billing: instead of CDR files appearing in the spool by magic, the mediation role is the component that turns heterogeneous vendor exports into the canonical records the rest of the platform consumes.
Roles and Components¶
| Component | Source | Responsibility |
|---|---|---|
MediationDaemon |
usr/src/mediation/mediation_daemon.cpp |
ACE timer handler; polls the ingest directory each tick, on the thread pool. |
| Format registry + descriptors | usr/src/mediation/format_registry.cpp, format_descriptor.cpp |
Configuration-driven format selection + parsing (see Extensibility). |
| Decoders | usr/src/mediation/decoders.cpp |
Generic csv / jsonl / fixed physical decoders. |
| Mapper + transforms | usr/src/mediation/mapper.cpp, transforms.cpp |
Map source columns → the canonical GRUR, applying a closed transform catalog. |
| Validator + normalizer | usr/src/mediation/validator.cpp, normalizer.cpp |
Structural + referential validation, then GRUR → billing.CDR. |
Data flow¶
sequenceDiagram
participant V as Network / partner (file)
participant M as Mediation role
participant H as cdr/new (home feed)
participant Z as roaming spool
participant L as CDR loader
participant R as Roaming role
V->>M: drop usage file in var/spool/mediation/in/
M->>M: select descriptor → (native? move as-is) → decode → map → validate → normalize
alt descriptor kind = home (or native passthrough)
M->>H: write billing.CDR (is_roaming=0) to var/spool/cdr/new/
L->>H: pick up, rate on the home path, insert offline
else descriptor kind = roaming
M->>Z: write billing.CDR (is_roaming=1) to var/spool/roaming/new/
R->>Z: pick up, rate at the roaming tariff, charge subscriber
end
M->>M: archive source to mediation/done/ (or reject/ on failure)
Each accepted record becomes one billing.CDR whose id carries the upstream mediation_id — the same UNIQUE-backed idempotency key the CDR loader uses for dedup (Postpaid Billing). Roaming records additionally carry the resolved visited_plmn_id and is_roaming = 1; home records carry is_roaming = 0 and a plan_id stamped from the resolved subscriber (the rater re-resolves the effective plan by event time for cutover).
Routing: home vs roaming vs native¶
A descriptor's [format] kind selects the pipeline: kind = "roaming" (the default, back-compatible with the GRUR descriptors) routes to the roaming spool; kind = "home" routes to the CDR-loader feed (var/spool/cdr/new). A descriptor with encoding = "native" is a passthrough: the file is already a serialized billing.CDR, so Mediation moves it straight into the loader feed with no parsing. Validation is kind-aware — home records do not require IMSI, currency, or a visited PLMN.
Built-in format (GRUR)¶
The Generic Roaming Usage Record is modeled on GSMA TAP3 (TD.57) semantics — IMSI, MSISDN, visited PLMN, service, chargeable units, charge, currency, sequence number — and ships as the built-in grur_v1 descriptor (CSV) plus grur_v1_jsonl (JSON Lines) under etc/mediation/formats/. The built-in format is itself just a descriptor: there is no privileged, hard-coded parse path.
UNITS is already in the platform's canonical unit per service (seconds for voice, bytes for data, events for SMS/MMS), so the built-in applies no unit transform.
Two more built-ins handle the home path: home_v1 (CSV: MSISDN,SVC,UNITS,EVENT_TS[,SEQ,IMSI], kind = "home") for non-roaming usage, and native_cdr (encoding = "native", *.cdr) for files already in the platform's internal format.
Extensibility — adding a vendor format without recompiling¶
New vendor formats are added by dropping a format descriptor TOML into etc/mediation/formats/ and restarting the role. A descriptor declares an encoding (csv / jsonl / fixed), detection rules (filename glob + header regex), and a field map with transforms drawn from a closed catalog (kb_to_bytes, mb_to_bytes, minutes_to_seconds, iso8601_to_epoch, tadig_to_plmn, svc_name_to_id, scale:<f>, default:<v>, …).
A worked example — a Nokia NWG export with ; delimiters, different column names, MB volumes and millisecond timestamps — is normalized into identical canonical CDRs by writing a nokia_nwg_v1.toml descriptor (mb_to_bytes + scale:0.001 + tadig_to_plmn) and nothing else. The regression suite proves this end to end in usr/share/tests/backend/tests/flow5_mediation/test_f5_03_new_format_no_recompile.py: it adds the descriptor + a sample at runtime and asserts ingestion without touching any compiled artifact.
No core code change
Adding a vendor that uses an already-supported encoding (delimited / columnar / keyed text) is configuration only. A new physical encoding (e.g. ASN.1 BER TAP3, a proprietary binary, XML) requires a new decoder in code, as does a transform primitive outside the catalog or any multi-record correlation — the engine is one-record-in → one-record-out by design.
Error handling¶
Failures are quarantined, never silently dropped:
- File-level (no descriptor matches the filename/header, or the decoder throws) → the source file is moved to
var/spool/mediation/reject/with a.reasonsidecar. - Per-record (a map/transform error, failed referential validation such as an unknown visited PLMN or unknown subscriber) → the record is rejected RAP-style; the source file is archived to
var/spool/mediation/done/with a.rejectsreport listing each failed row and reason. - Duplicates collide downstream on the
mediation_idUNIQUE constraint (the Roaming role routes them tovar/spool/roaming/duplicate/, the CDR loader tovar/spool/cdr/duplicate/), so re-presenting a batch never double-charges.
Configuration¶
See Configuration — mediation.toml carries the [modules] mediation = 1 switch, the [mediation] ingest/done/reject paths, the roaming_new_path output (roaming records), the cdr_new_path output (home + native records → the loader feed), and formats_dir (the descriptor directory). The poll cadence is [app] interval.