pass test_assoc_unreliable_rexmit_ordered_fragment
@@ -828,3 +828,93 @@ async fn test_assoc_unreliable_rexmit_ordered_no_fragment() -> Result<(), Error>
Ok(())
}
+
+//use std::io::Write;
+
+#[tokio::test]
+async fn test_assoc_unreliable_rexmit_ordered_fragment() -> Result<(), Error> {
+ /*env_logger::Builder::new()
+ .format(|buf, record| {
+ writeln!(
+ buf,
+ "{}:{} [{}] {} - {}",
+ record.file().unwrap_or("unknown"),
+ record.line().unwrap_or(0),
+ record.level(),
+ chrono::Local::now().format("%H:%M:%S.%6f"),
+ record.args()
+ )
+ })
+ .filter(None, log::LevelFilter::Trace)
+ .init();*/
+
+ const SI: u16 = 1;
+ let mut sbuf = vec![0u8; 2000];
+ for i in 0..sbuf.len() {
+ sbuf[i] = (i & 0xff) as u8;
+ }
+
+ let (br, ca, cb) = Bridge::new(0, None, None);
+
+ let (a0, mut a1) =
+ create_new_association_pair(&br, Arc::new(ca), Arc::new(cb), AckMode::NoDelay, 0).await?;
+
+ let (s0, s1) = establish_session_pair(&br, &a0, &mut a1, SI).await?;
+
+ {
+ // lock RTO value at 100 [msec]
+ let mut a = a0.association_internal.lock().await;
+ a.rto_mgr.set_rto(100, true);
+ }
+ // When we set the reliability value to 0 [times], then it will cause
+ // the chunk to be abandoned immediately after the first transmission.
+ s0.set_reliability_params(false, ReliabilityType::Rexmit, 0);
+ s1.set_reliability_params(false, ReliabilityType::Rexmit, 0); // doesn't matter
+
+ br.drop_next_nwrites(0, 1).await; // drop the first packet (second one should be sacked)
+
+ sbuf[0..4].copy_from_slice(&0u32.to_be_bytes());
+ let n = s0
+ .write_sctp(
+ &Bytes::from(sbuf.clone()),
+ PayloadProtocolIdentifier::Binary,
+ )
+ .await?;
+ assert_eq!(sbuf.len(), n, "unexpected length of received data");
+
+ sbuf[0..4].copy_from_slice(&1u32.to_be_bytes());
+ let n = s0
+ .write_sctp(
+ &Bytes::from(sbuf.clone()),
+ PayloadProtocolIdentifier::Binary,
+ )
+ .await?;
+ assert_eq!(sbuf.len(), n, "unexpected length of received data");
+
+ //log::debug!("flush_buffers");
+ flush_buffers(&br, &a0, &a1).await;
+
+ let mut buf = vec![0u8; 2000];
+
+ //log::debug!("read_sctp");
+ let (n, ppi) = s1.read_sctp(&mut buf).await?;
+ assert_eq!(n, sbuf.len(), "unexpected length of received data");
+ assert_eq!(ppi, PayloadProtocolIdentifier::Binary, "unexpected ppi");
+ assert_eq!(
+ u32::from_be_bytes([buf[0], buf[1], buf[2], buf[3]]),
+ 1,
+ "unexpected received data"
+ );
+
+ //log::debug!("process");
+ br.process().await;
+
+ {
+ let q = s0.reassembly_queue.lock().await;
+ assert!(!q.is_readable(), "should no longer be readable");
+ }
+
+ close_association_pair(&br, a0, a1).await;
+
+ Ok(())
+}
