浏览代码

assembler: remove offset correction.

Dario Nieuwenhuis 2 年之前
父节点
当前提交
413b205531
共有 2 个文件被更改,包括 9 次插入99 次删除
  1. 0 10
      src/iface/fragmentation.rs
  2. 9 89
      src/wire/sixlowpan.rs

+ 0 - 10
src/iface/fragmentation.rs

@@ -40,7 +40,6 @@ pub struct PacketAssembler<K> {
     assembler: Assembler,
     total_size: Option<usize>,
     expires_at: Instant,
-    offset_correction: isize,
 }
 
 impl<K> PacketAssembler<K> {
@@ -57,7 +56,6 @@ impl<K> PacketAssembler<K> {
             assembler: Assembler::new(),
             total_size: None,
             expires_at: Instant::ZERO,
-            offset_correction: 0,
         }
     }
 
@@ -66,11 +64,6 @@ impl<K> PacketAssembler<K> {
         self.assembler.clear();
         self.total_size = None;
         self.expires_at = Instant::ZERO;
-        self.offset_correction = 0;
-    }
-
-    pub(crate) fn set_offset_correction(&mut self, correction: isize) {
-        self.offset_correction = correction;
     }
 
     /// Set the total size of the packet assembler.
@@ -137,9 +130,6 @@ impl<K> PacketAssembler<K> {
     /// - Returns [`Error::PacketAssemblerBufferTooSmall`] when trying to add data into the buffer at a non-existing
     /// place.
     pub(crate) fn add(&mut self, data: &[u8], offset: usize) -> Result<(), AssemblerError> {
-        let offset = offset as isize + self.offset_correction;
-        let offset = if offset <= 0 { 0 } else { offset as usize };
-
         #[cfg(not(feature = "alloc"))]
         if self.buffer.len() < offset + data.len() {
             return Err(AssemblerError);

+ 9 - 89
src/wire/sixlowpan.rs

@@ -2139,9 +2139,6 @@ pub mod nhc {
 
 #[cfg(test)]
 mod test {
-    use crate::phy::ChecksumCapabilities;
-    use crate::time::Duration;
-
     use super::*;
 
     #[test]
@@ -2178,13 +2175,16 @@ mod test {
 
     #[test]
     fn sixlowpan_three_fragments() {
-        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;
 
-        let mut frags_cache = ReassemblyBuffer::new();
+        let key = frag::Key {
+            ll_src_addr: Ieee802154Address::Extended([50, 147, 130, 47, 40, 8, 62, 217]),
+            ll_dst_addr: Ieee802154Address::Extended([26, 11, 66, 66, 66, 66, 66, 66]),
+            datagram_size: 307,
+            datagram_tag: 63,
+        };
 
         let frame1: &[u8] = &[
             0x41, 0xcc, 0x92, 0xef, 0xbe, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x0b, 0x1a, 0xd9,
@@ -2214,18 +2214,7 @@ mod test {
         assert_eq!(frag.datagram_tag(), 0x003f);
         assert_eq!(frag.datagram_offset(), 0);
 
-        let key = frag.get_key(&ieee802154_repr);
-
-        let uncompressed = 40 + 8;
-        let compressed = 5 + 7;
-
-        let assr = frags_cache
-            .get(&key, Instant::now() + Duration::from_secs(60))
-            .unwrap();
-        assr.set_total_size(frag.datagram_size() as usize - uncompressed + compressed)
-            .unwrap();
-        assr.set_offset_correction(-((uncompressed - compressed) as isize));
-        assr.add(frag.payload(), 0).unwrap();
+        assert_eq!(frag.get_key(&ieee802154_repr), key);
 
         let frame2: &[u8] = &[
             0x41, 0xcc, 0x93, 0xef, 0xbe, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x0b, 0x1a, 0xd9,
@@ -2255,13 +2244,7 @@ mod test {
         assert_eq!(frag.datagram_tag(), 0x003f);
         assert_eq!(frag.datagram_offset(), 136 / 8);
 
-        let key = frag.get_key(&ieee802154_repr);
-
-        let assr = frags_cache
-            .get(&key, Instant::now() + Duration::from_secs(60))
-            .unwrap();
-        assr.add(frag.payload(), frag.datagram_offset() as usize * 8)
-            .unwrap();
+        assert_eq!(frag.get_key(&ieee802154_repr), key);
 
         let frame3: &[u8] = &[
             0x41, 0xcc, 0x94, 0xef, 0xbe, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x0b, 0x1a, 0xd9,
@@ -2290,69 +2273,6 @@ mod test {
         assert_eq!(frag.datagram_tag(), 0x003f);
         assert_eq!(frag.datagram_offset(), 232 / 8);
 
-        let key = frag.get_key(&ieee802154_repr);
-
-        let assr = frags_cache
-            .get(&key, Instant::now() + Duration::from_secs(60))
-            .unwrap();
-        assr.add(frag.payload(), frag.datagram_offset() as usize * 8)
-            .unwrap();
-
-        let assembled_packet = assr.assemble().unwrap();
-
-        let sixlowpan_frame = SixlowpanPacket::dispatch(assembled_packet).unwrap();
-
-        let iphc = if let SixlowpanPacket::IphcHeader = sixlowpan_frame {
-            iphc::Packet::new_checked(assembled_packet).unwrap()
-        } else {
-            unreachable!()
-        };
-
-        let iphc_repr = iphc::Repr::parse(
-            &iphc,
-            ieee802154_repr.src_addr,
-            ieee802154_repr.dst_addr,
-            &[],
-        )
-        .unwrap();
-
-        assert_eq!(
-            iphc_repr.dst_addr,
-            ipv6::Address::from_bytes(&[
-                0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x18, 0xb, 0x42, 0x42, 0x42, 0x42, 0x42,
-                0x42,
-            ]),
-        );
-        assert_eq!(
-            iphc_repr.ll_dst_addr,
-            Some(Ieee802154Address::from_bytes(&[
-                0x1a, 0xb, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
-            ])),
-        );
-        assert_eq!(iphc_repr.next_header, NextHeader::Compressed);
-        assert_eq!(iphc_repr.hop_limit, 64);
-
-        let sixlowpan_frame = nhc::NhcPacket::dispatch(iphc.payload()).unwrap();
-
-        let udp_hdr = if let nhc::NhcPacket::UdpHeader = sixlowpan_frame {
-            nhc::UdpNhcPacket::new_checked(iphc.payload()).unwrap()
-        } else {
-            unreachable!()
-        };
-
-        let payload = udp_hdr.payload();
-        assert_eq!(String::from_utf8_lossy(payload), "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam dui odio, iaculis vel rutrum at, tristique non nunc erat curae. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam dui odio, iaculis vel rutrum at, tristique non nunc erat curae. \n");
-
-        let udp_repr = nhc::UdpNhcRepr::parse(
-            &udp_hdr,
-            &iphc_repr.src_addr,
-            &iphc_repr.dst_addr,
-            &ChecksumCapabilities::default(),
-        )
-        .unwrap();
-
-        assert_eq!(udp_repr.src_port, 53855);
-        assert_eq!(udp_repr.dst_port, 6969);
-        assert_eq!(udp_hdr.checksum(), Some(0xb46b));
+        assert_eq!(frag.get_key(&ieee802154_repr), key);
     }
 }