1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//! Safe, zero-cost abstractions for Netmap kernel-bypass networking.
//!
//! # Features
//! - Zero-copy packet I/O
//! - Thread-per-ring with core pinning
//! - Batch Operations for high throughput
//! - Cross-platform support (with fallback implementation)
//!
//! # Usage
//!
//! Add `netmap-rs` to your `Cargo.toml`:
//! ```toml
//! [dependencies]
//! netmap-rs = { version = "0.3", features = ["sys"] }
//! ```
//!
//! Basic example:
//! ```no_run
//! use netmap_rs::prelude::*;
//! use std::thread::sleep;
//! use std::time::Duration;
//!
//! fn main() -> Result<(), Error> {
//! // Attempt to open a netmap interface.
//! // Replace "netmap:eth0" with your desired interface.
//! // The `.build()?` method finalizes the configuration and opens the interface.
//! let nm = NetmapBuilder::new("netmap:eth0")
//! .num_tx_rings(1) // Configure one transmission ring
//! .num_rx_rings(1) // Configure one reception ring
//! .build()?;
//!
//! // Get handles to the first transmission and reception rings.
//! let mut tx_ring = nm.tx_ring(0)?;
//! let mut rx_ring = nm.rx_ring(0)?;
//!
//! // Prepare a packet to send.
//! let packet_data = b"hello netmap!";
//!
//! // Send the packet.
//! // The `send` method might not transmit immediately; it queues the packet.
//! tx_ring.send(packet_data)?;
//! // `sync` ensures that queued packets are made available to the hardware.
//! tx_ring.sync();
//! println!("Sent packet: {:?}", packet_data);
//!
//! // Attempt to receive the packet.
//! let mut received = false;
//! for _ in 0..5 { // Try a few times with a delay
//! // `sync` on the rx_ring tells the kernel we are done with previously received packets
//! // and updates the ring's state to see new packets.
//! rx_ring.sync();
//! while let Some(frame) = rx_ring.recv() {
//! println!("Received packet: {:?}", frame.payload());
//! assert_eq!(frame.payload(), packet_data);
//! received = true;
//! break;
//! }
//! if received {
//! break;
//! }
//! sleep(Duration::from_millis(100)); // Wait a bit for the packet to arrive
//! }
//!
//! if !received {
//! eprintln!("Failed to receive the packet back.");
//! // Depending on the setup (e.g. loopback interface), this might indicate an issue.
//! }
//!
//! Ok(())
//! }
//! ```
//! For more advanced examples, such as Forward Error Correction (FEC),
//! reliable delivery with ARQ, or dedicating threads per ring, please see the
//! files in the `examples` directory of the crate.
// #![warn(rustdoc::missing_crate_level_docs)] // Already covered by the extensive example above
extern crate bitflags;
// Clippy seems to have a false positive with specific feature flags
extern crate thiserror;
/// Error types for the netmap library.
/// Fallback implementations for non-Netmap platforms.
/// Frame structures for representing network packets.
/// Netmap interface and builder types.
/// Netmap ring manipulation.
pub use netmap_min_sys as ffi;
// Tokio async support (optional feature)
// Re-export async types at the crate root when feature is enabled.
pub use ;
pub use crate::;
/// The `prelude` module re-exports commonly used types from this crate
/// for easier access.
///
/// It is recommended to import all items from the prelude:
/// ```
/// use netmap_rs::prelude::*;
/// ```
// Re-export sys-specific types only when sys feature is enabled
pub use crate::;