diff --git a/a653rs-router-linux/src/network.rs b/a653rs-router-linux/src/network.rs index cceab63..d863bb2 100644 --- a/a653rs-router-linux/src/network.rs +++ b/a653rs-router-linux/src/network.rs @@ -1,6 +1,6 @@ use a653rs_linux::partition::ApexLinuxPartition; use a653rs_router::prelude::*; -use std::{mem::size_of, net::UdpSocket}; +use std::net::UdpSocket; #[derive(Debug)] pub struct UdpNetworkInterface; @@ -15,14 +15,8 @@ impl PlatformNetworkInterface for UdpNetworkInterface { let sock = get_interface(id)?; match sock.sock.recv(buffer) { Ok(read) => { - let vl_id_len = size_of::(); - let vl_id = &buffer[0..vl_id_len]; - let mut vl_id_buf = [0u8; size_of::()]; - vl_id_buf.copy_from_slice(vl_id); - let vl_id = u32::from_be_bytes(vl_id_buf); - let _vl_id = VirtualLinkId::from_u32(vl_id); - let msg = &buffer[vl_id_len..read]; - router_trace!("Received message from UDP socket for VL {vl_id}: {:?}", msg); + let msg = &buffer[..read]; + router_trace!("Received message from UDP socket"); Ok(msg) } Err(_) => Err(InterfaceError::NoData), @@ -31,18 +25,15 @@ impl PlatformNetworkInterface for UdpNetworkInterface { fn platform_interface_send_unchecked( id: NetworkInterfaceId, - vl: VirtualLinkId, buffer: &[u8], ) -> Result { // This is safe, because the interfaces are only created before the list of // interfaces is used let sock = get_interface(id)?; - let vlid = vl.into_inner().to_be_bytes(); - let udp_buf = [vlid.as_slice(), buffer].concat(); - let res = sock.sock.send(&udp_buf); + let res = sock.sock.send(buffer); match res { Ok(trans) => { - router_trace!("Send {} bytes to UDP socket", udp_buf.len()); + router_trace!("Send {} bytes to UDP socket", buffer.len()); Ok(trans) } Err(e) => { diff --git a/a653rs-router-tests/src/lib.rs b/a653rs-router-tests/src/lib.rs index 309b221..f217fab 100644 --- a/a653rs-router-tests/src/lib.rs +++ b/a653rs-router-tests/src/lib.rs @@ -172,7 +172,6 @@ pub struct DummyNetIntf; impl PlatformNetworkInterface for DummyNetIntf { fn platform_interface_send_unchecked( _id: NetworkInterfaceId, - _vl: a653rs_router::prelude::VirtualLinkId, _buffer: &[u8], ) -> Result { Ok(1) diff --git a/a653rs-router-zynq7000/src/network.rs b/a653rs-router-zynq7000/src/network.rs index 81d5d04..a6a9522 100644 --- a/a653rs-router-zynq7000/src/network.rs +++ b/a653rs-router-zynq7000/src/network.rs @@ -1,6 +1,6 @@ use a653rs_router::prelude::{ CreateNetworkInterfaceId, InterfaceConfig, InterfaceError, NetworkInterfaceId, - PlatformNetworkInterface, VirtualLinkId, + PlatformNetworkInterface, }; use cobs::{decode_in_place, encode}; use core::mem::size_of; @@ -21,7 +21,6 @@ mod config { } struct UartFrame<'p, const MTU: usize> { - vl: VirtualLinkId, pl: &'p [u8], } @@ -49,25 +48,21 @@ impl<'p, const MTU: usize> UartFrame<'p, MTU> { return Err(()); } - // VL ID - let vl_id: [u8; 2] = (self.vl.into_inner() as u16).to_be_bytes(); - buf[0..2].copy_from_slice(&vl_id); - // Payload - buf[2..self.pl.len() + 2].copy_from_slice(self.pl); + buf[..self.pl.len()].copy_from_slice(self.pl); // CRC - let crc = crc16::State::::calculate(&buf[..self.pl.len() + 2]); + let crc = crc16::State::::calculate(&buf[..self.pl.len()]); let crc: [u8; 2] = crc.to_be_bytes(); - buf[self.pl.len() + 2..self.pl.len() + 4].copy_from_slice(&crc); + buf[self.pl.len()..self.pl.len() + 2].copy_from_slice(&crc); // COBS encode - let enclen = encode(&buf[0..self.pl.len() + 4], encoded); + let enclen = encode(&buf[0..self.pl.len() + 2], encoded); Ok(&encoded[..enclen]) } - fn decode(buf: &mut [u8]) -> Result<(VirtualLinkId, &[u8]), ()> { + fn decode(buf: &mut [u8]) -> Result<&[u8], ()> { // COBS decode let declen = decode_in_place(buf).or(Err(()))?; @@ -85,12 +80,7 @@ impl<'p, const MTU: usize> UartFrame<'p, MTU> { return Err(()); } - // VL ID - let (vl, pl) = msg.split_at(2); - let vl: [u8; 2] = vl.try_into().or(Err(()))?; - let vl = u16::from_be_bytes(vl); - - Ok((VirtualLinkId::from_u32(vl as u32), pl)) + Ok(msg) } } @@ -198,7 +188,7 @@ where } } match UartFrame::::decode(&mut buf) { - Ok((_vl, pl)) => { + Ok(pl) => { let rpl = &mut buffer[0..pl.len()]; rpl.copy_from_slice(pl); trace!(end_network_receive, id.0 as u16); @@ -213,11 +203,10 @@ where fn platform_interface_send_unchecked( id: NetworkInterfaceId, - vl: VirtualLinkId, buffer: &[u8], ) -> Result { let mut buf = [0u8; UartFrame::::max_encoded_len()]; - let frame = UartFrame:: { vl, pl: buffer }; + let frame = UartFrame:: { pl: buffer }; let encoded = UartFrame::::encode(&frame, &mut buf).or(Err(InterfaceError::InvalidData))?; diff --git a/a653rs-router/src/network.rs b/a653rs-router/src/network.rs index 9538821..9424a68 100644 --- a/a653rs-router/src/network.rs +++ b/a653rs-router/src/network.rs @@ -1,7 +1,7 @@ use crate::{ ports::PortError, router::{RouterInput, RouterOutput}, - types::{DataRate, VirtualLinkId}, + types::DataRate, }; use core::{ @@ -45,13 +45,13 @@ pub struct NetworkInterface { impl NetworkInterface { /// Sends data to the interface. - pub fn send(&self, vl: &VirtualLinkId, buf: &[u8]) -> Result { + pub fn send(&self, buf: &[u8]) -> Result { if buf.len() > self.mtu { return Err(InterfaceError::InsufficientBuffer); } router_trace!("Sending to interface"); - H::platform_interface_send_unchecked(self.id, *vl, buf) + H::platform_interface_send_unchecked(self.id, buf) } /// Receives data from the interface. @@ -69,7 +69,6 @@ pub trait PlatformNetworkInterface { /// Send something to the network and report how long it took. fn platform_interface_send_unchecked( id: NetworkInterfaceId, - vl: VirtualLinkId, buffer: &[u8], ) -> Result; @@ -158,13 +157,11 @@ impl RouterInput for NetworkInterface { } impl RouterOutput for NetworkInterface { - fn send(&self, vl: &VirtualLinkId, buf: &[u8]) -> Result<(), PortError> { - NetworkInterface::send(self, vl, buf) - .map(|_| ()) - .map_err(|e| { - router_debug!("Failed to send to network interface: {:?}", e); - PortError::Send - }) + fn send(&self, buf: &[u8]) -> Result<(), PortError> { + NetworkInterface::send(self, buf).map(|_| ()).map_err(|e| { + router_debug!("Failed to send to network interface: {:?}", e); + PortError::Send + }) } fn mtu(&self) -> PayloadSize { diff --git a/a653rs-router/src/ports.rs b/a653rs-router/src/ports.rs index 24e2726..2f5b562 100644 --- a/a653rs-router/src/ports.rs +++ b/a653rs-router/src/ports.rs @@ -82,7 +82,7 @@ impl RouterInput for QueuingIn { } impl RouterOutput for QueuingOut { - fn send(&self, _vl: &VirtualLinkId, buf: &[u8]) -> Result<(), PortError> { + fn send(&self, buf: &[u8]) -> Result<(), PortError> { let buf = buf.validate_write(self.inner.msg_size)?; let timeout = Duration::from_micros(10).as_nanos() as ApexSystemTime; ::send_queuing_message(self.inner.id, buf, timeout) @@ -95,7 +95,7 @@ impl RouterOutput for QueuingOut { } impl RouterOutput for SamplingOut { - fn send(&self, _vl: &VirtualLinkId, buf: &[u8]) -> Result<(), PortError> { + fn send(&self, buf: &[u8]) -> Result<(), PortError> { let buf = buf.validate_write(self.inner.msg_size)?; ::write_sampling_message(self.inner.id, buf) .map_err(|_e| PortError::Send) @@ -210,10 +210,10 @@ impl RouterInput for SamplingPortDe } impl RouterOutput for SamplingPortSource { - fn send(&self, vl: &VirtualLinkId, buf: &[u8]) -> Result<(), PortError> { - router_bench!(begin_apex_send, vl.0 as u16); + fn send(&self, buf: &[u8]) -> Result<(), PortError> { + router_bench!(begin_apex_send, self.id() as u16); let res = self.send(buf); - router_bench!(end_apex_send, vl.0 as u16); + router_bench!(end_apex_send, self.id() as u16); res.map_err(|_e| PortError::Send)?; Ok(()) } @@ -243,11 +243,11 @@ impl RouterIn impl RouterOutput for QueuingPortSender { - fn send(&self, vl: &VirtualLinkId, buf: &[u8]) -> Result<(), PortError> { + fn send(&self, buf: &[u8]) -> Result<(), PortError> { let timeout = SystemTime::Normal(Duration::from_micros(10)); - router_bench!(begin_apex_send, vl.0 as u16); + router_bench!(begin_apex_send, self.id() as u16); let res = self.send(buf, timeout); - router_bench!(end_apex_send, vl.0 as u16); + router_bench!(end_apex_send, self.id() as u16); res.map_err(|_e| PortError::Send)?; Ok(()) } diff --git a/a653rs-router/src/router.rs b/a653rs-router/src/router.rs index 6f2d1fd..1bd5906 100644 --- a/a653rs-router/src/router.rs +++ b/a653rs-router/src/router.rs @@ -166,7 +166,7 @@ pub trait RouterOutput { /// Sends `buf` to a virtual link on this `Output`. /// /// Returns a slice to the portion of `buf` that has *not* been transmitted. - fn send(&self, vl: &VirtualLinkId, buf: &[u8]) -> Result<(), PortError>; + fn send(&self, buf: &[u8]) -> Result<(), PortError>; /// Maximum transfer unit fn mtu(&self) -> PayloadSize; @@ -193,7 +193,7 @@ impl<'a, const I: usize, const O: usize> RouteTable<'a, I, O> { router_debug!("Received from {vl:?}: {buf:?}"); let outs = self.outputs.get(vl).ok_or(RouteError::InvalidVl)?; for out in outs.into_iter() { - out.send(vl, buf).map_err(|e| { + out.send(buf).map_err(|e| { router_debug!("Failed to route {:?}", vl); e })?;