From 574abdca7b1ccca6a90e7aa38c74197e3979f5aa Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Sun, 3 Nov 2024 16:26:14 +0100 Subject: [PATCH] Fix callbacks, added some design doc --- .gitignore | 2 +- core.md | 107 ++++++++++++++++++++++++++++++++++++++++++++++ test/test-linux.c | 39 ++++++++--------- 3 files changed, 126 insertions(+), 22 deletions(-) create mode 100644 core.md diff --git a/.gitignore b/.gitignore index 1474cb7..ab68491 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ *.a *.pcap build/* -test/unit/unit-core +test/unit/unit tags diff --git a/core.md b/core.md new file mode 100644 index 0000000..aaa4ace --- /dev/null +++ b/core.md @@ -0,0 +1,107 @@ +# FemtoTCP + +## Stack architecture + + - No dynamic allocation (pre-allocated sockets and buffers) + - Four-steps main loop function + - Callback-based socket interface (allows implementing blocking BSD calls) + + + +## Data structures + +* Two types of circular buffers (fixed size): + + - "fifo" : contains entire frames, including a descriptor. + - "queue" : contains pure data, indexed by byte. Used for TCP receive buffer + only. + +* One binary heap for timers + + + +### FemtoTCP fifo + +``` ++---------------------------------------------------------------------------------------------------------------------------+ +| +-----+---+----+-----+------------------+-----+---+----+-----+------------------+ | +| | De | E | IP | TCP | Payload | De | E | IP | TCP | Payload | | +| | sc | T | | | | sc | T | | | | | +|* FREE SPACE * | ri | H | | | | ri | H | | | | * FREE SPACE* | +| | pt | | | | | pt | | | | | | +| | or | | | | | or | | | | | | +| +-----+---+----+-----+------------------+-----+---+----+-----+------------------+ | ++---------------------------------------------------------------------------------------------------------------------------+ + ^ ^ + | | + | | + | | + |Tail Head| + +``` + + + +### FemtoTCP queue + +``` + +--------------+--------------------------------------------+---------------------------------------------------------------+ + | |*------------------------------------------*| | + | || || | + | || || | + |* FREE SPACE *|| DATA PAYLOAD || * FREE SPACE * | + | || || | + | || || | + | |*------------------------------------------*| | + +--------------+--------------------------------------------+---------------------------------------------------------------+ + ^ ^ + | | + | | + | | + |Tail Head| +``` + + + +## Sockets + +### TCP socket + +``` + +-------------+ + |Main loop TX | + +-------------+ + ^ ++----------------------------------+ | +| | +------+ +| TCP Socket | | +| | | +| | | +| | | +| +-----------------------+ +| +---------------+ | | +>DATA OUT==>>|socket send() |-->| TX buffer (fifo) | +| +---------------+ | | +| +-----------------------+ +| | +| | +| | +| +-----------------------+ +| +-------------+ | | +