Documentation
¶
Overview ¶
Package ldp implements the Platina Link Diagnostic Protocol
Index ¶
Constants ¶
const ( // Pattern header Pattern = "Pattern: " Length = "Length: " SHA256 = "Sha256: " // Special patterns Alpha = "Alpha" AlphaTest = "The quick brown fox jumps over the lazy dog" )
Variables ¶
var ErrPatternMismatch = errors.New("Pattern data mismatch")
var ErrPatternUnknown = errors.New("Pattern unknown")
var PatternMap = map[string]PatternEntry{ "00": {SequenceToPattern, CheckPattern, []byte{0x00}}, "FF": {SequenceToPattern, CheckPattern, []byte{0xff}}, "AA": {SequenceToPattern, CheckPattern, []byte{0xaa}}, "55": {SequenceToPattern, CheckPattern, []byte{0x55}}, "AA55": {SequenceToPattern, CheckPattern, []byte{0xaa, 0x55}}, "55AA": {SequenceToPattern, CheckPattern, []byte{0x55, 0xaa}}, "00FF": {SequenceToPattern, CheckPattern, []byte{0x00, 0xff}}, "FF00": {SequenceToPattern, CheckPattern, []byte{0xff, 0x00}}, Alpha: {SequenceToPattern, CheckPattern, []byte(AlphaTest)}, }
Functions ¶
func CheckPattern ¶
CheckPattern checks that the pattern received matches the expected data sequence. A pattern is defined as a potentially truncated, potentially repeated sequence. truncated
func NewMessage ¶
NewMessage returns a protocol message from the named pattern of the specified length
func NewRandomMessage ¶
func NewRandomMessage() []byte
NewRandomMessage returns a protocol message of a random length of a random type.
func PatternToMsg ¶
PatternToMsg takes a raw pattern named "n" with the contents "p" and formats a protocol message ready for the wire.
func SequenceToPattern ¶
SequenceToPattern converts a sequence of bytes into a pattern of the specified length. The pattern will be repeated up to the maximum length, and truncated. So if the input sequence is longer than the length it will simply be truncated. If the length is a multiple of the pattern length, the output pattern won't be truncated. If its not a multiple, then the bytes that fit will be repeated.
Types ¶
type PatternEntry ¶
type PatternEntry struct { Sourcer func(s []byte, l int) []byte // Function to create pattern Sinker func(s []byte, p []byte) error // Function to check pattern SequenceData []byte // Sequence bytes }
func (*PatternEntry) NewMessage ¶
func (pat *PatternEntry) NewMessage(pn string, l int) []byte
(pm *PatternEntry)NewMessage returns a protocol message using the specified PatternEntry and length
type Sink ¶
type Sink struct { GoodFrames int64 // Count of good frames received FramingErr int64 // Count of framing errors ProtocolErr int64 // Count of protocol errors ChecksumErr int64 // Count of checksum errors PatternErr int64 // Count of pattern errors // contains filtered or unexported fields }
Sink holds the context for received data. It contains state information, residual data, and counters.
func NewSink ¶
NewSink() creates a new sink. If we expect that we are not going to be initially synchronized (in the case that the agent is started independently on two machines) set preSync to false to indicate that it is expected that we will be initially unsynchronized. For loopback tests, set preSync to true. This ensures we count spurious bytes correctly.