OSPF - Open Shortest Path First

pcapkit.protocols.application.ospf contains OSPF only, which implements an extractor for Open Shortest Path First (OSPF) [*], whose structure is described as below:

Octets

Bits

Name

Description

0

0

ospf.version

Version Number

1

8

ospf.type

Type

2

16

ospf.len

Packet Length (header included)

4

32

ospf.router_id

Router ID

8

64

ospf.area_id

Area ID

12

96

ospf.chksum

Checksum

14

112

ospf.autype

Authentication Type

16

128

ospf.auth

Authentication

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 make() recomputed the length from the payload and dropped those octets; it takes them as packet_length and trailer (#1249, #1455).


class pcapkit.protocols.application.ospf.OSPF(file=None, length=None, **kwargs)[source]

Bases: Application[OSPF, OSPF]

This class implements Open Shortest Path First.

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 RFC 1812 Section 4.1 confines the internet layer to IP, ICMP and IGMP. Hence Application as the base, and layer == 'Application'. See Protocol Layer Placement.

Note

The subpackage does not track the dispatch tier. OSPF is dispatched from Internet.__proto__ at OSPFIGP (IANA protocol number 89), since IP is what carries it.

property name: str

Name of current protocol.

property alias: str

Acronym of current protocol.

property length: Literal[24]

Header length of current protocol.

property type: Packet

OSPF packet type.

read(length=None, **kwargs)[source]

Read Open Shortest Path First.

Structure of OSPF header [RFC 2328]:

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   Version #   |     Type      |         Packet length         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                          Router ID                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                           Area ID                             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Checksum            |             AuType            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       Authentication                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       Authentication                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:
  • length (int | None) – Length of packet data.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

OSPF

Returns:

Parsed packet data.

make(version=2, type=Packet.Hello, type_default=None, type_namespace=None, type_reversed=False, packet_length=None, router_id='0.0.0.0', area_id='0.0.0.0', checksum=b'\x00\x00', auth_type=Authentication.No_Authentication, auth_type_default=None, auth_type_namespace=None, auth_type_reversed=False, auth_data=b'\x00\x00\x00\x00\x00\x00\x00\x00', payload=b'', trailer=b'', **kwargs)[source]

Make (construct) packet data.

Parameters:
Return type:

OSPF

Returns:

Constructed packet data.

Raises:

ProtocolError – If auth_data is of an invalid type, is bytes that are not exactly 8 octets long, or is a dict missing a required key; or if packet_length is not an int in 0..65535.

Changed in version 1.5.0: packet_length is a new parameter before router_id, so a 1.4.x positional argument meant for router_id or a later parameter lands one parameter early (#1249).

classmethod _make_data(data)[source]

Create key-value pairs from data for protocol construction.

Parameters:

data (OSPF) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

_read_encrypt_auth(schema)[source]

Read Authentication field when Cryptographic Authentication is employed, i.e. autype is 2.

Structure of Cryptographic Authentication [RFC 2328]:

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|              0                |    Key ID     | Auth Data Len |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                 Cryptographic sequence number                 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:

schema (CryptographicAuthentication) – parsed authentication data

Return type:

CryptographicAuthentication

Returns:

Parsed packet data.

_make_encrypt_auth(auth_data)[source]

Make Authentication field when Cryptographic Authentication is employed.

Parameters:

auth_data (bytes | CryptographicAuthentication | CryptographicAuthentication | dict[str, Any]) – Authentication data, as raw octets, a schema, a data model, or the dict form of a data model.

Return type:

CryptographicAuthentication

Returns:

Authentication schema.

Raises:

ProtocolError – If auth_data is of an invalid type, is bytes that are not exactly 8 octets long, or is a dict missing a required key.

classmethod __index__()[source]

Numeral registry index of the protocol.

Return type:

TransType

Returns:

Numeral registry index of the protocol in IANA.

_make_id_numbers(id)[source]

Make router and area IDs.

Parameters:

id (IPv4Address | str | bytes | bytearray) – ID.

Return type:

bytes

Returns:

ID bytes.

Raises:

FieldValueError – If id is a bool (see parse_ip_address()).

Notes

Latent rather than live: nothing in this module calls this method (make() builds router_id/area_id straight from its own arguments), so the only caller is a unit test. It is routed through parse_ip_address() anyway, so that a future caller passing a bool gets FieldValueError rather than a silent 0.0.0.1.

The description below uses self.__class__.__name__ rather than self.alias, because alias here reads self._version, which read() only assigns from the wire – unavailable to a construction-only instance that never went through read().

Header Schemas

class pcapkit.protocols.schema.application.ospf.OSPF(version=NO_VALUE, type=NO_VALUE, length=NO_VALUE, router_id=NO_VALUE, area_id=NO_VALUE, checksum=NO_VALUE, auth_type=NO_VALUE, auth_data=NO_VALUE, payload=NO_VALUE, trailer=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: Schema

Header schema for OSPF packet.

version: int = <UInt8Field version>

Version.

type: Packet = <EnumField type>

Type.

length: int = <UInt16Field length>

Length.

router_id: IPv4Address = <IPv4AddressField router_id>

Router ID.

area_id: IPv4Address = <IPv4AddressField area_id>

Area ID.

checksum: bytes = <BytesField checksum>

Checksum.

auth_type: Authentication = <EnumField auth_type>

Authentication type.

auth_data: bytes | CryptographicAuthentication = <SwitchField auth_data>

Authentication data.

payload: bytes = <PayloadField payload>

Payload.

trailer: bytes = <PayloadField trailer>

Octets captured past the Packet Length, such as the message digest that cryptographic authentication appends (RFC 2328 Appendix D.4.3); compare IPv4.trailer.

class pcapkit.protocols.schema.application.ospf.CryptographicAuthentication(reserved=NO_VALUE, key_id=NO_VALUE, len=NO_VALUE, seq=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: Schema

Header schema for OSPF cryptographic authentication.

Added in version 1.5.0: Renamed from CrytographicAuthentication, which pcapkit.protocols.schema exported as OSPF_CrytographicAuthentication (#1090).

Removed in version 1.5.0: CrytographicAuthentication and OSPF_CrytographicAuthentication, with no alias (#1090).

reserved: bytes = <PaddingField reserved>

Reserved bytes.

key_id: int = <UInt8Field key_id>

Key ID.

len: int = <UInt8Field len>

Length.

seq: int = <UInt32Field seq>

Sequence number.

Auxiliary Functions

pcapkit.protocols.schema.application.ospf.ospf_auth_data_selector(pkt)[source]

Selector function for OSPF.auth_data field.

Parameters:

pkt (dict[str, Any]) – Packet data.

Return type:

FieldBase

Returns:

A SchemaField wrapped CryptographicAuthentication instance if OSPF.auth_type is 2, and a BytesField instance otherwise.

Data Models

class pcapkit.protocols.data.application.ospf.OSPF(version, type, len, router_id, area_id, chksum, autype)[source]

Bases: Protocol

Data model for OSPF packet.

version: int

Version number.

type: Packet

Type.

len: int

Packet length (header included).

router_id: IPv4Address

Router ID.

area_id: IPv4Address

Area ID.

chksum: bytes

Checksum.

autype: Authentication

Authentication type.

auth: bytes | CryptographicAuthentication

Authentication.

trailer: bytes

Octets captured past the Packet Length, present only when there are any.

class pcapkit.protocols.data.application.ospf.CryptographicAuthentication(reserved, key_id, len, seq)[source]

Bases: Data

Data model for OSPF cryptographic authentication.

Added in version 1.5.0: Renamed from CrytographicAuthentication, which pcapkit.protocols.data exported as OSPF_CrytographicAuthentication (#1090).

Removed in version 1.5.0: CrytographicAuthentication and OSPF_CrytographicAuthentication, with no alias (#1090).

reserved: bytes

The two reserved octets, as captured.

key_id: int

Key ID.

len: int

Authentication data length.

seq: int

Cryptographic sequence number.

Footnotes