UDP multicast allows a sender to transmit a single packet that is received by all subscribers to a multicast group address. Unlike unicast (one-to-one) or broadcast (one-to-all), multicast is one-to-many-interested.

Multicast address range: 224.0.0.0 to 239.255.255.255 (IPv4). For local network simulation, 239.x.x.x is the typical choice.

SpaceCAN virtual layer

The simulation harness runs multiple virtual CAN nodes as Tokio tasks. Each node joins a multicast group on the loopback interface. When one node "transmits" a CAN frame, it sends to the multicast address. All other nodes receive it — exactly simulating CAN bus broadcast behaviour.

use tokio::net::UdpSocket;

let socket = UdpSocket::bind("0.0.0.0:0").await?;
socket.join_multicast_v4(
    "239.1.2.3".parse()?,
    "127.0.0.1".parse()?  // interface
)?;
socket.set_multicast_loop_v4(true)?; // receive own transmissions

// Transmit: send to multicast group
socket.send_to(&frame_bytes, "239.1.2.3:4242").await?;

// Receive: normal recv
let mut buf = [0u8; 13];
socket.recv_from(&mut buf).await?;

The multicast approach means adding a new virtual node requires zero configuration changes to existing nodes — they all receive all traffic and filter by APID.