io

package
v3.30.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package io contains the interface between server implementations and the gateway frontends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustUplinkToken

func MustUplinkToken(ids *ttnpb.GatewayAntennaIdentifiers, timestamp uint32, concentratorTime scheduling.ConcentratorTime, serverTime time.Time, gatewayTime *time.Time) []byte

MustUplinkToken returns an uplink token from the given downlink path. This function panics if an error occurs. Use UplinkToken to handle errors.

func ParseUplinkToken

func ParseUplinkToken(buf []byte) (*ttnpb.UplinkToken, error)

ParseUplinkToken returns the downlink path from the given uplink token.

func UniqueUplinkMessagesByRSSI added in v3.14.0

func UniqueUplinkMessagesByRSSI(uplinks []*ttnpb.UplinkMessage) []*ttnpb.UplinkMessage

UniqueUplinkMessagesByRSSI returns the given list of gateway uplink messages after discarding duplicates by RSSI. Two gateway uplink messages are considered duplicates if the RawPayload is identical, and the RSSI values differ. In these cases, only the gateway uplink message with the highest RSSI will be included in the result.

UniqueUplinkMessagesByRSSI will allocate a new list of uplink messages, but will not copy the uplink messages themselves.

func UplinkToken

func UplinkToken(ids *ttnpb.GatewayAntennaIdentifiers, timestamp uint32, concentratorTime scheduling.ConcentratorTime, serverTime time.Time, gatewayTime *time.Time) ([]byte, error)

UplinkToken returns an uplink token from the given downlink path.

Types

type Connection

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

Connection is a connection to a gateway managed by a frontend.

func NewConnection

func NewConnection(
	ctx context.Context,
	frontend Frontend,
	gateway *ttnpb.Gateway,
	fps *frequencyplans.Store,
	enforceDutyCycle bool,
	scheduleAnytimeDelay *time.Duration,
	addr *ttnpb.GatewayRemoteAddress,
	opts ...ConnectionOption,
) (*Connection, error)

NewConnection instantiates a new gateway connection.

func (*Connection) BandID

func (c *Connection) BandID() string

BandID returns the common band ID for the frequency plans in this connection. TODO: Handle mixed bands (https://github.com/TheThingsNetwork/lorawan-stack/issues/1394)

func (*Connection) ConnectTime

func (c *Connection) ConnectTime() time.Time

ConnectTime returns the time the gateway connected.

func (*Connection) Context

func (c *Connection) Context() context.Context

Context returns the connection context.

func (*Connection) Disconnect

func (c *Connection) Disconnect(err error)

Disconnect marks the connection as disconnected and cancels the context.

func (*Connection) Down

func (c *Connection) Down() <-chan *ttnpb.DownlinkMessage

Down returns the downstream channel.

func (*Connection) DownStats

func (c *Connection) DownStats() (total uint64, t time.Time, ok bool)

DownStats returns the downstream statistics.

func (*Connection) FrequencyPlans

func (c *Connection) FrequencyPlans() []*frequencyplans.FrequencyPlan

FrequencyPlans returns the frequency plans for the gateway.

func (*Connection) Frontend

func (c *Connection) Frontend() Frontend

Frontend returns the frontend using this connection.

func (*Connection) Gateway

func (c *Connection) Gateway() *ttnpb.Gateway

Gateway returns the gateway entity.

func (*Connection) GatewayRemoteAddress added in v3.20.2

func (c *Connection) GatewayRemoteAddress() *ttnpb.GatewayRemoteAddress

GatewayRemoteAddress returns the time the remote address of the gateway as seen by the server.

func (*Connection) HandleStatus

func (c *Connection) HandleStatus(status *ttnpb.GatewayStatus) (err error)

HandleStatus updates the status stats and sends the status to the status channel.

func (*Connection) HandleTxAck

func (c *Connection) HandleTxAck(ack *ttnpb.TxAcknowledgment) (err error)

HandleTxAck sends the acknowledgment to the status channel.

func (*Connection) HandleUp

func (c *Connection) HandleUp(up *ttnpb.UplinkMessage, frontendSync *FrontendClockSynchronization) (err error)

HandleUp updates the uplink stats and sends the message to the upstream channel.

func (*Connection) LocationChanged

func (c *Connection) LocationChanged() <-chan struct{}

LocationChanged returns the location updates channel.

func (*Connection) PrimaryFrequencyPlan added in v3.10.0

func (c *Connection) PrimaryFrequencyPlan() *frequencyplans.FrequencyPlan

PrimaryFrequencyPlan returns the primary frequency plan of the gateway.

func (*Connection) RTTStats

func (c *Connection) RTTStats(percentile int, t time.Time) (min, max, median, np time.Duration, count int)

RTTStats returns the recorded round-trip time statistics.

func (*Connection) RecordRTT

func (c *Connection) RecordRTT(d time.Duration, t time.Time)

RecordRTT records the given round-trip time.

func (*Connection) ScheduleDown

func (c *Connection) ScheduleDown(path *ttnpb.DownlinkPath, msg *ttnpb.DownlinkMessage) (rx1, rx2 bool, delay time.Duration, err error)

ScheduleDown schedules and sends a downlink message by using the given path and updates the downlink stats. This method returns an error if the downlink message is not a Tx request.

func (*Connection) SendDown

func (c *Connection) SendDown(msg *ttnpb.DownlinkMessage) error

SendDown sends the downlink message directly on the downlink channel.

func (*Connection) Stats

func (c *Connection) Stats() (*ttnpb.GatewayConnectionStats, []string)

Stats collects and returns the gateway connection statistics and the field mask paths.

func (*Connection) StatsChanged

func (c *Connection) StatsChanged() <-chan struct{}

StatsChanged returns the stats changed channel.

func (*Connection) Status

func (c *Connection) Status() <-chan *ttnpb.GatewayStatus

Status returns the status channel.

func (*Connection) StatusStats

func (c *Connection) StatusStats() (last *ttnpb.GatewayStatus, t time.Time, ok bool)

StatusStats returns the status statistics.

func (*Connection) SyncWithGatewayConcentrator

func (c *Connection) SyncWithGatewayConcentrator(timestamp uint32, server time.Time, gateway *time.Time, concentrator scheduling.ConcentratorTime) scheduling.ConcentratorTime

SyncWithGatewayConcentrator synchronizes the clock with the given concentrator timestamp, the server time and the relative gateway time that corresponds to the given timestamp.

func (*Connection) TimeFromServerTime added in v3.16.0

func (c *Connection) TimeFromServerTime(t time.Time) (scheduling.ConcentratorTime, bool)

TimeFromServerTime returns the concentrator time by the given server time. This method returns false if the clock is not synced with the server.

func (*Connection) TimeFromTimestampTime

func (c *Connection) TimeFromTimestampTime(timestamp uint32) (scheduling.ConcentratorTime, bool)

TimeFromTimestampTime returns the concentrator time by the given timestamp. This method returns false if the clock is not synced with the server.

func (*Connection) TxAck

func (c *Connection) TxAck() <-chan *ttnpb.TxAcknowledgment

TxAck returns the downlink acknowledgments channel.

func (*Connection) TxAckStats added in v3.25.2

func (c *Connection) TxAckStats() (total uint64, t time.Time, ok bool)

TxAckStats return the transmission acknowledgement statistics.

func (*Connection) Up

func (c *Connection) Up() <-chan *ttnpb.GatewayUplinkMessage

Up returns the upstream channel.

func (*Connection) UpStats

func (c *Connection) UpStats() (total uint64, t time.Time, ok bool)

UpStats returns the upstream statistics.

func (*Connection) VersionInfoChanged added in v3.16.1

func (c *Connection) VersionInfoChanged() <-chan struct{}

VersionInfoChanged returns the version info updates channel.

type ConnectionOption added in v3.25.2

type ConnectionOption func(*connectionOptions)

ConnectionOption is a Connection option.

func WithStreamActive added in v3.25.2

func WithStreamActive(f func(MessageStream) bool) ConnectionOption

WithStreamActive overrides the stream activity check function. By default, the streams are always on.

type DownlinkTokens

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

DownlinkTokens stores a set of downlink tokens and can be used to track roundtrip time. The number of downlink tokens stored is fixed to 16. New issued tokens with `Next` overwrite the oldest token.

func (DownlinkTokens) FormatCorrelationID added in v3.12.0

func (t DownlinkTokens) FormatCorrelationID(token uint16) string

FormatCorrelationID formats a correlation ID for a downlink token.

func (DownlinkTokens) Get

Get returns the correlation IDs and time difference between the time given to `Next` and the given time by the token. If the token could not be found, this method returns false.

func (*DownlinkTokens) Next

func (t *DownlinkTokens) Next(msg *ttnpb.DownlinkMessage, time time.Time) uint16

Next returns a new downlink token for a downlink message.

func (DownlinkTokens) ParseTokenFromCorrelationIDs added in v3.12.0

func (t DownlinkTokens) ParseTokenFromCorrelationIDs(cids []string) (uint16, bool)

ParseTokenFromCorrelationIDs parses the correlation ID

type Frontend

type Frontend interface {
	// Protocol returns the protocol used in the frontend.
	Protocol() string
	// SupportsDownlinkClaim returns true if the frontend can itself claim downlinks.
	SupportsDownlinkClaim() bool
	// DutyCycleStyle returns the duty cycle style used by the frontend.
	DutyCycleStyle() scheduling.DutyCycleStyle
}

Frontend provides supported features by the gateway frontend.

type FrontendClockSynchronization added in v3.16.1

type FrontendClockSynchronization struct {
	Timestamp        uint32
	ServerTime       time.Time
	GatewayTime      *time.Time
	ConcentratorTime scheduling.ConcentratorTime
}

FrontendClockSynchronization contains the clock synchronization timestamps provided by a frontend for manual synchronization.

type MessageStream added in v3.25.2

type MessageStream uint32

MessageStream is a message stream.

const (
	UplinkStream   MessageStream = iota // UplinkStream is the uplink message stream.
	DownlinkStream                      // DownlinkStream is the downlink message stream.
	TxAckStream                         // TxAckStream is the transmission acknowledgment stream.
	StatusStream                        // StatusStream is the status message stream.
	RTTStream                           // RTTStream is the round-trip times stream.
)

type Server

type Server interface {
	// GetBaseConfig returns the component configuration.
	GetBaseConfig(ctx context.Context) config.ServiceBase
	// FillGatewayContext fills the given context and identifiers.
	// This method should only be used for request contexts.
	FillGatewayContext(
		ctx context.Context, ids *ttnpb.GatewayIdentifiers,
	) (context.Context, *ttnpb.GatewayIdentifiers, error)
	// AssertGatewayRights checks that the caller has the required rights over the provided gateway identifiers.
	AssertGatewayRights(ctx context.Context, ids *ttnpb.GatewayIdentifiers, required ...ttnpb.Right) error
	// Connect connects a gateway by its identifiers to the Gateway Server, and returns a Connection for traffic and
	// control.
	Connect(
		ctx context.Context,
		frontend Frontend,
		ids *ttnpb.GatewayIdentifiers,
		addr *ttnpb.GatewayRemoteAddress,
		opts ...ConnectionOption,
	) (*Connection, error)
	// GetFrequencyPlans gets the frequency plans by the gateway identifiers.
	GetFrequencyPlans(ctx context.Context,
		ids *ttnpb.GatewayIdentifiers) (map[string]*frequencyplans.FrequencyPlan, error)
	// ClaimDownlink claims the downlink path for the given gateway.
	ClaimDownlink(ctx context.Context, ids *ttnpb.GatewayIdentifiers) error
	// UnclaimDownlink releases the claim of the downlink path for the given gateway.
	UnclaimDownlink(ctx context.Context, ids *ttnpb.GatewayIdentifiers) error
	// FromRequestContext decouples the lifetime of the provided context from the values found in the context.
	FromRequestContext(ctx context.Context) context.Context
	// RateLimiter returns the rate limiter instance.
	RateLimiter() ratelimit.Interface
	// ValidateGatewayID validates the ID of the gateway.
	ValidateGatewayID(ctx context.Context, ids *ttnpb.GatewayIdentifiers) error
	task.Starter
}

Server represents the Gateway Server to gateway frontends.

Directories

Path Synopsis
ws
Package ws provides common interface for Web Socket front end.
Package ws provides common interface for Web Socket front end.
id6
Package id6 provides translation functions to the ID6 format.
Package id6 provides translation functions to the ID6 format.

Jump to

Keyboard shortcuts

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