Documentation ¶
Overview ¶
Package networkserver provides a LoRaWAN-compliant Network Server implementation.
Index ¶
- Variables
- func CreateDevice(ctx context.Context, r DeviceRegistry, dev *ttnpb.EndDevice, paths ...string) (*ttnpb.EndDevice, context.Context, error)
- func DeleteDevice(ctx context.Context, r DeviceRegistry, appID *ttnpb.ApplicationIdentifiers, ...) error
- type ApplicationUplinkQueue
- type ApplicationUplinkQueueConfig
- type ApplicationUplinkQueueDrainFunc
- type Config
- type DeviceRegistry
- type DownlinkPriorities
- type DownlinkPriorityConfig
- type DownlinkTaskQueue
- type DownlinkTaskQueueConfig
- type InteropClient
- type InteropConfig
- type MACSettingConfig
- type NetworkServer
- func (ns *NetworkServer) Context() context.Context
- func (ns *NetworkServer) Delete(ctx context.Context, req *ttnpb.EndDeviceIdentifiers) (*emptypb.Empty, error)
- func (ns *NetworkServer) DownlinkQueueList(ctx context.Context, ids *ttnpb.EndDeviceIdentifiers) (*ttnpb.ApplicationDownlinks, error)
- func (ns *NetworkServer) DownlinkQueuePush(ctx context.Context, req *ttnpb.DownlinkQueueRequest) (*emptypb.Empty, error)
- func (ns *NetworkServer) DownlinkQueueReplace(ctx context.Context, req *ttnpb.DownlinkQueueRequest) (*emptypb.Empty, error)
- func (ns *NetworkServer) GenerateDevAddr(ctx context.Context, req *emptypb.Empty) (*ttnpb.GenerateDevAddrResponse, error)
- func (ns *NetworkServer) Get(ctx context.Context, req *ttnpb.GetEndDeviceRequest) (*ttnpb.EndDevice, error)
- func (ns *NetworkServer) GetDefaultMACSettings(ctx context.Context, req *ttnpb.GetDefaultMACSettingsRequest) (*ttnpb.MACSettings, error)
- func (ns *NetworkServer) GetDeviceAddressPrefixes(ctx context.Context, _ *emptypb.Empty) (*ttnpb.GetDeviceAdressPrefixesResponse, error)
- func (ns *NetworkServer) GetNetID(ctx context.Context, _ *emptypb.Empty) (*ttnpb.GetNetIDResponse, error)
- func (ns *NetworkServer) HandleUplink(ctx context.Context, up *ttnpb.UplinkMessage) (_ *emptypb.Empty, err error)
- func (ns *NetworkServer) RegisterHandlers(s *runtime.ServeMux, conn *grpc.ClientConn)
- func (ns *NetworkServer) RegisterServices(s *grpc.Server)
- func (ns *NetworkServer) ReportTxAcknowledgment(ctx context.Context, txAck *ttnpb.GatewayTxAcknowledgment) (*emptypb.Empty, error)
- func (ns *NetworkServer) ResetFactoryDefaults(ctx context.Context, req *ttnpb.ResetAndGetEndDeviceRequest) (*ttnpb.EndDevice, error)
- func (ns *NetworkServer) Roles() []ttnpb.ClusterRole
- func (ns *NetworkServer) Set(ctx context.Context, req *ttnpb.SetEndDeviceRequest) (*ttnpb.EndDevice, error)
- type Option
- type RegistryCleaner
- type ScheduledDownlinkMatcher
- type UplinkDeduplicator
- type UplinkMatch
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = Config{ ApplicationUplinkQueue: ApplicationUplinkQueueConfig{ BufferSize: 1000, NumConsumers: 1, FastBufferSize: 16384, FastNumConsumers: 128, }, DownlinkTaskQueue: DownlinkTaskQueueConfig{ NumConsumers: 1, }, 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.RxDelay_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.
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 // Pop groups up to limit most recent application uplinks in the queue // by their application ID and calls f on each group. // Context passed to f must be derived from ctx. // Implementations must respect ctx.Done() value on best-effort basis. Pop(ctx context.Context, consumerID string, limit int, f func(context.Context, []*ttnpb.ApplicationUp) error) error }
type ApplicationUplinkQueueConfig ¶ added in v3.8.7
type ApplicationUplinkQueueConfig struct { Queue ApplicationUplinkQueue `name:"-"` BufferSize uint64 `name:"buffer-size"` NumConsumers uint64 `name:"num-consumers"` FastBufferSize uint64 `name:"fast-buffer-size"` FastNumConsumers uint64 `name:"fast-num-consumers"` }
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:"-"` DownlinkTaskQueue DownlinkTaskQueueConfig `name:"downlink-task-queue"` UplinkDeduplicator UplinkDeduplicator `name:"-"` ScheduledDownlinkMatcher ScheduledDownlinkMatcher `name:"-"` NetID types.NetID `name:"net-id" description:"NetID of this Network Server"` ClusterID string `name:"cluster-id" description:"Cluster ID 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 InteropConfig `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, 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) Range(ctx context.Context, paths []string, f func(context.Context, *ttnpb.EndDeviceIdentifiers, *ttnpb.EndDevice) bool) error BatchGetByID( ctx context.Context, appID *ttnpb.ApplicationIdentifiers, deviceIDs []string, paths []string, ) ([]*ttnpb.EndDevice, error) BatchDelete( ctx context.Context, appIDs *ttnpb.ApplicationIdentifiers, deviceIDs []string, ) ([]*ttnpb.EndDeviceIdentifiers, 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 ¶
func (c DownlinkPriorityConfig) Parse() (DownlinkPriorities, error)
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 // Dispatch dispatches the tasks in the queue. Dispatch(ctx context.Context, consumerID string) 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. // consumerID should be a unique ID for this consumer. Pop(ctx context.Context, consumerID string, f func(context.Context, *ttnpb.EndDeviceIdentifiers, time.Time) (time.Time, error)) error }
DownlinkTaskQueue represents an entity, that holds downlink tasks sorted by timestamp.
type DownlinkTaskQueueConfig ¶ added in v3.14.2
type DownlinkTaskQueueConfig struct { Queue DownlinkTaskQueue `name:"-"` NumConsumers uint64 `name:"num-consumers"` }
ApplicationUplinkQueueConfig defines downlink task queue configuration.
type InteropClient ¶
type InteropClient interface { HandleJoinRequest( ctx context.Context, netID types.NetID, nsID *types.EUI64, req *ttnpb.JoinRequest, ) (*ttnpb.JoinResponse, error) }
InteropClient is a client, which Network Server can use for interoperability.
type InteropConfig ¶ added in v3.24.1
type InteropConfig struct { config.InteropClient `name:",squash"` ID *types.EUI64 `name:"id" description:"NSID of this Network Server (EUI)"` }
InteropConfig represents interoperability client configuration.
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 ¶
func (c MACSettingConfig) Parse() (*ttnpb.MACSettings, error)
Parse parses the configuration and returns ttnpb.MACSettings.
type NetworkServer ¶
type NetworkServer struct { ttnpb.UnimplementedAsNsServer ttnpb.UnimplementedGsNsServer ttnpb.UnimplementedNsEndDeviceRegistryServer ttnpb.UnimplementedNsServer *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 (*NetworkServer) Context ¶
func (ns *NetworkServer) Context() context.Context
Context returns the context of the Network Server.
func (*NetworkServer) Delete ¶
func (ns *NetworkServer) Delete(ctx context.Context, req *ttnpb.EndDeviceIdentifiers) (*emptypb.Empty, error)
Delete implements NsEndDeviceRegistryServer.
func (*NetworkServer) DownlinkQueueList ¶
func (ns *NetworkServer) DownlinkQueueList(ctx context.Context, ids *ttnpb.EndDeviceIdentifiers) (*ttnpb.ApplicationDownlinks, error)
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) (*emptypb.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) (*emptypb.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 *emptypb.Empty) (*ttnpb.GenerateDevAddrResponse, error)
GenerateDevAddr returns a device address assignment in the device address range of the network server.
func (*NetworkServer) Get ¶
func (ns *NetworkServer) Get(ctx context.Context, req *ttnpb.GetEndDeviceRequest) (*ttnpb.EndDevice, error)
Get implements NsEndDeviceRegistryServer.
func (*NetworkServer) GetDefaultMACSettings ¶ added in v3.14.0
func (ns *NetworkServer) GetDefaultMACSettings(ctx context.Context, req *ttnpb.GetDefaultMACSettingsRequest) (*ttnpb.MACSettings, error)
func (*NetworkServer) GetDeviceAddressPrefixes ¶ added in v3.21.2
func (ns *NetworkServer) GetDeviceAddressPrefixes( ctx context.Context, _ *emptypb.Empty, ) (*ttnpb.GetDeviceAdressPrefixesResponse, error)
GetDeviceAddressPrefixes return the configured device address prefixes of the Network Server.
func (*NetworkServer) GetNetID ¶ added in v3.21.2
func (ns *NetworkServer) GetNetID(ctx context.Context, _ *emptypb.Empty) (*ttnpb.GetNetIDResponse, error)
GetNetID returns the NetID of the Network Server.
func (*NetworkServer) HandleUplink ¶
func (ns *NetworkServer) HandleUplink(ctx context.Context, up *ttnpb.UplinkMessage) (_ *emptypb.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, txAck *ttnpb.GatewayTxAcknowledgment, ) (*emptypb.Empty, 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 ¶
func (ns *NetworkServer) Set(ctx context.Context, req *ttnpb.SetEndDeviceRequest) (*ttnpb.EndDevice, error)
Set implements NsEndDeviceRegistryServer.
type RegistryCleaner ¶ added in v3.16.0
type RegistryCleaner struct { DevRegistry DeviceRegistry LocalSet map[string]struct{} }
RegistryCleaner is a service responsible for cleanup of the device registry.
func (*RegistryCleaner) CleanData ¶ added in v3.16.0
func (cleaner *RegistryCleaner) CleanData(ctx context.Context, isSet map[string]struct{}) error
CleanData cleans registry device data.
func (*RegistryCleaner) DeleteDeviceData ¶ added in v3.16.0
func (cleaner *RegistryCleaner) DeleteDeviceData(ctx context.Context, devSet []string) error
DeleteComplement deletes registry application data of all devices in the device id list.
func (*RegistryCleaner) RangeToLocalSet ¶ added in v3.16.0
func (cleaner *RegistryCleaner) RangeToLocalSet(ctx context.Context) error
RangeToLocalSet returns a set of devices that have data in the registry.
type ScheduledDownlinkMatcher ¶ added in v3.13.3
type ScheduledDownlinkMatcher interface { // Add stores metadata for a scheduled downlink message. Implementations may use the downlink // message correlation IDs to uniquely identify the scheduled downlink message. Add(ctx context.Context, down *ttnpb.DownlinkMessage) error // Match matches metadata of a scheduled downlink message from a TxAcknowledgement that was received by a gateway. // In case of a successful match, the scheduled downlink message is returned. If no downlink is matched, then an // error is returned instead. Implementations are free to return an error even when a match should have been // successful, for example if a long time has passed since the downlink was scheduled. Match(ctx context.Context, ack *ttnpb.TxAcknowledgment) (*ttnpb.DownlinkMessage, error) }
ScheduledDownlinkMatcher matches scheduled downlinks with the TxAcknowledgement received by a gateway.
type UplinkDeduplicator ¶
type UplinkDeduplicator interface { // DeduplicateUplink deduplicates an uplink message for specified time.Duration, in the provided round. // DeduplicateUplink returns true if the uplink is not a duplicate or false and error, if any, otherwise. DeduplicateUplink( ctx context.Context, up *ttnpb.UplinkMessage, window time.Duration, limit int, round uint64, ) (first bool, err error) // AccumulatedMetadata returns accumulated metadata for specified uplink message in the provided round and error, if any. AccumulatedMetadata(ctx context.Context, up *ttnpb.UplinkMessage, round uint64) (mds []*ttnpb.RxMetadata, err 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 }
Source Files ¶
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. |