Skip to content

casys-kaist/smoltcpplus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

smoltcpplus

smoltcpplus is a modified version of smoltcp v0.7.5. It enhances asynchronous and concurrent features, which allow flexible and efficient implementation of new network stack based on smoltcpplus.

Check original smoltcp for other detailed and recent informations: https://github.com/smoltcp-rs/smoltcp

What's different

(1) Avoid using Waker, but handle asynchronous tasks by function closure

   Waker wakes up the other task that desired to be handled asynchronously. However, there is no way to adjust start time of that task, which inherentely causes some non-determinism.
   It goes even worse when there exists shared state between the wake caller, and waked task. It casues and makes really hard to debug concurrent issues include race, deadlock, livelock, and etc.
   To handle this issue, We've decided to pass function closure as argument of interface, handle some part of task by using it, and aggregate additional task to be handled in the end.

(2) Make EthernetInterface and Socket immutable, so that it can be accessed by multiple thread.

   Since EthernetInterface and Socket are mutable, only daemon thread (who calls EthernetInterface::poll) will have ownership. So, EthernetInterface and Socket state changes are disallowed in other execution context including waker task.
   Although there exists multiple sockets and multiple thread using it, other threads simply send message to daemon thread, and wait for daemon thread to handle its socket jobs. It delays latency and cause additional memory allocation and copies.
   One observation is that EthernetInterface and Socket states are mostly accessed in read-only manner, only daemon and one socket-using thread would compete to change state. So, it is fine to wrap structures in lock to allow efficient sharing.

(3) Only IPv4, Icmp, and Tcp are supported currently

Features

Support no_std

smoltcpplus assumed to be run with no_std feature. For ease of test purpose, you can enable std and run it on Linux. Checkout simple_net example to see how std is used.

Feature std

The std feature enables use of objects and slices owned by the networking stack through a dependency on std::boxed::Box and std::vec::Vec. Also it includes some crossbeam-utils and channel for example implementation

This feature is disabled by default.

Feature alloc

The alloc feature enables use of objects owned by the networking stack through a dependency on collections from the alloc crate. This only works on nightly rustc.

This feature is enabled by default.

Features phy-tap_interface

Enable smoltcpplus::phy::TapInterface. Required to connect to tap interface

This feature is disabled by default.

Features socket-raw, socket-udp, and socket-tcp

Enable smoltcpplus::socket::RawSocket, smoltcpplus::socket::UdpSocket, and smoltcpplus::socket::TcpSocket, respectively.

These features are enabled by default.

Features `proto-ipv4

Enable IPv4.

Hosted usage examples

smoltcpplus, being a freestanding networking stack, needs to be able to transmit and receive raw frames. For testing purposes, we will use a regular OS, and run smoltcpplus in a userspace process. Only Linux is supported (right now).

examples/bench_server

examples/bench_server implements simple closed-loop tcp latency benchmark upon simple_net.
simple_net implements an inpendent network stack upon smoltcp. It provides posix-like socket api for user and handles Icmp, TCP in IPv4.

export NET_INF ens1f1
export NET_IP 10.0.2.2
# Setup
./examples/scripts/setup_net.sh $NET_INF $NET_IP

# Run simple latency server
cargo run --release --features="phy-tap_interface proto-ipv4 socket-icmp" --example bench_server -- tap0 latency 

# Clear
./examples/scripts/clear_net.sh $NET_INF
# In other computer connected to $NET_INF
export PKT_SIZE 4096
export PKT_COUNT 100000
export OUTPUT_FILE output.csv

cd examples/bench_cli
make
./bench_cli $NET_IP latency $PKT_SIZE $PKT_COUNT $OUTPUT_FILE

Avg latency (us) for packet size (bytes)

Network Stack 100 500 1400 4096
Linux 41.32 42.23 44.08 52.34
Linux (Docker) 41.49 42.6 44.39 51.43
Linux (KVM) 67.38 67.67 69.3 75.57
Coffer Mono 44.08 44.31 44.91 51.89
simple_net 40.98 42.30 43.94 59.78

examples/ping.rs

examples/ping.rs implements a minimal version of the ping utility using raw sockets.

The host is assigned the hardware address 02-00-00-00-00-02 and IPv4 address 10.0.2.2.

Read its source code, then run it as:

cargo run --example ping -- tap0 ADDRESS

It sends a series of 4 ICMP ECHO_REQUEST packets to the given address at one second intervals and prints out a status line on each valid ECHO_RESPONSE received.

The first ECHO_REQUEST packet is expected to be lost since arp_cache is empty after startup; the ECHO_REQUEST packet is dropped and an ARP request is sent instead.

Currently, netmasks are not implemented, and so the only address this example can reach is the other endpoint of the tap interface. It cannot reach itself because packets entering a tap interface do not loop back.

Contributors

License

smoltcpplus is distributed under the terms of Apache 2.0 license.

See LICENSE for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages