ldp

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2021 License: GPL-2.0, GPL-2.0-or-later Imports: 8 Imported by: 1

README

Package loopback implements that Platina Link Diagnostic Protocol.

© 2019 Platina Systems, Inc. All rights reserved. Use of this source code is governed by this GPL-2 [LICENSE].

Documentation

Overview

Package ldp implements the Platina Link Diagnostic Protocol

Index

Constants

View Source
const (
	// Pattern header
	Pattern = "Pattern: "
	Length  = "Length: "
	SHA256  = "Sha256: "

	// Special patterns
	Alpha     = "Alpha"
	AlphaTest = "The quick brown fox jumps over the lazy dog"
)

Variables

View Source
var ErrPatternMismatch = errors.New("Pattern data mismatch")
View Source
var ErrPatternUnknown = errors.New("Pattern unknown")
View Source
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

func CheckPattern(s []byte, p []byte) (err error)

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

func NewMessage(pn string, l int) (p []byte, err error)

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

func PatternToMsg(n string, p []byte) (m []byte)

PatternToMsg takes a raw pattern named "n" with the contents "p" and formats a protocol message ready for the wire.

func SequenceToPattern

func SequenceToPattern(s []byte, l int) (p []byte)

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

func NewSink(preSync bool) (s *Sink)

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.

func (*Sink) Write

func (s *Sink) Write(p []byte) (n int, err error)

Write() - write into the sink. Write bytes received into the sink, frame and parse.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL