Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions rattan-core/src/cells/bandwidth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ mod tests {

use super::*;
use crate::cells::bandwidth::queue::{
DropTailQueue, DropTailQueueConfig, InfiniteQueue, InfiniteQueueConfig,
DropTailQueue, DropTailQueueConfig, InfiniteQueue, InfiniteQueueConfig, PacketQueue,
};
use crate::cells::{StdPacket, TestPacket};

Expand Down Expand Up @@ -1028,7 +1028,7 @@ mod tests {
// A 256B + 14B packet needs 80ms transmission time.
let bandwidth = Bandwidth::from_bps(25600);

let packet_queue = InfiniteQueue::new(InfiniteQueueConfig {});
let packet_queue = InfiniteQueue::new(InfiniteQueueConfig {}).unwrap();
let cell = BwCell::new(bandwidth, packet_queue, BwType::NetworkLayer)?;

let ingress = cell.sender();
Expand Down Expand Up @@ -1109,7 +1109,7 @@ mod tests {
// A 256B packet needs 80ms transmission time.
let bandwidth = Bandwidth::from_bps(25600);
let packet_queue =
DropTailQueue::new(DropTailQueueConfig::new(None, 0, BwType::NetworkLayer));
DropTailQueue::new(DropTailQueueConfig::new(None, 0, BwType::NetworkLayer)).unwrap();
let cell = BwCell::new(bandwidth, packet_queue, BwType::NetworkLayer)?;

let ingress = cell.sender();
Expand Down Expand Up @@ -1181,7 +1181,7 @@ mod tests {
.build();

let packet_queue =
DropTailQueue::new(DropTailQueueConfig::new(None, 0, BwType::NetworkLayer));
DropTailQueue::new(DropTailQueueConfig::new(None, 0, BwType::NetworkLayer)).unwrap();
let cell = BwReplayCell::new(
Box::new(bandwidth_trace),
packet_queue,
Expand Down
45 changes: 21 additions & 24 deletions rattan-core/src/cells/bandwidth/queue/codel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ impl CoDelQueueConfig {
}
}

impl<P> From<CoDelQueueConfig> for CoDelQueue<P> {
fn from(config: CoDelQueueConfig) -> Self {
impl<P: Packet> TryFrom<CoDelQueueConfig> for CoDelQueue<P> {
type Error = &'static str;

fn try_from(config: CoDelQueueConfig) -> Result<Self, Self::Error> {
CoDelQueue::new(config)
}
}
Expand All @@ -84,29 +86,9 @@ pub struct CoDelQueue<P> {
ldelay: Duration, // sojourn time of last dequeued packet
}

impl<P> CoDelQueue<P> {
pub fn new(config: CoDelQueueConfig) -> Self {
debug!(?config, "New CoDelQueue");
Self {
queue: VecDeque::new(),
config,
now_bytes: 0,
count: 0,
lastcount: 0,
dropping: false,
first_above_time: None,
drop_next: Instant::now(),
ldelay: Duration::ZERO,
}
}
}

impl<P> Default for CoDelQueue<P>
where
P: Packet,
{
impl<P: Packet> Default for CoDelQueue<P> {
fn default() -> Self {
Self::new(CoDelQueueConfig::default())
Self::new(CoDelQueueConfig::default()).expect("CoDelQueue::new should never fail")
}
}

Expand Down Expand Up @@ -146,6 +128,21 @@ where
{
type Config = CoDelQueueConfig;

fn new(config: CoDelQueueConfig) -> Result<Self, &'static str> {
debug!(?config, "New CoDelQueue");
Ok(Self {
queue: VecDeque::new(),
config,
now_bytes: 0,
count: 0,
lastcount: 0,
dropping: false,
first_above_time: None,
drop_next: Instant::now(),
ldelay: Duration::ZERO,
})
}

fn configure(&mut self, config: Self::Config) {
self.config = config;
}
Expand Down
38 changes: 19 additions & 19 deletions rattan-core/src/cells/bandwidth/queue/drophead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ impl DropHeadQueueConfig {
}
}

impl<P> From<DropHeadQueueConfig> for DropHeadQueue<P> {
fn from(config: DropHeadQueueConfig) -> Self {
impl<P: Packet> TryFrom<DropHeadQueueConfig> for DropHeadQueue<P> {
type Error = &'static str;

fn try_from(config: DropHeadQueueConfig) -> Result<Self, Self::Error> {
DropHeadQueue::new(config)
}
}
Expand All @@ -51,24 +53,9 @@ pub struct DropHeadQueue<P> {
now_bytes: usize,
}

impl<P> DropHeadQueue<P> {
pub fn new(config: DropHeadQueueConfig) -> Self {
let packet_limit = config.packet_limit;
let byte_limit = config.byte_limit;
debug!(?config, "New DropHeadQueue");
Self {
queue: VecDeque::new(),
bw_type: config.bw_type,
packet_limit,
byte_limit,
now_bytes: 0,
}
}
}

impl<P> Default for DropHeadQueue<P> {
impl<P: Packet> Default for DropHeadQueue<P> {
fn default() -> Self {
Self::new(DropHeadQueueConfig::default())
Self::new(DropHeadQueueConfig::default()).expect("DropHeadQueue::new should never fail")
}
}

Expand All @@ -78,6 +65,19 @@ where
{
type Config = DropHeadQueueConfig;

fn new(config: DropHeadQueueConfig) -> Result<Self, &'static str> {
let packet_limit = config.packet_limit;
let byte_limit = config.byte_limit;
debug!(?config, "New DropHeadQueue");
Ok(Self {
queue: VecDeque::new(),
bw_type: config.bw_type,
packet_limit,
byte_limit,
now_bytes: 0,
})
}

fn configure(&mut self, config: Self::Config) {
self.packet_limit = config.packet_limit;
self.byte_limit = config.byte_limit;
Expand Down
38 changes: 19 additions & 19 deletions rattan-core/src/cells/bandwidth/queue/droptail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ impl DropTailQueueConfig {
}
}

impl<P> From<DropTailQueueConfig> for DropTailQueue<P> {
fn from(config: DropTailQueueConfig) -> Self {
impl<P: Packet> TryFrom<DropTailQueueConfig> for DropTailQueue<P> {
type Error = &'static str;

fn try_from(config: DropTailQueueConfig) -> Result<Self, Self::Error> {
DropTailQueue::new(config)
}
}
Expand All @@ -51,24 +53,9 @@ pub struct DropTailQueue<P> {
now_bytes: usize,
}

impl<P> DropTailQueue<P> {
pub fn new(config: DropTailQueueConfig) -> Self {
let packet_limit = config.packet_limit;
let byte_limit = config.byte_limit;
debug!(?config, "New DropTailQueue");
Self {
queue: VecDeque::new(),
bw_type: config.bw_type,
packet_limit,
byte_limit,
now_bytes: 0,
}
}
}

impl<P> Default for DropTailQueue<P> {
impl<P: Packet> Default for DropTailQueue<P> {
fn default() -> Self {
Self::new(DropTailQueueConfig::default())
Self::new(DropTailQueueConfig::default()).expect("DropTailQueue::new should never fail")
}
}

Expand All @@ -78,6 +65,19 @@ where
{
type Config = DropTailQueueConfig;

fn new(config: DropTailQueueConfig) -> Result<Self, &'static str> {
let packet_limit = config.packet_limit;
let byte_limit = config.byte_limit;
debug!(?config, "New DropTailQueue");
Ok(Self {
queue: VecDeque::new(),
bw_type: config.bw_type,
packet_limit,
byte_limit,
now_bytes: 0,
})
}

fn configure(&mut self, config: Self::Config) {
self.packet_limit = config.packet_limit;
self.byte_limit = config.byte_limit;
Expand Down
26 changes: 13 additions & 13 deletions rattan-core/src/cells/bandwidth/queue/infinite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ impl InfiniteQueueConfig {
}
}

impl<P> From<InfiniteQueueConfig> for InfiniteQueue<P> {
fn from(config: InfiniteQueueConfig) -> Self {
impl<P: Packet> TryFrom<InfiniteQueueConfig> for InfiniteQueue<P> {
type Error = &'static str;

fn try_from(config: InfiniteQueueConfig) -> Result<Self, Self::Error> {
InfiniteQueue::new(config)
}
}
Expand All @@ -29,18 +31,9 @@ pub struct InfiniteQueue<P> {
queue: VecDeque<P>,
}

impl<P> InfiniteQueue<P> {
pub fn new(_config: InfiniteQueueConfig) -> Self {
debug!("New InfiniteQueue");
Self {
queue: VecDeque::new(),
}
}
}

impl<P> Default for InfiniteQueue<P> {
impl<P: Packet> Default for InfiniteQueue<P> {
fn default() -> Self {
Self::new(InfiniteQueueConfig::default())
Self::new(InfiniteQueueConfig::default()).expect("InfiniteQueue::new should never fail")
}
}

Expand All @@ -50,6 +43,13 @@ where
{
type Config = InfiniteQueueConfig;

fn new(_config: InfiniteQueueConfig) -> Result<Self, &'static str> {
debug!("New InfiniteQueue");
Ok(Self {
queue: VecDeque::new(),
})
}

fn configure(&mut self, _config: Self::Config) {}

fn enqueue(&mut self, packet: P) {
Expand Down
4 changes: 4 additions & 0 deletions rattan-core/src/cells/bandwidth/queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ where
#[cfg(not(feature = "serde"))]
type Config: Send + Debug;

fn new(config: Self::Config) -> Result<Self, &'static str>
where
Self: Sized;

fn configure(&mut self, config: Self::Config);

fn enqueue(&mut self, packet: P);
Expand Down
6 changes: 4 additions & 2 deletions rattan-core/src/config/bandwidth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ macro_rules! impl_bw_cell_into_factory {
) -> impl CellFactory<bandwidth::BwCell<P, queue::$queue<P>>> {
move |handle| {
let _guard = handle.enter();
let queue = queue::$queue::<P>::new(self.queue_config.unwrap_or_default());
let queue = queue::$queue::<P>::new(self.queue_config.unwrap_or_default())
.map_err(|e| Error::ConfigError(e.to_string()))?;
BwCell::new(self.bandwidth, queue, self.bw_type.unwrap_or_default())
}
}
Expand Down Expand Up @@ -207,7 +208,8 @@ macro_rules! impl_bw_replay_cell_into_factory {
move |handle| {
let _guard = handle.enter();
let trace = self.get_trace()?;
let queue = queue::$queue::<P>::new(self.queue_config.unwrap_or_default());
let queue = queue::$queue::<P>::new(self.queue_config.unwrap_or_default())
.map_err(|e| Error::ConfigError(e.to_string()))?;
BwReplayCell::new(trace, queue, self.bw_type.unwrap_or_default())
}
}
Expand Down
4 changes: 2 additions & 2 deletions rattan-core/tests/integration/bandwidth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rattan_core::{
use rattan_core::{
cells::{
bandwidth::{
queue::{DropTailQueue, DropTailQueueConfig, InfiniteQueueConfig},
queue::{DropTailQueue, DropTailQueueConfig, InfiniteQueueConfig, PacketQueue},
BwCellConfig, BwReplayCell, BwReplayCellConfig, BwType,
},
ControlInterface, StdPacket,
Expand Down Expand Up @@ -792,7 +792,7 @@ fn test_replay() {
.build();
BwReplayCell::new(
Box::new(trace) as Box<dyn BwTrace>,
DropTailQueue::new(DropTailQueueConfig::new(100, None, BwType::default())),
DropTailQueue::new(DropTailQueueConfig::new(100, None, BwType::default())).unwrap(),
None,
)
})
Expand Down
Loading