Mininet is a project at Stanford that provides an API to emulate a multi-node network on a single machine. It uses linux containers and namespaces for configuration/resource isolation.
It is (was) not the only implementation of the idea that is as basic as it is extremely useful for testing in complex network setups.
All network stack variables (i.e. settings and state) are gather in one big struct and all network stack functions operate exclusively on the contents of this stack. Every process has one stack instance assigned to it by default and it may switch to another instance at any time. There are no changes to any socket-level API, all calls function exactly as before, but they are executed in the context of process' effective stack.
Process' default stack is inherited from the parent process, and this makes it trivial to run any existing application in a context of specific stack (by launching it from a process that selects desired stack and then does the exec).
At the bottom each stack connects to one or more network interfaces. Stacks may connect to the physical devices (multiple stacks per device is OK as long as it supports promiscuous mode), or they may connect to a virtual interface. Virtual interfaces in turn may have their inputs and outputs meshed together via hubs, switches or direct links, all of which may in turn be configured to emulate packet loss, latency, jitter and what not.
That's your basic network stack virtualization. Functioning version can be assembled from a forked Linux source in a couple of weekends. If only someone would bother submitting the patch after that :)
Project page: http://www.openflowswitch.org/foswiki/bin/view/OpenFlow/Mini...
Paper: http://conferences.sigcomm.org/hotnets/2010/papers/a19-lantz...
Other similar projects: