ether

package
v0.0.0-...-3ae95b5 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDeviceNotRegistered = errors.New("device not registered with the ether")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Logger          logr.Logger
	Clock           clockwork.Clock
	PacketTransform PacketTransform
}

Config configures the behaviour of the Ether

type Ether

type Ether struct {
	// contains filtered or unexported fields
}

Ether allows for modelling a radio transmission medium when using fake.Device to simulate radio devices

func New

func New(cfg Config) *Ether

New creates a new Ether

func (*Ether) Close

func (e *Ether) Close() error

Close gracefully shuts down the Ether and any background tasks

func (*Ether) RegisterDevice

func (e *Ether) RegisterDevice(device *fake.Device)

RegisterDevice connects a fake device to the ether so that its transmissions are propagated, and it may receive transmissions from other connected fake devices

func (*Ether) UnregisterDevice

func (e *Ether) UnregisterDevice(device *fake.Device)

UnregisterDevice removes a fake device from the ether, preventing further transmissions from reaching this device

type PacketTransform

type PacketTransform func(transmitter, receiver *fake.Device, packet []byte) TransformOutcome

A PacketTransform is both a predicate and map function for packets transmitted through the Ether: - If the resulting outcome has a nil packet then no packet will be delivered to the receiver - Otherwise the resulting packet will be scheduled to arrive after a specified delay

By providing custom PacketTransform functions, callers can add in logic to more accurately represent their transmission medium: adding in delays, corrupting the received packet, preventing receipt, etc.

func AddPacketDeliveryDelay

func AddPacketDeliveryDelay(transform PacketTransform, delay time.Duration) PacketTransform

AddPacketDeliveryDelay takes a PacketTransform and adds a delay to the resulting TransformOutcome

type TransformOutcome

type TransformOutcome struct {
	ReceivedPacket []byte
	FlightTime     time.Duration
}

TransformOutcome describes a packet that will be delivered to a receiver, created by a PacketTransform

func PerfectPacketTransform

func PerfectPacketTransform(_, _ *fake.Device, packet []byte) TransformOutcome

PerfectPacketTransform is a simple PacketTransform that always delivers all packets with no arrival delay

Jump to

Keyboard shortcuts

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