Thibaut Vandervelden 2 жил өмнө
parent
commit
f04a44d6bc

+ 18 - 7
examples/sixlowpan.rs

@@ -86,18 +86,29 @@ fn main() {
         64,
     )];
 
-    let cache = FragmentsCache::new(vec![], BTreeMap::new());
-
-    let mut out_packet_buffer = [0u8; 1280];
-
     let mut builder = InterfaceBuilder::new()
         .ip_addrs(ip_addrs)
         .pan_id(Ieee802154Pan(0xbeef));
     builder = builder
         .hardware_addr(ieee802154_addr.into())
-        .neighbor_cache(neighbor_cache)
-        .sixlowpan_fragments_cache(cache)
-        .sixlowpan_out_packet_cache(&mut out_packet_buffer[..]);
+        .neighbor_cache(neighbor_cache);
+
+    #[cfg(feature = "proto-ipv4-fragmentation")]
+    {
+        let ipv4_frag_cache = FragmentsCache::new(vec![], BTreeMap::new());
+        builder = builder.ipv4_fragments_cache(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());
+        builder = builder
+            .sixlowpan_fragments_cache(sixlowpan_frag_cache)
+            .sixlowpan_out_packet_cache(&mut out_packet_buffer[..]);
+    }
+
     let mut iface = builder.finalize(&mut device);
 
     let mut sockets = SocketSet::new(vec![]);

+ 27 - 0
src/iface/fragmentation.rs

@@ -1,5 +1,7 @@
 #![allow(unused)]
 
+use core::fmt;
+
 use managed::{ManagedMap, ManagedSlice};
 
 use crate::storage::Assembler;
@@ -26,6 +28,23 @@ enum AssemblerState {
     },
 }
 
+impl fmt::Display for AssemblerState {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match self {
+            AssemblerState::NotInit => write!(f, "Not init")?,
+            AssemblerState::Assembling {
+                assembler,
+                total_size,
+                expires_at,
+                offset_correction,
+            } => {
+                write!(f, "{} expires at {}", assembler, expires_at)?;
+            }
+        }
+        Ok(())
+    }
+}
+
 impl<'a> PacketAssembler<'a> {
     /// Create a new empty buffer for fragments.
     pub fn new<S>(storage: S) -> Self
@@ -151,8 +170,16 @@ impl<'a> PacketAssembler<'a> {
                 let len = data.len();
                 self.buffer[offset..][..len].copy_from_slice(data);
 
+                net_debug!(
+                    "frag assembler: receiving {} octests at offset {}",
+                    len,
+                    offset
+                );
+
                 match assembler.add(offset, data.len()) {
                     Ok(overlap) => {
+                        net_debug!("assembler: {}", self.assembler);
+
                         if overlap {
                             net_debug!("packet was added, but there was an overlap.");
                         }