Commit Graph

33 Commits (master)

Author SHA1 Message Date
Thibaut Vandervelden fb2d0029d8 Add support for 802.15.4 and 6LoWPAN 2021-10-21 01:25:12 +02:00
Dario Nieuwenhuis b674f0d0ba phy: simplify PcapSink trait 2021-10-03 21:29:40 +02:00
Dario Nieuwenhuis 1ac34f34eb Fix redundant closure clippy 2021-06-27 10:43:05 +02:00
Dario Nieuwenhuis 98fe17890a rustfmt 2021-06-27 09:31:59 +02:00
Dario Nieuwenhuis 6e8c2a8455 Add IP medium support to PcapWriter and Tracer. 2021-03-31 17:05:09 +02:00
Dario Nieuwenhuis 9e3b373e36 Add support for TUN interfaces. 2021-03-31 17:05:09 +02:00
Alex Crawford ea4579d68a Clean up examples
These were flagged by `cargo clippy`:

    warning: you seem to be trying to use match for destructuring a
             single pattern. Consider using `if let`
    warning: called `.nth(0)` on a `std::iter::Iterator`, when `.next()`
             is equivalent
    warning: using `write!()` with a format string that ends in a single
             newline
    warning: useless conversion to the same type:
             `smoltcp::wire::Ipv4Address`
    warning: called `map(f)` on an `Option` value where `f` is a closure
             that returns the unit type `()`
    warning: returning the result of a `let` binding from a block
    warning: use of `unwrap_or` followed by a function call
2021-01-04 10:39:27 -08:00
Dario Nieuwenhuis 88256dbdcf Update to Rust 2018. Fixes #271 2020-12-27 17:54:56 +01:00
whitequark be7750486f Bump log dependency to version 0.4. NFC.
This doesn't affect downstream code because log 0.3.9 is a facade
crate implemented in terms of log 0.4, and so log 0.3 and log 0.4
APIs can be used together.
2019-06-22 08:31:11 +00:00
whitequark 0134bb7399 Bump Rust version requirement to 1.27.
This allows us to use:
(1.26)
  - impl Trait
  - autoderef in pattern matching
  - fixed slice patterns
  - inclusive ranges
(1.27)
  - dyn Trait
  - #[must_use] on functions

To prepare for edition change, dyn is added where applicable. Other
edition changes would require bumping the requirement even higher,
and so they are not applied for now.
2019-06-22 08:19:39 +00:00
Astro a8f2725784 Implement IGMPv1/v2 processing.
Closes: #178
Approved by: whitequark
2018-08-01 10:26:51 +08:00
Dan Robertson e0b48caca3 Update phy mod to use new time types
Update everything but the socket types to use the new time types instead
of a basic u64

Closes: #141
Approved by: whitequark
2018-02-16 10:44:03 +08:00
Dan Robertson 20d1dd8a4a Update examples to use time types
Closes: #141
Approved by: whitequark
2018-02-16 10:44:02 +08:00
寧靜 96fd18ff8f Add missing #[cfg(feature = "phy-tap_interface")]. 2018-02-04 08:31:03 +00:00
whitequark f1a7fbe973 Split `poll_at`/`poll_delay` out of `poll`.
The previous model was flawed. Consider the following case:
  * The main loop looks as follows (pseudocode):
      loop {
        let _ = (tcp:1234).read_all()
        wait(iface.poll())
      }
  * The remote end is continuously transmitting data and at some
    point fills the window of (tcp:1234), stopping the transmission
    afterwards.
  * The local end processes the packets and, as a part of egress
    routine, emits an ACK. That also updates the window, and
    the socket's poll_at() routine returns None, since there is
    nothing to transmit or retransmit.
  * The local end now waits indefinitely even though it can start
    processing the data in the socket buffers right now.
2017-12-22 12:59:52 +00:00
whitequark 5ea177e6ab Add a stress test.
Run it without the `log` feature and in release mode:
  $ cargo run --release \
    --no-default-features \
    --features std,phy-tap_interface,socket-tcp \
    --example stress tap0 \
    [reader|writer]

There are currently two bugs exposed by it:
  * a crash in the reader mode,
  * slow-down in the writer mode.
2017-12-22 09:43:00 +00:00
whitequark 75e371d947 Rework the pretty printer to avoid superfluous trailing newlines. 2017-12-16 21:42:19 +00:00
Philipp Oppermann 6a8e21cec0 Redesign the phy::Device trait to avoid Drop impls. 2017-11-03 23:15:07 +00:00
whitequark 996389d653 Compute soft deadline in poll() and use nonblocking sockets.
Before this commit, anything that touched RawSocket or TapInterface
worked partly by accident and partly because of a horrible crutch
that resulted in massive latencies as well as inevitable packet loss
every time an ARP request had to be issued. Also, there was no way
to use poll() other than by continuously calling it in a busy loop.

After this commit, poll() indicates when the earliest timer expires,
and so the caller can sleep until that moment (or until packets
arrive).

Note that there is a subtle problem remaining: every time poll()
is called, every socket with a pending outbound packet whose
IP address doesn't correspond to a MAC address will send a new
ARP request, resulting in potentially a whole lot of such requests.
ARP rate limiting is a separate topic though.
2017-08-29 19:47:11 +00:00
whitequark 699f5daa3e utils::Dispose → io::Sink. 2017-08-21 07:28:32 +00:00
whitequark 7ba49607bf Update fault injector so that rate limiting works without std. 2017-07-23 15:10:57 +00:00
whitequark a89e57b128 Add --pcap option to all our examples.
Also, generally reorganize and clean up option handling.
2017-07-23 14:57:04 +00:00
whitequark e381f6ec3f Fix an off-by-three-orders-of-magnitude error. 2017-07-23 12:03:56 +00:00
whitequark cf37a34443 Fix argument order in Tracer::new callbacks. 2017-07-23 12:01:53 +00:00
whitequark b97cacd521 Inject the current timestamp into Device::{transmit,receive}.
Various parts of smoltcp require an arrow of time; a monotonically
increasing timestamp. Most obviously this is TCP sockets, but
the tracer and the pcap writer devices also benefit from having
timestamps. There are a few ways this could be implemented:
  1. using a static Cell, global for the entire smoltcp crate;
  2. using a static method on Device;
  3. using an instance method on Device;
  4. passing the current timestamp into *Interface::poll.

The first two options are undesirable because they create a notion
of global clock, and interfere e.g. with mocking.
The third option is undesirable because not all devices are
inherently tied to a particular clock, e.g. a loopback device isn't.

Therefore, the timestamp is injected into both sockets and devices
through the *Interface::poll method.
2017-07-23 09:48:14 +00:00
whitequark eae7907f60 Add EthernetTracer, a specialization of Tracer for EthernetFrame.
This makes the loopback example much nicer, #[cfg]-wise.
2017-07-23 06:28:00 +00:00
whitequark 6dd833f1f7 Use proper clock mocking in the loopback example. 2017-07-23 06:08:13 +00:00
whitequark 75ddbe9776 Add a bare-metal usage example. 2017-07-14 03:18:11 +00:00
whitequark 62c9b7d6fa In examples, trace the packets being dropped by the fault injector. 2017-06-26 08:44:07 +00:00
whitequark 02abd7a983 In examples, print packet dumps with timestamps, too.
This helps debugging retransmit issues.
2017-06-26 08:01:00 +00:00
whitequark 91ef5c60c3 Add packet shaping to the fault injector. 2017-05-29 10:53:30 +00:00
whitequark f49723bbf9 Add a TCP client example. 2017-03-05 04:47:45 +00:00
whitequark d20c98f870 Factor out common code from examples. 2017-03-05 04:19:19 +00:00