forwarder

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 64 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GatewayCmds = &cobra.Command{
		Use:   "gateway",
		Short: "gateway related commands",
	}
)

Functions

func DevAddrHasPrefix

func DevAddrHasPrefix(devAddr lorawan.DevAddr, prefix uint32, mask uint8) bool

func GatewayIDBytesToLoraEUID

func GatewayIDBytesToLoraEUID(id []byte) lorawan.EUI64

GatewayIDBytesToLoraEUID decodes the given id bytes into a gateway id.

func Info added in v1.0.8

func Info(w http.ResponseWriter, r *http.Request)

func IsMaybeMapperPacket

func IsMaybeMapperPacket(frame *gw.UplinkFrame, payload *lorawan.MACPayload) bool

func Run

func Run(cmd *cobra.Command, args []string)

Run the packet exchange.

func SetDevAddrPrefix

func SetDevAddrPrefix(devAddr lorawan.DevAddr, prefix uint32, maskLength uint8) lorawan.DevAddr

Types

type APIService added in v1.0.8

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

func (APIService) AddGateway added in v1.0.8

func (svc APIService) AddGateway(w http.ResponseWriter, r *http.Request)

func (APIService) Gateway added in v1.0.8

func (svc APIService) Gateway(w http.ResponseWriter, r *http.Request)

func (APIService) ImportGateways added in v1.0.8

func (svc APIService) ImportGateways(w http.ResponseWriter, r *http.Request)

func (APIService) ListGateways added in v1.0.8

func (svc APIService) ListGateways(w http.ResponseWriter, r *http.Request)

func (APIService) ListUnknownGateways added in v1.0.8

func (svc APIService) ListUnknownGateways(w http.ResponseWriter, r *http.Request)

func (APIService) OnboardGatewayMessage added in v1.0.8

func (svc APIService) OnboardGatewayMessage(w http.ResponseWriter, r *http.Request)

func (APIService) SyncGateway added in v1.0.8

func (svc APIService) SyncGateway(w http.ResponseWriter, r *http.Request)

type Accounter

type Accounter interface {
	// Allow returns an indication if the user is allowed to receive
	// the packet that took the given amount of airtime from the gateway.
	Allow(user common.Address, airtime time.Duration) bool

	// AddPayment must be called each time a router sends an airtime
	// payment to the forwarder. The accounter will store/track these
	// and determines if the router is allowed to receive more data.
	AddPayment(payment *router.AirtimePaymentEvent)
}

Accounter is implemented by account strategies that determine if a packet must be forwarded to a router or not because it hasn't paid for the service gateways connected to the packet exchange provide.

type Backend

type Backend interface {
	// Stop closes the backend.
	Stop() error

	// Start starts the backend.
	Start() error

	// SetDownlinkTxAckFunc sets the DownlinkTXAck handler func.
	SetDownlinkTxAckFunc(func(*gw.DownlinkTxAck))

	// SetGatewayStatsFunc sets the GatewayStats handler func.
	SetGatewayStatsFunc(func(*gw.GatewayStats))

	// SetUplinkFrameFunc sets the UplinkFrame handler func.
	SetUplinkFrameFunc(func(*gw.UplinkFrame))

	// SetRawPacketForwarderEventFunc sets the RawPacketForwarderEvent handler func.
	SetRawPacketForwarderEventFunc(func(*gw.RawPacketForwarderEvent))

	// SetSubscribeEventFunc sets the Subscribe handler func.
	SetSubscribeEventFunc(func(events.Subscribe))

	// SendDownlinkFrame sends the given downlink frame.
	SendDownlinkFrame(*gw.DownlinkFrame) error

	// ApplyConfiguration applies the given configuration to the gateway.
	ApplyConfiguration(*gw.GatewayConfiguration) error

	// RawPacketForwarderCommand sends the given raw command to the packet-forwarder.
	RawPacketForwarderCommand(*gw.RawPacketForwarderCommand) error
}

Backend defines the interface that a backend must implement.

type BasicStationBackendConfig added in v1.0.4

type BasicStationBackendConfig struct {
	Bind             *string        `mapstructure:"bind"`
	TLSCert          *string        `mapstructure:"tls_cert"`
	TLSKey           *string        `mapstructure:"tls_key"`
	CACert           *string        `mapstructure:"ca_cert"`
	StatsInterval    *time.Duration `mapstructure:"stats_interval"`
	PingInterval     *time.Duration `mapstructure:"ping_interval"`
	TimesyncInterval *time.Duration `mapstructure:"timesync_interval"`
	ReadTimeout      *time.Duration `mapstructure:"read_timeout"`
	WriteTimeout     *time.Duration `mapstructure:"write_timeout"`
	Region           string         `mapstructure:"region"`
}

type BlockchainConfig

type BlockchainConfig struct {
	Polygon *BlockchainPolygonConfig
}

type BlockchainPolygonConfig

type BlockchainPolygonConfig struct {
	Endpoint      string
	ChainID       uint64 `mapstructure:"-"`
	Confirmations uint64
}

type Config

type Config struct {
	Forwarder  ForwarderConfig
	Log        LogConfig
	BlockChain BlockchainConfig
	Database   *struct {
		Postgresql *database.Config
	}
	Metrics *MetricsConfig
}

func (Config) MetricsPrometheusAddress

func (cfg Config) MetricsPrometheusAddress() string

func (Config) MetricsPrometheusPath

func (cfg Config) MetricsPrometheusPath() string

func (Config) PrometheusEnabled

func (cfg Config) PrometheusEnabled() bool

type CoverageClient

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

func NewCoverageClient

func NewCoverageClient(cfg *Config) (*CoverageClient, error)

func (*CoverageClient) DeliverDiscoveryPacketReceipt

func (cc *CoverageClient) DeliverDiscoveryPacketReceipt(ctx context.Context, region h3light.Cell, dpr *mapper.DiscoveryPacketReceipt) (*mapper.DiscoveryPacketReceiptResponse, error)

func (*CoverageClient) DeliverDownlinkConfirmationPacketReceipt added in v1.1.0

func (cc *CoverageClient) DeliverDownlinkConfirmationPacketReceipt(ctx context.Context, region h3light.Cell, dpr *mapper.DownlinkConfirmationPacketReceipt) error

func (*CoverageClient) Run added in v1.1.0

func (cc *CoverageClient) Run(ctx context.Context)

type Exchange

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

Exchange has several tasks: - it provides a backend on which trusted gateways can connect - it connects to ThingsIX routers - it keeps a routing table to exchange data between gateways and routers

func NewExchange

func NewExchange(ctx context.Context, cfg *Config) (*Exchange, error)

NewExchange instantiates a new packet exchange where gateways and routers can exchange packets.

func (*Exchange) Run

func (e *Exchange) Run(ctx context.Context)

Run the exchange until the given ctx expires.

type ForwarderBackendConfig

type ForwarderBackendConfig struct {
	SemtechUDP    *ForwarderBackendSemtechUDPConfig `mapstructure:"semtech_udp"`
	BasicStation  *BasicStationBackendConfig        `mapstructure:"basic_station"`
	Concentratord *struct{}                         `mapstructure:"concentratord"`
}

type ForwarderBackendSemtechUDPConfig

type ForwarderBackendSemtechUDPConfig struct {
	UDPBind    *string `mapstructure:"udp_bind"`
	FakeRxTime *bool   `mapstructure:"fake_rx_time"`
}

type ForwarderConfig

type ForwarderConfig struct {
	// Backend holdsconfiguration related to the forwarders gateway
	// endpoint and supported protocol.
	Backend ForwarderBackendConfig

	// Gateways holds configuration related to gateways.
	Gateways ForwarderGatewayConfig

	Routers ForwarderRoutersConfig

	Mapping ForwarderMappingConfig

	// Optional account strategy configuration, if not specified no account is used meaning
	// that all packets are exchanged between gateway and routers.
	Accounting *struct{}
}

type ForwarderGatewayConfig

type ForwarderGatewayConfig struct {
	// BatchOnboarder configures the gateway batch onboarder smart contract plugin.
	BatchOnboarder struct {
		// Address is the smart contract chain address
		Address common.Address `mapstructure:"address"`
	} `mapstructure:"batch_onboarder"`

	// BatchOnboarder configures the gateway early adopter onboarder smart contract plugin.
	EarlyAdopter struct {
		// Address is the smart contract chain address
		Address common.Address `mapstructure:"-"`
	}

	// Store describes how gateways are stored/loaded in the forwarder.
	Store gateway.StoreConfig

	// RecordUnknown records gateways that connect to the forwarder but
	// are not in the forwarders gateway store. Recorded gateways can
	// be imported later if required.
	RecordUnknown *gateway.ForwarderGatewayRecordUnknownConfig `mapstructure:"record_unknown"`

	// Registry describes how gateway data is retrieved from the ThingsIX
	// gateway registry.
	Registry gateway.RegistrySyncConfig `mapstructure:"registry"`

	// HttpAPI configures the private Forwarder HTTP API
	HttpAPI ForwarderHttpApiConfig `mapstructure:"api"`

	// ThingsIXOnboardEndpoint accepts gateway onboard messages for easy onboarding
	ThingsIXOnboardEndpoint string
}

type ForwarderHttpApiConfig added in v1.0.4

type ForwarderHttpApiConfig struct {
	Address string `mapstructure:"address"`
}

type ForwarderMappingConfig added in v1.1.0

type ForwarderMappingConfig struct {
	ThingsIXApi *ForwarderMappingThingsIXAPIConfig `mapstructure:"thingsix_api"`
}

type ForwarderMappingThingsIXAPIConfig added in v1.1.0

type ForwarderMappingThingsIXAPIConfig struct {
	IndexEndpoint *string `mapstructure:"index_endpoint"`
	// Interval indicates how often the coverage-mapping-indexes are refreshed
	UpdateInterval *time.Duration `mapstructure:"interval"`
}

type ForwarderRoutersConfig

type ForwarderRoutersConfig struct {
	// Default routers that will receive all gateway data unfiltered
	Default []*Router

	// OnChain idicates that ThingsIX routers are loaded from the router
	// registry as deployed on the blockchain.
	OnChain *ForwarderRoutersOnChainConfig `mapstructure:"on_chain"`

	// ThingsIXApi indicates when non-nil that router information must be
	// fetched from the ThingsIX API
	ThingsIXApi *ForwarderRoutersThingsIXAPIConfig `mapstructure:"thingsix_api"`
}

type ForwarderRoutersOnChainConfig

type ForwarderRoutersOnChainConfig struct {
	// RegistryContract indicates when non-nil that router information must
	// be fetched from the registry smart contract (required blockchain cfg)
	RegistryContract common.Address `mapstructure:"registry"`

	// Interval indicates how often the routes are refreshed
	UpdateInterval *time.Duration `mapstructure:"interval"`
}

type ForwarderRoutersThingsIXAPIConfig

type ForwarderRoutersThingsIXAPIConfig struct {
	Endpoint *string
	// Interval indicates how often the routes are refreshed
	UpdateInterval *time.Duration `mapstructure:"interval"`
}

type GatewayCollector added in v1.0.3

type GatewayCollector struct {
	Gateways []*gateway.Gateway
}

func (*GatewayCollector) Do added in v1.0.3

func (c *GatewayCollector) Do(gw *gateway.Gateway) bool

type GatewayEvent

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

GatewayEvent is the decoded event received from a gateway through the backend. It contains the raw payload together with some helper function to determine what kind of event was received.

func (GatewayEvent) IsDownlinkAck

func (ge GatewayEvent) IsDownlinkAck() bool

IsDownlinkAck returns an indication if the vent is a downlink ACK.

func (GatewayEvent) IsJoin

func (ge GatewayEvent) IsJoin() bool

IsJoin returns an indication if the vent is a join event.

func (GatewayEvent) IsOnlineOfflineEvent

func (ge GatewayEvent) IsOnlineOfflineEvent() bool

IsOnlineOfflineEvent is an indication if a gateway went offline or became online.

func (ge GatewayEvent) IsUplink() bool

IsUplink returns an indication if the event is an uplink event.

type ID

type ID [32]byte

func (ID) String

func (id ID) String() string

type LogConfig

type LogConfig struct {
	Level     logrus.Level
	Timestamp bool
}

type MapperForwarder

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

func NewMapperForwarder

func NewMapperForwarder(cfg *Config, exchange *Exchange, gatewayStore gateway.GatewayStore) (*MapperForwarder, error)

func (*MapperForwarder) HandleMapperPacket

func (mc *MapperForwarder) HandleMapperPacket(frame *gw.UplinkFrame, mac *lorawan.MACPayload)

func (*MapperForwarder) Run added in v1.1.0

func (mc *MapperForwarder) Run(ctx context.Context)

type MetricsConfig

type MetricsConfig struct {
	Prometheus *MetricsPrometheusConfig
}

type MetricsPrometheusConfig

type MetricsPrometheusConfig struct {
	Address string
	Path    string
}

type NetworkEvent

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

NetworkEvent represents an event received from the network

type NoAccounting

type NoAccounting struct {
}

func NewNoAccountingStrategy

func NewNoAccountingStrategy() *NoAccounting

NewNoAccountingStrategy returns an Accounter that allows all data to be forwarded to the router and ignore router payments.

func (NoAccounting) AddPayment

func (a NoAccounting) AddPayment(payment *router.AirtimePaymentEvent)

AddPayment ignores the given payment

func (NoAccounting) Allow

func (a NoAccounting) Allow(user common.Address, airtime time.Duration) bool

Allow all data to the given user

type OnboardGatewayReply added in v1.0.4

type OnboardGatewayReply struct {
	Owner                        common.Address     `json:"owner"`
	Address                      common.Address     `json:"address"`
	ChainID                      uint64             `json:"chainId"`
	GatewayID                    gateway.ThingsIxID `json:"gatewayId"`
	GatewayOnboardSignature      string             `json:"gatewayOnboardSignature"`
	EarlyAdopterOnboardSignature string             `json:"earlyAdopterOnboardSignature"`
	LocalID                      lorawan.EUI64      `json:"localId"`
	NetworkID                    lorawan.EUI64      `json:"networkId"`
	Version                      uint8              `json:"version"`
	Onboarder                    common.Address     `json:"onboarder"`
}

type Router

type Router struct {
	// ID is the routers identity as its registered in the smart contract
	ThingsIXID ID
	// Endpoint is the URI where the router can be reached
	Endpoint string
	// Default is an indication if the router is configured in the configuration and wants to receive all data
	Default bool
	// Name is an optional name users can appoint to routers that are in the configuration
	Name string
	// NetID is the NetID that a Router wants to receive traffic for
	NetID lorawan.NetID
	// Prefix is the DevAddr prefix that matches the DevAddr of devices the Router wants to receive traffic for
	Prefix uint32
	// Mask is the DevAddr mask  that matches the DevAddr of devices the Router wants to receive traffic for
	Mask uint8
	// Owner is the routers owner
	Owner common.Address
	// FrequencyPlan is the frequency plan this router is registered for
	FrequencyPlan frequency_plan.BlockchainFrequencyPlan
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter(id [32]byte, endpoint string, def bool, netID lorawan.NetID, prefix uint32, mask uint8, frequencyPlan frequency_plan.BlockchainFrequencyPlan, owner common.Address, accounting Accounter) *Router

func (*Router) AcceptsJoin

func (r *Router) AcceptsJoin(devEUI lorawan.EUI64) bool

AcceptsJoin returns an indication if the device that wants to join the network is accepted by this router.

func (*Router) AllowAirtime

func (r *Router) AllowAirtime(owner common.Address, airtime time.Duration) bool

func (*Router) InterestedIn

func (r *Router) InterestedIn(addr lorawan.DevAddr) bool

InterestedIn returns an indication if router is interested in a message from a device with the given devaddr.

func (*Router) SetJoinFilter

func (r *Router) SetJoinFilter(filter *xorfilter.Xor8, bitmap *roaring64.Bitmap)

func (*Router) String

func (r *Router) String() string

type RouterClient

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

RouterClient communicates with a remote router and exchanges messages between the router and the packet exchange.

func NewRouterClient

func NewRouterClient(router *Router,
	routeTableBroadcaster *broadcast.Broadcaster[[]*Router],
	routerEvents chan *NetworkEvent, gatewayEvents *broadcast.Broadcaster[*GatewayEvent],
	routerDetails <-chan *RouterDetails) *RouterClient

NewRouterClient create a new client that connects to a remote routers and handles communication with that router.

func (*RouterClient) Run

func (rc *RouterClient) Run(ctx context.Context)

Run the router client until the given context expires. This includes connecting to the router and opening a bidirectional stream to it to exchange packets.

type RouterDetails

type RouterDetails struct {
	// Endpoint is the URI where the router can be reached
	Endpoint string
	// NetID is the NetID that a Router wants to receive traffic for
	NetID lorawan.NetID
	// Prefix is the DevAddr prefix that matches the DevAddr of devices the Router wants to receive traffic for
	Prefix uint32
	// Mask is the DevAddr mask  that matches the DevAddr of devices the Router wants to receive traffic for
	Mask uint8
	// FrequencyPlan that this router is interested in
	FrequencyPlan frequency_plan.BlockchainFrequencyPlan
	// Owner is the routers owner
	Owner common.Address
}

type RoutesUpdaterFunc

type RoutesUpdaterFunc func() ([]*Router, error)

RoutesUpdaterFunc is a callback that retrieves routing information from ThingsIX. It returns the set of routers or an error in case the set could not be fetched.

type RoutingTable

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

RoutingTable takes care of the communication between the Packet Exchange and external routers. Received data from the packet exchange is routed to routers that have expressed interest in it.

func (*RoutingTable) Run

func (r *RoutingTable) Run(ctx context.Context)

Run starts the integration with the routers on the ThingsIX network until the given context expires.

It fetches the list of registered routers and opens connects with these routers. For each router a client is started that maintains the connection with the router and exchanges messages with it. Periodically the latest set of registered routers is fetched and nieuw router clients are started for fresh registered routers or clients are stopped/updated when they are either removed or updated.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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