networkserver

package
v3.13.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Overview

Package networkserver provides a LoRaWAN-compliant Network Server implementation.

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	ApplicationUplinkQueue: ApplicationUplinkQueueConfig{
		BufferSize: 1000,
	},
	DeduplicationWindow: 200 * time.Millisecond,
	CooldownWindow:      time.Second,
	DownlinkPriorities: DownlinkPriorityConfig{
		JoinAccept:             "highest",
		MACCommands:            "highest",
		MaxApplicationDownlink: "high",
	},
	DefaultMACSettings: MACSettingConfig{
		ADRMargin:              func(v float32) *float32 { return &v }(mac.DefaultADRMargin),
		DesiredRx1Delay:        func(v ttnpb.RxDelay) *ttnpb.RxDelay { return &v }(ttnpb.RX_DELAY_5),
		ClassBTimeout:          func(v time.Duration) *time.Duration { return &v }(mac.DefaultClassBTimeout),
		ClassCTimeout:          func(v time.Duration) *time.Duration { return &v }(mac.DefaultClassCTimeout),
		StatusTimePeriodicity:  func(v time.Duration) *time.Duration { return &v }(mac.DefaultStatusTimePeriodicity),
		StatusCountPeriodicity: func(v uint32) *uint32 { return &v }(mac.DefaultStatusCountPeriodicity),
	},
	DownlinkQueueCapacity: 10000,
}

DefaultConfig is the default Network Server configuration.

View Source
var (
	DefaultOptions []Option
)

Functions

func CreateDevice added in v3.9.1

func CreateDevice(ctx context.Context, r DeviceRegistry, dev *ttnpb.EndDevice, paths ...string) (*ttnpb.EndDevice, context.Context, error)

CreateDevice creates device dev in r.

func DeleteDevice added in v3.9.1

func DeleteDevice(ctx context.Context, r DeviceRegistry, appID ttnpb.ApplicationIdentifiers, devID string) error

DeleteDevice deletes device identified by appID, devID from r.

Types

type ApplicationUplinkQueue

type ApplicationUplinkQueue interface {
	// Add adds application uplinks ups to queue.
	// Implementations must ensure that Add returns fast.
	Add(ctx context.Context, ups ...*ttnpb.ApplicationUp) error

	// PopApplication calls f on the most recent application uplink task in the schedule, for which timestamp is in range [0, time.Now()],
	// if such is available, otherwise it blocks until it is.
	// Context passed to f must be derived from ctx.
	// Implementations must respect ctx.Done() value on best-effort basis.
	Pop(ctx context.Context, f func(context.Context, ttnpb.ApplicationIdentifiers, ApplicationUplinkQueueDrainFunc) (time.Time, error)) error
}

type ApplicationUplinkQueueConfig added in v3.8.7

type ApplicationUplinkQueueConfig struct {
	Queue      ApplicationUplinkQueue `name:"-"`
	BufferSize uint64                 `name:"buffer-size"`
}

ApplicationUplinkQueueConfig defines application uplink queue configuration.

type ApplicationUplinkQueueDrainFunc added in v3.11.2

type ApplicationUplinkQueueDrainFunc func(limit int, f func(...*ttnpb.ApplicationUp) error) error

type Config

type Config struct {
	ApplicationUplinkQueue ApplicationUplinkQueueConfig `name:"application-uplink-queue"`
	Devices                DeviceRegistry               `name:"-"`
	DownlinkTasks          DownlinkTaskQueue            `name:"-"`
	UplinkDeduplicator     UplinkDeduplicator           `name:"-"`
	NetID                  types.NetID                  `name:"net-id" description:"NetID of this Network Server"`
	DevAddrPrefixes        []types.DevAddrPrefix        `name:"dev-addr-prefixes" description:"Device address prefixes of this Network Server"`
	DeduplicationWindow    time.Duration                `name:"deduplication-window" description:"Time window during which, duplicate messages are collected for metadata"`
	CooldownWindow         time.Duration                `` /* 138-byte string literal not displayed */
	DownlinkPriorities     DownlinkPriorityConfig       `name:"downlink-priorities" description:"Downlink message priorities"`
	DefaultMACSettings     MACSettingConfig             `` /* 128-byte string literal not displayed */
	Interop                config.InteropClient         `name:"interop" description:"Interop client configuration"`
	DeviceKEKLabel         string                       `name:"device-kek-label" description:"Label of KEK used to encrypt device keys at rest"`
	DownlinkQueueCapacity  int                          `name:"downlink-queue-capacity" description:"Maximum downlink queue size per-session"`
}

Config represents the NetworkServer configuration.

type DeviceRegistry

type DeviceRegistry interface {
	GetByEUI(ctx context.Context, joinEUI, devEUI types.EUI64, paths []string) (*ttnpb.EndDevice, context.Context, error)
	GetByID(ctx context.Context, appID ttnpb.ApplicationIdentifiers, devID string, paths []string) (*ttnpb.EndDevice, context.Context, error)
	RangeByUplinkMatches(ctx context.Context, up *ttnpb.UplinkMessage, cacheTTL time.Duration, f func(context.Context, *UplinkMatch) (bool, error)) error
	SetByID(ctx context.Context, appID ttnpb.ApplicationIdentifiers, devID string, paths []string, f func(context.Context, *ttnpb.EndDevice) (*ttnpb.EndDevice, []string, error)) (*ttnpb.EndDevice, context.Context, error)
}

DeviceRegistry is a registry, containing devices.

type DownlinkPriorities

type DownlinkPriorities struct {
	// JoinAccept is the downlink priority for join-accept messages.
	JoinAccept,

	MACCommands,

	MaxApplicationDownlink ttnpb.TxSchedulePriority
}

DownlinkPriorities define the schedule priorities for the different types of downlink.

type DownlinkPriorityConfig

type DownlinkPriorityConfig struct {
	// JoinAccept is the downlink priority for join-accept messages.
	JoinAccept string `` /* 131-byte string literal not displayed */
	// MACCommands is the downlink priority for downlink messages with MAC commands as FRMPayload (FPort = 0) or as FOpts.
	// If the MAC commands are carried in FOpts, the highest priority of this value and the concerning application
	// downlink message's priority is used.
	MACCommands string `` /* 142-byte string literal not displayed */
	// MaxApplicationDownlink is the highest priority permitted by the Network Server for application downlink.
	MaxApplicationDownlink string `` /* 161-byte string literal not displayed */
}

DownlinkPriorityConfig defines priorities for downlink messages.

func (DownlinkPriorityConfig) Parse

Parse attempts to parse the configuration and returns a DownlinkPriorities.

type DownlinkTaskQueue

type DownlinkTaskQueue interface {
	// Add adds downlink task for device identified by devID at time t.
	// Implementations must ensure that Add returns fast.
	Add(ctx context.Context, devID ttnpb.EndDeviceIdentifiers, t time.Time, replace bool) error

	// Pop calls f on the most recent downlink task in the schedule, for which timestamp is in range [0, time.Now()],
	// if such is available, otherwise it blocks until it is.
	// Context passed to f must be derived from ctx.
	// Implementations must respect ctx.Done() value on best-effort basis.
	Pop(ctx context.Context, f func(context.Context, ttnpb.EndDeviceIdentifiers, time.Time) (time.Time, error)) error
}

DownlinkTaskQueue represents an entity, that holds downlink tasks sorted by timestamp.

type InteropClient

type InteropClient interface {
	HandleJoinRequest(context.Context, types.NetID, *ttnpb.JoinRequest) (*ttnpb.JoinResponse, error)
}

InteropClient is a client, which Network Server can use for interoperability.

type MACSettingConfig

type MACSettingConfig struct {
	ADRMargin                  *float32                   `` /* 135-byte string literal not displayed */
	DesiredRx1Delay            *ttnpb.RxDelay             `` /* 130-byte string literal not displayed */
	DesiredMaxDutyCycle        *ttnpb.AggregatedDutyCycle `` /* 139-byte string literal not displayed */
	DesiredADRAckLimitExponent *ttnpb.ADRAckLimitExponent `` /* 148-byte string literal not displayed */
	DesiredADRAckDelayExponent *ttnpb.ADRAckDelayExponent `` /* 148-byte string literal not displayed */
	ClassBTimeout              *time.Duration             `` /* 164-byte string literal not displayed */
	ClassCTimeout              *time.Duration             `` /* 164-byte string literal not displayed */
	StatusTimePeriodicity      *time.Duration             `` /* 170-byte string literal not displayed */
	StatusCountPeriodicity     *uint32                    `` /* 184-byte string literal not displayed */
}

MACSettingConfig defines MAC-layer configuration.

func (MACSettingConfig) Parse

Parse parses the configuration and returns ttnpb.MACSettings.

type NetworkServer

type NetworkServer struct {
	*component.Component
	// contains filtered or unexported fields
}

NetworkServer implements the Network Server component.

The Network Server exposes the GsNs, AsNs, DeviceRegistry and ApplicationDownlinkQueue services.

func New

func New(c *component.Component, conf *Config, opts ...Option) (*NetworkServer, error)

New returns new NetworkServer.

func (*NetworkServer) Context

func (ns *NetworkServer) Context() context.Context

Context returns the context of the Network Server.

func (*NetworkServer) Delete

Delete implements NsEndDeviceRegistryServer.

func (*NetworkServer) DownlinkQueueList

DownlinkQueueList is called by the Application Server to get the current state of the downlink queue for a device.

func (*NetworkServer) DownlinkQueuePush

func (ns *NetworkServer) DownlinkQueuePush(ctx context.Context, req *ttnpb.DownlinkQueueRequest) (*pbtypes.Empty, error)

DownlinkQueuePush is called by the Application Server to push a downlink to queue for a device.

func (*NetworkServer) DownlinkQueueReplace

func (ns *NetworkServer) DownlinkQueueReplace(ctx context.Context, req *ttnpb.DownlinkQueueRequest) (*pbtypes.Empty, error)

DownlinkQueueReplace is called by the Application Server to completely replace the downlink queue for a device.

func (*NetworkServer) GenerateDevAddr

func (ns *NetworkServer) GenerateDevAddr(ctx context.Context, req *types.Empty) (*ttnpb.GenerateDevAddrResponse, error)

GenerateDevAddr returns a device address assignment in the device address range of the network server.

func (*NetworkServer) Get

Get implements NsEndDeviceRegistryServer.

func (ns *NetworkServer) HandleUplink(ctx context.Context, up *ttnpb.UplinkMessage) (_ *pbtypes.Empty, err error)

HandleUplink is called by the Gateway Server when an uplink message arrives.

func (*NetworkServer) RegisterHandlers

func (ns *NetworkServer) RegisterHandlers(s *runtime.ServeMux, conn *grpc.ClientConn)

RegisterHandlers registers gRPC handlers.

func (*NetworkServer) RegisterServices

func (ns *NetworkServer) RegisterServices(s *grpc.Server)

RegisterServices registers services provided by ns at s.

func (*NetworkServer) ReportTxAcknowledgment added in v3.12.0

func (ns *NetworkServer) ReportTxAcknowledgment(ctx context.Context, up *ttnpb.GatewayTxAcknowledgment) (_ *pbtypes.Empty, err error)

ReportTxAcknowledgment is called by the Gateway Server when a tx acknowledgment arrives.

func (*NetworkServer) ResetFactoryDefaults added in v3.11.0

func (ns *NetworkServer) ResetFactoryDefaults(ctx context.Context, req *ttnpb.ResetAndGetEndDeviceRequest) (*ttnpb.EndDevice, error)

ResetFactoryDefaults implements NsEndDeviceRegistryServer.

func (*NetworkServer) Roles

func (ns *NetworkServer) Roles() []ttnpb.ClusterRole

Roles returns the roles that the Network Server fulfills.

func (*NetworkServer) Set

Set implements NsEndDeviceRegistryServer.

type Option

type Option func(ns *NetworkServer)

Option configures the NetworkServer.

type UplinkDeduplicator

type UplinkDeduplicator interface {
	// DeduplicateUplink deduplicates an uplink message for specified time.Duration.
	// DeduplicateUplink returns true if the uplink is not a duplicate or false and error, if any, otherwise.
	DeduplicateUplink(context.Context, *ttnpb.UplinkMessage, time.Duration) (bool, error)
	// AccumulatedMetadata returns accumulated metadata for specified uplink message and error, if any.
	AccumulatedMetadata(context.Context, *ttnpb.UplinkMessage) ([]*ttnpb.RxMetadata, error)
}

UplinkDeduplicator represents an entity, that deduplicates uplinks and accumulates metadata.

type UplinkMatch added in v3.10.0

type UplinkMatch struct {
	ApplicationIdentifiers ttnpb.ApplicationIdentifiers
	DeviceID               string
	LoRaWANVersion         ttnpb.MACVersion
	FNwkSIntKey            *ttnpb.KeyEnvelope
	LastFCnt               uint32
	ResetsFCnt             *ttnpb.BoolValue
	Supports32BitFCnt      *ttnpb.BoolValue
	IsPending              bool
}

Directories

Path Synopsis
Internal package contains various Network Server utilities
Internal package contains various Network Server utilities
test
Package test contains testing utilities usable by all subpackages of networkserver including itself.
Package test contains testing utilities usable by all subpackages of networkserver including itself.
test/shared
Package test contains testing utilities usable by all subpackages of networkserver excluding itself.
Package test contains testing utilities usable by all subpackages of networkserver excluding itself.
time
Package time wraps "time" and allows for custom implementations of key functions.
Package time wraps "time" and allows for custom implementations of key functions.
Package redis provides Redis implementations of interfaces used by networkserver.
Package redis provides Redis implementations of interfaces used by networkserver.

Jump to

Keyboard shortcuts

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