OSPF - Open Shortest Path First¶
pcapkit.protocols.application.ospf.protocol contains
OSPF only, the abstract base of
the Open Shortest Path First (OSPF) family [*]. Each version is a member of its own:
Version |
Class |
Specification |
Header |
|---|---|---|---|
1 |
24 octets, AuType and Authentication |
||
2 |
24 octets, AuType and Authentication |
||
3 |
16 octets, Instance ID and a reserved octet |
All three share the first 14 octets alone, Version to Checksum, so the base
parses no header. IP protocol 89 is OSPF’s in every version, so
Internet.__proto__
binds this base, which picks the member by the Version octet. Each RFC requires its
own version there (RFC 1131 Section 8.2, RFC 2328 Section 8.2,
RFC 5340 Section 4.2.2), so a direct parse of any other version raises
ProtocolError, and behind IP the packet is left
Raw.
Added in version 1.5.0: Moved here from pcapkit.protocols.link.ospf, with its data model and
header schema. OSPF derives
from Application, so
its layer is 'Application' (#719).
Removed in version 1.5.0: pcapkit.protocols.link.ospf, pcapkit.protocols.data.link.ospf and
pcapkit.protocols.schema.link.ospf, the OSPF name that
pcapkit.protocols.link, pcapkit.protocols.data.link and
pcapkit.protocols.schema.link each exported, and the
OSPF_CrytographicAuthentication name that
pcapkit.protocols.data.link and pcapkit.protocols.schema.link
exported, with no alias (#719, #1090).
Changed in version 1.5.0: A rebuild keeps the parsed Packet Length and the octets past it, where
OSPF.make recomputed the length from the payload and dropped those octets;
it takes them as packet_length and trailer (#1249,
#1455).
Changed in version 1.8.1: OSPF became the abstract base
of the family, giving OSPFv1,
OSPFv2 or
OSPFv3; it read every
version with OSPFv2’s 24-octet header, OSPFv3’s 16-octet one included. A version
none of them reads, 0 or 4 to 255, is refused, and left
Raw behind IP (#3105).
Removed in version 1.8.1: pcapkit.protocols.application.ospf.schema and
pcapkit.protocols.application.ospf.data, with their OSPF and
CryptographicAuthentication classes and
pcapkit.protocols.application.ospf.schema.ospf_auth_data_selector;
pcapkit.protocols.application.ospf.Schema_OSPF,
pcapkit.protocols.application.ospf.Schema_CryptographicAuthentication,
pcapkit.protocols.application.ospf.Data_OSPF and
pcapkit.protocols.application.ospf.Data_CryptographicAuthentication; and
OSPF.read, OSPF.make and OSPF.length, with OSPF._make_data,
OSPF._read_encrypt_auth, OSPF._make_encrypt_auth, OSPF._read_id_numbers
and OSPF._make_id_numbers. None has an alias: the OSPFv2 header moved to
pcapkit.protocols.application.ospfv2, as OSPFv2, and each member defines
its own read, make and length (#3105).
- class pcapkit.protocols.application.ospf.protocol.OSPF[_PT: Data, _ST: Schema](file, length=None, /, *, version=None, layer=None, protocol=None, context=None)[source]¶
Bases:
Application[_PT,_ST],Generic[_PT,_ST]This class implements all protocols in the OSPF family.
A routing protocol computes the forwarding table rather than forwarding packets, so it is a user of the stack rather than part of its forwarding path. RFC 1812 Section 7 places it accordingly, titling that chapter “APPLICATION LAYER - ROUTING PROTOCOLS” with OSPF at §7.2.2, while the Internet Layer protocols RFC 1812 Section 4.1 names are IP, ICMP and IGMP. Hence
Applicationas the base, andlayer == 'Application'. See Protocol Layer Placement.It is abstract, as
L2TPis:length,read()andmake()are declared abstract byProtocolBase, and none is defined here. It dispatches on both paths, never giving an instance of this class (#2574). Theversionfield names the member; without it, octets give the one their Version octet names, and fields are refused.from_data()reads theversionof its data. See__new__().Note
The subpackage does not track the dispatch tier. OSPF is dispatched from
Internet.__proto__atOSPFIGP(IANA protocol number 89), since IP is what carries it.Changed in version 1.6.0: Each enumeration field of its
maketakes a member or anintcode, resolved with the enumeration’sget; a name, aboolfor a field wider than one bit, or a code the field cannot carry raisesProtocolError, rather than resolving against an enumeration inferred from the caller’s frame or writing a different value (#2594).Removed in version 1.6.0: The
type_default,type_namespace,type_reversed,auth_type_default,auth_type_namespaceandauth_type_reversedarguments of itsmake; resolve a name withresolve_index()first (#2594).Changed in version 1.8.1: Became the abstract base of the family; its parsing moved to
OSPFv2. Constructing it andfrom_data()give a member, and fields withoutversionare refused (#3105).Properties
Methods
- classmethod from_data(data, /, **kwargs)[source]¶
Create protocol instance from data.
- Parameters:
**kwargs (
Any) – AsProtocol.from_data.
- Return type:
- Returns:
Protocol instance; on this class, an instance of the member the
versionofdatanames.- Raises:
ProtocolError – If, on this class,
datacarries noversionor one no member reads.
Data Models
- __length_hint__()[source]¶
Return an estimated length for the object.
The longest member’s header, OSPFv1’s and OSPFv2’s 24 octets, as
L2TPv2.__length_hint__takes its longest form.- Return type:
- __init__(file=NO_VALUE, length=None, /, *, version=None, layer=None, protocol=None, context=None, **fields)[source]¶
Parse a protocol instance from its octets, or construct one from its fields.
- Overloads:
file (
IO[bytes] |bytes), length (int|None) =..., /, *, version (int|None) =..., layer (str|None) =..., protocol (str|ProtocolBase|Type[ProtocolBase] |None) =..., context (ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) =...→None*, version (
int|None) =..., context (ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) =..., **fields (Any) →None
- Parameters:
file (
IO[bytes] |bytes|NoValueType) – Source packet stream; omitted to construct.version (
int|None) – Version of OSPF: the member__new__()picks, which must be this class’s own.layer (
str|None) – AsProtocol.__init__.protocol (
str|ProtocolBase|Type[ProtocolBase] |None) – AsProtocol.__init__.context (
ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) – AsProtocol.__init__.**fields (
Any) – AsProtocol.__init__.
- Raises:
ProtocolError – If
versionis not a version of OSPF, or is not this class’s own version: that of the member it is or derives from.
Added in version 1.8.1.
- static __new__(cls, file=NO_VALUE, length=None, /, **kwargs)[source]¶
Create the member a parse or a construction of this class describes.
The
versionkeyword names the member. Without it, the octets give the member their Version octet, the first, names, and fields are refused. That member’s__init__then runs with the same arguments. A subclass of this class is created as itself.- Parameters:
- Return type:
- Returns:
An uninitialised instance of the member.
- Raises:
ProtocolError – On this class, if
versionis not a version of OSPF; if, without it, the octets are empty; or if fields come without it.
Added in version 1.8.1.
Utilities
- static _member_of_version(version)[source]¶
The member that reads a
versionof the Version octet.- Parameters:
version (
Any) – Version of OSPF.- Return type:
- Returns:
- Raises:
ProtocolError – For any other
version, or one that is noint, as aboolor afloatis even where it equals one.
Added in version 1.8.1.
- classmethod _dispatch(data, length)[source]¶
Pick the class that parses the OSPF packet at the start of
data.As
IGMP._dispatchdoes for IP protocol 2, before any class is built.- Parameters:
- Return type:
Type[ProtocolBase] |Type[Raw]- Returns:
The member its Version octet names, as
_member_of_version()gives it;Rawfor any other version, which then keeps its octets undissected.
Added in version 1.8.1.
- classmethod _construction_member(fields)[source]¶
The member
from_fields(),from_data()and a call given no file construct.On this class, the member the
versionfield names, which stays infields; on another, the class itself.- Parameters:
- Return type:
- Returns:
The member, or the class itself.
- Raises:
ProtocolError – If, on this class,
versionis missing or is not a version of OSPF.
Added in version 1.8.1.
- _make_version(version)[source]¶
Check that
versionis one this class reads, formake()to write.- Parameters:
version (
Any) – Theversiongiven tomake().- Return type:
- Returns:
version, as a plainint.- Raises:
ProtocolError – If
versionis not a version of OSPF, or names another member.
Added in version 1.8.1.
- static _rebuilt_version(data, own)[source]¶
The version a rebuild of
datawrites: its own, orownif the capture ended first.A capture that ends before the Version octet leaves it zero, which names no member’s own version; the rebuild is cut back before the octet, so the version it writes is never read (#2880).
- Parameters:
- Return type:
- Returns:
The version for
make().
Added in version 1.8.1.
- _verify_checksum(ospf, exempt=False)[source]¶
Record on
ospfthe outcome of verifying a 24-octet header’s checksum.Only under
CHECKSUM_VERIFY, aschecksum_status. OSPFv1 and OSPFv2 define it alike, over the packet but the 8-octet Authentication field at octet 16, with no pseudo-header (RFC 1131 Section A.2, RFC 2328 Appendix A.3.1). OSPFv3’s covers an IPv6 pseudo-header instead (RFC 5340 Appendix A.3.1) and is not verified.- Parameters:
ospf (
_PT) – Parsed packet data, withlenandchksum.exempt (
bool) – Whether the packet leaves its checksum unused, as OSPFv2’s cryptographic authentication does (RFC 2328 Appendix D.4.3).
- Return type:
Added in version 1.8.1.
- static _compute_checksum(schema, packet_length)[source]¶
Fill in a made 24-octet header’s checksum, as
_verify_checksum()checks it.- Parameters:
schema (
_ST) – The headermake()built, its checksum zero.packet_length (
int) – Its Packet Length.
Added in version 1.8.1.
Footnotes