netstack3_device/
queue.rs1use alloc::collections::VecDeque;
8
9use netstack3_base::{ErrorAndSerializer, WorkQueueReport};
10use packet::SerializeError;
11
12use crate::internal::base::DeviceSendFrameError;
13
14pub(crate) mod api;
15mod fifo;
16pub(crate) mod rx;
17pub(crate) mod tx;
18
19const MAX_RX_QUEUED_LEN: usize = 10000;
21const MAX_TX_QUEUED_LEN: usize = 10000;
23
24#[derive(Debug, PartialEq, Eq)]
26pub struct ReceiveQueueFullError<T>(pub T);
27
28#[derive(Debug, PartialEq, Eq)]
29pub enum TransmitQueueFrameError<S> {
30 NoQueue(DeviceSendFrameError),
31 QueueFull(S),
32 SerializeError(ErrorAndSerializer<SerializeError<()>, S>),
33}
34
35pub struct DequeueState<Meta, Buffer> {
37 dequeued_frames: VecDeque<(Meta, Buffer)>,
38}
39
40impl<Meta, Buffer> Default for DequeueState<Meta, Buffer> {
41 fn default() -> DequeueState<Meta, Buffer> {
42 DequeueState {
43 dequeued_frames: VecDeque::with_capacity(BatchSize::MAX),
46 }
47 }
48}
49
50#[derive(Debug, PartialEq, Eq)]
51enum EnqueueResult {
52 QueueWasPreviouslyEmpty,
53 QueuePreviouslyWasOccupied,
54}
55
56#[derive(Debug)]
57enum DequeueResult {
58 MoreStillQueued,
59 NoMoreLeft,
60}
61
62impl From<DequeueResult> for WorkQueueReport {
63 fn from(value: DequeueResult) -> Self {
64 match value {
65 DequeueResult::MoreStillQueued => Self::Pending,
66 DequeueResult::NoMoreLeft => Self::AllDone,
67 }
68 }
69}
70
71#[derive(Copy, Clone, Debug, Eq, PartialEq)]
77pub struct BatchSize(usize);
78
79impl BatchSize {
80 pub const MAX: usize = 100;
91
92 pub fn new_saturating(v: usize) -> Self {
95 Self(v.min(Self::MAX))
96 }
97}
98
99impl From<BatchSize> for usize {
100 fn from(BatchSize(v): BatchSize) -> Self {
101 v
102 }
103}
104
105impl Default for BatchSize {
106 fn default() -> Self {
107 Self(Self::MAX)
108 }
109}