OSPFv3 - Open Shortest Path First Version 3

pcapkit.protocols.application.ospfv3.protocol contains OSPFv3, which implements an extractor for OSPF for IPv6 (OSPFv3) [RFC 5340], whose 16-octet header (RFC 5340 Appendix A.3.1) has an Instance ID and a reserved octet in place of OSPFv2’s AuType and Authentication:

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.instance_id

Instance ID

15

120

ospf.reserved

Reserved

Added in version 1.8.1.

class pcapkit.protocols.application.ospfv3.protocol.OSPFv3(file, length=None, /, *, version=None, layer=None, protocol=None, context=None)[source]

Bases: OSPF[OSPFv3, OSPFv3]

This class implements OSPF for IPv6 (OSPF version 3).

Its checksum covers an IPv6 pseudo-header (RFC 5340 Appendix A.3.1), so it is neither verified nor computed.

Added in version 1.8.1.

Properties

property length: Literal[16]

Header length of current protocol.

Methods

classmethod id()[source]

Index ID of the protocol.

Return type:

tuple[Literal['OSPFv3']]

Returns:

Index ID of the protocol, narrowed to this member.

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

Read OSPF for IPv6.

Structure of OSPFv3 header [RFC 5340]:

 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             |  Instance ID  |      0        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:
  • length (int | None) – Length of packet data.

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

Return type:

OSPFv3

Returns:

Parsed packet data.

Raises:

ProtocolError – If the Version is not 3.

make(*, version=3, type=Packet.Hello, packet_length=None, router_id='0.0.0.0', area_id='0.0.0.0', checksum=None, instance_id=0, reserved=b'\x00', payload=b'', trailer=b'', **kwargs)[source]

Make (construct) packet data.

Parameters:
  • version (int) – OSPF version number, 3.

  • type (Packet | int) – OSPF packet type.

  • packet_length (int | None) – Packet length (header included). If not given, it is computed as 16 plus the length of payload.

  • router_id (IPv4Address | str | bytes) – Router ID.

  • area_id (IPv4Address | str | bytes) – Area ID.

  • checksum (bytes | None) – Checksum, zero if None: it covers an IPv6 pseudo-header, so none is computed.

  • instance_id (int) – Instance ID.

  • reserved (bytes) – The reserved octet after the Instance ID.

  • payload (bytes | ProtocolBase | Schema) – Payload data.

  • trailer (bytes) – Octets after the packet, outside the Packet Length; written as is.

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

Return type:

OSPFv3

Returns:

Constructed packet data.

Raises:

ProtocolError – If version is not 3; if packet_length is not an int in 0..65535; if checksum is not two octets; if instance_id is not an int in 0..255; if reserved is not one octet; or if type is a name, a bool, or a member or code its 8 bits cannot carry.

Data Models

__length_hint__()[source]

Return an estimated length for the object.

Return type:

Literal[16]

Utilities

classmethod _make_data(data)[source]

Create key-value pairs from data for protocol construction.

Parameters:

data (OSPFv3) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

Header Schemas

class pcapkit.protocols.application.ospfv3.schema.OSPFv3(version=NO_VALUE, type=NO_VALUE, length=NO_VALUE, router_id=NO_VALUE, area_id=NO_VALUE, checksum=NO_VALUE, instance_id=NO_VALUE, reserved=NO_VALUE, payload=NO_VALUE, trailer=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: Schema

Header schema for OSPFv3 packet: the 16-octet header of RFC 5340 Appendix A.3.1, which has an Instance ID and a reserved octet in place of OSPFv2’s AuType and Authentication fields.

Added in version 1.8.1.

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.

instance_id: int = <UInt8Field instance_id>

Instance ID.

reserved: bytes = <PaddingField reserved>

Reserved octet.

payload: bytes = <PayloadField payload>

Payload.

trailer: bytes = <PayloadField trailer>

Octets captured past the Packet Length; compare OSPFv2.trailer.

Data Models

class pcapkit.protocols.application.ospfv3.data.OSPFv3(version, type, len, router_id, area_id, chksum, instance_id, reserved)[source]

Bases: Protocol

Data model for OSPFv3 packet (RFC 5340 Appendix A.3.1).

Added in version 1.8.1.

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.

instance_id: int

Instance ID.

reserved: bytes

The reserved octet, as captured.

trailer: bytes

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