Expand description
Pure CDP frame codec — 802.3 + LLC/SNAP framing, the CDP header, and the TLV body.
Nothing in this file touches a socket, a capture handle, the LLM or AppState. Every
function here is a pure transformation between bytes and structured values, which is the
whole point: the raw-Ethernet transport in super needs packet-capture privilege and
cannot run in the test environment, so the part of CDP that can actually be wrong — the
wire format — is isolated where it can be tested exhaustively against literal specification
bytes and against real captures. See src/server/cdp/CLAUDE.md for what is proven and what
is not.
§Frame layout
destination MAC (6) 01:00:0C:CC:CC:CC
source MAC (6)
802.3 length (2) = 8 + len(CDP payload) -- a LENGTH, not an EtherType
LLC DSAP (1) 0xAA
LLC SSAP (1) 0xAA
LLC control (1) 0x03 (unnumbered information)
SNAP OUI (3) 00:00:0C (Cisco)
SNAP protocol (2) 0x2000 (CDP)
CDP version (1) 1 or 2
CDP TTL (1) seconds the neighbour should keep the entry
CDP checksum (2)
CDP TLVs (n) type(2) length(2) value(length-4)Note the TLV length includes its own 4-byte header, which is the single most common
mistake when hand-writing CDP: a Device ID of "myswitch" (8 bytes) is 00 01 00 0C, not
00 01 00 08.
Structs§
- CdpAddress
- One entry of an Addresses or Management Address TLV.
- CdpAdvertisement
- A CDP advertisement, in the terms the LLM reasons about.
- Decoded
Cdp - What
decode_payloadfound, including the checksum verdict. - Frame
Header - The addressing of a received frame.
- Other
Tlv - A TLV this codec recognises the existence of but does not model.
Enums§
- Duplex
- Interface duplex, as advertised in the Duplex TLV.
Constants§
- CAPABILITY_
FLAGS - Device capability bits, as advertised in the Capabilities TLV.
- CDP_
HEADER_ LEN - version + ttl + checksum.
- CDP_
MULTICAST_ MAC - The CDP multicast destination. Every CDP advertisement goes here; there is no unicast CDP.
- CDP_
PAYLOAD_ OFFSET - Offset of the CDP payload inside a complete frame.
- ETHERNET_
HEADER_ LEN - Ethernet header length: destination + source + length field.
- LLC_
CONTROL_ UI - LLC control byte: unnumbered information.
- LLC_
SAP_ SNAP - LLC DSAP/SSAP for SNAP-encapsulated traffic.
- LLC_
SNAP_ HEADER - The complete LLC + SNAP header that precedes every CDP payload.
- LLC_
SNAP_ HEADER_ LEN - LLC + SNAP header length.
- MAX_
8023_ LENGTH - The largest value the 802.3 length field can carry as a length.
- MAX_
TEXT_ TLV - Cap on any single text field the model authors.
- SNAP_
OUI_ CISCO - SNAP OUI for Cisco.
- SNAP_
PROTOCOL_ CDP - SNAP protocol id for CDP.
- TLV_
ADDRESSES - TLV_
CAPABILITIES - TLV_
DEVICE_ ID - TLV_
DUPLEX - TLV_
MANAGEMENT_ ADDRESS - TLV_
NATIVE_ VLAN - TLV_
PLATFORM - TLV_
PORT_ ID - TLV_
SOFTWARE_ VERSION
Functions§
- capability_
bits - Encode capability names into a bitmask, rejecting anything unrecognised.
- capability_
names - Decode a capability bitmask into the names this codec knows.
- checksum
- The CDP checksum: a 16-bit one’s-complement sum (RFC 1071) over the CDP payload with the checksum field zeroed — with Cisco’s non-standard treatment of an odd-length payload.
- decode_
frame - Split a complete Ethernet frame into its header and the CDP payload.
- decode_
payload - Parse a CDP payload into an advertisement plus the checksum verdict.
- encode_
frame - Wrap a CDP payload in the 802.3 + LLC/SNAP header addressed to the CDP multicast group.
- encode_
payload - Serialise an advertisement to a CDP payload, checksum included.
- mac_
to_ string - Render a MAC as the canonical lowercase colon form.
- parse_
mac - Parse
aa:bb:cc:dd:ee:fforaa-bb-cc-dd-ee-ffinto six bytes. - payload_
checksum - The checksum a CDP payload should carry:
checksumover the payload with bytes 2..4 forced to zero.