Skip to content

Commit

Permalink
fix(device): return an error when setting an empty config to BwDevice
Browse files Browse the repository at this point in the history
Refs: #6
  • Loading branch information
Centaurus99 committed Mar 1, 2024
1 parent 0859d49 commit a570e30
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions rattan/src/devices/bandwidth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ where
type Config = BwDeviceConfig<P, Q>;

fn set_config(&self, config: Self::Config) -> Result<(), Error> {
if config.bandwidth.is_none() && config.queue_config.is_none() {
// This ensures that incorrect HTTP requests will return errors.
return Err(Error::ConfigError(
"At least one of bandwidth and queue_config should be set".to_string(),
));
}
if let Some(bandwidth) = config.bandwidth {
if bandwidth > MAX_BANDWIDTH {
return Err(Error::ConfigError(
Expand Down Expand Up @@ -275,6 +281,7 @@ where
fn peek(&self) -> Option<&P>;
}

#[derive(Debug)]
pub struct InfiniteQueue<P> {
queue: VecDeque<P>,
}
Expand Down Expand Up @@ -330,6 +337,7 @@ impl FiniteQueueConfig {
}
}

#[derive(Debug)]
pub struct DropTailQueue<P> {
queue: VecDeque<P>,
packet_limit: usize,
Expand Down Expand Up @@ -390,6 +398,7 @@ where
}
}

#[derive(Debug)]
pub struct DropHeadQueue<P> {
queue: VecDeque<P>,
packet_limit: usize,
Expand Down

0 comments on commit a570e30

Please sign in to comment.