Skip to main content

NetworkLayer

Struct NetworkLayer 

Source
pub struct NetworkLayer<T: TransportPort> { /* private fields */ }
Expand description

Non-router BACnet network layer.

Wraps a TransportPort and provides APDU-level send/receive by handling NPDU framing. This layer does not act as a router (it does not forward messages between networks), but it can send to remote devices through local routers using NPDU destination addressing.

Implementations§

Source§

impl<T: TransportPort + 'static> NetworkLayer<T>

Source

pub fn new(transport: T) -> Self

Create a new network layer wrapping the given transport.

Source

pub fn enable_network_control_receiver( &mut self, ) -> Result<Receiver<ReceivedNetworkControl>, Error>

Enable the one-consumer decoded network-control stream.

This must be called before Self::start and at most once. Dropping the returned receiver disables control delivery without affecting APDU ingress.

Source

pub async fn start(&mut self) -> Result<Receiver<ReceivedApdu>, Error>

Start the network layer. Returns a receiver for incoming APDUs.

This starts the underlying transport and spawns a dispatch task that decodes incoming NPDUs and extracts APDUs.

Source

pub async fn send_apdu( &self, apdu: &[u8], destination_mac: &[u8], expecting_reply: bool, priority: NetworkPriority, ) -> Result<(), Error>

Send an APDU to a specific local destination by MAC address.

Source

pub async fn send_apdu_with_data_attributes( &self, apdu: &[u8], destination_mac: &[u8], expecting_reply: bool, priority: NetworkPriority, data_attributes: &[DataAttribute], ) -> Result<(), Error>

Send an APDU with data attributes to a specific local destination.

Source

pub async fn broadcast_apdu( &self, apdu: &[u8], expecting_reply: bool, priority: NetworkPriority, ) -> Result<(), Error>

Broadcast an APDU on the local network.

Source

pub async fn broadcast_apdu_with_data_attributes( &self, apdu: &[u8], expecting_reply: bool, priority: NetworkPriority, data_attributes: &[DataAttribute], ) -> Result<(), Error>

Broadcast an APDU with data attributes on the local network.

Source

pub async fn broadcast_global_apdu( &self, apdu: &[u8], expecting_reply: bool, priority: NetworkPriority, ) -> Result<(), Error>

Broadcast an APDU globally (DNET=0xFFFF, hop_count=255).

Unlike broadcast_apdu() which only reaches the local subnet, this sets DNET=0xFFFF so routers will forward to all reachable networks.

Source

pub async fn broadcast_global_apdu_with_data_attributes( &self, apdu: &[u8], expecting_reply: bool, priority: NetworkPriority, data_attributes: &[DataAttribute], ) -> Result<(), Error>

Broadcast an APDU globally with data attributes (DNET=0xFFFF, hop_count=255).

Source

pub async fn broadcast_to_network( &self, apdu: &[u8], dest_network: u16, expecting_reply: bool, priority: NetworkPriority, ) -> Result<(), Error>

Broadcast an APDU to a specific remote network via routers.

Like broadcast_global_apdu() but targets a single network number instead of all networks (DNET=0xFFFF).

Source

pub async fn broadcast_to_network_with_data_attributes( &self, apdu: &[u8], dest_network: u16, expecting_reply: bool, priority: NetworkPriority, data_attributes: &[DataAttribute], ) -> Result<(), Error>

Broadcast an APDU with data attributes to a specific remote network via routers.

Source

pub async fn send_apdu_routed( &self, apdu: &[u8], dest_network: u16, dest_mac: &[u8], router_mac: &[u8], expecting_reply: bool, priority: NetworkPriority, ) -> Result<(), Error>

Send an APDU to a remote device through a local router.

The NPDU is sent via unicast to router_mac (the next-hop router on the local network), but the NPDU header addresses the final destination with dest_network / dest_mac.

Source

pub async fn send_apdu_routed_with_data_attributes( &self, apdu: &[u8], dest_network: u16, dest_mac: &[u8], router_mac: &[u8], expecting_reply: bool, priority: NetworkPriority, data_attributes: &[DataAttribute], ) -> Result<(), Error>

Send an APDU with data attributes to a remote device through a local router.

Source

pub async fn send_apdu_routed_via_local_broadcast( &self, apdu: &[u8], dest_network: u16, dest_mac: &[u8], expecting_reply: bool, priority: NetworkPriority, ) -> Result<(), Error>

Send a routed APDU with a broadcast link DA, for when the next-hop router’s MAC is unknown.

Clause 6.5.3: the data link DA “shall be the MAC address of the BACnet router corresponding to the DNET parameter or the appropriate broadcast DA if the address of the router is initially unknown”. The NPDU still addresses one device via DNET/DADR, which is why Clause 6.3’s broadcast restriction does not bite: “a MAC layer multicast or broadcast address may be used for other PDU types when the network layer address restricts the destination to a single device”.

Source

pub async fn send_apdu_routed_via_local_broadcast_with_data_attributes( &self, apdu: &[u8], dest_network: u16, dest_mac: &[u8], expecting_reply: bool, priority: NetworkPriority, data_attributes: &[DataAttribute], ) -> Result<(), Error>

Send a routed APDU with data attributes and a broadcast link DA.

Source

pub fn transport(&self) -> &T

Access the underlying transport.

Useful for transport-specific operations like BBMD registration after the network layer has been started.

Source

pub fn local_mac(&self) -> &[u8] ⓘ

Get the transport’s local MAC address.

Source

pub fn network_control_ingress_sequence(&self) -> u64

Sequence assigned to the most recently decoded network-control ingress.

The value is updated before the control is queued for its opt-in consumer. At counter exhaustion it remains at u64::MAX, which makes sequence-based consumers fail closed rather than accepting an alias.

Source

pub async fn stop(&mut self) -> Result<(), Error>

Stop the network layer and underlying transport.

Trait Implementations§

Source§

impl<T: TransportPort> Drop for NetworkLayer<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<T> Freeze for NetworkLayer<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for NetworkLayer<T>
where T: RefUnwindSafe,

§

impl<T> Send for NetworkLayer<T>

§

impl<T> Sync for NetworkLayer<T>

§

impl<T> Unpin for NetworkLayer<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for NetworkLayer<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for NetworkLayer<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more