OSPF - Open Shortest Path First

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

Octets

Bits

Name

Description

0

0

ospf.version

Version Number

0

0

ospf.type

Type

0

1

ospf.len

Packet Length (header included)

0

2

ospf.router_id

Router ID

0

4

ospf.area_id

Area ID

0

6

ospf.chksum

Checksum

0

7

ospf.autype

Authentication Type

1

8

ospf.auth

Authentication


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

Bases: Link[OSPF, OSPF]

This class implements Open Shortest Path First.

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 (Optional[int]) – Length of packet data.

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

Return type:

OSPF

Returns:

Parsed packet data.

make(version=2, type=<Packet.Hello: 1>, type_default=None, type_namespace=None, type_reversed=False, router_id='0.0.0.0', area_id='0.0.0.0', checksum=b'\\x00\\x00', auth_type=<Authentication.No_Authentication: 0>, 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'', **kwargs)[source]

Make (construct) packet data.

Parameters:
Return type:

OSPF

Returns:

Constructed packet data.

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 (CrytographicAuthentication) – parsed authentication data

Return type:

CrytographicAuthentication

Returns:

Parsed packet data.

_make_encrypt_auth(auth_data)[source]

Make Authentication field when Cryptographic Authentication is employed.

Parameters:
Return type:

bytes | CrytographicAuthentication

Returns:

Authentication bytes.

classmethod __index__()[source]

Numeral registry index of the protocol.

Raises:

UnsupportedCall – This protocol has no registry entry.

Return type:

NoReturn

Header Schemas

class pcapkit.protocols.schema.link.ospf.OSPF(dict_=None, **kwargs)[source]

Bases: Schema

Header schema for OSPF packet.

version: int = <UInt8Field version>

Version.

type: Enum_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: Enum_Authentication = <EnumField auth_type>

Authentication type.

auth_data: bytes | CrytographicAuthentication = <SwitchField auth_data>

Authentication data.

payload: bytes = <PayloadField payload>

Payload.

class pcapkit.protocols.schema.link.ospf.CrytographicAuthentication(dict_=None, **kwargs)[source]

Bases: Schema

Header schema for OSPF cryptographic authentication.

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.link.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:

Data Models

class pcapkit.protocols.data.link.ospf.OSPF(*args: VT, **kwargs: VT)[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 | CrytographicAuthentication

Authentication.

class pcapkit.protocols.data.link.ospf.CrytographicAuthentication(*args: VT, **kwargs: VT)[source]

Bases: Data

Data model for OSPF crytographic authentication.

key_id: int

Key ID.

len: int

Authentication data length.

seq: int

Cryptographic sequence number.

Footnotes