Educational userspace TCP/IP stack in Python. It is inspired by PyTCP's modular architecture and zero-copy design, while adopting a more explicit and control-oriented internal architecture for protocol handling.
- Support Ethernet II frame
- ARP request and reply handling
- ARP cache
- Temporary buffering of IP datagrams during MAC resolution
- ARP probe support
- Gratuitous ARP
- ARP retry mechanism
- Multicast Ethernet frames
- Full IPv4 support
- IP fragmentation and reassembly
- Direct delivery within the local network
- Default gateway fallback when no matching route exists
- Sending supported
- Receiving not yet implemented
- Echo Request / Echo Reply
- Destination Unreachable (port/protocol)
- TTL Exceeded
- Reassembly Timeout Exceeded
- Multicast handling
- Broadcast handling
- Fully supported
Basic TCP implementation with support for:
- MSS (Maximum Segment Size)
- TCP options:
- EOL
- NOP
- Delayed ACK
- Improved out-of-order segment handling
- Window scaling
- TCP Congestion Control
tipy provides a Python-like socket API for easy integration.
AF_INET / SOCK_DGRAM— UDPAF_INET / SOCK_STREAM— TCPAF_INET / SOCK_RAW— Raw IPv4 access
bind()connect()send()recv()close()shutdown()settimeout()setsockopt()
sendto()recvfrom()listen()
IPPROTO_IPSOL_SOCKET
IP_TTLIP_OPTIONSSO_LINGER
- Packet integrity validation is not yet implemented.
- DHCP is not supported; static network configuration is required.
shutdown()currently only closes the TCP TX path (SHUT_WRbehavior).SHUT_RDis not yet supported.
Run your script from the tipy project root directory, then import:
from tipy import tipy, socketstack = tipy(ifname="tap7")
stack.start()sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((LISTEN_IP, LISTEN_PORT))
sock.connect((PEER_IP, PEER_PORT))sock.send(DATA)data = sock.recv(1024)sock.close()This section prepares a Linux bridge and TAP interface required for running tipy.
The following names and network settings are used in this example:
- Physical interface:
enp0s3 - Bridge interface:
br0 - TAP interface:
tap7 - Network:
192.168.2.0/24
nmcli con down <profile>nmcli con add \
con-name br0 \
ifname br0 \
type bridge \
ipv4.addresses 192.168.2.199/24 \
ipv4.gateway 192.168.2.1 \
ipv4.dns 192.168.2.1
nmcli con mod br0 stp no
nmcli con mod br0 ethernet.accept-all-mac-addresses yes- This creates a bridge interface with a static IP address and disables STP for simplicity.
nmcli con add \
con-name enp0s3-slave \
ifname enp0s3 \
type bridge-slave \
master br0- This connects your physical network card to the bridge.
nmcli con add \
con-name tap7 \
ifname tap7 \
type tun \
mode tap \
master br0
nmcli con mod tap7 ethernet.mac-address 00:11:22:33:44:55- This creates a TAP device and assigns it a fixed MAC address.
- Important: The MAC address assigned here must match the MAC configured in tipy's config.py.
nmcli con up br0
nmcli con up enp0s3-slave
nmcli con up tap7- This activates the bridge, physical interface, and TAP device.
All scripts must be executed from the root directory of the tipy project to ensure proper module resolution.
PYTHONPATH=. python3 -O your_script.pyPYTHONPATH=. python3 your_script.py