VLAN - 802.1Q/802.1ad VLAN Tag Types

pcapkit.protocols.link.vlan contains VLAN only, an abstract base class holding the tag layout shared by every VLAN tag [*]. The two concrete tags live in modules of their own:

EtherType

Class

0x8100 (customer tag, 802.1Q)

C_Tag

0x88A8 (service tag, 802.1ad)

S_Tag

The tag structure is described as below:

Octets

Bits

Name

Description

1

0

vlan.tci

Tag Control Information

1

0

vlan.tci.pcp

Priority Code Point

1

3

vlan.tci.dei

Drop Eligible Indicator

1

4

vlan.tci.vid

VLAN Identifier

3

24

vlan.type

Protocol (Internet Layer)

The two tags carry an identical tag control information layout and are told apart solely by the tag protocol identifier (TPID) that selected them – 0x8100 for the customer tag against 0x88A8 for the service tag. That TPID is not part of either tag: it is the EtherType field of whatever encapsulates the tag, so both classes read the same four octets and share every byte of parsing and construction code, which is what this base holds.

They are nonetheless distinct classes rather than one class bound at two EtherTypes, because 802.1ad stacks them. In a Q-in-Q frame the service tag’s own next-EtherType is 0x8100, which selects a customer tag in turn, so both tags appear in one frame:

ethernet.type                = 0x88A8
ethernet.s_tag.tci.vid       = 100     <- service tag,  802.1ad
ethernet.s_tag.type          = 0x8100
ethernet.s_tag.c_tag.tci.vid = 200     <- customer tag, 802.1Q
ethernet.s_tag.c_tag.type    = 0x0800

info_name – s_tag against c_tag – is what keeps the two apart in the parsed Info. A single class bound at both EtherTypes would nest one c_tag inside another, leaving nothing in the output to say which of the two was the service tag.

Two distinct EtherTypes also means two distinct __index__() values, which is the project’s rule for when protocols get separate modules: siblings that share an index may share a module, as InARP shares arp and DRARP shares rarp. This base declares no index of its own – it is abstract and nothing dispatches to it – so its __index__ raises.

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

Bases: Link[VLAN, VLAN]

Abstract base class for 802.1Q/802.1ad VLAN tag types.

The class implements the whole of the tag – both parsing and construction – since the customer and service tags are byte-for-byte identical. What it deliberately leaves to its subclasses is only how the tag names itself: name, alias and info_name.

It is abstract for the same reason IP is: name is declared abstract by ProtocolBase and is not defined here, so the class cannot be instantiated. Bind C_Tag or S_Tag, never this class.

property length: Literal[4]

Header length of current protocol.

property protocol: EtherType

Name of next layer protocol.

classmethod id()[source]

Index ID of the protocol.

Return type:

tuple[Literal['VLAN'], Literal['C_Tag'], Literal['S_Tag']]

Returns:

Index ID of the protocol – the family name, then every tag in it, as HTTP.id does for its own family. Note that unlike HTTP’s versions, the two tags are distinct protocols rather than flavours of one, so each is its own canonical name; they carry VLAN only as a secondary alias.

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

Read 802.1Q/802.1ad VLAN tag type.

Structure of 802.1Q/802.1ad VLAN tag type [IEEE 802.1Q]:

 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|              TCI              |                               |
|-------------------------------|                               |
|  P  |D|                       |             Type              |
|  C  |E|          VID          |                               |
|  P  |I|                       |                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:
  • length (int | None) – Length of packet data.

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

Return type:

VLAN

Returns:

Parsed packet data.

make(tci=None, pcp=<PriorityLevel.BE: 0>, pcp_default=None, pcp_namespace=None, pcp_reversed=False, dei=False, vid=0, type=<EtherType.Internet_Protocol_version_4: 2048>, type_default=None, type_namespace=None, type_reversed=False, payload=b'', **kwargs)[source]

Make (construct) packet data.

Parameters:
Return type:

VLAN

Returns:

Constructed packet data.

classmethod _make_data(data)[source]

Create key-value pairs from data for protocol construction.

Parameters:

data (VLAN) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

classmethod __index__()[source]

Numeral registry index of the protocol.

Raises:

UnsupportedCall – This protocol has no registry entry.

Return type:

NoReturn

Header Schemas

Both tags share these, since their layouts are identical.

class pcapkit.protocols.schema.link.vlan.VLAN(*args: _VT, **kwargs: _VT)[source]

Bases: Schema

Header schema for an 802.1Q/802.1ad VLAN tag.

tci: TCIType = <BitField tci>

Tag control information.

type: EtherType = <EnumField type>

EtherType.

payload: bytes = <PayloadField payload>

Payload.

class pcapkit.protocols.schema.link.vlan.TCI(*args: _VT, **kwargs: _VT)[source]

Bases: Schema

Header schema for 802.1Q/802.1ad VLAN tag control information.

pcp: PriorityLevel = <EnumField pcp>

Priority code point.

dei: int = <UInt8Field dei>

Drop eligible indicator.

vid: int = <UInt16Field vid>

VLAN identifier.

Type Stubs

class pcapkit.protocols.schema.link.vlan.TCIType[source]

Bases: TypedDict

Type of 802.1Q/802.1ad VLAN tag control information.

pcp: int

Priority code point.

dei: int

Drop eligible indicator.

vid: int

VLAN identifier.

Data Models

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

Bases: Protocol

Data model for an 802.1Q/802.1ad VLAN tag.

tci: TCI

Tag control information.

type: EtherType

Protocol (Internet Layer).

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

Bases: Data

Data model for tag control information.

pcp: PriorityLevel

Priority code point.

dei: bool

Drop eligible indicator.

vid: int

VLAN identifier.

Footnotes