Stepping through a TCP/IP stack

I was working as a QA engineer for a proprietary embedded operating system. They built their own ATN stack and stepping though it with a debugger was the most eye opening experience I have had with networking. Watching each layer of the stack build their part of the packet was amazing. Then finally being able to see the built packet on the wire had more meaning. As an educator I would like share this experience with others. Does anyone know of a straight forward method stepping though a TCP/IP stack? Ideally I would like something easier than debugging a *BSD or Linux kernel, although if this is the only option then some tips and tricks for this process would be nice. A reference stack written in C/C++ that could be run in user mode with Visual Studio or Eclipse would be ideal.

40k 20 20 gold badges 96 96 silver badges 124 124 bronze badges asked Dec 27, 2011 at 16:13 66.8k 38 38 gold badges 164 164 silver badges 243 243 bronze badges

I don't think debugging is the best way of learning. In case of TCP/IP, just reading kernel source codes and/or inspecting real packets with a tool like Wireshark seems to be much more informative.

Commented Dec 30, 2011 at 17:15

@Evgeny Kluev I could not disagree more. Looking at traffic on the wire is just the result of a complex process. Its as if you are looking at a shadow of a woman to try figure out how beautiful she really is.

Commented Jan 2, 2012 at 19:36 Right. At last (after reading the OP once more) I got your point. It may be impressive. Commented Jan 3, 2012 at 11:08 What was the debugger you used to step through the ATN-stack? Commented Jan 4, 2012 at 18:37 Congratulations my friend. This is the kind of teacher the world needs. Very inspiring! Commented Jan 5, 2012 at 18:20

8 Answers 8

This all depends on what you want to focus on. From your question, the thing you are most interested in is the data flow throughout the different layers (user-space stream -> voltage on the cable).

For this, I propose you use http://www.csse.uwa.edu.au/cnet/, which is a full network simulator. It allows you to step through all levels of the stack.

Real systems will always have a clear distinction between Layer3, Layer2 and Layer1 (Ethernet and CRC-checking firmware on chip, hardware MAC). You will have trouble getting into the OS and some implementation details will be messy and confusing for students. For Linux, you'll have to explain kernel infrastructure to make sense of the TCP/IP stack design.

If you are only interested in the TCP/IP part, I recommend you use an embedded TCP/IP stack like http://www.sics.se/~adam/lwip/ . You can incorporate this into a simple user-space program and fully construct the TCP/IP packet.

Please note that there are a lot of network communication aspects that you cannot address while stepping through the TCP/IP stack. There is still a MAC chip in between which regulates medium access, collisions etc. Below that, there is a PHY chip which translates everything into electric/optical signals, and there is even a protocol which handles communication between MAC and PHY. Also, you are not seeing all aspects related to queueing, concurrency, OS resource allocation ea. A full picture should include all of these aspects, which can only be seen in a network simulator.