Expand description
The network side of a single site: what a server does with what a gateway forwarded.
A gateway hands over packets without reading them, because it holds no keys. Deciding
what a packet is, admitting the device that sent it, decrypting what it carries, and
working out when and where to answer is the network server’s work, and this module does
that much of it for one site: a Network holds the devices it admits, the sessions it
has granted, and the counters it has seen, and turns an Rxpk into an Event.
It runs no sockets and keeps no clock. An uplink goes in as the gateway reported it, and
a downlink comes back as a Txpk ready for a PULL_RESP, timed in the concentrator’s
own microseconds, so the caller owns every decision about the wire.
The windows come from the published parameters rather than from habit. RP002-1.0.5
section 3.3 gives the delays that are recommended for every region, TS001-1.0.4 gives the
layout of the two bytes a join accept carries, and the channel a first window answers on
is regional: Rx1Channels carries the two shapes the specification defines.
§Examples
A device joins, sends a reading, and is answered in its first receive window.
use pamoja_gateway::network::{Event, Network, Registration};
use pamoja_gateway::udp::Rxpk;
use pamoja_lora::region::Region;
use pamoja_lora::LinkSettings;
use pamoja_lorawan::Device;
let mut network = Network::new(Region::Eu868.plan(), 0x00_00_2A);
let device = Device::new([1; 8], [2; 8], [3; 16]);
network.register(Registration::new([1; 8], [2; 8], [3; 16]));
// The gateway forwards the join request it heard.
let link = LinkSettings::new(7, 125_000);
let request = device.join_request(0x1234);
let heard = Rxpk::new(868_100_000, link, request.as_bytes().to_vec()).with_timestamp_us(1_000);
let joined = network.uplink(&heard).expect("the request verifies");
assert!(matches!(joined, Event::Joined { .. }));Structs§
- Network
- The network side of one site.
- Registration
- A device the network admits, and the key it was provisioned with.
- Slot
- Where and when a downlink answers an uplink, in the concentrator’s own terms.
- Windows
- When and where a network answers, and at what rate.
Enums§
- Event
- What a forwarded packet turned out to be.
- Network
Error - What can go wrong admitting or reading a forwarded packet.
- Rx1Channels
- The channel the first receive window answers on, which the region decides.
Constants§
- JOIN_
ACCEPT_ DELA Y1_ US - The delay before the first window a join accept may be sent in, in microseconds.
- JOIN_
ACCEPT_ DELA Y2_ US - The delay before the second window a join accept may be sent in, in microseconds.
- MAX_
FCNT_ GAP - How far ahead of the counter it has seen a network will follow a device.
- RECEIVE_
DELA Y1_ US - The delay between the end of an uplink and the opening of the first receive window, in microseconds, as RP002-1.0.5 section 3.3 recommends for every region.
- RECEIVE_
DELA Y2_ US - The delay before the second receive window, which the same table fixes at one second after the first.