use std::time::Duration;
use netring::{AsyncInjector, Injector, TxPacer};
#[tokio::main]
async fn main() -> Result<(), netring::Error> {
let iface = std::env::args().nth(1).unwrap_or_else(|| "lo".to_string());
let pps: f64 = std::env::args()
.nth(2)
.and_then(|s| s.parse().ok())
.unwrap_or(1000.0);
let injector = Injector::builder()
.interface(&iface)
.tx_timestamps(true)
.build()?;
let mut tx = AsyncInjector::new(injector)?;
let frames = futures::stream::iter((0..10_000u32).map(|_| vec![0u8; 64]));
let sent = tx
.send_stream(frames, Some(TxPacer::packets_per_second(pps)))
.await?;
let _ = tx.wait_drained(Duration::from_secs(2)).await;
let mut stamped = 0;
for _ in 0..sent.min(5) {
if let Some(ts) = tx.read_tx_timestamp() {
println!("egress timestamp: {ts:?}");
stamped += 1;
}
}
println!("sent {sent} frames at ~{pps} pps on {iface}; read {stamped} egress timestamps");
Ok(())
}