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:
The tag structure is described as below:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
1 |
0 |
|
Tag Control Information |
1 |
0 |
|
Priority Code Point |
1 |
3 |
|
Drop Eligible Indicator |
1 |
4 |
|
VLAN Identifier |
3 |
24 |
|
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]¶
-
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,aliasandinfo_name.It is abstract for the same reason
IPis:nameis declared abstract byProtocolBaseand is not defined here, so the class cannot be instantiated. BindC_TagorS_Tag, never this class.- classmethod id()[source]¶
Index ID of the protocol.
- Return type:
- Returns:
Index ID of the protocol – the family name, then every tag in it, as
HTTP.iddoes 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 carryVLANonly 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| | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- 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:
pcp (
PriorityLevel|IntEnum|IntEnum|str|int) – Priority Code Point (PCP) field.pcp_namespace (
dict[str,int] |dict[int,str] |Type[IntEnum] |Type[IntEnum] |None) – Namespace of PCP field.pcp_reversed (
bool) – Reversed flag of PCP field.dei (
bool) – Drop Eligible Indicator (DEI) field.vid (
int) – VLAN Identifier (VID) field.type (
EtherType|IntEnum|IntEnum|str|int) – EtherType field.type_default (
int|None) – Default value of EtherType field.type_namespace (
dict[str,int] |dict[int,str] |Type[IntEnum] |Type[IntEnum] |None) – Namespace of EtherType field.type_reversed (
bool) – Reversed flag of EtherType field.payload (
bytes|ProtocolBase|Schema) – Payload field.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- classmethod __index__()[source]¶
Numeral registry index of the protocol.
- Raises:
UnsupportedCall – This protocol has no registry entry.
- Return type:
Header Schemas¶
Both tags share these, since their layouts are identical.
- class pcapkit.protocols.schema.link.vlan.VLAN(*args: _VT, **kwargs: _VT)[source]¶
Bases:
SchemaHeader schema for an 802.1Q/802.1ad VLAN tag.
- class pcapkit.protocols.schema.link.vlan.TCI(*args: _VT, **kwargs: _VT)[source]¶
Bases:
SchemaHeader schema for 802.1Q/802.1ad VLAN tag control information.
- pcp: PriorityLevel = <EnumField pcp>¶
Priority code point.
Type Stubs¶
Data Models¶
- class pcapkit.protocols.data.link.vlan.VLAN(*args: VT, **kwargs: VT)[source]¶
Bases:
ProtocolData model for an 802.1Q/802.1ad VLAN tag.
- class pcapkit.protocols.data.link.vlan.TCI(*args: VT, **kwargs: VT)[source]¶
Bases:
DataData model for tag control information.
- pcp: PriorityLevel¶
Priority code point.
Footnotes