Release notes for uC/IP, a free TCP/IP/PPP stack for uC/OS
Version 1.0.0
By Guy Lancaster <lancasterg@acm.org> 1998-8-10

uC/IP Release Notes

These release notes for uC/IP are divided into the following sections:

Introduction

This is the first release of a free TCP/IP/PPP protocol stack for the uC/OS Real-Time Operating System.  As a first release it's still rather rough and very much larger than desired however it is working well in an embedded product and therefore may be useful to others.  Much of the code is ported from public sources including BDS Lite and KA9Q (and its derivatives) and carries copyright notices from those sources.  Essentially TCP is based on KA9Q but with ideas from BSD, IP is a simple implementation supporting BSD structures, ICMP is ported from BSD, and PPP is ported from the BSD version of the distribution common to BSD, Linux, and many other systems.

A Brief History

We at Global Election Systems Inc. have been converting our embedded systems from monolithic designs and proprietary protocols to real-time multitasking designs and standard protocols.  For various reasons, we chose uC/OS as the foundation for our projects but when evaluating the commercial TCP offerings, we felt that we would want to tweak them as much as we would the public sources and therefore we might as well just work with the public sources.  We started with volumes 1 and 2 of Stevens' TCP/IP Illustrated and a CDROM of BSD-Lite and dived into it.  As always, it was rather more involved than planned but also more rewarding in that by the time we got through it, we really knew our stuff.  Luckily Global has no commercial interest in the result and was quite willing to let me make the code publicly available provided that I did it on my own time and that there was no liability to the company.

Design Overview

This stack is designed for a small black box system with a minimal user interface and a serial port.  No keyboard, no video display, no disk drive, and no network adaptor.  In various modes our box can operate independantly with occasional connections to a host or it can work online with continous communications with the host.  Our serial link may be directly connected to the host or via modem and telephone lines.  Now, using the TCP procotols, the connection may go through any network configuration including the Internet.

Network Buffers

Central to the sources we used is the idea of a network or memory buffer.  In BSD and KA9Q it's known as an mbuf.  Normally data is transferred to a chain of buffers at the packet interface (commonly known simply as an interface) which are then transferred via queues through the protocol layers until finally being unloaded at the socket layer.  We modified the design of the mbuf and renamed it nbuf for Network Buffer.  Since our system has limited RAM space and we want to guarantee that needed space is always available, we create a fixed number of nbufs and manage them as a resource pool.  The netbuf module provides functions supporting nbuf allocation and queueing and services such as prepending, appending, and truncating nbuf chains.  In our stack, we use nbufs right from the serial interrupt handler up to the application interface.

For any particular application, it's important to select the nbuf and pool sizes for optimum performance.  First, set the size of the nbufs so that on average, each packet fits in a single nbuf.  If your application communicates with a lot of small packets and rarely more than 100 bytes, say a telnet app that returns a single line at a time, then set the nbuf size to about 50 bytes and allocate more of them.  If your application does bulk transfers, set the nbuf size to handle a full TCP segment and thereby minimize the chaining overhead.  There is currently a minimum nbuf size since it needs to handle an entire LCP packet in PPP.  With a little work LCP would be able to handle packets split across multiple nbufs.

In the next pass through the code I'd like to add a buffer type field that the protocols can use to automatically handle data from different sources.  In particular, I'd like to know whether or not a PPP packet needs to have special characters escaped or not so that this could be handled in the serial driver.  When the PPP protocols build a packet, they automatically encode the special characters.  To handle this, PPP needs to know where a packet originated and then ensure that all packets are encoded before passing them to the serial driver.  This requires a character by character filter (copy) operation which could trivially be handled at the driver level if only it knew.

Point to Point Protocol

The PPP code was the first code implemented and is the greatest resource hog.  PPP is composed of a number of different protocols handling everything from testing the link to compression and user authentication.  Essentially PPP recieves nbuf packet chains from the serial port, filters out the escape sequences, passes it through decompressors and finally passes an IP packet to the IP protocol.  In most systems PPP is implemented as a packet driver so that it's compatible with the interface for an ethernet packet driver but that requires managing another set of buffers.

Most of the PPP protocols use the finite state machine engine in the netfsm module.  Note that although code is included for CHAP, it has never been used and will not likely work out-of-the-box.

Transaction Control Protocol/Internet Protocol

As mentioned, the TCP code is based on the KA9Q sources although the TCP Control Block (TCB) includes fields from the BSD codes.  The biggest changes from either of these sources is in the timers and the use of semaphores.  KA9Q was written for the single tasking environment of DOS and therefore uses callback functions to drive applications using the stack.  We wanted to make blocking calls and therefore we built semaphores into the TCB to sychronize reads, writes, connections, and for mutual exclusion of critical sections.  This design doesn't handle waking up multiple tasks waiting on a read or write which would be useful if the connection has closed.  This isn't a problem for our application but I'd like to find a more general solution.

In Unix, the normal method to handle TCP timers is to have processes polling all of the TCB at 200ms and 500ms intervals.  Like all polling, this means that CPU cycles are "wasted" checking TCB's that don't need to be serviced but the method scales well (i.e. linearly) to large numbers of TCBs.  In uC/IP we use Linux style timers with preallocated timer structures that get inserted into an ordered linked list that is polled by the system clock interrupt.  This works well for a small number of TCBs but for more than a few dozen, the overhead of inserting and removing timers from the list would start to exceed in a non-linear fashion the cost of polling all the TCBs.

The IP module is pretty basic since we only do trivial routing and we don't handle fragmentation.  One thing that I would like to change is the use of the socket style network addresses.  The sockaddr struct (NetAddr type) is wonderfully general when you want it to handle any type of network address but won't be able to handle IPv6 addresses without change.  So, I would like to go through and simply handle IP addresses.

Features

Features Supported

The optimization

Features NOT Supported