mirror of
https://github.com/smoltcp-rs/smoltcp.git
synced 2025-10-02 15:15:05 +00:00
Better names for buffers (#653)
This commit is contained in:
parent
297d90b0ff
commit
fe26f462dd
@ -9,7 +9,7 @@ use std::str::{self, FromStr};
|
||||
feature = "proto-sixlowpan-fragmentation",
|
||||
feature = "proto-ipv4-fragmentation"
|
||||
))]
|
||||
use smoltcp::iface::FragmentsCache;
|
||||
use smoltcp::iface::ReassemblyBuffer;
|
||||
|
||||
use smoltcp::iface::{InterfaceBuilder, NeighborCache, Routes, SocketSet};
|
||||
use smoltcp::phy::{wait as phy_wait, Device, Medium};
|
||||
@ -55,20 +55,20 @@ fn main() {
|
||||
let mut ipv4_out_packet_cache = [0u8; 1280];
|
||||
#[cfg(feature = "proto-ipv4-fragmentation")]
|
||||
{
|
||||
let ipv4_frag_cache = FragmentsCache::new(vec![], BTreeMap::new());
|
||||
let ipv4_frag_cache = ReassemblyBuffer::new(vec![], BTreeMap::new());
|
||||
builder = builder
|
||||
.ipv4_fragments_cache(ipv4_frag_cache)
|
||||
.ipv4_out_packet_cache(&mut ipv4_out_packet_cache[..]);
|
||||
.ipv4_reassembly_buffer(ipv4_frag_cache)
|
||||
.ipv4_fragmentation_buffer(&mut ipv4_out_packet_cache[..]);
|
||||
}
|
||||
|
||||
#[cfg(feature = "proto-sixlowpan-fragmentation")]
|
||||
let mut sixlowpan_out_packet_cache = [0u8; 1280];
|
||||
#[cfg(feature = "proto-sixlowpan-fragmentation")]
|
||||
{
|
||||
let sixlowpan_frag_cache = FragmentsCache::new(vec![], BTreeMap::new());
|
||||
let sixlowpan_frag_cache = ReassemblyBuffer::new(vec![], BTreeMap::new());
|
||||
builder = builder
|
||||
.sixlowpan_fragments_cache(sixlowpan_frag_cache)
|
||||
.sixlowpan_out_packet_cache(&mut sixlowpan_out_packet_cache[..]);
|
||||
.sixlowpan_reassembly_buffer(sixlowpan_frag_cache)
|
||||
.sixlowpan_fragmentation_buffer(&mut sixlowpan_out_packet_cache[..]);
|
||||
}
|
||||
|
||||
if medium == Medium::Ethernet {
|
||||
|
@ -9,7 +9,7 @@ use std::os::unix::io::AsRawFd;
|
||||
feature = "proto-sixlowpan-fragmentation",
|
||||
feature = "proto-ipv4-fragmentation"
|
||||
))]
|
||||
use smoltcp::iface::FragmentsCache;
|
||||
use smoltcp::iface::ReassemblyBuffer;
|
||||
use smoltcp::iface::{InterfaceBuilder, NeighborCache, SocketSet};
|
||||
use smoltcp::phy::{wait as phy_wait, Device, Medium};
|
||||
use smoltcp::socket::{tcp, udp};
|
||||
@ -78,20 +78,20 @@ fn main() {
|
||||
let mut ipv4_out_packet_cache = [0u8; 10_000];
|
||||
#[cfg(feature = "proto-ipv4-fragmentation")]
|
||||
{
|
||||
let ipv4_frag_cache = FragmentsCache::new(vec![], BTreeMap::new());
|
||||
let ipv4_frag_cache = ReassemblyBuffer::new(vec![], BTreeMap::new());
|
||||
builder = builder
|
||||
.ipv4_fragments_cache(ipv4_frag_cache)
|
||||
.ipv4_out_packet_cache(&mut ipv4_out_packet_cache[..]);
|
||||
.ipv4_reassembly_buffer(ipv4_frag_cache)
|
||||
.ipv4_fragmentation_buffer(&mut ipv4_out_packet_cache[..]);
|
||||
}
|
||||
|
||||
#[cfg(feature = "proto-sixlowpan-fragmentation")]
|
||||
let mut sixlowpan_out_packet_cache = [0u8; 1280];
|
||||
#[cfg(feature = "proto-sixlowpan-fragmentation")]
|
||||
{
|
||||
let sixlowpan_frag_cache = FragmentsCache::new(vec![], BTreeMap::new());
|
||||
let sixlowpan_frag_cache = ReassemblyBuffer::new(vec![], BTreeMap::new());
|
||||
builder = builder
|
||||
.sixlowpan_fragments_cache(sixlowpan_frag_cache)
|
||||
.sixlowpan_out_packet_cache(&mut sixlowpan_out_packet_cache[..]);
|
||||
.sixlowpan_reassembly_buffer(sixlowpan_frag_cache)
|
||||
.sixlowpan_fragmentation_buffer(&mut sixlowpan_out_packet_cache[..]);
|
||||
}
|
||||
|
||||
if medium == Medium::Ethernet {
|
||||
|
@ -47,7 +47,7 @@ use std::collections::BTreeMap;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::str;
|
||||
|
||||
use smoltcp::iface::{FragmentsCache, InterfaceBuilder, NeighborCache, SocketSet};
|
||||
use smoltcp::iface::{InterfaceBuilder, NeighborCache, ReassemblyBuffer, SocketSet};
|
||||
use smoltcp::phy::{wait as phy_wait, Medium, RawSocket};
|
||||
use smoltcp::socket::tcp;
|
||||
use smoltcp::socket::udp;
|
||||
@ -95,18 +95,18 @@ fn main() {
|
||||
|
||||
#[cfg(feature = "proto-ipv4-fragmentation")]
|
||||
{
|
||||
let ipv4_frag_cache = FragmentsCache::new(vec![], BTreeMap::new());
|
||||
builder = builder.ipv4_fragments_cache(ipv4_frag_cache);
|
||||
let ipv4_frag_cache = ReassemblyBuffer::new(vec![], BTreeMap::new());
|
||||
builder = builder.ipv4_reassembly_buffer(ipv4_frag_cache);
|
||||
}
|
||||
|
||||
#[cfg(feature = "proto-sixlowpan-fragmentation")]
|
||||
let mut out_packet_buffer = [0u8; 1280];
|
||||
#[cfg(feature = "proto-sixlowpan-fragmentation")]
|
||||
{
|
||||
let sixlowpan_frag_cache = FragmentsCache::new(vec![], BTreeMap::new());
|
||||
let sixlowpan_frag_cache = ReassemblyBuffer::new(vec![], BTreeMap::new());
|
||||
builder = builder
|
||||
.sixlowpan_fragments_cache(sixlowpan_frag_cache)
|
||||
.sixlowpan_out_packet_cache(&mut out_packet_buffer[..]);
|
||||
.sixlowpan_reassembly_buffer(sixlowpan_frag_cache)
|
||||
.sixlowpan_fragmentation_buffer(&mut out_packet_buffer[..]);
|
||||
}
|
||||
|
||||
let mut iface = builder.finalize(&mut device);
|
||||
|
@ -48,7 +48,7 @@ use std::collections::BTreeMap;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::str;
|
||||
|
||||
use smoltcp::iface::{FragmentsCache, InterfaceBuilder, NeighborCache, SocketSet};
|
||||
use smoltcp::iface::{InterfaceBuilder, NeighborCache, ReassemblyBuffer, SocketSet};
|
||||
use smoltcp::phy::{wait as phy_wait, Medium, RawSocket};
|
||||
use smoltcp::socket::tcp;
|
||||
use smoltcp::wire::{Ieee802154Pan, IpAddress, IpCidr};
|
||||
@ -166,7 +166,7 @@ fn main() {
|
||||
64,
|
||||
)];
|
||||
|
||||
let cache = FragmentsCache::new(vec![], BTreeMap::new());
|
||||
let cache = ReassemblyBuffer::new(vec![], BTreeMap::new());
|
||||
|
||||
let mut builder = InterfaceBuilder::new()
|
||||
.ip_addrs(ip_addrs)
|
||||
@ -174,8 +174,8 @@ fn main() {
|
||||
builder = builder
|
||||
.hardware_addr(ieee802154_addr.into())
|
||||
.neighbor_cache(neighbor_cache)
|
||||
.sixlowpan_fragments_cache(cache)
|
||||
.sixlowpan_out_packet_cache(vec![]);
|
||||
.sixlowpan_reassembly_buffer(cache)
|
||||
.sixlowpan_fragmentation_buffer(vec![]);
|
||||
let mut iface = builder.finalize(&mut device);
|
||||
|
||||
let mut sockets = SocketSet::new(vec![]);
|
||||
|
@ -286,7 +286,7 @@ pub struct InterfaceBuilder<'a> {
|
||||
#[cfg(feature = "proto-sixlowpan-fragmentation")]
|
||||
sixlowpan_fragments: PacketAssemblerSet<'a, SixlowpanFragKey>,
|
||||
#[cfg(feature = "proto-sixlowpan-fragmentation")]
|
||||
sixlowpan_fragments_cache_timeout: Duration,
|
||||
sixlowpan_reassembly_buffer_timeout: Duration,
|
||||
#[cfg(feature = "proto-sixlowpan-fragmentation")]
|
||||
sixlowpan_out_buffer: ManagedSlice<'a, u8>,
|
||||
}
|
||||
@ -325,8 +325,8 @@ let builder = InterfaceBuilder::new()
|
||||
|
||||
# #[cfg(feature = "proto-ipv4-fragmentation")]
|
||||
let builder = builder
|
||||
.ipv4_fragments_cache(ipv4_frag_cache)
|
||||
.ipv4_out_packet_cache(vec![]);
|
||||
.ipv4_reassembly_buffer(ipv4_frag_cache)
|
||||
.ipv4_fragmentation_buffer(vec![]);
|
||||
|
||||
let iface = builder.finalize(&mut device);
|
||||
```
|
||||
@ -359,7 +359,7 @@ let iface = builder.finalize(&mut device);
|
||||
#[cfg(feature = "proto-sixlowpan-fragmentation")]
|
||||
sixlowpan_fragments: PacketAssemblerSet::new(&mut [][..], &mut [][..]),
|
||||
#[cfg(feature = "proto-sixlowpan-fragmentation")]
|
||||
sixlowpan_fragments_cache_timeout: Duration::from_secs(60),
|
||||
sixlowpan_reassembly_buffer_timeout: Duration::from_secs(60),
|
||||
#[cfg(feature = "proto-sixlowpan-fragmentation")]
|
||||
sixlowpan_out_buffer: ManagedSlice::Borrowed(&mut [][..]),
|
||||
}
|
||||
@ -474,13 +474,13 @@ let iface = builder.finalize(&mut device);
|
||||
}
|
||||
|
||||
#[cfg(feature = "proto-ipv4-fragmentation")]
|
||||
pub fn ipv4_fragments_cache(mut self, storage: PacketAssemblerSet<'a, Ipv4FragKey>) -> Self {
|
||||
pub fn ipv4_reassembly_buffer(mut self, storage: PacketAssemblerSet<'a, Ipv4FragKey>) -> Self {
|
||||
self.ipv4_fragments = storage;
|
||||
self
|
||||
}
|
||||
|
||||
#[cfg(feature = "proto-ipv4-fragmentation")]
|
||||
pub fn ipv4_out_packet_cache<T>(mut self, storage: T) -> Self
|
||||
pub fn ipv4_fragmentation_buffer<T>(mut self, storage: T) -> Self
|
||||
where
|
||||
T: Into<ManagedSlice<'a, u8>>,
|
||||
{
|
||||
@ -489,7 +489,7 @@ let iface = builder.finalize(&mut device);
|
||||
}
|
||||
|
||||
#[cfg(feature = "proto-sixlowpan-fragmentation")]
|
||||
pub fn sixlowpan_fragments_cache(
|
||||
pub fn sixlowpan_reassembly_buffer(
|
||||
mut self,
|
||||
storage: PacketAssemblerSet<'a, SixlowpanFragKey>,
|
||||
) -> Self {
|
||||
@ -498,16 +498,16 @@ let iface = builder.finalize(&mut device);
|
||||
}
|
||||
|
||||
#[cfg(feature = "proto-sixlowpan-fragmentation")]
|
||||
pub fn sixlowpan_fragments_cache_timeout(mut self, timeout: Duration) -> Self {
|
||||
pub fn sixlowpan_reassembly_buffer_timeout(mut self, timeout: Duration) -> Self {
|
||||
if timeout > Duration::from_secs(60) {
|
||||
net_debug!("RFC 4944 specifies that the reassembly timeout MUST be set to a maximum of 60 seconds");
|
||||
}
|
||||
self.sixlowpan_fragments_cache_timeout = timeout;
|
||||
self.sixlowpan_reassembly_buffer_timeout = timeout;
|
||||
self
|
||||
}
|
||||
|
||||
#[cfg(feature = "proto-sixlowpan-fragmentation")]
|
||||
pub fn sixlowpan_out_packet_cache<T>(mut self, storage: T) -> Self
|
||||
pub fn sixlowpan_fragmentation_buffer<T>(mut self, storage: T) -> Self
|
||||
where
|
||||
T: Into<ManagedSlice<'a, u8>>,
|
||||
{
|
||||
@ -611,7 +611,7 @@ let iface = builder.finalize(&mut device);
|
||||
#[cfg(feature = "proto-sixlowpan-fragmentation")]
|
||||
sixlowpan_fragments: self.sixlowpan_fragments,
|
||||
#[cfg(feature = "proto-sixlowpan-fragmentation")]
|
||||
sixlowpan_fragments_cache_timeout: self.sixlowpan_fragments_cache_timeout,
|
||||
sixlowpan_fragments_cache_timeout: self.sixlowpan_reassembly_buffer_timeout,
|
||||
|
||||
#[cfg(not(any(
|
||||
feature = "proto-ipv4-fragmentation",
|
||||
@ -3817,8 +3817,8 @@ mod test {
|
||||
|
||||
#[cfg(feature = "proto-ipv4-fragmentation")]
|
||||
let iface_builder = iface_builder
|
||||
.ipv4_fragments_cache(PacketAssemblerSet::new(vec![], BTreeMap::new()))
|
||||
.ipv4_out_packet_cache(vec![]);
|
||||
.ipv4_reassembly_buffer(PacketAssemblerSet::new(vec![], BTreeMap::new()))
|
||||
.ipv4_fragmentation_buffer(vec![]);
|
||||
|
||||
#[cfg(feature = "proto-igmp")]
|
||||
let iface_builder = iface_builder.ipv4_multicast_groups(BTreeMap::new());
|
||||
@ -3847,13 +3847,13 @@ mod test {
|
||||
|
||||
#[cfg(feature = "proto-sixlowpan-fragmentation")]
|
||||
let iface_builder = iface_builder
|
||||
.sixlowpan_fragments_cache(PacketAssemblerSet::new(vec![], BTreeMap::new()))
|
||||
.sixlowpan_out_packet_cache(vec![]);
|
||||
.sixlowpan_reassembly_buffer(PacketAssemblerSet::new(vec![], BTreeMap::new()))
|
||||
.sixlowpan_fragmentation_buffer(vec![]);
|
||||
|
||||
#[cfg(feature = "proto-ipv4-fragmentation")]
|
||||
let iface_builder = iface_builder
|
||||
.ipv4_fragments_cache(PacketAssemblerSet::new(vec![], BTreeMap::new()))
|
||||
.ipv4_out_packet_cache(vec![]);
|
||||
.ipv4_reassembly_buffer(PacketAssemblerSet::new(vec![], BTreeMap::new()))
|
||||
.ipv4_fragmentation_buffer(vec![]);
|
||||
|
||||
#[cfg(feature = "proto-igmp")]
|
||||
let iface_builder = iface_builder.ipv4_multicast_groups(BTreeMap::new());
|
||||
|
@ -23,6 +23,6 @@ pub use self::route::{Route, Routes};
|
||||
pub use socket_set::{SocketHandle, SocketSet, SocketStorage};
|
||||
|
||||
#[cfg(any(feature = "proto-ipv4", feature = "proto-sixlowpan"))]
|
||||
pub use self::fragmentation::{PacketAssembler, PacketAssemblerSet as FragmentsCache};
|
||||
pub use self::fragmentation::{PacketAssembler, PacketAssemblerSet as ReassemblyBuffer};
|
||||
|
||||
pub use self::interface::{Interface, InterfaceBuilder, InterfaceInner as Context};
|
||||
|
@ -2067,14 +2067,14 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn sixlowpan_three_fragments() {
|
||||
use crate::iface::FragmentsCache;
|
||||
use crate::iface::ReassemblyBuffer;
|
||||
use crate::time::Instant;
|
||||
use crate::wire::ieee802154::Frame as Ieee802154Frame;
|
||||
use crate::wire::ieee802154::Repr as Ieee802154Repr;
|
||||
use crate::wire::Ieee802154Address;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
let mut frags_cache = FragmentsCache::new(vec![], BTreeMap::new());
|
||||
let mut frags_cache = ReassemblyBuffer::new(vec![], BTreeMap::new());
|
||||
|
||||
let frame1: &[u8] = &[
|
||||
0x41, 0xcc, 0x92, 0xef, 0xbe, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x0b, 0x1a, 0xd9,
|
||||
|
Loading…
x
Reference in New Issue
Block a user