NGAP - NG Application Protocol¶
pcapkit.protocols.application.ngap contains
NGAP only,
which implements extractor for the NG Application Protocol
(NGAP) [*], as specified in 3GPP TS 38.413.
NGAP is the control plane between a 5G RAN node (gNB or ng-eNB) and an AMF.
It runs over SCTP and is named by the DATA chunk’s payload protocol
identifier rather than by a port, so NGAP is registered on
SCTP.__proto__ under
PPID 60 (NG_Application_Protocol) and PPID 66
(NGAP_over_DTLS_over_SCTP), c.f.
pcapkit.foundation.registry.protocols.register_sctp().
An SCTP DATA chunk that names NGAP carries exactly one NGAP-PDU, encoded
in aligned PER (ALIGNED PACKED ENCODING RULES, APER). There is no
header to read and no framing to resolve: the whole payload is the encoding,
and none of its structure is visible until an ASN.1 decoder has run over it.
Decoding therefore needs the optional pycrate dependency
(pip install pypcapkit[NGAP]). pcapkit imports and works without
it; an NGAP payload simply degrades to the opaque payload path, exactly as an
unregistered PPID would, because
SCTP._import_next_layer
is wrapped in beholder() and falls back to
Raw.
Why pycrate rather than a PER codec of our own¶
Two things make it the cheaper answer. pycrate ships NGAP already
compiled, at pycrate_asn1dir/NGAP.py, so the 3GPP ASN.1 source does not
have to be vendored here and tracked across releases; and it is pure
Python, with no compiled extension to build on any platform. Decoding costs
0.15 ms per PDU, the same order as pcapkit’s own per-packet cost, so
the generic strategy below is not paying for the convenience.
Generic conversion, not 81 hand-written procedures¶
The decoded value tree is mapped into Info
objects structurally, by ASN.1 shape rather than by procedure:
ASN.1 / |
|
|---|---|
|
|
|
|
|
|
|
|
|
|
|
That is a deliberate trade. Every one of the 81 elementary procedures and 438
protocol IEs works on the day it is decoded, and a new 3GPP release needs no
code change here; what is given up is per-IE typing, so an IE’s value is
reported in the specification’s own shape rather than as a
pcapkit-specific model. The fields worth reading at a glance – the PDU
kind, procedure code, criticality, message type name and the IE list – are
surfaced as first-class fields on
NGAP regardless.
Known limitations¶
PPID 66 payloads are not decoded.
NGAP_over_DTLS_over_SCTPwraps theNGAP-PDUin a DTLS record, andpcapkitimplements no DTLS, so the bytes reachingNGAP.read()are not an APER encoding. The PPID is registered so that it is named rather than anonymous; the payload itself degrades toRaw.The specification version is |pycrate|_’s, not this package’s. The IE and procedure enumerations were generated from
NGAP_Constantsofpycrate0.8.1 (Release-18-era: 81 procedure codes, 438 protocol IE IDs, highest 443). Apycratethat carries a newer NGAP will decode IEs thatProcedureCodeandProtocolIEdo not name; both extend themselves at lookup time rather than failing, so such a value is reported asUnassigned_<n>.NGAP over a fragmented SCTP association is not reassembled. A DATA chunk is decoded on its own, so an
NGAP-PDUsplit across chunks by SCTP fragmentation fails to decode rather than being reassembled first.Private IEs (``PrivateMessage``) carry no schema. Their contents are vendor defined, so the generic conversion reports whatever ASN.1 shape the encoding declares and cannot name the fields.
- class pcapkit.protocols.application.ngap.NGAP(file=None, length=None, **kwargs)[source]¶
Bases:
Application[NGAP,NGAP]This class implements NG Application Protocol.
- property length: int¶
Header length of current protocol.
NGAP prefixes its payload with nothing and carries no next layer, so the whole
NGAP-PDUis the header and this is its length. That is notself.__length_hint__, which reports the four-octet prefix common to every PDU rather than this PDU’s size.
- make(kind=PDUKind.INITIATING_MESSAGE, procedure=None, criticality=<Criticality.reject: 0>, message=None, value=None, data=None, **kwargs)[source]¶
Make (construct) packet data.
- Parameters:
kind (
PDUKind|str) – WhichNGAP-PDUalternative to construct.procedure (
ProcedureCode|int|None) – Procedure code.criticality (
Criticality|int|str) – Criticality of the procedure.message (
str|None) – Name of the message type, e.g.NGSetupRequest.value (
Any) – Message body, either asSequencefrom a previousread()or as the plain Python valuepycrateexpects.data (
bytes|None) – Pre-encodedNGAP-PDU. When given, it is used verbatim and every other argument is ignored, which is also the only path that does not needpycrate.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- Raises:
ProtocolError – If
datais not given and eitherprocedureormessageis missing, ifpycrateis not installed, or if the arguments do not describe a message the specification can encode.
- __length_hint__()[source]¶
Return an estimated length for the object.
Every
NGAP-PDUopens with the same four octets under aligned PER – theCHOICEindex, the procedure code, the criticality, and the first octet of the open type’s length determinant – so four is the fixed prefix NGAP has in place of a header. It is not a minimum PDU length: the smallest completeNGAP-PDUmeasured here, a message whoseprotocolIEslist is empty, is seven octets.- Return type:
Literal[4]
Auxiliary Functions¶
- pcapkit.protocols.application.ngap.load_pycrate()[source]¶
Load the optional
pycrateNGAP-PDUobject.- Return type:
- Returns:
pycrate_asn1dir.NGAP.NGAP_PDU_Descriptions.NGAP_PDU, theCHOICEoverinitiatingMessage/successfulOutcome/unsuccessfulOutcomethat is the entry point of the compiled specification, orNonewhenpycrateis not installed.
Notes
The import is attempted at most once and the outcome is cached. It is not free even when it succeeds –
pycrate_asn1dir.NGAPis a 4.9 MB module – which is the other reason it happens here rather than at module import: neitherimport pcapkitnor the documentation build should pay for it.
- pcapkit.protocols.application.ngap._PYCRATE: Any = NotImplemented¶
Cached
NGAP-PDUobject, c.f.load_pycrate().NotImplementedmeans the import has not been attempted yet, andNonethat it was attempted andpycrateis not installed – three states, so a capture full of NGAP packets does not pay for a failing import on every frame.
- pcapkit.protocols.application.ngap._PDU_LOCK¶
Guards the module-level
NGAP-PDUobject returned byload_pycrate(). That object is stateful:from_aper()stores the decoded value on it andget_val()hands back the decoder’s own containers rather than copies, so two decodes running concurrently through it would each see the other’s tree. The lock is held across the conversion, not merely across the decode, for that second reason.
- pcapkit.protocols.application.ngap._convert(value)[source]¶
Convert a
pycratedecoded value intopcapkitdata models.- Parameters:
value (
Any) – A node of the tree returned byNGAP_PDU.get_val().- Return type:
- Returns:
The same tree, with mappings as
Sequence,CHOICEpairs asChoice, andBIT STRINGpairs asBitString.
Notes
The two 2-tuple shapes are told apart by their first element, which is unambiguous:
pycratespells aCHOICEas(name, value)with astrname and aBIT STRINGas(bits, length)with twoint. Any other tuple is passed through with its members converted, so an ASN.1 construct not listed above degrades to its own shape rather than being mangled into one of these.
Auxiliary Data¶
- class pcapkit.protocols.application.ngap.PDUKind(*values)[source]¶
Bases:
StrEnumWhich alternative of the
NGAP-PDUCHOICEa PDU is.The values are spelled as the ASN.1 identifiers, so that a name decoded by
pycrateresolves by value.- INITIATING_MESSAGE = 'initiatingMessage'¶
A procedure’s request, or a class 2 procedure’s only message.
- SUCCESSFUL_OUTCOME = 'successfulOutcome'¶
A class 1 procedure’s successful response.
- UNSUCCESSFUL_OUTCOME = 'unsuccessfulOutcome'¶
A class 1 procedure’s unsuccessful response.
- static _generate_next_value_(name, start, count, last_values)¶
Return the lower-cased version of the member name.
- class pcapkit.protocols.application.ngap.Criticality(*values)[source]¶
Bases:
IntEnum[Criticality] What a receiver must do with an IE it does not understand.
Members are named for the ASN.1 identifiers rather than upper-cased, so that
Criticality.get()resolves a name decoded bypycratethrough the standard member map. The values are theENUMERATEDindices, which is what goes on the wire.- reject = 0¶
Reject the whole message.
- ignore = 1¶
Ignore the IE and carry on.
- notify = 2¶
Ignore the IE, carry on, and report it.
- classmethod _missing_(value)[source]¶
Lookup function used when value is not found.
- Parameters:
value (
int) – Value to get enum item.- Raises:
ValueError – Always.
Criticalityis anENUMERATEDwith no extension marker, so a fourth value cannot be encoded and a lookup for one is a bug rather than a newer specification.- Return type:
- class pcapkit.protocols.application.ngap.ProcedureCode(*values)[source]¶
Bases:
IntEnum[ProcedureCode] NGAP elementary procedure codes, 3GPP TS 38.413.
- class pcapkit.protocols.application.ngap.ProtocolIE(*values)[source]¶
Bases:
IntEnum[ProtocolIE-ID] NGAP protocol IE identifiers, 3GPP TS 38.413.
An IE’s ID name and the name of the open type its value is keyed under differ in places – IE 21 is
id-DefaultPagingDRXbut its value arrives keyedPagingDRX– soIE.typecarries the latter alongside this.
Note
ProcedureCode and
ProtocolIE are rendered without
their members on purpose: between them they carry 519 of them, each named for
the 3GPP identifier it comes from, and a page listing all of them is longer
than the specification’s own tables and no more useful. Read them from
pcapkit/protocols/application/ngap.py, or from
pycrate_asn1dir.NGAP.NGAP_Constants, which is where they were generated
from.
Unlike the enumerations under pcapkit.const, these are not crawled
from an IANA registry – 3GPP publishes them in the ASN.1 of TS 38.413 rather
than in a registry with a stable page – so there is no matching module under
pcapkit.vendor.
Header Schemas¶
- class pcapkit.protocols.schema.application.ngap.NGAP(dict_=None, **kwargs)[source]¶
Bases:
SchemaHeader schema for NGAP packet.
NGAP has no header of its own: an SCTP DATA chunk whose payload protocol identifier names NGAP carries exactly one aligned-PER-encoded
NGAP-PDUand nothing else, so there is no length field to read and no framing to resolve. The whole payload is the encoding, and its structure only becomes visible once the ASN.1 decoder has run.
Data Models¶
- class pcapkit.protocols.data.application.ngap.NGAP(*args: VT, **kwargs: VT)[source]¶
Bases:
ProtocolData model for NGAP protocol.
The three
NGAP-PDUalternatives –initiatingMessage,successfulOutcomeandunsuccessfulOutcome– carry an identical field set and are distinguished bykindrather than by three near-identical models.- procedure: ProcedureCode¶
Procedure code.
- criticality: Criticality¶
Criticality of the procedure.
- class pcapkit.protocols.data.application.ngap.IE(*args: VT, **kwargs: VT)[source]¶
Bases:
DataData model for one NGAP protocol information element.
- id: ProtocolIE¶
Protocol IE ID.
- criticality: Criticality¶
Criticality, i.e. what a receiver must do when it does not understand
id.
- class pcapkit.protocols.data.application.ngap.Choice(*args: VT, **kwargs: VT)[source]¶
Bases:
DataData model for an ASN.1
CHOICEalternative or open type.Both the selected alternative’s name and its value are kept, since the name is the only thing that says which of the alternatives was sent – an
NGAP-PDUcarrying('globalGNB-ID', ...)and one carrying('globalNgENB-ID', ...)are otherwise indistinguishable once the value has been converted.
- class pcapkit.protocols.data.application.ngap.BitString(*args: VT, **kwargs: VT)[source]¶
Bases:
DataData model for an ASN.1
BIT STRING.A bit string is not a whole number of octets, so its length is carried alongside its value rather than being implied by it –
gNB-IDis a 22-to-32-bit field, and(0x000102, 24)and(0x000102, 32)are different identifiers.
- class pcapkit.protocols.data.application.ngap.Sequence(*args: VT, **kwargs: VT)[source]¶
Bases:
DataData model for an ASN.1
SEQUENCE,SETorSEQUENCE OFmember.Fields are whatever the specification names them, so this model carries no fixed annotations: it is populated from the decoded value tree. ASN.1 identifiers are hyphenated where Python identifiers cannot be, e.g.
gNB-ID, so such fields are reachable by subscription (seq['gNB-ID']) rather than by attribute access.
Footnotes