Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: smoltcp-rs/smoltcp
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 97499ac280cd
Choose a base ref
...
head repository: smoltcp-rs/smoltcp
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 37ba81f807fd
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Jul 23, 2017

  1. Copy the full SHA
    ac988f6 View commit details
  2. Copy the full SHA
    8c339d8 View commit details
  3. Copy the full SHA
    37ba81f View commit details
Showing with 19 additions and 19 deletions.
  1. +1 −1 examples/loopback.rs
  2. +2 −2 examples/utils.rs
  3. +8 −8 src/phy/fault_injector.rs
  4. +8 −8 src/phy/tracer.rs
2 changes: 1 addition & 1 deletion examples/loopback.rs
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ fn main() {
}

let mut device = Loopback::new();
let mut device = EthernetTracer::new(device, |printer, _timestamp| trace!("{}", printer));
let mut device = EthernetTracer::new(device, |_timestamp, printer| trace!("{}", printer));

let mut arp_cache_entries: [_; 8] = Default::default();
let mut arp_cache = SliceArpCache::new(&mut arp_cache_entries[..]);
4 changes: 2 additions & 2 deletions examples/utils.rs
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ pub fn setup_logging() {
let startup_at = Instant::now();
setup_logging_with_clock(move || {
let elapsed = Instant::now().duration_since(startup_at);
elapsed.as_secs() * 1000 + (elapsed.subsec_nanos() / 1000) as u64
elapsed.as_secs() * 1000 + (elapsed.subsec_nanos() / 1000000) as u64
})
}

@@ -78,7 +78,7 @@ pub fn setup_device(more_args: &[&str])
let seed = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().subsec_nanos();

let device = TapInterface::new(&matches.free[0]).unwrap();
let device = EthernetTracer::new(device, |printer, _timestamp| trace!("{}", printer));
let device = EthernetTracer::new(device, |_timestamp, printer| trace!("{}", printer));
let mut device = FaultInjector::new(device, seed);
device.set_drop_chance(drop_chance);
device.set_corrupt_chance(corrupt_chance);
16 changes: 8 additions & 8 deletions src/phy/fault_injector.rs
Original file line number Diff line number Diff line change
@@ -109,14 +109,14 @@ impl State {
/// or hardware limitations (such as a limited number or size of usable network buffers).
#[derive(Debug)]
pub struct FaultInjector<D: Device> {
lower: D,
inner: D,
state: State,
config: Config
}

impl<D: Device> FaultInjector<D> {
/// Create a fault injector device, using the given random number generator seed.
pub fn new(lower: D, seed: u32) -> FaultInjector<D> {
pub fn new(inner: D, seed: u32) -> FaultInjector<D> {
#[cfg(feature = "std")]
let state = State {
rng_seed: seed,
@@ -129,15 +129,15 @@ impl<D: Device> FaultInjector<D> {
rng_seed: seed,
};
FaultInjector {
lower: lower,
inner: inner,
state: state,
config: Config::default()
}
}

/// Return the underlying device, consuming the fault injector.
pub fn into_lower(self) -> D {
self.lower
pub fn into_inner(self) -> D {
self.inner
}

/// Return the probability of corrupting a packet, in percents.
@@ -222,15 +222,15 @@ impl<D: Device> Device for FaultInjector<D>
type TxBuffer = TxBuffer<D::TxBuffer>;

fn limits(&self) -> DeviceLimits {
let mut limits = self.lower.limits();
let mut limits = self.inner.limits();
if limits.max_transmission_unit > MTU {
limits.max_transmission_unit = MTU;
}
limits
}

fn receive(&mut self, timestamp: u64) -> Result<Self::RxBuffer, Error> {
let mut buffer = self.lower.receive(timestamp)?;
let mut buffer = self.inner.receive(timestamp)?;
if self.state.maybe(self.config.drop_pct) {
net_trace!("rx: randomly dropping a packet");
return Err(Error::Exhausted)
@@ -262,7 +262,7 @@ impl<D: Device> Device for FaultInjector<D>
net_trace!("tx: dropping a packet because of rate limiting");
buffer = None;
} else {
buffer = Some(self.lower.transmit(timestamp, length)?);
buffer = Some(self.inner.transmit(timestamp, length)?);
}
Ok(TxBuffer {
buffer: buffer,
16 changes: 8 additions & 8 deletions src/phy/tracer.rs
Original file line number Diff line number Diff line change
@@ -8,39 +8,39 @@ use super::{DeviceLimits, Device};
/// using the provided writer function, and then passes them to another
/// device.
pub struct Tracer<D: Device, P: PrettyPrint> {
lower: D,
inner: D,
writer: fn(u64, PrettyPrinter<P>)
}

impl<D: Device, P: PrettyPrint> Tracer<D, P> {
/// Create a tracer device.
pub fn new(lower: D, writer: fn(timestamp: u64, printer: PrettyPrinter<P>)) -> Tracer<D, P> {
pub fn new(inner: D, writer: fn(timestamp: u64, printer: PrettyPrinter<P>)) -> Tracer<D, P> {
Tracer {
lower: lower,
inner: inner,
writer: writer
}
}

/// Return the underlying device, consuming the tracer.
pub fn into_lower(self) -> D {
self.lower
pub fn into_inner(self) -> D {
self.inner
}
}

impl<D: Device, P: PrettyPrint> Device for Tracer<D, P> {
type RxBuffer = D::RxBuffer;
type TxBuffer = TxBuffer<D::TxBuffer, P>;

fn limits(&self) -> DeviceLimits { self.lower.limits() }
fn limits(&self) -> DeviceLimits { self.inner.limits() }

fn receive(&mut self, timestamp: u64) -> Result<Self::RxBuffer, Error> {
let buffer = self.lower.receive(timestamp)?;
let buffer = self.inner.receive(timestamp)?;
(self.writer)(timestamp, PrettyPrinter::<P>::new("<- ", &buffer));
Ok(buffer)
}

fn transmit(&mut self, timestamp: u64, length: usize) -> Result<Self::TxBuffer, Error> {
let buffer = self.lower.transmit(timestamp, length)?;
let buffer = self.inner.transmit(timestamp, length)?;
Ok(TxBuffer { buffer, timestamp, writer: self.writer })
}
}