phy: introduce hardware based checksum settings, rename DeviceLimits

this contains a rename of occurrences of
DeviceLimits -> DeviceCapabilities.
v0.7.x
Steffen Butzer 2017-09-16 11:04:07 +02:00 committed by whitequark
parent f8ab0a6b29
commit f9093d15aa
9 changed files with 43 additions and 43 deletions

View File

@ -169,8 +169,8 @@ impl<'a, 'b, 'c, DeviceT: Device + 'a> Interface<'a, 'b, 'c, DeviceT> {
}
fn socket_egress(&mut self, sockets: &mut SocketSet, timestamp: u64) -> Result<()> {
let mut limits = self.device.limits();
limits.max_transmission_unit -= EthernetFrame::<&[u8]>::header_len();
let mut caps = self.device.capabilities();
caps.max_transmission_unit -= EthernetFrame::<&[u8]>::header_len();
for socket in sockets.iter_mut() {
let mut device_result = Ok(());
@ -491,7 +491,7 @@ impl<'a, 'b, 'c, DeviceT: Device + 'a> Interface<'a, 'b, 'c, DeviceT> {
}
#[cfg(feature = "socket-tcp")]
Packet::Tcp((ip_repr, mut tcp_repr)) => {
let limits = self.device.limits();
let caps = self.device.capabilities();
self.dispatch_ip(timestamp, ip_repr, |ip_repr, payload| {
// This is a terrible hack to make TCP performance more acceptable on systems
// where the TCP buffers are significantly larger than network buffers,
@ -500,8 +500,8 @@ impl<'a, 'b, 'c, DeviceT: Device + 'a> Interface<'a, 'b, 'c, DeviceT> {
// this would result in our peer pushing our window and sever packet loss.
//
// I'm really not happy about this "solution" but I don't know what else to do.
if let Some(max_burst_size) = limits.max_burst_size {
let mut max_segment_size = limits.max_transmission_unit;
if let Some(max_burst_size) = caps.max_burst_size {
let mut max_segment_size = caps.max_transmission_unit;
max_segment_size -= EthernetFrame::<&[u8]>::header_len();
max_segment_size -= ip_repr.buffer_len();
max_segment_size -= tcp_repr.header_len();

View File

@ -1,5 +1,5 @@
use {Error, Result};
use super::{DeviceLimits, Device};
use super::{DeviceCapabilities, Device};
// We use our own RNG to stay compatible with #![no_std].
// The use of the RNG below has a slight bias, but it doesn't matter.
@ -188,12 +188,12 @@ impl<D: Device> Device for FaultInjector<D>
type RxBuffer = D::RxBuffer;
type TxBuffer = TxBuffer<D::TxBuffer>;
fn limits(&self) -> DeviceLimits {
let mut limits = self.inner.limits();
if limits.max_transmission_unit > MTU {
limits.max_transmission_unit = MTU;
fn capabilities(&self) -> DeviceCapabilities {
let mut caps = self.inner.capabilities();
if caps.max_transmission_unit > MTU {
caps.max_transmission_unit = MTU;
}
limits
caps
}
fn receive(&mut self, timestamp: u64) -> Result<Self::RxBuffer> {

View File

@ -12,7 +12,7 @@ use std::collections::VecDeque;
use alloc::{Vec, VecDeque};
use {Error, Result};
use super::{Device, DeviceLimits};
use super::{Device, DeviceCapabilities};
/// A loopback device.
#[derive(Debug)]
@ -32,10 +32,10 @@ impl Device for Loopback {
type RxBuffer = Vec<u8>;
type TxBuffer = TxBuffer;
fn limits(&self) -> DeviceLimits {
DeviceLimits {
fn capabilities(&self) -> DeviceCapabilities {
DeviceCapabilities {
max_transmission_unit: 65535,
..DeviceLimits::default()
..DeviceCapabilities::default()
}
}

View File

@ -21,7 +21,7 @@
```rust
use std::slice;
use smoltcp::{Error, Result};
use smoltcp::phy::{DeviceLimits, Device};
use smoltcp::phy::{DeviceCapabilities, Device};
const TX_BUFFERS: [*mut u8; 2] = [0x10000000 as *mut u8, 0x10001000 as *mut u8];
const RX_BUFFERS: [*mut u8; 2] = [0x10002000 as *mut u8, 0x10003000 as *mut u8];
@ -54,11 +54,11 @@ impl Device for EthernetDevice {
type RxBuffer = &'static [u8];
type TxBuffer = EthernetTxBuffer;
fn limits(&self) -> DeviceLimits {
let mut limits = DeviceLimits::default();
limits.max_transmission_unit = 1536;
limits.max_burst_size = Some(2);
limits
fn capabilities(&self) -> DeviceCapabilities {
let mut caps = DeviceCapabilities::default();
caps.max_transmission_unit = 1536;
caps.max_burst_size = Some(2);
caps
}
fn receive(&mut self, _timestamp: u64) -> Result<Self::RxBuffer> {
@ -135,12 +135,12 @@ pub use self::tap_interface::TapInterface;
/// A tracer device for Ethernet frames.
pub type EthernetTracer<T> = Tracer<T, super::wire::EthernetFrame<&'static [u8]>>;
/// A description of device limitations.
/// A description of device capabilities.
///
/// Higher-level protocols may achieve higher throughput or lower latency if they consider
/// the bandwidth or packet size limitations.
#[derive(Debug, Clone, Default)]
pub struct DeviceLimits {
pub struct DeviceCapabilities {
/// Maximum transmission unit.
///
/// The network device is unable to send or receive frames larger than the value returned
@ -172,8 +172,8 @@ pub trait Device {
type RxBuffer: AsRef<[u8]>;
type TxBuffer: AsRef<[u8]> + AsMut<[u8]>;
/// Get a description of device limitations.
fn limits(&self) -> DeviceLimits;
/// Get a description of device capabilities.
fn capabilities(&self) -> DeviceCapabilities;
/// Receive a frame.
///

View File

@ -5,7 +5,7 @@ use std::io::Write;
use byteorder::{ByteOrder, NativeEndian};
use Result;
use super::{DeviceLimits, Device};
use super::{DeviceCapabilities, Device};
enum_with_unknown! {
/// Captured packet header type.
@ -132,7 +132,7 @@ impl<D: Device, S: PcapSink + Clone> Device for PcapWriter<D, S> {
type RxBuffer = D::RxBuffer;
type TxBuffer = TxBuffer<D::TxBuffer, S>;
fn limits(&self) -> DeviceLimits { self.lower.limits() }
fn capabilities(&self) -> DeviceCapabilities { self.lower.capabilities() }
fn receive(&mut self, timestamp: u64) -> Result<Self::RxBuffer> {
let buffer = self.lower.receive(timestamp)?;

View File

@ -5,7 +5,7 @@ use std::io;
use std::os::unix::io::{RawFd, AsRawFd};
use Result;
use super::{sys, DeviceLimits, Device};
use super::{sys, DeviceCapabilities, Device};
/// A socket that captures or transmits the complete frame.
#[derive(Debug)]
@ -40,10 +40,10 @@ impl Device for RawSocket {
type RxBuffer = Vec<u8>;
type TxBuffer = TxBuffer;
fn limits(&self) -> DeviceLimits {
DeviceLimits {
fn capabilities(&self) -> DeviceCapabilities {
DeviceCapabilities {
max_transmission_unit: self.mtu,
..DeviceLimits::default()
..DeviceCapabilities::default()
}
}

View File

@ -5,7 +5,7 @@ use std::io;
use std::os::unix::io::{RawFd, AsRawFd};
use {Error, Result};
use super::{sys, DeviceLimits, Device};
use super::{sys, DeviceCapabilities, Device};
/// A virtual Ethernet interface.
#[derive(Debug)]
@ -41,10 +41,10 @@ impl Device for TapInterface {
type RxBuffer = Vec<u8>;
type TxBuffer = TxBuffer;
fn limits(&self) -> DeviceLimits {
DeviceLimits {
fn capabilities(&self) -> DeviceCapabilities {
DeviceCapabilities {
max_transmission_unit: self.mtu,
..DeviceLimits::default()
..DeviceCapabilities::default()
}
}

View File

@ -1,6 +1,6 @@
use Result;
use wire::pretty_print::{PrettyPrint, PrettyPrinter};
use super::{DeviceLimits, Device};
use super::{DeviceCapabilities, Device};
/// A tracer device.
///
@ -31,7 +31,7 @@ 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.inner.limits() }
fn capabilities(&self) -> DeviceCapabilities { self.inner.capabilities() }
fn receive(&mut self, timestamp: u64) -> Result<Self::RxBuffer> {
let buffer = self.inner.receive(timestamp)?;

View File

@ -5,7 +5,7 @@
use core::{cmp, fmt};
use {Error, Result};
use phy::DeviceLimits;
use phy::DeviceCapabilities;
use wire::{IpProtocol, IpAddress, IpEndpoint, TcpSeqNumber, TcpRepr, TcpControl};
use socket::{Socket, IpRepr};
use storage::{Assembler, RingBuffer};
@ -1185,7 +1185,7 @@ impl<'a> TcpSocket<'a> {
self.rx_buffer.window() as u16 > self.remote_last_win
}
pub(crate) fn dispatch<F>(&mut self, timestamp: u64, limits: &DeviceLimits,
pub(crate) fn dispatch<F>(&mut self, timestamp: u64, caps: &DeviceCapabilities,
emit: F) -> Result<()>
where F: FnOnce((IpRepr, TcpRepr)) -> Result<()> {
if !self.remote_endpoint.is_specified() { return Err(Error::Exhausted) }
@ -1358,7 +1358,7 @@ impl<'a> TcpSocket<'a> {
if repr.control == TcpControl::Syn {
// Fill the MSS option. See RFC 6691 for an explanation of this calculation.
let mut max_segment_size = limits.max_transmission_unit;
let mut max_segment_size = caps.max_transmission_unit;
max_segment_size -= ip_repr.buffer_len();
max_segment_size -= repr.header_len();
repr.max_seg_size = Some(max_segment_size as u16);
@ -1526,9 +1526,9 @@ mod test {
fn recv<F>(socket: &mut TcpSocket, timestamp: u64, mut f: F)
where F: FnMut(Result<TcpRepr>) {
let mut limits = DeviceLimits::default();
limits.max_transmission_unit = 1520;
let result = socket.dispatch(timestamp, &limits, |(ip_repr, tcp_repr)| {
let mut caps = DeviceCapabilities::default();
caps.max_transmission_unit = 1520;
let result = socket.dispatch(timestamp, &caps, |(ip_repr, tcp_repr)| {
let ip_repr = ip_repr.lower(&[LOCAL_END.addr.into()]).unwrap();
assert_eq!(ip_repr.protocol(), IpProtocol::Tcp);