storage

package
v2.4.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2018 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RX1 = iota
	RX2
)

Available RX window options.

View Source
const (
	ModulationFSK  = "FSK"
	ModulationLoRa = "LORA"
)

Modulations

View Source
const (
	DeviceProfileKeyTempl = "lora:ns:dp:%s"
)

Templates used for generating Redis keys

View Source
const (
	ServiceProfileKeyTempl = "lora:ns:sp:%s"
)

Templates used for generating Redis keys

View Source
const UplinkHistorySize = 20

UplinkHistorySize contains the number of frames to store

Variables

View Source
var (
	ErrAlreadyExists                  = errors.New("object already exists")
	ErrDoesNotExist                   = errors.New("object does not exist")
	ErrDoesNotExistOrFCntOrMICInvalid = errors.New("device-session does not exist or invalid fcnt or mic")
	ErrInvalidAggregationInterval     = errors.New("invalid aggregation interval")
	ErrInvalidName                    = errors.New("invalid gateway name")
	ErrInvalidFPort                   = errors.New("invalid fPort (must be > 0)")
)

errors

Functions

func AddDeviceToMulticastGroup

func AddDeviceToMulticastGroup(db sqlx.Execer, devEUI lorawan.EUI64, multicastGroupID uuid.UUID) error

AddDeviceToMulticastGroup adds the given device to the given multicast-group.

func CreateDevice

func CreateDevice(db sqlx.Execer, d *Device) error

CreateDevice creates the given device.

func CreateDeviceActivation

func CreateDeviceActivation(db sqlx.Queryer, da *DeviceActivation) error

CreateDeviceActivation creates the given device-activation.

func CreateDeviceProfile

func CreateDeviceProfile(db sqlx.Execer, dp *DeviceProfile) error

CreateDeviceProfile creates the given device-profile.

func CreateDeviceProfileCache

func CreateDeviceProfileCache(p *redis.Pool, dp DeviceProfile) error

CreateDeviceProfileCache caches the given device-profile in Redis. The TTL of the device-profile is the same as that of the device-sessions.

func CreateDeviceQueueItem

func CreateDeviceQueueItem(db sqlx.Queryer, qi *DeviceQueueItem) error

CreateDeviceQueueItem adds the given item to the device queue.

func CreateGateway

func CreateGateway(db sqlx.Execer, gw *Gateway) error

CreateGateway creates the given gateway.

func CreateGatewayCache

func CreateGatewayCache(p *redis.Pool, gw Gateway) error

CreateGatewayCache caches the given gateway in Redis. The TTL of the gateway is the same as that of the device-sessions.

func CreateGatewayProfile

func CreateGatewayProfile(db sqlx.Execer, c *GatewayProfile) error

CreateGatewayProfile creates the given gateway-profile. As this will execute multiple SQL statements, it is recommended to perform this within a transaction.

func CreateMACCommandQueueItem

func CreateMACCommandQueueItem(p *redis.Pool, devEUI lorawan.EUI64, block MACCommandBlock) error

CreateMACCommandQueueItem creates a new mac-command queue item.

func CreateMulticastGroup

func CreateMulticastGroup(db sqlx.Execer, mg *MulticastGroup) error

CreateMulticastGroup creates the given multi-cast group.

func CreateMulticastQueueItem

func CreateMulticastQueueItem(db sqlx.Queryer, qi *MulticastQueueItem) error

CreateMulticastQueueItem adds the given item to the queue.

func CreateRoutingProfile

func CreateRoutingProfile(db sqlx.Execer, rp *RoutingProfile) error

CreateRoutingProfile creates the given routing-profile.

func CreateServiceProfile

func CreateServiceProfile(db sqlx.Execer, sp *ServiceProfile) error

CreateServiceProfile creates the given service-profile.

func CreateServiceProfileCache

func CreateServiceProfileCache(p *redis.Pool, sp ServiceProfile) error

CreateServiceProfileCache caches the given service-profile into the Redis. This is used for faster lookups, but also in case of roaming where we only want to store the service-profile of a roaming device for a finite duration. The TTL of the service-profile is the same as that of the device-sessions.

func DeleteDevice

func DeleteDevice(db sqlx.Execer, devEUI lorawan.EUI64) error

DeleteDevice deletes the device matching the given DevEUI.

func DeleteDeviceActivationsForDevice

func DeleteDeviceActivationsForDevice(db sqlx.Execer, devEUI lorawan.EUI64) error

DeleteDeviceActivationsForDevice removes the device-activation for the given DevEUI.

func DeleteDeviceGatewayRXInfoSet

func DeleteDeviceGatewayRXInfoSet(p *redis.Pool, devEUI lorawan.EUI64) error

DeleteDeviceGatewayRXInfoSet deletes the device gateway rx-info meta-data for the given Device EUI.

func DeleteDeviceProfile

func DeleteDeviceProfile(db sqlx.Execer, id uuid.UUID) error

DeleteDeviceProfile deletes the device-profile matching the given id.

func DeleteDeviceQueueItem

func DeleteDeviceQueueItem(db sqlx.Execer, id int64) error

DeleteDeviceQueueItem deletes the device-queue item matching the given id.

func DeleteDeviceSession

func DeleteDeviceSession(p *redis.Pool, devEUI lorawan.EUI64) error

DeleteDeviceSession deletes the device-session matching the given DevEUI.

func DeleteGateway

func DeleteGateway(db sqlx.Execer, id lorawan.EUI64) error

DeleteGateway deletes the gateway matching the given Gateway ID.

func DeleteGatewayProfile

func DeleteGatewayProfile(db sqlx.Execer, id uuid.UUID) error

DeleteGatewayProfile deletes the gateway-profile matching the given ID.

func DeleteMACCommandQueueItem

func DeleteMACCommandQueueItem(p *redis.Pool, devEUI lorawan.EUI64, block MACCommandBlock) error

DeleteMACCommandQueueItem deletes the given mac-command from the queue.

func DeleteMulticastGroup

func DeleteMulticastGroup(db sqlx.Execer, id uuid.UUID) error

DeleteMulticastGroup deletes the multicast-group matching the given ID.

func DeleteMulticastQueueItem

func DeleteMulticastQueueItem(db sqlx.Execer, id int64) error

DeleteMulticastQueueItem deletes the queue-item given an id.

func DeletePendingMACCommand

func DeletePendingMACCommand(p *redis.Pool, devEUI lorawan.EUI64, cid lorawan.CID) error

DeletePendingMACCommand removes the pending mac-command for the given CID.

func DeleteRoutingProfile

func DeleteRoutingProfile(db sqlx.Execer, id uuid.UUID) error

DeleteRoutingProfile deletes the routing-profile matching the given id.

func DeleteServiceProfile

func DeleteServiceProfile(db sqlx.Execer, id uuid.UUID) error

DeleteServiceProfile deletes the service-profile matching the given id.

func DeviceSessionExists

func DeviceSessionExists(p *redis.Pool, devEUI lorawan.EUI64) (bool, error)

DeviceSessionExists returns a bool indicating if a device session exist.

func FlushDeviceProfileCache

func FlushDeviceProfileCache(p *redis.Pool, id uuid.UUID) error

FlushDeviceProfileCache deletes a cached device-profile.

func FlushDeviceQueueForDevEUI

func FlushDeviceQueueForDevEUI(db sqlx.Execer, devEUI lorawan.EUI64) error

FlushDeviceQueueForDevEUI deletes all device-queue items for the given DevEUI.

func FlushGatewayCache

func FlushGatewayCache(p *redis.Pool, gatewayID lorawan.EUI64) error

FlushGatewayCache deletes a cached gateway.

func FlushMACCommandQueue

func FlushMACCommandQueue(p *redis.Pool, devEUI lorawan.EUI64) error

FlushMACCommandQueue flushes the mac-command queue for the given DevEUI.

func FlushMulticastQueueForMulticastGroup

func FlushMulticastQueueForMulticastGroup(db sqlx.Execer, multicastGroupID uuid.UUID) error

FlushMulticastQueueForMulticastGroup flushes the multicast-queue given a multicast-group id.

func FlushServiceProfileCache

func FlushServiceProfileCache(p *redis.Pool, id uuid.UUID) error

FlushServiceProfileCache deletes a cached service-profile.

func GetDevEUIsForMulticastGroup

func GetDevEUIsForMulticastGroup(db sqlx.Queryer, multicastGroupID uuid.UUID) ([]lorawan.EUI64, error)

GetDevEUIsForMulticastGroup returns all Device EUIs within the given multicast-group id.

func GetGatewaysForIDs

func GetGatewaysForIDs(db sqlx.Queryer, ids []lorawan.EUI64) (map[lorawan.EUI64]Gateway, error)

GetGatewaysForIDs returns a map of gateways given a slice of IDs.

func GetMaxEmitAtTimeSinceGPSEpochForDevEUI

func GetMaxEmitAtTimeSinceGPSEpochForDevEUI(db sqlx.Queryer, devEUI lorawan.EUI64) (time.Duration, error)

GetMaxEmitAtTimeSinceGPSEpochForDevEUI returns the maximum / last GPS epoch scheduling timestamp for the given DevEUI.

func GetMaxEmitAtTimeSinceGPSEpochForMulticastGroup

func GetMaxEmitAtTimeSinceGPSEpochForMulticastGroup(db sqlx.Queryer, multicastGroupID uuid.UUID) (time.Duration, error)

GetMaxEmitAtTimeSinceGPSEpochForMulticastGroup returns the maximum / last GPS epoch scheduling timestamp for the given multicast-group.

func GetMaxScheduleAtForMulticastGroup

func GetMaxScheduleAtForMulticastGroup(db sqlx.Queryer, multicastGroupID uuid.UUID) (time.Time, error)

GetMaxScheduleAtForMulticastGroup returns the maximum schedule at timestamp for the given multicast-group.

func GetMulticastGroupsForDevEUI

func GetMulticastGroupsForDevEUI(db sqlx.Queryer, devEUI lorawan.EUI64) ([]uuid.UUID, error)

GetMulticastGroupsForDevEUI returns the multicast-group ids to which the given Device EUI belongs.

func GetRandomDevAddr

func GetRandomDevAddr(p *redis.Pool, netID lorawan.NetID) (lorawan.DevAddr, error)

GetRandomDevAddr returns a random DevAddr, prefixed with NwkID based on the given NetID.

func PopDownlinkFrame

func PopDownlinkFrame(p *redis.Pool, token uint32) (lorawan.EUI64, gw.DownlinkFrame, error)

PopDownlinkFrame returns the first downlink-frame for the given token.

func RemoveDeviceFromMulticastGroup

func RemoveDeviceFromMulticastGroup(db sqlx.Execer, devEUI lorawan.EUI64, multicastGroupID uuid.UUID) error

RemoveDeviceFromMulticastGroup removes the given device from the given multicast-group.

func SaveDeviceGatewayRXInfoSet

func SaveDeviceGatewayRXInfoSet(p *redis.Pool, rxInfoSet DeviceGatewayRXInfoSet) error

SaveDeviceGatewayRXInfoSet saves the given DeviceGatewayRXInfoSet.

func SaveDeviceSession

func SaveDeviceSession(p *redis.Pool, s DeviceSession) error

SaveDeviceSession saves the device-session. In case it doesn't exist yet it will be created.

func SaveDownlinkFrames

func SaveDownlinkFrames(p *redis.Pool, devEUI lorawan.EUI64, frames []gw.DownlinkFrame) error

SaveDownlinkFrames saves the given downlink-frames. The downlink-frames must share the same token!

func SaveMetrics

func SaveMetrics(p *redis.Pool, name string, metrics MetricsRecord) error

SaveMetrics stores the given metrics into Redis.

func SaveMetricsForInterval

func SaveMetricsForInterval(p *redis.Pool, agg AggregationInterval, name string, metrics MetricsRecord) error

SaveMetricsForInterval aggregates and stores the given metrics.

func SetAggregationIntervals

func SetAggregationIntervals(intervals []AggregationInterval) error

SetAggregationIntervals sets the metrics aggregation to the given intervals.

func SetMetricsTTL

func SetMetricsTTL(minute, hour, day, month time.Duration)

SetMetricsTTL sets the storage TTL.

func SetPendingMACCommand

func SetPendingMACCommand(p *redis.Pool, devEUI lorawan.EUI64, block MACCommandBlock) error

SetPendingMACCommand sets a mac-command to the pending buffer. In case an other mac-command with the same CID has been set to pending, it will be overwritten.

func SetTimeLocation

func SetTimeLocation(name string) error

SetTimeLocation sets the time location.

func Transaction

func Transaction(db *common.DBLogger, f func(tx sqlx.Ext) error) error

Transaction wraps the given function in a transaction. In case the given functions returns an error, the transaction will be rolled back.

func UpdateDevice

func UpdateDevice(db sqlx.Execer, d *Device) error

UpdateDevice updates the given device.

func UpdateDeviceProfile

func UpdateDeviceProfile(db sqlx.Execer, dp *DeviceProfile) error

UpdateDeviceProfile updates the given device-profile.

func UpdateDeviceQueueItem

func UpdateDeviceQueueItem(db sqlx.Execer, qi *DeviceQueueItem) error

UpdateDeviceQueueItem updates the given device-queue item.

func UpdateGateway

func UpdateGateway(db sqlx.Execer, gw *Gateway) error

UpdateGateway updates the given gateway.

func UpdateGatewayProfile

func UpdateGatewayProfile(db sqlx.Execer, c *GatewayProfile) error

UpdateGatewayProfile updates the given gateway-profile. As this will execute multiple SQL statements, it is recommended to perform this within a transaction.

func UpdateMulticastGroup

func UpdateMulticastGroup(db sqlx.Execer, mg *MulticastGroup) error

UpdateMulticastGroup updates the given multicast-grup.

func UpdateRoutingProfile

func UpdateRoutingProfile(db sqlx.Execer, rp *RoutingProfile) error

UpdateRoutingProfile updates the given routing-profile.

func UpdateServiceProfile

func UpdateServiceProfile(db sqlx.Execer, sp *ServiceProfile) error

UpdateServiceProfile updates the given service-profile.

func ValidateAndGetFullFCntUp

func ValidateAndGetFullFCntUp(s DeviceSession, fCntUp uint32) (uint32, bool)

ValidateAndGetFullFCntUp validates if the given fCntUp is valid and returns the full 32 bit frame-counter. Note that the LoRaWAN packet only contains the 16 LSB, so in order to validate the MIC, the full 32 bit frame-counter needs to be set. After a succesful validation of the FCntUp and the MIC, don't forget to synchronize the Node FCntUp with the packet FCnt.

func ValidateDevNonce

func ValidateDevNonce(db sqlx.Queryer, joinEUI, devEUI lorawan.EUI64, nonce lorawan.DevNonce, joinType lorawan.JoinType) error

ValidateDevNonce validates the given dev-nonce for the given DevEUI / JoinEUI combination.

Types

type AggregationInterval

type AggregationInterval string

AggregationInterval defines the aggregation type.

const (
	AggregationMinute AggregationInterval = "MINUTE"
	AggregationHour   AggregationInterval = "HOUR"
	AggregationDay    AggregationInterval = "DAY"
	AggregationMonth  AggregationInterval = "MONTH"
)

Metrics aggregation intervals.

type Device

type Device struct {
	DevEUI            lorawan.EUI64 `db:"dev_eui"`
	CreatedAt         time.Time     `db:"created_at"`
	UpdatedAt         time.Time     `db:"updated_at"`
	DeviceProfileID   uuid.UUID     `db:"device_profile_id"`
	ServiceProfileID  uuid.UUID     `db:"service_profile_id"`
	RoutingProfileID  uuid.UUID     `db:"routing_profile_id"`
	SkipFCntCheck     bool          `db:"skip_fcnt_check"`
	ReferenceAltitude float64       `db:"reference_altitude"`
}

Device defines a LoRaWAN device.

func GetDevice

func GetDevice(db sqlx.Queryer, devEUI lorawan.EUI64) (Device, error)

GetDevice returns the device matching the given DevEUI.

func GetDevicesWithClassBOrClassCDeviceQueueItems

func GetDevicesWithClassBOrClassCDeviceQueueItems(db sqlx.Ext, count int) ([]Device, error)

GetDevicesWithClassBOrClassCDeviceQueueItems returns a slice of devices that qualify for downlink Class-C transmission. The device records will be locked for update so that multiple instances can run this query in parallel without the risk of duplicate scheduling.

type DeviceActivation

type DeviceActivation struct {
	ID          int64             `db:"id"`
	CreatedAt   time.Time         `db:"created_at"`
	DevEUI      lorawan.EUI64     `db:"dev_eui"`
	JoinEUI     lorawan.EUI64     `db:"join_eui"`
	DevAddr     lorawan.DevAddr   `db:"dev_addr"`
	FNwkSIntKey lorawan.AES128Key `db:"f_nwk_s_int_key"`
	SNwkSIntKey lorawan.AES128Key `db:"s_nwk_s_int_key"`
	NwkSEncKey  lorawan.AES128Key `db:"nwk_s_enc_key"`
	DevNonce    lorawan.DevNonce  `db:"dev_nonce"`
	JoinReqType lorawan.JoinType  `db:"join_req_type"`
}

DeviceActivation defines the device-activation for a LoRaWAN device.

func GetLastDeviceActivationForDevEUI

func GetLastDeviceActivationForDevEUI(db sqlx.Queryer, devEUI lorawan.EUI64) (DeviceActivation, error)

GetLastDeviceActivationForDevEUI returns the most recent activation for the given DevEUI.

type DeviceGatewayRXInfo

type DeviceGatewayRXInfo struct {
	GatewayID lorawan.EUI64
	RSSI      int
	LoRaSNR   float64
}

DeviceGatewayRXInfo holds the meta-data of a gateway receiving the last uplink message.

type DeviceGatewayRXInfoPB

type DeviceGatewayRXInfoPB struct {
	// Gateway ID.
	GatewayId []byte `protobuf:"bytes,1,opt,name=gateway_id,json=gatewayId,proto3" json:"gateway_id,omitempty"`
	// RSSI.
	Rssi int32 `protobuf:"varint,2,opt,name=rssi,proto3" json:"rssi,omitempty"`
	// LoRa SNR.
	LoraSnr              float64  `protobuf:"fixed64,3,opt,name=lora_snr,json=loraSnr,proto3" json:"lora_snr,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*DeviceGatewayRXInfoPB) Descriptor

func (*DeviceGatewayRXInfoPB) Descriptor() ([]byte, []int)

func (*DeviceGatewayRXInfoPB) GetGatewayId

func (m *DeviceGatewayRXInfoPB) GetGatewayId() []byte

func (*DeviceGatewayRXInfoPB) GetLoraSnr

func (m *DeviceGatewayRXInfoPB) GetLoraSnr() float64

func (*DeviceGatewayRXInfoPB) GetRssi

func (m *DeviceGatewayRXInfoPB) GetRssi() int32

func (*DeviceGatewayRXInfoPB) ProtoMessage

func (*DeviceGatewayRXInfoPB) ProtoMessage()

func (*DeviceGatewayRXInfoPB) Reset

func (m *DeviceGatewayRXInfoPB) Reset()

func (*DeviceGatewayRXInfoPB) String

func (m *DeviceGatewayRXInfoPB) String() string

func (*DeviceGatewayRXInfoPB) XXX_DiscardUnknown

func (m *DeviceGatewayRXInfoPB) XXX_DiscardUnknown()

func (*DeviceGatewayRXInfoPB) XXX_Marshal

func (m *DeviceGatewayRXInfoPB) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*DeviceGatewayRXInfoPB) XXX_Merge

func (dst *DeviceGatewayRXInfoPB) XXX_Merge(src proto.Message)

func (*DeviceGatewayRXInfoPB) XXX_Size

func (m *DeviceGatewayRXInfoPB) XXX_Size() int

func (*DeviceGatewayRXInfoPB) XXX_Unmarshal

func (m *DeviceGatewayRXInfoPB) XXX_Unmarshal(b []byte) error

type DeviceGatewayRXInfoSet

type DeviceGatewayRXInfoSet struct {
	DevEUI lorawan.EUI64
	DR     int
	Items  []DeviceGatewayRXInfo
}

DeviceGatewayRXInfoSet contains the rx-info set of the receiving gateways for the last uplink.

func GetDeviceGatewayRXInfoSet

func GetDeviceGatewayRXInfoSet(p *redis.Pool, devEUI lorawan.EUI64) (DeviceGatewayRXInfoSet, error)

GetDeviceGatewayRXInfoSet returns the DeviceGatewayRXInfoSet for the given Device EUI.

func GetDeviceGatewayRXInfoSetForDevEUIs

func GetDeviceGatewayRXInfoSetForDevEUIs(p *redis.Pool, devEUIs []lorawan.EUI64) ([]DeviceGatewayRXInfoSet, error)

GetDeviceGatewayRXInfoSetForDevEUIs returns the DeviceGatewayRXInfoSet objects for the given Device EUIs.

type DeviceGatewayRXInfoSetPB

type DeviceGatewayRXInfoSetPB struct {
	// Device EUI.
	DevEui []byte `protobuf:"bytes,1,opt,name=dev_eui,json=devEui,proto3" json:"dev_eui,omitempty"`
	// Data-rate.
	Dr uint32 `protobuf:"varint,2,opt,name=dr,proto3" json:"dr,omitempty"`
	// Items contains set items.
	Items                []*DeviceGatewayRXInfoPB `protobuf:"bytes,3,rep,name=items,proto3" json:"items,omitempty"`
	XXX_NoUnkeyedLiteral struct{}                 `json:"-"`
	XXX_unrecognized     []byte                   `json:"-"`
	XXX_sizecache        int32                    `json:"-"`
}

func (*DeviceGatewayRXInfoSetPB) Descriptor

func (*DeviceGatewayRXInfoSetPB) Descriptor() ([]byte, []int)

func (*DeviceGatewayRXInfoSetPB) GetDevEui

func (m *DeviceGatewayRXInfoSetPB) GetDevEui() []byte

func (*DeviceGatewayRXInfoSetPB) GetDr

func (m *DeviceGatewayRXInfoSetPB) GetDr() uint32

func (*DeviceGatewayRXInfoSetPB) GetItems

func (*DeviceGatewayRXInfoSetPB) ProtoMessage

func (*DeviceGatewayRXInfoSetPB) ProtoMessage()

func (*DeviceGatewayRXInfoSetPB) Reset

func (m *DeviceGatewayRXInfoSetPB) Reset()

func (*DeviceGatewayRXInfoSetPB) String

func (m *DeviceGatewayRXInfoSetPB) String() string

func (*DeviceGatewayRXInfoSetPB) XXX_DiscardUnknown

func (m *DeviceGatewayRXInfoSetPB) XXX_DiscardUnknown()

func (*DeviceGatewayRXInfoSetPB) XXX_Marshal

func (m *DeviceGatewayRXInfoSetPB) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*DeviceGatewayRXInfoSetPB) XXX_Merge

func (dst *DeviceGatewayRXInfoSetPB) XXX_Merge(src proto.Message)

func (*DeviceGatewayRXInfoSetPB) XXX_Size

func (m *DeviceGatewayRXInfoSetPB) XXX_Size() int

func (*DeviceGatewayRXInfoSetPB) XXX_Unmarshal

func (m *DeviceGatewayRXInfoSetPB) XXX_Unmarshal(b []byte) error

type DeviceProfile

type DeviceProfile struct {
	CreatedAt          time.Time `db:"created_at"`
	UpdatedAt          time.Time `db:"updated_at"`
	ID                 uuid.UUID `db:"device_profile_id"`
	SupportsClassB     bool      `db:"supports_class_b"`
	ClassBTimeout      int       `db:"class_b_timeout"` // Unit: seconds
	PingSlotPeriod     int       `db:"ping_slot_period"`
	PingSlotDR         int       `db:"ping_slot_dr"`
	PingSlotFreq       int       `db:"ping_slot_freq"` // in Hz
	SupportsClassC     bool      `db:"supports_class_c"`
	ClassCTimeout      int       `db:"class_c_timeout"`     // Unit: seconds
	MACVersion         string    `db:"mac_version"`         // Example: "1.0.2" [LW102]
	RegParamsRevision  string    `db:"reg_params_revision"` // Example: "B" [RP102B]
	RXDelay1           int       `db:"rx_delay_1"`
	RXDROffset1        int       `db:"rx_dr_offset_1"`
	RXDataRate2        int       `db:"rx_data_rate_2"`       // Unit: bits-per-second
	RXFreq2            int       `db:"rx_freq_2"`            // In Hz
	FactoryPresetFreqs []int     `db:"factory_preset_freqs"` // In Hz
	MaxEIRP            int       `db:"max_eirp"`             // In dBm
	MaxDutyCycle       int       `db:"max_duty_cycle"`       // Example: 10 indicates 10%
	SupportsJoin       bool      `db:"supports_join"`
	RFRegion           string    `db:"rf_region"`
	Supports32bitFCnt  bool      `db:"supports_32bit_fcnt"`
}

DeviceProfile defines the backend.DeviceProfile with some extra meta-data

func GetAndCacheDeviceProfile

func GetAndCacheDeviceProfile(db sqlx.Queryer, p *redis.Pool, id uuid.UUID) (DeviceProfile, error)

GetAndCacheDeviceProfile returns the device-profile from cache in case available, else it will be retrieved from the database and then stored in cache.

func GetDeviceProfile

func GetDeviceProfile(db sqlx.Queryer, id uuid.UUID) (DeviceProfile, error)

GetDeviceProfile returns the device-profile matching the given id.

func GetDeviceProfileCache

func GetDeviceProfileCache(p *redis.Pool, id uuid.UUID) (DeviceProfile, error)

GetDeviceProfileCache returns a cached device-profile.

type DeviceQueueItem

type DeviceQueueItem struct {
	ID                      int64          `db:"id"`
	CreatedAt               time.Time      `db:"created_at"`
	UpdatedAt               time.Time      `db:"updated_at"`
	DevEUI                  lorawan.EUI64  `db:"dev_eui"`
	FRMPayload              []byte         `db:"frm_payload"`
	FCnt                    uint32         `db:"f_cnt"`
	FPort                   uint8          `db:"f_port"`
	Confirmed               bool           `db:"confirmed"`
	IsPending               bool           `db:"is_pending"`
	EmitAtTimeSinceGPSEpoch *time.Duration `db:"emit_at_time_since_gps_epoch"`
	TimeoutAfter            *time.Time     `db:"timeout_after"`
}

DeviceQueueItem represents an item in the device queue (downlink).

func GetDeviceQueueItem

func GetDeviceQueueItem(db sqlx.Queryer, id int64) (DeviceQueueItem, error)

GetDeviceQueueItem returns the device-queue item matching the given id.

func GetDeviceQueueItemsForDevEUI

func GetDeviceQueueItemsForDevEUI(db sqlx.Queryer, devEUI lorawan.EUI64) ([]DeviceQueueItem, error)

GetDeviceQueueItemsForDevEUI returns all device-queue items for the given DevEUI, ordered by id (keep in mind FCnt rollover).

func GetNextDeviceQueueItemForDevEUI

func GetNextDeviceQueueItemForDevEUI(db sqlx.Queryer, devEUI lorawan.EUI64) (DeviceQueueItem, error)

GetNextDeviceQueueItemForDevEUI returns the next device-queue item for the given DevEUI, ordered by f_cnt (note that the f_cnt should never roll over).

func GetNextDeviceQueueItemForDevEUIMaxPayloadSizeAndFCnt

func GetNextDeviceQueueItemForDevEUIMaxPayloadSizeAndFCnt(db sqlx.Ext, devEUI lorawan.EUI64, maxPayloadSize int, fCnt uint32, routingProfileID uuid.UUID) (DeviceQueueItem, error)

GetNextDeviceQueueItemForDevEUIMaxPayloadSizeAndFCnt returns the next device-queue for the given DevEUI item respecting: * maxPayloadSize: the maximum payload size * fCnt: the current expected frame-counter In case the payload exceeds the max payload size or when the payload frame-counter is behind the actual frame-counter, the payload will be removed from the queue and the next one will be retrieved. In such a case, the application-server will be notified.

func GetPendingDeviceQueueItemForDevEUI

func GetPendingDeviceQueueItemForDevEUI(db sqlx.Queryer, devEUI lorawan.EUI64) (DeviceQueueItem, error)

GetPendingDeviceQueueItemForDevEUI returns the pending device-queue item for the given DevEUI.

func (DeviceQueueItem) Validate

func (d DeviceQueueItem) Validate() error

Validate validates the DeviceQueueItem.

type DeviceSession

type DeviceSession struct {
	// MAC version
	MACVersion string

	// profile ids
	DeviceProfileID  uuid.UUID
	ServiceProfileID uuid.UUID
	RoutingProfileID uuid.UUID

	// session data
	DevAddr        lorawan.DevAddr
	DevEUI         lorawan.EUI64
	JoinEUI        lorawan.EUI64
	FNwkSIntKey    lorawan.AES128Key
	SNwkSIntKey    lorawan.AES128Key
	NwkSEncKey     lorawan.AES128Key
	AppSKeyEvelope *KeyEnvelope
	FCntUp         uint32
	NFCntDown      uint32
	AFCntDown      uint32
	ConfFCnt       uint32

	// Only used by ABP activation
	SkipFCntValidation bool

	RXWindow     RXWindow
	RXDelay      uint8
	RX1DROffset  uint8
	RX2DR        uint8
	RX2Frequency int

	// TXPowerIndex which the node is using. The possible values are defined
	// by the lorawan/band package and are region specific. By default it is
	// assumed that the node is using TXPower 0. This value is controlled by
	// the ADR engine.
	TXPowerIndex int

	// DR defines the (last known) data-rate at which the node is operating.
	// This value is controlled by the ADR engine.
	DR int

	// ADR defines if the device has ADR enabled.
	ADR bool

	// MinSupportedTXPowerIndex defines the minimum supported tx-power index
	// by the node (default 0).
	MinSupportedTXPowerIndex int

	// MaxSupportedTXPowerIndex defines the maximum supported tx-power index
	// by the node, or 0 when not set.
	MaxSupportedTXPowerIndex int

	// MaxSupportedDR defines the maximum supported DR index by the node,
	// or 0 when not set.
	MaxSupportedDR int

	// NbTrans defines the number of transmissions for each unconfirmed uplink
	// frame. In case of 0, the default value is used.
	// This value is controlled by the ADR engine.
	NbTrans uint8

	EnabledChannels       []int                // deprecated, migrated by GetDeviceSession
	EnabledUplinkChannels []int                // channels that are activated on the node
	ExtraUplinkChannels   map[int]band.Channel // extra uplink channels, configured by the user
	ChannelFrequencies    []int                // frequency of each channel
	UplinkHistory         []UplinkHistory      // contains the last 20 transmissions
	UplinkGatewayHistory  map[lorawan.EUI64]UplinkGatewayHistory

	// LastDevStatusRequest contains the timestamp when the last device-status
	// request was made.
	LastDevStatusRequested time.Time

	// LastDownlinkTX contains the timestamp of the last downlink.
	LastDownlinkTX time.Time

	// Class-B related configuration.
	BeaconLocked      bool
	PingSlotNb        int
	PingSlotDR        int
	PingSlotFrequency int

	// RejoinRequestEnabled defines if the rejoin-request is enabled on the
	// device.
	RejoinRequestEnabled bool

	// RejoinRequestMaxCountN defines the 2^(C+4) uplink message interval for
	// the rejoin-request.
	RejoinRequestMaxCountN int

	// RejoinRequestMaxTimeN defines the 2^(T+10) time interval (seconds)
	// for the rejoin-request.
	RejoinRequestMaxTimeN int

	RejoinCount0               uint16
	PendingRejoinDeviceSession *DeviceSession

	// ReferenceAltitude holds the device reference altitude used for
	// geolocation.
	ReferenceAltitude float64
}

DeviceSession defines a device-session.

func GetDeviceSession

func GetDeviceSession(p *redis.Pool, devEUI lorawan.EUI64) (DeviceSession, error)

GetDeviceSession returns the device-session for the given DevEUI.

func GetDeviceSessionForPHYPayload

func GetDeviceSessionForPHYPayload(p *redis.Pool, phy lorawan.PHYPayload, txDR, txCh int) (DeviceSession, error)

GetDeviceSessionForPHYPayload returns the device-session matching the given PHYPayload. This will fetch all device-sessions associated with the used DevAddr and based on FCnt and MIC decide which one to use.

func GetDeviceSessionsForDevAddr

func GetDeviceSessionsForDevAddr(p *redis.Pool, devAddr lorawan.DevAddr) ([]DeviceSession, error)

GetDeviceSessionsForDevAddr returns a slice of device-sessions using the given DevAddr. When no device-session is using the given DevAddr, this returns an empty slice.

func (*DeviceSession) AppendUplinkHistory

func (s *DeviceSession) AppendUplinkHistory(up UplinkHistory)

AppendUplinkHistory appends an UplinkHistory item and makes sure the list never exceeds 20 records. In case more records are present, only the most recent ones will be preserved. In case of a re-transmission, the record with the best MaxSNR is stored.

func (DeviceSession) GetDownlinkGatewayMAC

func (s DeviceSession) GetDownlinkGatewayMAC() (lorawan.EUI64, error)

GetDownlinkGatewayMAC returns the gateway MAC of the gateway close to the device. TODO: refactor so that it uses GetDeviceGatewayRXInfoSet.

func (DeviceSession) GetMACVersion

func (s DeviceSession) GetMACVersion() lorawan.MACVersion

GetMACVersion returns the LoRaWAN mac version.

func (DeviceSession) GetPacketLossPercentage

func (s DeviceSession) GetPacketLossPercentage() float64

GetPacketLossPercentage returns the percentage of packet-loss over the records stored in UplinkHistory. Note it returns 0 when the uplink history table hasn't been filled yet to avoid reporting 33% for example when one of the first three uplinks was lost.

func (*DeviceSession) ResetToBootParameters

func (s *DeviceSession) ResetToBootParameters(dp DeviceProfile)

ResetToBootParameters resets the device-session to the device boo parameters as defined by the given device-profile.

type DeviceSessionOld

type DeviceSessionOld struct {
	// profile ids
	DeviceProfileID  string
	ServiceProfileID string
	RoutingProfileID string

	// session data
	DevAddr  lorawan.DevAddr
	DevEUI   lorawan.EUI64
	JoinEUI  lorawan.EUI64 // TODO: remove?
	NwkSKey  lorawan.AES128Key
	FCntUp   uint32
	FCntDown uint32

	// Only used by ABP activation
	SkipFCntValidation bool

	RXWindow     RXWindow
	RXDelay      uint8
	RX1DROffset  uint8
	RX2DR        uint8
	RX2Frequency int

	// TXPowerIndex which the node is using. The possible values are defined
	// by the lorawan/band package and are region specific. By default it is
	// assumed that the node is using TXPower 0. This value is controlled by
	// the ADR engine.
	TXPowerIndex int

	// DR defines the (last known) data-rate at which the node is operating.
	// This value is controlled by the ADR engine.
	DR int

	// ADR defines if the device has ADR enabled.
	ADR bool

	// MaxSupportedTXPowerIndex defines the maximum supported tx-power index
	// by the node, or 0 when not set.
	MaxSupportedTXPowerIndex int

	// MaxSupportedDR defines the maximum supported DR index by the node,
	// or 0 when not set.
	MaxSupportedDR int

	// NbTrans defines the number of transmissions for each unconfirmed uplink
	// frame. In case of 0, the default value is used.
	// This value is controlled by the ADR engine.
	NbTrans uint8

	EnabledChannels       []int                // deprecated, migrated by GetDeviceSession
	EnabledUplinkChannels []int                // channels that are activated on the node
	ExtraUplinkChannels   map[int]band.Channel // extra uplink channels, configured by the user
	ChannelFrequencies    []int                // frequency of each channel
	UplinkHistory         []UplinkHistory      // contains the last 20 transmissions
	LastRXInfoSet         models.RXInfoSet     // sorted set (best at index 0)

	// LastDevStatusRequest contains the timestamp when the last device-status
	// request was made.
	LastDevStatusRequested time.Time

	// LastDevStatusBattery contains the last received battery status.
	LastDevStatusBattery uint8

	// LastDevStatusMargin contains the last received margin status.
	LastDevStatusMargin int8

	// LastDownlinkTX contains the timestamp of the last downlink.
	LastDownlinkTX time.Time

	// Class-B related configuration.
	BeaconLocked      bool
	PingSlotNb        int
	PingSlotDR        int
	PingSlotFrequency int
}

DeviceSessionOld defines the "old" device-session struct. This struct is needed to gob decode "old" device-sessions.

type DeviceSessionPB

type DeviceSessionPB struct {
	// ID of the device-profile.
	DeviceProfileId string `protobuf:"bytes,1,opt,name=device_profile_id,json=deviceProfileId,proto3" json:"device_profile_id,omitempty"`
	// ID of the service-profile.
	ServiceProfileId string `protobuf:"bytes,2,opt,name=service_profile_id,json=serviceProfileId,proto3" json:"service_profile_id,omitempty"`
	// ID of the routing-profile.
	RoutingProfileId string `protobuf:"bytes,3,opt,name=routing_profile_id,json=routingProfileId,proto3" json:"routing_profile_id,omitempty"`
	// Device address.
	DevAddr []byte `protobuf:"bytes,4,opt,name=dev_addr,json=devAddr,proto3" json:"dev_addr,omitempty"`
	// Device EUI.
	DevEui []byte `protobuf:"bytes,5,opt,name=dev_eui,json=devEui,proto3" json:"dev_eui,omitempty"`
	// Join EUI.
	JoinEui []byte `protobuf:"bytes,6,opt,name=join_eui,json=joinEui,proto3" json:"join_eui,omitempty"`
	// FNwkSIntKey.
	FNwkSIntKey []byte `protobuf:"bytes,7,opt,name=f_nwk_s_int_key,json=fNwkSIntKey,proto3" json:"f_nwk_s_int_key,omitempty"`
	// SNwkSIntKey.
	SNwkSIntKey []byte `protobuf:"bytes,8,opt,name=s_nwk_s_int_key,json=sNwkSIntKey,proto3" json:"s_nwk_s_int_key,omitempty"`
	// NwkSEncKey.
	NwkSEncKey []byte `protobuf:"bytes,9,opt,name=nwk_s_enc_key,json=nwkSEncKey,proto3" json:"nwk_s_enc_key,omitempty"`
	// AppSKeyEnvelope contains the (encrypted) AppSKey key-envelope.
	AppSKeyEnvelope *common.KeyEnvelope `protobuf:"bytes,45,opt,name=app_s_key_envelope,json=appSKeyEnvelope,proto3" json:"app_s_key_envelope,omitempty"`
	// Uplink frame-counter.
	FCntUp uint32 `protobuf:"varint,10,opt,name=f_cnt_up,json=fCntUp,proto3" json:"f_cnt_up,omitempty"`
	// Downlink frame-counter (network-server).
	NFCntDown uint32 `protobuf:"varint,11,opt,name=n_f_cnt_down,json=nFCntDown,proto3" json:"n_f_cnt_down,omitempty"`
	// Uplink frame-counter (application-server).
	// Note: this frame-counter is managed by the application-server.
	AFCntDown uint32 `protobuf:"varint,12,opt,name=a_f_cnt_down,json=aFCntDown,proto3" json:"a_f_cnt_down,omitempty"`
	// Frame-counter holding the last confirmed downlink frame (n_f_cnt_down or a_f_cnt_down).
	ConfFCnt uint32 `protobuf:"varint,39,opt,name=conf_f_cnt,json=confFCnt,proto3" json:"conf_f_cnt,omitempty"`
	// Skip uplink frame-counter validation.
	SkipFCntCheck bool `protobuf:"varint,13,opt,name=skip_f_cnt_check,json=skipFCntCheck,proto3" json:"skip_f_cnt_check,omitempty"`
	// RX Delay.
	RxDelay uint32 `protobuf:"varint,14,opt,name=rx_delay,json=rxDelay,proto3" json:"rx_delay,omitempty"`
	// RX1 data-rate offset.
	Rx1DrOffset uint32 `protobuf:"varint,15,opt,name=rx1_dr_offset,json=rx1DrOffset,proto3" json:"rx1_dr_offset,omitempty"`
	// RX2 data-rate.
	Rx2Dr uint32 `protobuf:"varint,16,opt,name=rx2_dr,json=rx2Dr,proto3" json:"rx2_dr,omitempty"`
	// RX2 frequency.
	Rx2Frequency uint32 `protobuf:"varint,17,opt,name=rx2_frequency,json=rx2Frequency,proto3" json:"rx2_frequency,omitempty"`
	// TXPowerIndex which the node is using. The possible values are defined
	// by the lorawan/band package and are region specific. By default it is
	// assumed that the node is using TXPower 0. This value is controlled by
	// the ADR engine.
	TxPowerIndex uint32 `protobuf:"varint,18,opt,name=tx_power_index,json=txPowerIndex,proto3" json:"tx_power_index,omitempty"`
	// DR defines the (last known) data-rate at which the node is operating.
	// This value is controlled by the ADR engine.
	Dr uint32 `protobuf:"varint,19,opt,name=dr,proto3" json:"dr,omitempty"`
	// ADR defines if the device has ADR enabled.
	Adr bool `protobuf:"varint,20,opt,name=adr,proto3" json:"adr,omitempty"`
	// MaxSupportedTXPowerIndex defines the maximum supported tx-power index
	// by the node, or 0 when not set.
	MaxSupportedTxPowerIndex uint32 `` /* 141-byte string literal not displayed */
	// MaxSupportedDR defines the maximum supported DR index by the node,
	// or 0 when not set.
	MaxSupportedDr uint32 `protobuf:"varint,22,opt,name=max_supported_dr,json=maxSupportedDr,proto3" json:"max_supported_dr,omitempty"`
	// NbTrans defines the number of transmissions for each unconfirmed uplink
	// frame. In case of 0, the default value is used.
	// This value is controlled by the ADR engine.
	NbTrans uint32 `protobuf:"varint,23,opt,name=nb_trans,json=nbTrans,proto3" json:"nb_trans,omitempty"`
	// Channels that are activated on the device.
	EnabledUplinkChannels []uint32 `` /* 135-byte string literal not displayed */
	// Extra uplink channels, configured by the user.
	ExtraUplinkChannels map[uint32]*DeviceSessionPBChannel `` /* 210-byte string literal not displayed */
	// Frequency of each channel.
	ChannelFrequencies []uint32 `protobuf:"varint,26,rep,packed,name=channel_frequencies,json=channelFrequencies,proto3" json:"channel_frequencies,omitempty"`
	// Uplink history for ADR (last 20 uplink transmissions).
	UplinkAdrHistory []*DeviceSessionPBUplinkADRHistory `protobuf:"bytes,27,rep,name=uplink_adr_history,json=uplinkAdrHistory,proto3" json:"uplink_adr_history,omitempty"`
	// Uplink gateway history (for Class B / C).
	// Note that as bytes are not supported in a Protobuf map, the gateway ID is HEX encoded.
	UplinkGatewayHistory map[string]*DeviceSessionPBUplinkGatewayHistory `` /* 212-byte string literal not displayed */
	// Last device-status requested timestamp (Unix ns)
	LastDeviceStatusRequestTimeUnixNs int64 `` /* 172-byte string literal not displayed */
	// Last downlink timestamp (Unix ns).
	LastDownlinkTxTimestampUnixNs int64 `` /* 158-byte string literal not displayed */
	// Class-B beacon is locked.
	BeaconLocked bool `protobuf:"varint,33,opt,name=beacon_locked,json=beaconLocked,proto3" json:"beacon_locked,omitempty"`
	// Class-B ping-slot nb.
	PingSlotNb uint32 `protobuf:"varint,34,opt,name=ping_slot_nb,json=pingSlotNb,proto3" json:"ping_slot_nb,omitempty"`
	// Class-B ping-slot data-rate.
	PingSlotDr uint32 `protobuf:"varint,35,opt,name=ping_slot_dr,json=pingSlotDr,proto3" json:"ping_slot_dr,omitempty"`
	// Class-B ping-slot tx frequency.
	PingSlotFrequency uint32 `protobuf:"varint,36,opt,name=ping_slot_frequency,json=pingSlotFrequency,proto3" json:"ping_slot_frequency,omitempty"`
	// LoRaWAN mac-version.
	MacVersion string `protobuf:"bytes,37,opt,name=mac_version,json=macVersion,proto3" json:"mac_version,omitempty"`
	// MinSupportedTXPowerIndex defines the minimum supported tx-power index
	// by the node (default 0).
	MinSupportedTxPowerIndex uint32 `` /* 141-byte string literal not displayed */
	// RejoinRequestEnabled defines if the rejoin-request is enabled on the
	// device.
	RejoinRequestEnabled bool `protobuf:"varint,44,opt,name=rejoin_request_enabled,json=rejoinRequestEnabled,proto3" json:"rejoin_request_enabled,omitempty"`
	// RejoinRequestMaxCountN defines the 2^(C+4) uplink message interval for
	// the rejoin-request.
	RejoinRequestMaxCountN uint32 `` /* 135-byte string literal not displayed */
	// RejoinRequestMaxTimeN defines the 2^(T+10) time interval (seconds)
	// for the rejoin-request.
	RejoinRequestMaxTimeN uint32 `` /* 132-byte string literal not displayed */
	// Rejoin counter (RJCount0).
	// This counter is reset to 0 after each successful join-accept.
	RejoinCount_0 uint32 `protobuf:"varint,42,opt,name=rejoin_count_0,json=rejoinCount0,proto3" json:"rejoin_count_0,omitempty"`
	// Pending rejoin device-session contains a device-session which has not
	// yet been activated by the device (by sending a first uplink).
	PendingRejoinDeviceSession []byte `` /* 144-byte string literal not displayed */
	// Device reference altitude for geolocation.
	ReferenceAltitude    float64  `protobuf:"fixed64,46,opt,name=reference_altitude,json=referenceAltitude,proto3" json:"reference_altitude,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*DeviceSessionPB) Descriptor

func (*DeviceSessionPB) Descriptor() ([]byte, []int)

func (*DeviceSessionPB) GetAFCntDown

func (m *DeviceSessionPB) GetAFCntDown() uint32

func (*DeviceSessionPB) GetAdr

func (m *DeviceSessionPB) GetAdr() bool

func (*DeviceSessionPB) GetAppSKeyEnvelope

func (m *DeviceSessionPB) GetAppSKeyEnvelope() *common.KeyEnvelope

func (*DeviceSessionPB) GetBeaconLocked

func (m *DeviceSessionPB) GetBeaconLocked() bool

func (*DeviceSessionPB) GetChannelFrequencies

func (m *DeviceSessionPB) GetChannelFrequencies() []uint32

func (*DeviceSessionPB) GetConfFCnt

func (m *DeviceSessionPB) GetConfFCnt() uint32

func (*DeviceSessionPB) GetDevAddr

func (m *DeviceSessionPB) GetDevAddr() []byte

func (*DeviceSessionPB) GetDevEui

func (m *DeviceSessionPB) GetDevEui() []byte

func (*DeviceSessionPB) GetDeviceProfileId

func (m *DeviceSessionPB) GetDeviceProfileId() string

func (*DeviceSessionPB) GetDr

func (m *DeviceSessionPB) GetDr() uint32

func (*DeviceSessionPB) GetEnabledUplinkChannels

func (m *DeviceSessionPB) GetEnabledUplinkChannels() []uint32

func (*DeviceSessionPB) GetExtraUplinkChannels

func (m *DeviceSessionPB) GetExtraUplinkChannels() map[uint32]*DeviceSessionPBChannel

func (*DeviceSessionPB) GetFCntUp

func (m *DeviceSessionPB) GetFCntUp() uint32

func (*DeviceSessionPB) GetFNwkSIntKey

func (m *DeviceSessionPB) GetFNwkSIntKey() []byte

func (*DeviceSessionPB) GetJoinEui

func (m *DeviceSessionPB) GetJoinEui() []byte

func (*DeviceSessionPB) GetLastDeviceStatusRequestTimeUnixNs

func (m *DeviceSessionPB) GetLastDeviceStatusRequestTimeUnixNs() int64

func (*DeviceSessionPB) GetLastDownlinkTxTimestampUnixNs

func (m *DeviceSessionPB) GetLastDownlinkTxTimestampUnixNs() int64

func (*DeviceSessionPB) GetMacVersion

func (m *DeviceSessionPB) GetMacVersion() string

func (*DeviceSessionPB) GetMaxSupportedDr

func (m *DeviceSessionPB) GetMaxSupportedDr() uint32

func (*DeviceSessionPB) GetMaxSupportedTxPowerIndex

func (m *DeviceSessionPB) GetMaxSupportedTxPowerIndex() uint32

func (*DeviceSessionPB) GetMinSupportedTxPowerIndex

func (m *DeviceSessionPB) GetMinSupportedTxPowerIndex() uint32

func (*DeviceSessionPB) GetNFCntDown

func (m *DeviceSessionPB) GetNFCntDown() uint32

func (*DeviceSessionPB) GetNbTrans

func (m *DeviceSessionPB) GetNbTrans() uint32

func (*DeviceSessionPB) GetNwkSEncKey

func (m *DeviceSessionPB) GetNwkSEncKey() []byte

func (*DeviceSessionPB) GetPendingRejoinDeviceSession

func (m *DeviceSessionPB) GetPendingRejoinDeviceSession() []byte

func (*DeviceSessionPB) GetPingSlotDr

func (m *DeviceSessionPB) GetPingSlotDr() uint32

func (*DeviceSessionPB) GetPingSlotFrequency

func (m *DeviceSessionPB) GetPingSlotFrequency() uint32

func (*DeviceSessionPB) GetPingSlotNb

func (m *DeviceSessionPB) GetPingSlotNb() uint32

func (*DeviceSessionPB) GetReferenceAltitude

func (m *DeviceSessionPB) GetReferenceAltitude() float64

func (*DeviceSessionPB) GetRejoinCount_0

func (m *DeviceSessionPB) GetRejoinCount_0() uint32

func (*DeviceSessionPB) GetRejoinRequestEnabled

func (m *DeviceSessionPB) GetRejoinRequestEnabled() bool

func (*DeviceSessionPB) GetRejoinRequestMaxCountN

func (m *DeviceSessionPB) GetRejoinRequestMaxCountN() uint32

func (*DeviceSessionPB) GetRejoinRequestMaxTimeN

func (m *DeviceSessionPB) GetRejoinRequestMaxTimeN() uint32

func (*DeviceSessionPB) GetRoutingProfileId

func (m *DeviceSessionPB) GetRoutingProfileId() string

func (*DeviceSessionPB) GetRx1DrOffset

func (m *DeviceSessionPB) GetRx1DrOffset() uint32

func (*DeviceSessionPB) GetRx2Dr

func (m *DeviceSessionPB) GetRx2Dr() uint32

func (*DeviceSessionPB) GetRx2Frequency

func (m *DeviceSessionPB) GetRx2Frequency() uint32

func (*DeviceSessionPB) GetRxDelay

func (m *DeviceSessionPB) GetRxDelay() uint32

func (*DeviceSessionPB) GetSNwkSIntKey

func (m *DeviceSessionPB) GetSNwkSIntKey() []byte

func (*DeviceSessionPB) GetServiceProfileId

func (m *DeviceSessionPB) GetServiceProfileId() string

func (*DeviceSessionPB) GetSkipFCntCheck

func (m *DeviceSessionPB) GetSkipFCntCheck() bool

func (*DeviceSessionPB) GetTxPowerIndex

func (m *DeviceSessionPB) GetTxPowerIndex() uint32

func (*DeviceSessionPB) GetUplinkAdrHistory

func (m *DeviceSessionPB) GetUplinkAdrHistory() []*DeviceSessionPBUplinkADRHistory

func (*DeviceSessionPB) GetUplinkGatewayHistory

func (m *DeviceSessionPB) GetUplinkGatewayHistory() map[string]*DeviceSessionPBUplinkGatewayHistory

func (*DeviceSessionPB) ProtoMessage

func (*DeviceSessionPB) ProtoMessage()

func (*DeviceSessionPB) Reset

func (m *DeviceSessionPB) Reset()

func (*DeviceSessionPB) String

func (m *DeviceSessionPB) String() string

func (*DeviceSessionPB) XXX_DiscardUnknown

func (m *DeviceSessionPB) XXX_DiscardUnknown()

func (*DeviceSessionPB) XXX_Marshal

func (m *DeviceSessionPB) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*DeviceSessionPB) XXX_Merge

func (dst *DeviceSessionPB) XXX_Merge(src proto.Message)

func (*DeviceSessionPB) XXX_Size

func (m *DeviceSessionPB) XXX_Size() int

func (*DeviceSessionPB) XXX_Unmarshal

func (m *DeviceSessionPB) XXX_Unmarshal(b []byte) error

type DeviceSessionPBChannel

type DeviceSessionPBChannel struct {
	// Frequency (Hz).
	Frequency uint32 `protobuf:"varint,1,opt,name=frequency,proto3" json:"frequency,omitempty"`
	// Min. data-rate.
	MinDr uint32 `protobuf:"varint,2,opt,name=min_dr,json=minDr,proto3" json:"min_dr,omitempty"`
	// Max. data-rate.
	MaxDr                uint32   `protobuf:"varint,3,opt,name=max_dr,json=maxDr,proto3" json:"max_dr,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*DeviceSessionPBChannel) Descriptor

func (*DeviceSessionPBChannel) Descriptor() ([]byte, []int)

func (*DeviceSessionPBChannel) GetFrequency

func (m *DeviceSessionPBChannel) GetFrequency() uint32

func (*DeviceSessionPBChannel) GetMaxDr

func (m *DeviceSessionPBChannel) GetMaxDr() uint32

func (*DeviceSessionPBChannel) GetMinDr

func (m *DeviceSessionPBChannel) GetMinDr() uint32

func (*DeviceSessionPBChannel) ProtoMessage

func (*DeviceSessionPBChannel) ProtoMessage()

func (*DeviceSessionPBChannel) Reset

func (m *DeviceSessionPBChannel) Reset()

func (*DeviceSessionPBChannel) String

func (m *DeviceSessionPBChannel) String() string

func (*DeviceSessionPBChannel) XXX_DiscardUnknown

func (m *DeviceSessionPBChannel) XXX_DiscardUnknown()

func (*DeviceSessionPBChannel) XXX_Marshal

func (m *DeviceSessionPBChannel) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*DeviceSessionPBChannel) XXX_Merge

func (dst *DeviceSessionPBChannel) XXX_Merge(src proto.Message)

func (*DeviceSessionPBChannel) XXX_Size

func (m *DeviceSessionPBChannel) XXX_Size() int

func (*DeviceSessionPBChannel) XXX_Unmarshal

func (m *DeviceSessionPBChannel) XXX_Unmarshal(b []byte) error

type DeviceSessionPBUplinkADRHistory

type DeviceSessionPBUplinkADRHistory struct {
	// Uplink frame-counter.
	FCnt uint32 `protobuf:"varint,1,opt,name=f_cnt,json=fCnt,proto3" json:"f_cnt,omitempty"`
	// Max SNR (of deduplicated frames received by one or multiple gateways).
	MaxSnr float32 `protobuf:"fixed32,2,opt,name=max_snr,json=maxSnr,proto3" json:"max_snr,omitempty"`
	// TX Power (as known by the network-server).
	TxPowerIndex uint32 `protobuf:"varint,3,opt,name=tx_power_index,json=txPowerIndex,proto3" json:"tx_power_index,omitempty"`
	// Number of receiving gateways.
	GatewayCount         uint32   `protobuf:"varint,4,opt,name=gateway_count,json=gatewayCount,proto3" json:"gateway_count,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*DeviceSessionPBUplinkADRHistory) Descriptor

func (*DeviceSessionPBUplinkADRHistory) Descriptor() ([]byte, []int)

func (*DeviceSessionPBUplinkADRHistory) GetFCnt

func (*DeviceSessionPBUplinkADRHistory) GetGatewayCount

func (m *DeviceSessionPBUplinkADRHistory) GetGatewayCount() uint32

func (*DeviceSessionPBUplinkADRHistory) GetMaxSnr

func (*DeviceSessionPBUplinkADRHistory) GetTxPowerIndex

func (m *DeviceSessionPBUplinkADRHistory) GetTxPowerIndex() uint32

func (*DeviceSessionPBUplinkADRHistory) ProtoMessage

func (*DeviceSessionPBUplinkADRHistory) ProtoMessage()

func (*DeviceSessionPBUplinkADRHistory) Reset

func (*DeviceSessionPBUplinkADRHistory) String

func (*DeviceSessionPBUplinkADRHistory) XXX_DiscardUnknown

func (m *DeviceSessionPBUplinkADRHistory) XXX_DiscardUnknown()

func (*DeviceSessionPBUplinkADRHistory) XXX_Marshal

func (m *DeviceSessionPBUplinkADRHistory) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*DeviceSessionPBUplinkADRHistory) XXX_Merge

func (dst *DeviceSessionPBUplinkADRHistory) XXX_Merge(src proto.Message)

func (*DeviceSessionPBUplinkADRHistory) XXX_Size

func (m *DeviceSessionPBUplinkADRHistory) XXX_Size() int

func (*DeviceSessionPBUplinkADRHistory) XXX_Unmarshal

func (m *DeviceSessionPBUplinkADRHistory) XXX_Unmarshal(b []byte) error

type DeviceSessionPBUplinkGatewayHistory

type DeviceSessionPBUplinkGatewayHistory struct {
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*DeviceSessionPBUplinkGatewayHistory) Descriptor

func (*DeviceSessionPBUplinkGatewayHistory) Descriptor() ([]byte, []int)

func (*DeviceSessionPBUplinkGatewayHistory) ProtoMessage

func (*DeviceSessionPBUplinkGatewayHistory) ProtoMessage()

func (*DeviceSessionPBUplinkGatewayHistory) Reset

func (*DeviceSessionPBUplinkGatewayHistory) String

func (*DeviceSessionPBUplinkGatewayHistory) XXX_DiscardUnknown

func (m *DeviceSessionPBUplinkGatewayHistory) XXX_DiscardUnknown()

func (*DeviceSessionPBUplinkGatewayHistory) XXX_Marshal

func (m *DeviceSessionPBUplinkGatewayHistory) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*DeviceSessionPBUplinkGatewayHistory) XXX_Merge

func (*DeviceSessionPBUplinkGatewayHistory) XXX_Size

func (*DeviceSessionPBUplinkGatewayHistory) XXX_Unmarshal

func (m *DeviceSessionPBUplinkGatewayHistory) XXX_Unmarshal(b []byte) error

type ExtraChannel

type ExtraChannel struct {
	Modulation       string  `db:"modulation"`
	Frequency        int     `db:"frequency"`
	Bandwidth        int     `db:"bandwidth"`
	Bitrate          int     `db:"bitrate"`
	SpreadingFactors []int64 `db:"spreading_factors"`
}

ExtraChannel defines an extra channel for the gateway-profile.

type GPSPoint

type GPSPoint struct {
	Latitude  float64
	Longitude float64
}

GPSPoint contains a GPS point.

func (*GPSPoint) Scan

func (l *GPSPoint) Scan(src interface{}) error

Scan implements the sql.Scanner interface.

func (GPSPoint) Value

func (l GPSPoint) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type Gateway

type Gateway struct {
	GatewayID        lorawan.EUI64  `db:"gateway_id"`
	CreatedAt        time.Time      `db:"created_at"`
	UpdatedAt        time.Time      `db:"updated_at"`
	FirstSeenAt      *time.Time     `db:"first_seen_at"`
	LastSeenAt       *time.Time     `db:"last_seen_at"`
	Location         GPSPoint       `db:"location"`
	Altitude         float64        `db:"altitude"`
	GatewayProfileID *uuid.UUID     `db:"gateway_profile_id"`
	Boards           []GatewayBoard `db:"-"`
}

Gateway represents a gateway.

func GetAndCacheGateway

func GetAndCacheGateway(db sqlx.Queryer, p *redis.Pool, gatewayID lorawan.EUI64) (Gateway, error)

GetAndCacheGateway returns a gateway from the cache in case it is available. In case the gateway is not cached, it will be retrieved from the database and then cached.

func GetGateway

func GetGateway(db sqlx.Queryer, id lorawan.EUI64) (Gateway, error)

GetGateway returns the gateway for the given Gateway ID.

func GetGatewayCache

func GetGatewayCache(p *redis.Pool, gatewayID lorawan.EUI64) (Gateway, error)

GetGatewayCache returns a cached gateway.

type GatewayBoard

type GatewayBoard struct {
	FPGAID           *lorawan.EUI64     `db:"fpga_id"`
	FineTimestampKey *lorawan.AES128Key `db:"fine_timestamp_key"`
}

GatewayBoard holds the gateway board configuration.

type GatewayProfile

type GatewayProfile struct {
	ID            uuid.UUID      `db:"gateway_profile_id"`
	CreatedAt     time.Time      `db:"created_at"`
	UpdatedAt     time.Time      `db:"updated_at"`
	Channels      []int64        `db:"channels"`
	ExtraChannels []ExtraChannel `db:"-"`
}

GatewayProfile defines a gateway-profile.

func GetGatewayProfile

func GetGatewayProfile(db sqlx.Queryer, id uuid.UUID) (GatewayProfile, error)

GetGatewayProfile returns the gateway-profile matching the given ID.

func (GatewayProfile) GetVersion

func (p GatewayProfile) GetVersion() string

GetVersion returns the gateway-profile version.

type KeyEnvelope

type KeyEnvelope struct {
	KEKLabel string
	AESKey   []byte
}

KeyEnvelope defined a key-envelope.

type MACCommandBlock

type MACCommandBlock struct {
	CID         lorawan.CID
	External    bool // command was enqueued by an external service
	MACCommands MACCommands
}

MACCommandBlock defines a block of MAC commands that must be handled together.

func GetMACCommandQueueItems

func GetMACCommandQueueItems(p *redis.Pool, devEUI lorawan.EUI64) ([]MACCommandBlock, error)

GetMACCommandQueueItems returns the mac-command queue items for the given DevEUI.

func GetPendingMACCommand

func GetPendingMACCommand(p *redis.Pool, devEUI lorawan.EUI64, cid lorawan.CID) (*MACCommandBlock, error)

GetPendingMACCommand returns the pending mac-command for the given CID. In case no items are pending, nil is returned.

func (*MACCommandBlock) Size

func (m *MACCommandBlock) Size() (int, error)

Size returns the size (in bytes) of the mac-commands within this block.

type MACCommands

type MACCommands []lorawan.MACCommand

MACCommands holds a slice of MACCommand items.

func (MACCommands) MarshalBinary

func (m MACCommands) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*MACCommands) UnmarshalBinary

func (m *MACCommands) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type MetricsRecord

type MetricsRecord struct {
	Time    time.Time
	Metrics map[string]float64
}

MetricsRecord holds a single metrics record.

func GetMetrics

func GetMetrics(p *redis.Pool, agg AggregationInterval, name string, start, end time.Time) ([]MetricsRecord, error)

GetMetrics returns the metrics for the requested aggregation interval.

type MulticastGroup

type MulticastGroup struct {
	ID               uuid.UUID          `db:"id"`
	CreatedAt        time.Time          `db:"created_at"`
	UpdatedAt        time.Time          `db:"updated_at"`
	MCAddr           lorawan.DevAddr    `db:"mc_addr"`
	MCNwkSKey        lorawan.AES128Key  `db:"mc_nwk_s_key"`
	FCnt             uint32             `db:"f_cnt"`
	GroupType        MulticastGroupType `db:"group_type"`
	DR               int                `db:"dr"`
	Frequency        int                `db:"frequency"`
	PingSlotPeriod   int                `db:"ping_slot_period"`
	RoutingProfileID uuid.UUID          `db:"routing_profile_id"` // there is no downlink data, but it can be used for future error reporting
	ServiceProfileID uuid.UUID          `db:"service_profile_id"`
}

MulticastGroup defines a multicast-group.

func GetMulticastGroup

func GetMulticastGroup(db sqlx.Queryer, id uuid.UUID, forUpdate bool) (MulticastGroup, error)

GetMulticastGroup returns the multicast-group for the given ID.

type MulticastGroupType

type MulticastGroupType string

MulticastGroupType type defines the multicast-group type.

const (
	MulticastGroupB MulticastGroupType = "B"
	MulticastGroupC MulticastGroupType = "C"
)

Possible multicast-group types.

type MulticastQueueItem

type MulticastQueueItem struct {
	ID                      int64          `db:"id"`
	CreatedAt               time.Time      `db:"created_at"`
	ScheduleAt              time.Time      `db:"schedule_at"`
	EmitAtTimeSinceGPSEpoch *time.Duration `db:"emit_at_time_since_gps_epoch"`
	MulticastGroupID        uuid.UUID      `db:"multicast_group_id"`
	GatewayID               lorawan.EUI64  `db:"gateway_id"`
	FCnt                    uint32         `db:"f_cnt"`
	FPort                   uint8          `db:"f_port"`
	FRMPayload              []byte         `db:"frm_payload"`
}

MulticastQueueItem defines a multicast queue-item.

func GetMulticastQueueItemsForMulticastGroup

func GetMulticastQueueItemsForMulticastGroup(db sqlx.Queryer, multicastGroupID uuid.UUID) ([]MulticastQueueItem, error)

GetMulticastQueueItemsForMulticastGroup returns all queue-items given a multicast-group id.

func GetSchedulableMulticastQueueItems

func GetSchedulableMulticastQueueItems(db sqlx.Ext, count int) ([]MulticastQueueItem, error)

GetSchedulableMulticastQueueItems returns a slice of multicast-queue items for scheduling. The returned queue-items will be locked for update so that this query can be executed in parallel.

func (MulticastQueueItem) Validate

func (m MulticastQueueItem) Validate() error

Validate validates the MulticastQueueItem.

type RXWindow

type RXWindow int8

RXWindow defines the RX window option.

type RatePolicy

type RatePolicy string

RatePolicy defines the RatePolicy type.

const (
	Drop RatePolicy = "Drop"
	Mark RatePolicy = "Mark"
)

Available rate policies.

type RoutingProfile

type RoutingProfile struct {
	ID        uuid.UUID `json:"RoutingProfileID" db:"routing_profile_id"`
	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
	ASID      string    `json:"AS-ID" db:"as_id"` // Value can be IP address, DNS name, etc.
	CACert    string    `db:"ca_cert"`
	TLSCert   string    `db:"tls_cert"`
	TLSKey    string    `db:"tls_key"`
}

RoutingProfile defines the backend.RoutingProfile with some extra meta-data.

func GetAllRoutingProfiles

func GetAllRoutingProfiles(db sqlx.Queryer) ([]RoutingProfile, error)

GetAllRoutingProfiles returns all the available routing-profiles.

func GetRoutingProfile

func GetRoutingProfile(db sqlx.Queryer, id uuid.UUID) (RoutingProfile, error)

GetRoutingProfile returns the routing-profile matching the given id.

type ServiceProfile

type ServiceProfile struct {
	CreatedAt              time.Time  `db:"created_at"`
	UpdatedAt              time.Time  `db:"updated_at"`
	ID                     uuid.UUID  `db:"service_profile_id"`
	ULRate                 int        `db:"ul_rate"`
	ULBucketSize           int        `db:"ul_bucket_size"`
	ULRatePolicy           RatePolicy `db:"ul_rate_policy"`
	DLRate                 int        `db:"dl_rate"`
	DLBucketSize           int        `db:"dl_bucket_size"`
	DLRatePolicy           RatePolicy `db:"dl_rate_policy"`
	AddGWMetadata          bool       `db:"add_gw_metadata"`
	DevStatusReqFreq       int        `db:"dev_status_req_freq"` // Unit: requests-per-day
	ReportDevStatusBattery bool       `db:"report_dev_status_battery"`
	ReportDevStatusMargin  bool       `db:"report_dev_status_margin"`
	DRMin                  int        `db:"dr_min"`
	DRMax                  int        `db:"dr_max"`
	ChannelMask            []byte     `db:"channel_mask"`
	PRAllowed              bool       `db:"pr_allowed"`
	HRAllowed              bool       `db:"hr_allowed"`
	RAAllowed              bool       `db:"ra_allowed"`
	NwkGeoLoc              bool       `db:"nwk_geo_loc"`
	TargetPER              int        `db:"target_per"` // Example: 10 indicates 10%
	MinGWDiversity         int        `db:"min_gw_diversity"`
}

ServiceProfile defines the backend.ServiceProfile with some extra meta-data.

func GetAndCacheServiceProfile

func GetAndCacheServiceProfile(db sqlx.Queryer, p *redis.Pool, id uuid.UUID) (ServiceProfile, error)

GetAndCacheServiceProfile returns the service-profile from cache in case available, else it will be retrieved from the database and then stored in cache.

func GetServiceProfile

func GetServiceProfile(db sqlx.Queryer, id uuid.UUID) (ServiceProfile, error)

GetServiceProfile returns the service-profile matching the given id.

func GetServiceProfileCache

func GetServiceProfileCache(p *redis.Pool, id uuid.UUID) (ServiceProfile, error)

GetServiceProfileCache returns a cached service-profile.

type UplinkGatewayHistory

type UplinkGatewayHistory struct{}

UplinkGatewayHistory contains the uplink gateway history meta-data. This is used for Class-B and Class-C downlinks.

type UplinkHistory

type UplinkHistory struct {
	FCnt         uint32
	MaxSNR       float64
	TXPowerIndex int
	GatewayCount int
}

UplinkHistory contains the meta-data of an uplink transmission.

Jump to

Keyboard shortcuts

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