Skip to main content

shadow_rs/network/
mod.rs

1//! The network simulation.
2//!
3//! This contains code that simulates the Internet and upstream routers. It does not contain any
4//! emulation of Linux networking behaviour, which exists in the [`crate::host`] module.
5
6use std::net::Ipv4Addr;
7
8use crate::network::packet::PacketRc;
9
10pub mod dns;
11pub mod graph;
12pub mod packet;
13pub mod router;
14
15/// Specifies a throughput limit that should be enforced when forwarding packets.
16pub enum RateLimit {
17    BytesPerSecond(u64),
18    Unlimited,
19}
20
21pub trait PacketDevice {
22    fn get_address(&self) -> Ipv4Addr;
23    fn pop(&self) -> Option<PacketRc>;
24    fn push(&self, packet: PacketRc);
25}
26
27#[cfg(test)]
28mod tests {
29    use shadow_shim_helper_rs::{emulated_time::EmulatedTime, simulation_time::SimulationTime};
30
31    pub fn mock_time_millis(millis_since_sim_start: u64) -> EmulatedTime {
32        let simtime = SimulationTime::from_millis(millis_since_sim_start);
33        EmulatedTime::from_abs_simtime(simtime)
34    }
35}