This is a lightweight NIC simulator that exposes a TAP interface on Linux and emulates NIC-like behaviors:
- RX/TX rings (lock-free single-producer/single-consumer queues)
- Rate limiting (token bucket, Mbps)
- Artificial latency / jitter (ms)
- Packet loss (%)
- Basic stats (pps, bps, drops, latency percentiles)
- MAC filtering (optional, default allow-all)
- Graceful shutdown (SIGINT/SIGTERM)
It is not a PCIe device model. Instead, it simulates a soft NIC path using a TAP device so you can test host networking stacks and traffic without special hardware.
Tested on Ubuntu 22.04+. Should compile on any recent Linux with TUN/TAP support.
sudo apt-get update && sudo apt-get install -y build-essential cmake libssl-dev
mkdir -p build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j
Requires CAP_NET_ADMIN to create/configure TAP. You can run via sudo.
sudo ./nic-sim --ifname nic0 --rate-mbps 500 --delay-ms 2 --jitter-ms 1 --loss 0.1 --mtu 1500
This will create a TAP device nic0
. Bring it up and assign an IP in a separate shell:
sudo ip link set dev nic0 up
sudo ip addr add 10.10.10.1/24 dev nic0
Now generate traffic (e.g., ping yourself or run iperf against another namespace):
# Self-echo: packets you send to nic0 are looped back after delay/loss/rate-limit
ping -I nic0 10.10.10.1
sudo ip netns add ns1
sudo ip link set nic0 netns ns1
sudo ip netns exec ns1 ip link set dev nic0 up
sudo ip netns exec ns1 ip addr add 10.10.10.2/24 dev nic0
# from a different interface on host, add route or launch a second TAP instance
Usage: nic-sim [options]
--ifname <name> TAP name to create (default: nic0)
--rate-mbps <float> Rate limit in megabits per second (default: unlimited)
--delay-ms <int> Base one-way delay in milliseconds (default: 0)
--jitter-ms <int> Jitter added uniformly in [0, jitter] ms (default: 0)
--loss <float> Packet loss percentage 0..100 (default: 0)
--mtu <int> MTU for TAP (default: 1500)
--stats-interval <s> Stats print interval seconds (default: 1)
--mac <xx:xx:xx:xx:xx:xx> Optional MAC filter (accept dest MAC == given or broadcast)
--seed <int> RNG seed (default: time-based)
- TAP backend: acts like a NIC from the host standpoint.
- RX/TX Rings: Two SPSC queues model NIC descriptor rings.
- Traffic path: frames read from TAP are enqueued → shaped (loss/rate/latency) → dequeued back to TAP (loopback). This lets you test end-to-end behavior under controlled impairments.
- Rate limiter: token bucket in bytes, refilled by wall clock.
- Delay: queue with per-packet target release time.
- Loss: Bernoulli with configurable percentage.
- Stats: per-direction counters, drops, avg latency.
- Add pcap capture/replay.
- Implement multi-queue and RSS hashing.
- Add ethtool-like control plane via UNIX socket/JSON.
- Integrate XDP/eBPF hook before/after shaping for programmable dataplane.
- Provide a DPDK PMD wrapper to expose nic-sim as a virtual device.
MIT