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, keyed as for a customer tag; a service
tag’s keys start s_tag instead:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Tag Control Information |
0 |
0 |
|
Priority Code Point |
0 |
3 |
|
Drop Eligible Indicator |
0 |
4 |
|
VLAN Identifier |
2 |
16 |
|
Protocol (Internet Layer) |
The two tags carry an identical tag control information layout and differ only
in the tag protocol identifier (TPID) that selected them – 0x8100 for the
customer tag, 0x88A8 for the service tag. The TPID is not part of either tag:
it is the EtherType field of whatever encapsulates the tag. Both classes read the
same four octets and share all parsing and construction code, which this base
holds.
They are still 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:
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. One class bound at both EtherTypes
would nest a c_tag inside a c_tag, leaving nothing to say which was the
service tag.
Two EtherTypes also mean two __index__()
values, which is the project’s rule for separate modules: siblings that share an
index may share a module, as InARP shares
arp and
DRARP shares
rarp. This base is abstract, nothing
dispatches to it, and it declares no index, 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.Changed in version 1.5.0: Became an abstract base. The 802.1Q customer tag it implemented, with its
name,aliasandinfo_name, moved toC_Tag.- 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