Skip to main content

Crate mediation

Crate mediation 

Source
Expand description

Telecom usage mediation domain library.

A pure library for the arithmetic and classification between a mobile or fixed network and a billing system: normalising, validating, deduplicating and correlating usage records. Zero I/O, no async, no clock, exact integer quantities. It computes usage, not money: octets, seconds and event counts, attributed to a charged party, a network and a service.

Long-form documentation: https://hupe1980.github.io/mediation. Every example there is compiled by this crate’s test suite.

§Modules

ModuleContents
errorParseError and DecodeError — one per input kind, string and bytes
digitsDigitString — inline digits, plus the TBCD and plain-BCD codecs
berBerReader, BerElement, BerTag — the X.690 framing a CDR arrives in
cdrtimeCdrTimestamp, QuarterHourOffset, DstAdjustment, MsTimeZone, Seconds
volumeOctets, VolumePair, ByteScale — integer data volumes
plmnMcc, Mnc, PlmnId, TadigCode — network identity, and its three-octet wire form
dialplanDialContext, Destination, DestinationClass, NumberingPlan — dial string to E.164 destination
identityImsi, Msisdn, Imei, Imeisv, Iccid, Supi, Gpsi, Pei, Suci, Nai, AddressString
jurisdictionusage_country(), customer_country_presumption() — two questions, two countries
locationUserLocation, Uli, Cgi, Sai, Rai, Lai, Ecgi, Ncgi, Tai — where a record was produced
numberingNumberRange, NumberRangeSet, Porting, terminating_plmn — who really terminates a number
partyChargedParty, SubscriberRef, TenantRef — who the usage is charged to
correlationCorrelationKeys, ChargingId, Icid, CallId, correlate(), CorrelatedGroup, LegChain
containerServiceDataContainer, ContainerSet, RatingGroup, ChangeCondition
partialPartialInfo, PartialRun, Reassembly, RecordClosureCause
pipelineprocess(), Batch, ProcessState, ProcessOutcome — the whole layer, in one pass
sessionDnn, Snssai, RatType, ChargingCharacteristics — the network, slice, access and charging profile a session ran on
timebandsplit_session(), split_measured(), apportion() — dividing usage at a tariff boundary
recordUsageRecord, RecordType, ServiceDomain, SourceRef
latenessLatenessPolicy, Lateness — one concept behind every window
sequenceSequenceSpace, SequenceValue, SequenceTracker, SequenceSnapshot — wrap-aware gap detection
dedupRecordKey, DedupStore, DedupWindow — natural-key deduplication
dispositionDisposition, Outcome, BatchReconciliation, PeriodLedger — the conservation law
validationvalidate_records(), Rule (V01–V21), Finding, Severity
restatementRestatement, UsageDelta, RestatementLog — corrections as signed events
qualityscore_batch(), QualityGrade, ReleaseBlocker — the release gate
aggregationaggregate_released(), UsageTotal — what the batch adds up to
roamingTapBatch, BatchTotals, ScaledAmount, RapReturn — a partner’s batch, and whether it adds up
fairuseassess(), FairUseAssessment, FairUseAlert, VolumeAllowance — EU 2016/2286
retentionRetentionPolicy, RetentionSchedule, Deletion — how long a record may be kept
fraudSignal, Indication, impossible_travel() — evidence, never verdicts
privacyPseudonymiser, Reduction, itemise_called() — narrowing an identity to the question

§Time is local, not UTC

A charging record carries a local wall-clock time and a quarter-hour offset (3GPP TS 32.298). Read as UTC, an evening event lands on the wrong day, and no constant corrects it because the offset varies per record.

use mediation::CdrTimestamp;

let ts: CdrTimestamp = "2026-07-28T00:30:00+05:45".parse().unwrap();
assert_eq!(ts.local_date().to_string(), "2026-07-28");    // the subscriber's day
assert_eq!(ts.to_utc().date().to_string(), "2026-07-27"); // is not the UTC day

§Integer quantities

Octets is a u64 and Seconds a u32; no quantity passes through a float, which stops representing consecutive integers above 2^53 octets. VolumePair keeps uplink and downlink apart. Rounding to chargeable units (Octets::units_ceil, Seconds::units_ceil) is a rating decision, offered and applied by nothing.

§Determinism

No function reads the clock, the filesystem, the network or other ambient state. An evaluation instant is a parameter, so an archived batch replays to the verdicts it originally got.

§Every record reaches exactly one outcome

carried_in + ingested == billable + suppressed + duplicate + rejected + held

BatchReconciliation::balances is that equation, and PeriodLedger chains batches so it holds across a billing period. See disposition.

§Every input is untrusted

Every FromStr and wire decoder returns a Result for arbitrary input and never panics. Anything sized by the input is bounded (SequenceTracker::observe, PartialRun::assess, BerReader nesting depth) while counts stay exact, and no field is silently skipped.

Re-exports§

pub use aggregation::AggregationError;
pub use aggregation::ReleasedTotals;
pub use aggregation::UsageTotal;
pub use aggregation::aggregate;
pub use aggregation::aggregate_by;
pub use aggregation::aggregate_rating_groups;
pub use aggregation::aggregate_released;
pub use aggregation::aggregate_released_with_carry;
pub use ber::BerElement;
pub use ber::BerLength;
pub use ber::BerReader;
pub use ber::BerTag;
pub use ber::TagClass;
pub use cdrtime::CdrTimestamp;
pub use cdrtime::Century;
pub use cdrtime::DstAdjustment;
pub use cdrtime::MsTimeZone;
pub use cdrtime::QuarterHourOffset;
pub use cdrtime::Seconds;
pub use container::ChangeCondition;
pub use container::ContainerSet;
pub use container::Qos5qi;
pub use container::RatingGroup;
pub use container::ServiceDataContainer;
pub use correlation::BrokenLeg;
pub use correlation::CallId;
pub use correlation::ChargingId;
pub use correlation::CorrelatedGroup;
pub use correlation::CorrelationConfig;
pub use correlation::CorrelationKey;
pub use correlation::CorrelationKeys;
pub use correlation::CorrelationResult;
pub use correlation::Icid;
pub use correlation::LegChain;
pub use correlation::PacketSessionId;
pub use correlation::Unmatched;
pub use correlation::UnmatchedReason;
pub use correlation::correlate;
pub use dedup::DedupDecision;
pub use dedup::DedupStore;
pub use dedup::DedupWindow;
pub use dedup::NotKeyable;
pub use dedup::RecordKey;
pub use dialplan::AreaCode;
pub use dialplan::Destination;
pub use dialplan::DestinationClass;
pub use dialplan::DialContext;
pub use dialplan::DialContextError;
pub use dialplan::DialError;
pub use dialplan::GermanNumberingPlan;
pub use dialplan::NumberingPlan;
pub use dialplan::ShortCode;
pub use dialplan::ShortCodePattern;
pub use digits::DigitString;
pub use disposition::BatchReconciliation;
pub use disposition::ChainBreak;
pub use disposition::Disposition;
pub use disposition::HoldReason;
pub use disposition::Outcome;
pub use disposition::PeriodLedger;
pub use disposition::PeriodTotals;
pub use disposition::RejectReason;
pub use disposition::SuppressReason;
pub use error::DecodeError;
pub use error::ParseError;
pub use fairuse::AllowanceStatus;
pub use fairuse::FairUseAlert;
pub use fairuse::FairUseAssessment;
pub use fairuse::ObservationWindow;
pub use fairuse::PresenceDay;
pub use fairuse::Region;
pub use fairuse::Regions;
pub use fairuse::SafeHarbour;
pub use fairuse::VolumeAllowance;
pub use fraud::Indication;
pub use fraud::Signal;
pub use fraud::TrafficShape;
pub use fraud::TransitTimes;
pub use fraud::UniformTransit;
pub use fraud::ait_signature;
pub use fraud::bypass_signature;
pub use fraud::impossible_travel;
pub use fraud::premium_destination;
pub use fraud::wangiri_pattern;
pub use identity::AddressString;
pub use identity::Gpsi;
pub use identity::Iccid;
pub use identity::Imei;
pub use identity::Imeisv;
pub use identity::Imsi;
pub use identity::Msin;
pub use identity::Msisdn;
pub use identity::Nai;
pub use identity::NatureOfAddress;
pub use identity::NumberingPlanIndicator;
pub use identity::Pei;
pub use identity::RoutingIndicator;
pub use identity::Suci;
pub use identity::Supi;
pub use identity::Tac;
pub use jurisdiction::Ambiguity;
pub use jurisdiction::Jurisdiction;
pub use jurisdiction::customer_country_presumption;
pub use jurisdiction::is_abroad;
pub use jurisdiction::usage_country;
pub use lateness::Lateness;
pub use lateness::LatenessPolicy;
pub use location::CellId;
pub use location::Cgi;
pub use location::Ecgi;
pub use location::Eci;
pub use location::EnbKind;
pub use location::ExtendedEnbKind;
pub use location::ExtendedMacroEnbId;
pub use location::GnbIdLength;
pub use location::Lac;
pub use location::Lai;
pub use location::MacroEnbId;
pub use location::Ncgi;
pub use location::Nci;
pub use location::Rai;
pub use location::RoutingAreaCode;
pub use location::Sai;
pub use location::ServiceAreaCode;
pub use location::TacWidth;
pub use location::Tai;
pub use location::TrackingAreaCode;
pub use location::Uli;
pub use location::UserLocation;
pub use numbering::NumberRange;
pub use numbering::NumberRangeSet;
pub use numbering::Porting;
pub use numbering::is_ported;
pub use numbering::terminating_plmn;
pub use partial::OrphanReason;
pub use partial::PartialFormat;
pub use partial::PartialInfo;
pub use partial::PartialRun;
pub use partial::Reassembly;
pub use partial::RecordClosureCause;
pub use party::ChargedParty;
pub use party::NfInstanceId;
pub use party::PartyId;
pub use party::SubscriberRef;
pub use party::TenantRef;
pub use party::UnattributableReason;
pub use pipeline::Batch;
pub use pipeline::NoSuppression;
pub use pipeline::ProcessConfig;
pub use pipeline::ProcessOutcome;
pub use pipeline::ProcessState;
pub use pipeline::SequenceGap;
pub use pipeline::Suppression;
pub use pipeline::process;
pub use pipeline::process_with;
pub use plmn::Mcc;
pub use plmn::Mnc;
pub use plmn::MncWidth;
pub use plmn::MncWidths;
pub use plmn::NorthAmericanRule;
pub use plmn::PlmnId;
pub use plmn::TadigCode;
pub use privacy::Itemisation;
pub use privacy::ItemisedDestination;
pub use privacy::NumberPrefix;
pub use privacy::ProtectedDestinations;
pub use privacy::Pseudonym;
pub use privacy::Pseudonymiser;
pub use privacy::ReducedSubscriber;
pub use privacy::Reduction;
pub use privacy::ShortenedNumber;
pub use privacy::itemise_called;
pub use privacy::itemise_calling;
pub use privacy::reduce_equipment;
pub use privacy::reduce_to_country;
pub use privacy::reduce_to_network;
pub use privacy::software_version;
pub use quality::QualityGrade;
pub use quality::QualityReport;
pub use quality::ReleaseBlocker;
pub use quality::score_batch;
pub use quality::score_dispositions;
pub use record::CallDirection;
pub use record::NodeId;
pub use record::PrimaryMeasure;
pub use record::RecordType;
pub use record::ServiceDomain;
pub use record::SourceRef;
pub use record::UsageRecord;
pub use restatement::RestateReason;
pub use restatement::Restatement;
pub use restatement::RestatementLog;
pub use restatement::UsageDelta;
pub use retention::Deletion;
pub use retention::RetentionBasis;
pub use retention::RetentionPolicy;
pub use retention::RetentionSchedule;
pub use roaming::BatchDiscrepancy;
pub use roaming::BatchTotals;
pub use roaming::RapReturn;
pub use roaming::ScaledAmount;
pub use roaming::TapBatch;
pub use roaming::TotalKind;
pub use sequence::SequenceObservation;
pub use sequence::SequenceSpace;
pub use sequence::SequenceTracker;
pub use sequence::SequenceValue;
pub use session::ChargingCharacteristics;
pub use session::Dnn;
pub use session::RatType;
pub use session::SessionContext;
pub use session::SliceServiceType;
pub use session::Snssai;
pub use timeband::Apportionment;
pub use timeband::SplitError;
pub use timeband::TimeSlice;
pub use timeband::UsageSplit;
pub use timeband::apportion;
pub use timeband::split_measured;
pub use timeband::split_session;
pub use validation::Finding;
pub use validation::Rule;
pub use validation::Severity;
pub use validation::ValidationConfig;
pub use validation::ValidationReport;
pub use validation::validate_records;
pub use volume::ByteScale;
pub use volume::Octets;
pub use volume::VolumePair;

Modules§

aggregation
What the batch adds up to.
ber
Basic Encoding Rules — the framing every 3GPP charging record is wrapped in.
cdrtime
Charging-record time: local time plus an offset, never a bare instant.
container
Per-service usage inside one record.
correlation
Tying a record to the usage it describes — the identifiers, and the join.
dedup
Deduplication: the natural key is the whole design.
dialplan
What the subscriber dialled, and what kind of destination it is.
digits
DigitString — a short run of decimal digits, stored inline, and the two binary-coded-decimal conventions a charging record uses.
disposition
The conservation law: every ingested record reaches exactly one outcome.
error
ParseError — the single error type every FromStr in this crate returns.
fairuse
Fair use and permanent roaming (EU 2016/2286).
fraud
Fraud signals: evidence, never verdicts.
identity
Subscriber, subscription and equipment identifiers.
jurisdiction
Which country’s rules apply — and which question you are asking.
lateness
How late a record is, and what that changes.
location
Where a record was produced: cells, service areas and tracking areas.
numbering
What a dialled number means: ranges, and who actually terminates it.
partial
Partial records: reconstruct, never invent.
party
Who a usage record is attributed to.
pipeline
One pass over a batch: the pieces of this crate, wired in a fixed order.
plmn
Network identity: Mcc, Mnc, PlmnId and TadigCode.
privacy
Reducing an identity to what a question actually needs.
quality
The release gate: may this batch be invoiced?
record
The core usage record, and the vocabulary that classifies it.
restatement
Corrections are new records, never edits.
retention
How long a record may be kept, and what it is anchored to.
roaming
Roaming batches: what a partner sent, and whether it adds up.
sequence
Completeness: sequence gaps are the only evidence of loss.
session
What a PDU session was established against: a data network and a slice.
timeband
Splitting one session across tariff-time boundaries.
validation
The numbered rule catalogue.
volume
Data volumes as integer octets, and the unit arithmetic around them.