Documentation ¶
Overview ¶
Package lldp implements marshaling and unmarshaling of IEEE 802.1AB Link Layer Discovery Protocol frames.
Index ¶
Constants ¶
const ( // EtherType is the registered EtherType for the Link Layer Discovery // Protocol, when the protocol is encapsulated in a IEEE 802.3 Ethernet // frame. EtherType ethernet.EtherType = 0x88cc )
const TLVLengthMax = 0x01ff
TLVLengthMax is the maximum length of value data allowed in a TLV.
Variables ¶
var ( // ErrInvalidFrame is returned when a Frame (LLDPDU) is invalid due to // one of the following reasons: // - Any of the four mandatory TLV values are not present, or are in // an incorrect order: // - Chassis ID // - Port ID // - TTL // - End of LLDPDU ErrInvalidFrame = errors.New("invalid frame") )
var ( // ErrInvalidTLV is returned when a TLV is invalid due to one of the // following reasons: // - Type is greater than TLVTypeMax // - Length is greater than TLVLengthMax // - Length does not match actual length of Value ErrInvalidTLV = errors.New("invalid TLV") )
Functions ¶
This section is empty.
Types ¶
type ChassisID ¶
type ChassisID struct { // Subtype specifies the type of identification carried in this ChassisID. Subtype ChassisIDSubtype // ID specifies raw bytes containing identification information for // this ChassisID. // // ID may carry alphanumeric data or binary data, depending upon the // value of Subtype. ID []byte }
A ChassisID is a structure parsed from a chassis ID TLV. It contains information which identifies a particular chassis on a given network.
func (*ChassisID) MarshalBinary ¶
MarshalBinary allocates a byte slice and marshals a ChassisID into binary form.
MarshalBinary never returns an error.
func (*ChassisID) UnmarshalBinary ¶
UnmarshalBinary unmarshals a byte slice into a ChassisID.
If the byte slice does not contain enough data to unmarshal a valid ChassisID, io.ErrUnexpectedEOF is returned.
type ChassisIDSubtype ¶
type ChassisIDSubtype uint8
A ChassisIDSubtype is a value used to indicate the type of content carried in a ChassisID.
const ( ChassisIDSubtypeReserved ChassisIDSubtype = 0 ChassisIDSubtypeChassisComponenent ChassisIDSubtype = 1 ChassisIDSubtypeInterfaceAlias ChassisIDSubtype = 2 ChassisIDSubtypePortComponent ChassisIDSubtype = 3 ChassisIDSubtypeMACAddress ChassisIDSubtype = 4 ChassisIDSubtypeNetworkAddress ChassisIDSubtype = 5 ChassisIDSubtypeInterfaceName ChassisIDSubtype = 6 ChassisIDSubtypeLocallyAssigned ChassisIDSubtype = 7 )
List of valid ChassisIDSubtype values.
func (ChassisIDSubtype) String ¶
func (i ChassisIDSubtype) String() string
type Frame ¶
type Frame struct { // ChassisID specifies mandatory chassis ID information regarding // a device. It contains information which identifies a particular // chassis on a given network. ChassisID *ChassisID // PortID specifies mandatory port ID information regarding a device. // It contains information which identifies a particular port within // the context of a system, on a given network. PortID *PortID // TTL specifies a mandatory time-to-live value which indicates how long // information within a Frame should be considered valid. TTL time.Duration // Optional specifies zero or more optional TLV values in raw format. Optional []*TLV }
A Frame is a LLDP frame, or LLDP Data Unit (LLDPDU). A Frame carries device information in a series of type-length-value (TLV) structures.
func (*Frame) MarshalBinary ¶
MarshalBinary allocates a byte slice and marshals a Frame into binary form.
If ChassisID or Port ID are nil, or TTL is greater than 65535 seconds, ErrInvalidFrame is returned.
If any problems are detected with TLVs, ErrInvalidTLV is returned.
func (*Frame) UnmarshalBinary ¶
UnmarshalBinary unmarshals a byte slice into a Frame.
If the byte slice does not contain enough data to unmarshal a valid Frame, io.ErrUnexpectedEOF is returned.
If the four mandatory TLV values chassis ID, port ID, TTL, and end of LLDPDU, are missing or do not appear in order, ErrInvalidFrame is returned.
type PortID ¶
type PortID struct { // Subtype specifies the type of identification carried in this PortID. Subtype PortIDSubtype // ID specifies raw bytes containing identification information for // this PortID. // // ID may carry alphanumeric data or binary data, depending upon the // value of Subtype. ID []byte }
A PortID is a structure parsed from a port ID TLV. It contains information which identifies a particular chassis on a given network.
func (*PortID) MarshalBinary ¶
MarshalBinary allocates a byte slice and marshals a PortID into binary form.
MarshalBinary never returns an error.
func (*PortID) UnmarshalBinary ¶
UnmarshalBinary unmarshals a byte slice into a PortID.
If the byte slice does not contain enough data to unmarshal a valid PortID, io.ErrUnexpectedEOF is returned.
type PortIDSubtype ¶
type PortIDSubtype uint8
A PortIDSubtype is a value used to indicate the type of content carried in a PortID.
const ( PortIDSubtypeReserved PortIDSubtype = 0 PortIDSubtypeInterfaceAlias PortIDSubtype = 1 PortIDSubtypePortComponent PortIDSubtype = 2 PortIDSubtypeMACAddress PortIDSubtype = 3 PortIDSubtypeNetworkAddress PortIDSubtype = 4 PortIDSubtypeInterfaceName PortIDSubtype = 5 PortIDSubtypeAgentCircuitID PortIDSubtype = 6 PortIDSubtypeLocallyAssigned PortIDSubtype = 7 )
List of valid PortIDSubtype values.
func (PortIDSubtype) String ¶
func (i PortIDSubtype) String() string
type TLV ¶
type TLV struct { // Type specifies the type of value carried in this TLV. Type TLVType // Length specifies the length of the value carried in this TLV. Length uint16 // Value specifies the raw data carried in this TLV. Value []byte }
A TLV is a type-length-value structure used to carry information in an encoded format.
func (*TLV) MarshalBinary ¶
MarshalBinary allocates a byte slice and marshals a TLV into binary form.
If Type is too large (greater than 127), Length is too large (greater than 511), or Length does not match the actual length of Value, ErrInvalidTLV is returned.
func (*TLV) UnmarshalBinary ¶
UnmarshalBinary unmarshals a byte slice into a TLV.
If the byte slice does not contain enough data to unmarshal a valid TLV, io.ErrUnexpectedEOF is returned.
type TLVType ¶
type TLVType uint8
A TLVType is a value used to identify the type of information carried in a TLV.
const ( // Mandatory TLVType values which must occur in all LLDPDUs. // TLVTypeEnd is a special sentinel value used to indicate the end of // TLVs in a LLDPDU. TLVTypeEnd TLVType = 0 TLVTypeChassisID TLVType = 1 TLVTypePortID TLVType = 2 TLVTypeTTL TLVType = 3 // Optional TLVType values which may occur in LLDPDUs. TLVTypePortDescription TLVType = 4 TLVTypeSystemName TLVType = 5 TLVTypeSystemDescription TLVType = 6 TLVTypeSystemCapabilities TLVType = 7 TLVTypeManagementAddress TLVType = 8 // TLVTypeOrganizationSpecific is a special TLVType which can be used // to carry organization-specific data in a special format. TLVTypeOrganizationSpecific TLVType = 127 // TLVTypeMax is an alias for the maximum possible value for a TLVType. TLVTypeMax TLVType = TLVTypeOrganizationSpecific )
List of valid TLVType values.